[IMP] make fetch_mail's refactoring more useful by returning the ids of
mails creates/objects matched [ADD] preliminary docstringspull/78/head
parent
5c03dba5a6
commit
466d88fb2f
|
@ -48,4 +48,4 @@ class openerp_standard(base):
|
||||||
if folder.delete_matching:
|
if folder.delete_matching:
|
||||||
connection.store(msgid, '+FLAGS', '\\DELETED')
|
connection.store(msgid, '+FLAGS', '\\DELETED')
|
||||||
|
|
||||||
return result
|
return [result]
|
||||||
|
|
|
@ -83,6 +83,10 @@ class fetchmail_server(Model):
|
||||||
cr, uid, check_original, context)
|
cr, uid, check_original, context)
|
||||||
|
|
||||||
def handle_folder(self, cr, uid, ids, connection, folder, context=None):
|
def handle_folder(self, cr, uid, ids, connection, folder, context=None):
|
||||||
|
'''Return ids of objects matched'''
|
||||||
|
|
||||||
|
matched_object_ids = []
|
||||||
|
|
||||||
for this in self.browse(cr, uid, ids, context=context):
|
for this in self.browse(cr, uid, ids, context=context):
|
||||||
logger.info('start checking for emails in %s server %s',
|
logger.info('start checking for emails in %s server %s',
|
||||||
folder.path, this.name)
|
folder.path, this.name)
|
||||||
|
@ -103,16 +107,23 @@ class fetchmail_server(Model):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for msgid in msgids[0].split():
|
for msgid in msgids[0].split():
|
||||||
this.apply_matching(connection, folder, msgid, match_algorithm)
|
matched_object_ids += this.apply_matching(
|
||||||
|
connection, folder, msgid, match_algorithm)
|
||||||
|
|
||||||
logger.info('finished checking for emails in %s server %s',
|
logger.info('finished checking for emails in %s server %s',
|
||||||
folder.path, this.name)
|
folder.path, this.name)
|
||||||
|
|
||||||
|
return matched_object_ids
|
||||||
|
|
||||||
def get_msgids(self, cr, uid, ids, connection, context=None):
|
def get_msgids(self, cr, uid, ids, connection, context=None):
|
||||||
|
'''Return imap ids of messages to process'''
|
||||||
return connection.search(None, 'UNDELETED')
|
return connection.search(None, 'UNDELETED')
|
||||||
|
|
||||||
def apply_matching(self, cr, uid, ids, connection, folder, msgid,
|
def apply_matching(self, cr, uid, ids, connection, folder, msgid,
|
||||||
match_algorithm, context=None):
|
match_algorithm, context=None):
|
||||||
|
'''Return ids of objects matched'''
|
||||||
|
|
||||||
|
matched_object_ids = []
|
||||||
|
|
||||||
for this in self.browse(cr, uid, ids, context=context):
|
for this in self.browse(cr, uid, ids, context=context):
|
||||||
result, msgdata = connection.fetch(msgid, '(RFC822)')
|
result, msgdata = connection.fetch(msgid, '(RFC822)')
|
||||||
|
@ -142,6 +153,7 @@ class fetchmail_server(Model):
|
||||||
found_ids[0], folder, mail_message,
|
found_ids[0], folder, mail_message,
|
||||||
msgdata[0][1], msgid, context)
|
msgdata[0][1], msgid, context)
|
||||||
cr.commit()
|
cr.commit()
|
||||||
|
matched_object_ids += found_ids[:1]
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
cr.rollback()
|
cr.rollback()
|
||||||
logger.exception(
|
logger.exception(
|
||||||
|
@ -150,9 +162,15 @@ class fetchmail_server(Model):
|
||||||
elif folder.flag_nonmatching:
|
elif folder.flag_nonmatching:
|
||||||
connection.store(msgid, '+FLAGS', '\\FLAGGED')
|
connection.store(msgid, '+FLAGS', '\\FLAGGED')
|
||||||
|
|
||||||
|
return matched_object_ids
|
||||||
|
|
||||||
def attach_mail(
|
def attach_mail(
|
||||||
self, cr, uid, ids, connection, object_id, folder,
|
self, cr, uid, ids, connection, object_id, folder,
|
||||||
mail_message, msgid, context=None):
|
mail_message, msgid, context=None):
|
||||||
|
'''Return ids of messages created'''
|
||||||
|
|
||||||
|
mail_message_ids = []
|
||||||
|
|
||||||
for this in self.browse(cr, uid, ids, context):
|
for this in self.browse(cr, uid, ids, context):
|
||||||
partner_id = None
|
partner_id = None
|
||||||
if folder.model_id.model == 'res.partner':
|
if folder.model_id.model == 'res.partner':
|
||||||
|
@ -181,30 +199,32 @@ class fetchmail_server(Model):
|
||||||
self.pool.get('ir.attachment').create(
|
self.pool.get('ir.attachment').create(
|
||||||
cr, uid, data_attach, context=context))
|
cr, uid, data_attach, context=context))
|
||||||
|
|
||||||
self.pool.get('mail.message').create(
|
mail_message_ids.append(
|
||||||
cr, uid,
|
self.pool.get('mail.message').create(
|
||||||
{
|
cr, uid,
|
||||||
'partner_id': partner_id,
|
{
|
||||||
'model': folder.model_id.model,
|
'partner_id': partner_id,
|
||||||
'res_id': object_id,
|
'model': folder.model_id.model,
|
||||||
'body_text': mail_message.get('body'),
|
'res_id': object_id,
|
||||||
'body_html': mail_message.get('body_html'),
|
'body_text': mail_message.get('body'),
|
||||||
'subject': mail_message.get('subject'),
|
'body_html': mail_message.get('body_html'),
|
||||||
'email_to': mail_message.get('to'),
|
'subject': mail_message.get('subject'),
|
||||||
'email_from': mail_message.get('from'),
|
'email_to': mail_message.get('to'),
|
||||||
'email_cc': mail_message.get('cc'),
|
'email_from': mail_message.get('from'),
|
||||||
'reply_to': mail_message.get('reply'),
|
'email_cc': mail_message.get('cc'),
|
||||||
'date': mail_message.get('date'),
|
'reply_to': mail_message.get('reply'),
|
||||||
'message_id': mail_message.get('message-id'),
|
'date': mail_message.get('date'),
|
||||||
'subtype': mail_message.get('subtype'),
|
'message_id': mail_message.get('message-id'),
|
||||||
'headers': mail_message.get('headers'),
|
'subtype': mail_message.get('subtype'),
|
||||||
'state': folder.msg_state,
|
'headers': mail_message.get('headers'),
|
||||||
'attachment_ids': [(6, 0, attachments)],
|
'state': folder.msg_state,
|
||||||
},
|
'attachment_ids': [(6, 0, attachments)],
|
||||||
context)
|
},
|
||||||
|
context))
|
||||||
|
|
||||||
if folder.delete_matching:
|
if folder.delete_matching:
|
||||||
connection.store(msgid, '+FLAGS', '\\DELETED')
|
connection.store(msgid, '+FLAGS', '\\DELETED')
|
||||||
|
return mail_message_ids
|
||||||
|
|
||||||
def button_confirm_login(self, cr, uid, ids, context=None):
|
def button_confirm_login(self, cr, uid, ids, context=None):
|
||||||
retval = super(fetchmail_server, self).button_confirm_login(cr, uid,
|
retval = super(fetchmail_server, self).button_confirm_login(cr, uid,
|
||||||
|
|
Loading…
Reference in New Issue