[PATCH] emacs: Allow user to choose "From" address when composing a new message.

Carl Worth cworth at cworth.org
Tue May 24 15:02:01 PDT 2011


In order to select a From address, the user simply presses M instead of
m to begin composing a message. By default the list of names/addresses
to be used during completion will be automatically generated by the
settings in the notmuch configuration file. The user can customize
the notmuch-identities variable to provide an alternate list.
---
 emacs/notmuch-hello.el |    3 ++-
 emacs/notmuch-mua.el   |   40 ++++++++++++++++++++++++++++++++++++++--
 emacs/notmuch.el       |    3 ++-
 3 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index e58dd24..5f3bcc8 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -298,7 +298,8 @@ should be. Returns a cons cell `(tags-per-line width)'."
     (define-key map "=" 'notmuch-hello-update)
     (define-key map "G" 'notmuch-hello-poll-and-update)
     (define-key map (kbd "<C-tab>") 'widget-backward)
-    (define-key map "m" 'notmuch-mua-mail)
+    (define-key map "m" 'notmuch-mua-new-mail)
+    (define-key map "M" 'notmuch-mua-new-mail-prompt-for-sender)
     (define-key map "s" 'notmuch-hello-goto-search)
     map)
   "Keymap for \"notmuch hello\" buffers.")
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index dc7b386..76bcba4 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -118,8 +118,7 @@ list."
 
 (defun notmuch-mua-mail (&optional to subject other-headers continue
 				   switch-function yank-action send-actions)
-  "Invoke the notmuch mail composition window."
-  (interactive)
+  "Invoke the notmuch mail composition window with optional headers."
 
   (when notmuch-mua-user-agent-function
     (let ((user-agent (funcall notmuch-mua-user-agent-function)))
@@ -138,6 +137,43 @@ list."
 
   (message-goto-to))
 
+(defcustom notmuch-identities nil
+  "Identities that can be used as the From: address when composing a new message.
+
+If this variable is left unset, then a list will be constructed from the
+name and addresses configured in the notmuch configuration file."
+  :group 'notmuch
+  :type '(repeat string))
+
+(defun notmuch-mua-sender-collection ()
+  (if notmuch-identities
+      notmuch-identities
+    (mapcar (lambda (address)
+	      (concat (notmuch-user-name) " <" address ">"))
+	    (cons (notmuch-user-primary-email) (notmuch-user-other-email)))))
+
+(defun notmuch-mua-new-mail-from (&optional sender)
+  (if sender
+      (notmuch-mua-mail nil nil (list (cons 'from sender)))
+    (notmuch-mua-mail)))
+
+(defvar notmuch-mua-sender-history nil)
+
+(defun notmuch-mua-new-mail (&optional prompt-for-sender)
+  "Begin composing a new email with notmuch."
+  (interactive "P")
+  (if prompt-for-sender
+      (let* ((collection (notmuch-mua-sender-collection))
+	     (sender (ido-completing-read "Send mail From: " collection
+					  nil 'confirm nil 'notmuch-mua-sender-history (car collection))))
+	(notmuch-mua-new-mail-from sender))
+    (notmuch-mua-mail)))
+
+(defun notmuch-mua-new-mail-prompt-for-sender ()
+  "Begin composing a new email with notmuch, and prompt for the From: address."
+  (interactive)
+  (notmuch-mua-new-mail t))
+
 (defun notmuch-mua-send-and-exit (&optional arg)
   (interactive "P")
   (message-send-and-exit arg))
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 64f72a0..0c1c8d0 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -204,7 +204,8 @@ For a mouse binding, return nil."
     (define-key map "p" 'notmuch-search-previous-thread)
     (define-key map "n" 'notmuch-search-next-thread)
     (define-key map "r" 'notmuch-search-reply-to-thread)
-    (define-key map "m" 'notmuch-mua-mail)
+    (define-key map "m" 'notmuch-mua-new-mail)
+    (define-key map "M" 'notmuch-mua-new-mail-prompt-for-sender)
     (define-key map "s" 'notmuch-search)
     (define-key map "o" 'notmuch-search-toggle-order)
     (define-key map "c" 'notmuch-search-stash-map)
-- 
1.7.5.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20110524/d21218ee/attachment.pgp>


More information about the notmuch mailing list