13

Unsetting mutt's configuration variables imap_user, imap_pass (and perhaps preconnect, imap_authenticators as well) via an account-hook . "unset ... " call, seems to be common practice, if not a necessity, for handling multiple imap accounts (see Managing multiple IMAP/POP accounts (OPTIONAL), Mutt imap multiple account, mutt: gmail IMAP unresponsive, an account-hook related configuration file in funtoo.org).

Currently I handle only one account via IMAP. Plans for multiple account handling lead me to follow the instructions found in the last of the above mentioned links (someone's example of mutt configuration). Therefore, in a similar way, I used the following:

account-hook . 'unset imap_user; unset imap_pass; unset tunnel'
account-hook 'imaps://mail.domain.net:993/INBOX/' "set [email protected]"
account-hook 'imaps://mail.domain.net:993/INBOX/' "set imap_pass=${my_password}"

This is stored in a separate file (named account_hooks) and sourced from inside muttrc. For reasons I don't understand, mutt keeps asking for the username and the password. However, if the variables imap_user and imap_pass are set directly in muttrc, e.g.

set my_password="`gpg --decrypt ~/.mutt/password.gpg`"
set imap_authenticators='login'
set imap_login = '[email protected]'
set imap_user = '[email protected]'
set imap_pass ="${my_password}"

everything works fine. The account_hooks file is the first one sourced and no other account-hook . "unset ..." call(s) exist(s) anywhere else.

Update, The folder-hooks file is (and was, I think) as follows:

#--------------------------------------------------------------------------
# Folders and hooks
#--------------------------------------------------------------------------
# folder-hook 'imaps://UserName%[email protected]:993/'
set folder = "~/.maildir"       # IMAP: local, using offlineimap -- folder="imaps://mail.domain.net:993/INBOX/"
source ~/.mutt/mailboxes        # source automatically generated mailboxes
set spoolfile = "+INBOX"        # spoolfile='imaps://mail.domain.net:993/'
set postponed = "+INBOX/Drafts"

# Sending -----------------------------------------------------------------
set smtp_url="smtp://[email protected]@mail.domain.net:587/"
set smtp_pass=${my_password}
set record = "+INBOX/Sent"
set copy=yes

# Index format ----------------------------------------------------------------
folder-hook *[sS]ent* 'set sort=threads'
folder-hook *[sS]ent* 'set sort_browser=reverse-date'
folder-hook *[sS]ent* 'set sort_aux=reverse-last-date-received'
folder-hook *[sS]ent* 'set index_format="%2C | %Z [%d] %-30.30t (%-4.4c) %s"'
folder-hook ! *[sS]ent* 'set index_format="%2C | %Z [%d] %-30.30F (%-4.4c) %s"':

Why does, the separate file account_hooks, not feed properly the variables of interest in this case (i.e. imap_user and imap_pass)?

Nikos Alexandris
  • 1,460
  • 2
  • 18
  • 41

1 Answers1

3

You can set username and password directly, but it doesn't work when you use an account-hook, so probably the account-hook doesn't work.

An account-hook consists of a regexp for the mailboxes, and those commands which should be executed if a mailbox matches the regexp.

Since the commands (set imap_user, set imap_pass) are not executed, we can assume that the regexp didn't match your mailboxes.

You are using 'imaps://mail.domain.net:993/INBOX/' which is very specific. Probably your mailboxes are named slightly different.

Is this the only mail account from mail.domain.net you are using? If so, reducing the regexp to 'mail.domain.net' should be enough to match your mailboxes.

account-hook . 'unset imap_user; unset imap_pass; unset tunnel
account-hook mail.domain.net "set [email protected]"
account-hook mail.domain.net "set imap_pass=${my_password}"
Nikos Alexandris
  • 1,460
  • 2
  • 18
  • 41
  • I came back to work this out. Most likely your interpretation is right. I'll, hopefully, verify this soon. Thank you. – Nikos Alexandris Feb 16 '16 at 21:45
  • If both `set imap_user` and `set imap_pass` are not executed, why am I asked for a password for `Password for [email protected]:` then? Exactly the user-id and domain set for `account-hook` in the `account-hooks` file? – Nikos Alexandris Feb 17 '16 at 09:02
  • I got it fixed! I think I was missing to provide the `${my_password}` correctly for the `smtp_pass` variable. It was `${password}`... :-/ – Nikos Alexandris Feb 17 '16 at 09:11
  • Regarding my last comment, after multiple experimental edits, it seems that I wrongly used `"${password}"`, instead of `"${my_password}"`. The `account-hooks` file seems to work for at least 2 acounts, now, properly. And another third one for which it get's stuck to another issue, namely an `SSL failed: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unsupported protocol`. But that is not directly related to the Question aksed and answered here. So, excluding "typos", the problem, initially, was indeed the `regexp` not matching the mailbox(es) in question. – Nikos Alexandris Feb 17 '16 at 09:17