我使用imap-idle-channel-adapter接收spring Integration中的电子邮件:
A5 SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL
A5 BAD invalid command or parameters
似乎imap服务器认为上面的命令无效,任何人都可以告诉我如何修复?
我的调试信息:
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;
我的配置
<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>
答案 0 :(得分:0)
我的邮件服务器不支持NOT(*****)命令,因此以下命令不起作用
A5 SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL
所以我将DefaultSearchTermStrategy改为我自己的名字,名为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);
}
}
以下命令将在邮件服务器上执行并且运行良好
A5 SEARCH UNSEEN ALL
stackoverflow中的相关主题 Using spring integration IMAP adapter, how to fetch an email which was marked "unread" manually?