'Overrides mail_thread message_new that is called by the mailgateway
through message_process.
This override updates the document according to the email.'

@api.model
def message_new(self, msg_dict, custom_values=None):

    self = self.with_context(default_user_id=False)
    if (custom_values is None):
        custom_values = {}
    defaults = {'name': (msg_dict.get('subject') or _('No    Subject')), 'email_from': msg_dict.get('from'), 'email_cc': msg_dict.get('cc'), 'partner_id': msg_dict.get('author_id', False)}
    if msg_dict.get('author_id'):
        defaults.update(self._onchange_partner_id_values(msg_dict.get('author_id')))
    if (msg_dict.get('priority') in dict(crm_stage.AVAILABLE_PRIORITIES)):
        defaults['priority'] = msg_dict.get('priority')
    defaults.update(custom_values)
    return super(Lead, self).message_new(msg_dict, custom_values=defaults)
