-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move mailboxes code to separate app #295
base: master
Are you sure you want to change the base?
Conversation
cb05ffb
to
27bf2fc
Compare
55acaf8
to
4742957
Compare
e3dc962
to
575e057
Compare
575e057
to
4245d26
Compare
276759b
to
2b52d42
Compare
…ts with unit tests
2b52d42
to
efb1856
Compare
mailboxes/utils.py
Outdated
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_message_number(listing_message): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like some docstrings on these utils would be a help for my understanding.
MailReadStatuses.UNPROCESSABLE, | ||
] | ||
) | ||
read_message_ids = set(mail_read_statuses.values_list("message_id", flat=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This set of message ids gets larger and larger, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does. This keeps the implementation mostly the same as it was before but switching to a set should mean a slightly faster lookup instead of building a big list and checking existence that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So just to fully check my understanding, we get all of the IDs for the messages read since the start of time in the app? Any ideas how large this is right now?
mailboxes/utils.py
Outdated
class MarkStatus: | ||
def __init__(self, message_id, message_num, read_status): | ||
self.message_id = message_id | ||
self.message_num = message_num | ||
self.read_status = read_status | ||
|
||
def __call__(self, status): | ||
logger.info( | ||
"Marking message_id %s with message_num %s from %r as %s", | ||
self.message_id, | ||
self.message_num, | ||
self.read_status.mailbox, | ||
status, | ||
) | ||
self.read_status.status = status | ||
self.read_status.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this just be a model method..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably. But this is keeping the output of this function the same so I didn’t have to change it at the point where it’s used.
def is_read(message, read_messages): | ||
return message.message_id in read_messages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if MailboxMessage
can have the read status passed in to it on creation so that this could be a method on there instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would end up being mostly the same in the end anyway, it’s just slightly shifting whether it’s a function or a method. You would still end up doing the same calls really.
mailboxes/utils.py
Outdated
message_id=message.message_id, | ||
message_num=message.message_number, | ||
mail_data=mail_data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can the email message data be mutable..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was to do with headers that came back from the mailbox. Technically the email is identical but there are headers that change when you read the message multiple times, something like a request id or an updating timestamp.
In this case it was to stop the message from being duplicated if the email gets read again as the data isn’t really changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I chose to do the update so it preserves the most recent headers in the case you did read the file data multiple times.
At the moment nearly all of the
lite-hmrc
code resides in a single Django application calledmail
. This makes it quite overwhelming to understand where to look for code when debugging and diagnosing problems.The main purpose of this PR is to split out one aspect of the
mail
application which is the code related to mail servers and mailboxes.As part of this there are a few bonus extras as well:
email
standard library