<commit_before>import base64
import psycopg2

import openerp
from openerp import SUPERUSER_ID
from openerp import http
from openerp.addons.web.controllers.main import content_disposition


class MailController(http.Controller):
    _cp_path = '/mail'

    @http.route('/mail/download_attachment', type='http', auth='user')
    def download_attachment(self, req, model, id, method, attachment_id, **kw):
        # FIXME use /web/binary/saveas directly
        Model = req.session.model(model)
        res = getattr(Model, method)(int(id), int(attachment_id))
        if res:
            filecontent = base64.b64decode(res.get('base64'))
            filename = res.get('filename')
            if filecontent and filename:
                return req.make_response(filecontent,
                    headers=[('Content-Type', 'application/octet-stream'),
                            ('Content-Disposition', content_disposition(filename))])
        return req.not_found()

    @http.route('/mail/receive', type='json', auth='none')
    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)<commit_msg>[FIX] mail: fixed download_attachment controller<commit_after>import base64
import psycopg2

import openerp
from openerp import SUPERUSER_ID
from openerp import http
from openerp.http import request
from openerp.addons.web.controllers.main import content_disposition


class MailController(http.Controller):
    _cp_path = '/mail'

    @http.route('/mail/download_attachment', type='http', auth='user')
    def download_attachment(self, model, id, method, attachment_id, **kw):
        # FIXME use /web/binary/saveas directly
        Model = request.registry.get(model)
        res = getattr(Model, method)(request.cr, request.uid, int(id), int(attachment_id))
        if res:
            filecontent = base64.b64decode(res.get('base64'))
            filename = res.get('filename')
            if filecontent and filename:
                return request.make_response(
                    filecontent,
                    headers=[('Content-Type', 'application/octet-stream'),
                             ('Content-Disposition', content_disposition(filename))])
        return request.not_found()

    @http.route('/mail/receive', type='json', auth='none')
    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)
{'fraction_non_alphanumeric': 0.11643090315560392, 'fraction_numerical': 0.00797968806673921, 'mean_word_length': 2.6724367509986684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5693165', 'n_tokens_mistral': 788, 'n_tokens_neox': 749, 'n_words': 183}