473,811 Members | 3,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1818
"nephish" <ne*****@xit.ne t> wrote in message
news:ma******** *************** *************** @python.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.ne t> wrote in message
news:ma******** *************** *************** @python.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_f rom_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*********@py thon.org>
Sent: Wednesday, June 22, 2005 10:48 AM
Subject: Re: need to strip stuff off email


"nephish" <ne*****@xit.ne t> wrote in message
news:mailman.72 3.1119399951.10 512.py********* @python.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_f rom_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
3112
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 that Numerology program I wrote years ago in VB. There are times I am totally stuck (for instance, I just had an idea to put the numerical values of the alphabet and months of the year in a dictionary located in a function. Then, I can import the...
16
2184
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 (although I'd like to keep the nested tables, if possible). Some of this can be stripped using Search/Replace, but some of it contains codes which differ from page to page. How many pages? About 750, totalling 80 megabytes of data, which I'm
30
4176
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 ok. I need to make an x y chart for some data that comes in from sensors at different times durring the day. i need it to show the value in the y and the time in the x . no problem so far. But what i cannot get to happen is to scale x (time of the...
3
11702
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. For example: - Strip(Char(Digits(v_cntrct_no_seed)),L,'0') - v_cntrct_no_seed is defined as Integer - Char and Digits return a character representation of a number with
6
9096
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 string that I tried tweaking without success. Any help would be much appreciated. Thanks in advance, Mark C. hereinde@yahoo.com
5
8726
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 does it not work? I want to get rid of all ' ' and ':' in the string. I've checked the doc and from what I can tell this is what strip() is supposed to do. Thanks for any help.
3
2013
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
2360
by: eight02645999 | last post by:
hi can someone explain strip() for these : 'example' when i did this: 'abcd,words.words'
6
1765
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
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10393
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.