From 786be57db0813f999af2454536121a8c3b3d82ee Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Sun, 6 May 2018 08:26:23 -0700 Subject: [PATCH 1/4] updated URLS - added https - updated new git URLs --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index b651dcb..9a5a4b3 100644 --- a/README.rst +++ b/README.rst @@ -16,13 +16,13 @@ send the message sans attachment. AttachCheck It was written in Benjamin Mako Hill. You can find the latest version of this program, more information, and some of Mako's sometime accidentally insightful or useful ideas at his eponymous -homepage at: http://mako.cc +homepage at: https://mako.cc The AttachCheck website with the latest version of the program is always -available here: http://mako.cc/projects/attachcheck/ +available here: https://mako.cc/projects/attachcheck/ The latest version of source code is kepted in a Git repository at -http://projects.mako.cc/source/?p=attachcheck and can be checked out or +https://projects.mako.cc/source/attachcheck and can be checked out or branched with the command:: git clone git://projects.mako.cc/attachcheck -- 2.30.2 From b6434634799c3c5ddce74997a2f5705ec9011c52 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Sun, 30 Sep 2018 10:30:50 -0500 Subject: [PATCH 2/4] move to python3 - move the new system to python3 - rework the subject munging so that it doesn't involve working with the full message as string - pass message object around explicitly --- attachcheck | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/attachcheck b/attachcheck index e633291..5580a32 100755 --- a/attachcheck +++ b/attachcheck @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # AttachCheck -- A MTA wrapper to help check outgoing email for # forgotten attachments. @@ -49,7 +49,7 @@ import email import re ## SUB: send message -def send_message(): +def send_message(message): global sendmail @@ -60,13 +60,13 @@ def send_message(): from subprocess import Popen, PIPE process = Popen(cmd, stdin=PIPE) mailpipe = process.stdin - mailpipe.write( message_string ) + mailpipe.write( message.as_string().encode() ) mailpipe.close() sys.exit( process.wait() ) ## SUB: print error message def print_error(): - print >>sys.stderr, \ + print(\ """(Your message mentions attachments but does not include any. Either: @@ -78,11 +78,11 @@ Either: (2) Add a \"X-AttachCheck-Override: Yes\" header the message. -Read the documentation for AttachCheck for more details.""" +Read the documentation for AttachCheck for more details.""", file=sys.stderr) # get the mail from stdin -message_string = sys.stdin.read() -message = email.message_from_string( message_string ) +message_bytes = sys.stdin.buffer.read() +message = email.message_from_bytes( message_bytes ) attachment_expected = False attachment_seen = False @@ -124,21 +124,22 @@ if attachment_expected: # if we are expecting an attachment and we've seen one, we should # send the file and be done with things if attachment_seen: - send_message() + send_message(message) # if we are expected have not seen it, we need to check to see if # the mail has been confirmed else: # check for the confirmation - - if re.search( r'Subject: CONFIRM', message_string ): - message_string = re.sub( r'(Subject: )(CONFIRM )(.*?)\n', - r'\1\3\n', message_string ) - send_message() - - elif message.get( 'X-AttachCheck-Override' ) == "Yes": - send_message() + subject_string = message['Subject'] + print(subject_string) + if re.search( r'^\s*CONFIRM', subject_string ): + subject_string = re.sub( r'(CONFIRM )(.*?)', r'\2', subject_string ) + message['Subject'] = subject_string + send_message(message) + + elif message['X-AttachCheck-Override'] == "Yes": + send_message(message) else: print_error() @@ -147,4 +148,4 @@ if attachment_expected: # if we are not expecting anything more, we should send the message else: - send_message() + send_message(message) -- 2.30.2 From ec0cb0c5badb29607e954015809a739bcfa4beec Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Thu, 13 Apr 2023 14:09:00 -0700 Subject: [PATCH 3/4] updated attachcheck to work with python 3.11 seems like any regex that uses global options needs to move them to the beginning of the regex now. this affected 3 regexes in attachcheck --- attachcheck | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/attachcheck b/attachcheck index 5580a32..86f110a 100755 --- a/attachcheck +++ b/attachcheck @@ -34,8 +34,8 @@ 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)(?im)' ] +attachment_regexes = [ r'(?im)\battach(ed|ment|ing)?\b', + r'(?im)\balleg(o|at[oaie]|ando)' ] # ignore quoted text (which might refer to attachments in previous emails) attachment_regexes = [ r'(^|^[^\n>].*)' + x for x in attachment_regexes ] @@ -109,8 +109,8 @@ for part in message.walk(): attachment_expected = True # check to see if this mime-type is something we can ignore - elif ( re.match( r'message/(?m)', part.get_content_type() ) or - re.match( r'multipart/(?m)', part.get_content_type() ) or + elif ( re.match( r'(?m)message/', part.get_content_type() ) or + re.match( r'(?m)multipart/', part.get_content_type() ) or part.get_content_type() in ignored_types ): continue -- 2.30.2 From 1bd2db6d6595e4290aa867a8099da6e7820aacd1 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Thu, 13 Apr 2023 14:11:28 -0700 Subject: [PATCH 4/4] minor tweak to make the last patch actually land... --- attachcheck | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/attachcheck b/attachcheck index 86f110a..19159e4 100755 --- a/attachcheck +++ b/attachcheck @@ -34,11 +34,11 @@ 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'(?im)\battach(ed|ment|ing)?\b', - r'(?im)\balleg(o|at[oaie]|ando)' ] +attachment_regexes = [ r'\battach(ed|ment|ing)?\b', + r'\balleg(o|at[oaie]|ando)' ] # ignore quoted text (which might refer to attachments in previous emails) -attachment_regexes = [ r'(^|^[^\n>].*)' + x for x in attachment_regexes ] +attachment_regexes = [ r'(?im)(^|^[^\n>].*)' + x for x in attachment_regexes ] ### No Edit Below This Line ########################################### -- 2.30.2