5 from openerp import SUPERUSER_ID
6 from openerp import http
7 from openerp.http import request
8 from openerp.addons.web.controllers.main import content_disposition
12 class MailController(http.Controller):
15 @http.route('/mail/download_attachment', type='http', auth='user')
16 def download_attachment(self, model, id, method, attachment_id, **kw):
17 # FIXME use /web/binary/saveas directly
18 Model = request.registry.get(model)
19 res = getattr(Model, method)(request.cr, request.uid, int(id), int(attachment_id))
21 filecontent = base64.b64decode(res.get('base64'))
22 filename = res.get('filename')
23 content_type = mimetypes.guess_type(filename)
24 if filecontent and filename:
25 return request.make_response(
27 headers=[('Content-Type', content_type[0] or 'application/octet-stream'),
28 ('Content-Disposition', content_disposition(filename))])
29 return request.not_found()
31 @http.route('/mail/receive', type='json', auth='none')
32 def receive(self, req):
33 """ End-point to receive mail from an external SMTP server. """
34 dbs = req.jsonrequest.get('databases')
36 message = dbs[db].decode('base64')
38 registry = openerp.registry(db)
39 with registry.cursor() as cr:
40 mail_thread = registry['mail.thread']
41 mail_thread.message_process(cr, SUPERUSER_ID, None, message)
42 except psycopg2.Error: