'How to create mbox using Java JavaMail?

How to read mail inbox using IMAP protocol and JavaMail and then use local disk to store mails. There is no documentation of mstor. I try this way but it seems that MStorStore just read local mbox instead of creating and updating it according to the external server passed as params in connect() function. I get error: Folder [Inbox] does not exist.

Session lSession = Session.getDefaultInstance(props);
MStorStore lStore = new MStorStore(lSession , new URLName("mstor:c:/some_path/" + _mailModel.account.login));
lStore.connect(_mailModel.account.imap, _mailModel.account.login, _mailModel.account.password);
Folder lInbox = lStore.getDefaultFolder().getFolder("Inbox");

The questioin is how to create MBox from javax.mail.Store that i could read and update using Mstor.



Solution 1:[1]

I don't know if I am answering the right question (or answering a question at all), but, here is a method I wrote in a Scala program that takes an array of javamail Messages (acquired via imap) and writes them to a new mbox file in a directory named "mbox" in the root of my project using MStorStore. The new file is named whatever is passed in the "mboxName" parameter.

def writeToMbox(messages: Array[Message], mboxName: String) {    
    val mProps = System.getProperties
    mProps.setProperty("mstor.mbox.metadataStrategy", "none")
    val mSession = Session.getDefaultInstance(mProps)
    val mStore = new MStorStore(mSession, new URLName("mstor:mbox"))
    mStore.connect
    val mFolder = mStore.getDefaultFolder
    val localMbox = (new File("mbox", mboxName)).createNewFile
    val mbox = mFolder.getFolder(mboxName)
    mbox.open(Folder.READ_WRITE)
    mbox.appendMessages(messages)
    mbox.close(false)
    mStore.close
  }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 awfulHack