[code.view]

[top] / python / PyMOTW / mailbox / mailbox_maildir_remove.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """
     """
     
     __version__ = "$Id$"
     #end_pymotw_header
     
     import mailbox
     import os
     
     mbox = mailbox.Maildir('Example')
     to_remove = []
     for key, msg in mbox.iteritems():
         if '2' in msg['subject']:
             print 'Removing:', key
             to_remove.append(key)
     mbox.lock()
     try:
         for key in to_remove:
             mbox.remove(key)
     finally:
         mbox.flush()
         mbox.close()
     
     for dirname, subdirs, files in os.walk('Example'):
         print dirname
         print '\tDirectories:', subdirs
         for name in files:
             fullname = os.path.join(dirname, name)
             print
             print '***', fullname
             print open(fullname).read()
             print '*' * 20
     

[top] / python / PyMOTW / mailbox / mailbox_maildir_remove.py

contact | logmethods.com