X-Git-Url: https://projects.mako.cc/source/attachcheck/blobdiff_plain/23604a138fba0b335152f5fed4c675fac58b0bfc..786be57db0813f999af2454536121a8c3b3d82ee:/attachcheck diff --git a/attachcheck b/attachcheck old mode 100644 new mode 100755 index ebcd6be..e633291 --- a/attachcheck +++ b/attachcheck @@ -3,20 +3,30 @@ # AttachCheck -- A MTA wrapper to help check outgoing email for # forgotten attachments. -# (c) 2005 -- Benjamin Mako Hill -# Author/Software Homepage at: http://mako.cc +# (c) 2004-2009 -- Benjamin Mako Hill +# Software Homepage at: http://mako.cc/projects/attachcheck -# This software comes with ABSOLUTELY NO WARRANTY. -# This is free software and is licensed under the GNU GPL. +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. -__copyright__ = "Copyright (c) 2004 Benjamin Mako Hill" -__author__ = "Benjamin Mako Hill " +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +__copyright__ = "Copyright (c) 2004-2009 Benjamin Mako Hill" +__author__ = "Benjamin Mako Hill " ### Configuration Options ########################################### # location of the sendmail binary -sendmail = "/usr/sbin/sendmail -oi" +sendmail = "/usr/sbin/sendmail" # list of mimetype which are, for the sake of this program, not # attachments @@ -25,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 ########################################### @@ -40,11 +52,17 @@ import re def send_message(): global sendmail - sendmail = sendmail + " " + " ".join( sys.argv[1:] ) - - mailpipe = os.popen("%s -t" % sendmail_with_args, 'w') + + # construct the sendmail pipe more safely (thanks iain murray!) + cmd = sys.argv[:] + cmd[0] = sendmail + + from subprocess import Popen, PIPE + process = Popen(cmd, stdin=PIPE) + mailpipe = process.stdin mailpipe.write( message_string ) - sys.exit( mailpipe.close() ) + mailpipe.close() + sys.exit( process.wait() ) ## SUB: print error message def print_error():