"be-handle-mail --output" added to support easy testing.
authorW. Trevor King <wking@drexel.edu>
Fri, 17 Jul 2009 12:16:45 +0000 (08:16 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 17 Jul 2009 12:16:45 +0000 (08:16 -0400)
interfaces/email/interactive/be-handle-mail

index e0ed58484378390dbe5ee91251d179131a00373e..180320d3b478b16aa0a8eeaf687d2a72f9ea1946 100755 (executable)
@@ -212,6 +212,15 @@ def compose_response(ret, out_text, err_text, info):
     return response_email
 
 def main():
+    from optparse import OptionParser
+
+    usage="be-handle-mail [options]\n\n%s" % (__doc__)
+    parser = OptionParser(usage=usage)
+    parser.add_option('-o', '--output', dest='output', action='store_true',
+                      help="Don't mail the generated message, print it to stdout instead.  Useful for testing be-handle-mail functionality without the whole mail transfer agent and procmail setup.")
+
+    options,args = parser.parse_args()
+
     msg_text = sys.stdin.read()
     try: 
         ret,out_text,err_text,info = run_message(msg_text)
@@ -223,8 +232,11 @@ def main():
             f.write("Uncaught exception:\n%s\n" % (e,))
             f.close()
         sys.exit(1)
-    response_email = compose_response(ret, out_text, err_text, info)
-    send_pgp_mime.mail(response_email.plain(), send_pgp_mime.sendmail)
+    response_email = compose_response(ret, out_text, err_text, info).plain()
+    if options.output == True:
+        print send_pgp_mime.flatten(response_email)
+    else:
+        send_pgp_mime.mail(response_email, send_pgp_mime.sendmail)
 
 if __name__ == "__main__":
     main()