appending messages in imaplib

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • huw.lynes@gmail.com

    #1

    appending messages in imaplib

    So I have the unfortunate task of migrating several hundred users from
    local mail (mbox and mh) up to an exchange server as part of wearisome
    SOX compliance nonsense.

    I thought the best path through this thicket would be to knock up a
    quick python script using imaplib to replicate folder structures on the
    IMAP server and copy the mails accross.

    Accessing the IMAP server is great. I can log in, search for mail,
    change folder and fetch mail. but I just can't seem to get .append() to
    work. Here is a quick example.

    server = IMAP4("mail01")
    server.login("h uw-l","xxxxxxxx x")
    ('OK', ['LOGIN completed.'])
    server.create(" Migration")
    ('OK', ['CREATE completed.'])
    #using a mail client I can verify that the folder was created
    server.select(" Inbox")
    'OK'
    r,data = server.fetch('2 20','(RFC822)')
    #data now contains a real mail message off the server
    message = data
    server.append(" Migration",None ,None,message)

    at which point it just sits there and does nothing. Any ideas greatly
    appreciated. I'm assuming that it has something to do with the way I'm
    passing it the message but I don't really know where to go from here.

    Thanks,
    Huw

  • Laurent Pointal

    #2
    Re: appending messages in imaplib

    huw.lynes@gmail .com wrote:[color=blue]
    > So I have the unfortunate task of migrating several hundred users from
    > local mail (mbox and mh) up to an exchange server as part of wearisome
    > SOX compliance nonsense.
    >
    > I thought the best path through this thicket would be to knock up a
    > quick python script using imaplib to replicate folder structures on the
    > IMAP server and copy the mails accross.[/color]

    [zip]


    Have you tried to search for mbox2imap ?

    On google the first link is... a Python script.



    And there are other entries...



    Looking for mh2imap seem quasi unproductive.

    A+

    Comment

    • huw.lynes@gmail.com

      #3
      Re: appending messages in imaplib

      >On google the first link is... a Python script.
      [color=blue]
      >http://home.tiscali.cz:8080/~cz21055...s/mbox2imap.py[/color]
      [color=blue]
      >And there are other entries...[/color]

      That appears to contain the magic I need thanks. It just use python
      mailbox so adding in MH support should be trivial. Then I need to add
      some directory walking logic around it and all should be good.

      Just ran a 1500 mail mbox through it and it worked like a charm.

      Cheers,
      Huw

      Comment

      Working...