/** * @param localFlag * @return String */ private String sendMail(HashMap<String, List<EmailPojo>> hashMapMail, boolean localFlag) { String failrueId = null; String accountName = null; String getfailrueId; try { for (String key : hashMapMail.keySet()) { List<EmailPojo> mailPojoList = hashMapMail.get(key); Account account = mailPojoList.get(0).getAccount(); accountName = account.getName(); Operator operator; if (localFlag) { operator = (Operator) beanFactory.getBean("localsmtp"); } else { if (beanFactory.containsBean(account.getSendProtocolType())) { operator = (Operator) beanFactory.getBean(account.getSendProtocolType()); } else { operator = (Operator) beanFactory.getBean("localsmtp"); } } getfailrueId = operator.sendMail(mailPojoList); if (failrueId == null) { if (getfailrueId != null) { failrueId = getfailrueId; } } else { if (getfailrueId != null) { failrueId += "," + getfailrueId; } } } } catch (Exception e) { log.error("sendMail/SendMailListener/Exception: " + "[" + accountName + "]", e); } return failrueId; }
/** * Deliveres notification to the user that an email has been dropped. Typically due to size * restriction * * @param account * @param messageNumber * @param message * @throws Exception */ public void saveMessageDroppedNotification( Account account, int messageNumber, Message message, int reportedSize) throws Exception { MessageParser parser = new MessageParser(); Email email = new Email(); email.setSubject( "Your email"); // ReceiverUtilsTools.subSubject(parser.parseMsgSubject(message), // subjectSize)); email.setFrom(parser.parseMsgAddress(message, "FROM", false)); email.setTo(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "TO", true))); email.setCc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "CC", true))); email.setBcc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "BCC", true))); email.setMaildate(ReceiverUtilsTools.dateToStr(message.getSentDate())); email.setStatus("0"); email.setUserId(account.getUser_id()); email.setMessage_type("EMAIL"); Body body = new Body(); String droppedMessage = getEmailDroppedMessage(account, getMessageDate(message), reportedSize, email.getFrom()); body.setData(droppedMessage.getBytes()); email.setBodySize(droppedMessage.length()); int saveStatus = DALDominator.newSaveMail(account, email, body); if (log.isDebugEnabled()) log.debug( String.format( "[%s] msgNum=%d, saving completed for dropped message with status %s", account.getName(), messageNumber, saveStatus)); }
/** * It so happens Gmail sends us sent messages as well as received once * * @param account * @param message * @return * @throws Exception */ protected boolean isSentMessage(Account account, Message message) throws Exception { MessageParser parser = new MessageParser(); if (EmailUtil.isFromSameAsAccount(account, message)) { String to = parser.parseMsgAddress(message, "TO", true); String cc = parser.parseMsgAddress(message, "CC", true); if (!to.contains(account.getName()) && !cc.contains(account.getName())) { log.warn( String.format( "msgNum=%d, message is 'sent' not 'received' discarding, for %s", message.getMessageNumber(), account.getName())); return true; } } return false; }
boolean isMessageTooBig(Folder folder, Account account, Message message, int messageNumber) throws Exception { int messageSize = (folder instanceof POP3Folder) ? ((POP3Folder) folder).getMessageSize(messageNumber) : getMessageSize(message, account); boolean messageTooBig = messageSize > maximumMessageSize; if (messageTooBig) { log.warn( String.format( "msgNum=%d, message is too big %d bytes, discarding for %s", messageNumber, messageSize, account.getName())); saveMessageDroppedNotification(account, messageNumber, message, messageSize); } return messageTooBig; }