473,396 Members | 2,070 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,396 software developers and data experts.

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 8842
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**********@yahoo.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.py
## 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(maildir):

print os.path.join(maildir, file)

fp = open(os.path.join(maildir, file), "rb")
p = email.Parser.Parser()
msg = p.parse(fp)
fp.close()
#print msg.get("From")
#print msg.get("Content-Type")

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

filename = part.get_param("name")
if filename==None:
filename = "part-%i" % counter
counter += 1
fp = open(os.path.join(dir, filename), 'wb')
print os.path.join(dir, filename)
fp.write(part.get_payload(decode=1))
fp.close()
if __name__ == '__main__':
main()




Jul 18 '05 #4
chuck amadi <ch*********@ntlworld.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**********@yahoo.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
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"...
0
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...
1
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 . ...
6
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...
16
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...
27
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 =...
3
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...
4
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...
0
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
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.