473,395 Members | 1,386 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,395 software developers and data experts.

Example of a email processing to a file

Hi sorry to try and get someone to do my job but im at logger heads at
the moment .

I have been assigned a duty to abstract from a mail acoount
(/var/spool/mail/Usersurvey)

The email messages are encapsulated in xml I want to parse the data into
a database.

I have been programming with UnixMailbox Module and been able to view
the contents but how do I get all the messages into one file.I know the
database part just this extraction bit.

I fsomeone has a snippet or example would be great as I got a tight
deadline .

Cheers all
Jul 18 '05 #1
1 1665
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

chuck amadi wrote:

I have been programming with UnixMailbox Module and been able to view
the contents but how do I get all the messages into one file.I know the
database part just this extraction bit.


Is this what you want ?

messages is a results's of rfc822.Message(....) list.

def save2mbox(dir_backup,mbox,messages,compressed,expi red):
""" Guarda la lista de mensajes
en el directorio dir_backup y
con nombre mbox
"""
# Verificamos que existe dir_backup
import os
if not os.path.exists(dir_backup):
os.makedirs(dir_backup)

YYYY,MM,DD,hh,mm,ss,ms,mms,e =gmtime(expired)
mymbox="%s-%d%.2d%.2d" % (mbox,YYYY,MM,DD)
if compressed:
import gzip
fw=gzip.GzipFile(dir_backup+'/'+mymbox+'.gz','ab',5)
else:
fw=open(dir_backup+'/'+mbox,'ab')
for msg in messages:
try:
fecha=rfc822.formatdate(mktime(msg.getdate('date') ))
except:
fecha=rfc822.formatdate(mktime(gmtime(0)))
fw.write("From %s %s\r\n" % (msg.getaddr('from'
[-1],fecha))
fw.write(msg.fp.getvalue())
fw.write("\r\n")
fw.close()
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAtpn2MKsc+XeZcdwRAis7AJ0SxLhGzV+mXNQUeiTHYO Ob8csVTACdHgau
hwMYBLTVPk2hqbw3ZAhd2SU=
=P3lZ
-----END PGP SIGNATURE-----
Jul 18 '05 #2

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

Similar topics

4
by: Paul Schmidt | last post by:
Dear list: I am new to python, and I am trying to figure out the short answer on something. I want to open a POP3 mailbox, read the enclosed mail using the POP3 module, , and then process it...
0
by: Ganapathy | last post by:
I have COM dll code written in VC 6.0. When i tried compiling this code in VC 7, The MIDL cmpiler gets called twice. i.e. it initially compiles fully & immediately a line - 64 bit processing'...
2
by: devendra pardeshi | last post by:
hi friends/seniors i am stuck on one problem in VB 6.0 and need solution. see if u can help me. first i describe the problem. Can u imagin the WinZip scenario. we right click on some file...
5
by: Geoff Pennington | last post by:
My VB.Net app reads an Excel file, processes it one row at a time, and when processing is complete writes the row to a database. The typical file will have several thousand rows and may take a...
5
by: B. Williams | last post by:
I need some assistance with random access file processing. I have a function that I would like to change from sequential file processing to random access. Thanks in advance. void...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
2
by: patrice.pare | last post by:
Hello, Here is a summary of my Dev Environment: I use Visual Studio 2005 Team Suite SP1 with Crystal Report XI SP1 on a Windows XP SP2 development workstation. I also use SQL Server 2000 SP4. ...
16
by: Ed Bitzer | last post by:
Trying to send groups of email with program using System.Net.Mail. I do not clear MailMessage but repeatedly loop changing only the Bcc entries. Works fine if all addresses are valid. As a simple...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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.