Browse Source

Merge pull request #286 from StefanRijnhart/8.0-fetchmail_folder_context

[IMP] Allow for context on fetchmail folder configurations to set default values
pull/295/head
Alexandre Fayolle 9 years ago
parent
commit
aab03c013c
  1. 13
      fetchmail_attach_from_folder/model/fetchmail_server.py
  2. 4
      fetchmail_attach_from_folder/model/fetchmail_server_folder.py
  3. 1
      fetchmail_attach_from_folder/view/fetchmail_server.xml

13
fetchmail_attach_from_folder/model/fetchmail_server.py

@ -24,6 +24,7 @@ import base64
import simplejson
from lxml import etree
from openerp import models, fields, api, exceptions
from openerp.tools.safe_eval import safe_eval
from openerp.tools.translate import _
from openerp.tools.misc import UnquoteEvalContext
_logger = logging.getLogger(__name__)
@ -69,7 +70,8 @@ class fetchmail_server(models.Model):
connection = this.connect()
for folder in this.folder_ids.filtered('active'):
this.handle_folder(connection, folder)
this.with_context(safe_eval(folder.context or '{}'))\
.handle_folder(connection, folder)
connection.close()
return super(fetchmail_server, self).fetch_mail(
@ -218,6 +220,15 @@ class fetchmail_server(models.Model):
connection = this.connect()
connection.select()
for folder in this.folder_ids.filtered('active'):
try:
folder_context = safe_eval(folder.context or '{}')
except Exception, e:
raise exceptions.ValidationError(
_('Invalid context "%s": %s') % (folder.context, e))
if not isinstance(folder_context, dict):
raise exceptions.ValidationError(
_('Context "%s" is not a dictionary.') %
folder.context)
if connection.select(folder.path)[0] != 'OK':
raise exceptions.ValidationError(
_('Mailbox %s not found!') % folder.path)

4
fetchmail_attach_from_folder/model/fetchmail_server_folder.py

@ -86,6 +86,10 @@ class fetchmail_server_folder(models.Model):
domain = fields.Char(
'Domain',
help='Fill in a search filter to narrow down objects to match')
context = fields.Char(
'Context',
help=('Context that is passed during mail processing. Can be used to '
'set default values.'))
msg_state = fields.Selection(
[
('sent', 'Sent'),

1
fetchmail_attach_from_folder/view/fetchmail_server.xml

@ -45,6 +45,7 @@
<field name="msg_state" />
<field name="model_order" attrs="{'readonly': [('match_first','==',False)], 'required': [('match_first','==',True)]}" placeholder="name asc,type desc" />
<field name="domain" placeholder="[('state', '=', 'open')]" />
<field name="context" placeholder="{'default_supplier': True}" />
</group>
</group>
</form>

Loading…
Cancel
Save