473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

need to strip stuff off email

hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?
thanks
Jul 19 '05 #1
4 1796
"nephish" <ne*****@xit.net> wrote in message
news:ma**************************************@pyth on.org...
hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?
thanks


See the example at the end of the email package documentation.

John Roth

Jul 19 '05 #2
nephish wrote:
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?


Without more context and info, I think the best one can say at this
stage is "use the email" module.

Have you tried that? Whether you have or not, sample code would help a
lot in understanding what you're doing, or perhaps more description
about your platform, what form the mail message is in, maybe an example
of the before and after state of the message, and such things...

-Peter
Jul 19 '05 #3

"nephish" <ne*****@xit.net> wrote in message
news:ma**************************************@pyth on.org...
hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?
thanks


The body is: The rest of the email after "the first blank line after the
subject header". In practice it is the first blank line.

If you get the message into a string it can sometimes be easier to just
RSPLIT the string at '\r\n\r\n', if the message is in a list then the body
= '\r\n'.join(msg[x:]) where x = that blank line +1 , that way if you
don't need any of the header info, you don't have to decode the message and
rebuild it in a file.

if you *are* using the email module, eg

msg = email.message_from_file(a_file)

then rsplit the msg to get the same result.

As someone will no doubt point out, some emails are broken and parts of
the headers will end up in the body (even when you view the email it in a
client), this is very rare though.


Jul 19 '05 #4
----- Original Message -----
From: "Tim Williams" <li********@tdw.net>
To: <py*********@python.org>
Sent: Wednesday, June 22, 2005 10:48 AM
Subject: Re: need to strip stuff off email


"nephish" <ne*****@xit.net> wrote in message
news:mailman.723.1119399951.10512.py*********@pyth on.org...
hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself) so i can later write it to a text file.

anyone know how to accomplish this?
thanks

The body is: The rest of the email after "the first blank line after the
subject header". In practice it is the first blank line.

If you get the message into a string it can sometimes be easier to just
RSPLIT the string at '\r\n\r\n', if the message is in a list then the

body = '\r\n'.join(msg[x:]) where x = that blank line +1 , that way if you
don't need any of the header info, you don't have to decode the message and rebuild it in a file.

if you *are* using the email module, eg

msg = email.message_from_file(a_file)

then rsplit the msg to get the same result.

As someone will no doubt point out, some emails are broken and parts of
the headers will end up in the body (even when you view the email it in a
client), this is very rare though.


Ah, trying to do anything before my first cup of coffee in the morning is
always a mistake - substitute RSPLIT with LSPLIT for both occurrences above
!!! :(

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
16
by: Voetleuce en f?nsievry | last post by:
G'day I have some pages written by a bot and much of the code does not concern the visible content on the site. I'd like to strip all the codes that do not affect or influence the visible stuff...
30
by: nephish | last post by:
Hey there, i have tried about every graphing package for python i can get to work on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get matplot to work) so far, they all are working...
3
by: alex.mcshane | last post by:
Hi - I would be grateful for any advice on the following. Within DB2 for OS/390, the STRIP Scaler Function is available. Its function is, for example, to remove leading zeros from a string. ...
6
by: Mark C | last post by:
All, Is there such a function that can strip all non alpha ( not between a-z) characters from a string? I have a function that I currently use that will strip one character at a time from a...
5
by: dan.j.weber | last post by:
I'm using Python 2.3.5 and when I type the following in the interactive prompt I see that strip() is not working as advertised: >>>s = 'p p:p' >>>s.strip(' :') 'p p:p' Is this just me or...
3
by: AutoShutdown | last post by:
I am using VBscript in a asp file. lets say I have a value... abc="JDD-20015-19,12" def="JDD-20015-07,8" Question (1)
6
by: eight02645999 | last post by:
hi can someone explain strip() for these : 'example' when i did this: 'abcd,words.words'
6
by: george | last post by:
hello, which is the best way to strip jscript/vbscript from user input? Is there any module I could reuse? thanks in advance george P.S. the solution must allow users to enter html code.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.