Decode message

Max Destiny
Max Destiny used Ask the Experts™
on
well  how can I decode the emails  so i can get plain text?

import poplib;

import io;

import string;

import encodings;

try:

 server = poplib.POP3_SSL("pop.gmail.com",poplib.POP3_SSL_PORT);

   

except:

 print("Error");



response = server.user('XXXXXXXX@gmail.com');

response1 =  server.pass_('XXXXXXXX');

print(response);

print(response1);



# download the first message in the list


messages = server.list();

print(messages);
   

























  

Open in new window


help appreciated
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
You'll do this via...

1) Retrieve the message from where it lives.

Your code above looks like it's starting to bring up a server, rather than a client.

You have to connect as a client to an existing server.

2) Then break the message apart into components, might be text or MIME.

3) Then decode each component, which will occur differently based on MIME type.

Based on your code above, this might be a new process for you.

Likely best to start with some GitHub sample code. Likely there are many snippets you'll find useful.

For a 100% solution, you'll have to build a tool like the NeoMutt email client from scratch... which will be... a substantial task...

You might provide an example of an email your trying to decode.

If you have a specific type of email, this will be far simpler than a generalized approach for decoding all possible email that can every be generated.
nociSoftware Engineer
Distinguished Expert 2018

Commented:
The email module can do the heavylifting for you:
https://docs.python.org/2/library/email.html#module-email

Some examples of it's use:
https://docs.python.org/2/library/email-examples.html
EirmanChief Operations Manager

Commented:
I suggest that you download and install Pegasus Email (It's free)

If the message is still on the server you can download it,
choosing whether you want to leave it on the server.

Then ....
View the RAW message by clicking on the Raw View tab
Truncated to protect my privacy
It may give you the decoded view you are looking for,
but seeing how the message is composed can be useful.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial