473,578 Members | 2,744 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 3138
> 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
1863
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
1664
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
3735
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
8856
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
3673
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
2088
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
4549
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
2375
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
1087
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
7850
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
8126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8291
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...
1
7874
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...
0
8150
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...
0
5343
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
3786
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...
0
3801
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1114
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.