procmail
[Top] [All Lists]

Re: Add a string to "From" field

1998-11-16 07:08:49
On Mon, 16 Nov 1998 13:52:08 +0100, Alexandre Farcy
<Alexandre(_dot_)Farcy(_at_)prism(_dot_)uvsq(_dot_)fr> wrote:
in my .procmailrc how can i change the "From" field of a message (before
i store or forward it) with formail ?
i want to add a word to the Sender name according to the subject of the
mail...

Please be more specific. The one-line answer is, you filter it with
:0fhw | formail -whatever, but basically, I would imagine you are
after something like this:

    :0
    * ^Subject:[        ]*\/(foo|bar|baz)
    {
        # If we enter the braces, it means
        # MATCH now contains one of foo, bar, or baz

        # We insert that as a comment after the Sender:
        # but first we have to extract the original Sender: information

        # Remember the Subject keyword match
        MAGICWORD=$MATCH

        # Now extract Sender: into MATCH, and replace original Sender:
        # with a doctored version. We grab the data from From: if
        #  there is no Sender: field

        :0
        * ^From:[       ]*\/[^  ].*
        * ^Sender:[     ]*\/[^  ].*
        { } # If neither existed, we're in trouble :-)

        :0fhw
        | formail -I "Sender: $MATCH ($MAGICWORD)"
    }

The whitespace between the [] brackets consists of a tab and a space,
in any order. 

Possible misunderstandings:

  * You talk about From (as in From: I presume, not From_) and then
    about Sender: -- which do you mean, or if you mean both, how
    exactly should they relate to each other? (Historically, Sender:
    was used when From: didn't contain the "true" sender. The examples
    in RFC822 are along the lines of Secretary sending something on
    behalf of Boss, in which case you'd have Sender: Secretary and
    From: Boss.)

  * How exactly do you want to decide what should be added to the
    "Sender name"? I have assumed you want to copy something from the
    Subject only because that's fairly simple to do. If you want to
    add "Foo" when there's a "Bar" or a "Baz" in the Subject, that's
    possible too, but more complicated (in the general case --
    certainly if there is only one string which you want to add iff
    one of a number of others is present in the Subject, that's easy,
    but it doesn't scale too well).

  * Do you really feel comfortable changing a header which should be
    under the sender's control, not yours (whether Sender: or From:)
    and how exactly do you propose to change it? (Adding a comment in
    parentheses is rather benign, but I fail to see how this serves
    any useful purpose ... Unless you forward to a service which
    clobbers most other headers and you have something you want to
    smuggle in piggybacked on one of the surviving headers.)

If this doesn't help, perhaps you want to follow up to the list with a
more detailed description of what you want to accomplish. 

/* era */

-- 
.obBotBait: It shouldn't even matter whether    <http://www.iki.fi/~era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>

<Prev in Thread] Current Thread [Next in Thread>