Changeset 294


Ignore:
Timestamp:
01/06/10 13:18:48 (14 years ago)
Author:
bas
Message:

email2trac.py.in:

  • added new configuration parameter, strip_content_types thanks to Otto. eg:

strip_content_types: application/pgp-signature, application/mac-binhex40

Will skip pgp signature attachments and apple binhex40 attachments, closes #68

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r292 r294  
    132132                self.author     = None
    133133                self.id         = None
     134               
     135                self.STRIP_CONTENT_TYPES = list()
    134136
    135137                self.VERSION = version
     
    236238
    237239                if parameters.has_key('binhex'):
    238                         self.BINHEX = parameters['binhex']
    239                 else:
    240                         self.BINHEX = 'warn'
     240                        self.STRIP_CONTENT_TYPES.append('application/mac-binhex40')
    241241
    242242                if parameters.has_key('applesingle'):
    243                         self.APPLESINGLE = parameters['applesingle']
    244                 else:
    245                         self.APPLESINGLE = 'warn'
     243                        self.STRIP_CONTENT_TYPES.append('application/applefile')
    246244
    247245                if parameters.has_key('appledouble'):
    248                         self.APPLEDOUBLE = parameters['appledouble']
    249                 else:
    250                         self.APPLEDOUBLE = 'warn'
     246                        self.STRIP_CONTENT_TYPES.append('application/applefile')
     247
     248                if parameters.has_key('strip_content_types'):
     249                        items = parameters['strip_content_types'].split(',')
     250                        for item in items:
     251                                self.STRIP_CONTENT_TYPES.append(item.strip())
    251252
    252253                self.WORKFLOW = None
     
    10881089                """
    10891090                message_parts = []
    1090                
    1091                 # This is used to figure out when we are inside an AppleDouble container
    1092                 # AppleDouble containers consists of two parts: Mac-specific file data, and platform-independent data
    1093                 # We strip away Mac-specific stuff
    1094                 appledouble_parts = []
    1095 
     1091       
    10961092                ALTERNATIVE_MULTIPART = False
    10971093
     
    11011097                                print 'TD: Message part: Content-Type: %s' % part.get_content_type()
    11021098
    1103 
    1104                         # Check whether we just finished processing an AppleDouble container
    1105                         if part not in appledouble_parts:
    1106                                 appledouble_parts = []
    1107 
    11081099                        ## Check content type
    1109                         #
    1110                         if part.get_content_type() == 'application/mac-binhex40':
    1111                                 #
    1112                                 # Special handling for BinHex attachments. Options are drop (leave out with no warning), warn (and leave out), and keep
    1113                                 #
    1114                                 if self.BINHEX == 'warn':
    1115                                         message_parts.append("'''A BinHex attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
    1116                                         continue
    1117                                 elif self.BINHEX == 'drop':
    1118                                         continue
    1119 
    1120                         elif part.get_content_type() == 'application/applefile':
    1121                                 #
    1122                                 # Special handling for the Mac-specific part of AppleDouble/AppleSingle attachments. Options are strip (leave out with no warning), warn (and leave out), and keep
    1123                                 #
    1124                                
    1125                                 if part in appledouble_parts:
    1126                                         if self.APPLEDOUBLE == 'warn':
    1127                                                 message_parts.append("'''The resource fork of an attachment named '%s' was removed.'''" % part.get_filename())
    1128                                                 continue
    1129                                         elif self.APPLEDOUBLE == 'strip':
    1130                                                 continue
    1131                                 else:
    1132                                         if self.APPLESINGLE == 'warn':
    1133                                                 message_parts.append("'''An AppleSingle attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
    1134                                                 continue
    1135                                         elif self.APPLESINGLE == 'drop':
    1136                                                 continue
    1137 
    1138                         elif part.get_content_type() == 'multipart/appledouble':
    1139                                 #
    1140                                 # If we entering an AppleDouble container, set up appledouble_parts so that we know what to do with its subparts
    1141                                 #
    1142                                 appledouble_parts = part.get_payload()
     1100                        #
     1101                        if part.get_content_type() in self.STRIP_CONTENT_TYPES:
     1102
     1103                                if self.DEBUG:
     1104                                        print "TD: A %s attachment named '%s' was skipped" %(part.get_content_type(), part.get_filename())
     1105
    11431106                                continue
    11441107
    1145                         elif part.get_content_type() == 'multipart/alternative':
     1108                        ## Catch some mulitpart execptions
     1109                        #
     1110                        if part.get_content_type() == 'multipart/alternative':
    11461111                                ALTERNATIVE_MULTIPART = True
    11471112                                continue
    11481113
    1149                         # Skip multipart containers
     1114                        ## Skip multipart containers
    11501115                        #
    11511116                        if part.get_content_maintype() == 'multipart':
     
    11541119                                continue
    11551120                       
    1156                         # Check if this is an inline part. It's inline if there is co Cont-Disp header, or if there is one and it says "inline"
     1121                        ## Check if this is an inline part. It's inline if there is co Cont-Disp header, or if there is one and it says "inline"
     1122                        #
    11571123                        inline = self.inline_part(part)
    11581124
    1159                         # Drop HTML message
     1125                        ## Drop HTML message
     1126                        #
    11601127                        if ALTERNATIVE_MULTIPART and self.DROP_ALTERNATIVE_HTML_VERSION:
    11611128                                if part.get_content_type() == 'text/html':
     
    11661133                                        continue
    11671134
    1168                         # Inline text parts are where the body is
     1135                        ## Inline text parts are where the body is
     1136                        #
    11691137                        if part.get_content_type() == 'text/plain' and inline:
    11701138                                if self.DEBUG:
     
    11921160                                        body_text = self.wrap_text(body_text)
    11931161
    1194                                 # Get contents charset (iso-8859-15 if not defined in mail headers)
     1162                                ## Get contents charset (iso-8859-15 if not defined in mail headers)
    11951163                                #
    11961164                                charset = part.get_content_charset()
Note: See TracChangeset for help on using the changeset viewer.