Advertisement
Guest User

Untitled

a guest
May 26th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1.  
  2. def fix_body(body: str) -> str:
  3. lines = body.splitlines()
  4. # aws caps lines at 76.
  5. # line continuations are marked with =\n
  6. # cant do a simple find replace because
  7. # we only want to do it in position 76
  8. i = len(lines) - 2
  9. while i > 0:
  10. if lines[i][75:] == '=':
  11. lines[i] = lines[i][:75] + lines[i+1]
  12. del lines[i+1]
  13. body = '\n'.join(body)
  14. return body
  15.  
  16.  
  17. def parse_reply(raw_email: str) -> str:
  18. message: Message = EMAIL_PARSER.parsestr(raw_email)
  19. body: Message = get_email_body(message)
  20. body: str = fix_body(body.get_payload())
  21. reply: str = EmailReplyParser.parse_reply(body)
  22. reply = re.sub(r'\b\n\b', ' ', reply)
  23. return reply
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement