dump msg from MAPI item not working



  • I am trying to save an msg file from a MAPI item:

    #!/usr/bin/env python
    
    import kopano
    server = kopano.Server(server_socket='http://XXXX:237/kopano', auth_user='XXX, auth_pass='XXXX')
    store = server.user('mail').store
    store = store.folder('Inbox')
    
    for mail in store:
            if mail.entryid == 'XXXXXXXX':
                            msgfile = '/tmp/test.MSG'
                            f = open(msgfile, 'wb')
                            mail.dump(f,attachments=True,archiver=True)
                            f.close()
    

    This gives a file called test.MSG which is also binary:

    file test.MSG
    test.MSG: 8086 relocatable (Microsoft)
    

    But when I try to open it with Outlook, it says that I do not have enough permissions to open it. This is independent of the permissions and the location of the file (I have tried al lot). Alos other tools like msgconvert seem not to be able to read the file.

    What might be wrong?

    Thanks!



  • python-kopano does not support saving items to Microsoft’s MSG format documented here. If there is a reasonable and up to date Python library for it, it would be interesting to implement.


  • Kopano

    @jelly said in dump msg from MAPI item not working:

    python-kopano does not support saving items to Microsoft’s MSG format

    But what does work is exporting to eml. A sample script for this is at https://stash.kopano.io/projects/KC/repos/kopanocore/browse/swig/python/kopano/scripts/rfcdump.py



  • Thanks for the feedback. I now dump to eml and reimport to MSG via MSGConverter and wine (subprocess). Not nice, but it works.


Log in to reply