core.utils.fetchers.BaseFetcher module

Module with the BaseFetcher class template.

class core.utils.fetchers.BaseFetcher.BaseFetcher(account)[source]

Bases: ABC

Template class for the mailfetcher classes.

Provides arg-checking for methods.

Parameters:

account (Account)

PROTOCOL = ''

Name of the used protocol, should be one of MailFetchingProtocols.

AVAILABLE_FETCHING_CRITERIA: tuple[str, ...] = ('',)

Tuple of all criteria available for fetching. Should refer to MailFetchingCriteria. Must be immutable!

DEFAULT_FETCHING_CRITERION = <core.utils.FetchingCriterion.FetchingCriterion object>

Default criterion to use for fetching emails with the fetcher class.

abstractmethod __init__(account)[source]

Constructor basis, sets up the instance logger.

Parameters:

account (Account) – The model of the account to fetch from.

Return type:

None

abstractmethod connect_to_host()[source]

Opens the connection to the mailserver.

Return type:

None

abstractmethod test(mailbox=None)[source]

Tests the connection to the mailaccount and, if given, the mailbox.

Parameters:

mailbox (Mailbox | None) – The mailbox to be tested. Default is None.

Raises:

ValueError – If the mailbox argument does not belong to self.account.

Return type:

None

abstractmethod fetch_emails(mailbox, criterion=<core.utils.FetchingCriterion.FetchingCriterion object>)[source]

Fetches emails based on a criterion from the server.

Parameters:
Yields:

Mails in the mailbox matching the criterion as bytes.

Raises:

ValueError – If the fetching_criterion is not available for this fetcher.

Return type:

Generator[bytes]

abstractmethod fetch_mailboxes()[source]

Fetches all mailbox names from the server.

Return type:

list[tuple[str, str]]

Returns:

List of data of all mailboxes in the account. Empty if none are found.

abstractmethod restore(email)[source]

Restores an email to a mailbox.

Parameters:

email (Email) – The email to restore.

Raises:
Return type:

None

abstractmethod close()[source]

Closes the connection to the mail server.

Return type:

None

__str__()[source]

Returns a string representation of the BaseFetcher instances.

Return type:

str

Returns:

The string representation of the fetcher instance.