I have several accounts associated with mu4e and I can both receive and send - using smtpmail-multi - from all them without problems. I am not using contexts. The relevant parts in my configuration look like this:
(setq message-citation-line-function 'message-insert-formatted-citation-line)
(setq message-citation-line-format "On %a, %b %d %Y, %f wrote:\n")
(setq smtpmail-multi-accounts
(quote
((yahoo . ("xxxx#yahoo.com"
"smtp.mail.yahoo.com"
587
"xxxxx#yahoo.com"
nil nil nil nil))
(other . ("xxxxx#other.com"
"smtp.other.com"
465
"xxxx#other.com"
ssl nil nil nil))
(etc . ("xx#etc.com"
"smtp.etc.com"
465
"xx#etc.com"
ssl nil nil nil))
;; ...
)))
(setq smtpmail-multi-associations
(quote
(("xxxx#yahoo.com" yahoo)
("xxx#other.com" other)
("xx#etc.com" etc)
;; ....
)))
(setq smtpmail-multi-default-account (quote yahoo))
(setq message-send-mail-function 'smtpmail-multi-send-it)
(setq mu4e-compose-dont-reply-to-self t)
(setq mu4e-user-mail-address-list '("xxxx#yahoo.com"
"xxx#other.com"
"xx#etc.com"
;; ...
))
(setq user-full-name "XXXXXX")
(setq user-mail-address "xxx#other.com")
This way I can properly send emails from the right account just by typing the address of my email in the FROM: field.
When replying, I want mu4e to identify the account to which the message has been send and update FROM: field accordingly so that I don't have to type in the proper account all the time myself. I am looking for a way to do this without having to upgrade my entire configuration to using contexts.
After a lot of tweaking I came up with this:
(defun my-mu4e-set-account ()
"Set the account for composing a message."
(if mu4e-compose-parent-message
(let ((mail (cdr (car (mu4e-message-field mu4e-compose-parent-message :to)))))
(if (member mail mu4e-user-mail-address-list)
(setq user-mail-address mail)
(setq user-mail-address "my#default.account")))
(helm :sources
`((name . "Select account: ")
(candidates . mu4e-user-mail-address-list)
(action . (lambda (candidate) (setq user-mail-address candidate)))))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
where mu4e-user-mail-address-list is, obviously, a list with my mail accounts
This will reply with the proper account and, more, will open a helm mini menu asking me which account to use every time I compose a new message.
I know that this blog post has a multi account setup that automatically picks up the FROM field. Might want to take a look at it. Mu4e is on my todo list so I can't give you a direct answer.
Related
I am using ERC in emacs 24 and using the following code in my .emacs. The erc-global-notify function is adapted from http://www.emacswiki.org/emacs/ErcPageMe. Unfortunately, I couoldn't get any notifcations from dbus when the emacs with erc windows is minimized. What's the problem with it?
(require 'erc-match)
(erc-match-mode t)
(setq erc-keywords '("c++" "python" "emacs" "i")
erc-pals '("ij" "yy" "xx"))
(require 'notifications)
(defun erc-global-notify (match-type nick message)
"Notify when someone sends a message that matches a regexp in `erc-keywords'."
(when (and (eq match-type 'keyword)
;; I don't want to see anything from the erc server
(null (string-match "^[sS]erver" nick))
;; or bots
(null (string-match "\\(bot\\|serv\\)!" nick)))
(notifications-notify
:title nick
:body message
:urgency 'normal)))
(add-hook 'erc-text-matched-hook 'erc-global-notify)
I have this function
(defun mention-notify (match-type nickuserhost msg)
(interactive)
(if (and (eq match-type 'current-nick)
(eq (string-match "^-NickServ-" msg) nil) ;this is probably not needed
(eq (string-match "^\\*\\*\\*" msg) nil))
(progn
(shell-command "mpg123 -q /home/kuba/Pobrane/beep-8.mp3")
(notify "ERC" msg))))
(add-hook 'erc-text-matched-hook 'mention-notify)
But it execute command even it message start from ***. What I'm doing wrong here? How this function should look like?
I read that page but it only show how to send notification for all mentions, even from server. like:
*** Users on #<chanel>: jcubic...
or
*** jcubic has changed mode for jcubic to +i
It seams that when I check for 'current-nick - msg is not the whole message but substring containing my nick, I try to check for keyword instead of current-nick and check if my nick that I always use appear in the text but using keyword doesn't work at all.
You might also want to look at Sauron:
http://www.emacswiki.org/emacs/Sauron
I copied erc-match-message function from erc.el file into my .emacs file and I added one flag to hook
(run-hook-with-args
'erc-text-matched-hook
(intern match-type)
(or nickuserhost
(concat "Server:" (erc-get-parsed-vector-type vector)))
message
(string-match "^\\*\\*\\*"
(buffer-substring (point-min) (point-max)))))))
last flag is set if message is erc system message - starts with *** so now I can check this flag in my hook
(defun mention-notify (match-type nickuserhost msg notification)
(interactive)
(if (and (eq match-type 'current-nick)
(not notification))
(progn
(shell-command "mpg123 -q /home/kuba/Pobrane/beep-8.mp3")
(notify "ERC" msg))))
UPDATE I also didn't want to recive message from -NickServ- so I add this
(run-hook-with-args
'erc-text-matched-hook
(intern match-type)
(or nickuserhost
(concat "Server:" (erc-get-parsed-vector-type vector)))
message
(let ((whole-msg (buffer-substring (point-min) (point-max))))
(or (string-match "^-NickServ-" whole-msg)
(string-match "^\\*\\*\\*" whole-msg)))))))
A quick google search for "erc mention notify" yields a bunch of example code to do exactly what you want.
I use Gnus 5.13 for emails (on Mac OS X 10.7.2 with emacs 24). I use the gnus-posting-styles entry (eval (set (make-local-variable 'message-cite-reply-position) 'above)) in order to place the point (cursor) on top of the message in replies. This allows me to either top-reply or to reply inline (between the message that I would like to reply to). Unfortunately, the above entry also puts my signature on top of the message I would like to reply to. That's okay if I want to top-reply, but it's wrong if I want to reply inline. How can I force the signature to be placed under the message I reply to?
Discarding the 'message-cite-reply-position' modification, I have added the following to my .gnus.el file, and now when replying to an e-mail or news post, first goes the yanked message, then my signature, and the point is placed at the beginning of the message.
(eval-after-load "gnus-msg"
'(defun gnus-inews-yank-articles (articles)
(let (beg article yank-string)
(message-goto-body)
(while (setq article (pop articles))
(when (listp article)
(setq yank-string (nth 1 article)
article (nth 0 article)))
(save-window-excursion
(set-buffer gnus-summary-buffer)
(gnus-summary-select-article nil nil nil article)
(gnus-summary-remove-process-mark article))
(gnus-copy-article-buffer nil yank-string)
(let ((message-reply-buffer gnus-article-copy)
(message-reply-headers
;; The headers are decoded.
(with-current-buffer gnus-article-copy
(save-restriction
(nnheader-narrow-to-headers)
(nnheader-parse-naked-head)))))
(message-yank-original)
(setq beg (or beg (mark t))))
(when articles
(insert "\n")))
(push-mark)
; (goto-char beg))) -- Original
(message-goto-body) ; -- Modified, so point will be moved to beginning of article
(insert "\n\n") ; -- and two empty lines will be added.
(message-goto-body)))) ; --
I would like to save all attachments to an email at once. I therefore set gnus-summary-save-parts-default-mime to ".* /.*". However, when using "X m", I not only get all attachments, but also a file named "nnimap+my.name#googlemail.com/INBOX.2393.1" (referring to the account I'm reading emails from) which contains the signature of the email I received. How can I exclude files of this "type" from being saved on "X m"? In other words: How can I specify the correct regexp for gnus-summary-save-parts-default-mime to prevent this file from being saved, too?
This defadvice will do what you want for the moment by excluding any parts that do not have filenames (in this case that is true of the article itself):
(defadvice gnus-summary-save-parts-1 (around gnus-summary-save-parts-exclude-self activate)
(let ((handle (ad-get-arg 2)))
(unless (and (not (stringp (car handle)))
(not (mm-handle-filename handle)))
ad-do-it)))
I am using Gnus v5.13; if you're also using the same or similar version, let me know if this modified version of gnus-summary-save-parts-1 works for you; you will want to set gnus-summary-save-parts-exclude-article to t. If it works for you, I will submit a patch for it to the Gnus projects.
Note, either use the above defadvice OR use the code below, but do not use both together. The defadvice is an easy quick fix that you can use for the moment. The code below I will submit as a patch to the Gnus project and I only included this here for you to test to see if it works on your system if you are also using Gnus v5.13. If they accept this patch and make it part of a future release then you will not need the defadvice above; instead you'll just be able to customize the gnus-summary-save-parts-exclude-article variable.
(require 'gnus)
(require 'gnus-sum)
(defcustom gnus-summary-save-parts-exclude-article nil
"If non-nil don't save article along with attachments."
:group 'gnus-article-mime
:type 'boolean)
(defun gnus-summary-save-parts-1 (type dir handle reverse)
(if (stringp (car handle))
(mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
(cdr handle))
(when (if reverse
(not (string-match type (mm-handle-media-type handle)))
(string-match type (mm-handle-media-type handle)))
(let* ((name (or
(mm-handle-filename handle)
(unless gnus-summary-save-parts-exclude-article
(format "%s.%d.%d" gnus-newsgroup-name
(cdr gnus-article-current)
gnus-summary-save-parts-counter))))
(file (when name
(expand-file-name
(gnus-map-function
mm-file-name-rewrite-functions
(file-name-nondirectory
name))
dir))))
(when file
(incf gnus-summary-save-parts-counter)
(unless (file-exists-p file)
(mm-save-part-to-file handle file)))))))
I switched from mutt to gnus and would like to extract urls from emails and be able to launch a new buffer that contains all urls in a given email. Urlview does this for mutt as a frame of reference for what I am looking for.
I wrote the following and tested it to work on a couple of articles. Maybe it will be a good starting point for you.
(defun gnus-article-extract-url-into-buffer ()
(interactive)
(let ((simple-url-regexp "https?://")
urls)
(save-excursion
;; collect text URLs
(while (search-forward-regexp simple-url-regexp nil t)
(when-let (url (thing-at-point 'url))
(setq urls (cons url urls))))
(beginning-of-buffer)
;; collect widget URLs
(while (not (eobp))
(goto-char (next-overlay-change (point)))
(when-let (link (get-text-property (point) 'gnus-string))
(and (string-match simple-url-regexp link)
(setq urls (cons link urls))))
(goto-char (next-overlay-change (point)))))
(when urls
(switch-to-buffer-other-window "*gnus-article-urls*")
(dolist (url urls)
(insert url))
(beginning-of-buffer))))
I should clarify that this is intended to be run from within the article buffer.
Also, I may have missed the point by taking what you said literally about launching a new buffer containing the urls, in which case you can change the last form to:
(when urls
(dolist (url urls)
(browse-url url)))
Or, Tyler's approach is simpler if you don't need to parse widget urls.
I don't think that function is built-in. The following code will do what you want. From the summary buffer, call M-x urlview, or bind it to a convenient key. The save-excursion wrapper should drop you back in the summary buffer, but for some reason it leaves you in the article buffer. Just hitting the h key will put you back, but you shouldn't need to do that. Maybe someone else can clarify that part?
(defun urlview ()
(interactive)
(save-excursion
(gnus-summary-select-article-buffer)
(beginning-of-buffer)
(while
(re-search-forward "https?://" nil t)
(browse-url-at-point))))
Edit: Joseph's answer works for both http and https, which I had overlooked. So I swiped that part of his code.