Commits

Luke Plant committed 8a5d1b7 Merge

Merged from default

Comments (0)

Files changed (5)

cciw/cciwmain/management/__init__.py

Empty file added.

cciw/cciwmain/management/commands/__init__.py

Empty file added.

cciw/cciwmain/management/commands/handle_mailing_lists.py

+import os
+import zc.lockfile
+
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+
+    def handle(self, *args, **options):
+        try:
+            l = zc.lockfile.LockFile('.handle_mail_lock')
+        except zc.lockfile.LockError:
+            return
+
+        try:
+            try:
+                from cciw.mail.lists import handle_all_mail
+                handle_all_mail()
+            except:
+                from django.core.mail import mail_admins
+                import traceback
+                import sys
+                subject = 'Sending mail error'
+                exc_info = sys.exc_info()
+                message = '\n'.join(traceback.format_exception(*exc_info))
+                mail_admins(subject, message, fail_silently=True)
+        finally:
+            # Delete the lock
+            l.close()

cciw/mail/lists.py

 def forward_email_to_list(mail, addresslist, original_to):
     from_addr = mail['From']
 
-    # search and erase the original 'To' address in the 'Received'
-    # headers, to hinder recipients from mailing the address themselves
-    mail._headers = [(name, val.replace(original_to, "private@cciw.co.uk"))
-                     for name, val in mail._headers]
+    # Various headers seem to cause problems. We whitelist the ones
+    # that are OK:
+    good_headers = [
+        'content-type',
+        'content-transfer-encoding',
+        'subject',
+        'from',
+        'mime-version',
+        'user-agent',
+        'content-disposition',
+        'date',
+        ]
+    mail._headers = [(name, val) for name, val in mail._headers
+                     if name.lower() in good_headers]
 
     # Use Django's wrapper object for connection,
     # but not the message.
         mail['To'] = addr
         # Need new message ID, or webfaction's mail server will only send one
         del mail['Message-ID']
-        del mail['Message-Id']
         mail['Message-ID'] = make_msgid()
         c.connection.sendmail(from_addr, [addr], mail.as_string())
     c.close()

scripts/handle_mail.py

-#!/usr/bin/env python2.5
-import os
-import zc.lockfile
-
-def main():
-    try:
-        l = zc.lockfile.LockFile('.handle_mail_lock')
-    except zc.lockfile.LockError:
-        return
-
-    try:
-        try:
-            from cciw.mail.lists import handle_all_mail
-            handle_all_mail()
-        except:
-            from django.core.mail import mail_admins
-            import traceback
-            import sys
-            subject = 'Sending mail error'
-            exc_info = sys.exc_info()
-            message = '\n'.join(traceback.format_exception(*exc_info))
-            mail_admins(subject, message, fail_silently=True)
-    finally:
-        # Delete the lock
-        l.close()
-
-if __name__ == '__main__':
-    main()