From b786f3d4a9025f8975d98544221b58d5b09e9c0f Mon Sep 17 00:00:00 2001 From: Matti Lehtinen Date: Fri, 28 Aug 2020 15:56:10 +0300 Subject: [PATCH] Fix reading message id and size when returned in reversed order --- django_mailbox/transports/imap.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/django_mailbox/transports/imap.py b/django_mailbox/transports/imap.py index 2599adad..c16ba71a 100644 --- a/django_mailbox/transports/imap.py +++ b/django_mailbox/transports/imap.py @@ -82,8 +82,14 @@ def _get_small_message_ids(self, message_ids): for each_msg in data: each_msg = each_msg.decode() try: - uid = each_msg.split(' ')[2] - size = each_msg.split(' ')[4].rstrip(')') + stripped_msg = each_msg.replace('(', '').replace(')', '') + split_msg = stripped_msg.split(' ') + for i, s in enumerate(split_msg): + if s == 'UID': + uid = split_msg[i + 1] + elif s == 'RFC822.SIZE': + size = split_msg[i + 1] + if int(size) <= int(self.max_message_size): safe_message_ids.append(uid) except ValueError as e: