Record Class EmailReceiveConfig

java.lang.Object
java.lang.Record
cloud.opencode.base.email.EmailReceiveConfig

public record EmailReceiveConfig(String host, int port, String username, String password, String oauth2Token, EmailReceiveConfig.Protocol protocol, boolean ssl, boolean starttls, Duration timeout, Duration connectionTimeout, String defaultFolder, int maxMessages, boolean deleteAfterReceive, boolean markAsReadAfterReceive, boolean debug) extends Record
Email Receive Configuration Record 邮件接收配置记录

Immutable configuration for IMAP/POP3 email receiving.

用于IMAP/POP3邮件接收的不可变配置。

Features | 主要功能:

  • IMAP/POP3 protocol support - IMAP/POP3协议支持
  • SSL/TLS configuration - SSL/TLS配置
  • Connection pool settings - 连接池设置
  • Timeout configuration - 超时配置
  • Folder preferences - 文件夹偏好设置

Usage Examples | 使用示例:

// IMAP configuration
EmailReceiveConfig config = EmailReceiveConfig.builder()
    .host("imap.example.com")
    .username("user@example.com")
    .password("password")
    .imap()
    .ssl(true)
    .build();

// POP3 configuration
EmailReceiveConfig config = EmailReceiveConfig.builder()
    .host("pop3.example.com")
    .port(995)
    .username("user")
    .password("pass")
    .pop3()
    .ssl(true)
    .build();

