The IMAP filter for the mail channel selected the exception "A5 BAD invalid command or parameters";

I am using imap-idle-channel-adapter to receive emails in spring integration:

A5 SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL
A5 BAD invalid command or parameters

      

it seems like the IMAP server is treating the above commands as invalid, can anyone tell me how to fix it?

My debug posts:

DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: closeFoldersOnStoreFailure
DEBUG IMAPS: trying to connect to host "imap.mxhichina.com", port 993, isSSL true
* OK AliYun IMAP Server Ready(10.177.11.50)
A0 CAPABILITY
* CAPABILITY IMAP4rev1 IDLE XLIST UIDPLUS ID SASL-IR AUTH=XOAUTH AUTH=EXTERNAL
A0 OK CAPABILITY completed
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: AUTH: EXTERNAL
DEBUG IMAPS: protocolConnect login, host=imap.mxhichina.com, user=*****, password=<non-null>
DEBUG IMAPS: mechanism PLAIN not supported by server
DEBUG IMAPS: mechanism LOGIN not supported by server
DEBUG IMAPS: mechanism NTLM not supported by server
DEBUG IMAPS: mechanism XOAUTH2 disabled by property: mail.imaps.auth.xoauth2.disable
DEBUG IMAPS: LOGIN command trace suppressed
DEBUG IMAPS: LOGIN command result: A1 OK LOGIN completed
A2 CAPABILITY
* CAPABILITY IMAP4rev1 IDLE XLIST UIDPLUS ID SASL-IR AUTH=XOAUTH AUTH=EXTERNAL
A2 OK CAPABILITY completed
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: AUTH: EXTERNAL
A3 LIST "" INBOX
* LIST () "/" "INBOX"
A3 OK LIST completed
DEBUG IMAPS: connection available -- size: 1
A4 SELECT INBOX
* 2 EXISTS
* 0 RECENT
* OK [UNSEEN 0]
* OK [UIDNEXT 25] Predicted next UID.
* OK [UIDVALIDITY 2] UIDs valid.
* FLAGS (\Answered \Seen \Deleted \Draft \Flagged)
* OK [PERMANENTFLAGS (\Answered \Seen \Deleted \Draft \Flagged)] Limited.
A4 OK [READ-WRITE] SELECT completed
A5 SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL
A5 BAD invalid command or parameters
13:41:00.557 WARN  [task-scheduler-1][org.springframework.integration.mail.ImapIdleChannelAdapter] error occurred in idle task
javax.mail.MessagingException: A5 BAD invalid command or parameters;

      

my config

<int-mail:imap-idle-channel-adapter id="mailAdapter"
                                    store-uri="imaps://${username}:${password}@imap.mxhichina.com/INBOX"
                                    channel="inboundChannel"
                                    auto-startup="true"
                                    should-delete-messages="true"
                                    should-mark-messages-as-read="true"
                                    java-mail-properties="javaMailProperties"/>

    <util:properties id="javaMailProperties">
        <prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
        <prop key="mail.imap.socketFactory.fallback">false</prop>
        <prop key="mail.store.protocol">imaps</prop>
        <prop key="mail.transport.protocol">smtps</prop>
        <prop key="mail.smtps.auth">true</prop>
        <prop key="mail.debug">true</prop>
        <prop key="mail.smtp.starttls.enable">true</prop>
    </util:properties>

      

+3


source to share


1 answer


Command

NOT (*****) is not supported by my mail server, so the following command doesn't work

A5 SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL

      

So, I changed the DefaultSearchTermStrategy to my own called UnseenSearchTermStrategy

@Component
public class UnseenSearchTermStrategy  implements SearchTermStrategy {
    UnseenSearchTermStrategy(){
        super();
    }
    @Override
    public SearchTerm generateSearchTerm(Flags flags, Folder folder) {
        return new FlagTerm(new Flags(Flags.Flag.SEEN), false);
    }
}

      



and the following commands will run on the mail server and will work well

A5 SEARCH UNSEEN ALL

      

Related topics on stackoverflow Using the spring IMAP integration adapter, how do I get an email that has been marked "unread" manually?

0


source







All Articles