Skip to content

Instantly share code, notes, and snippets.

@kousu
Created December 17, 2017 19:43
Show Gist options
  • Save kousu/867050ee0de5dddaf1312647ddd83279 to your computer and use it in GitHub Desktop.
Save kousu/867050ee0de5dddaf1312647ddd83279 to your computer and use it in GitHub Desktop.
procmail snippet for auto-binning / auto-filtering mailing lists
# mailing lists
#
# This automatically sorts mail from mailing lists into folders named after the list
# [email protected] will go into your IMAP Lists/misc folder
# [email protected] will go into Lists/fanciness
# (if you need more specific rules, you can tweak or add a rule for your specific lists *ahead* of this rule)
#
# Now, procmail doesn't(?) have capturing groups, closest it has a capturing \/,
# which grabs everything from itself *to the end* of the line* of the match
# (thanks https://serverfault.com/questions/660159/procmail-recipe-with-capturing-group/660571);
# so how this rule works is by grabbing the list-post header, which is supposed to be part of the email standards,
# and extracting the name of the mailing list *before* the domain
# (i.e. everything after the mailto: and before the first @, that's what [^\@]* means)
# and puts that into $MATCH;
# .Lists.$MATCH is because, for some reason, at least with Dovecot, mail subfolders are separated by . not by /
:0
* ^List-Post: <mailto:\/[^\@]*
.Lists.$MATCH/
# ref: https://people.dsv.su.se/~jpalme/ietf/mail-headers/mail-headers.html
# ref: * ^FROM_DAEMON is a built in procmail rule meant to capture anything that looks like a mailing list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment