On 2008-01-25, Corey Halpin wrote:
>   Once I figure out how to make this actually work, I'll write up a page on 
> the wiki.
 
  I had somehow managed to miss (over and over) that python's strings don't 
use CRLF line-endings, and PGP/MIME messages require CRLF line-endings in the 
signed data.
  The attached patch fixed that, and works nicely for me.

  Also attached is a patch to put hashcash stamps on autoreplies.
  I'd like to add it to the hashcash HOWTO on the wiki, but it appears I need 
to ask someone to give me edit rights?

regards,
~crh
Index: tmda-1.1.12/TMDA/AutoResponse.py
===================================================================
--- tmda-1.1.12.orig/TMDA/AutoResponse.py       2008-01-24 23:46:03.166814000 
-0600
+++ tmda-1.1.12/TMDA/AutoResponse.py    2008-01-25 13:38:41.000000000 -0600
@@ -23,16 +23,19 @@
 
 
 from email import message_from_string
+from email import encoders
 from email.charset import add_alias
 from email.errors import MessageError
 from email.header import Header, decode_header
 from email.mime.message import MIMEMessage
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
+from email.mime.application import MIMEApplication
 from email.utils import formataddr, parseaddr
 
 import os
 import time
+import string
 
 import Defaults
 import Util
@@ -121,8 +124,7 @@
         for h in bad_headers:
             if self.bouncemsg.has_key(h):
                 del self.bouncemsg[h]
-        textpart = MIMEText(self.bouncemsg.get_payload(), 'plain',
-                            self.bodycharset)
+        textpart = self.create_text();
         bodyparts = 1 + Defaults.AUTORESPONSE_INCLUDE_SENDER_COPY
         if bodyparts == 1:
             # A single text/plain entity.
@@ -242,3 +244,27 @@
                                response_filename), 'w')
         fp.close()
 
+    def create_text(self):
+        """
+        Create the body part of the MIME entity for the auto reply.
+        """
+        rc = None
+        if Defaults.USE_GPG_SIGNATURES:
+            rc=MIMEMultipart('signed', micalg='pgp-sha1',
+                              protocol='application/pgp-signature')
+            body_text = MIMEText(self.bouncemsg.get_payload(),'plain',
+                                 self.bodycharset)
+            (gpg_in, gpg_out)=os.popen2('gpg -a -b')
+            gpg_in.write(string.replace(body_text.as_string(),'\n','\r\n'))
+            gpg_in.close()
+            signature = gpg_out.read();
+            gpg_out.close()
+            body_signature = MIMEApplication(signature, 'pgp-signature',
+                             encoders.encode_noop )
+            rc.attach(body_text);
+            rc.attach(body_signature);
+        else:
+            rc = MIMEText(self.bouncemsg.get_payload(), 'plain',
+                          self.bodycharset)
+        return rc
+
Index: tmda-1.1.12/TMDA/Defaults.py
===================================================================
--- tmda-1.1.12.orig/TMDA/Defaults.py   2008-01-24 23:57:06.000000000 -0600
+++ tmda-1.1.12/TMDA/Defaults.py        2008-01-24 23:57:31.000000000 -0600
@@ -1571,6 +1571,9 @@
 if not vars().has_key('CRYPT_KEY_FILE'):
     CRYPT_KEY_FILE = os.path.join(DATADIR, 'crypt_key')
 
+if not vars().has_key('USE_GPG_SIGNATURES'):
+    USE_GPG_SIGNATURES = False
+
 ###################################
 # END of user configurable settings
 ###################################
Index: tmda-1.1.12/TMDA/AutoResponse.py
===================================================================
--- tmda-1.1.12.orig/TMDA/AutoResponse.py       2008-01-25 14:13:49.000000000 
-0600
+++ tmda-1.1.12/TMDA/AutoResponse.py    2008-01-25 16:36:19.000000000 -0600
@@ -212,6 +212,13 @@
             self.mimemsg['Auto-Submitted'] = 'auto-generated (failure)'
         self.mimemsg['X-Delivery-Agent'] = 'TMDA/%s (%s)' % (Version.TMDA,
                                                              Version.CODENAME)
+
+        if Defaults.USE_HASHCASH_AUTOREPLIES:
+            cmd='hashcash -qm -b24 -Z1 %s' % self.mimemsg.get('to')
+            stamp = os.popen(cmd)
+            self.mimemsg['X-Hashcash']=stamp.read()
+            stamp.close()
+
         # Optionally, add some custom headers.
         Util.add_headers(self.mimemsg, Defaults.ADDED_HEADERS_SERVER)
         # Optionally, remove some headers.
Index: tmda-1.1.12/TMDA/Defaults.py
===================================================================
--- tmda-1.1.12.orig/TMDA/Defaults.py   2008-01-25 14:13:49.000000000 -0600
+++ tmda-1.1.12/TMDA/Defaults.py        2008-01-25 14:15:51.000000000 -0600
@@ -1571,6 +1571,9 @@
 if not vars().has_key('CRYPT_KEY_FILE'):
     CRYPT_KEY_FILE = os.path.join(DATADIR, 'crypt_key')
 
+if not vars().has_key('USE_HASHCASH_AUTOREPLIES'):
+    USE_HASHCASH_AUTOREPLIES = False
+
 ###################################
 # END of user configurable settings
 ###################################

Attachment: pgpgPysI27FWN.pgp
Description: PGP signature

_____________________________________________
tmda-users mailing list ([email protected])
http://tmda.net/lists/listinfo/tmda-users

Reply via email to