# mutt changes from/to header => hell (HELP ME!)

## BlinkEye

i've been trying for two days now and i can't get it to work. mutt changes my from/to headers occasionaly or not the way i want it to. 

i use a imap server (courier-imap), several maildirs, postfix as a MTA and fetchmail to get my mail from other accounts.

this is my last .muttrc i tried out:

```
set imap_authenticators="plain:login"

set mbox_type=Maildir

set folder=imaps://*mydomain*:993/INBOX

set mbox=imaps://*mydomain*/INBOX

mailboxes =.box1 =.box2

set imap_user="BlinkEye"

set hidden_host=yes

set record="=.Sent"

set realname="Blink Eye"

set from="blinkeye@*mydomain*"

alternates (root|postmaster)@*mydomain*

set use_from

set reverse_name

unset reverse_realname

folder-hook .box2 my_hdr From: somename@*otherdomain* (some name)
```

i now send a mail from somename@*otherdomain* to blinkeye@*mydomain* and reply the mail mutt wants to send the mail from somename@*otherdomain* to somename@*otherdomain*! WTF?

here's the header of such a message:

```
Return-Path: somename@*otherdomain*

X-Original-To: blinkeye@*mydomain*

Delivered-To: blinkeye@*mydomain*

/* snip ------- (received headers) ------- */

Date: Wed, 27 Oct 2004 14:14:11 +0200

From: Other User <somename@*otherdomain*>

To: blinkeye@*mydomain*

Subject: headers test (from/to address)

Message-ID: <20041027121411.GA28435@blabla>

Mime-Version: 1.0

Content-Type: text/plain; charset=us-ascii

Content-Disposition: inline

User-Agent: Mutt/1.5.6i
```

----------

## ozonator

