Browse Source

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

pull/78/head
Holger Brunn 12 years ago
parent
commit
05021bf360
  1. 2
      fetchmail_attach_from_folder/match_algorithm/email_domain.py
  2. 2
      fetchmail_attach_from_folder/match_algorithm/email_exact.py
  3. 3
      fetchmail_attach_from_folder/match_algorithm/openerp_standard.py
  4. 7
      fetchmail_attach_from_folder/model/fetchmail_server.py
  5. 40
      fetchmail_attach_from_folder/model/fetchmail_server_folder.py
  6. 17
      fetchmail_attach_from_folder/view/fetchmail_server.xml
  7. 3
      fetchmail_attach_from_folder/wizard/attach_mail_manually.py

2
fetchmail_attach_from_folder/match_algorithm/email_domain.py

@ -24,7 +24,7 @@ from email_exact import email_exact
class email_domain(email_exact):
'''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'
def search_matches(self, cr, uid, conf, mail_message, mail_message_org):

2
fetchmail_attach_from_folder/match_algorithm/email_exact.py

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

3
fetchmail_attach_from_folder/match_algorithm/openerp_standard.py

@ -24,6 +24,9 @@ from base import base
from openerp.tools.safe_eval import safe_eval
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'
readonly_fields = ['model_field', 'mail_field', 'match_first', 'domain',
'model_order', 'flag_nonmatching']

7
fetchmail_attach_from_folder/model/fetchmail_server.py

@ -193,7 +193,7 @@ class fetchmail_server(Model):
if view_type == 'form':
view = etree.fromstring(
result['fields']['folder_ids']['views']['tree']['arch'])
result['fields']['folder_ids']['views']['form']['arch'])
modifiers={}
docstr=''
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].append(
("match_algorithm","==",algorithm.__name__))
docstr+=_(algorithm.__doc__) or ''
docstr += _(algorithm.name) + '\n' + _(algorithm.__doc__) + \
'\n\n'
for field in view:
if field.tag == 'field' and field.get('name') in modifiers:
@ -218,7 +219,7 @@ class fetchmail_server(Model):
if (field.tag == 'field' and
field.get('name') == 'match_algorithm'):
field.set('help', docstr)
result['fields']['folder_ids']['views']['tree']['arch'] = \
result['fields']['folder_ids']['views']['form']['arch'] = \
etree.tostring(view)
return result

40
fetchmail_attach_from_folder/model/fetchmail_server_folder.py

@ -48,17 +48,41 @@ class fetchmail_server_folder(Model):
'Path', size=256, help='The path to your mail '
'folder. Typically would be something like \'INBOX.myfolder\'',
required=True),
'model_id': fields.many2one('ir.model', 'Model', required=True),
'model_field': fields.char('Field (model)', size=128),
'model_order': fields.char('Order (model)', size=128),
'model_id': fields.many2one(
'ir.model', 'Model', required=True,
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(
_get_match_algorithms_sel,
'Match algorithm', required=True, translate=True),
'mail_field': fields.char('Field (email)', size=128),
'Match algorithm', required=True, translate=True,
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'),
'delete_matching': fields.boolean('Delete matches'),
'flag_nonmatching': fields.boolean('Flag nonmatching'),
'match_first': fields.boolean('Use 1st match'),
'delete_matching': fields.boolean(
'Delete matches',
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', size=128, help='Fill in a search '
'filter to narrow down objects to match')

17
fetchmail_attach_from_folder/view/fetchmail_server.xml

@ -19,7 +19,7 @@
nolabel="1"
colspan="2"
on_change="onchange_server_type(type, is_ssl, object_id)">
<tree editable="bottom">
<tree>
<field name="sequence" invisible="1" />
<field name="path" />
<field name="model_id" />
@ -38,6 +38,21 @@
string="Attach mail manually"
icon="gtk-redo" />
</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>
</group>
</xpath>

3
fetchmail_attach_from_folder/wizard/attach_mail_manually.py

@ -46,7 +46,8 @@ class attach_mail_manually(TransientModel):
defaults['mail_ids']=[]
connection = folder.server_id.connect()
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':
logger.error('Could not search mailbox %s on %s' % (
folder.path, this.server))

Loading…
Cancel
Save