6

I'm trying to create a Procmail rule based on all of From, Subject and a string in the body:

:0 B:
* ^From:.*root@example.com.*
* ^Subject:.*fixed string in the subject line.*
* .*fixed string in the body.*
/dev/null

I'm trying to delete a persistently problematic mail source whose only safe option is to check all three of these.

What am I doing wrong here? Presumably this is something do do with the B flag?

7

You need both H and B if you want to match headers and body. See the Procmail Tips page, full of useful examples. Try

:0 HB
* ^From:.*root@example.com
* ^Subject:.*fixed string in the subject line
* fixed string in the body
/dev/null

(note, the above doc refers to a bug in version 3.22 whereby once HB is used further uses of just B will still look through H).

  • Thanks very much - that works, and as such as a great relief for my inbox! Am surprised I didn't come across any examples of this when searching. – fooquency May 4 '16 at 17:30
3
:0
* ^From:.*root@example.com
* ^Subject:.*fixed string in the subject line
* B ?? fixed string in the body
/dev/null

man procmailrc

variablename ??
Match the remainder of this condition against the value of this environment variable (which cannot be a pseudo variable). A special case is if variablename is equal to B, H, HB or BH; this merely overrides the default header/body search area defined by the initial flags on this recipe.

  • +1 This is the more useful answer, as you don't want to look for the From: and Subject: headers in the body of the message, or find the string in random other headers. – tripleee May 6 '16 at 4:14
  • The trailing : is more than useless here; the purpose of locking is to prevent the message from being mangled, but if you are ditching it anyway, you honestly won't care, and locking will consume some resources which are probably better spent elsewhere. – tripleee May 6 '16 at 4:15
  • Also the trailing .* in the regular expressions is redundant and useless. – tripleee May 6 '16 at 4:15
  • @tripleee I have used "minimal sample modification" approach. – AnFi May 6 '16 at 5:52
  • I can see that, but not fixing obvious errors in the OP's code would certainly warrant a comment to that effect at the very least. – tripleee May 6 '16 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.