コード例 #1
0
ファイル: attachment.py プロジェクト: alephdata/msglite
    def __init__(self, msg, dir_):
        """
        :param msg: the Message instance that the attachment belongs to.
        :param dir_: the directory inside the msg file where the attachment is
            located.
        """
        self.msg = msg
        self.dir = dir_
        stream = self._getStream("__properties_version1.0")
        self.props = Properties(stream, constants.TYPE_ATTACHMENT)

        # Get display name
        self.title = self._getStringStream("__substg1.0_3001")

        # Get extension
        self.extension = self._getStringStream("__substg1.0_3703")

        # Get long filename
        self.long_filename = self._getStringStream("__substg1.0_3707")

        # Get short filename
        self.short_filename = self._getStringStream("__substg1.0_3704")

        # Get Content-ID
        self.cid = self._getStringStream("__substg1.0_3712")

        # Get MIME type
        self.content_type = self._getStringStream("__substg1.0_370E")

        # Get attachment data
        self.data = None

        # MS-OXPROPS 2.601, MS-OXCMSG 2.2.2.9:
        self.method = self.props.get("37050003")
        if self.method is not None:
            self.method = self.method.value & 0x7

        self.type = "data"
        # cf. MS-OXCMSG 2.2.2.9 PidTagAttachMethod Property
        # TODO Handling for special attachment types (like 7)
        if self.method == 0x5:
            prefix = join_path(msg.prefix, dir_, "__substg1.0_3701000D")
            self.type = "msg"
            self.data = msg.__class__(
                self.msg.path,
                prefix=prefix,
                ole=msg.ole,
                filename=self.get_filename(),
                encoding=self.msg.encoding,
            )
        else:
            self.data = self._getStream("__substg1.0_37010102")
            if self.data is None:
                path = join_path("__substg1.0_3701000D", "CONTENTS")
                self.data = self._getStream(path)

        if self.data is None:
            log.warning("Empty attachment: %r", self)
            self.type = None
コード例 #2
0
 def __init__(self, msg, dir_):
     self.dir = dir_
     stream = msg._getStream(join_path(dir_, "__properties_version1.0"))
     self.props = Properties(stream, constants.TYPE_RECIPIENT)
     self.email = msg._getStringStream(join_path(dir_, "__substg1.0_39FE"))
     if not self.email:
         self.email = msg._getStringStream(
             join_path(dir_, "__substg1.0_3003"))
     self.name = msg._getStringStream(join_path(dir_, "__substg1.0_3001"))
     self.type = self.props.get("0C150003").value
     self.formatted = format_party(self.email, self.name)
コード例 #3
0
 def _getStream(self, filename):
     filename = join_path(self.prefix, filename)
     try:
         with self.ole.openstream(filename) as stream:
             return stream.read()
     except OSError:
         return None
コード例 #4
0
 def _getStringStream(self, filename):
     """
     Gets a string representation of the requested filename.
     Checks for both ASCII and Unicode representations and returns
     a value if possible.  If there are both ASCII and Unicode
     versions, then :param prefer: specifies which will be
     returned.
     """
     return self.msg._getStringStream(join_path(self.dir, filename))
コード例 #5
0
    def __init__(self, msg, dir_):
        """
        :param msg: the Message instance that the attachment belongs to.
        :param dir_: the directory inside the msg file where the attachment is
            located.
        """
        self.msg = msg
        self.dir = dir_
        stream = self._getStream("__properties_version1.0")
        self.props = Properties(stream, constants.TYPE_ATTACHMENT)

        # Get long filename
        self.longFilename = self._getStringStream("__substg1.0_3707")

        # Get short filename
        self.shortFilename = self._getStringStream("__substg1.0_3704")

        # Get Content-ID
        self.cid = self._getStringStream("__substg1.0_3712")

        # Get attachment data
        self.data = None
        if self.exists("__substg1.0_37010102"):
            self.type = "data"
            self.data = self._getStream("__substg1.0_37010102")
        elif self.exists("__substg1.0_3701000D"):
            if (self.props["37050003"].value & 0x7) != 0x5:
                raise TypeError("Container is not an embedded msg file.")
            prefix = join_path(msg.prefix, dir_, "__substg1.0_3701000D")
            self.type = "msg"
            self.data = msg.__class__(
                self.msg.path,
                prefix=prefix,
                ole=msg.ole,
                filename=self.getDefaultFilename(),
            )
        else:
            # TODO Handling for special attachment types (like 0x00000007)
            raise TypeError("Unknown attachment type.")
コード例 #6
0
 def exists(self, inp):
     """Checks if :param inp: exists in the msg file."""
     return self.ole.exists(join_path(self.prefix, inp))
コード例 #7
0
 def exists(self, filename):
     """
     Checks if stream exists inside the attachment folder.
     """
     return self.msg.exists(join_path(self.dir, filename))
コード例 #8
0
 def _getStream(self, filename):
     return self.msg._getStream(join_path(self.dir, filename))
コード例 #9
0
ファイル: attachment.py プロジェクト: alephdata/msglite
 def _getStringStream(self, filename):
     """Gets a string representation of the requested filename."""
     return self.msg._getStringStream(join_path(self.dir, filename))