Ticket #106: mac-attachments.diff

File mac-attachments.diff, 3.2 KB (added by ben@…, 14 years ago)
  • private/var/folders/2l/2l213h3uF+8i8q5g7V96LE+++TI/Cleanup

     
    243243                else:
    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'])
    248263                        os.environ['PYTHON_EGG_CACHE'] = self.python_egg_cache
     
    978993                body parts are returned as strings, attachments are returned as tuples of (filename, Message object)
    979994                """
    980995                message_parts = []
     996               
     997                # This is used to figure out when we are inside an AppleDouble container
     998                # AppleDouble containers consists of two parts: Mac-specific file data, and platform-independent data
     999                # We strip away Mac-specific stuff
     1000                appledouble_parts = []
    9811001
    9821002                for part in msg.walk():
    983                         # 'multipart/*' is a container for multipart messages
    984                         #
    9851003                        if self.DEBUG:
    9861004                                print 'TD: Message part: Content-Type: %s' % part.get_content_type()
     1005                               
     1006                        # Check whether we just finished processing an AppleDouble container
     1007                        if part not in appledouble_parts:
     1008                                appledouble_parts = []
     1009
     1010                        # Special handling for BinHex attachments. Options are drop (leave out with no warning), warn (and leave out), and keep
     1011                        if part.get_content_type() == 'application/mac-binhex40':
     1012                                if self.BINHEX == 'warn':
     1013                                        message_parts.append("'''A BinHex attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
     1014                                        continue
     1015                                elif self.BINHEX == 'drop':
     1016                                        continue
     1017
     1018                        # Special handling for AppleSingle attachments. Options are drop (leave out with no warning), warn (and leave out), and keep
     1019                        if part.get_content_type() == 'application/applefile' and not part in appledouble_parts:
     1020                                if self.APPLESINGLE == 'warn':
     1021                                        message_parts.append("'''An AppleSingle attachment named '%s' was ignored (use MIME encoding instead).'''" % part.get_filename())
     1022                                        continue
     1023                                elif self.APPLESINGLE == 'drop':
     1024                                        continue
    9871025
     1026                        # Special handling for the Mac-specific part of AppleDouble attachments. Options are strip (leave out with no warning), warn (and leave out), and keep
     1027                        if part.get_content_type() == 'application/applefile':
     1028                                if self.APPLEDOUBLE == 'warn':
     1029                                        message_parts.append("'''The resource fork of an attachment named '%s' was removed.'''" % part.get_filename())
     1030                                        continue
     1031                                elif self.APPLEDOUBLE == 'strip':
     1032                                        continue
     1033
     1034                        # If we entering an AppleDouble container, set up appledouble_parts so that we know what to do with its subparts
     1035                        if part.get_content_type() == 'multipart/appledouble':
     1036                                appledouble_parts = part.get_payload()
     1037                                continue
     1038
     1039                        # Any other multipart/* is just a container for multipart messages
    9881040                        if part.get_content_maintype() == 'multipart':
    9891041                                continue
    9901042