Browse Source

better doc

Guénaël Muller 7 years ago
parent
commit
73eb068934
1 changed files with 21 additions and 4 deletions
  1. 21 4
      tracim/tracim/lib/email_fetcher.py

+ 21 - 4
tracim/tracim/lib/email_fetcher.py View File

37
         mail_data['from'] = parseaddr(msg['From'])[1]
37
         mail_data['from'] = parseaddr(msg['From'])[1]
38
         # Reply key
38
         # Reply key
39
         mail_data['to'] = parseaddr(msg['To'])[1]
39
         mail_data['to'] = parseaddr(msg['To'])[1]
40
-
40
+        # INFO - G.M - 2017-11-15
41
+        #  We only need to save the first/oldest addr of references
41
         mail_data['references'] = parseaddr(msg['References'])[1]
42
         mail_data['references'] = parseaddr(msg['References'])[1]
42
         if TRACIM_SPECIAL_KEY_HEADER in msg:
43
         if TRACIM_SPECIAL_KEY_HEADER in msg:
43
             mail_data[TRACIM_SPECIAL_KEY_HEADER] = str_header(msg[TRACIM_SPECIAL_KEY_HEADER])  # nopep8
44
             mail_data[TRACIM_SPECIAL_KEY_HEADER] = str_header(msg[TRACIM_SPECIAL_KEY_HEADER])  # nopep8
50
         )
51
         )
51
 
52
 
52
     except Exception:
53
     except Exception:
53
-        # FIXME - G.M - 2017-15-11 - handle exceptions correctly
54
+        # FIXME - G.M - 2017-11-15 - handle exceptions correctly
54
         return {}
55
         return {}
55
-    # FIXME - G.M - 2017-15-11 - get the best body candidate in MIME
56
+    # FIXME - G.M - 2017-11-15 - get the best body candidate in MIME
56
     # msg.get_body() look like the best way to get body but it's a py3.6 feature
57
     # msg.get_body() look like the best way to get body but it's a py3.6 feature
57
     for part in msg.walk():
58
     for part in msg.walk():
59
+        # TODO - G.M - 2017-11-15 - Handle HTML mail body
60
+        # TODO - G.M - 2017-11-15 - Parse properly HTML (and text ?) body
58
         if not part.get_content_type() == "text/plain":
61
         if not part.get_content_type() == "text/plain":
59
             continue
62
             continue
60
         else:
63
         else:
100
 
103
 
101
 class MailFetcher(object):
104
 class MailFetcher(object):
102
 
105
 
103
-    def __init__(self, host, port, user, password, folder, delay, endpoint) \
106
+    def __init__(self,
107
+                 host: str, port: str, user: str, password: str, folder: str,
108
+                 delay: int, endpoint: str) \
104
             -> None:
109
             -> None:
110
+        """
111
+        Fetch mail from a mailbox folder through IMAP and add their content to
112
+        Tracim through http according to mail Headers.
113
+        Fetch is regular.
114
+        :param host: imap server hostname
115
+        :param port: imap connection port
116
+        :param user: user login of mailbox
117
+        :param password: user password of mailbox
118
+        :param folder: mail folder where new mail are fetched
119
+        :param delay: seconds to wait before fetching new mail again
120
+        :param endpoint: tracim http endpoint where decoded mail are send.
121
+        """
105
         self._connection = None
122
         self._connection = None
106
         self._mails = []
123
         self._mails = []
107
         self.host = host
124
         self.host = host