IMAP Problems

Discussion in 'Python' started by Paul, Jul 2, 2010.

  1. Paul

    Paul Guest

    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('', '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()
     
    Paul, Jul 2, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik Ormåsen

    Curier-IMAP and imap.create()

    Henrik Ormåsen, Aug 19, 2006, in forum: Ruby
    Replies:
    0
    Views:
    178
    Henrik Ormåsen
    Aug 19, 2006
  2. Jon Fi
    Replies:
    4
    Views:
    548
    Kashia Buch
    Oct 21, 2006
  3. jasonnaylor
    Replies:
    1
    Views:
    257
    jasonnaylor
    Apr 16, 2008
  4. Adam Akhtar
    Replies:
    1
    Views:
    179
    Eric Hodel
    Dec 15, 2008
  5. Abhishiv Saxena

    Support for IMAP IDLE in net/imap

    Abhishiv Saxena, Jul 3, 2009, in forum: Ruby
    Replies:
    4
    Views:
    199
    Eric Hodel
    Jul 4, 2009
Loading...

Share This Page