I have written some code in Python using imapclient and poplib to collect my emails from my online account. The received emails get saved to a plain text file.
When I get my email using POP3 is it saved perfectly in the text file with all the carriage returns and line spacings in the correct place. I believe this is because POP3 emails are saved line by line so it will automatically implement the carriage returns for each new line.
IMAP on the other hand is not so friendly. The IMAP text contains all the \r\n with the occasional \t, but when I view the text file in vi, notepad, wordpad and word, none of them implement the carriage return, linefeed or tabs.
From what I’ve read the reason is because those programs just see the \r\n as text and don’t know what do to with it.
So my question is, how do I convert the IMAP text so the \r\n is seen for what it truly is in Windows and Linux using Python.
Thanks.
Try
email_content.decode('string_escape').Example: