Changeset 278 for trunk/email2trac.py.in


Ignore:
Timestamp:
08/25/09 11:53:01 (15 years ago)
Author:
bas
Message:

email2trac.py.in:

  • added new parameter and feature to drop the HTML version of multipart/alternative message part, closes #30 keyword: drop_alternative_html_version default is 0
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r276 r278  
    230230                        self.REFLOW = 1
    231231
     232                if parameters.has_key('drop_alternative_html_version'):
     233                        self.DROP_ALTERNATIVE_HTML_VERSION = int(parameters['drop_alternative_html_version'])
     234                else:
     235                        self.DROP_ALTERNATIVE_HTML_VERSION = 0
     236
    232237                if parameters.has_key('strip_signature'):
    233238                        self.STRIP_SIGNATURE = int(parameters['strip_signature'])
     
    11041109                appledouble_parts = []
    11051110
     1111                ALTERNATIVE_MULTIPART = False
     1112
    11061113                for part in msg.walk():
    11071114                        if self.DEBUG:
     1115                                print 'TD: Message part: Main-Type: %s' % part.get_content_maintype()
    11081116                                print 'TD: Message part: Content-Type: %s' % part.get_content_type()
    1109                                
     1117
     1118
    11101119                        # Check whether we just finished processing an AppleDouble container
    11111120                        if part not in appledouble_parts:
    11121121                                appledouble_parts = []
    11131122
    1114                         # Special handling for BinHex attachments. Options are drop (leave out with no warning), warn (and leave out), and keep
     1123                        ## Check content type
     1124                        #
    11151125                        if part.get_content_type() == 'application/mac-binhex40':
     1126                                #
     1127                                # Special handling for BinHex attachments. Options are drop (leave out with no warning), warn (and leave out), and keep
     1128                                #
    11161129                                if self.BINHEX == 'warn':
    11171130                                        message_parts.append("'''A BinHex attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
     
    11201133                                        continue
    11211134
    1122                         # Special handling for AppleSingle attachments. Options are drop (leave out with no warning), warn (and leave out), and keep
    1123                         if part.get_content_type() == 'application/applefile' and not part in appledouble_parts:
    1124                                 if self.APPLESINGLE == 'warn':
    1125                                         message_parts.append("'''An AppleSingle attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
    1126                                         continue
    1127                                 elif self.APPLESINGLE == 'drop':
    1128                                         continue
    1129 
    1130                         # Special handling for the Mac-specific part of AppleDouble attachments. Options are strip (leave out with no warning), warn (and leave out), and keep
    1131                         if part.get_content_type() == 'application/applefile':
    1132                                 if self.APPLEDOUBLE == 'warn':
    1133                                         message_parts.append("'''The resource fork of an attachment named '%s' was removed.'''" % part.get_filename())
    1134                                         continue
    1135                                 elif self.APPLEDOUBLE == 'strip':
    1136                                         continue
    1137 
    1138                         # If we entering an AppleDouble container, set up appledouble_parts so that we know what to do with its subparts
    1139                         if part.get_content_type() == 'multipart/appledouble':
     1135                        elif part.get_content_type() == 'application/applefile':
     1136                                #
     1137                                # 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
     1138                                #
     1139                               
     1140                                if part in appledouble_parts:
     1141                                        if self.APPLEDOUBLE == 'warn':
     1142                                                message_parts.append("'''The resource fork of an attachment named '%s' was removed.'''" % part.get_filename())
     1143                                                continue
     1144                                        elif self.APPLEDOUBLE == 'strip':
     1145                                                continue
     1146                                else:
     1147                                        if self.APPLESINGLE == 'warn':
     1148                                                message_parts.append("'''An AppleSingle attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
     1149                                                continue
     1150                                        elif self.APPLESINGLE == 'drop':
     1151                                                continue
     1152
     1153                        elif part.get_content_type() == 'multipart/appledouble':
     1154                                #
     1155                                # If we entering an AppleDouble container, set up appledouble_parts so that we know what to do with its subparts
     1156                                #
    11401157                                appledouble_parts = part.get_payload()
    11411158                                continue
    11421159
    1143                         # Any other multipart/* is just a container for multipart messages
     1160                        elif part.get_content_type() == 'multipart/alternative':
     1161                                ALTERNATIVE_MULTIPART = True
     1162                                continue
     1163
     1164                        # Skip multipart containers
     1165                        #
    11441166                        if part.get_content_maintype() == 'multipart':
     1167                                if self.DEBUG:
     1168                                        print "TD: Skipping multipart container"
    11451169                                continue
    1146 
     1170                       
    11471171                        # 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"
    11481172                        inline = self.inline_part(part)
     1173
     1174                        # Drop HTML message
     1175                        if ALTERNATIVE_MULTIPART and self.DROP_ALTERNATIVE_HTML_VERSION:
     1176                                if part.get_content_type() == 'text/html':
     1177                                        if self.DEBUG:
     1178                                                print "TD: Skipping alternative HTML message"
     1179
     1180                                        ALTERNATIVE_MULTIPART = False
     1181                                        continue
    11491182
    11501183                        # Inline text parts are where the body is
Note: See TracChangeset for help on using the changeset viewer.