Please review this patch. I don’t know whether I got the syntax right. I think
the logic is ok. ;-)
If there were a test bench for this script I would use it…
The idea is to reject file names that begin with ‘-‘ and types that are known
bad.
Index: secmail.py
===================================================================
--- secmail.py (revision 974086)
+++ secmail.py (working copy)
@@ -180,8 +180,17 @@
if len(subpayload.get_payload(decode=True))<10240: continue
# if not subpayload.get_payload(decode=True): continue
- # get_filename doesn't appear to have an endswith method
- # if subpayload.get_filename().endswith('.gpg'): continue
+ # analyze file name and type
+ filename = subpayload.get_filename()
+ splitname = filename.split('.')
+ if len(splitname) < 2: continue
+ filebase = splitname[len(splitname) - 2]
+ filetype = splitname[len(splitname) - 1]
+ if filebase[0] == '-': continue
+
+ rejecttypes = ['zip', 'doc', 'docx', 'xls', 'gpg']
+ if filetype in rejecttypes: continue
+
attachments.append(subpayload)
if len(attachments) == 0: return
Craig L Russell
Architect, Oracle
http://db.apache.org/jdo
408 276-5638 mailto:[email protected]
P.S. A good JDO? O, Gasp!