[Email-SIG] save .msg as .txt

Kalpana Sinduria kalpana.sinduria at patni.com
Sun May 8 11:39:08 CEST 2005


Hi,
	no it's not in plain .txt format. it's in Microsoft's outlook message
(.msg) format.
	I tired the following code, but it's not working

	******************
	  import email.Parser
        fp = open('mymail.msg', 'rb')
        p = email.Parser.Parser()
        msg = p.parse(fp)  ---- > error
        fp.close()
	 ******************

Error are:

  File "/usr/lib/python2.2/email/Parser.py", line 62, in parse
self._parseheaders(root, fp)
  File "/usr/lib/python2.2/email/Parser.py", line 128, in _parseheaders
raise Errors.HeaderParseError(
email.Errors.HeaderParseError: Not a header, not a continuation: ``
ÿÿÿÿ%__substg1.0_0064001E*ÿÿÿÿÿÿÿÿÿÿÿÿ$__substg1.0_0065001E*
ÿÿÿÿ#_substg1.0_0070001E*ÿÿÿÿÿÿÿÿÿÿÿÿ"__substg1.0_00710102*ÿÿÿÿ!__substg1.0_
0C190102*ÿÿÿÿÿÿÿÿÿÿÿÿI__substg1.0_0C1A001E*ÿÿÿÿ__substg1.0_0C1D0102*ÿÿÿÿÿÿÿÿ
ÿÿÿÿ
__substg1.0_0C1E001E*ÿÿÿÿ__substg1.0_0C1F001E*ÿÿÿÿÿÿÿÿ_substg1.0_0E1D001E*ÿÿ
ÿÿÿÿÿÿÿÿÿÿ__substg1.0_1000001E*ÿÿÿÿ$__substg1.0_1008001E*ÿÿÿÿÿÿÿÿÿÿÿÿe__subs
tg1.0_10090102*ÿÿÿÿ''
>>> PuTTYPuTTYPuTTY
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'PuTTYPuTTYPuTTY' is not defined
>>>


Rgds,
Kalpana

-----Original Message-----
From: Barry Warsaw [mailto:barry at python.org]
Sent: Saturday, May 07, 2005 6:32 PM
To: kalpana.sinduria at patni.com
Cc: email-sig at python.org
Subject: Re: [Email-SIG] save .msg as .txt


On Sat, 2005-05-07 at 05:54, Kalpana Sinduria wrote:

> 	I am new for python. working on Linux, having python 2.2 ver.
> 	I have to write a C++ code to convert Microsoft .msg file to plain .txt
> file.
>
> 	Is it possible to parse Microsoft .msg  using python's email package and
> save it as .txt file.
> 	I am interested only in "from", "CC", "subject", "Date time " and
"message
> body" not in attachment with .msg file.

If it's stored in plain text RFC 2822 format, then sure <wink>.  If not,
then no, email's parse wouldn't be able to handle it.  Is the format
even documented?  I've heard that it's nearly impossible to get the full
plain text message out of some Microsoft tools.

-Barry




http://www.patni.com
World-Wide Partnerships. World-Class Solutions.
_____________________________________________________________________

This e-mail message may contain proprietary, confidential or legally
privileged information for the sole use of the person or entity to
whom this message was originally addressed. Any review, e-transmission
dissemination or other use of or taking of any action in reliance upon
this information by persons or entities other than the intended
recipient is prohibited. If you have received this e-mail in error
kindly delete  this e-mail from your records. If it appears that this
mail has been forwarded to you without proper authority, please notify
us immediately at netadmin at patni.com and delete this mail. 
_____________________________________________________________________


More information about the Email-SIG mailing list