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

Can I get message filename from a Maildir mailbox stream?

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

Jul 18 '05 #1
3 2310
no**@noah.org 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
Jul 18 '05 #2
>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
Jul 18 '05 #3
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

Jul 18 '05 #4

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

Similar topics

1
by: Matej Cepl | last post by:
Hi, is there any example of use of mailbox.py. I would be especially interested if anybody made a objects which would be able to .delete() ..append() etc. individual messages. Thanks, Matej
0
by: support | last post by:
******************** e-mail Manager Notification ********************** As a security precaution this mail was blocked and discarded since it contains attachments with file extensions not allowed...
0
by: Edvard Majakari | last post by:
I'm trying to create an improved front-end for training messages for a spam filter. I discovered an excellent Python module email - now it's so easy to support variety of mailbox formats. However,...
11
by: hilz | last post by:
Hi all: I have a FILE pointer that points to a file on disk (not any other io stream). is there a way to get the filename of that FILE? i thought it would be the _tmpfname part of the struct, but...
4
by: Jed | last post by:
I have looked everywhere and cannot find a resolution for this. I have read several post on this forum that allude to similar issues but I have not found a solution. I am sending dynamic...
10
by: Jerry LeVan | last post by:
Hi, I am futzing around with Andrew Stuarts "Catchmail" program that stores emails into a postgresql database. I want to avoid inserting the same email more than once... (pieces of the email...
7
by: pedagani | last post by:
Dear comp.lang.c++, I'm trying to read a file with very long filename using ifstream. Although, the file exists the file open for read fails. Is there a restriction on the size? I'm using winXP...
6
by: fnoppie | last post by:
Hi, I am near to desperation as I have a million things to get a solution for my problem. I have to post a multipart message to a url that consists of a xml file and an binary file (pdf)....
2
by: tinnews | last post by:
I am trying to write a utility to remove empty maildir mailboxes. It sounds like this should be very simple but it's proving really difficult. I'm doing this on a Fedora 7 system with python...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...

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.