One thought:  since you have that folder-hook there for mailboxes that match '.box2' (remember, the '.' will match any character, since that's an expression), once you visit a mailbox that matches '.box2', that 'from' header will stick.  To avoid that, you can do it with something like this, earlier in the config:

```
folder-hook . "unmy_hdr *"
```

One other thought, that might be more appropriate for your situation:  with alternates set correctly, you likely don't need to re-set the From header with a folder-hook.  Here's what I'm thinking.  If I'm reading your config correctly, and my hunch about it is correct, you're getting mail addressed to both somename@*otherdomain* and somename@*mydomain*, and having fetchmail to put the otherdomain stuff in .box2, maybe the rest in .box1.  And, of course, you want the from address set appropriately, depending on the address to whom the mail was originally sent -- in other words, mail to otherdomain addresses (in .box2) should get a reply from an otherdomain address, and mail to mydomain should get a reply from the corresponding mydomain address.  So, one thing you can do is drop the folder-hook altogether, and try this:

```
alternates .*@.*\.mydomain\..* ^somename@.*otherdomain\..*
```

Adjust the regexp as you wish, of course, but make sure it matches the addresses you use, i.e., at which you receive mail.  For the expression there, this means if I mail you at blinkeye@mydomain.org, and you hit reply, mutt will set the from to blinkeye@mydomain.org (and because I used '.*' to stand for any username at mydomain, if you get mail at blahblah@mydomain.org, you'll reply with blahblah@mydomain.org, too).  And, if you get mail at somename@otherdomain.com, your reply will show a from of somename@otherdomain.com.  In short, with alternates set correctly, mutt will handle your 'from' headers appropriately, without the need for hooks that modify 'from'.  Hope that's clear enough to help.   :Smile: 

----------

## BlinkEye

thank's a lot for your detailed answer. i forgot to mentioned that i don't want mutt to change my headers at all, if i get mail to webmaster@*mydomain* i want the mail to be sent from webmaster@*mydomian* -  i'm excactly trying to find an alternate solution like yours. i tried yours, and it didn't work - the problem is i don't know anything about regex - and i don't know if the line provided from you is correct (syntax or semantic). i still don't know if the alternate list needs to be in quotes, double-quotes or simply an expression!

for simplification, let's say *mydomain* is hotmail.com (whith regular admin users like: sysadmin@hotmail.com, webmaster@hotmail.com etc.) and my second domain (which isn't mine) is aol.com, my third would be aol.org etc.

[EDIT] of course i removed any hook command [/EDIT]

----------

## BlinkEye

oukei, i glanced at regex shortly. i'm really thinking that mutt-1.5.6-r3 has a bug. a SIMPLE regex like

```
set from="postmaster@hotmail.com"

alternates (webmaster|admin|root|cerberos|postmaster)@blinkeye.ch
```

changes the header of a mail sent to webmaster@hotmail.com EVERY time to postmaster@hotmail.com, no matter if i use quotes or double quotes for the alternate command. if i remove the "set from=..." entry i simply takes the last regex possibility, i.e. postmaster@hotmail.com. this IS REALLY annoying.

again, my .muttrc file:

```
set from="postmaster@hotmail.com"        

alternates (webmaster|admin|root|postmaster)@hotmail.com

set hidden_host=yes
```

----------

## ozonator

This all works for me here, with 1.5.6-r4.  Just looked at my own configs here, and noticed one thing that might do the trick:

```
set reverse_name
```

That's unset by default, and affects how mutt makes the 'from' line.  According to the man page, "If this variable is set, the default From:  line of the reply messages is built using the address where you received the messages you are replying to."

----------

## BlinkEye

thanks, and now i'm back to the beginning. it works twice but not three o more times:

```
Date: Thu, 28 Oct 2004 20:53:31 +0200

From: <webmaster@hotmail.com>

To: Blink Eye <blinkeye@aol.com>

Subject: Re: HEADER 12345

User-Agent: Mutt/1.5.6i

tsss

On 20:44 Thu 28 Oct     , Glosi wrote:

> Date: Thu, 28 Oct 2004 20:44:53 +0200

> From: <webmaster@hotmail.com>

> To: Blink Eye blinkeye@aol.com

> Subject: Re: HEADER 12345

> User-Agent: Mutt/1.5.6i

>

> tss

>

> On 18:19 Thu 28 Oct, Blink Eye wrote:

> > Date: Thu, 28 Oct 2004 18:19:43 +0200

> > From: Blink Eye <blinkeye@aol.com>

> > To: webmaster@hotmail.com

> > Subject: HEADER 12345

> > User-Agent: Mutt/1.5.6i

> >

> > ts

> >

```

you see, the third reply is still wrong (as is the forth etc)! why the hell isn't that working?

----------

## ozonator

$alternates must be set to include all the addresses at which you receive mail.  If your alternates is the same as it was two posts ago, i.e.,

 *BlinkEye wrote:*   

> 
> 
> ```
> alternates (webmaster|admin|root|postmaster)@hotmail.com
> ```
> ...

 

then for that to work with the example you just gave, it also must include the blinkeye@aol.com address, i.e. make this your alternates:

```
alternates ^((((web|post)master)|admin)|root)@hotmail.com$ , ^blinkeye@aol.com$
```

Again, the key for mutt setting the correct 'from' line is that $alternates includes all your addresses -- if an address doesn't match an expression there, mutt won't set the 'from' correctly.  If it helps while experimenting, try setting alternates very broadly (even to '.*' an expression that should match anything) and see if that works; if so, you'll know it's a matter of setting $alternates correctly.

----------

## BlinkEye

thanks a lot for your time and effort. i didn't know i have to include every mail address in alternates. the thing is - at the moment it changes the to field wrongly - i.e. it sets the To field to the same address as the From field. how can this happen?

----------

## ozonator

 *BlinkEye wrote:*   

> the thing is - at the moment it changes the to field wrongly - i.e. it sets the To field to the same address as the From field. how can this happen?

 

As far as I know, mutt uses whatever was last set as 'From'.  First when you start mutt, that's what's set in the 'from' variable (i.e., set from= ...).  Thereafter, if the 'from' changes, it will stick, i.e., after any hooks or match to an expression in $alternates.  In other words, it doesn't keep returning to whatever you set with 'set from= ...', which was a one-time configuration.

In your example from a couple of posts ago, as you noticed mutt correctly re-set the from address for the first reply:  the message was to webmaster@hotmail.com, which was in your $alternates, so the from line on the reply indicated 'From: <webmaster@hotmail.com>'.  That message, however, was to blinkeye@aol.com, which (at the time of that post, at least) was not in $alternates.  So, when replying to that one in turn, mutt just used the last known from address it knew about, i.e., webmaster@hotmail.com.  Had blinkeye@aol.com been in $alternates, the from should have changed accordingly when replying to that message.

It's a bit tricky, so I hope that helps.  It's definitely worth the effort, since it makes handling mail to multiple addresses wonderfully easy.

----------

## BlinkEye

your example makes sense, but it doesn't work for me. the third reply sends the mail back to himself or the same way it arrived. i'm completely lost, i've now tried for days but the trial and error doesn't work. i began from 0 and built several configs, i copied over 10 but they have all the same problem - third/forth etc. reply doesn't work. 

is there any chance that you could try this out and have a look how mutt behaves with your config? could you maybe post or PM me your config file? or would it be easier to create a new for me? i don't see why this is so difficult, i have 2 domain names, one with several accounts (i.e. (root|admin|...)@hotmail.com and one user@aol.com).

i've lost the patience   :Twisted Evil: 

----------

## ozonator

Time for a sample config, then, since your setup seems similar enough to mine.  I have two of my own domains (mydomain.ca and mydomainext.org), plus a pair of e-mail addresses from my ISP, my old university addresses (which forward to me), and gmail, hotmail, and yahoo addresses.  Those that have variants on my name are those with 'first', 'initial', and 'last'. Here, then, are the relevant bits of my config, i.e., the parts that tell mutt how to do the From header:

```
alternates .*@mydomain(ext)?\.(org|ca)$ , ^(initial)?last@isp\.com$ , \

  ^((first(\.|_))|initial)last@.*(u?toronto\.(ca|edu)|(gmail|(hotmail|yahoo))\.(ca|com))$

set hostname="mydomain.ca"

unset use_domain

set realname="First Last"

set from="me@mydomain.ca"

set use_from

set reverse_name

unset reverse_realname
```

Now, you mentioned that you have 2 domain names, one with several accounts (i.e. (root|admin|...)@hotmail.com, and one user@aol.com).  Let  me assume, then, that you've got hotmail.com and aol.com; your primary (default) address I'll assume is blinkeye@aol.com.  Following that, you could try this config:

```
alternates .*@hotmail\.com$ , ^blinkeye@aol\.com$

set hostname="hotmail.com"

unset use_domain

set realname="Blink Eye"

set from="blinkeye@aol.com"

set use_from

set reverse_name

unset reverse_realname
```

With this config, $alternates is set more broadly than it likely needs to be -- it will match any incoming address @hotmail.com -- but since we're assuming they're your domains, that should be fine (i.e., given that you receive only your mail and aren't worried about impersonating someone else at either of your domains).  To make that more precise, it would be something like this:

```
alternates (((web|post)master|admin)|root)@hotmail\.com$ , ^blinkeye@aol\.com$
```

Given that this works for me, I hope it will work for you, assuming you have no other hooks or configuration settings that might affect how mutt makes the 'from' line.  If it still gives you trouble, PM me your whole config, and we can see if there's anything obvious that can be fixed.  Best of luck!

----------

## BlinkEye

i've sent you a pm with my (true) config and the header of the mail i sent across the web 3 times. it works twice, but the third time - i.e. the second reply - switches suddenly the headers (To: should be From: and vice versa). i used the following:

```

```

.muttrc: 

```
 pts/9 # cat .muttrc

set mbox_type=Maildir

set folder=/home/*myusername*/.maildir

set mbox=/home/*myusername*/.maildir

mailboxes =.Hotmail =.AOL 

alternates .*@hotmail\.com$ , ^blinkeye@aol\.com$

set hostname="mydomain"

unset use_domain

set realname="bla bla"

set from="username@hotmail.com"

set use_from

set reverse_name

unset reverse_realname
```

does anyone have an idea? it can't be i'm the only one who's suffering this behaviour!

----------

