mash-sap commented on a change in pull request #7213: URL: https://github.com/apache/camel/pull/7213#discussion_r829460988
########## File path: components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java ########## @@ -388,63 +387,57 @@ private SearchTerm computeSearchTerm() { return null; } - protected Queue<Exchange> createExchanges(List<KeyValueHolder<String, Message>> messages) throws MessagingException { - Queue<Exchange> answer = new LinkedList<>(); - - for (int i = 0; i < messages.size(); i++) { - try { - KeyValueHolder<String, Message> holder = messages.get(i); - String key = holder.getKey(); - Message message = holder.getValue(); + protected Exchange createExchange(KeyValueHolder<String, Message> holder) throws MessagingException { + try { + String key = holder.getKey(); + Message message = holder.getValue(); - if (LOG.isTraceEnabled()) { - LOG.trace("Mail #{} is of type: {} - {}", i, ObjectHelper.classCanonicalName(message), message); - } + if (LOG.isTraceEnabled()) { + LOG.trace("Mail is of type: {} - {}", ObjectHelper.classCanonicalName(message), message); + } - if (!message.getFlags().contains(Flags.Flag.DELETED)) { - Exchange exchange = createExchange(message); - if (getEndpoint().getConfiguration().isMapMailMessage()) { - // ensure the mail message is mapped, which can be ensured by touching the body/header/attachment - LOG.trace("Mapping #{} from javax.mail.Message to Camel MailMessage", i); - exchange.getIn().getBody(); - exchange.getIn().getHeaders(); - // must also map attachments - try { - Map<String, Attachment> att = new HashMap<>(); - getEndpoint().getBinding().extractAttachmentsFromMail(message, att); - if (!att.isEmpty()) { - exchange.getIn(AttachmentMessage.class).setAttachmentObjects(att); - } - } catch (MessagingException | IOException e) { - // must release exchange before throwing exception - releaseExchange(exchange, true); - throw new RuntimeCamelException("Error accessing attachments due to: " + e.getMessage(), e); + if (!message.getFlags().contains(Flags.Flag.DELETED)) { + Exchange exchange = createExchange(message); + if (getEndpoint().getConfiguration().isMapMailMessage()) { + // ensure the mail message is mapped, which can be ensured by touching the body/header/attachment + LOG.trace("Mapping from javax.mail.Message to Camel MailMessage"); + exchange.getIn().getBody(); + exchange.getIn().getHeaders(); + // must also map attachments + try { + Map<String, Attachment> att = new HashMap<>(); + getEndpoint().getBinding().extractAttachmentsFromMail(message, att); + if (!att.isEmpty()) { + exchange.getIn(AttachmentMessage.class).setAttachmentObjects(att); } + } catch (MessagingException | IOException e) { + // must release exchange before throwing exception + releaseExchange(exchange, true); + throw new RuntimeCamelException("Error accessing attachments due to: " + e.getMessage(), e); } + } - // If the protocol is POP3 we need to remember the uid on the exchange - // so we can find the mail message again later to be able to delete it - // we also need to remember the UUID for idempotent repository - exchange.setProperty(MAIL_MESSAGE_UID, key); + // If the protocol is POP3 we need to remember the uid on the exchange + // so we can find the mail message again later to be able to delete it + // we also need to remember the UUID for idempotent repository + exchange.setProperty(MAIL_MESSAGE_UID, key); - answer.add(exchange); - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("Skipping message as it was flagged as deleted: {}", MailUtils.dumpMessage(message)); - } - } - } catch (Exception e) { - if (skipFailedMessage) { - LOG.debug("Skipping failed message at index {} due {}", i, e.getMessage(), e); - } else if (handleFailedMessage) { - handleException(e); - } else { - throw e; + return exchange; + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Skipping message as it was flagged as deleted: {}", MailUtils.dumpMessage(message)); } } + } catch (Exception e) { + if (skipFailedMessage) { + LOG.debug("Skipping failed message at index due {}", e.getMessage(), e); Review comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org