Results 1 to 5 of 5

Thread: imap admin access with python's imaplib

  1. #1
    sunqiang is offline New Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    2

    Default imap admin access with python's imaplib

    google search 'imap admin access' returns this post.
    at first, I think python's imaplib.proxyauth is the intuitive way.
    so here is the demo code:
    Code:
    hostname, username, password = get_config()
    conn = imaplib.IMAP4_SSL(hostname)
    typ, cap = conn.login(username, password)   # username is a admin
    conn.proxyauth("user1")
    however, proxyauth raise a error "imaplib.error: PROXYAUTH command error: BAD ['parse error: command not implemented']

    after some debuging, it seems the line "conn.login(username, password)" will translated to send the tcp string 'PALI1 LOGIN username "password"\r\n', this works. and the line "conn.proxyauth("user1")" will translated to 'PALI2 PROXYAUTH user1\r\n', and it failed.

    so I wonder how imapsync, as this post said, knows to do this delegated authentication.

    imapsync's "imapsync --host1 source.server.com --user1 username --authuser1 adminusername --password1 adminpassword " will translated to what TCP protocal string?

  2. #2
    eduard.guloiu is offline New Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    2

    Default

    Hello,

    First of all you should enable Plain text login in zimbra (anyway that's the method that works with zimbra proxy).
    If you use zimbra proxy (or not) you can auth as admin via ssl with the imap AUTH command.
    This is what it works:
    imap_conn = imaplib.IMAP4_SSL(imaphost,imapport)
    authcb = lambda resp: "{0}\x00{1}\x00{2}".format(user,adminuser,adminpas s)
    imap_conn.authenticate("PLAIN", authcb)
    I am working on a script that dumps the entire mailbox and import only differences in case of restore. I will post it as soon as it works.
    Bare with me.
    Tip: fetching one message a time takes let's say about 2 hours to backup, if you get bulk (let's say 200 msgs at once) it will last 6 minutes.

  3. #3
    sunqiang is offline New Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    2

    Default

    Quote Originally Posted by eduard.guloiu View Post
    Hello,

    First of all you should enable Plain text login in zimbra (anyway that's the method that works with zimbra proxy).
    If you use zimbra proxy (or not) you can auth as admin via ssl with the imap AUTH command.
    This is what it works:
    imap_conn = imaplib.IMAP4_SSL(imaphost,imapport)
    authcb = lambda resp: "{0}\x00{1}\x00{2}".format(user,adminuser,adminpas s)
    imap_conn.authenticate("PLAIN", authcb)
    I am working on a script that dumps the entire mailbox and import only differences in case of restore. I will post it as soon as it works.
    Bare with me.
    Tip: fetching one message a time takes let's say about 2 hours to backup, if you get bulk (let's say 200 msgs at once) it will last 6 minutes.
    thanks! you made my day! with your help, I search "python imap plain authentication", and it returns "http://www.tylerlesmann.com/2009/apr/15/plain-imap-authentication-python/" (almost the same as yours direct answer)
    can't waiting your dump and restore script~
    thanks again.

  4. #4
    eduard.guloiu is offline New Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    2

    Default

    Finaly,

    After a lot of work, here it is:
    https://docs.google.com/open?id=0B5j...XBIY1J1Q0p4UFk
    Alternate location:
    http://ed.contconsult.ro/?a=d&i=26bFu5VWVe

    I have tested it wit gmail and imported back to zimbra. Some flags are awkward on gmail but I check all of them from script.

    I am dumping all the messages in a shelve object with the key made of md5 from message header and folder. (you will not have duplicates).
    Import is done using threads as max as batch_size, as python imap allows only one message at a time (which is very slow).

    Use case example
    dump gmail
    gmail uses login over ssl so this should work:
    /home/eguloiu/python-imap-util.py -i imap.gmail.com -u user@gmail.com -a user@gmail.com -p 'secret pass' -t 993 -s -b -l

    import into zimbra:
    /home/eguloiu/python-imap-util.py -i <zimbra ip or name> -u user@domain -a admin@domain -p <admin pass> -t 993 -s -r -f <backup file generated>

    See help for more options, or take a look into the scritp.

    I need your feedback and anyone's who uses the script.


    This is some output from my zimbra server:
    ------Backup start time 2012-09-20 18:57:58.012247
    ['"Chats"', '"Contacts"', '"Drafts"', '"INBOX"', '"INBOX/Drafts"', '"INBOX/Sent"', '"INBOX/Spam"', '"Junk"', '"Sent"']
    Selected folder: "Chats"

    Selected folder: "Contacts"

    Selected folder: "Drafts"

    Selected folder: "INBOX"
    Writting message 75993 of 75993
    Selected folder: "INBOX/Drafts"

    Selected folder: "INBOX/Sent"

    Selected folder: "INBOX/Spam"

    Selected folder: "Junk"
    Writting message 155 of 155
    Selected folder: "Sent"

    ------Backup end time: 2012-09-20 19:03:49.420811, Duration: 0:05:51.408580


    I will really appreciate any feedback.

    Thanks
    Last edited by eduard.guloiu; 09-20-2012 at 10:17 AM. Reason: Alternate download location

  5. #5
    sunqiang is offline New Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    2

    Default

    well done, I'll check the it asap, and let you know if I had any issues.
    thanks again
    Quote Originally Posted by eduard.guloiu View Post
    Finaly,

    After a lot of work, here it is:
    https://docs.google.com/open?id=0B5j...XBIY1J1Q0p4UFk
    Alternate location:
    Open Upload - File download

    I have tested it wit gmail and imported back to zimbra. Some flags are awkward on gmail but I check all of them from script.

    I am dumping all the messages in a shelve object with the key made of md5 from message header and folder. (you will not have duplicates).
    Import is done using threads as max as batch_size, as python imap allows only one message at a time (which is very slow).

    Use case example
    dump gmail
    gmail uses login over ssl so this should work:
    /home/eguloiu/python-imap-util.py -i imap.gmail.com -u user@gmail.com -a user@gmail.com -p 'secret pass' -t 993 -s -b -l

    import into zimbra:
    /home/eguloiu/python-imap-util.py -i <zimbra ip or name> -u user@domain -a admin@domain -p <admin pass> -t 993 -s -r -f <backup file generated>

    See help for more options, or take a look into the scritp.

    I need your feedback and anyone's who uses the script.


    This is some output from my zimbra server:
    ------Backup start time 2012-09-20 18:57:58.012247
    ['"Chats"', '"Contacts"', '"Drafts"', '"INBOX"', '"INBOX/Drafts"', '"INBOX/Sent"', '"INBOX/Spam"', '"Junk"', '"Sent"']
    Selected folder: "Chats"

    Selected folder: "Contacts"

    Selected folder: "Drafts"

    Selected folder: "INBOX"
    Writting message 75993 of 75993
    Selected folder: "INBOX/Drafts"

    Selected folder: "INBOX/Sent"

    Selected folder: "INBOX/Spam"

    Selected folder: "Junk"
    Writting message 155 of 155
    Selected folder: "Sent"

    ------Backup end time: 2012-09-20 19:03:49.420811, Duration: 0:05:51.408580


    I will really appreciate any feedback.

    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Admin (and admin users) can't access other mailboxes...
    By djsmiley2k in forum Administrators
    Replies: 15
    Last Post: 01-19-2012, 05:06 AM
  2. Login via python imaplib
    By jimmyj_in in forum Users
    Replies: 1
    Last Post: 09-02-2010, 12:20 PM
  3. Replies: 0
    Last Post: 01-28-2010, 01:17 AM
  4. imap admin access
    By garyo in forum Administrators
    Replies: 1
    Last Post: 01-14-2009, 01:03 AM
  5. Replies: 9
    Last Post: 08-31-2006, 08:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •