-----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-----