added two fixes from iain murray
[attachcheck] / attachcheck
index 20e16c861ce13aaaa674783ea620adbcd88ab882..e5ac549ed9be819b9dcf9c54d7d57e76587b4483 100755 (executable)
@@ -35,8 +35,10 @@ ignored_types = ( "applica/pgp-signat", "application/pgp-signature" )
 # list of regular expressions which we will view as being indicative
 # of an attachment
 attachment_regexes = [ r'\battach(ed|ment|ing)?\b(?im)',
-                       r'\balleg(o|at[oaie]|ando)' ]
+                       r'\balleg(o|at[oaie]|ando)(?im)' ]
 
+# ignore quoted text (which might refer to attachments in previous emails)
+attachment_regexes = [ r'(^|^[^\n>].*)' + x for x in attachment_regexes ]
 
 ### No Edit Below This Line
 ###########################################
@@ -50,9 +52,13 @@ import re
 def send_message(): 
 
     global sendmail
-    sendmail = sendmail + " " + " ".join( sys.argv[1:] )
-   
-    mailpipe = os.popen("%s" % sendmail, 'w')
+
+    # construct the sendmail pipe more safely (thanks iain murray!)
+    cmd = sys.argv[:]
+    cmd[0] = sendmail
+
+    from subprocess import Popen, PIPE
+    mailpipe = Popen(cmd, stdin=PIPE).stdin
     mailpipe.write( message_string )
     sys.exit( mailpipe.close() )
 
@@ -125,7 +131,7 @@ if attachment_expected:
         # check for the confirmation
 
         if re.search( r'Subject: CONFIRM', message_string ):
-            message_string = re.sub( r'(Subject: )(CONFIRM)(.*?)\n',
+            message_string = re.sub( r'(Subject: )(CONFIRM )(.*?)\n',
                                      r'\1\3\n', message_string )
             send_message()
 

Benjamin Mako Hill || Want to submit a patch?