#!/usr/bin/env python # Reads an e-mail message from stdin, and sets up a gnus compose buffer # with it ready to edit/send. Only handles single-line To, Cc, Subject, etc. import sys import subprocess readinghead = True to = 'nil' cc = 'nil' bcc = 'nil' subject = 'nil' body = '"' for line in sys.stdin: # Replace \ with \\ line=line.replace('\\', r'\\') # Replace " with \" line=line.replace(r'"', r'\"') if readinghead: line = line.strip() if line: if line.startswith('To: '): to = '"' + line[4:] + '"' elif line.startswith('Cc: '): cc = '"' + line[4:] + '"' elif line.startswith('Bcc: '): bcc = '"' + line[5:] + '"' elif line.startswith('Subject: '): subject = '"' + line[9:] + '"' else: print 'Error: unknown line in head:' print line sys.exit(1) else: readinghead = False else: body += line body += '"' elisp = '(mozmail-compose-gnus %s %s %s %s %s)' % (to, subject, cc, bcc, body) subprocess.call(['emacsclient', '-n', '--eval', elisp])