|  | @@ -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()
 |