Changeset 238 for trunk/email2trac.py.in


Ignore:
Timestamp:
12/05/08 06:12:25 (15 years ago)
Author:
bromine
Message:

email2trac.py.in:

  • more versatile handling of Mac attachments; closes #106
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r237 r238  
    244244                        self.USE_TEXTWRAP = 0
    245245
     246                if parameters.has_key('binhex'):
     247                        self.BINHEX = parameters['binhex']
     248                else:
     249                        self.BINHEX = 'warn'
     250
     251                if parameters.has_key('applesingle'):
     252                        self.APPLESINGLE = parameters['applesingle']
     253                else:
     254                        self.APPLESINGLE = 'warn'
     255
     256                if parameters.has_key('appledouble'):
     257                        self.APPLEDOUBLE = parameters['appledouble']
     258                else:
     259                        self.APPLEDOUBLE = 'warn'
     260
    246261                if parameters.has_key('python_egg_cache'):
    247262                        self.python_egg_cache = str(parameters['python_egg_cache'])
     
    980995                """
    981996                message_parts = []
     997               
     998                # This is used to figure out when we are inside an AppleDouble container
     999                # AppleDouble containers consists of two parts: Mac-specific file data, and platform-independent data
     1000                # We strip away Mac-specific stuff
     1001                appledouble_parts = []
    9821002
    9831003                for part in msg.walk():
    984                         # 'multipart/*' is a container for multipart messages
    985                         #
    9861004                        if self.DEBUG:
    9871005                                print 'TD: Message part: Content-Type: %s' % part.get_content_type()
    988 
     1006                               
     1007                        # Check whether we just finished processing an AppleDouble container
     1008                        if part not in appledouble_parts:
     1009                                appledouble_parts = []
     1010
     1011                        # Special handling for BinHex attachments. Options are drop (leave out with no warning), warn (and leave out), and keep
     1012                        if part.get_content_type() == 'application/mac-binhex40':
     1013                                if self.BINHEX == 'warn':
     1014                                        message_parts.append("'''A BinHex attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
     1015                                        continue
     1016                                elif self.BINHEX == 'drop':
     1017                                        continue
     1018
     1019                        # Special handling for AppleSingle attachments. Options are drop (leave out with no warning), warn (and leave out), and keep
     1020                        if part.get_content_type() == 'application/applefile' and not part in appledouble_parts:
     1021                                if self.APPLESINGLE == 'warn':
     1022                                        message_parts.append("'''An AppleSingle attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
     1023                                        continue
     1024                                elif self.APPLESINGLE == 'drop':
     1025                                        continue
     1026
     1027                        # Special handling for the Mac-specific part of AppleDouble attachments. Options are strip (leave out with no warning), warn (and leave out), and keep
     1028                        if part.get_content_type() == 'application/applefile':
     1029                                if self.APPLEDOUBLE == 'warn':
     1030                                        message_parts.append("'''The resource fork of an attachment named '%s' was removed.'''" % part.get_filename())
     1031                                        continue
     1032                                elif self.APPLEDOUBLE == 'strip':
     1033                                        continue
     1034
     1035                        # If we entering an AppleDouble container, set up appledouble_parts so that we know what to do with its subparts
     1036                        if part.get_content_type() == 'multipart/appledouble':
     1037                                appledouble_parts = part.get_payload()
     1038                                continue
     1039
     1040                        # Any other multipart/* is just a container for multipart messages
    9891041                        if part.get_content_maintype() == 'multipart':
    9901042                                continue
Note: See TracChangeset for help on using the changeset viewer.