Kaynağa Gözat

Email Fetcher: use_idle and max_connection_lifetime as config params

Guénaël Muller 6 yıl önce
ebeveyn
işleme
4e170105a1

+ 3 - 0
tracim/development.ini.base Dosyayı Görüntüle

@@ -222,6 +222,9 @@ email.reply.imap.user = your_imap_user
222 222
 email.reply.imap.password = your_imap_password
223 223
 email.reply.imap.folder = INBOX
224 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 228
 # Token for communication between mail fetcher and tracim controller
226 229
 email.reply.token = mysecuretoken
227 230
 # Delay in seconds between each check

+ 8 - 0
tracim/tracim/config/app_cfg.py Dosyayı Görüntüle

@@ -384,6 +384,14 @@ class CFG(object):
384 384
         self.EMAIL_REPLY_IMAP_USE_SSL = asbool(tg.config.get(
385 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 395
         self.EMAIL_REPLY_USE_HTML_PARSING = asbool(tg.config.get(
388 396
             'email.reply.use_html_parsing',
389 397
             True,

+ 2 - 0
tracim/tracim/lib/daemons.py Dosyayı Görüntüle

@@ -174,6 +174,8 @@ class MailFetcherDaemon(Daemon):
174 174
             use_ssl=cfg.EMAIL_REPLY_IMAP_USE_SSL,
175 175
             folder=cfg.EMAIL_REPLY_IMAP_FOLDER,
176 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 179
             # FIXME - G.M - 2017-11-15 - proper tracim url formatting
178 180
             endpoint=cfg.WEBSITE_BASE_URL + "/events",
179 181
             token=cfg.EMAIL_REPLY_TOKEN,

+ 10 - 4
tracim/tracim/lib/email_fetcher.py Dosyayı Görüntüle

@@ -28,11 +28,9 @@ IMAP_CHECKED_FLAG = FLAGGED
28 28
 
29 29
 MAIL_FETCHER_FILELOCK_TIMEOUT = 10
30 30
 MAIL_FETCHER_CONNECTION_TIMEOUT = 60*3
31
-MAIL_FETCHER_CONNECTION_MAX_LIFETIME = 60*10
32 31
 MAIL_FETCHER_IDLE_RESPONSE_TIMEOUT = 60*9   # this should be not more
33 32
 # that 29 minutes according to rfc2177.(server wait 30min by default)
34 33
 
35
-IDLE_MODE = False
36 34
 
37 35
 
38 36
 class MessageContainer(object):
@@ -161,6 +159,8 @@ class MailFetcher(object):
161 159
         password: str,
162 160
         use_ssl: bool,
163 161
         folder: str,
162
+        use_idle: bool,
163
+        connection_max_lifetime: int,
164 164
         delay: int,
165 165
         endpoint: str,
166 166
         token: str,
@@ -178,7 +178,10 @@ class MailFetcher(object):
178 178
         :param password: user password of mailbox
179 179
         :param use_ssl: use imap over ssl connection
180 180
         :param folder: mail folder where new mail are fetched
181
+        :param use_idle: use IMAP IDLE(server notification) when available
181 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 185
         :param endpoint: tracim http endpoint where decoded mail are send.
183 186
         :param token: token to authenticate http connexion
184 187
         :param use_html_parsing: parse html mail
@@ -191,6 +194,8 @@ class MailFetcher(object):
191 194
         self.use_ssl = use_ssl
192 195
         self.folder = folder
193 196
         self.delay = delay
197
+        self.use_idle = use_idle
198
+        self.connection_max_lifetime = connection_max_lifetime
194 199
         self.endpoint = endpoint
195 200
         self.token = token
196 201
         self.use_html_parsing = use_html_parsing
@@ -225,12 +230,13 @@ class MailFetcher(object):
225 230
                 imapc.select_folder(self.folder)
226 231
 
227 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 234
                 while time.time() < deadline:
230 235
                     # check for new mails
231 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 240
                         # IDLE_mode: wait until event from server
235 241
                         logger.debug(self, 'wail for event(IDLE)')
236 242
                         imapc.idle()