[MRG] lp:~therp-nl/therp-addons/fetchmail_attach_from_folder rev 89

pull/2800/head
Holger Brunn 2013-03-26 12:22:16 +01:00 committed by Ronald Portier
parent cfe406a223
commit 7f167a7580
7 changed files with 60 additions and 14 deletions

View File

@ -24,7 +24,7 @@ from email_exact import email_exact
class email_domain(email_exact): class email_domain(email_exact):
'''Search objects by domain name of email address. '''Search objects by domain name of email address.
Beware of match_first here, this is most likely to ge it wrong (gmail...)''' Beware of match_first here, this is most likely to get it wrong (gmail)'''
name = 'Domain of email address' name = 'Domain of email address'
def search_matches(self, cr, uid, conf, mail_message, mail_message_org): def search_matches(self, cr, uid, conf, mail_message, mail_message_org):

View File

@ -25,6 +25,8 @@ from openerp.tools.safe_eval import safe_eval
from openerp.addons.mail.mail_message import to_email from openerp.addons.mail.mail_message import to_email
class email_exact(base): class email_exact(base):
'''Search for exactly the mailadress as noted in the email'''
name = 'Exact mailadress' name = 'Exact mailadress'
required_fields = ['model_field', 'mail_field'] required_fields = ['model_field', 'mail_field']

View File

@ -24,6 +24,9 @@ from base import base
from openerp.tools.safe_eval import safe_eval from openerp.tools.safe_eval import safe_eval
class openerp_standard(base): class openerp_standard(base):
'''No search at all. Use OpenERP's standard mechanism to attach mails to
mail.thread objects. Note that this algorithm always matches.'''
name = 'OpenERP standard' name = 'OpenERP standard'
readonly_fields = ['model_field', 'mail_field', 'match_first', 'domain', readonly_fields = ['model_field', 'mail_field', 'match_first', 'domain',
'model_order', 'flag_nonmatching'] 'model_order', 'flag_nonmatching']

View File

@ -193,7 +193,7 @@ class fetchmail_server(Model):
if view_type == 'form': if view_type == 'form':
view = etree.fromstring( view = etree.fromstring(
result['fields']['folder_ids']['views']['tree']['arch']) result['fields']['folder_ids']['views']['form']['arch'])
modifiers={} modifiers={}
docstr='' docstr=''
for algorithm in self.pool.get('fetchmail.server.folder')\ for algorithm in self.pool.get('fetchmail.server.folder')\
@ -206,7 +206,8 @@ class fetchmail_server(Model):
modifiers[field][modifier].insert(0, '|') modifiers[field][modifier].insert(0, '|')
modifiers[field][modifier].append( modifiers[field][modifier].append(
("match_algorithm","==",algorithm.__name__)) ("match_algorithm","==",algorithm.__name__))
docstr+=_(algorithm.__doc__) or '' docstr += _(algorithm.name) + '\n' + _(algorithm.__doc__) + \
'\n\n'
for field in view: for field in view:
if field.tag == 'field' and field.get('name') in modifiers: if field.tag == 'field' and field.get('name') in modifiers:
@ -218,7 +219,7 @@ class fetchmail_server(Model):
if (field.tag == 'field' and if (field.tag == 'field' and
field.get('name') == 'match_algorithm'): field.get('name') == 'match_algorithm'):
field.set('help', docstr) field.set('help', docstr)
result['fields']['folder_ids']['views']['tree']['arch'] = \ result['fields']['folder_ids']['views']['form']['arch'] = \
etree.tostring(view) etree.tostring(view)
return result return result

View File

