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@xxxxxxxxx', '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()
.



Relevant Pages

  • Re: mail and contact sychronisation ???
    ... Because you say you're seeing a local Inbox and an Exchange Server Inbox, I'm thinking you have Outlook configured to use both the server mailbox and a local PST file. ...
    (microsoft.public.windows.server.sbs)
  • Re: Administrator Inbox
    ... There are two methods to permit sharing of inbox, ... Within the primary users mailbox (such as logged on as the ... On the server, under the primary user's account in Active ...
    (microsoft.public.backoffice.smallbiz2000)
  • The Esc Character.
    ... I then tried Mac help for the Mac email client that I use with effectivity to find the article I copy and paste below. ... where I selected all of the messages and then clicked on Remove From Server. ... My mailbox is over its quota ... For .Mac or IMAP accounts, click the Size header to find the largest mail folders on your server. ...
    (comp.sys.mac.misc)
  • Re: Offline Files -- & -- Migration Strategy
    ... So your mail is delivered to a mailbox on your MailSite server, ... Outlook, running on your desktop PC, retrieves it using POP, right? ... just configure Exchange to be the SMTP server as in a normal SBS ...
    (microsoft.public.windows.server.sbs)
  • Re: cannot connect to mailbox after new install
    ... the new exch server was selected already. ... As for removing old exch svr, i don't have the old svr anymore; ... Can you verify the manual removal of your old Exchange Server? ... I did a find for users with exch mailbox and was able to find 41 ...
    (microsoft.public.exchange.setup)