core.models.Account module

Module with the Account model class.

core.models.Account.logger = <Logger core.models.Account (INFO)>

The logger instance for this module.

class core.models.Account.Account(*args, **kwargs)[source]

Bases: ExportModelOperationsMixin('account'), DirtyFieldsMixin, URLMixin, DownloadMixin, FavoriteModelMixin, TimestampModelMixin, HealthModelMixin, Model

Database model for the account data of a mail account.

BASENAME = 'account'
DELETE_NOTICE = 'This will delete the records of this account and all mailboxes, emails and attachments found in it!'
DELETE_NOTICE_PLURAL = 'This will delete the records of these accounts and all mailboxes, emails and attachments found in them!'
MAX_MAIL_HOST_PORT = 65535
mail_address

The username of the account. Unique together with user. Named mail_address for continuity.

password

The password to log into the account.

mail_host

The url of the mail server where the account is located.

mail_host_port

The port of the mail server. Can be null if the default port of the protocol is used.

protocol

The mail protocol of the mail server.

timeout

The timeout parameter for the connection to the host, defaults to 10s.

allow_insecure_connection

Whether to allow insecure connections to the host, defaults to False.

user

The user this account belongs to. Deletion of that user deletes this correspondent.

__str__()[source]

Returns a string representation of the model data.

Return type:

str

Returns:

The string representation of the account, using mail_address and protocol.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

_meta = <Options for Account>
created

The datetime the model instance was created. Is set automatically.

get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, 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_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=False, **kwargs)
get_protocol_display(*, field=<django.db.models.fields.CharField: protocol>)
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.

is_healthy

Flags whether the model instance is subject to errors. None by default.

last_error

The latest error in connection with the model instance.

last_error_occurred_at

The time of occurrence of the latest error.

mailboxes

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.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

objects = <django.db.models.manager.Manager object>
save(*args, **kwargs)[source]

Extended to auto-update mailboxes when the account is saved for the first time.

Return type:

None

Parameters:
updated

The datetime the model instance entry was last updated. Is set automatically.

user_id
clean()[source]

Validation for the unique together constraint on mail_account. Validate the account data by testing if one of the relevant fields is dirty.

Required to allow correct validation of the create form.

Raises:

ValidationError – If the instance violates the constraint or testing fails.

Return type:

None

get_fetcher_class()[source]

Returns the fetcher class from core.utils.fetchers corresponding to protocol.

Return type:

type[BaseFetcher]

Returns:

The fetcher class for the account.

Raises:

ValueError – If the protocol doesn’t match any fetcher class. Marks the account as unhealthy in this case.

get_fetcher()[source]

Instantiates the fetcher from core.utils.fetchers corresponding to protocol.

Handles possible errors instantiating the fetcher.

Return type:

BaseFetcher

Returns:

A fetcher instance for the account.

Raises:
  • ValueError – If the protocol doesn’t match any fetcher class. Marks the account as unhealthy in this case.

  • MailAccountError – If the fetcher fails to initialize. Marks the account as unhealthy in this case.

test()[source]

Tests whether the data in the model is correct.

Tests connecting and logging in to the mailhost and account. The core.models.Account.is_healthy flag is set accordingly. Relies on the test method of the core.utils.fetchers classes.

Raises:

MailAccountError – If the test is fails.

Return type:

None

update_mailboxes()[source]

Scans the given mailaccount for unknown mailboxes, parses and inserts them into the database.

If successful, marks this account as healthy, otherwise unhealthy.

Raises:

MailAccountError – If scanning for mailboxes failed.

Return type:

None

add_daemons()[source]

Adds a default set of daemons to the in- and sent mailboxes of this account.

Return type:

None

property complete_mail_address: str

The complete mail address of the account. If the username (mail_address) is not valid a valid address, constructs one with mail_host. If there is no username, guess it from the Eonvelope users name.

Returns:

A valid mail address for the account.

property mail_host_address: str

The mail_host address with port specified for the hostname.

Returns:

The complete host address.

property available_download_formats: list[tuple[str, StrOrPromise]]

Get all formats that emails in this account can be downloaded in.

Returns:

A list of download formats and format names.

property has_download: bool

Checks whether a download is possible for the instance.