Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Marcel van der Boom 2020-05-19 09:09:08 +02:00
commit fa5b181e25
7 changed files with 10 additions and 204 deletions

View File

@ -73,10 +73,6 @@
- In addition, he added support for custom headers, so the ones for for the
non-gnus-view should work just as well.
- Pierre Neidhardt contributed an experimental "Account Setup Helper" which
wraps the existing context setup with some niceties for accounts. See the
manual for details.
- ~org-mode~ support is enabled by default now. ~speedbar~ support is disabled
by default.

View File

@ -30,7 +30,6 @@
(require 'cl-lib)
(require 'mu4e-utils)
(defvar mu4e-move-to-trash-patterns)
(defvar smtpmail-smtp-user)
(defvar mu4e-view-date-format)
@ -83,118 +82,6 @@ none."
;; if it matches, nil otherwise
vars) ;; alist of variables.
(defvar mu4e-no-trash-providers '("gmail.com" "googlemail.com")
"List of email providers that don't support the trash flag.")
(cl-defun make-mu4e-context-account (&key name
enter-func
leave-func
match-func
vars
;; We set sane defaults for the following variables. They will be added to
;; the context vars.
(user-mail-address user-mail-address)
(smtpmail-smtp-user smtpmail-smtp-user)
;; Folders:
maildir
(drafts-folder "drafts")
(sent-folder "sent")
(trash-folder "trash")
(refile-folder "archive")
;; Trash fix.
no-trash-flag
;; Rule for matching the context.
predicate)
"Create a context with sane defaults (see `make-mu4e-context').
Also:
- Add the context to the `mu4e-contexts'.
- Update the bookmarks to ignore the trash folder if NO-TRASH-FLAG is non-nil.
Options beyond those of `make-mu4e-context':
- `user-mail-address': Defaults to the global value when the context is created.
- `smtpmail-smtp-user': Defaults to the global value if non-nil when the context
is created, or the context `user-mail-address' otherwise.
- `maildir': Mailbox folder name in as stored in `mu4e-maildir' (just the name,
there must be no '/'). Defaults to `name'.
- `drafts-folder': Context value of `mu4e-drafts-folder'. Defaults to
\"drafts\".
- `sent-folder': Context value of `mu4e-sent-folder'. Defaults to \"sent\".
- `trash-folder': Context value of `mu4e-trash-folder'. Defaults to \"trash\".
- `refile-folder': Context value of `mu4e-refile-folder'. Defaults to
\"refile\".
- `no-trash-flag': If non-nil, the maildir will be added to
`mu4e-move-to-trash-patterns' so that trashing moves the message instead of flagging.
- `predicate': A function that takes a message and returns non-nil if it matches
the context. This is only used if `match-func' is not provided, in which case
the context is always matched against the message folder.
Example of a mailbox where only the sent-folder differs from the
default folders (see `make-mu4e-context' and `mu4e-context'):
(let ((gandi-smtp-vars '((smtpmail-smtp-server . \"mail.gandi.net\")
(smtpmail-stream-type . starttls)
(smtpmail-smtp-service . 587))))
(make-mu4e-context-account
:name \"personal\"
:user-mail-address \"john@doe.xyz\"
:sent-folder \"Sent\"
:vars gandi-smtp-vars)
(make-mu4e-context-account
:name \"work\"
:user-mail-address \"john@work.org\"
:sent-folder \"Sent\"
:predicate (lambda (msg)
(mu4e-message-contact-field-matches
msg '(:from :to) \"boss@work.org\"))
:vars gandi-smtp-vars))"
(cl-assert name)
(setq maildir (concat "/" (or maildir name) "/")
smtpmail-smtp-user (or smtpmail-smtp-user user-mail-address)
no-trash-flag (or no-trash-flag
(string-match (regexp-opt mu4e-no-trash-providers)
user-mail-address))
;; TODO: Seems that mu4e fails to start when no default folder is set.
;; The following setq is a workaround.
mu4e-drafts-folder (concat maildir drafts-folder)
mu4e-sent-folder (concat maildir sent-folder)
mu4e-trash-folder (concat maildir trash-folder)
mu4e-refile-folder (concat maildir refile-folder))
(when no-trash-flag
;; Exclude trash folder from all bookmarks. This is useful for mailboxes
;; which don't use the "trash" flag like Gmail.
(dolist (bookmark mu4e-bookmarks)
(setq bookmark (plist-put bookmark :query
(format "NOT maildir:\"%s\" AND %s"
mu4e-trash-folder
(plist-get bookmark :query)))))
;; If this is a Gmail context, we add the maildir to the pattern list so
;; that they can be properly trashed.
(add-to-list 'mu4e-move-to-trash-patterns (concat "^" maildir)))
(let ((context (make-mu4e-context :name name
:enter-func enter-func
:leave-func leave-func
:match-func match-func
:vars vars)))
(unless (mu4e-context-match-func context)
(setf (mu4e-context-match-func context)
`(lambda (msg)
(when msg
(or
,(when predicate
`(funcall ,predicate msg))
(string-prefix-p ,maildir (mu4e-message-field msg :maildir)))))))
(setf (mu4e-context-vars context)
(append `((user-mail-address . ,user-mail-address)
(smtpmail-smtp-user . ,smtpmail-smtp-user)
(mu4e-drafts-folder . ,mu4e-drafts-folder)
(mu4e-sent-folder . ,mu4e-sent-folder)
(mu4e-trash-folder . ,mu4e-trash-folder)
(mu4e-refile-folder . ,mu4e-refile-folder))
(mu4e-context-vars context)))
;; Required when using multiple addresses and if we don't want to
;; reply to ourselves.
(add-to-list 'mu4e-contexts context)
context))
(defun mu4e~context-ask-user (prompt)
"Let user choose some context based on its name."

View File

@ -198,8 +198,9 @@ buffers found, compose a new message and then attach the file."
(if (= (length bufs) 1)
(get-buffer (car bufs))
(let ((prompt (mu4e-format "%s" "Attach to buffer")))
(funcall mu4e-completing-read-function prompt
bufs))))
(substring-no-properties
(funcall mu4e-completing-read-function prompt
bufs)))))
;; setup a new mail composition buffer
(if (y-or-n-p "Compose new mail and attach this file? ")
(progn (mu4e-compose-new)

View File

@ -803,6 +803,7 @@ after the end of the search results."
(mu4e~headers-defun-mark-for refile)
(mu4e~headers-defun-mark-for something)
(mu4e~headers-defun-mark-for delete)
(mu4e~headers-defun-mark-for trash)
(mu4e~headers-defun-mark-for flag)
(mu4e~headers-defun-mark-for move)
(mu4e~headers-defun-mark-for read)
@ -812,26 +813,6 @@ after the end of the search results."
(mu4e~headers-defun-mark-for unread)
(mu4e~headers-defun-mark-for action)
(defvar mu4e-move-to-trash-patterns '()
"List of regexps to match for moving to trash instead of flagging them.
This is particularly useful for mailboxes that don't use the
trash flag like Gmail. See `mu4e-view-mark-for-trash'.")
(defun mu4e-headers-mark-for-trash ()
"Mark message for \"move\" to the trash folder if the message
maildir matches any regexp in `mu4e-move-to-trash-patterns'.
Otherwise mark with the \"trash\" flag."
(interactive)
(let ((msg-dir (mu4e-message-field (mu4e-message-at-point) :maildir)))
(if (not (seq-filter (lambda (re)
(string-match re msg-dir))
mu4e-move-to-trash-patterns))
(mu4e-headers-mark-and-next 'trash)
(mu4e-mark-set 'move (if (functionp mu4e-trash-folder)
(funcall mu4e-trash-folder (mu4e-message-at-point))
(mu4e-get-trash-folder (mu4e-message-at-point))))
(mu4e-headers-next))))
;;; Headers-mode and mode-map
(defvar mu4e-headers-mode-map nil

View File

@ -376,7 +376,8 @@ name. If the special shortcut 'o' (for _o_ther) is used, or if
all maildirs under `mu4e-maildir'."
(let ((prompt (mu4e-format "%s" prompt)))
(if (not (mu4e-maildir-shortcuts))
(funcall mu4e-completing-read-function prompt (mu4e-get-maildirs))
(substring-no-properties
(funcall mu4e-completing-read-function prompt (mu4e-get-maildirs)))
(let* ((mlist (append (mu4e-maildir-shortcuts)
'((:maildir "ther" :key ?o))))
(fnames
@ -391,8 +392,9 @@ all maildirs under `mu4e-maildir'."
mlist ", "))
(kar (read-char (concat prompt fnames))))
(if (member kar '(?/ ?o)) ;; user chose 'other'?
(funcall mu4e-completing-read-function prompt
(mu4e-get-maildirs) nil nil "/")
(substring-no-properties
(funcall mu4e-completing-read-function prompt
(mu4e-get-maildirs) nil nil "/"))
(or (plist-get
(cl-find-if (lambda (item) (= kar (plist-get item :key)))
(mu4e-maildir-shortcuts)) :maildir)

View File

@ -1615,7 +1615,6 @@ list."
(mu4e~view-defun-mark-for move)
(mu4e~view-defun-mark-for refile)
(mu4e~view-defun-mark-for trash)
(mu4e~view-defun-mark-for delete)
(mu4e~view-defun-mark-for flag)
(mu4e~view-defun-mark-for unflag)
@ -1623,6 +1622,7 @@ list."
(mu4e~view-defun-mark-for something)
(mu4e~view-defun-mark-for read)
(mu4e~view-defun-mark-for unread)
(mu4e~view-defun-mark-for trash)
(mu4e~view-defun-mark-for untrash)
(defun mu4e-view-marked-execute ()

View File

@ -2350,17 +2350,6 @@ Some mailboxes behave differently however and they don't interpret the
trash flag. In cases like Gmail, the message must be @emph{moved} to
the trash folder and the trash flag must not be used.
@code{mu4e} has provisions for non-standard mailboxes: if a message
maildir matches a regular expression in
@code{mu4e-move-to-trash-patterns} then the message is moved instead of
being flagged. When a context is created with
@code{make-mu4e-context-account} (see @ref{Account setup helper}), the
pattern is automatically added for you.
This should work fine for Gmail and similar mailboxes. Note that in the
case of Gmail, you might have to configure your mailbox ``expunge''
settings.
@node Leaving the headers buffer
@section Leaving the headers buffer
@ -2518,7 +2507,6 @@ example:
* Context policies::How to determine the current context
* Contexts and special folders::Using context variables to determine them
* Contexts example::How to define contexts
* Account setup helper::Context creation with reasonable defaults
@end menu
It can be useful to switch between different sets of settings in
@ -2729,55 +2717,6 @@ no context matches (or if you always want to be asked).
and commas and note the '.' between variable name and its value.
@end itemize
@node Account setup helper
@section Account setup helper
Contexts can be cumbersome to set up. Thankfully @code{mu4e} provides
a helper function @code{make-mu4e-context-account} to easily get
started. The function helps initializing the context plus a couple of
variables with reasonable defaults. Everything should work out of the
box in most cases.
A short example for two contexts:
@lisp
(let ((gandi-smtp-vars '((smtpmail-smtp-server . "mail.gandi.net")
(smtpmail-stream-type . starttls)
(smtpmail-smtp-service . 587))))
(make-mu4e-context-account
:name "personal"
:user-mail-address "john@@doe.xyz"
:sent-folder "Sent"
:vars gandi-smtp-vars)
(make-mu4e-context-account
:name "work"
:user-mail-address "john@@work.org"
:sent-folder "Sent"
:predicate (lambda (msg)
(mu4e-message-contact-field-matches
msg '(:from :to) "boss@@work.org"))
:vars gandi-smtp-vars))
@end lisp
A couple of things to note:
@itemize
@item Only the @code{name} slot is mandatory.
@item The maildir default to the context name.
@item Folders only need to be given a name, not a relative path.
They will be automatically stored under the maildir.
@item When the @code{match-func} is not provided, the context is matched
against @code{predicate} if provided or the maildir of the current
message otherwise.
@item If the e-mail address for some account is not already known to @t{mu}, you
should probably @t{mu} about it with the @t{--my-address} parameter to
@t{mu init}.
@end itemize
If the context created by @code{make-mu4e-context-account} is not
enough, you can display the generated context with e.g. @code{M-x
describe-variable mu4e-contexts} and tweak the result as needed.
@node Dynamic folders
@chapter Dynamic folders