|
@ -123,6 +123,11 @@ class FetchmailServerFolder(models.Model): |
|
|
'view_type': 'form', |
|
|
'view_type': 'form', |
|
|
'view_mode': 'form'} |
|
|
'view_mode': 'form'} |
|
|
|
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def set_draft(self): |
|
|
|
|
|
self.write({'state': 'draft'}) |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def get_msgids(self, connection, criteria): |
|
|
def get_msgids(self, connection, criteria): |
|
|
"""Return imap ids of messages to process""" |
|
|
"""Return imap ids of messages to process""" |
|
@ -167,6 +172,7 @@ class FetchmailServerFolder(models.Model): |
|
|
msgids = self.get_msgids(connection, 'UNDELETED') |
|
|
msgids = self.get_msgids(connection, 'UNDELETED') |
|
|
match_algorithm = self.get_algorithm() |
|
|
match_algorithm = self.get_algorithm() |
|
|
for msgid in msgids[0].split(): |
|
|
for msgid in msgids[0].split(): |
|
|
|
|
|
# We will accept exceptions for single messages |
|
|
try: |
|
|
try: |
|
|
self.env.cr.execute('savepoint apply_matching') |
|
|
self.env.cr.execute('savepoint apply_matching') |
|
|
self.apply_matching(connection, msgid, match_algorithm) |
|
|
self.apply_matching(connection, msgid, match_algorithm) |
|
@ -177,6 +183,29 @@ class FetchmailServerFolder(models.Model): |
|
|
"Failed to fetch mail %s from %s", |
|
|
"Failed to fetch mail %s from %s", |
|
|
msgid, self.server_id.name) |
|
|
msgid, self.server_id.name) |
|
|
|
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def fetch_mail(self): |
|
|
|
|
|
"""Retrieve all mails for IMAP folders. |
|
|
|
|
|
|
|
|
|
|
|
We will use a separate connection for each folder. |
|
|
|
|
|
""" |
|
|
|
|
|
for this in self: |
|
|
|
|
|
if not this.active or this.state != 'done': |
|
|
|
|
|
continue |
|
|
|
|
|
connection = None |
|
|
|
|
|
try: |
|
|
|
|
|
# New connection per folder |
|
|
|
|
|
connection = this.server_id.connect() |
|
|
|
|
|
this.retrieve_imap_folder(connection) |
|
|
|
|
|
connection.close() |
|
|
|
|
|
except Exception: |
|
|
|
|
|
_logger.error(_( |
|
|
|
|
|
"General failure when trying to connect to %s server %s."), |
|
|
|
|
|
this.server_id.type, this.server_id.name, exc_info=True) |
|
|
|
|
|
finally: |
|
|
|
|
|
if connection: |
|
|
|
|
|
connection.logout() |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def update_msg(self, connection, msgid, matched=True, flagged=False): |
|
|
def update_msg(self, connection, msgid, matched=True, flagged=False): |
|
|
"""Update msg in imap folder depending on match and settings.""" |
|
|
"""Update msg in imap folder depending on match and settings.""" |
|
|