Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Can I get message filename from a Maildir mailbox stream?

Reply
Thread Tools

Can I get message filename from a Maildir mailbox stream?

 
 
noah@noah.org
Guest
Posts: n/a
 
      02-19-2005
Is there a way to figure out what
filename an email object points to in a
qmail style Maildir directory?

Hmmm... I don't think so, but I'm hoping I wrong.

I instantiated a Maildir mailbox and I'm
iterating through the messages. When I find a
special message I want to move it or delete it
or something.

Yours,
Noah

 
Reply With Quote
 
 
 
 
Phil Jackson
Guest
Posts: n/a
 
      02-19-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> Is there a way to figure out what filename an email object points to
> in a qmail style Maildir directory?


What do you mean bu "email object"? Surely if you are iterating a
Maildir then you should have the filename. Or am I misunderstanding
what you mean?

Phil
 
Reply With Quote
 
 
 
 
Michael Josephson
Guest
Posts: n/a
 
      02-19-2005
>a way to figure out what filename an email object points to in a
>qmail style Maildir directory?


Assuming you're using the mailbox module from the standard Python
library, the Message objects you get back provide access to the file
object as an instance variable called fp. So if you have:

maildir = mailbox.Maildir("/home/mike/Maildir")
message = maildir.next()

The filename is message.fp.name

Note that the file object is open when you are in this state so you
may want to close it before you do a move/delete etc.

-Michael
 
Reply With Quote
 
Noah
Guest
Posts: n/a
 
      02-22-2005
This didn't work. I'm using the standard Python 2.3.4 library
mailbox.Maildir. I got an error that message instance
has no attribute 'fp'.

I ended up not using mailbox.Maildir at all.
It occured to me that since Maildir style mailboxes
is just a collection of files that it was simpler to write
a generator that walked the directory using os.listdir.

def Maildir_messages (path):
d = os.listdir(path)
for filename in d:
fin = file (os.path.join(path, filename))
yield (email.message_from_file(fin), filename)
fin.close()

for msg, msg_filename in Maildir_messages ("/home/noah/Maildir/new"):
print msg_filename
print msg['Subject']

Yours,
Noah

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mailbox.Maildir(), confusing documentation tinnews@isbd.co.uk Python 2 04-06-2008 10:39 AM
A question about creating Maildir mailboxes with mailbox.Maildir tinnews@isbd.co.uk Python 0 04-03-2008 01:00 PM
mailbox.Maildir question/problem tinnews@isbd.co.uk Python 2 12-14-2007 10:01 AM
mailbox module, Maildir, and flags jesse.k.rosenthal@gmail.com Python 0 09-11-2007 12:29 AM
mailbox.py examples (Maildir) Matej Cepl Python 1 08-06-2003 08:36 PM



Advertisments