コード例 #1
0
    def parse_postmark(self, obj):
        from_field = (obj['FromFull']['Name'], obj['FromFull']['Email'])
        tos = [(o['Name'], o['Email']) for o in obj['ToFull']]
        ccs = [(o['Name'], o['Email']) for o in obj['CcFull']]
        attachments = []
        for a in obj['Attachments']:
            attachment = BytesIO(base64.b64decode(a['Content']))
            attachment.content_type = a['ContentType']
            attachment.size = a['ContentLength']
            attachment.name = a['Name']
            attachment.create_date = None
            attachment.mod_date = None
            attachment.read_date = None
            attachments.append(attachment)

        return {
            'msgobj': obj,
            'date': self.parse_date(obj['Date']),
            'subject': obj['Subject'],
            'body': obj['TextBody'],
            'html': obj['HtmlBody'],
            'from': from_field,
            'to': tos,
            'cc': ccs,
            'resent_to': [],
            'resent_cc': [],
            'attachments': attachments
        }
コード例 #2
0
ファイル: email_utils.py プロジェクト: gabelula/froide
    def parse_postmark(self, obj):
        from_field = (obj["FromFull"]["Name"], obj["FromFull"]["Email"])
        tos = [(o["Name"], o["Email"]) for o in obj["ToFull"]]
        ccs = [(o["Name"], o["Email"]) for o in obj["CcFull"]]
        attachments = []
        for a in obj["Attachments"]:
            attachment = BytesIO(base64.b64decode(a["Content"]))
            attachment.content_type = a["ContentType"]
            attachment.size = a["ContentLength"]
            attachment.name = a["Name"]
            attachment.create_date = None
            attachment.mod_date = None
            attachment.read_date = None
            attachments.append(attachment)

        return {
            "msgobj": obj,
            "date": self.parse_date(obj["Date"]),
            "subject": obj["Subject"],
            "body": obj["TextBody"],
            "html": obj["HtmlBody"],
            "from": from_field,
            "to": tos,
            "cc": ccs,
            "resent_to": [],
            "resent_cc": [],
            "attachments": attachments,
        }
コード例 #3
0
    def parse_attachment(self, message_part):
        content_disposition = message_part.get("Content-Disposition", None)
        if content_disposition:
            dispo_type, dispo_dict = self.parse_dispositions(
                content_disposition)
            if dispo_type == "attachment" or (dispo_type == 'inline'
                                              and 'filename' in dispo_dict):
                content_type = message_part.get("Content-Type", None)
                file_data = message_part.get_payload(decode=True)
                if file_data is None:
                    payloads = message_part.get_payload()
                    file_data = '\n\n'.join([p.as_string() for p in payloads])
                    try:
                        file_data = file_data.encode('utf-8')
                    except:
                        pass

                attachment = BytesIO(file_data)
                attachment.content_type = message_part.get_content_type()
                attachment.size = len(file_data)
                attachment.name = None
                attachment.create_date = None
                attachment.mod_date = None
                attachment.read_date = None
                if "filename" in dispo_dict:
                    attachment.name = dispo_dict['filename']
                if content_type:
                    _, content_dict = self.parse_dispositions(content_type)
                    if 'name' in content_dict:
                        attachment.name = content_dict['name']
                if attachment.name is None and content_type == 'message/rfc822':
                    p = Parser()
                    msgobj = p.parse(BytesIO(attachment.getvalue()))
                    subject = self.parse_header_field(msgobj['Subject'])
                    if subject:
                        attachment.name = '%s.eml' % subject[:45]
                if "create-date" in dispo_dict:
                    attachment.create_date = dispo_dict[
                        'create-date']  # TODO: datetime
                if "modification-date" in dispo_dict:
                    attachment.mod_date = dispo_dict[
                        'modification-date']  # TODO: datetime
                if "read-date" in dispo_dict:
                    attachment.read_date = dispo_dict[
                        'read-date']  # TODO: datetime
                return attachment
        return None
    def parse_attachment(self, message_part):
        content_disposition = message_part.get("Content-Disposition", None)
        if content_disposition:
            dispo_type, dispo_dict = self.parse_dispositions(content_disposition)
            if dispo_type == "attachment" or (dispo_type == 'inline' and
                    'filename' in dispo_dict):
                content_type = message_part.get("Content-Type", None)
                file_data = message_part.get_payload(decode=True)
                if file_data is None:
                    payloads = message_part.get_payload()
                    file_data = '\n\n'.join([p.as_string() for p in payloads])
                    try:
                        file_data = file_data.encode('utf-8')
                    except:
                        pass

                attachment = BytesIO(file_data)
                attachment.content_type = message_part.get_content_type()
                attachment.size = len(file_data)
                attachment.name = None
                attachment.create_date = None
                attachment.mod_date = None
                attachment.read_date = None
                if "filename" in dispo_dict:
                    attachment.name = dispo_dict['filename']
                if content_type:
                    _, content_dict = self.parse_dispositions(content_type)
                    if 'name' in content_dict:
                        attachment.name = content_dict['name']
                if attachment.name is None and content_type == 'message/rfc822':
                    p = Parser()
                    msgobj = p.parse(BytesIO(attachment.getvalue()))
                    subject = self.parse_header_field(msgobj['Subject'])
                    if subject:
                        attachment.name = '%s.eml' % subject[:45]
                if "create-date" in dispo_dict:
                    attachment.create_date = dispo_dict['create-date']  # TODO: datetime
                if "modification-date" in dispo_dict:
                    attachment.mod_date = dispo_dict['modification-date']  # TODO: datetime
                if "read-date" in dispo_dict:
                    attachment.read_date = dispo_dict['read-date']  # TODO: datetime
                return attachment
        return None
コード例 #5
0
ファイル: email_utils.py プロジェクト: gabelula/froide
 def parse_attachment(self, message_part):
     content_disposition = message_part.get("Content-Disposition", None)
     if content_disposition:
         dispo_type, dispo_dict = self.parse_dispositions(content_disposition)
         if dispo_type == "attachment" or (dispo_type == "inline" and "filename" in dispo_dict):
             content_type = message_part.get("Content-Type", None)
             file_data = message_part.get_payload(decode=True)
             if file_data is None:
                 payloads = message_part.get_payload()
                 file_data = "\n\n".join([p.as_string() for p in payloads]).encode("utf-8")
             attachment = BytesIO(file_data)
             attachment.content_type = message_part.get_content_type()
             attachment.size = len(file_data)
             attachment.name = None
             attachment.create_date = None
             attachment.mod_date = None
             attachment.read_date = None
             if "filename" in dispo_dict:
                 attachment.name = dispo_dict["filename"]
             if content_type:
                 _, content_dict = self.parse_dispositions(content_type)
                 if "name" in content_dict:
                     attachment.name = content_dict["name"]
             if attachment.name is None and content_type == "message/rfc822":
                 p = Parser()
                 msgobj = p.parse(BytesIO(attachment.getvalue()))
                 subject = self.parse_header_field(msgobj["Subject"])
                 if subject:
                     attachment.name = "%s.eml" % subject[:45]
             if "create-date" in dispo_dict:
                 attachment.create_date = dispo_dict["create-date"]  # TODO: datetime
             if "modification-date" in dispo_dict:
                 attachment.mod_date = dispo_dict["modification-date"]  # TODO: datetime
             if "read-date" in dispo_dict:
                 attachment.read_date = dispo_dict["read-date"]  # TODO: datetime
             return attachment
     return None