Exemple #1
0
 def __init__(self,
              path,
              prefix='',
              attachmentClass=Attachment,
              filename=None,
              delayAttachments=False):
     """
     :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 attachmentClass: optional, the class the Message object
         will use for attachments. You probably should
         not change this value unless you know what you
         are doing.
     :param filename: optional, the filename to be used by default when saving.
     :param delayAttachments: optional, delays the initialization of attachments
         until the user attempts to retrieve them. Allows MSG files with bad
         attachments to be initialized so the other data can be retrieved.
     """
     MSGFile.__init__(self, path, prefix, attachmentClass, filename)
     # Initialize properties in the order that is least likely to cause bugs.
     # TODO have each function check for initialization of needed data so these
     # lines will be unnecessary.
     self.mainProperties
     self.header
     self.recipients
     if not delayAttachments:
         self.attachments
     self.to
     self.cc
     self.sender
     self.date
     self.__crlf = '\n'  # This variable keeps track of what the new line character should be
     self.body
Exemple #2
0
 def close(self):
     try:
         self._attachments
         for attachment in self.attachments:
             if attachment.type == 'msg':
                 attachment.data.close()
     except AttributeError:
         pass
     MSGFile.close(self)
Exemple #3
0
 def __init__(self,
              path,
              prefix='',
              attachmentClass=Attachment,
              filename=None,
              overrideEncoding=None):
     MSGFile.__init__(self, path, prefix, attachmentClass, filename,
                      overrideEncoding)
     self.named
Exemple #4
0
def openMsg(path, prefix = '', attachmentClass = None, filename = None, delayAttachments = False, overrideEncoding = None, attachmentErrorBehavior = constants.ATTACHMENT_ERROR_THROW, strict = True):
    """
    Function to automatically open an MSG file and detect what type it is.

    :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 attachmentClass: optional, the class the Message object
        will use for attachments. You probably should
        not change this value unless you know what you
        are doing.
    :param filename: optional, the filename to be used by default when saving.
    :param delayAttachments: optional, delays the initialization of attachments
        until the user attempts to retrieve them. Allows MSG files with bad
        attachments to be initialized so the other data can be retrieved.

    If :param strict: is set to `True`, this function will raise an exception
    when it cannot identify what MSGFile derivitive to use. Otherwise, it will
    log the error and return a basic MSGFile instance.
    """
    from extract_msg.appointment import Appointment
    from extract_msg.attachment import Attachment
    from extract_msg.contact import Contact
    from extract_msg.message import Message
    from extract_msg.msg import MSGFile

    attachmentClass = Attachment if attachmentClass is None else attachmentClass

    msg = MSGFile(path, prefix, attachmentClass, filename, overrideEncoding, attachmentErrorBehavior)
    classtype = msg.classType
    if classtype.startswith('IPM.Contact') or classtype.startswith('IPM.DistList'):
        msg.close()
        return Contact(path, prefix, attachmentClass, filename, overrideEncoding, attachmentErrorBehavior)
    elif classtype.startswith('IPM.Note') or classtype.startswith('REPORT'):
        msg.close()
        return Message(path, prefix, attachmentClass, filename, delayAttachments, overrideEncoding, attachmentErrorBehavior)
    elif classtype.startswith('IPM.Appointment') or classtype.startswith('IPM.Schedule'):
        msg.close()
        return Appointment(path, prefix, attachmentClass, filename, delayAttachments, overrideEncoding, attachmentErrorBehavior)
    elif strict:
        msg.close()
        raise UnrecognizedMSGTypeError('Could not recognize msg class type "{}". It is recommended you report this to the developers.'.format(msg.classType))
    else:
        logger.error('Could not recognize msg class type "{}". It is recommended you report this to the developers.'.format(msg.classType))
        return msg
Exemple #5
0
 def __init__(self, path, prefix = '', attachmentClass = Attachment, filename = None):
     MSGFile.__init__(self, path, prefix, attachmentClass, filename)
 def __init__(self, path, prefix = '', attachmentClass = Attachment, filename = None, overrideEncoding = None, attachmentErrorBehavior = constants.ATTACHMENT_ERROR_THROW):
     MSGFile.__init__(self, path, prefix, attachmentClass, filename, overrideEncoding, attachmentErrorBehavior)
     self.named