Browse Source

Email_fetcher : Add support for IMAP unencrypted connection

Guénaël Muller 7 years ago
parent
commit
0cebea15d8

+ 1 - 0
tracim/development.ini.base View File

221
 email.reply.imap.user = your_imap_user
221
 email.reply.imap.user = your_imap_user
222
 email.reply.imap.password = your_imap_password
222
 email.reply.imap.password = your_imap_password
223
 email.reply.imap.folder = INBOX
223
 email.reply.imap.folder = INBOX
224
+email.reply.imap.ssl = true
224
 # Token for communication between mail fetcher and tracim controller
225
 # Token for communication between mail fetcher and tracim controller
225
 email.reply.token = mysecuretoken
226
 email.reply.token = mysecuretoken
226
 # Delay in seconds between each check
227
 # Delay in seconds between each check

+ 3 - 0
tracim/tracim/config/app_cfg.py View File

379
         self.EMAIL_REPLY_TOKEN = tg.config.get(
379
         self.EMAIL_REPLY_TOKEN = tg.config.get(
380
             'email.reply.token',
380
             'email.reply.token',
381
         )
381
         )
382
+        self.EMAIL_REPLY_IMAP_SSL = asbool(tg.config.get(
383
+            'email.reply.imap.ssl',
384
+        ))
382
 
385
 
383
         self.TRACKER_JS_PATH = tg.config.get(
386
         self.TRACKER_JS_PATH = tg.config.get(
384
             'js_tracker_path',
387
             'js_tracker_path',

+ 1 - 0
tracim/tracim/lib/daemons.py View File

171
             port=cfg.EMAIL_REPLY_IMAP_PORT,
171
             port=cfg.EMAIL_REPLY_IMAP_PORT,
172
             user=cfg.EMAIL_REPLY_IMAP_USER,
172
             user=cfg.EMAIL_REPLY_IMAP_USER,
173
             password=cfg.EMAIL_REPLY_IMAP_PASSWORD,
173
             password=cfg.EMAIL_REPLY_IMAP_PASSWORD,
174
+            ssl=cfg.EMAIL_REPLY_IMAP_SSL,
174
             folder=cfg.EMAIL_REPLY_IMAP_FOLDER,
175
             folder=cfg.EMAIL_REPLY_IMAP_FOLDER,
175
             delay=cfg.EMAIL_REPLY_CHECK_HEARTBEAT,
176
             delay=cfg.EMAIL_REPLY_CHECK_HEARTBEAT,
176
             # FIXME - G.M - 2017-11-15 - proper tracim url formatting
177
             # FIXME - G.M - 2017-11-15 - proper tracim url formatting

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

176
                  port: str,
176
                  port: str,
177
                  user: str,
177
                  user: str,
178
                  password: str,
178
                  password: str,
179
+                 ssl: bool,
179
                  folder: str,
180
                  folder: str,
180
                  delay: int,
181
                  delay: int,
181
                  endpoint: str,
182
                  endpoint: str,
189
         :param port: imap connection port
190
         :param port: imap connection port
190
         :param user: user login of mailbox
191
         :param user: user login of mailbox
191
         :param password: user password of mailbox
192
         :param password: user password of mailbox
193
+        :param ssl: use imap over ssl connection
192
         :param folder: mail folder where new mail are fetched
194
         :param folder: mail folder where new mail are fetched
193
         :param delay: seconds to wait before fetching new mail again
195
         :param delay: seconds to wait before fetching new mail again
194
         :param endpoint: tracim http endpoint where decoded mail are send.
196
         :param endpoint: tracim http endpoint where decoded mail are send.
199
         self.port = port
201
         self.port = port
200
         self.user = user
202
         self.user = user
201
         self.password = password
203
         self.password = password
204
+        self.ssl = ssl
202
         self.folder = folder
205
         self.folder = folder
203
         self.delay = delay
206
         self.delay = delay
204
         self.endpoint = endpoint
207
         self.endpoint = endpoint
225
         # Are old connexion properly close this way ?
228
         # Are old connexion properly close this way ?
226
         if self._connection:
229
         if self._connection:
227
             self._disconnect()
230
             self._disconnect()
228
-        # TODO - G.M - 2017-11-15 Support unencrypted connection ?
229
         # TODO - G.M - 2017-11-23 Support for predefined SSLContext ?
231
         # TODO - G.M - 2017-11-23 Support for predefined SSLContext ?
230
         # without ssl_context param, tracim use default security configuration
232
         # without ssl_context param, tracim use default security configuration
231
         # which is great in most case.
233
         # which is great in most case.
232
-        self._connection = imaplib.IMAP4_SSL(self.host, self.port)
234
+        if self.ssl:
235
+            self._connection = imaplib.IMAP4_SSL(self.host, self.port)
236
+        else:
237
+            self._connection = imaplib.IMAP4(self.host, self.port)
238
+
233
         try:
239
         try:
234
             self._connection.login(self.user, self.password)
240
             self._connection.login(self.user, self.password)
235
         except Exception as e:
241
         except Exception as e: