Browse Source

Check unflagged instead of unseen.

Guénaël Muller 6 years ago
parent
commit
7883757cd4
1 changed files with 4 additions and 13 deletions
  1. 4 13
      tracim/tracim/lib/email_fetcher.py

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

26
 CONTENT_TYPE_TEXT_PLAIN = 'text/plain'
26
 CONTENT_TYPE_TEXT_PLAIN = 'text/plain'
27
 CONTENT_TYPE_TEXT_HTML = 'text/html'
27
 CONTENT_TYPE_TEXT_HTML = 'text/html'
28
 
28
 
29
-IMAP_SEEN_FLAG = imapclient.SEEN
30
 IMAP_CHECKED_FLAG = imapclient.FLAGGED
29
 IMAP_CHECKED_FLAG = imapclient.FLAGGED
31
 
30
 
32
 MAIL_FETCHER_FILELOCK_TIMEOUT = 10
31
 MAIL_FETCHER_FILELOCK_TIMEOUT = 10
342
         """
341
         """
343
         messages = []
342
         messages = []
344
 
343
 
345
-        logger.debug(self, 'Fetch unseen messages')
346
-        uids = imapc.search(['UNSEEN'])
347
-        logger.debug(self, 'Found {} unseen mails'.format(
348
-            len(uids),
349
-        ))
350
-        imapc.add_flags(uids, IMAP_SEEN_FLAG)
351
-        logger.debug(self, 'Temporary Flag {} mails as seen'.format(
344
+        logger.debug(self, 'Fetch unflagged messages')
345
+        uids = imapc.search(['UNFLAGGED'])
346
+        logger.debug(self, 'Found {} unflagged mails'.format(
352
             len(uids),
347
             len(uids),
353
         ))
348
         ))
354
         for msgid, data in imapc.fetch(uids, ['BODY.PEEK[]']).items():
349
         for msgid, data in imapc.fetch(uids, ['BODY.PEEK[]']).items():
421
                         str(r.status_code),
416
                         str(r.status_code),
422
                         details,
417
                         details,
423
                     ))
418
                     ))
424
-                # Flag all correctly checked mail, unseen the others
419
+                # Flag all correctly checked mail
425
                 if r.status_code in [200, 204, 400]:
420
                 if r.status_code in [200, 204, 400]:
426
                     imapc.add_flags((mail.uid,), IMAP_CHECKED_FLAG)
421
                     imapc.add_flags((mail.uid,), IMAP_CHECKED_FLAG)
427
-                else:
428
-                    imapc.remove_flags((mail.uid,), IMAP_SEEN_FLAG)
429
             # TODO - G.M - Verify exception correctly works
422
             # TODO - G.M - Verify exception correctly works
430
             except requests.exceptions.Timeout as e:
423
             except requests.exceptions.Timeout as e:
431
                 log = 'Timeout error to transmit fetched mail to tracim : {}'
424
                 log = 'Timeout error to transmit fetched mail to tracim : {}'
432
                 logger.error(self, log.format(str(e)))
425
                 logger.error(self, log.format(str(e)))
433
-                imapc.remove_flags((mail.uid,), IMAP_SEEN_FLAG)
434
             except requests.exceptions.RequestException as e:
426
             except requests.exceptions.RequestException as e:
435
                 log = 'Fail to transmit fetched mail to tracim : {}'
427
                 log = 'Fail to transmit fetched mail to tracim : {}'
436
                 logger.error(self, log.format(str(e)))
428
                 logger.error(self, log.format(str(e)))
437
-                imapc.remove_flags((mail.uid,), IMAP_SEEN_FLAG)