procmail filters – apply to received mails.

If you already have some mail in your maildir and you have set procmail filters, then it is difficult to apply the procmail filter, right? Not so, you just need to go to the Inbox directory and then execute the command.

for i in *; do cat $i|procmail; rm -f "$i"; done

This will pass all of your e-mail through procmail again and then your filters will get applied. Mails will go to their appropriate directory and you will be one happy man, I hope.


Enhanced by Zemanta

Transfer all the google feed URLs to rss2email.

Next step in restoring my settings was to get the working rules and all the blogs into rss2email. I have subscribed to more than 150 blogs. So, adding all of them manually was difficult.

For a time like this, I subscribe to all the blogs using google reader and then add them to rss2email. So I had quickly exported the google feeds list and then had to find a way to extract the URLs for the blog to the rss2email. The command to add a url is r2e add, so I wrote this one line just now to do the task for me.

Hope it helps someone:

for i in $(cat google-reader-subscriptions.xml |grep xmlUrl|sed -e \’s@.*xmlUrl=\”\\(.*\\) .*@\\1@\’|sed -e \’s/\”//\’); do r2e add $i; done

Now all I needed to do was to setup procmail again to deliver the messages to my homedir. I already have posted article on procmailrc so that was simple. So all done. Hope this helps someone.

Send mail to yourself and read in your favourite client and configure the rules to move to directory.

By default when you send a mail using sendmail, the mail goes to the default directory. What I wanted to do was, use rss2email, to send the mails and then sort them in different folders depending on the From address.

Sendmail uses procmail to deliver mail locally. So here\’s what I had to do:

Configure the rss2email to send the mail to amit@localhost

Next, configure the procmail to deliver mail to my home directory. To do this we will use the <dot>procmailrc file in the home directory. The contents of the file are :

MAILDIR=$HOME/Maildir      #you\’d better make sure it exists
DEFAULT=$MAILDIR/inbox   #completely optional
LOGFILE=/var/log/from   #recommended

This sets the folder for the mail delivery to $HOME/Maildir. The format for the mail file would be mbox and the filename used for mail delivery would be inbox. Ensure that the folder and file exists. Now we will add some rules to place the mail in the appropriate file(or folder in mbox terminology)

* ^From.*shell*

The rule states that if the from field contains shell then move the message to the commands file rather than inbox folder. You can add as many rules as you want and you are done.

To test your rule:

create a file called test.msg with the contents

From: shell commands

and run the command:

procmail ~/.procmailrc <test.msg

and check which file the message went to … and you are done.