imaplib question

Laszlo Nagy gandalf at designaproduct.biz
Fri Jul 14 09:54:58 EDT 2006


  Hello,

I'm trying to write a very simple program that moves all messages from 
INBOX into another folder.
I'm not sure what am I doing wrong. This is a very simple task. I 
believe I need to call these methods:

- search -> get all message UIDs in the INBOX
- copy -> copy all messages to another folder
- store -> mark all messages in INBOX as deleted
- expunge -> delete them physically

Here is what I have now:

conn = getnewimapconnection()
try:
    typ,data = conn.select()
    check_error((typ,data))
    #print "Number of messages in INBOX: ",data[0]   
    typ,all_messages = conn.search(None,'(ALL)')
    check_error((typ,data))
   
    #mailboxes = conn.list()[1]
    #for mb in mailboxes:
    #    print mb   
    #raise SystemExit   
   
    # Store all messages into another
    typ,data = conn.copy(all_messages,'"PublicInbox"')
    check_error((typ,data))
finally:
    conn.logout()


I get this error:

Traceback (most recent call last):
  File "MailDaemon.py", line 99, in ?
    check_error((typ,data))
  File "MailDaemon.py", line 15, in check_error
    raise IMAPError((typ,data))
__main__.IMAPError: ('NO', ["[TRYCREATE] Mailbox doesn't exist: 2"])

However, if I comment out the for loop that lists the mailboxes, I see this:

(\HasNoChildren) "/" "PublicInbox"

I also tried 'PublicInbox' '/PublicInbox' and '/ PublicInbox' etc. but 
none of them works. Most strangely, if I create a new mailbox with 
create('TTT') then it creates a new mailbox successfuly.

Please help me

    Laszlo




More information about the Python-list mailing list