Skip to content

Instantly share code, notes, and snippets.

Created December 27, 2012 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4388701 to your computer and use it in GitHub Desktop.
Save anonymous/4388701 to your computer and use it in GitHub Desktop.
Generate send-hooks for addresses (set from, force encrypt...) using a yaml configuration file The file is called a "ruleset" Each entry is a "rule" and is a dictionary Each rule can map to many mutt hooks
'''
Generate send-hooks for addresses (set from, force encrypt...) using a yaml
configuration file
The file is called a "ruleset"
Each entry is a "rule" and is a dictionary
Each rule can map to many mutt hooks
'''
import yaml
try:
from yaml import CLoader as Loader
except:
from yaml import Loader
def make_rule(rule):
when = []
what = []
if 'domains' in rule:
for domain in rule['domains']:
when.append(r'\@%s$' % domain)
if 'addresses' in rule:
for address in rule['addresses']:
when.append(r'^%s$' % address)
if 'from' in rule:
what.append('my_hdr From: %s' % rule['from'])
if 'gpg' in rule:
gpg = []
if 'crypt' in rule['gpg']:
gpg.append('crypt_autoencrypt')
if 'sign' in rule['gpg']:
gpg.append('crtyp_autosign')
if gpg:
what.append('set %s' % ' '.join(gpg))
for condition in when:
for action in what:
yield "send-hook '~t %s' '%s'" % (condition, action)
def make_rules(src):
ruleset = yaml.load(src, Loader=Loader)
for rule in ruleset:
out = tuple(make_rule(rule))
for hook in out:
print hook
if __name__ == '__main__':
import sys
src = sys.argv[1]
make_rules(open(src, 'r'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment