public static void storeMessage(Principal principal, InputStream compressedStream, MessageState compressed) throws ArchiveException
{
if (compressedStream == null)
throw new ArchiveException("assertion failure: null message,username or remoteIP",logger,ArchiveException.RecoveryDirective.RETRYLATER);
logger.debug("message received for archival (via smtp service) {"+principal+"'}");
Config config = ConfigurationService.getConfig();
/*
try {
File faultyFile = new File("c:\\temp.tmp");
FileOutputStream fos = new FileOutputStream(faultyFile);
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = compressedStream.read(buf)) >= 0) {
fos.write(buf, 0, numRead);
}
fos.close();
} catch (Exception e) {
logger.error(e);
return;
}
return;*/
Email message = null;
try {
if (compressed==MessageState.COMPRESSED)
message = new Email(null,new GZIPInputStream(compressedStream));
else
message = new Email(null,compressedStream);
} catch (Exception io) {
if (io.getCause() instanceof MaxMessageSizeException) {
logger.error("cannot process message. max message size is exceeded.",io.getCause());
throw new ArchiveException("cannot process message. max message size is exceeded.",(MaxMessageSizeException)io.getCause(),logger,ArchiveException.RecoveryDirective.REJECT);
}
logger.error("archive message is corrupted. unable to parse it.",io);
try {
messageStore.copyEmailToNoArchiveQueue(message);
} catch (Exception e2) {
throw new ArchiveException("failed to copy message to the no archive queue.",e2,logger,ArchiveException.RecoveryDirective.RETRYLATER);
}
}
if (!config.isDefaultPassPhraseModified()) {
try {
messageStore.copyEmailToNoArchiveQueue(message);
} catch (Exception e2) {
throw new ArchiveException("failed to copy message to the no archive queue.",e2,logger,ArchiveException.RecoveryDirective.RETRYLATER);
}
logger.error("failed to archive message. encryption password is not set.");
}
if (config.getArchiveRules().shouldArchive(message,ConfigurationService.getConfig().getDomains())==ArchiveRules.Action.ARCHIVE) {
try {
archive(principal,message,false);
} catch (Exception e) {
logger.error("error occurred while archiving message. message will be reprocessed on server restart",e);
try {
messageStore.copyEmailToNoArchiveQueue(message);
} catch (Exception e2) {
throw new ArchiveException("failed to copy message to the no archive queue.",e2,logger,ArchiveException.RecoveryDirective.RETRYLATER);
}
}
} else {
audit.info("skip email {"+message+", "+principal+"}");