How do I export mail.app rules to other filtering solutions such as procmail?

Solution 1:

You can find them in plist format (just an xml flavor) in:

~/Library/Mail/V2/MailData/MessageRules.plist

You can write a script in the language of your choice to parse this file and produce rules suitable to procmail.

Here is a python draft:

#!/usr/bin/env python

import plistlib

pl = plistlib.readPlist('/Users/<user>/Library/Mail/V2/MailData/SyncedRules.plist')

for rule in pl:
    print
    print ':0:'
    mbox = ''
    for key in rule:
        if key == 'Criteria':
            for c in rule[key]:
                print '^%s:.*%s' % (c['Header'], c['Expression'])
        if key == 'CopyToMailbox':
            mbox = rule[key]
    print mbox