예제 #1
0
 def __init__(self, filename):
     OleFileIO.__init__(self, filename)
예제 #2
0
    def __init__(self, path, prefix='', filename=None):
        """
        :param path: path to the msg file in the system or is the raw msg file.
        :param prefix: used for extracting embeded msg files
            inside the main one. Do not set manually unless
            you know what you are doing.
        :param filename: optional, the filename to be used by default when
            saving.
        """
        self.path = path
        OleFileIO.__init__(self, path)
        prefixl = []
        tmp_condition = prefix != ''
        if tmp_condition:
            if not isinstance(prefix, str):
                try:
                    prefix = '/'.join(prefix)
                except Exception:
                    raise TypeError('Invalid prefix: ' + str(type(prefix)))
            prefix = prefix.replace('\\', '/')
            g = prefix.split("/")
            if g[-1] == '':
                g.pop()
            prefixl = g
            if prefix[-1] != '/':
                prefix += '/'
        self.prefix = prefix
        self.__prefixList = prefixl

        # Parse the main props
        prop_type = constants.TYPE_MESSAGE_EMBED
        if self.prefix == '':
            prop_type = constants.TYPE_MESSAGE
        propdata = self._getStream('__properties_version1.0')
        self.mainProperties = Properties(propdata, prop_type)

        # Determine if the message is unicode-style:
        # PidTagStoreSupportMask
        self.is_unicode = False
        if '340D0003' in self.mainProperties:
            value = self.mainProperties['340D0003'].value
            self.is_unicode = (value & 0x40000) != 0

        self.encoding = self.guessEncoding()
        if '66C30003' in self.mainProperties:
            # PidTagCodePageId
            codepage = self.mainProperties['66C30003'].value
            self.encoding = get_encoding(codepage, self.encoding)
        if '3FFD0003' in self.mainProperties:
            # PidTagMessageCodepage
            codepage = self.mainProperties['3FFD0003'].value
            self.encoding = get_encoding(codepage, self.encoding)

        # Determine file name (is this needed?)
        if tmp_condition:
            addr = prefixl[:-1] + ['__substg1.0_3001']
            filename = self._getStringStream(addr, prefix=False)
        if filename is not None:
            self.filename = filename
        elif path is not None:
            if len(path) < 1536:
                self.filename = path
            else:
                self.filename = None
        else:
            self.filename = None

        log.debug('Message encoding: %s', self.encoding)
        self.header = self.parseHeader()
        self.recipients = self.parseRecipients()
        self.attachments = self.parseAttachments()
        self.subject = self._getStringStream('__substg1.0_0037')
        self.date = self.mainProperties.date