Class ImapEmailReceiver
java.lang.Object
cloud.opencode.base.email.receiver.ImapEmailReceiver
- All Implemented Interfaces:
AutoCloseable
IMAP Email Receiver Implementation
IMAP邮件接收器实现
Receives emails using IMAP protocol with full feature support.
使用IMAP协议接收邮件,支持完整功能。
Features | 主要功能:
- Full IMAP support (SSL/STARTTLS) - 完整IMAP支持(SSL/STARTTLS)
- Folder management - 文件夹管理
- Server-side search - 服务器端搜索
- Flag manipulation - 标记操作
- Move/copy operations - 移动/复制操作
- Attachment handling - 附件处理
Usage Examples | 使用示例:
// Password authentication
EmailReceiveConfig config = EmailReceiveConfig.builder()
.host("imap.gmail.com")
.username("user@gmail.com")
.password("app-password")
.imap()
.ssl(true)
.build();
// OAuth2 authentication
EmailReceiveConfig oauthConfig = EmailReceiveConfig.builder()
.host("imap.gmail.com")
.username("user@gmail.com")
.oauth2Token(accessToken)
.imap()
.ssl(true)
.build();
try (ImapEmailReceiver receiver = new ImapEmailReceiver(config)) {
receiver.connect();
List<ReceivedEmail> emails = receiver.receiveUnread();
for (ReceivedEmail email : emails) {
processEmail(email);
receiver.markAsRead(email.messageId());
}
}
Security | 安全性:
- Thread-safe: No (use one instance per thread) - 线程安全: 否(每线程使用一个实例)
- Since:
- JDK 25, opencode-base-email V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionImapEmailReceiver(EmailReceiveConfig config) Create IMAP receiver with configuration 使用配置创建IMAP接收器 -
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Close the receiver (alias for disconnect) 关闭接收器(disconnect的别名)voidconnect()voidvoidintgetMessageCount(String folder) intgetUnreadCount(String folder) booleanvoidmarkAsRead(String messageId) voidmarkAsUnread(String messageId) voidmoveToFolder(String messageId, String targetFolder) receive(EmailQuery query) default List<ReceivedEmail> Receive all emails from default folder 从默认文件夹接收所有邮件receiveById(String messageId) voidsetFlagged(String messageId, boolean flagged)
-
Constructor Details
-
ImapEmailReceiver
Create IMAP receiver with configuration 使用配置创建IMAP接收器- Parameters:
config- the receive configuration | 接收配置
-
-
Method Details
-
connect
public void connect() -
disconnect
public void disconnect() -
isConnected
public boolean isConnected() -
receiveUnread
-
receive
-
receiveById
-
getMessageCount
-
getUnreadCount
-
markAsRead
-
markAsUnread
-
setFlagged
-
delete
-
moveToFolder
-
listFolders
-
receiveAll
Receive all emails from default folder 从默认文件夹接收所有邮件- Returns:
- list of received emails | 接收到的邮件列表
-
close
default void close()Close the receiver (alias for disconnect) 关闭接收器(disconnect的别名)- Specified by:
closein interfaceAutoCloseable
-