-2

I'm receiving several mails per day from different senders with different subjects. Usually, there is some identifier (integer) that is within the Subject:, and I'd like to sort mails according to that identifier. The parsing of the identifier shouldn't be a problem. However, there is no pre-define range of integers that are valid. What I'd like to have is mail with same identifier somehow bundeled together, be it that these mails are stored in a separate folder per identifier, or listed within a conversation such that mail programs display them as connected.

What I'm running right now is a getmail/procmail combination to fetch those mails. What I need is some idea how that could the problem could be solved. If somebody has a hint how to find a solution, preferrably with procmail, let me know. Thanks!

Example:

mail1: From: User1 Subject: message for ID 1234

mail2: From: User2 Subject: message for ID 4567

mail3: From: User3 Subject: ID 1234 finished

mail4: From: User1 Subject: starting ID 9999

mail5: From: User2 Subject: finished ID 9999

What I'd like to have is all messages with identical ID in the Subject: bundled, for the example above that would be 3 'buckets': 1234, 4567, 9999.

user236012
  • 235
  • 2
  • 8

1 Answers1

0

To extract the first integer from the Subject: header and use that as the name of the folder to save to,

:0
* ^Subject:[^0-9]*\/[0-9]+
$MATCH

If you would like for the folder to be a Maildir folder instead of a flat Berkeley mbox file, use $MATCH/. instead.

The special token \/ causes Procmail to store the input string which matches the regex after this token in the variable MATCH.

tripleee
  • 139,311
  • 24
  • 207
  • 268