Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   IMAP Problems (http://www.velocityreviews.com/forums/t727243-imap-problems.html)

Paul 07-02-2010 10:35 PM

IMAP Problems
 
Hi,
I'm trying to write a simple script which displays the basic details
of a person's mailbox. My problem is that it causes all the messages
to be marked as read on the server, which is not what I'm after, and I
also can't get the imap.sort command to work properly (currently
commented out as I replaced it with a imap.search to get the thing
working.
These are probably very simple things, but I've not tried this library
before so am a bit stuck so any help wwould be very gratefully
received.
Thanks,
Paul

Code:

# -*- coding: cp1252 -*-
import imaplib,email

# you want to connect to a server; specify which server
server= imaplib.IMAP4_SSL('imap.googlemail.com')
# after connecting, tell the server who you are
server.login('xxxx@gmail.com', 'xxxxxxx')
# this will show you a list of available folders
# possibly your Inbox is called INBOX, but check the list of mailboxes
code, mailboxen= server.list()
print mailboxen
# if it's called INBOX, thenů
server.select("INBOX")

typ, data = server.search(None, 'ALL')
#typ, data = server.sort("Date","UTF-8", 'ALL')
print len(data[0].split())
for num in data[0].split():
typ, data = server.fetch(num, '(RFC822)')
#print 'Message %s\n%s\n' % (num, data[0][1])
msg = email.message_from_string(data[0][1])
print msg["From"]
print msg["Subject"]
print msg["Date"]
print "_______________________________"

server.close()
server.logout()


All times are GMT. The time now is 09:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.