@ -48,17 +48,41 @@ class fetchmail_server_folder(Model):
'Path', size=256, help='The path to your mail ' 'Path', size=256, help='The path to your mail '
'folder. Typically would be something like \'INBOX.myfolder\'', 'folder. Typically would be something like \'INBOX.myfolder\'',
required=True), required=True),
'model_id': fields.many2one('ir.model', 'Model', required=True), 'model_id': fields.many2one(
'model_field': fields.char('Field (model)', size=128), 'ir.model', 'Model', required=True,
'model_order': fields.char('Order (model)', size=128), help='The model to attach emails to'),
'model_field': fields.char(
'Field (model)', size=128,
help='The field in your model that contains the field to match '
'against.\n'
'Examples:\n'
'\'email\' if your model is res.partner, or '
'\'partner_id.email\' if you\'re matching sale orders'),
'model_order': fields.char(
'Order (model)', size=128,
help='Fields to order by, this mostly useful in conjunction '
'with \'Use 1st match\''),
'match_algorithm': fields.selection( 'match_algorithm': fields.selection(
_get_match_algorithms_sel, _get_match_algorithms_sel,
'Match algorithm', required=True, translate=True), 'Match algorithm', required=True, translate=True,
'mail_field': fields.char('Field (email)', size=128), help='The algorithm used to determine which object an email '
'matches.'),
'mail_field': fields.char(
'Field (email)', size=128,
help='The field in the email used for matching. Typically '
'this is \'to\' or \'from\''),
'server_id': fields.many2one('fetchmail.server', 'Server'), 'server_id': fields.many2one('fetchmail.server', 'Server'),
'delete_matching': fields.boolean('Delete matches'), 'delete_matching': fields.boolean(
'flag_nonmatching': fields.boolean('Flag nonmatching'), 'Delete matches',
'match_first': fields.boolean('Use 1st match'), help='Delete matched emails from server'),
'flag_nonmatching': fields.boolean(
'Flag nonmatching',
help='Flag emails in the server that don\'t match any object '
'in OpenERP'),
'match_first': fields.boolean(
'Use 1st match',
help='If there are multiple matches, use the first one. If '
'not checked, multiple matches count as no match at all'),
'domain': fields.char( 'domain': fields.char(
'Domain', size=128, help='Fill in a search ' 'Domain', size=128, help='Fill in a search '
'filter to narrow down objects to match') 'filter to narrow down objects to match')

View File

@ -19,7 +19,7 @@
nolabel="1" nolabel="1"
colspan="2" colspan="2"
on_change="onchange_server_type(type, is_ssl, object_id)"> on_change="onchange_server_type(type, is_ssl, object_id)">
<tree editable="bottom"> <tree>
<field name="sequence" invisible="1" /> <field name="sequence" invisible="1" />
<field name="path" /> <field name="path" />
<field name="model_id" /> <field name="model_id" />
@ -38,6 +38,21 @@
string="Attach mail manually" string="Attach mail manually"
icon="gtk-redo" /> icon="gtk-redo" />
</tree> </tree>
<form col="6">
<field name="path" />
<field name="model_id" />
<field name="model_field" />
<field name="match_algorithm" />
<field name="mail_field" />
<newline />
<field name="delete_matching" />
<field name="flag_nonmatching" />
<field name="match_first" />
<field name="model_order" attrs="{'readonly': [('match_first','==',False)], 'required': [('match_first','==',True)]}" />
<field name="domain" />
<label />
<button type="object" name="button_attach_mail_manually" string="Attach mail manually" icon="gtk-redo" />
</form>
</field> </field>
</group> </group>
</xpath> </xpath>

View File

@ -46,7 +46,8 @@ class attach_mail_manually(TransientModel):
defaults['mail_ids']=[] defaults['mail_ids']=[]
connection = folder.server_id.connect() connection = folder.server_id.connect()
connection.select(folder.path) connection.select(folder.path)
result, msgids = connection.search(None, 'UNDELETED') result, msgids = connection.search(None,
'FLAGGED' if folder.flag_nonmatching else 'UNDELETED')
if result != 'OK': if result != 'OK':
logger.error('Could not search mailbox %s on %s' % ( logger.error('Could not search mailbox %s on %s' % (
folder.path, this.server)) folder.path, this.server))