procmail
[Top] [All Lists]

Re: Associative arrays in procmail recipes?

2002-12-24 10:46:59
On 24 Dec, Don Hammond wrote:
| On 24 Dec, Marco Fioretti wrote:
| [...]
|| 
|| In other words, I'd like a generic way to bind a generic string to an
|| unrelated one.
|| If this where Perl, I would build an associative array:
|| 
|| %FOLDER_NAMES = (
||      'discuss(_at_)openoffice(_dot_)org', 'OOO',
||      'anaconda-devel-list-admin(_at_)redhat(_dot_)com', 'custom_redhat',
|| 
||      .....
|| );
|| 
|| and change the "save message to folder" line above to:
|| 
||      save message to folder $FOLDER_NAMES{$1}
|| 
|| How do I do this in procmail? (Some days ago I *did* search with google
|| both in the archives and on the Internet, to no avail)
| 
| LIST_LOOKUP=":discuss(_at_)openoffice(_dot_)org:OOO:\
| anaconda-devel-list-admin(_at_)redhat(_dot_)com:custom_redhat"
| 
| :0:
| * your condition(s) that place(s) intended "key" in MATCH variable
| * $ LIST_LOOKUP ?? :$MATCH:\/[^:]+
| $MATCH
| 

Minor addendum ...

You would probably want to use $\MATCH in the condition:

  * $ LIST_LOOKUP ?? :$\MATCH:\/[^:]+

so that characters special to the regexp engine are escaped. In
practice, it probably doesn't matter; but it is more precise. Also, if a
colon could be in the "key" name, you will have to use a different
delimiter that's guaranteed to be unique.


-- 
Email address in From: header is valid  * but only for a couple of days *
This is my reluctant response to spammers' unrelenting address harvesting



_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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