[FIX] fetchmail:

* sever_id pass into context instead of as a parameter into process method call

bzr revid: hmo@tinyerp.com-20100625095741-m5lign7qe8erey7o
This commit is contained in:
Harry (OpenERP) 2010-06-25 15:27:41 +05:30
parent bcb1b02c10
commit 0226465056
3 changed files with 40 additions and 18 deletions

View File

@ -107,12 +107,7 @@ class crm_send_new_email(osv.osv_memory):
body = obj.text
body = case_pool.format_body(body)
email_from = getattr(obj, 'email_from', False)
x_headers = {
'model': model,
'resource-id': res_id
}
email_from = getattr(obj, 'email_from', False)
if message_id:
x_headers['References'] = "%s" % (message_id)

View File

@ -50,7 +50,7 @@ class email_server(osv.osv):
'type':fields.selection([
('pop', 'POP Server'),
('imap', 'IMAP Server'),
], 'State', select=True, readonly=False),
], 'Server Type', select=True, readonly=False),
'is_ssl':fields.boolean('SSL ?', required=False),
'attach':fields.boolean('Add Attachments ?', required=False),
'date': fields.date('Date', readonly=True, states={'draft':[('readonly', False)]}),
@ -107,11 +107,13 @@ class email_server(osv.osv):
ids = self.search(cr, uid, [])
return self.fetch_mail(cr, uid, ids, context)
def fetch_mail(self, cr, uid, ids, context={}):
def fetch_mail(self, cr, uid, ids, context=None):
if not context:
context = {}
email_tool = self.pool.get('email.server.tools')
for server in self.browse(cr, uid, ids, context):
logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail start checking for new emails on %s' % (server.name))
context.update({'server_id': server.id, 'server_type': server.type})
count = 0
try:
if server.type == 'imap':
@ -123,10 +125,10 @@ class email_server(osv.osv):
imap_server.login(server.user, server.password)
imap_server.select()
result, data = imap_server.search(None, '(UNSEEN)')
result, data = imap_server.search(None, '(UNSEEN)')
for num in data[0].split():
result, data = imap_server.fetch(num, '(RFC822)')
res_id = email_tool.process_email(cr, uid, server.object_id.model, data[0][1], attach=server.attach, server_id=server.id, server_type=server.type, context=context)
res_id = email_tool.process_email(cr, uid, server.object_id.model, data[0][1], attach=server.attach, context=context)
if res_id and server.action_id:
action_pool = self.pool.get('ir.actions.server')
action_pool.run(cr, uid, [server.action_id.id], {'active_id': res_id, 'active_ids':[res_id]})
@ -154,7 +156,7 @@ class email_server(osv.osv):
for num in range(1, numMsgs + 1):
(header, msges, octets) = pop_server.retr(num)
msg = '\n'.join(msges)
res_id = email_tool.process_email(cr, uid, server.object_id.model, data[0][1], attach=server.attach, server_id=server.id, server_type=server.type, context=context)
res_id = email_tool.process_email(cr, uid, server.object_id.model, data[0][1], attach=server.attach, context=context)
if res_id and server.action_id:
action_pool = self.pool.get('ir.actions.server')
action_pool.run(cr, uid, [server.action_id.id], {'active_id': res_id, 'active_ids':[res_id]})
@ -182,10 +184,34 @@ class mailgate_message(osv.osv):
'type':fields.selection([
('pop', 'POP Server'),
('imap', 'IMAP Server'),
], 'State', select=True, readonly=True),
], 'Server Type', select=True, readonly=True),
}
_order = 'id desc'
def create(self, cr, uid, values, context=None):
if not context:
context={}
server_id = context.get('server_id',False)
server_type = context.get('server_type',False)
if server_id:
values['server_id'] = server_id
if server_type:
values['server_type'] = server_type
res = super(mailgate_message,self).create(cr, uid, values, context=context)
return res
def write(self, cr, uid, ids, values, context=None):
if not context:
context={}
server_id = context.get('server_id',False)
server_type = context.get('server_type',False)
if server_id:
values['server_id'] = server_id
if server_type:
values['server_type'] = server_type
res = super(mailgate_message,self).write(cr, uid, ids, values, context=context)
return res
mailgate_message()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -175,7 +175,7 @@ class mailgate_tool(osv.osv_memory):
bits = _email.sub(record, text)
return bits
def history(self, cr, uid, model, res_ids, msg, attach):
def history(self, cr, uid, model, res_ids, msg, attach, context=None):
"""This function creates history for mails fetched
@param self: The object pointer
@param cr: the current row, from the database cursor,
@ -205,7 +205,7 @@ class mailgate_tool(osv.osv_memory):
'user_id': uid,
'attachment_ids': [(6, 0, attach)]
}
msg_id = msg_pool.create(cr, uid, msg_data)
msg_id = msg_pool.create(cr, uid, msg_data, context=context)
return True
def email_send(self, cr, uid, model, res_id, msg, from_email=False, email_default=False):
@ -423,7 +423,8 @@ Thanks
if not len(res_ids):
new_res_id = create_record(msg)
res_ids = [new_res_id]
# Store messages
# Store messages
context.update({'model' : model})
if hasattr(model_pool, '_history'):
model_pool._history(cr, uid, res_ids, _('Receive'), history=True,
subject = msg.get('subject'),
@ -433,9 +434,9 @@ Thanks
message_id = msg.get('message-id'),
references = msg.get('references', False),
attach = msg.get('attachments', {}).items(),
context = {'model' : model})
context = context)
else:
self.history(cr, uid, model, res_ids, msg, att_ids)
self.history(cr, uid, model, res_ids, msg, att_ids, context=context)
return new_res_id
def get_partner(self, cr, uid, from_email, context=None):