Browse Source

some refactoring in email fetcher

Guénaël Muller 7 years ago
parent
commit
c6c3a37150
1 changed files with 8 additions and 12 deletions
  1. 8 12
      tracim/tracim/lib/email_fetcher.py

+ 8 - 12
tracim/tracim/lib/email_fetcher.py View File

139
     def get_key(self) -> typing.Optional[str]:
139
     def get_key(self) -> typing.Optional[str]:
140
 
140
 
141
         """
141
         """
142
+        key is the string contain in some mail header we need to retrieve.
142
         First try checking special header, them check 'to' header
143
         First try checking special header, them check 'to' header
143
         and finally check first(oldest) mail-id of 'references' header
144
         and finally check first(oldest) mail-id of 'references' header
144
         """
145
         """
145
-        key = None
146
         first_ref = self.get_first_ref()
146
         first_ref = self.get_first_ref()
147
         to_address = self.get_to_address()
147
         to_address = self.get_to_address()
148
         special_key = self.get_special_key()
148
         special_key = self.get_special_key()
149
 
149
 
150
         if special_key:
150
         if special_key:
151
-            key = special_key
152
-        if not key and to_address:
153
-            key = DecodedMail.find_key_from_mail_address(to_address)
154
-        if not key and first_ref:
155
-            key = DecodedMail.find_key_from_mail_address(first_ref)
156
-
157
-        return key
151
+            return special_key
152
+        if to_address:
153
+            return DecodedMail.find_key_from_mail_address(to_address)
154
+        if first_ref:
155
+            return DecodedMail.find_key_from_mail_address(first_ref)
158
 
156
 
159
     @classmethod
157
     @classmethod
160
     def find_key_from_mail_address(cls, mail_address: str) \
158
     def find_key_from_mail_address(cls, mail_address: str) \
168
         username = mail_address.split('@')[0]
166
         username = mail_address.split('@')[0]
169
         username_data = username.split('+')
167
         username_data = username.split('+')
170
         if len(username_data) == 2:
168
         if len(username_data) == 2:
171
-            key = username_data[1]
172
-        else:
173
-            key = None
174
-        return key
169
+            return username_data[1]
170
+        return None
175
 
171
 
176
 
172
 
177
 class MailFetcher(object):
173
 class MailFetcher(object):