Eventually we'll commit after every message.
"""
-import libbe.cmdutil, libbe.utility
+import cStringIO as StringIO
import email
+import libbe.cmdutil, libbe.utility
import send_pgp_mime
import sys
import time
response_header = [u"From: %s" % HANDLER_ADDRESS,
u"To: %s" % author,
- u"Date: %s" % , libbe.utility.time_to_str(time.time()),
+ u"Date: %s" % libbe.utility.time_to_str(time.time()),
u"Content-Type: text/plain; charset=%s" % encoding,
u"Content-Transfer-Encoding: 8bit",
u"In-reply-to: %s" % (id),
- u"Subject: %s Re: %s" % (SUBJECT_COMMENT, command),
+ u"Subject: Re: %s %s" % (SUBJECT_COMMENT, command),
]
response_body = [u"Results of running: (exit code %d)" % ret,
u" %s %s" % (command, " ".join(command_args)),]
def main():
msg_text = sys.stdin.read()
- response_email = handle_message(msg_text)
+ response_email = run_message(msg_text)
send_pgp_mime.mail(response_email, send_pgp_mime.sendmail)
if __name__ == "__main__":
"""
Python module and command line tool for sending pgp/mime email.
-Mostly uses subprocess to call gpg and a sendmail-compatible mailer
-(defaults to msmtp). If you lack gpg, either don't use the encryption
-functions or adjust the pgp_* commands. If you don't use msmtp,
-adjust the sendmail command.
+Mostly uses subprocess to call gpg and a sendmail-compatible mailer.
+If you lack gpg, either don't use the encryption functions or adjust
+the pgp_* commands. You may need to adjust the sendmail command to
+point to whichever sendmail-compatible mailer you have on your system.
"""
from cStringIO import StringIO
pgp_sign_command='/usr/bin/gpg --no-verbose --quiet --batch %p --output - --detach-sign --armor --textmode %?a?-u "%a"? %f'
pgp_encrypt_only_command='/usr/bin/gpg --no-verbose --quiet --batch --output - --encrypt --armor --textmode --always-trust --encrypt-to "%a" %R -- %f'
pgp_encrypt_sign_command='/usr/bin/gpg --no-verbose --quiet --batch %p --output - --encrypt --sign %?a?-u "%a"? --armor --textmode --always-trust --encrypt-to "%a" %R -- %f'
-sendmail='/usr/bin/msmtp -t'
+sendmail='/usr/sbin/sendmail -t'
def execute(args, stdin=None, expect=(0,)):
"""
if passphrase == None:
return (None,'')
return (passphrase, pgp_stdin_passphrase_arg)
+ def plain(self):
+ """
+ text/plain
+ """
+ msg = MIMEText(self.body)
+ for k,v in self.headermsg.items():
+ msg[k] = v
+ return msg
def sign(self, passphrase=None):
"""
multipart/signed
type="int", metavar='DESCRIPTOR')
parser.add_option('--mode', dest='mode', default='sign',
- help="One of 'sign', 'encrypt', or 'sign-encrypt'. Defaults to %default.",
+ help="One of 'sign', 'encrypt', 'sign-encrypt', or 'plain'. Defaults to %default.",
metavar='MODE')
parser.add_option('-a', '--sign-as', dest='sign_as',
message = m.encrypt()
elif options.mode == "sign-encrypt":
message = m.signAndEncrypt()
+ elif options.mode == "plain":
+ message = m.plain()
else:
print "Unrecognized mode '%s'" % options.mode