OK, I'm having lots of issues with send-hooks recently, it seems. My new project: trying to deal with my mailing lists correctly. I have a bunch of lists, each with its own folder under =lists, to which I'm subscribed. In my ideal situation, when I send mail to any of those lists, I want my From: header to be changed to reflect the address with which I'm subscribed to that list; further, if I'm in a list-specific folder and sending mail that isn't to any other list, then I want the from address to also use the address with which I'm subscribed to the list to which the folder corresponds. If that's confusing, here's an example: I'm subscribed to this list, with mail to this list going into =lists/mutt, and to the loganalysis list, with mail to that list going into =lists/loganalysis. I'm subscribed to this list with the address <[EMAIL PROTECTED]>, and to the loganalysis list with <[EMAIL PROTECTED]>. If I'm in =lists/mutt, and I send a message to the loganalysis list, I want my From: header to be set to <loganalysis@...>, but if I send a message to anyone else from that folder, I want it set to <mutt@...>, and if I send a message to this list from any folder, I want it also set to <mutt@...>. OK, that should be fairly straightforward--except that the system default address I get also needs to be changed in all non-list folders, as well; I also have a couple of send-hooks that need to be in place in those other non-list folders, and the send-hooks that correspond to individual lists should also be visible in the non-list folders. So if I'm in my inbox, mail should come from <[EMAIL PROTECTED]>, unless it's to a list, in which case the list address should be used, or it's to exception_person1, in which case a different address entirely should be used. This means that I have to have some sort of default
folder-hook . my_hdr From: <[EMAIL PROTECTED]> in the mix, just to get the "normal" behaviour I'd want. And since I have some sendhooks of the form send-hook exception_person1 my_hdr From: <different_address> , I also have to have a default send-hook to set things back: send-hook . my_hdr <[EMAIL PROTECTED]> should appear before the other send-hooks. OK, but to get the behaviour I want in terms of default address in a given list folder, I also have to do the following: folder-hook =lists/mutt my_hdr From: <mutt@...> . And to get the "mail to any list from any folder gets the appropriate list From" behaviour, I also have send-hook [EMAIL PROTECTED] my_hdr From: <mutt@...> . But I've got a problem--send hooks always trump folder hooks, because you change into the folder before you start composing a message. So my "folder-hook =lists/mutt" line never takes effect; the very first message I compose in that folder matches one of the send-hooks, and the header gets reset. OK, so I need to have my send-hooks be context dependent, somehow. My next thought was to try: send-hook . my_hdr From: <svc@...> folder-hook =lists/mutt send-hook . my_hdr From: <mutt@...> send-hook mutt-users my_hdr From: <mutt@...> . That doesn't work quite right, either, however; if I change into =lists/mutt, and then go back to my inbox, the mutt default send-hook stays in effect, and all mail from my inbox goes out with my mutt address. So we revise yet again: folder-hook . send-hook . my_hdr From: <svc@...> folder-hook =lists/mutt send-hook . my_hdr From: <mutt@...> send-hook mutt-users my_hdr From: <mutt@...> . And that should work, right? Wrong. Here's where I'm getting confused--everything works pretty much the same way as with the previous iteration. I even went in and added some diagnostic messages to my rc.testing file, whose current contents are: set folder="~/mail" # +foo or =foo -> $folder/foo set spoolfile="=inbox" # Incoming mail (!) folder-hook . set edit_hdrs folder-hook . send-hook . my_hdr From: <svc@...> folder-hook . push !echo<space>'Creating<space>default<space>send-hooks<enter>' folder-hook . send-hook . push !echo<space>'Running<space>default-folder<space>send-hook<enter>' folder-hook =lists/mutt send-hook . my_hdr From: <mutt@...> folder-hook =lists/mutt push !echo<space>'Creating<space>mutt<space>send-hooks<enter>' folder-hook =lists/mutt send-hook . push !echo<space>'Running<space>mutt-folder<space>send-hook<enter>' send-hook mutt-users my_hdr From: <mutt@...> (plus some comments on previous tests). (It sure would be nice if mutt had some option that would tell it to show you each hook that is attempted, in the order in which they are attempted, and ideally the string against which they match if they do in fact match, so that this sort of push+echo stuff wasn't necessary.) OK, so when I start mutt up with /usr/local/bin/mutt -F rc.testing , I see the following: Creating default send-hooks . OK, so that's working fine. Then I change to =lists/mutt, and see: Creating mutt send-hooks Creating default send-hooks . Huh? The default send-hooks should be created first, not second. Well, what happens when I compose a mail to some random address (so the generic mutt-users send-hook isn't matched) from inside that folder? Well, when I enter the composer, my From: header is set to <mutt@...>, so the correct send-hook is being matched, but when I exit the composer, what I see is Running mutt-folder send-hook Running default-folder send-hook . Huh again? If the default-folder send-hook is getting run second, then I should be seeing <svc@...> as my address in the composer, not <mutt@...>. So it looks like the echo statements are getting buffered somehow, and returned in reverse order. So I change back to my inbox, and see Creating default send-hooks as expected; this means that the default-folder send-hook should be last on the stack, and thus should be the one in effect, right? Well, when I compose a message to a random address, the From: header in the composer is still <mutt@...>, and the messages I get when I leave the composer are Running mutt-folder send-hook Running default-folder send-hook . Huh for a third time? I would have expected something like Running default-folder send-hook Running mutt-folder send-hook Running default-folder send-hook , given that I've now created the default-folder send-hook twice. Unless mutt can detect when two hooks of the same type have the same pattern, and simply overwrites the old one with the new one without moving it to the end of the list... only that can't be the case because the mutt-folder send-hook and the default-folder send-hook both are send-hooks with idential patterns, so if that were true then I should be seeing just one of them running at a time. So, I'm totally confused now. What gives? -- Sweth. -- Sweth Chandramouli Idiopathic Systems Consulting [EMAIL PROTECTED] http://www.idiopathic.net/