procmail
[Top] [All Lists]

Re: sorting based on domain and receiver

2010-02-04 12:26:09
At 10:49 2010-02-04 +0100, frantisek holop wrote:
hi there,

i am trying to automate the following process:
let's say there is a helpdesk, or some such entity that
gets email in the form: country(_at_)brand(_dot_)com

i'd like to create a recipe to automatically sort
incoming mails into folders in the form of: brand-country

e.g.
austria(_at_)mybrand1(_dot_)com -> mybrand1-austria
germany(_at_)mybrand1(_dot_)com -> mybrand1-germany
germany(_at_)mybrand2(_dot_)com -> mybrand2-germany
etc.

as far as i can tell from the man pages, MATCH is not
too flexible for this....

MATCH is plenty flexible. Follow the link in my .sig and download my SANDBOX (which is what you're going to want to use to test your contraption anyway). The .procmailrc there has an extraction of the From: address to split it into the username and domain portions, and it used MATCH for this. In your case, you'll be using a different Field to parse, but the process is much the same.

Is this feedback coming via a webform where the To: will be consistent, or is it something a user will have typed in (say from printed literature, etc). Could there be multiple To: recipients, or this recipient be a Cc: or Bcc?

These issues will affect how you look for the address you're supposed to be parsing. Case-sensitivity may also play a role if you're extracting the strings and using them directly to compose a folder name: Germany != germany

If you conceivably have multiple domains which may be identified which are handled as the same brand, or just want to "normalize" the folder names rather than making them the same as the domain, you can look up the domain portion in a fashion similar to:

LOOKUP=`(fgrep -i " $DOMAIN" path/to/indexfile | sed -e "s/\(\(.*\):.*\)$/\2")`

then have indexfile contain:

brando: brando.tld brando-wipes.tld
fubar: fubar-airways.tld fubar-international.tld
springfree: springfree.tld ickypoo.tld stinkydiapers.tld

Each domain is delimited with a space. Yea, my fgrep operation doesn't look for a trailing space, but using fgrep when your input includes dots is a bit easier (though procmail can emit that string with regexp operators - specifically, the dots - escaped).

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>