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 imap_user=UserName@domain.net"
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 = 'UserName@domain.net'
set imap_user = 'UserName@domain.net'
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%domain.net@mail.domain.net: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://UserName@domain.net@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)?

6
  • If you're still interested in answer I would like to see the folder-hook lines you have in your .muttrc. Then I can draw some conclusions and offer a complete solution. Oct 22, 2014 at 11:10
  • 1
    @brauner, so late and busy, apologies. I haven't found the time to experiment more with this, since I didn't need it. I have to trace back the folder-hook settings I used at the time, I guess I have'm as a backup. Mar 26, 2015 at 14:47
  • can you post a debug file from 'mutt -d 5' ?
    – asdmin
    Apr 17, 2015 at 7:47
  • @asdmin for the moment, the response is DEBUG was not defined during compilation. Ignored.. Once I'll find some time, I'll recompile and post back. Apr 17, 2015 at 7:57
  • @kyrias thnx for edits Apr 20, 2015 at 15:37

1 Answer 1

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 imap_user=UserName@domain.net"
account-hook mail.domain.net "set imap_pass=${my_password}"
4
  • I came back to work this out. Most likely your interpretation is right. I'll, hopefully, verify this soon. Thank you. Feb 16, 2016 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 UserName@mail.domain.net: then? Exactly the user-id and domain set for account-hook in the account-hooks file? Feb 17, 2016 at 9:02
  • I got it fixed! I think I was missing to provide the ${my_password} correctly for the smtp_pass variable. It was ${password}... :-/ Feb 17, 2016 at 9: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. Feb 17, 2016 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.