Setting the right account to compose messages

85 views
Skip to first unread message

Charles-H. Schulz

unread,
May 4, 2015, 2:35:05 AM5/4/15
to mu-di...@googlegroups.com
Hello,

As a follow up to this thread (1) I started to investigate this function which is listed in the doc in order to have mu4e enable to compose emails based on the available accounts:

(defun my-mu4e-set-account ()
  "Set the account for composing a message."
  (let* ((account
          (if mu4e-compose-parent-message
              (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
                (string-match "/\\(.*?\\)/" maildir)
                (match-string 1 maildir))
            (completing-read (format "Compose with account: (%s) "
                                     (mapconcat #'(lambda (var) (car var))
                                                my-mu4e-account-alist "/"))
                             (mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
                             nil t nil nil (caar my-mu4e-account-alist))))
         (account-vars (cdr (assoc account my-mu4e-account-alist))))
    (if account-vars
        (mapc #'(lambda (var)
                  (set (car var) (cadr var)))
              account-vars)
      (error "No email account found"))))

Unfortunately I am not that familiar with elisp. I started to tinker with some of the variables of the function, esp. in this way:

    (account-vars (cdr (assoc account 'my-mu4e-account-alist))))
  (if account-vars
      (mapc #'(lambda (var)
                (set (car var) (cadr var)))
            account-vars)
    (error "No email account found"))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)

The error message that I get is different. I get a "Wrong number of arguments: mapconcat, 2" message. I get that I added a ' infront of the last vmy-mu4e-account-alist; but I do not understand what else I could do to make this function work. Thoughts?

Thanks,
Charles.

Gour

unread,
May 5, 2015, 2:10:56 AM5/5/15
to mu-di...@googlegroups.com

Charles-H. Schulz <charles....@gmail.com> writes:

> but I do not understand what else I could do to make this function
> work. Thoughts?

I'm not familiar-enough with Elisp to debug it and therefore I simply did
copy&paste from some blog post.

Here is my version which does work:

;-Composing-Email----------------------------------
; Reset global C-x m to mu4e variant that will prompt for specifc account
(global-set-key (kbd "C-x m") 'mu4e-compose-new)
;; Select the correct account based on email message and prompt for which
;; account to use when composing a new message
(defun my-mu4e-set-account ()
"Set the account for composing a message."
(let* ((account
(if mu4e-compose-parent-message
(let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
(string-match "/\\(.*?\\)/" maildir)
(match-string 1 maildir))
(completing-read (format "Compose with account: (%s) "
(mapconcat #'(lambda (var) (car var)) my-mu4e-account-alist "/"))
(mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
nil t nil nil (caar my-mu4e-account-alist))))
(account-vars (cdr (assoc account my-mu4e-account-alist))))
(if account-vars
(mapc #'(lambda (var)
(set (car var) (cadr var)))
account-vars)
(error "No email account found"))))

(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)

;;
;;msmtp stuff
;;

;; we need to set send-mail-funtion
(setq send-mail-function 'sendmail-send-it)
(setq message-send-mail-function 'message-send-mail-with-sendmail)
;; we substitute sendmail with msmtp
(setq sendmail-program "/usr/bin/msmtp"
mail-specify-envelope-from t
mail-envelope-from 'header)

;; Choose account label to feed msmtp -a option based on From header in Message buffer;
;; This function must be added to message-send-mail-hook for on-the-fly change of From address
;; before sending message since message-send-mail-hook is processed right before sending message.
(defun choose-msmtp-account ()
(if (message-mail-p)
(save-excursion
(let* ((from
(save-restriction
(message-narrow-to-headers)
(message-fetch-field "from")))
(account
(cond
((string-match "go...@atmarama.net" from)"gour")
((string-match "mygm...@gmail.com" from)"mygmailid")
)
)
)
(setq message-sendmail-extra-arguments (list '"-a" account))
)
)
)
)

(setq message-sendmail-envelope-from 'header)
(add-hook 'message-send-mail-hook 'choose-msmtp-account)

; Final custom function for any other customization
(defun my-mu4e-compose-settings ()
"Set some custom variables when composing an email"
(setq fill-column 77))
(add-hook 'mu4e-compose-mode-hook 'my-mu4e-compose-settings)

You can try it and report if it works...


Sincerely,
Gour

--
The humble sages, by virtue of true knowledge, see with equal
vision a learned and gentle brāhmana, a cow, an elephant, a dog
and a dog-eater.

Charles-H. Schulz

unread,
May 6, 2015, 4:22:04 AM5/6/15
to mu-di...@googlegroups.com
Hello Gour,

2015-05-05 8:09 GMT+02:00 Gour <go...@atmarama.net>:

Charles-H. Schulz <charles....@gmail.com> writes:

> but I do not understand what else I could do to make this function
> work. Thoughts?

I'm not familiar-enough with Elisp to debug it and therefore I simply did
copy&paste from some blog post.

Here is my version which does work:
[......snipped some code]



You can try it and report if it works...

I tried and it still does not work, or rather partially works just like before. I can reply to emails from one account but not more. The error message is the same "Wrong type argument, sequencep". I am investigating the problem; it seems that there's a function (likely the one that handle the selection of the account for composing messages) that expects some variable but ultimately does not get it. The Messages buffer on emacs may not be enough and I may have to use the elisp debugger.

Ideas and thoughts welcome.

Thanks,

Charles.

Charles-H. Schulz

unread,
May 7, 2015, 5:35:38 AM5/7/15
to mu-di...@googlegroups.com
Hello again,

I've been trying to debug the function used to compose messages. I got this output when running M-x eval-last-sexp :

Debugger entered--Lisp error: (invalid-function (maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
  ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
  eval(((maildir (mu4e-message-field mu4e-compose-parent-message :maildir))) nil)
eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp t nil)
  execute-extended-command(nil)
  call-interactively(execute-extended-command nil nil)
  recursive-edit()

I'm not so sure about what this means: is "maildir" not a known variable or am I looking in the wrong direction?

Best,

Charles.
 

Thanks,

Charles.

Gour

unread,
May 8, 2015, 4:31:48 AM5/8/15
to mu-di...@googlegroups.com

Charles-H. Schulz <charles....@gmail.com> writes:

> I'm not so sure about what this means: is "maildir" not a known variable or
> am I looking in the wrong direction?

Hmm...can you show us how does you Maildir hierarchy look like?

Mine is:

~/Maildir

...

├── archive_2014
│   ├── cur
│   ├── new
│   └── tmp
├── drafts
│   ├── cur
│   ├── new
│   └── tmp
├── gmailid
│   ├── drafts
│   ├── inbox
│   ├── queue
│   ├── sent
│   └── trash
├── gour
│   ├── drafts
│   ├── inbox
│   ├── lists
│   ├── queue
│   ├── sent
│   ├── spam
│   └── trash
├── inbox
│   ├── cur
│   ├── new
│   └── tmp
├── queue
│   ├── cur
│   ├── new
│   └── tmp
├── sent
│   ├── cur
│   ├── new
│   └── tmp
├── spam
│   ├── cur
│   ├── new
│   └── tmp
├── trash
│   ├── cur
│   ├── new
│   └── tmp
└── unsure
├── cur
├── new
└── tmp

Sincerely,
Gour

--
As a strong wind sweeps away a boat on the water,
even one of the roaming senses on which the mind
focuses can carry away a man's intelligence.

Charles-H. Schulz

unread,
May 8, 2015, 2:14:57 PM5/8/15
to mu-di...@googlegroups.com
Hello Gour,

2015-05-08 10:31 GMT+02:00 Gour <go...@atmarama.net>:

Charles-H. Schulz <charles....@gmail.com> writes:

> I'm not so sure about what this means: is "maildir" not a known variable or
> am I looking in the wrong direction?

Hmm...can you show us how does you Maildir hierarchy look like?


Sure, there it is :
/home/chs/Maildir/
├── Adocentyn
│   ├── Archive
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Brouillons
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Calendar
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Configuration
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Contacts
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Corbeille
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Drafts
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Envoy&AOk-s
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Files
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Journal
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Notes
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Other Users.melissa.Calendar
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Other Users.melissa.Files
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Queue
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Sent
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Spam
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Tasks
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Trash
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   └── emacs divers
│       ├── cur
│       ├── new
│       └── tmp
├── GMX
│   ├── Confidential
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Entw&APw-rfe
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Gel&APY-scht
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Gel&APY-scht.Neuer ordner
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Gesendet
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── OUTBOX
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Restore
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   └── Spamverdacht
│       ├── cur
│       ├── new
│       └── tmp
├── Laposte
│   ├── Chats
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Contacts
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Dossier personnel
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Drafts
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Emailed Contacts
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Junk
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Sent
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   └── Trash
│       ├── cur
│       ├── new
│       └── tmp
├── TDF
│   ├── INBOX
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Archive
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Brouillons
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Corbeille
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Donations
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Drafts
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Envoy&AOk-s
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.INBOX.Drafts
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.INBOX.Junk
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.INBOX.Sent
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.INBOX.Trash
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Junk
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.MC
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Queue
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── INBOX.Sent
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   └── INBOX.Trash

│       ├── cur
│       ├── new
│       └── tmp
├── drafts
│   ├── cur
│   ├── new
│   └── tmp
├── sent

│   ├── cur
│   ├── new
│   └── tmp
└── trash
    ├── cur
    ├── new
    └── tmp


Best,

Charles.

Charles-H. Schulz

unread,
May 8, 2015, 2:32:31 PM5/8/15
to mu-di...@googlegroups.com
Hello again,

2015-05-08 20:14 GMT+02:00 Charles-H. Schulz <charles....@gmail.com>:
Hello Gour,

2015-05-08 10:31 GMT+02:00 Gour <go...@atmarama.net>:

Charles-H. Schulz <charles....@gmail.com> writes:

> I'm not so sure about what this means: is "maildir" not a known variable or
> am I looking in the wrong direction?

Hmm...can you show us how does you Maildir hierarchy look like?


Sure, there it is :
/home/chs/Maildir/

[.... SNIPPED A LOT OF STUFF....]

One useful additional information on this. Aside the fact that we're celebrating Emacs' 30birthday, I've debugged the init file a bit more. Now the exact and most accurate error message I get so far when evaluating the function in question is "void function account".

This seems to suggest (1) that the use of the function "account" has not been defined anywhere in emacs, and at least not in the init file. It does not make too much sense to me (why did no one here encounter this problem before?) and my hunch would be that it alludes to some very related problem; in short it suggests that the function used to define what account to use when composing a message relies on something which is not defined; and that in turn my mu4e-account-alist is not really being used anyway. Odd.

Hope this helps,

 

Joost Kremers

unread,
May 8, 2015, 6:02:57 PM5/8/15
to mu-di...@googlegroups.com


On Friday, May 8, 2015 at 8:32:31 PM UTC+2, Charles-H. Schulz wrote:
One useful additional information on this. Aside the fact that we're celebrating Emacs' 30birthday, I've debugged the init file a bit more. Now the exact and most accurate error message I get so far when evaluating the function in question is "void function account".

This seems to suggest (1) that the use of the function "account" has not been defined anywhere in emacs, and at least not in the init file.

In principle, yes, but it's unlikely that a function would simply be called `account'. Normally, one would expect some package prefix. Moreover, in the code that you've posted before, `account' is not supposed to be a function. Instead, it's a (local) variable.

So the fact that you get a `void function` error suggests suggests that you've misplaced an opening parenthesis somewhere. Not necessarily in the function `my-mu4e-set-account', BTW, it might be in the code preceding that function in your init file.

(Actually, the other error messages you posted earlier in the thread point in the same direction: Emacs is interpreting something that should be a variable or an expression as if it were a function call, which is usually the result of a misplaced parenthesis.)

It does not make too much sense to me (why did no one here encounter this problem before?)

I suspect because you changed something that broke the code... ;-)
 
in short it suggests that [...] that in turn my mu4e-account-alist is not really being used anyway. Odd.

Well, you did mention that you put a quote (') before that variable name somewhere, which may very well have that effect.

I would suggest you copy the code given in the manual, paste in in your init file and do not change anything. If you ~/Maildir is organised as described and you defined `my-mu4e-account-alist' correctly, the function works and there shouldn't be any need to change anything. If your needs are slightly different, then post here describing what you need and I'm sure there'll be someone willing to help you make the necessary changes.

HTH

Joost


Charles-H. Schulz

unread,
May 13, 2015, 3:23:56 AM5/13/15
to mu-di...@googlegroups.com

Hello Joost, Gour,

Thanks a lot for the suggestion. It seems I fixed it and you pointed me to the right track. I had indeed added a ' to each account in my account list (the one defined in mu4e-my-account-alist) a few moths ago as I was getting error messages when ealing the defvar section at that time.

Now I am happy to report that the account selection works properly in repling to and composing mails. I still have an error 78 on my msmtprc but I am working on it now.

Thanks a lot!!!

Charles.

Reply all
Reply to author
Forward
0 new messages