[IMP] mail: added JSON end-point to receive mails.

bzr revid: vmt@openerp.com-20130619132123-efw3fyqqw33q0s4q
This commit is contained in:
Vo Minh Thu 2013-06-19 15:21:23 +02:00
parent ac1d0742a0
commit 960252d091
1 changed files with 18 additions and 0 deletions

View File

@ -1,4 +1,7 @@
import base64
import openerp
from openerp import SUPERUSER_ID
import openerp.addons.web.http as oeweb
from openerp.addons.web.controllers.main import content_disposition
@ -20,3 +23,18 @@ class MailController(oeweb.Controller):
headers=[('Content-Type', 'application/octet-stream'),
('Content-Disposition', content_disposition(filename, req))])
return req.not_found()
@oeweb.jsonrequest
def receive(self, req):
""" End-point to receive mail from an external SMTP server. """
dbs = req.jsonrequest.get('databases')
for db in dbs:
message = dbs[db].decode('base64')
try:
registry = openerp.registry(db)
with registry.cursor() as cr:
mail_thread = registry['mail.thread']
mail_thread.message_process(cr, SUPERUSER_ID, None, message)
except psycopg2.Error:
pass
return True