I am using poplib to grab emails from a mail server. The method retr(n) retrieves the nth email message. It returns messages in a funny form where everything is broken into lines and placed in a tuple. What gives! : it inserts the characters '3D' randomly into the email. Furthermore, it breaks tagged elements into pieces and inserts '=' at the break. As anyone else seen this?
Asked
Active
Viewed 196 times
0
-
That's called "Quoted Printable" encoding (http://en.wikipedia.org/wiki/Quoted-printable) the messages are (in all likelihood) already formatted that way. – nobody Apr 01 '14 at 21:18
-
neat thanks! You might want to make that into an answer so I can mark it. – user442920 Apr 02 '14 at 01:10
1 Answers
0
Giving Andrew Medico credit, the string you are seeing is in "Quoted Printable Encoding" (http://en.wikipedia.org/wiki/Quoted-printable). The emails were already in that format when I received them, in my case.
I was able to turn it back into a "normal" string using the quopri module (https://docs.python.org/2/library/quopri.html).
import poplib
import quopri
pop_conn = poplib.POP3_SSL( "the_host" )
pop_conn.user("my_user")
pop_conn.pass_("my_password")
email_i_want = 1
encoded_msg = pop_conn.retr( email_i_want )[1]
joined_msg = str( '\n'.join(encoded_msg) )
decoded_msg = quopri.decodestring( joined_msg )
print decoded_msg

Nate-Bit Int
- 165
- 9