core.utils.fetchers.POP3Fetcher module

Module with the POP3_SSL_Fetcher class.

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

Bases: BaseFetcher, SafePOPMixin

Maintains a connection to the POP server and fetches data using poplib.

Opens a connection to the POP server on construction and is preferably used in a ‘with’ environment. Allows fetching of mails and mailboxes from an account on an POP host.

Since POP does not have any mailboxes, none of the methods should raise a MailboxError.

Parameters:

account (Account)

PROTOCOL = 'POP3'

Name of the used protocol, refers to MailFetchingProtocols.POP3.

AVAILABLE_FETCHING_CRITERIA: tuple[str, ...] = (EmailFetchingCriterionChoices.ALL,)

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

__init__(account)[source]

Constructor, starts the POP connection and logs into the account.

Parameters:

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

Return type:

None

connect_to_host()[source]

Opens the connection to the POP server using the credentials from account.

Raises:

MailAccountError – If an error occurs or a bad response is returned.

Return type:

None

test(mailbox=None)[source]

Tests the connection to the mailserver and, if a mailbox is provided, whether messages can be listed.

Parameters:

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

Raises:
  • ValueError – If the mailbox does not belong to self.account.

  • MailAccountError – If the test fails because an error occurs or a bad response is returned.

Return type:

None

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

Fetches and returns all maildata from the server.

Parameters:
  • mailbox (Mailbox) – Database model of the mailbox to fetch data from.

  • criterion (FetchingCriterion) – POP only supports ALL lookups. Defaults to eonvelope.MailFetchingCriteria.ALL. This arg ensures compatibility with the other fetchers.

Yields:

Mails in the mailbox.

Raises:
  • ValueError – If the mailbox does not belong to self.account. If criterion is not eonvelope.MailFetchingCriteria.ALL.

  • MailAccountError – If an error occurs or a bad response is returned.

Return type:

Generator[bytes]

fetch_mailboxes()[source]

Returns the data of the mailboxes. For POP3 there is only one mailbox named ‘INBOX’.

Note

This method is built to match the fetcherclasses interface.

Return type:

list[tuple[str, str]]

Returns:

The name of the mailbox in the account in a list.

restore(email)[source]

Places an email in its mailbox.

Note

POP doesn’t offer an action to upload emails.

Parameters:

email (Email) – The email to restore.

Raises:

NotImplementedError – POP can’t restore emails.

Return type:

None

close()[source]

Logs out of the account and closes the connection to the POP server if it is open.

Return type:

None