public Message processMessage( Account account, String messageStoreBucket, Message message, int messageNumber, String messageId, String context, StopWatch watch, List<MessageValidator> validators, EmailProcess emailProcess) throws Exception { long start = System.nanoTime(); try { StopWatchUtils.newTask( watch, String.format("msgNum=%s, storeCheck", messageNumber), context, log); log.debug( String.format( "msgNum=%d, checking if messageId=%s is known for %s", messageNumber, messageId, context)); message = valiateAndPrepMessage( account, messageStoreBucket, message, messageNumber, messageId, validators); if (message != null) { log.info( String.format( "msgNum=%d, messageId=%s, message is new for %s", messageNumber, messageId, context)); boolean result = emailProcess.process(message, messageNumber, messageId); if (result) { return message; } } } finally { if (log.isDebugEnabled()) log.debug( String.format( "msgNum=%d, checked if messageId=%s is known in %dms for %s", messageNumber, messageId, (System.nanoTime() - start) / 1000000, context)); } return null; }
public boolean processMessage( Account account, Message message, int messageNumber, String messageId, Folder folder, Set<String> storeMessageIds, String storeBucket, String context, StopWatch watch, FolderHelper folderHelper) throws Exception { boolean result = false; long start = System.nanoTime(); try { StopWatchUtils.newTask( watch, String.format("msgNum=%s, storeCheck", messageNumber), context, log); // Log.debug(log4j, "msgNum=%d, checking if messageId=%s is known for %s", messageNumber, // messageId, context); // Log.debug(log4j, "msgNum=%d, checking if messageId=%s is too old or too big or sent for // %s", messageNumber, messageId, context); StopWatchUtils.newTask( watch, String.format("msgNum=%s, tooOld-tooBig-check", messageNumber), context, log); if (isMessageTooOld(account, message, context)) { log.warn( String.format( "msgNum=%d, messageId=%s, message is too old, sentDate=%s, discarding, for %s", messageNumber, messageId, message.getSentDate(), context)); // this message is too old and needs to be ignored } else { message = getFullyLoad(message, folder, context); int messageSize = (folder instanceof POP3Folder) ? ((POP3Folder) folder).getMessageSize(messageNumber) : getMessageSize(message, account); if (messageSize > maximumMessageSize) { log.warn( String.format( "msgNum=%d, messageId=%s, message is too big %d bytes, discarding for %s", messageNumber, messageId, messageSize, context)); saveMessageDroppedNotification(account, messageNumber, message, messageSize); } else { if (log.isDebugEnabled()) log.debug( String.format( "msgNum=%d, messageId=%s, message is new for %s", messageNumber, messageId, context)); try { new EmailSaveProcess(account, watch, context) .process(message, messageNumber, messageId); } catch (Throwable e) { log.fatal( String.format( "msgNum=%d, messageId=%s, subject=%s message saving failed for %s", messageNumber, messageId, message.getSubject(), context), e); StopWatchUtils.newTask( watch, String.format("msgNum=%s, removeFromStore", messageNumber), context, log); } result = true; } } } finally { if (log.isDebugEnabled()) log.debug( String.format( "msgNum=%d, checked if messageId=%s is known in %dms for %s", messageNumber, messageId, (System.nanoTime() - start) / 1000000, context)); } return result; }