Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 20, 2022 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/4587f4f70b733eebc36f247bd79c7fdc to your computer and use it in GitHub Desktop.
Save aspose-com-gists/4587f4f70b733eebc36f247bd79c7fdc to your computer and use it in GitHub Desktop.
Write and Read Messages on Thunderbird Storage in Java
// Load file
try (FileInputStream stream = new FileInputStream("file.mbox")) {
// Create load options
MboxLoadOptions lo = new MboxLoadOptions();
lo.setLeaveOpen(false);
// Read messages from file
try (MboxrdStorageReader reader = new MboxrdStorageReader(stream, lo)) {
MailMessage msg;
String[] fromMarker = {null};
while ((msg = reader.readNextMessage(/* out */fromMarker)) != null) {
System.out.println(fromMarker[0]);
}
}
}
// Load file
try (FileOutputStream writeStream = new FileOutputStream("inbox")) {
// Create writer
try (MboxrdStorageWriter writer = new MboxrdStorageWriter(writeStream, false)) {
// Load message from MSG file
MailMessage msg = MailMessage.load("Message.msg");
String[] fromMarker = {null};
// Write message
writer.writeMessage(msg, fromMarker);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment