// generate new UUID
UUID newMessageId = new MessageIdBuilder().build();
try {
Message oldMessage = messageDAO.getParsed(mailbox, messageId);
FileInputStream in = new FileInputStream(file);
MimeParser parser = new MimeParser();
// parse message
parser.parse(in);
Message newMessage = parser.getMessage();
newMessage.setSize(file.length()); // update message size
in.close();
// add labels to message
for(Integer label : oldMessage.getLabels()) {
newMessage.addLabel(label);
}
// add markers to message
for(Marker marker : oldMessage.getMarkers()) {
newMessage.addMarker(marker);
}
// store message
in = new FileInputStream(file);
messageDAO.put(mailbox, newMessageId, newMessage, in);