0

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!

user3236841
  • 1,088
  • 1
  • 15
  • 39
  • `^From` does not match `Resent-From:`. You are probably matching on the `From_` pseudo-header (your recipe i matching the colon after `From`); see also http://www.iki.fi/era/procmail/mini-faq.html#from-- – tripleee Dec 23 '19 at 19:51
  • Don't understan dthis comment. The link redirects to a dead link. My From is different from Resent-From in the above example, yet still gets sent to the sent folder. – user3236841 Dec 24 '19 at 04:49
  • I'm not in a place where I can test, but perhaps you could still [edit] to include a log excerpt with `VERBOSE=yes` to demonstrate this? See also http://www.iki.fi/era/mail/procmail-debug.html (aka https://web.archive.org/web/20191008180530/porkmail.org/era/mail/procmail-debug.html) – tripleee Dec 24 '19 at 10:44
  • The `Return-Path:` *does* indicate that the envelope sender in the `From_` line would have matched your recipe without a colon in this case, even though it does not end up getting written out to the saved message. – tripleee Dec 24 '19 at 10:45
  • I have provided the complete header of the envelope. So, this e-mail ends up in my sent-mail folder even though it should not have because the From is something else. Thanks for the additional link, this works and I will get VERBOSE going. – user3236841 Dec 24 '19 at 14:41
  • The `^` in the regex means beginning of line. The regex you show can only match `From` at beginning of line. At the risk of sounding repetitive, I urge you to add a colon after those four literal characters to disambiguate it from other fields which begin with the same string; but it cannot match fields which do not begin with these characters. – tripleee Dec 24 '19 at 18:48
  • Thanks for this. Btw, who do I put a wildcard inside the e-mail address. For instance, sometimes, my From says: user@ns12.outlook.com (or something else) and sometimes it says user@outlook.com, depending on what I used to send e-mail. I want both to go to my sent folder. Would a "*" after the @ and before outlook be appropriate? – user3236841 Dec 25 '19 at 16:00
  • No; the regex to ray "anything" is `.*` (dot star) but you want to constrain it to no whitespace, no @, no dot, one or more, followed by a dot; all of this repeated zero or more times. That's `([^ @.]+\.)*` where the whitespace should consist of a space and a tab. – tripleee Dec 25 '19 at 17:57
  • Don't heap on new questions; search before asking a new question (this is very much a regex FAQ, though getting the Procmail variant exactly right has probably not been answered on Stack Overflow). – tripleee Dec 25 '19 at 17:59
  • I appreciate your answers as well as for pointing out that using a wildcard would be too simplistic in my case. I will not post newer questions on this thread. Thanks very much, tripleee! – user3236841 Dec 26 '19 at 15:02

1 Answers1

0

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
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Thanks, so I use a lock only on files in the MBOX format then, I guess? I used to use MBOX but nowadays I use .mh folders and so that is legacy for me. Do I use a colon for /dev/null? – user3236841 Dec 23 '19 at 15:03
  • There is no need to lock `/dev/null` or, generally speaking, directory-based folder formats. See also http://www.iki.fi/era/procmail/mini-faq.html#locking – tripleee Dec 23 '19 at 17:26
  • I am sorry but the suggestion does not work. I still get all forwarded mail in my sent folder. I tried changing the order but to no avial. What am I doing wrong? I use procmail -d %s as my call to procmail. It looks like the original suggestion is doing an OR or ignoring the second one. – user3236841 Dec 23 '19 at 18:01
  • The suggested link in comment #2 is bad. – user3236841 Dec 23 '19 at 18:13
  • The link works for me. I *think* you are not describing your situation properly; can you how a (trimmed down) message which you think should not pass both conditions, but which does? – tripleee Dec 23 '19 at 19:08
  • The link goes to porkmail.org/era/procmail/mini-faq.html#locking which is not found. I have updated an example which should not pass both conditions since Resent-From is different from From. Is it possible to only check on a From (but not any other field having a From as part of the word?). Thanks again! – user3236841 Dec 24 '19 at 00:05
  • I can only repeat that the link works for me. The content is hosted on porkmail.org but it has moved in the past so I use the canonical redirector as recommended on the page. Maybe try https://web.archive.org/web/20191008180530/porkmail.org/era/procmail/mini-faq.html – tripleee Dec 24 '19 at 09:51