|
|
@ -22,6 +22,8 @@ |
|
|
|
|
|
|
|
from openerp.osv import fields |
|
|
|
from openerp.osv.orm import TransientModel |
|
|
|
import logging |
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
class attach_mail_manually(TransientModel): |
|
|
@ -38,19 +40,22 @@ class attach_mail_manually(TransientModel): |
|
|
|
if context is None: |
|
|
|
context = {} |
|
|
|
|
|
|
|
defaults = super(attach_mail_manually, self).default_get(cr, uid, |
|
|
|
fields_list, context) |
|
|
|
defaults = super(attach_mail_manually, self).default_get( |
|
|
|
cr, uid, fields_list, context |
|
|
|
) |
|
|
|
|
|
|
|
for folder in self.pool.get('fetchmail.server.folder').browse(cr, uid, |
|
|
|
for folder in self.pool.get('fetchmail.server.folder').browse( |
|
|
|
cr, uid, |
|
|
|
[context.get('default_folder_id')], context): |
|
|
|
defaults['mail_ids'] = [] |
|
|
|
connection = folder.server_id.connect() |
|
|
|
connection.select(folder.path) |
|
|
|
result, msgids = connection.search(None, |
|
|
|
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)) |
|
|
|
folder.path, folder.server_id.name)) |
|
|
|
continue |
|
|
|
attach_mail_manually_mail._columns['object_id'].selection = [ |
|
|
|
(folder.model_id.model, folder.model_id.name)] |
|
|
@ -58,12 +63,13 @@ class attach_mail_manually(TransientModel): |
|
|
|
result, msgdata = connection.fetch(msgid, '(RFC822)') |
|
|
|
if result != 'OK': |
|
|
|
logger.error('Could not fetch %s in %s on %s' % ( |
|
|
|
msgid, folder.path, this.server)) |
|
|
|
msgid, folder.path, folder.server_id.name)) |
|
|
|
continue |
|
|
|
mail_message = self.pool.get('mail.thread').message_parse( |
|
|
|
cr, uid, msgdata[0][1], |
|
|
|
save_original=folder.server_id.original, |
|
|
|
context=context) |
|
|
|
context=context |
|
|
|
) |
|
|
|
defaults['mail_ids'].append((0, 0, { |
|
|
|
'msgid': msgid, |
|
|
|
'subject': mail_message.get('subject', ''), |
|
|
@ -82,7 +88,7 @@ class attach_mail_manually(TransientModel): |
|
|
|
result, msgdata = connection.fetch(mail.msgid, '(RFC822)') |
|
|
|
if result != 'OK': |
|
|
|
logger.error('Could not fetch %s in %s on %s' % ( |
|
|
|
msgid, folder.path, this.server)) |
|
|
|
mail.msgid, this.folder_id.path, this.server)) |
|
|
|
continue |
|
|
|
|
|
|
|
mail_message = self.pool.get('mail.thread').message_parse( |
|
|
@ -90,12 +96,15 @@ class attach_mail_manually(TransientModel): |
|
|
|
save_original=this.folder_id.server_id.original, |
|
|
|
context=context) |
|
|
|
|
|
|
|
this.folder_id.server_id.attach_mail(connection, |
|
|
|
this.folder_id.server_id.attach_mail( |
|
|
|
connection, |
|
|
|
mail.object_id.id, this.folder_id, mail_message, |
|
|
|
mail.msgid) |
|
|
|
mail.msgid |
|
|
|
) |
|
|
|
connection.close() |
|
|
|
return {'type': 'ir.actions.act_window_close'} |
|
|
|
|
|
|
|
|
|
|
|
class attach_mail_manually_mail(TransientModel): |
|
|
|
_name = 'fetchmail.attach.mail.manually.mail' |
|
|
|
|
|
|
@ -105,10 +114,16 @@ class attach_mail_manually_mail(TransientModel): |
|
|
|
'msgid': fields.char('Message id', size=16, readonly=True), |
|
|
|
'subject': fields.char('Subject', size=128, readonly=True), |
|
|
|
'date': fields.datetime('Date', readonly=True), |
|
|
|
'object_id': fields.reference('Object', |
|
|
|
selection=lambda self, cr, uid, context: |
|
|
|
[(m.model, m.name) for m in |
|
|
|
self.pool.get('ir.model').browse(cr, uid, |
|
|
|
'object_id': fields.reference( |
|
|
|
'Object', |
|
|
|
selection=lambda self, cr, uid, context: [ |
|
|
|
(m.model, m.name) |
|
|
|
for m in self.pool.get('ir.model').browse( |
|
|
|
cr, uid, |
|
|
|
self.pool.get('ir.model').search(cr, uid, []), |
|
|
|
context)], size=128), |
|
|
|
context |
|
|
|
) |
|
|
|
], |
|
|
|
size=128, |
|
|
|
), |
|
|
|
} |