core.models.Email module¶
Module with the Email model class.
- core.models.Email.logger = <Logger core.models.Email (INFO)>¶
The logger instance for this module.
- class core.models.Email.Email(*args, **kwargs)[source]¶
Bases:
ExportModelOperationsMixin('email'),DownloadMixin,ThumbnailMixin,URLMixin,FavoriteModelMixin,FilePathModelMixin,TimestampModelMixin,ModelDatabase model for an email.
- BASENAME = 'email'¶
- DELETE_NOTICE = 'This will delete the records of this email and all its attachments but not its correspondents.'¶
- DELETE_NOTICE_PLURAL = 'This will delete the records of these emails and all their attachments but not their correspondents.'¶
- datetime¶
The Date header of the mail.
- subject¶
The subject header of the mail.
- plain_bodytext¶
The plain bodytext of the mail. Can be blank.
- html_bodytext¶
The html bodytext of the mail. Can be blank.
- in_reply_to: models.ManyToManyField[Email, Email]¶
The mails that this mail is a response to. Technically just a single mail, but as a mail can exist in multiple mailboxes, this needs to be able to reference multiples.
- datasize¶
The bytes size of the mail.
- correspondents: models.ManyToManyField[Correspondent, Correspondent]¶
The correspondents that are mentioned in this mail. Bridges through
core.models.EmailCorrespondent.
- mailbox: models.ForeignKey[Mailbox]¶
The mailbox that this mail has been found in. Unique together with
message_id. Deletion of that mailbox deletes this mail.
- headers¶
All other header fields of the mail. Can be null.
- x_spam_flag¶
The x_spam header of this mail. Can be null.
- __str__()[source]¶
Returns a string representation of the model data.
- Return type:
- Returns:
The string representation of the email, using
message_id,datetimeandmailbox.
- save(*args, **kwargs)[source]¶
Extended :django:
django.models.Model.save()method.Saves the data to eml if configured.
- fill_from_email_bytes(email_bytes)[source]¶
Fills the
core.models.Emailwith data from an email in bytes form.- Parameters:
email_bytes (
bytes) – The email bytes data.- Return type:
- Returns:
The
core.models.Emailinstance with data from the bytes.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- _meta = <Options for Email>¶
- add_correspondents()[source]¶
Adds the correspondents from the headerfields to the model.
- Return type:
- attachments¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- created¶
The datetime the model instance was created. Is set automatically.
- emailcorrespondents¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- file_path¶
The relative path in the storage where the file is stored. Can be null if no file has been saved (null does not collide with the unique constraint.).
- get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)¶
- get_next_by_datetime(*, field=<django.db.models.fields.DateTimeField: datetime>, is_next=True, **kwargs)¶
- get_next_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=True, **kwargs)¶
- get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)¶
- get_previous_by_datetime(*, field=<django.db.models.fields.DateTimeField: datetime>, is_next=False, **kwargs)¶
- get_previous_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=False, **kwargs)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_favorite¶
Flags favorite accounts. False by default.
- mailbox_id¶
- objects = <django.db.models.manager.Manager object>¶
- referenced_by¶
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- replies¶
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- updated¶
The datetime the model instance entry was last updated. Is set automatically.
- add_in_reply_to()[source]¶
Adds the in-reply-to emails from the headerfields to the model.
- Return type:
- reprocess()[source]¶
Reprocesses the mails connections to other emails in the database.
- Return type:
- restore_to_mailbox()[source]¶
Restores the email to its mailbox.
- Raises:
NotImplementedError – If the emails account does not allow restoring.
FileNotFoundError – If there is no eml file for the email.
MailAccountError – If there was an error connected to the account.
MailboxError – If there was an error with the mailbox.
- Return type:
- property conversation: QuerySet[source]¶
Recursively gets all emails that are part of this emails conversation, connected through references or in_reply_to.
- Returns:
Queryset of all mails in the conversation.
- property can_be_restored: bool¶
Checks if the email can be restored to its mailbox.
- Returns:
Whether the email can be restored.
- property html_version: str[source]¶
Renders a html version of this email.
Uses the template and css from constance settings.
- Returns:
The emails html version.
- property is_spam: bool¶
Checks the spam headers to decide whether the mail is spam.
- Returns:
Whether the mail is considered spam.
- classmethod create_from_email_bytes(email_bytes, mailbox)[source]¶
Creates an
core.models.Emailfrom an email in bytes form.- Parameters:
- Return type:
- Returns:
The
core.models.Emailinstance with data from the bytes. None if there is no Message-ID header inemail_message, if the mail already exists in the db or if the mail is spam and is supposed to be thrown out.
- static _queryset_as_zip_eml(queryset)[source]¶
Parses a queryset of emails into a zip of eml files.
Note
Does not validate args! This has to be done beforehand.
- Return type:
_TemporaryFileWrapper- Parameters:
queryset (QuerySet)
- static _queryset_as_mailbox_file(queryset, file_format)[source]¶
Parses a queryset of emails into a mailbox file.
Note
Does not validate args! This has to be done beforehand.
- static _queryset_as_mailbox_zip(queryset, file_format)[source]¶
Parses a queryset of emails into a zipped mailbox dir.
Note
Does not validate args! This has to be done beforehand.
- static queryset_as_file(queryset, file_format)[source]¶
Processes the files of the emails in the queryset into a temporary file.
- Parameters:
queryset (
QuerySet) – The email queryset to compile into a file.file_format (
str) – The desired format of the file. Must be one ofcore.constants.SupportedEmailDownloadFormats. Case-insensitive.
- Return type:
_TemporaryFileWrapper- Returns:
The temporary file wrapper.
- Raises:
ValueError – If the given
file_formatis not supported.Email.DoesNotExist – If the
querysetis empty.