在自动引导收到的电子邮件中,我添加了下面显示的代码,如何将电子邮件的正文添加到说明中,但我得到的是html格式 任何人都可以知道如何添加电子邮件正文的内容与描述字段相同。
def message_new(self, cr, uid, msg, custom_values=None, context=None):
myString = msg.get('subject', '')
myString.index('Phone:')
mobileNumber = myString[myString.index('Phone:')+6:myString.index('Phone:')+16]
if context is None:
context = {}
data = {}
if isinstance(custom_values, dict):
data = custom_values.copy()
model = context.get('thread_model') or self._name
model_pool = self.pool[model]
fields = model_pool.fields_get(cr, uid, context=context)
if 'name' in fields and not data.get('name'):
data['name'] = msg.get('subject', '')
if 'mobile' in fields and not data.get('mobile'):
data['mobile'] = mobileNumber
if 'description' in fields and not data.get('description'):
data['description'] = msg.get('body', '')
res_id = model_pool.create(cr, uid, data, context=context)
return res_id
答案 0 :(得分:1)
试试:
from openerp.tools import html2plaintext
# ...
if 'description' in fields and not data.get('description'):
data['description'] = html2plaintext(msg.get('body')) if msg.get('body') else ''
# ...