procmail

procmail: conditioning on multiple fields


I would like to store e-mails sent by me to others using the "From" field to a folder called "/sent"

So, I use:

:0:
*^From.*user@outlook.com
$HOME/Mail/sent/.

And it used to work fine. However, now I am also forwarding my e-mail from the address:user@outlook.com, what is happending is that the e-mail envelope contains the header: Resent-From.*user@outlook.com so all forwarded e-mail is being saved to the sent folder.

Is it possible to have a double condition. That is something that says that if both Resent-From and From have *user@outlook.com, then it should go to the sent-folder. In other words, is it possible to use a AND or OR or Negation condition.

Update: The provided solution is correct. I was making an error in that I had neglected the ":". Thanks for both the solution and the patience. I also learnt a number of things and about a number of resources, for which also I am grateful,

Thanks!


Solution

  • Procmail by default does exactly what you ask. Multiple conditions will be ANDed together. The first one which fails causes the recipe to be abandoned; if they all succeed, the action is taken.

    :0  # second colon removed - don't use lock on directories
    * ^From:(.*\<)?user@outlook\.com
    * ^Resent-From:(.*\<)?user@outlook\.com
    $HOME/Mail/sent/.
    

    Notice also how I modified your regex to tighten it up.

    To do NOT, add a ! in front of the condition. To do OR, you can negate both conditions, and take the action in the "else" part (de Morgan's law).

    :0
    * ! First condition
    * ! Other condition
    { } # do nothing
    :0E # else, meaning at least one was true
    action
    

    Of course, if both conditions are regular expressions, you can simply use the regex or operator.

    :0
    * First condition|Other condition
    action