X-Git-Url: https://git.madduck.net/code/mailplate.git/blobdiff_plain/08674f5191c95221b9e3a3d348913d1b2e916d17..8e1c938ce7630a3ec2c1963e1fa9ab652a432d77:/mailplate diff --git a/mailplate b/mailplate index 4b03c05..490ba8e 100755 --- a/mailplate +++ b/mailplate @@ -3,41 +3,8 @@ # # mailplate — reformat mail drafts according to templates # -# This script reformats mail drafts according to a given template. The -# template may be specified on the command line, but mailplate can also use -# control information from the template files to automatically select an -# appropriate template (--auto). A selection menu feature is planned (--menu). -# -# Applying a template means obtainined select data from an existing mail -# message (unless --new is specified) and to fill it into appropriate slots in -# the template. Messages are processed in three parts: headers, body, and -# signature. -# -# The template can define two types of headers: mandatory and preservatory. -# Mandatory headers take precedence over headers in the existing message and -# thus overwrite them. Preservatory headers instruct mailplate to port their -# data from the existing mail message. Headers in the existing message but not -# defined in the template are dropped, unless --keep-unknown is given. -# -# Body and signature are separated by '-- '. If this sentinel is not found, -# no signature is extracted. -# -# Templates can be interpolated and data filled into slots. Helper slots are -# filled with the output of helper commands (which must be defined in the -# configuration), environment variable slots are just that, and mail variable -# slots can be filled with data obtained by running regexps or commands over -# the message. -# -# This script can be run in multiple ways: -# -# As a filter, it applies a template to data from stdin and writes the result -# to stdout. -# -# Given a file, it modifies the file, unless it cannot write to the file, in -# which case it writes to stdout. -# -# When --editor is passed, the script spawns sensible-editor on the result. It -# may thus be used as the editor for your mail user agent. +# Please see the mailplate(1) manpage or the homepage for more information: +# http://madduck.net/code/mailplate/ # # TODO: if headers like From are absent from the mail, they should not be kept # but replaced with a default. @@ -86,6 +53,7 @@ HELPER_SLOT_TRAILER = ')' # character ending a helper slot STD_HEADERS = ('From', 'To', 'Cc', 'Bcc', 'Subject', 'Reply-To', 'In-Reply-To') KEEP_HEADERS = { 'KEEP_FROM_HEADER' : STD_HEADERS[:1] , 'KEEP_STD_HEADERS' : STD_HEADERS[1:] + , 'KEEP_ALL_HEADERS' : STD_HEADERS } SIG_DELIM='\n-- \n' @@ -414,10 +382,14 @@ for line in templ: l = line[:-1] if len(l) == 0: payload = '' # end of headers - elif l[0] == KEEP_SLOT_LEADER and KEEP_HEADERS.has_key(l[1:]): - # found predefined header slot keyword - for header in KEEP_HEADERS[l[1:]]: - headers[header.lower()] = (header, _keep_header) + elif l[0] == KEEP_SLOT_LEADER: + if KEEP_HEADERS.has_key(l[1:]): + # found predefined header slot keyword + for header in KEEP_HEADERS[l[1:]]: + headers[header.lower()] = (header, _keep_header) + else: + err('unknown header slot ' + l + ' found') + sys.exit(posix.EX_CONFIG) else: header, content = l.split(':', 1) content = content.strip()