Skip to content

Mail Receiver fetch redundant Messages  #3619

@wangYX657211334

Description

@wangYX657211334

Version
org.springframework.integration:spring-integration-mail:5.5.3

Describe the bug

example:

Pop3MailReceiver mailReceiver = ...;
mailReceiver.setMaxFetchSize(10);
Object[] messages = mailReceiver.receive();

The above code execute result messages.length is 10, it is right
but, in the org.springframework.integration.mail.AbstractMailReceiver.searchAndFilterMessages method, fetch all messages, Cause performance problems
spring-integration-mail source code:

private MimeMessage[] searchAndFilterMessages() throws MessagingException {
    this.logger.debug(() -> "attempting to receive mail from folder [" + this.folder.getFullName() + "]");
    Message[] messagesToProcess;
    Message[] messages = searchForNewMessages();
    if (this.maxFetchSize > 0 && messages.length > this.maxFetchSize) {
        Message[] reducedMessages = new Message[this.maxFetchSize];
        System.arraycopy(messages, 0, reducedMessages, 0, this.maxFetchSize);
        messagesToProcess = reducedMessages;
    }
    else {
        messagesToProcess = messages;
    }
    this.logger.debug(() -> "found " + messagesToProcess.length + " new messages");
    if (messagesToProcess.length > 0) {
        fetchMessages(messages);
    }

    this.logger.debug(() -> "Received " + messagesToProcess.length + " messages");

    MimeMessage[] filteredMessages = filterMessagesThruSelector(messagesToProcess);

    postProcessFilteredMessages(filteredMessages);
    return filteredMessages;
}

commit link
fetchMessages(messages); changed to fetchMessages(messagesToProcess); ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions