Filter obvious footers from email mirror messages.

(imported from commit 7e22b6823b5d0a07f7f350e4af65be66728a8f88)
This commit is contained in:
Jessica McKellar 2013-10-02 11:54:25 -04:00
parent 0d6ad56c29
commit 6afdfeb1dc
1 changed files with 12 additions and 1 deletions

View File

@ -157,6 +157,17 @@ def extract_body(message):
raise ZulipEmailForwardError("Unable to find plaintext or HTML message body") raise ZulipEmailForwardError("Unable to find plaintext or HTML message body")
def filter_footer(text):
# Try to filter out obvious footers.
possible_footers = filter(lambda line: line.strip().startswith("--"),
text.split("\n"))
if len(possible_footers) != 1:
# Be conservative and don't try to scrub content if there
# isn't a trivial footer structure.
return text
return text.partition("--")[0].strip()
def extract_and_upload_attachments(message): def extract_and_upload_attachments(message):
attachment_links = [] attachment_links = []
@ -225,7 +236,7 @@ def fetch(result, proto, mailboxes):
debug_info = {} debug_info = {}
try: try:
body = extract_body(message) body = filter_footer(extract_body(message))
to = find_emailgateway_recipient(message) to = find_emailgateway_recipient(message)
debug_info["to"] = to debug_info["to"] = to
stream = extract_and_validate(to) stream = extract_and_validate(to)