- def _get_reply_to(self, cr, uid, values, context=None):
- """ Return a specific reply_to: alias of the document through message_get_reply_to
- or take the email_from
- """
- if values.get('reply_to'):
- return values.get('reply_to')
- email_reply_to = False
-
- # model, res_id: comes from values OR related message
- model = values.get('model')
- res_id = values.get('res_id')
- if values.get('mail_message_id') and (not model or not res_id):
- message = self.pool.get('mail.message').browse(cr, uid, values.get('mail_message_id'), context=context)
- if not model:
- model = message.model
- if not res_id:
- res_id = message.res_id
-
- # if model and res_id: try to use ``message_get_reply_to`` that returns the document alias
- if model and res_id and hasattr(self.pool[model], 'message_get_reply_to'):
- email_reply_to = self.pool[model].message_get_reply_to(cr, uid, [res_id], context=context)[0]
- # no alias reply_to -> reply_to will be the email_from, only the email part
- if not email_reply_to and values.get('email_from'):
- emails = tools.email_split(values.get('email_from'))
- if emails:
- email_reply_to = emails[0]
-
- # format 'Document name <email_address>'
- if email_reply_to and model and res_id:
- document_name = self.pool[model].name_get(cr, SUPERUSER_ID, [res_id], context=context)[0]
- if document_name:
- # sanitize document name
- sanitized_doc_name = re.sub(r'[^\w+.]+', '-', document_name[1])
- # generate reply to
- email_reply_to = _('"Followers of %s" <%s>') % (sanitized_doc_name, email_reply_to)
-
- return email_reply_to
-