Reputation: 57
I want to get the email body but not in html format . I have used Beautifulsoup and data = re.sub(r'<.*?>', '', html2) to remove the html tags but it didn't work I can't receieve email to applicant
def message_new(self, cr, uid, msg, custom_values=None, context=None):
""" Overrides mail_thread message_new that is called by the mailgateway
through message_process.
This override updates the document according to the email.
"""
if custom_values is None:
custom_values = {}
val = msg.get('from').split('<')[0]
val1 = msg.get('from').split('<')[1]
val2 = val1.split('>')[0]
myString2 = msg.get('body') if msg.get('body') else ''
soup = BeautifulSoup(myString2)
data = soup.get_text()
defaults = {
'name': msg.get('subject') or _("No Subject"),
'partner_name': val,
'email_from': val2,
'email_cc': msg.get('cc'),
'user_id': False,
'partner_id': msg.get('author_id', False),
'description': data,
}
if msg.get('priority'):
defaults['priority'] = msg.get('priority')
defaults.update(custom_values)
return super(hr_applicant, self).message_new(cr, uid, msg,custom_values=defaults, context=context)
Upvotes: 0
Views: 3242
Reputation: 79
please try re library of python for remove html tags from text.
import re
text = re.compile('<.*?>')
message = re.sub(text, '', self.body)
Upvotes: 1
Reputation: 5931
I've been using HTMLParser with good success for the exact same thing: stripping out the HTML tags but keep the data.
from HTMLParser import HTMLParser
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.append(d)
def get_data(self):
return ''.join(self.fed)
def strip_tags(html):
s = MLStripper()
s.feed(html)
return s.get_data()
strip_tags
expects a string containing your HTML content.
Upvotes: 0