Browse Source

Email Fetcher: use_idle and max_connection_lifetime as config params

Guénaël Muller 6 years ago
parent
commit
4e170105a1

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

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.use_ssl = true
224
 email.reply.imap.use_ssl = true
225
+email.reply.imap.use_idle = true
226
+# Re-new connection each 10 minutes
227
+email.reply.connection.max_lifetime = 600
225
 # Token for communication between mail fetcher and tracim controller
228
 # Token for communication between mail fetcher and tracim controller
226
 email.reply.token = mysecuretoken
229
 email.reply.token = mysecuretoken
227
 # Delay in seconds between each check
230
 # Delay in seconds between each check

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

384
         self.EMAIL_REPLY_IMAP_USE_SSL = asbool(tg.config.get(
384
         self.EMAIL_REPLY_IMAP_USE_SSL = asbool(tg.config.get(
385
             'email.reply.imap.use_ssl',
385
             'email.reply.imap.use_ssl',
386
         ))
386
         ))
387
+        self.EMAIL_REPLY_IMAP_USE_IDLE = asbool(tg.config.get(
388
+            'email.reply.imap.use_idle',
389
+            True,
390
+        ))
391
+        self.EMAIL_REPLY_CONNECTION_MAX_LIFETIME = int(tg.config.get(
392
+            'email.reply.connection.max_lifetime',
393
+            600, # 10 minutes
394
+        ))
387
         self.EMAIL_REPLY_USE_HTML_PARSING = asbool(tg.config.get(
395
         self.EMAIL_REPLY_USE_HTML_PARSING = asbool(tg.config.get(
388
             'email.reply.use_html_parsing',
396
             'email.reply.use_html_parsing',
389
             True,
397
             True,

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

174
             use_ssl=cfg.EMAIL_REPLY_IMAP_USE_SSL,
174
             use_ssl=cfg.EMAIL_REPLY_IMAP_USE_SSL,
175
             folder=cfg.EMAIL_REPLY_IMAP_FOLDER,
175
             folder=cfg.EMAIL_REPLY_IMAP_FOLDER,
176
             delay=cfg.EMAIL_REPLY_CHECK_HEARTBEAT,
176
             delay=cfg.EMAIL_REPLY_CHECK_HEARTBEAT,
177
+            use_idle=cfg.EMAIL_REPLY_IMAP_USE_IDLE,
178
+            connection_max_lifetime=cfg.EMAIL_REPLY_CONNECTION_MAX_LIFETIME,
177
             # FIXME - G.M - 2017-11-15 - proper tracim url formatting
179
             # FIXME - G.M - 2017-11-15 - proper tracim url formatting
178
             endpoint=cfg.WEBSITE_BASE_URL + "/events",
180
             endpoint=cfg.WEBSITE_BASE_URL + "/events",
179
             token=cfg.EMAIL_REPLY_TOKEN,
181
             token=cfg.EMAIL_REPLY_TOKEN,

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

28
 
28
 
29
 MAIL_FETCHER_FILELOCK_TIMEOUT = 10
29
 MAIL_FETCHER_FILELOCK_TIMEOUT = 10
30
 MAIL_FETCHER_CONNECTION_TIMEOUT = 60*3
30
 MAIL_FETCHER_CONNECTION_TIMEOUT = 60*3
31
-MAIL_FETCHER_CONNECTION_MAX_LIFETIME = 60*10
32
 MAIL_FETCHER_IDLE_RESPONSE_TIMEOUT = 60*9   # this should be not more
31
 MAIL_FETCHER_IDLE_RESPONSE_TIMEOUT = 60*9   # this should be not more
33
 # that 29 minutes according to rfc2177.(server wait 30min by default)
32
 # that 29 minutes according to rfc2177.(server wait 30min by default)
34
 
33
 
35
-IDLE_MODE = False
36
 
34
 
37
 
35
 
38
 class MessageContainer(object):
36
 class MessageContainer(object):
161
         password: str,
159
         password: str,
162
         use_ssl: bool,
160
         use_ssl: bool,
163
         folder: str,
161
         folder: str,
162
+        use_idle: bool,
163
+        connection_max_lifetime: int,
164
         delay: int,
164
         delay: int,
165
         endpoint: str,
165
         endpoint: str,
166
         token: str,
166
         token: str,
178
         :param password: user password of mailbox
178
         :param password: user password of mailbox
179
         :param use_ssl: use imap over ssl connection
179
         :param use_ssl: use imap over ssl connection
180
         :param folder: mail folder where new mail are fetched
180
         :param folder: mail folder where new mail are fetched
181
+        :param use_idle: use IMAP IDLE(server notification) when available
181
         :param delay: seconds to wait before fetching new mail again
182
         :param delay: seconds to wait before fetching new mail again
183
+        :param connection_max_lifetime: maximum duration allowed for a connection.
184
+           connection is automatically renew when his lifetime excess this value
182
         :param endpoint: tracim http endpoint where decoded mail are send.
185
         :param endpoint: tracim http endpoint where decoded mail are send.
183
         :param token: token to authenticate http connexion
186
         :param token: token to authenticate http connexion
184
         :param use_html_parsing: parse html mail
187
         :param use_html_parsing: parse html mail
191
         self.use_ssl = use_ssl
194
         self.use_ssl = use_ssl
192
         self.folder = folder
195
         self.folder = folder
193
         self.delay = delay
196
         self.delay = delay
197
+        self.use_idle = use_idle
198
+        self.connection_max_lifetime = connection_max_lifetime
194
         self.endpoint = endpoint
199
         self.endpoint = endpoint
195
         self.token = token
200
         self.token = token
196
         self.use_html_parsing = use_html_parsing
201
         self.use_html_parsing = use_html_parsing
225
                 imapc.select_folder(self.folder)
230
                 imapc.select_folder(self.folder)
226
 
231
 
227
                 # force renew connection when deadline is reached
232
                 # force renew connection when deadline is reached
228
-                deadline = time.time() + MAIL_FETCHER_CONNECTION_MAX_LIFETIME
233
+                deadline = time.time() + self.connection_max_lifetime
229
                 while time.time() < deadline:
234
                 while time.time() < deadline:
230
                     # check for new mails
235
                     # check for new mails
231
                     self._check_mail(imapc)
236
                     self._check_mail(imapc)
232
 
237
 
233
-                    if IDLE_MODE and imapc.has_capability('IDLE'):
238
+
239
+                    if self.use_idle and imapc.has_capability('IDLE'):
234
                         # IDLE_mode: wait until event from server
240
                         # IDLE_mode: wait until event from server
235
                         logger.debug(self, 'wail for event(IDLE)')
241
                         logger.debug(self, 'wail for event(IDLE)')
236
                         imapc.idle()
242
                         imapc.idle()