Browse Source

[IMP] fetchmail_attach_from_folder. Separate confirm for folder.

Now it is impossible to confirm a connection to a imap server if there is a problem
in one folder. This commit provides a new state field on the folder and e separate
comfirm button per folder.
pull/1317/merge
Ronald Portier 7 years ago
committed by Holger Brunn
parent
commit
bee7ea0722
  1. 18
      fetchmail_attach_from_folder/models/fetchmail_server.py
  2. 31
      fetchmail_attach_from_folder/models/fetchmail_server_folder.py
  3. 8
      fetchmail_attach_from_folder/views/fetchmail_server.xml

18
fetchmail_attach_from_folder/models/fetchmail_server.py

@ -5,7 +5,7 @@ import logging
import simplejson
from lxml import etree
from odoo import _, api, exceptions, fields, models
from odoo import _, api, fields, models
from odoo.tools.safe_eval import safe_eval
from odoo.tools.misc import UnquoteEvalContext
@ -46,6 +46,7 @@ class FetchmailServer(models.Model):
# 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:
@ -58,21 +59,6 @@ class FetchmailServer(models.Model):
connection.logout()
return True
@api.multi
def button_confirm_login(self):
retval = super(FetchmailServer, self).button_confirm_login()
for this in self:
this.write({'state': 'draft'})
connection = this.connect()
connection.select()
for folder in this.folder_ids.filtered('active'):
if connection.select(folder.path)[0] != 'OK':
raise exceptions.ValidationError(
_('Mailbox %s not found!') % folder.path)
connection.close()
this.write({'state': 'done'})
return retval
def fields_view_get(
self, view_id=None, view_type='form',
toolbar=False, submenu=False):

31
fetchmail_attach_from_folder/models/fetchmail_server_folder.py

@ -5,7 +5,7 @@ import base64
import logging
from odoo import _, api, models, fields
from odoo.exceptions import UserError
from odoo.exceptions import UserError, ValidationError
from .. import match_algorithm
@ -35,11 +35,21 @@ class FetchmailServerFolder(models.Model):
algorithms.sort()
return algorithms
server_id = fields.Many2one('fetchmail.server', 'Server')
sequence = fields.Integer('Sequence')
state = fields.Selection([
('draft', 'Not Confirmed'),
('done', 'Confirmed')],
string='Status',
readonly=True,
required=True,
copy=False,
default='draft')
path = fields.Char(
'Path',
help="The path to your mail folder. Typically would be something like "
"'INBOX.myfolder'", required=True)
required=True,
help="The path to your mail folder."
" Typically would be something like 'INBOX.myfolder'")
model_id = fields.Many2one(
'ir.model', 'Model', required=True,
help='The model to attach emails to')
@ -62,7 +72,6 @@ class FetchmailServerFolder(models.Model):
'Field (email)',
help='The field in the email used for matching. Typically '
"this is 'to' or 'from'")
server_id = fields.Many2one('fetchmail.server', 'Server')
delete_matching = fields.Boolean(
'Delete matches',
help='Delete matched emails from server')
@ -89,6 +98,20 @@ class FetchmailServerFolder(models.Model):
def get_algorithm(self):
return self._get_match_algorithms()[self.match_algorithm]()
@api.multi
def button_confirm_folder(self):
for this in self:
this.write({'state': 'draft'})
if not this.active:
continue
connection = this.server_id.connect()
connection.select()
if connection.select(this.path)[0] != 'OK':
raise ValidationError(
_('Invalid folder %s!') % this.path)
connection.close()
this.write({'state': 'done'})
@api.multi
def button_attach_mail_manually(self):
self.ensure_one()

8
fetchmail_attach_from_folder/views/fetchmail_server.xml

@ -33,12 +33,18 @@
<field name="mail_field" />
</tree>
<form>
<field name="state" invisible="1" />
<header>
<button
type="object"
name="button_confirm_folder"
string="Test &amp; Confirm"
states="draft"/>
<button
type="object"
name="button_attach_mail_manually"
string="Attach mail manually"
icon="gtk-redo" />
states="done"/>
</header>
<group>
<group>

Loading…
Cancel
Save