On Tue, Nov 02, 2010 at 02:36:09PM +0000, Adam Spiers wrote:
> Hi all,
> I'm seeing some very strange behaviour regarding the selection of a
> default account with the following config file:
> When I run msmtp in 'pretend' mode, it all looks good:
> However, when I remove the '-P' flag, it goes horribly wrong:
> $ msmtp -d --read-envelope-from -C ~/.msmtprc test@... < mail.txt
> ignoring system configuration file /etc/msmtprc: No such file or directory
> loaded user configuration file /home/adam/.msmtprc
> using account common from /home/adam/.msmtprc
> reading recipients from the command line
> msmtp: cannot locate host dummy: Name or service not known
> msmtp: could not send mail (account common from /home/adam/.msmtprc)
> This must be a bug, right? For some reason it looks like it's
> defaulting to the first account in the list, rather than the one
> called 'default'.
Upon further investigation, it seems that if neither -P nor -a are
specified, the default account selected is the first one in the config
file. This got me suspicious, so I started reading the manual page
more closely and found the following snippets:
Read the envelope from address from the From header of the
Set the envelope-from address. It is only used when
auto_from is off.
If no account was chosen yet (with --account or --host),
this option will choose the first account that has the given
envelope-from address (set with the from command). If no
such account is found, "default" is used.
The user can choose which account to use in one of three ways:
--from=address or --read-envelope-from
Choose the first account from the system or user
configuration file that has a matching envelope-from address
as specified by a from command. This works only when neither
--account nor --host is used.
The envelope_from=yes option lets Mutt use the -f option of
msmtp. Therefore msmtp chooses the first account that matches the
from address you@....
So I'm guessing that msmtp extracted the address from the From:
header, and then looks for the first account which has a 'from' value
matching that address.
However, this does not explain why the behaviour is different in
pretend mode; I strongly suspect that's a bug.
Additionally, I would suggest that in debug mode, the output should be
altered to include an explanation of the account selection process.