本文整理汇总了Python中email_reply_parser.EmailReplyParser类的典型用法代码示例。如果您正苦于以下问题:Python EmailReplyParser类的具体用法?Python EmailReplyParser怎么用?Python EmailReplyParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EmailReplyParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sentiment_sliding
def sentiment_sliding(messages, window=1000, shift=20):
allwords = []
data = {}
for m in messages:
if "\\Sent" not in m.get("folders", tuple()):
continue
if not m.get("body") or not m["body"].get("content"):
continue
allwords.append(EmailReplyParser.parse_reply(m["body"]["content"]))
allwords = " ".join(allwords)
allwords = allwords.encode("ascii", "ignore")
allwords = allwords.split()
current_window = 0
next_window = window
print "number of words", len(allwords)
while True:
if len(allwords) < next_window:
print "sliding-sentiment reached end at lengths:%s" % len(allwords)
break
print "sliding-sentiment start:%s end:%s" % (current_window, next_window)
data[current_window] = " ".join(allwords[current_window:next_window])
data[current_window] = indicoio.sentiment(data[current_window])
print data[current_window]
current_window += shift
next_window += shift
return data
示例2: collect_project_status
def collect_project_status():
for data in frappe.get_all("Project Update",
{'date': today(), 'sent': 0}):
replies = frappe.get_all('Communication',
fields=['content', 'text_content', 'sender'],
filters=dict(reference_doctype="Project Update",
reference_name=data.name,
communication_type='Communication',
sent_or_received='Received'),
order_by='creation asc')
for d in replies:
doc = frappe.get_doc("Project Update", data.name)
user_data = frappe.db.get_values("User", {"email": d.sender},
["full_name", "user_image", "name"], as_dict=True)[0]
doc.append("users", {
'user': user_data.name,
'full_name': user_data.full_name,
'image': user_data.user_image,
'project_status': frappe.utils.md_to_html(
EmailReplyParser.parse_reply(d.text_content) or d.content
)
})
doc.save(ignore_permissions=True)
示例3: incoming_letter_email
def incoming_letter_email():
body = EmailReplyParser.parse_reply(unicode(request.form.get('text')).encode('ascii','xmlcharrefreplace'))
body = '\n'.join(body.split('\n')).replace("\n","<br />")
regexp = re.findall(r'[\w\.-][email protected][\w\.-]+',request.form.get('from'))
try:
attachments = int(request.form.get('attachments'))
except Exception:
attachments = 0
if len(regexp) > 0 and len(regexp[-1]) > 0:
username = regexp[-1].lower()
else:
return_bad_params(username)
return Response(response=jfail("missing parameters"), status=200)
to_name = request.form.get('to')
to_address = unicode(request.form.get('subject')).encode('ascii','xmlcharrefreplace').lower().replace("fw:","").replace("re:","").strip()
if None in [body,username,to_name,to_address]:
return_bad_params(username)
return Response(response=jfail("missing parameters"), status=200)
user = User(username)
if user.is_valid():
send_letter(user,to_name,to_address,body,attachments)
else:
return_unknown_sender(username)
return Response(response=jfail("unknown sender"), status=200)
return Response(response=jsuccess(), status=200)
示例4: get_summary_message
def get_summary_message(self):
'''Return summary of replies as HTML'''
settings = frappe.get_doc('Daily Work Summary Settings')
replies = frappe.get_all('Communication', fields=['content', 'text_content', 'sender'],
filters=dict(reference_doctype=self.doctype, reference_name=self.name,
communication_type='Communication', sent_or_received='Received'),
order_by='creation asc')
did_not_reply = self.email_sent_to.split()
for d in replies:
d.sender_name = frappe.db.get_value("Employee", {"user_id": d.sender},
"employee_name") or d.sender
if d.sender in did_not_reply:
did_not_reply.remove(d.sender)
if d.text_content:
d.content = markdown(EmailReplyParser.parse_reply(d.text_content))
did_not_reply = [(frappe.db.get_value("Employee", {"user_id": email}, "employee_name") or email)
for email in did_not_reply]
return frappe.render_template(self.get_summary_template(),
dict(replies=replies,
original_message=settings.message,
title=_('Daily Work Summary for {0}'.format(formatdate(self.creation))),
did_not_reply= ', '.join(did_not_reply) or '',
did_not_reply_title = _('No replies from')))
示例5: extract_reply
def extract_reply(msg):
"""Extracts the portion of an email that should contain commands.
"""
for part in msg.walk():
if part.get_content_type() == 'text/plain':
content = part.get_payload(decode=True)
return EmailReplyParser.parse_reply(content)
示例6: clean_comment
def clean_comment(comment):
comment = EmailReplyParser.parse_reply(comment)
block = re.compile(r'`{3,}.*?`{3,}|<pre>.*?</pre>|^(?: {4,}|\t+).*?$', re.MULTILINE | re.DOTALL)
comment = block.sub('', comment)
inline = re.compile(r'`.*?`', re.MULTILINE | re.DOTALL)
comment = inline.sub('', comment)
link = re.compile(r'!?\[(.*?)\]\(.*?\)', re.MULTILINE | re.DOTALL)
comment = link.sub(r'\1', comment)
url = re.compile(r'\(?https?://\S+\)?', re.MULTILINE | re.DOTALL)
comment = url.sub('', comment)
code = re.compile(r'(?:[A-Z][a-z]*){2,}(?:::(?:[A-Z][a-z]*)+)*(?:\.|#\S+)*', re.MULTILINE | re.DOTALL)
comment = code.sub('', comment)
ruby = re.compile(r'(?:\w+/)*\w*\.rb', re.MULTILINE | re.DOTALL)
comment = ruby.sub('', comment)
emoji = re.compile(r':\S+:', re.MULTILINE | re.DOTALL)
comment = emoji.sub('', comment)
return comment
示例7: post
def post(self, request):
token = request.POST['token']
signature = request.POST['signature']
timestamp = request.POST['timestamp']
key = options.get('mail.mailgun-api-key')
if not key:
logging.error('mail.mailgun-api-key is not set')
return HttpResponse(status=500)
if not self.verify(key, token, timestamp, signature):
logging.info('Unable to verify signature for mailgun request')
return HttpResponse(status=403)
to_email = parseaddr(request.POST['To'])[1]
from_email = parseaddr(request.POST['From'])[1]
try:
group_id = email_to_group_id(to_email)
except Exception:
logging.info('%r is not a valid email address', to_email)
return HttpResponse(status=500)
payload = EmailReplyParser.parse_reply(request.POST['body-plain']).strip()
if not payload:
# If there's no body, we don't need to go any further
return HttpResponse(status=200)
process_inbound_email.delay(from_email, group_id, payload)
return HttpResponse(status=201)
示例8: text_reply
def text_reply(self):
"""
>>> email_msg = MessageDecorator.from_file('test/test_single.eml')
>>> email_msg.text_reply()
'plain word1, word2, word2, word3, word3, word3'
"""
text = self.text()
return EmailReplyParser.parse_reply(text)
示例9: instanciate_answer
def instanciate_answer(self, lines):
answer = self.answer_class()
msgtxt = ''.join(lines)
msg = email.message_from_string(msgtxt)
temporary, permanent = all_failures(msg)
if permanent:
answer.is_bounced = True
answer.email_from = scan_message(msg).pop()
elif temporary:
raise TemporaryFailure
else:
answer.email_from = msg["From"]
the_recipient = msg["To"]
answer.subject = msg["Subject"]
answer.when = msg["Date"]
answer.message_id = msg["Message-ID"]
the_recipient = re.sub(r"\n", "", the_recipient)
regex = re.compile(r".*[\+\-](.*)@.*")
the_match = regex.match(the_recipient)
if the_match is None:
raise CouldNotFindIdentifier
answer.email_to = the_recipient
answer.outbound_message_identifier = the_match.groups()[0]
logging.info("Reading the parts")
for part in msg.walk():
logging.info("Part of type " + part.get_content_type())
content_type_attr = self.content_types_attrs.get(part.get_content_type())
if content_type_attr:
charset = part.get_content_charset() or "ISO-8859-1"
data = part.get_payload(decode=True).decode(charset)
setattr(
answer,
content_type_attr,
EmailReplyParser.parse_reply(data).strip(),
)
else:
self.handle_not_processed_part(part)
attachment = self.parse_attachment(part)
if attachment:
answer.add_attachment(attachment)
log = 'New incoming email from %(from)s sent on %(date)s with subject %(subject)s and content %(content)s'
log = log % {
'from': answer.email_from,
'date': answer.when,
'subject': answer.subject,
'content': answer.content_text,
}
logging.info(log)
return answer
示例10: __init__
def __init__(self, message):
if (not isinstance(message, dict) or 'TextBody' not in message):
log.exception('ActivityEmailParser didn\'t get a valid message.')
raise ActivityEmailEncodingError(
'Invalid or malformed json message object.')
self.email = message
reply = self._extra_email_reply_parse(self.email['TextBody'])
self.reply = EmailReplyParser.read(reply).reply
示例11: get_reply_message
def get_reply_message(message):
from email_reply_parser import EmailReplyParser
for payload in message.get_payload():
if payload.get_content_type() == 'text/plain':
content = payload.get_payload()
break
return EmailReplyParser.parse_reply(content)
示例12: __init__
def __init__(self, email_text):
"""Decode base64 email and turn it into a Django email object."""
try:
email_text = base64.standard_b64decode(urllib2.unquote(email_text.rstrip()))
except TypeError:
# Corrupt or invalid base 64.
self.decode_error = True
return
self.email = message_from_string(email_text)
self.reply_text = EmailReplyParser.read(self.email.get_payload()).reply
示例13: get_data
def get_data(start=0):
#frappe.only_for('Employee', 'System Manager')
data = frappe.get_all('Communication',
fields=('content', 'text_content', 'sender', 'creation'),
filters=dict(reference_doctype='Daily Work Summary'),
order_by='creation desc', limit=40, start=start)
for d in data:
d.sender_name = frappe.db.get_value("Employee", {"user_id": d.sender},
"employee_name") or d.sender
if d.text_content:
d.content = markdown(EmailReplyParser.parse_reply(d.text_content))
return data
示例14: handle
def handle(self, lines):
answer = self.answer_class()
msgtxt = ''.join(lines)
msg = email.message_from_string(msgtxt)
temporary, permanent = all_failures(msg)
if temporary or permanent:
answer.is_bounced = True
answer.email_from = scan_message(msg).pop()
else:
answer.email_from = msg["From"]
the_recipient = msg["To"]
answer.subject = msg["Subject"]
answer.when = msg["Date"]
the_recipient = re.sub(r"\n", "", the_recipient)
regex = re.compile(r".*[\+\-](.*)@.*")
answer.outbound_message_identifier = regex.match(the_recipient).groups()[0]
charset = msg.get_charset()
logging.info("Reading the parts")
for part in msg.walk():
logging.info("Part of type "+part.get_content_type())
if part.get_content_type() == 'text/plain':
charset = part.get_content_charset()
if not charset:
charset = "ISO-8859-1"
data = part.get_payload(decode=True).decode(charset)
text = EmailReplyParser.parse_reply(data)
text.strip()
answer.content_text = text
#logging stuff
log = 'New incoming email from %(from)s sent on %(date)s with subject %(subject)s and content %(content)s'
log = log % {
'from':answer.email_from,
'date':answer.when,
'subject':answer.subject,
'content':answer.content_text
}
logging.info(log)
return answer
示例15: parse
def parse(shitmail):
message_id = shitmail['Message-ID']
date = datetime.fromtimestamp(mktime(email.utils.parsedate(shitmail['Date'])))
from_ = shitmail['From']
subject = shitmail['Subject']
body = extract_body(shitmail)
cleanup_body = EmailReplyParser.parse_reply(body).strip()
in_reply_to = shitmail['In-Reply-To']
c = model.session.query(model.Post).filter(model.Post.message_id == message_id).count()
if c > 0:
logging.error("double message-id: " + message_id)
return
post = model.Post(message_id, date, from_, subject, cleanup_body, in_reply_to)
model.session.add(post)
model.session.commit()