Class EmailIdleMonitor

java.lang.Object
cloud.opencode.base.email.listener.EmailIdleMonitor
All Implemented Interfaces:
AutoCloseable

public class EmailIdleMonitor extends Object implements AutoCloseable
Email IDLE Monitor 邮件IDLE监控器

Monitors mailbox for new emails using IMAP IDLE command.

使用IMAP IDLE命令监控邮箱中的新邮件。

Features | 主要功能:

  • Real-time email notification - 实时邮件通知
  • IMAP IDLE support - IMAP IDLE支持
  • Automatic reconnection - 自动重连
  • Multiple listener support - 多监听器支持
  • Folder monitoring - 文件夹监控

Note | 注意:

IDLE is only supported by IMAP protocol. POP3 does not support real-time notifications.

IDLE仅IMAP协议支持。POP3不支持实时通知。

Usage Examples | 使用示例:

EmailIdleMonitor monitor = EmailIdleMonitor.builder()
    .config(config)
    .folder("INBOX")
    .listener(email -> {
        System.out.println("New email: " + email.subject());
    })
    .build();

monitor.start();
// ... application runs ...
monitor.stop();

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
Since:
JDK 25, opencode-base-email V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • builder

      public static EmailIdleMonitor.Builder builder()
      Create a new builder 创建新的构建器
      Returns:
      the builder | 构建器
    • start

      public void start()
      Start monitoring for new emails 开始监控新邮件
    • stop

      public void stop()
      Stop monitoring 停止监控
    • isRunning

      public boolean isRunning()
      Check if monitoring is running 检查是否正在监控
      Returns:
      true if running | 正在运行返回true
    • addListener

      public void addListener(EmailListener listener)
      Add a listener 添加监听器
      Parameters:
      listener - the listener to add | 要添加的监听器
    • removeListener

      public void removeListener(EmailListener listener)
      Remove a listener 移除监听器
      Parameters:
      listener - the listener to remove | 要移除的监听器
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable