Skip to content

Commit

Permalink
LTD-3804-limit-hmrc-emails (#196)
Browse files Browse the repository at this point in the history
* add config email limit

* add variable
  • Loading branch information
depsiatwal authored Jun 13, 2023
1 parent e34e7b3 commit 7e68948
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
INCOMING_EMAIL_HOSTNAME = env("INCOMING_EMAIL_HOSTNAME", default="")
INCOMING_EMAIL_USER = env("INCOMING_EMAIL_USER", default="")
INCOMING_EMAIL_POP3_PORT = env("INCOMING_EMAIL_POP3_PORT", default=None)
INCOMING_EMAIL_CHECK_LIMIT = env.int("INCOMING_EMAIL_CHECK_LIMIT", default=100)

HMRC_TO_DIT_EMAIL_PASSWORD = env("HMRC_TO_DIT_EMAIL_PASSWORD", default="")
HMRC_TO_DIT_EMAIL_HOSTNAME = env("HMRC_TO_DIT_EMAIL_HOSTNAME", default="")
Expand Down
8 changes: 6 additions & 2 deletions mail/libraries/mailbox_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ def get_message_iterator(pop3_connection: POP3_SSL, username: str) -> Iterator[T
mails: list
_, mails, _ = pop3_connection.list()
mailbox_config, _ = MailboxConfig.objects.get_or_create(username=username)
incoming_email_check_limit = settings.INCOMING_EMAIL_CHECK_LIMIT

# Check only the last 500 emails
# Check only the emails specified in the setting
# Since we don't delete emails from these mailboxes the total number can be very high over a perio
# and increases the processing time.
# The mails is a list of message number and size - message number is an increasing value so the
# latest emails will always be at the end.
mail_message_ids = [get_message_id(pop3_connection, m.decode(settings.DEFAULT_ENCODING)) for m in mails[-500:]]
mail_message_ids = [
get_message_id(pop3_connection, m.decode(settings.DEFAULT_ENCODING))
for m in mails[-incoming_email_check_limit:]
]

# these are mailbox message ids we've seen before
read_messages = get_read_messages(mailbox_config)
Expand Down

0 comments on commit 7e68948

Please sign in to comment.