// OAuth2 configuration (Gmail/Outlook)
EmailReceiveConfig config = EmailReceiveConfig.builder()
    .host("imap.gmail.com")
    .username("user@gmail.com")
    .oauth2Token(accessToken)
    .imap()
    .ssl(true)
    .build();

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-email V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Email Receive Configuration Builder 邮件接收配置构建器
    static enum 
    Email receiving protocol 邮件接收协议
  • Constructor Summary

    Constructors
    Constructor
    Description
    EmailReceiveConfig(String host, int port, String username, String password, String oauth2Token, EmailReceiveConfig.Protocol protocol, boolean ssl, boolean starttls, Duration timeout, Duration connectionTimeout, String defaultFolder, int maxMessages, boolean deleteAfterReceive, boolean markAsReadAfterReceive, boolean debug)
    Creates an instance of a EmailReceiveConfig record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Create a new builder 创建新的构建器
    Returns the value of the connectionTimeout record component.
    boolean
    Returns the value of the debug record component.
    Returns the value of the defaultFolder record component.
    boolean
    Returns the value of the deleteAfterReceive record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Get the store protocol name for Jakarta Mail 获取Jakarta Mail的存储协议名称
    final int
    Returns a hash code value for this object.
    boolean
    Check if OAuth2 authentication is configured 检查是否配置了OAuth2认证
    Returns the value of the host record component.
    boolean
    Check if IMAP protocol is used 检查是否使用IMAP协议
    boolean
    Check if POP3 protocol is used 检查是否使用POP3协议
    boolean
    Returns the value of the markAsReadAfterReceive record component.
    int
    Returns the value of the maxMessages record component.
    Returns the value of the oauth2Token record component.
    Returns the value of the password record component.
    int
    Returns the value of the port record component.
    Returns the value of the protocol record component.
    boolean
    Check if authentication is required 检查是否需要认证
    boolean
    ssl()
    Returns the value of the ssl record component.
    boolean
    Returns the value of the starttls record component.
    Returns the value of the timeout record component.
    Return string representation with masked sensitive fields 返回屏蔽敏感字段的字符串表示
    Returns the value of the username record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • EmailReceiveConfig

      public EmailReceiveConfig(String host, int port, String username, String password, String oauth2Token, EmailReceiveConfig.Protocol protocol, boolean ssl, boolean starttls, Duration timeout, Duration connectionTimeout, String defaultFolder, int maxMessages, boolean deleteAfterReceive, boolean markAsReadAfterReceive, boolean debug)
      Creates an instance of a EmailReceiveConfig record class.
      Parameters:
      host - the value for the host record component
      port - the value for the port record component
      username - the value for the username record component
      password - the value for the password record component
      oauth2Token - the value for the oauth2Token record component
      protocol - the value for the protocol record component
      ssl - the value for the ssl record component
      starttls - the value for the starttls record component
      timeout - the value for the timeout record component
      connectionTimeout - the value for the connectionTimeout record component
      defaultFolder - the value for the defaultFolder record component
      maxMessages - the value for the maxMessages record component
      deleteAfterReceive - the value for the deleteAfterReceive record component
      markAsReadAfterReceive - the value for the markAsReadAfterReceive record component
      debug - the value for the debug record component
  • Method Details

    • builder

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

      public boolean requiresAuth()
      Check if authentication is required 检查是否需要认证
      Returns:
      true if authentication is required | 需要认证返回true
    • hasOAuth2

      public boolean hasOAuth2()
      Check if OAuth2 authentication is configured 检查是否配置了OAuth2认证
      Returns:
      true if OAuth2 is configured | 配置了OAuth2返回true
    • getStoreProtocol

      public String getStoreProtocol()
      Get the store protocol name for Jakarta Mail 获取Jakarta Mail的存储协议名称
      Returns:
      the store protocol name | 存储协议名称
    • isImap

      public boolean isImap()
      Check if IMAP protocol is used 检查是否使用IMAP协议
      Returns:
      true if using IMAP | 使用IMAP返回true
    • isPop3

      public boolean isPop3()
      Check if POP3 protocol is used 检查是否使用POP3协议
      Returns:
      true if using POP3 | 使用POP3返回true
    • toString

      public String toString()
      Return string representation with masked sensitive fields 返回屏蔽敏感字段的字符串表示

      Passwords and OAuth2 tokens are masked to prevent accidental exposure in logs.

      密码和OAuth2令牌被屏蔽以防止在日志中意外暴露。

      Specified by:
      toString in class Record
      Returns:
      the masked string representation | 屏蔽后的字符串表示
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • host

      public String host()
      Returns the value of the host record component.
      Returns:
      the value of the host record component
    • port

      public int port()
      Returns the value of the port record component.
      Returns:
      the value of the port record component
    • username

      public String username()
      Returns the value of the username record component.
      Returns:
      the value of the username record component
    • password

      public String password()
      Returns the value of the password record component.
      Returns:
      the value of the password record component
    • oauth2Token

      public String oauth2Token()
      Returns the value of the oauth2Token record component.
      Returns:
      the value of the oauth2Token record component
    • protocol

      public EmailReceiveConfig.Protocol protocol()
      Returns the value of the protocol record component.
      Returns:
      the value of the protocol record component
    • ssl

      public boolean ssl()
      Returns the value of the ssl record component.
      Returns:
      the value of the ssl record component
    • starttls

      public boolean starttls()
      Returns the value of the starttls record component.
      Returns:
      the value of the starttls record component
    • timeout

      public Duration timeout()
      Returns the value of the timeout record component.
      Returns:
      the value of the timeout record component
    • connectionTimeout

      public Duration connectionTimeout()
      Returns the value of the connectionTimeout record component.
      Returns:
      the value of the connectionTimeout record component
    • defaultFolder

      public String defaultFolder()
      Returns the value of the defaultFolder record component.
      Returns:
      the value of the defaultFolder record component
    • maxMessages

      public int maxMessages()
      Returns the value of the maxMessages record component.
      Returns:
      the value of the maxMessages record component
    • deleteAfterReceive

      public boolean deleteAfterReceive()
      Returns the value of the deleteAfterReceive record component.
      Returns:
      the value of the deleteAfterReceive record component
    • markAsReadAfterReceive

      public boolean markAsReadAfterReceive()
      Returns the value of the markAsReadAfterReceive record component.
      Returns:
      the value of the markAsReadAfterReceive record component
    • debug

      public boolean debug()
      Returns the value of the debug record component.
      Returns:
      the value of the debug record component