{
Config config = Config.getConfig();
if (emailId==null || emailId.getVolume()==null || emailId.getUniqueID()==null)
throw new MessageStoreException("assertion failure: null emailID, volume or uniqueId",logger);
if(emailId.getUniqueID() == null)
throw new MessageStoreException("insert message was found to have a null message id.", logger);
logger.debug("insertMessage {"+emailId + "}");
if (!config.isDefaultPassPhraseModified())
throw new MessageStoreException("failed to archive message. encryption password is not set. {"+emailId+"}",logger);
File messageFile = getNewFile(emailId.getVolume(),emailId.getUniqueID(),messageFileExtension);
if (messageFile.exists()) {
logger.debug("no need to archive. message already exists in the store. {"+emailId+"}");
return false;
}
try {
email.setHeader("X-MailArchiva-Archive-Date", DateUtil.convertDatetoString(new Date()));
} catch (MessagingException me) {
logger.error("failed to set archive date");
}
try {
writeEmail(email, messageFile);
} catch (Exception e) {
throw new MessageStoreException("failed to write message to store {"+emailId+"}",e,logger);
}
return true;
}