Getting/Saving email attachments w/ poplib and email modules

2005-06-21 Thread brettk
Hello All,

Here's what I'm trying to do:

I need to connect to a pop3 server, download all messages, and copy all
of the attachments into a specific directory.  The actual email message
is unimportant.  Now, I've found plenty of examples that strip the
attachments from an email message, but most (if not all) of them take a
file parameter.  My question is this:

How can i retrieve an email message via poplib and pass it to
email.message_from_string()?

This is essentially what i'm doing now,

##
import email
import poplib

mimes = ["image/tif","image/tiff","images/x-tif","image/x-tiff",
"application/tif","application/tiff","application/x-tif",
"application/x-tiff"]

def WriteAttachment(msg):
docs = [(part.get_filename(),part.get_payload(decode=True))
for part in msg.get_payload() if part.get_type() in mimes]
for name,data in docs:
f = file(name,'wb')
f.write(data)
f.close()

ms = poplib.POP3(server)
ms.user(uname)
ms.pass_(passw)

msgcount = len(ms.list()[1])
for i in range(msgcount):
for j in ms.retr(i+1)[1]:
   msg = email.message_from_string(j)
   WriteAttachment(msg)

##

I'm sure i'm missing something pretty simple, i just need a slap in the
right direction...

TIA

-- 
http://mail.python.org/mailman/listinfo/python-list


Listening for a Keypress (Console, not GUI)

2005-06-23 Thread brettk
Hello All,

I've written a small daemon that monitors a pop3 mailbox and downloads
any new messages.  It's run from the console in windows, and instead of
having it print something each time it gets a message or writes a file,
i'd like to store those values as internal variables and print them to
the screen whenever the user wants to see them.

So, my question is, using a regular console, is there a way I can get
python to listen for a specific keystroke?  I'm using signal handling
to deal with ^C, could I also do something like that?

TIA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Listening for a Keypress (Console, not GUI)

2005-06-23 Thread brettk
Ok, I should really read my messages more carefully before posting, I
apologize.

This is what i'm envisioning

"Python Mail Service is running..."


Status is printed like:

"Current Statistics"
Messages retrieved : 12345
Errors: 123
Total Files Written: 12345

Like that - again, apologies for my lack of detail in the first message

-- 
http://mail.python.org/mailman/listinfo/python-list