Browse Source

[IMP] fetchmail_attach_from_folder. Button to retrieve single folder.

Also possibility to reset state for folder.
pull/1317/merge
Ronald Portier 7 years ago
committed by Holger Brunn
parent
commit
5f57264d30
  1. 17
      fetchmail_attach_from_folder/models/fetchmail_server.py
  2. 29
      fetchmail_attach_from_folder/models/fetchmail_server_folder.py
  3. 11
      fetchmail_attach_from_folder/views/fetchmail_server.xml

17
fetchmail_attach_from_folder/models/fetchmail_server.py

@ -70,22 +70,7 @@ class FetchmailServer(models.Model):
for this in self: for this in self:
if not this.folders_only: if not this.folders_only:
super(FetchmailServer, this).fetch_mail() super(FetchmailServer, this).fetch_mail()
try:
# New connection for retrieving folders
connection = this.connect()
for folder in this.folder_ids.filtered('active'):
if folder.state == 'done':
folder.retrieve_imap_folder(connection)
connection.close()
except Exception:
_logger.error(_(
"General failure when trying to connect to"
" %s server %s."),
this.type, this.name, exc_info=True)
finally:
if connection:
connection.logout()
return True
this.folder_ids.fetch_mail()
def fields_view_get( def fields_view_get(
self, view_id=None, view_type='form', self, view_id=None, view_type='form',

29
fetchmail_attach_from_folder/models/fetchmail_server_folder.py

@ -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."""

11
fetchmail_attach_from_folder/views/fetchmail_server.xml

@ -31,6 +31,7 @@
<field name="model_field" /> <field name="model_field" />
<field name="match_algorithm" /> <field name="match_algorithm" />
<field name="mail_field" /> <field name="mail_field" />
<field name="state" />
</tree> </tree>
<form> <form>
<field name="state" invisible="1" /> <field name="state" invisible="1" />
@ -45,6 +46,16 @@
name="button_attach_mail_manually" name="button_attach_mail_manually"
string="Attach mail manually" string="Attach mail manually"
states="done"/> states="done"/>
<button
type="object"
name="fetch_mail"
string="Fetch folder now"
states="done"/>
<button
string="Reset Confirmation"
type="object"
name="set_draft"
states="done"/>
</header> </header>
<group> <group>
<group> <group>

Loading…
Cancel
Save