gpt4 book ai didi

java - IMAP 电子邮件 channel 适配器引发异常 "A5 BAD invalid command or parameters;"

转载 作者:行者123 更新时间:2023-12-02 01:35:20 25 4
gpt4 key购买 nike

我正在使用 imap-idle-channel-adapter 在 Spring 集成中接收电子邮件:

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>

最佳答案

我的邮件服务器不支持 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?

关于java - IMAP 电子邮件 channel 适配器引发异常 "A5 BAD invalid command or parameters;",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45540205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com