* make it configurable what to do with sent messages (part 2), and document it:

By default, @t{mu4e} puts a copy of any messages you sent in the folder you
set for @code{mu4e-sent-folder}. In some case, this may not be what you want -
for example, when using GMail+@abbr{IMAP} (but @emph{not} with
GMail+@abbr{POP3}), this interferes with GMail's handling of the sent messages
folder, and you may end up with duplicate messages. For this, since @t{mu4e}
0.9.8.3, there is the variable @code{mu4e-sent-messages-behavior}, which takes
a symbol. The default is @code{'sent} which, as stated causes the message to
be copied to your sent-messages folder. Other possible values are
@code{'trash} (so the sent message is copied to the trash-folder
(@code{mu4e-trash-folder}), and @code{'delete} to simply discard the message
altogether.
This commit is contained in:
djcb 2012-03-13 20:13:30 +02:00
parent 4122b76607
commit a051f3a89f
3 changed files with 70 additions and 33 deletions

View File

@ -190,7 +190,7 @@ And finally, the cited body of MSG, as per `mu4e-send-cite-original'."
(concat (concat
;; if there's no Re: yet, prepend it ;; if there's no Re: yet, prepend it
(if (string-match (concat "^" mu4e-send-reply-prefix) subject) (if (string-match (concat "^" mu4e-send-reply-prefix) subject)
"" mu4e-send-reply-prefix) "" mu4e-send-reply-prefix)
subject)) subject))
(propertize mail-header-separator 'read-only t 'intangible t) '"\n" (propertize mail-header-separator 'read-only t 'intangible t) '"\n"
@ -220,7 +220,7 @@ And finally, the cited body of MSG, as per `mu4e-send-cite-original'."
(mu4e-send-header "From" (or (mu4e-send-from-create) "")) (mu4e-send-header "From" (or (mu4e-send-from-create) ""))
(when (boundp 'mail-reply-to) (when (boundp 'mail-reply-to)
(mu4e-send-header "Reply-To" mail-reply-to)) (mu4e-send-header "Reply-To" mail-reply-to))
(mu4e-send-header "To" "") (mu4e-send-header "To" "")
(mu4e-send-header "User-agent" (mu4e-send-user-agent)) (mu4e-send-header "User-agent" (mu4e-send-user-agent))
(mu4e-send-header "References" (mu4e-send-references-create msg)) (mu4e-send-header "References" (mu4e-send-references-create msg))
@ -228,7 +228,7 @@ And finally, the cited body of MSG, as per `mu4e-send-cite-original'."
(concat (concat
;; if there's no Re: yet, prepend it ;; if there's no Re: yet, prepend it
(if (string-match (concat "^" mu4e-send-forward-prefix) subject) (if (string-match (concat "^" mu4e-send-forward-prefix) subject)
"" mu4e-send-forward-prefix) "" mu4e-send-forward-prefix)
subject)) subject))
(propertize mail-header-separator 'read-only t 'intangible t) "\n" (propertize mail-header-separator 'read-only t 'intangible t) "\n"
@ -362,7 +362,7 @@ using Gnus' `message-mode'."
(message-goto-to) (message-goto-to)
(message-goto-body)))) (message-goto-body))))
(defun mu4e-send-save-copy-maybe () (defun mu4e-send-save-copy-maybe ()
"If `mu4e-save-sent-messages-behavior' is a symbol 'delete, move "If `mu4e-save-sent-messages-behavior' is a symbol 'delete, move
@ -371,9 +371,9 @@ using Gnus' `message-mode'."
`message-sent-hook'." `message-sent-hook'."
(let ((docid (gethash (buffer-file-name) mu4e-path-docid-map))) (let ((docid (gethash (buffer-file-name) mu4e-path-docid-map)))
(unless docid (error "unknown message (%S)" (buffer-file-name))) (unless docid (error "unknown message (%S)" (buffer-file-name)))
(save-buffer) ;; save the messages, so emacs won't annoy us
(if (eq mu4e-sent-messages-behavior 'delete) (if (eq mu4e-sent-messages-behavior 'delete)
(progn (progn
(save-buffer)
(mu4e-proc-remove-msg docid)) ;; remove it (mu4e-proc-remove-msg docid)) ;; remove it
(progn ;; try to save the message the sent folder (progn ;; try to save the message the sent folder
(save-excursion (save-excursion
@ -382,11 +382,12 @@ using Gnus' `message-mode'."
(if (search-forward-regexp (concat "^" mail-header-separator "\n")) (if (search-forward-regexp (concat "^" mail-header-separator "\n"))
(replace-match "") (replace-match "")
(error "cannot find mail-header-separator")) (error "cannot find mail-header-separator"))
(save-buffer)
;; ok, all seems well, well move the message to the sent-folder ;; ok, all seems well, well move the message to the sent-folder
(if (eq mu4e-sent-messages-behavior 'trash) (if (eq mu4e-sent-messages-behavior 'trash)
(mu4e-proc-move-msg docid mu4e-trash-folder "+T-D+S") (mu4e-proc-move-msg docid mu4e-trash-folder "+T-D+S")
(mu4e-proc-move-msg docid mu4e-sent-folder "-T-D+S"))))))) (mu4e-proc-move-msg docid mu4e-sent-folder "-T-D+S")))))))
(defun mu4e-send-set-parent-flag () (defun mu4e-send-set-parent-flag ()

View File

@ -263,6 +263,20 @@ recommended you use \"html2text -utf8 -width 72\"."
:type 'string :type 'string
:group 'mu4e-compose) :group 'mu4e-compose)
(defcustom mu4e-sent-messages-behavior 'sent
"Determines what mu4e does with sent messages - this is a symbol
which can be either:
'sent --> move the sent message to the Sent-folder (`mu4e-sent-folder')
'trash --> move the sent message to the Trash-folder (`mu4e-trash-folder')
'delete --> delete the sent message.
Note, when using GMail/IMAP, you should set this to either 'trash
or 'delete, since GMail already takes care of keeping copies in the
sent folder."
:type 'symbol
:safe 'symbolp
:group 'mu4e-compose)
;; Faces ;; Faces
(defgroup mu4e-faces nil (defgroup mu4e-faces nil
@ -638,13 +652,13 @@ function prefers the text part, but this can be changed by setting
(if html (length html) 0))) ;; real text part? (if html (length html) 0))) ;; real text part?
(setq body txt)) (setq body txt))
;; no body yet? try html ;; no body yet? try html
(unless body (unless body
(when html (when html
(setq body (setq body
(with-temp-buffer (with-temp-buffer
(insert html) (insert html)
;; if defined, use the external tool ;; if defined, use the external tool
(if mu4e-html2text-command (if mu4e-html2text-command
(shell-command-on-region (point-min) (point-max) (shell-command-on-region (point-min) (point-max)
mu4e-html2text-command nil t) mu4e-html2text-command nil t)
;; otherwise... ;; otherwise...

View File

@ -183,7 +183,7 @@ configuration}.
You can do all of the mail retrieval @emph{outside} of @t{emacs}/@t{mu4e}, but You can do all of the mail retrieval @emph{outside} of @t{emacs}/@t{mu4e}, but
you can also do it from the @t{mu4e}. For that, set the variable you can also do it from the @t{mu4e}. For that, set the variable
@code{mu4e-get-mail-command} to the command you want to use for retrieving @code{mu4e-get-mail-command} to the command you want to use for retrieving
mail, which you can then access from the @ref{Main view}. mail, which you can then access from the @ref{Main view}.
You can also have this command run periodically (in the background), by You can also have this command run periodically (in the background), by
setting the variable @code{mu4e-update-interval} to the number of seconds setting the variable @code{mu4e-update-interval} to the number of seconds
@ -249,6 +249,26 @@ A very minimal setup could look something like:
Note, since @t{mu4e} uses the same @t{message mode} and @t{smtpmail} Note, since @t{mu4e} uses the same @t{message mode} and @t{smtpmail}
that Gnus uses, any setting for those will also work for @t{mu4e}. that Gnus uses, any setting for those will also work for @t{mu4e}.
By default, @t{mu4e} puts a copy of any messages you sent in the folder you
set for @code{mu4e-sent-folder}. In some case, this may not be what you want -
for example, when using GMail+@abbr{IMAP} (but @emph{not} with
GMail+@abbr{POP3}), this interferes with GMail's handling of the sent messages
folder, and you may end up with duplicate messages. For this, since @t{mu4e}
0.9.8.3, there is the variable @code{mu4e-sent-messages-behavior}, which takes
a symbol. The default is @code{'sent} which, as stated causes the message to
be copied to your sent-messages folder. Other possible values are
@code{'trash} (so the sent message is copied to the trash-folder
(@code{mu4e-trash-folder}), and @code{'delete} to simply discard the message
altogether.
Thus, for GMail-IMAP you can add the following to your settings:
@verbatim
;; don't save message to Sent Messages, GMail/IMAP will take care of this
(setq mu4e-sent-messages-behavior 'trash)
@end verbatim
@node Queuing mail @node Queuing mail
@section Queuing mail @section Queuing mail
@ -877,27 +897,27 @@ notifications in the sauron-buffer when new messages arrive.
#!/bin/sh #!/bin/sh
# put the path to your Inbox folder here # put the path to your Inbox folder here
CHECKDIR="/home/$LOGNAME/Maildir/Inbox" CHECKDIR="/home/$LOGNAME/Maildir/Inbox"
sauron-msg () { sauron-msg () {
DBUS_COOKIE="/home/$LOGNAME/.sauron-dbus" DBUS_COOKIE="/home/$LOGNAME/.sauron-dbus"
if test "x$DBUS_SESSION_BUS_ADDRESS" = "x"; then if test "x$DBUS_SESSION_BUS_ADDRESS" = "x"; then
if test -e $DBUS_COOKIE; then if test -e $DBUS_COOKIE; then
export DBUS_SESSION_BUS_ADDRESS="`cat $DBUS_COOKIE`" export DBUS_SESSION_BUS_ADDRESS="`cat $DBUS_COOKIE`"
fi fi
fi fi
if test -n "x$DBUS_SESSION_BUS_ADDRESS"; then if test -n "x$DBUS_SESSION_BUS_ADDRESS"; then
dbus-send --session \ dbus-send --session \
--dest="org.gnu.Emacs" \ --dest="org.gnu.Emacs" \
"/org/gnu/Emacs/Sauron" \ "/org/gnu/Emacs/Sauron" \
"org.gnu.Emacs.Sauron.AddMsgEvent" \ "org.gnu.Emacs.Sauron.AddMsgEvent" \
string:shell uint32:3 string:"$1" string:shell uint32:3 string:"$1"
fi fi
} }
for f in `find $CHECKDIR -mmin -2 -a -type f`; do for f in `find $CHECKDIR -mmin -2 -a -type f`; do
subject=`$MU view $f | grep '^Subject:' | sed 's/^Subject://'` subject=`$MU view $f | grep '^Subject:' | sed 's/^Subject://'`
sauron-msg "mail: $subject" sauron-msg "mail: $subject"
done done
@end verbatim @end verbatim
Note, you should put something like: Note, you should put something like:
@ -1058,10 +1078,9 @@ realdelete = no
@end verbatim @end verbatim
Of course, you need replace @t{USERNAME} and @t{PASSWORD} with your actual Of course, you need replace @t{USERNAME} and @t{PASSWORD} with your actual
Gmail username and password. GMail username and password.
After this, you can download your mail, it should look something like the After this, you should be able to download your mail:
following:
@verbatim @verbatim
$ offlineimap $ offlineimap
OfflineIMAP 6.3.4 OfflineIMAP 6.3.4
@ -1112,6 +1131,9 @@ Now, let's make a @t{mu4e} configuration for this:
(setq mu4e-sent-folder "/[Gmail].Sent Mail") (setq mu4e-sent-folder "/[Gmail].Sent Mail")
(setq mu4e-trash-folder "/[Gmail].Trash") (setq mu4e-trash-folder "/[Gmail].Trash")
;; don't save message to Sent Messages, GMail/IMAP will take care of this
(setq mu4e-sent-messages-behavior 'delete)
;; setup some handy shortcuts ;; setup some handy shortcuts
(setq mu4e-maildir-shortcuts (setq mu4e-maildir-shortcuts
'( ("/INBOX" . ?i) '( ("/INBOX" . ?i)