imap_storage.storage.email package

Submodules

imap_storage.storage.email.address module

Address class

class imap_storage.storage.email.address.Address(display_name='', addr_spec=None)[source]

Bases: email.headerregistry.Address

Represents addresses mainly for the Email header

imap_storage.storage.email.body module

Body class

class imap_storage.storage.email.body.Body(xml_str)[source]

Bases: object

This class represents the Email body without physical attachments

add_item(tag, text=None, attribs=None, parent=None)[source]

Add new Child to body or some other parent :param tag: Tag name of the new item :param text: Text content of the new item :param attribs: Dictionary!!! {‘attribname’: ‘attribvalue’} :returns: reference to new item

get_by_tag(tag)[source]

Get xml item by tag :param tag: Tag to return :returns: List of tag items

new(tag='container')[source]

Create new Email body :param tag: Tag of the main node :returns: self

static new_id(count=8)[source]

Creates Unique ID :param count: Number of letters the id should have :returns: new uid

remove_item(id_)[source]

remove item from body :param id_: Id of the item to remove

imap_storage.storage.email.email module

Email and Attachment class

class imap_storage.storage.email.email.Email(directory, uid)[source]

Bases: object

Emails as data storage interface :param imap: Imap connection :param uid: new object if None - make sure to run new method

add_file(file_obj)[source]

add file to email :param file_obj: Object of class storage.file.File :returns: success bool

add_item(tag, text=None, attribs=None, parent=None)[source]

forwards to body method

body

access to the body object, fetch if not already done

delete()[source]

delete this email

Returns:True if success
Return type:bool
fetch_payloads()[source]

fetch payloads of this email

Returns:self.files with appended payloads
Return type:list
file_by_id(id_)[source]

get file by id Id is saved in the body (xml)

Parameters:id (str) – id of the file to get
Returns:object
Return type:File
file_by_name(name)[source]

get file by name

Parameters:name (str) – of the file to get
Returns:object
Return type:File
files

access to the file objects, fetch if not already done

head

access to the head object, fetch if not already done

html

get the whole email with files as html

name

name of the email :returns: name :rtype: str

new_body()[source]

create new empty body for this email

new_head(subject, from_addr_obj, to_addr_obj)[source]

Create new message and save it :param subject: subject as string :param from_addr_obj: from-address as Address Object :param to_addr_obj: to-address as Address Object :returns: self

path

path of the email

Returns:directory path/uid
Return type:str
plain

get the whole email with files as plain text

remove_file(file)[source]

removes file object from email

Parameters:file (File) – File object to delete from email
remove_file_by_attrib(attrib, value)[source]

remove file from email eg. remove_file_by_attrib(‘id’, ‘ldsKLfds’) :param attrib: attribute to select :param value: value of the attribute

save()[source]

Produce new Email from body, head and files, save it, delete old

subject

subject of the email It is a cached value and fetches one time when accessing the property

Returns:subject
Return type:str
to_string(html=False)[source]

https://stackoverflow.com/a/43157340 mixed |—alternative | |—text | |—related | |—html | |—inline image | |—inline image |—attachment |—attachment

xml_files

list of files that are registered in xml body

Type:returns

imap_storage.storage.email.file module

File class

imap_storage.storage.email.file.file_from_local(path)[source]

create File object from local path :param path: Of the local file

imap_storage.storage.email.file.file_from_upload(uploaded_file)[source]

create File object from Django uploaded file

imap_storage.storage.email.file.file_from_payload(email_obj, payload)[source]

create File object from message payload

imap_storage.storage.email.file.file_from_xml(email_obj, xml)[source]

create File object from xml structure

imap_storage.storage.email.head module

Head class

class imap_storage.storage.email.head.Head(msg_obj=None)[source]

Bases: email.mime.multipart.MIMEMultipart

Represents the head of an Email :param msg_obj: either pass a msg_obj to parse or run Head().new(*)

Module contents