'Process an incoming RFC2822 email message, relying on
``mail.message.parse()`` for the parsing operation,
and ``message_route()`` to figure out the target model.
Once the target model is known, its ``message_new`` method
is called with the new message (if the thread record did not exist)
or its ``message_update`` method (if it did).
There is a special case where the target model is False: a reply
to a private message. In this case, we skip the message_new /
message_update step, to just post a new message using mail_thread
message_post.
:param string model: the fallback model to use if the message
does not match any of the currently configured mail aliases
(may be None if a matching alias is supposed to be present)
:param message: source of the RFC2822 message
:type message: string or xmlrpclib.Binary
:type dict custom_values: optional dictionary of field values
to pass to ``message_new`` if a new record needs to be created.
Ignored if the thread record already exists, and also if a
matching mail.alias was found (aliases define their own defaults)
:param bool save_original: whether to keep a copy of the original
email source attached to the message after it is imported.
:param bool strip_attachments: whether to strip all attachments
before processing the message, in order to save some space.
:param int thread_id: optional ID of the record/thread from ``model``
to which this mail should be attached. When provided, this
overrides the automatic detection based on the message
headers.'

@api.model
def message_process(self, model, message, custom_values=None, save_original=False, strip_attachments=False, thread_id=None):

    if isinstance(message, xmlrpclib.Binary):
        message = str(message.data)
    if isinstance(message, unicode):
        message = message.encode('utf-8')
    msg_txt = email.message_from_string(message)
    msg = self.message_parse(msg_txt, save_original=save_original)
    if strip_attachments:
        msg.pop('attachments', None)
    if msg.get('message_id'):
        existing_msg_ids = self.env['mail.message'].search([('message_id', '=', msg.get('message_id'))])
        if existing_msg_ids:
            _logger.info('Ignored    mail    from    %s    to    %s    with    Message-Id    %s:    found    duplicated    Message-Id    during    processing', msg.get('from'), msg.get('to'), msg.get('message_id'))
            return False
    routes = self.message_route(msg_txt, msg, model, thread_id, custom_values)
    thread_id = self.message_route_process(msg_txt, msg, routes)
    return thread_id
