diff options
author | drebs <drebs@leap.se> | 2015-04-15 14:16:13 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2015-04-16 11:53:48 -0300 |
commit | ae90151c632b376abc2a5bdf76d136b3a3629ea6 (patch) | |
tree | 05a6275c3f4f0597c0790da89925fdb0b9125dd6 /src/leap/mx | |
parent | 057de70291aee0eaedb8f8318dd1132e960e7e97 (diff) |
[bug] fix extraction of uuid from message headers
Before this commit, the mail receiver system used to compare the domain of the
delivery addresses found in the "Delivered-To" header to find out the final
delivery address. If we assume that the mail server delivery to the spool mail
directory was correct, then we have two facts: (1) the topmost "Delivered-To"
header is the one that indicates the correct final delivery address; and (2)
we should expect the address to be <uuid>@<domain> because of the earlier
alias resolve query made by the mail server.
Another problem is that the domain comparison would compare whatever is in the
"Delivered-To" header with whatever the python's socket module would return,
which depends on the values on /etc/hosts and the order of the values in that
file. This was causing problems whenever the platform made changes in
/etc/hosts.
So this commit eliminates the domain check and gets the uuid from the first
"Delivered-To" header found in the message.
Related: #6858.
Diffstat (limited to 'src/leap/mx')
-rw-r--r-- | src/leap/mx/mail_receiver.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py index f0b9c03..6b384f2 100644 --- a/src/leap/mx/mail_receiver.py +++ b/src/leap/mx/mail_receiver.py @@ -39,7 +39,6 @@ import signal import json import email.utils -import socket from email import message_from_string from email.MIMEMultipart import MIMEMultipart @@ -181,8 +180,6 @@ class MailReceiver(Service): self._directories = directories self._bounce_from = bounce_from self._bounce_subject = bounce_subject - - self._domain = socket.gethostbyaddr(socket.gethostname())[0] self._processing_skipped = False def startService(self): @@ -357,7 +354,7 @@ class MailReceiver(Service): def _get_owner(self, mail): """ - Given an email, returns the uuid of the owner. + Given an email, return the uuid of the owner. :param mail: mail to analyze :type mail: email.message.Message @@ -365,18 +362,17 @@ class MailReceiver(Service): :returns: uuid :rtype: str or None """ - uuid = None - + # we expect the topmost "Delivered-To" header to indicate the correct + # final delivery address. It should consist of <uuid>@<domain>, as the + # earlier alias resolver query should have translated the username to + # the user id. See https://leap.se/code/issues/6858 for more info. delivereds = mail.get_all("Delivered-To") if delivereds is None: + # XXX this should not happen! see the comment above return None - for to in delivereds: - name, addr = email.utils.parseaddr(to) - parts = addr.split("@") - if len(parts) > 1 and parts[1] == self._domain: - uuid = parts[0] - break - + final_address = delivereds.pop(0) + _, addr = email.utils.parseaddr(final_address) + uuid, _ = addr.split("@") return uuid @defer.inlineCallbacks |