浏览代码

some refactoring in email fetcher

Guénaël Muller 7 年前
父节点
当前提交
c6c3a37150
共有 1 个文件被更改,包括 8 次插入12 次删除
  1. 8 12
      tracim/tracim/lib/email_fetcher.py

+ 8 - 12
tracim/tracim/lib/email_fetcher.py 查看文件

@@ -139,22 +139,20 @@ class DecodedMail(object):
139 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 143
         First try checking special header, them check 'to' header
143 144
         and finally check first(oldest) mail-id of 'references' header
144 145
         """
145
-        key = None
146 146
         first_ref = self.get_first_ref()
147 147
         to_address = self.get_to_address()
148 148
         special_key = self.get_special_key()
149 149
 
150 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 157
     @classmethod
160 158
     def find_key_from_mail_address(cls, mail_address: str) \
@@ -168,10 +166,8 @@ class DecodedMail(object):
168 166
         username = mail_address.split('@')[0]
169 167
         username_data = username.split('+')
170 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 173
 class MailFetcher(object):