473,569 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python, mbox files and forwarding messages

Can Python parse a mbox file and forward each individual message within
that file to someone else?

For example, let's say I have a 10MB mbox file that has 678 messages.
I'd like to send each of the messages to sa*********@nor thpole.com...
how might I do that? Also, how might I handle messages that have an
attachment associated with them during the forward process?

Thanks,
Brad
Jul 18 '05 #1
2 3136
> Can Python parse a mbox file and forward each individual message within
that file to someone else?
Yes.
For example, let's say I have a 10MB mbox file that has 678 messages.
I'd like to send each of the messages to sa*********@nor thpole.com...
how might I do that? Also, how might I handle messages that have an
attachment associated with them during the forward process?


import smtplib

def find_all_at_lin estart(data, st):
start = 0
if data[:len(st)] == st:
start += len(st)
yield 0
end = len(data)
st = \n'+st
while start < end:
nstart = data.find(st, start, end)
if nstart == -1:
return
start = nstart+len(st)
yield nstart

def forward_email(m boxfname, email_from, email_to, host, port):
mail = open('mboxfname ', 'rb').read()
lst = list(find_all_a t_linestart(mai l, 'From '))
smtpc = smtplib.SMTP(ho st, port)
for i in xrange(len(lst)-1):
start = lst[i]
end = lst[i+1]
#strip off the mbox From ... line
r = mail.find('\n', start, end)
email = mail[r+1:end]
if email:
smtpc.sendmail( email_from, [email_to], email)
start = lst[-1]
end = len(mail)
r = mail.find('\n', start, end)
email = mail[r+1:end]
if email:
smtpc.sendmail( email_from, [email_to], email)
smtpc.close()
Pardon if it doesn't quite work, this was done in my email client, and
has not been tested.

- Josiah

Jul 18 '05 #2
On Tue, 26 Oct 2004 13:08:36 -0400, Brad Tilley <br********@gma il.com> wrote:
Can Python parse a mbox file and forward each individual message within
that file to someone else?
[...] Also, how might I handle messages that have an
attachment associated with them during the forward process?


By ignoring them. You don't have to be MIME-aware to forward a message, and
the mbox format(s) aren't MIME-aware either.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Jul 18 '05 #3

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

Similar topics

1
1860
by: Paul Rubin | last post by:
I was surprised there was no obvious way with spamassassin (maybe I shoulda looked at spambayes) to split an existing mbox file into its spam and non-spam messages. So I wrote one. It's pretty slow, taking around 1.5 seconds per message on a 2 ghz Athlon, making me wonder how serious ISP's getting thousands of incoming messages per hour can...
7
1662
by: Uwe Grauer | last post by:
Hi all, who can help on reading and writing mozilla-mail folders with python? I wanted to implement something like an email-sync for mozilla-mail in python. I did some tests, but something is strange with the email (rfc822) modules in python. (The output of parsed messages is different from the original input) Any hints of how (what...
52
3720
by: Olivier Scalbert | last post by:
Hello , What is the python way of doing this : perl -pi -e 's/string1/string2/' file ? Thanks Olivier
4
8855
by: Chuck Amadi | last post by:
Has anyone got a simple python script that will parse a linux mbox and create a large file to view . Cheers Chu
10
3670
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. Andrew dalke@dalkescientific.com
5
2087
by: Gregory Piñero | last post by:
I was wondering what methods you experts would reccomend for this task? Here are the options I have come up with so far: 1. Build something with the poblib library (http://docs.python.org/lib/module-poplib.html) --Any pointers on doing this? How to I get poplib to save messages in a standard format I can later import into Thunderbird,...
11
4547
by: Jonathan Pritchard | last post by:
Does anyone know of a library to read/write mbox format (used to store emails e.g. in Thunderbird) in ANSI C (cross platform is key)? Is there a more appropriate place to ask this? -- Reclaim Your Inbox! http://www.mozilla.org/products/thunderbird
18
2371
by: Grant Edwards | last post by:
Could whoever is responsible for the gateway that is grabbing my postings off of Usenet and e-mailing them out please fix the headers in the mail messages so that I don't get the bounce messages? While you're at it, might as well fix it for everybody else too. ;) Its a bit rude to send out mass e-mail messages with headers faked up so...
0
1084
by: Steve Holden | last post by:
Sirshendu Rakshit wrote: I believe the difference between UnixMailbox and other types is that the UnixMailbox is specifically designed to identify the gaps between messages by the blank line and the "From ....". While this isn't technically RFC 2822 format, it's useful to have the header. If you don't want it you can always throw it away...
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
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...
0
6277
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...
1
5501
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...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
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...

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.