payload of an email in string format, python

I got payload as a string instance using get_payload() method. But I want my payload in a way where I could access it word by word I tried several things like as_string() method, flatten() method, get_charset() method , but every time there is some problem.

I got my payload using the following code

import email
from email import *


Just tested your snippet with a couple of my own raw emails. Works fine...

get_payload() returns either a list or string, so you need to check that first

if isinstance(payload, list):
    for m in payload:
        print str(m).split()

    print str(m).split()


Per our discussion, your issue was that you were not checking is_multipart() on the fp object, which actually is a message instance. If fp.is_multipart() == True, then get_payload() will return a list of message instances. In your case, based on your example mail message, it was NOT multipart, and fp was actually the object you were interesting in.

I got my payload as a string as my fp was not multipart If it could have been a multipart, it would have returned a list of strings so now I can just use the following code

abc=payload.split(" ")

it gives me the output as follows ['good', 'day\nhttp://\n\n', '', '', '', '', '', '', '', '', '', '', '', 'Sun,', '18', 'Dec', '2011', '10:53:43\n_________________\n"She', 'wiped', 'him', 'dry', 'with', 'soft', 'flannel,', 'and', 'gave', 'him', 'some', 'clean,', 'dry', 'clothes,=\n', 'and', 'made', 'him', 'very', 'comfortable', 'again."', '(c)', 'Lyrica', 'wa946758\n']

thanks to jdi :) p.s. couldnt post it as an answer yesterday, as there was some restriction with points

Need Your Help

Android Sim Change Detect, error in Log.e

android service broadcastreceiver

I have error when refer to LogCat. I have store the storedsimcard(1st) and compare with currentsimcard(2nd), if sim serial is different, logcat will print out sim changed. But i had problem with my

Indexed array quicksort debug

c++ debugging quicksort

I'm going nuts over this special quicksort algorithm and I don't know where is the problem. I've found an example on a forum that explains very well what I'm trying to do.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.