From 6d218b1151bdebf069401152960f6631d8d8b0f8 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Sat, 13 Jun 2009 16:06:35 -0400 Subject: [PATCH] added two fixes from iain murray - fix to keep it from catching the message in quoted text - safer working with sendmail --- attachcheck | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/attachcheck b/attachcheck index 5864de0..e5ac549 100755 --- a/attachcheck +++ b/attachcheck @@ -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() ) -- 2.30.2