473,546 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Python script to read and output MailBox body to a file

Has anyone got a simple python script that will parse a linux mbox and create
a large file to view .

Cheers

Chu
Jul 18 '05 #1
4 8853
Chuck Amadi <ch***@smtl.co. uk> wrote:
Has anyone got a simple python script that will parse a linux mbox
and create a large file to view .


"Create a large file to view"? Care to elaborate?

--
William Park, Open Geometry Consulting, <op**********@y ahoo.ca>
No, I will not fix your computer! I'll reformat your harddisk, though.
Jul 18 '05 #2
William Park wrote:
Chuck Amadi <ch***@smtl.co. uk> wrote:
Has anyone got a simple python script that will parse a linux mbox
and create a large file to view .

"Create a large file to view"? Care to elaborate?


I've sent him a working example that disassembles mailboxes in both mbox and maildir form. Personally, I'm now scouting around for code that will let you delete and expunge messages from an mbox mailbox. I fear I need to pull my thumb out and expand the mailbox module to handle writing as well. mbox manipulations are butt ugly.

---eric


Jul 18 '05 #3
Eric S. Johansson wrote:
William Park wrote:
Chuck Amadi <ch***@smtl.co. uk> wrote:
Has anyone got a simple python script that will parse a linux mbox
and create a large file to view .
"Create a large file to view"? Care to elaborate?

I've sent him a working example that disassembles mailboxes in both
mbox and maildir form. Personally, I'm now scouting around for code
that will let you delete and expunge messages from an mbox mailbox. I
fear I need to pull my thumb out and expand the mailbox module to
handle writing as well. mbox manipulations are butt ugly.

---eric

Cheers I do note that I need to create a global-config file I have
seen something on this in O'Reilly Python Programming . Albiet I dont
need to connect to a pop3 account .Thus would this script need a bit
of hacking or is the script I got sufficient as Monday 7th is my D-Day
to get that script working and demo to my boss.


Note briefly my main goal is to get the body content to another file for
processing to Postgresql database.

#file: getSurveyMail.p y
## The email messages is read as flat text form a file or other source,
##the text is parsed to produce the object structure of the email message.
#!/usr/bin/env python

import mboxutils
import mailbox
import email
import sys
import os
import rfc822
import StringIO
import email.Parser
import types

# email package for managing email messages
# Open Users Mailbox
# class Message()

def main():

# The Directory that will contain the Survey Results

dir = "/tmp/SurveyResults/"
# The Web Survey User Inbox
# Mailbox /home/testwwws/Mail/inbox

maildir = "/home/testwwws/Mail/inbox"
for file in os.listdir(mail dir):

print os.path.join(ma ildir, file)

fp = open(os.path.jo in(maildir, file), "rb")
p = email.Parser.Pa rser()
msg = p.parse(fp)
fp.close()
#print msg.get("From")
#print msg.get("Conten t-Type")

counter = 1
for part in msg.walk():
if part.get_main_t ype() == 'multipart':
continue

filename = part.get_param( "name")
if filename==None:
filename = "part-%i" % counter
counter += 1
fp = open(os.path.jo in(dir, filename), 'wb')
print os.path.join(di r, filename)
fp.write(part.g et_payload(deco de=1))
fp.close()
if __name__ == '__main__':
main()




Jul 18 '05 #4
chuck amadi <ch*********@nt lworld.com> wrote:
Eric S. Johansson wrote:
William Park wrote:
Chuck Amadi <ch***@smtl.co. uk> wrote:

Has anyone got a simple python script that will parse a linux
mbox and create a large file to view .

"Create a large file to view"? Care to elaborate?


Note briefly my main goal is to get the body content to another file
for processing to Postgresql database.


One email body per file, or all email bodies in one file?

--
William Park, Open Geometry Consulting, <op**********@y ahoo.ca>
No, I will not fix your computer! I'll reformat your harddisk, though.
Jul 18 '05 #5

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

Similar topics

9
2713
by: Alex Martelli | last post by:
All my mailboxes have been filling up with files of about 130k to 150k, no doubt copies of some immensely popular virus. So, I've no doubt lost lots of real mail because of "mailbox full" conditions (the proliferating fake bounce messages more or less ensure nobody knows their mail to me has bounced, either). As an emergency response I and...
0
1340
by: chuck amadi | last post by:
Hi all I'm new to the list not bad at Java but limited Python (only basics) I will read my Python Book and variuos doc's but a little help is needed(Tight deadline looming). Im running Python 2.3 on Suse 9 Pro Im a Sys Admin and I have been given a task of getting Zope Survey (dmtl) web form that I have built that I have ebcapsulated with...
1
3288
by: chuck amadi | last post by:
any python script which will parse an email messages into a file to poplulate a database. Im trying with UnixMailbox but I cant figure out howto abstract the all email data messages to a file . ## mailbox-Survey.py #!/usr/bin/env python import mailbox,rfc822 # Open Users Mailbox mb = mailbox.UnixMailbox(open("/var/spool/mail/chucka"))
6
7710
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the email posts and been advised to use the email Module and mailbox Module. The blurb from a memeber of this list . Im not at work at the moment So I...
16
6958
by: Chuck Amadi | last post by:
Sorry to bovver you again (again) here's script. I still can't see why the get_payload() doesn't produce the plain text message body of an emails in the testwwws users mailbox. As you can see I have tried a few things but no joy what am I missing. Is the another snippet in relation to get_payload to access the body contents print and...
27
4588
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res = $doc->loadHTMLFile("./aBasicSearchResult.html"); if ( $res == true ) { $zip = $doc->getElementById('zipRaw_id')->value; if ( 0 != $zip ) {
3
4264
by: Ivan Zuzak | last post by:
Hello, My Python application calls web services available on the Internet. The web service being called is defined through application user input. The Python built-in library allows access to web services using HTTP protocol, which is not acceptible - generating SOAP messages for arbitrary web services is something i wish to avoid. I...
4
1771
by: pmcgover | last post by:
I enjoyed Paul Barry's September article in Linux Journal entitled, "Web Reporting with MySQL, CSS and Perl". It provides a simple, elegant way to use HTML to display database content without any sql markup in the cgi script. The cgi script simply calls the Mysql command line with the HTML option (-H) and the SQL script file directed to...
0
2192
by: Grzegorz Smith | last post by:
Hi All. I 'm learning ZSI to use SOAP and I desperately need help. I'm working on example from tutorial -(examples/server/send_response/ simple/wsdl/). Here are my wsdl files -http://pastebin.com/873488. I made wsdl2py wsdl2py --complexType --file=binding.wsdl and get Example_services.py and Example_Services_types.py. Here is the...
0
7504
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
7435
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
7694
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. ...
1
7461
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...
1
5360
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
5080
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
3491
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
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
747
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.