def _full_ext_body(self): extbody = ExtBodyContent() extbody.char_set = self.charset extbody.local_id = CommonMethods.increment_local_id() extbody.gid = "{0:0>5}_{1}".format(extbody.local_id, extbody.gid) extbody.transfer_encoding = self.transfer_encoding extbody.eol = CommonMethods.get_eol(self.payload.get_payload()) extbody.hash = CommonMethods.get_hash(self.payload.as_bytes()) extbody.body_content = self.payload.get_payload() children = OrderedDict({ "ContentType": self.content_type, "Disposition": self.disposition, "DispositionFileName": self.disposition_file_name, "ContentTransferEncoding": self.transfer_encoding }) extbody.build_xml_file(children) self.ext_body_content.append(extbody) self.payload = None
def __init__(self, rel_path, local_id, message, fn=None): """Constructor for Message""" self.logger = logging.getLogger("MessageType") self.message = message # type: Message self.fn = fn # First parts of the schema message-type self.relative_path = rel_path # type: str self.local_id = local_id self.message_id = CommonMethods.cdata_wrap( self.message.get("Message-ID")) # type: str if self.message_id == '' or self.message_id is None: self.message_id = 'No Message-ID supplied' self.mime_version = CommonMethods.cdata_wrap( self.message.get("MIME-Version")) # type: str self.incomplete = [] # type: list[IncompleteParse] # xm:message-headers xml_d = CommonMethods.tup_to_xml_date( CommonMethods.parsedate_tz(self.message.get("Date"))) self.orig_date = xml_d # type: str self.m_from = CommonMethods.cdata_wrap( self.message.get("From")) # type: str self.sender = CommonMethods.cdata_wrap( self.message.get("Sender")) # type: str try: self.m_to = CommonMethods.cdata_wrap( self.message.get("To")) # type: str except TypeError as te: self.logger.error("{}".format(te)) self.incomplete.append( IncompleteParse('TypeError parsing To Header', te)) self.cc = CommonMethods.cdata_wrap(self.message.get("Cc")) # type: str self.bcc = CommonMethods.cdata_wrap( self.message.get("Bcc")) # type: str self.in_reply_to = CommonMethods.cdata_wrap( self.message.get("In-Reply-To")) self.references = CommonMethods.cdata_wrap( self.message.get("References")) # type: str self.comments = CommonMethods.cdata_wrap( self.message.get("Comments")) # type: str self.keywords = CommonMethods.cdata_wrap( self.message.get("Keywords")) # type: str try: self.subject = CommonMethods.cdata_wrap( self.message.get("Subject")) # type: str except TypeError as te: self.logger.error("{}".format(te)) self.incomplete.append( IncompleteParse('TypeError parsing Subject line', te)) try: self.status_flag = status.get( self.message.get("Status")) # type: str except Exception as e: self.incomplete.append( IncompleteParse('TypeError parsing Status', e)) self.headers = [] # type: list[Header] self.single_body = [] # type: list[SingleBody] self.multiple_body = [] # type: list[MultiBody] try: self.eol = CommonMethods.get_eol( self.message.as_string(policy=self.message.policy.clone( utf8=True))) # type: str except KeyError as e: self.logger.error("Inspect Message: KeyError {}".format( self.message.get("Message-ID"))) self.incomplete.append(IncompleteParse('KeyError parsing EOL', e)) except UnicodeEncodeError as ue: print(sys.gettrace()) self.logger.error("Inspect Message: UnicodeEncodeError {}".format( self.message.get("Message-ID"))) self.incomplete.append( IncompleteParse('UnicodeEncodeError parsing EOL', ue)) except LookupError as le: self.logger.error("Inspect Message: LookupError {}".format( self.message.get("Message-ID"))) self.incomplete.append( IncompleteParse('LookupError parsing EOL', le)) except Exception as er: self.incomplete.append( IncompleteParse('LookupError parsing EOL', er)) finally: self.eol = 'LF' self.hash = CommonMethods.get_hash( self.message.as_bytes()) # type: Hash self._process_headers() self._process_payload()