Record Class ReceivedEmail

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

public record ReceivedEmail(String messageId, String from, String fromName, List<String> to, List<String> cc, List<String> bcc, String replyTo, String subject, String textContent, String htmlContent, Instant sentDate, Instant receivedDate, List<Attachment> attachments, Map<String,String> headers, EmailFlags flags, String folder, int messageNumber, long size) extends Record
Received Email Record 接收的邮件记录

Immutable record representing an email received via IMAP/POP3.

表示通过IMAP/POP3接收的邮件的不可变记录。

Features | 主要功能:

  • Full email content (text and HTML) - 完整邮件内容(文本和HTML)
  • Attachment support - 附件支持
  • Email flags (read, answered, etc.) - 邮件标记(已读、已回复等)
  • Header access - 邮件头访问
  • Folder information - 文件夹信息

Usage Examples | 使用示例:

// Process received emails
List<ReceivedEmail> emails = OpenEmail.receiveUnread();
for (ReceivedEmail email : emails) {
    System.out.println("From: " + email.from());
    System.out.println("Subject: " + email.subject());

    if (email.hasAttachments()) {
        for (Attachment att : email.attachments()) {
            saveAttachment(att);
        }
    }
}

Security | 安全性:

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

    • ReceivedEmail

      public ReceivedEmail(String messageId, String from, String fromName, List<String> to, List<String> cc, List<String> bcc, String replyTo, String subject, String textContent, String htmlContent, Instant sentDate, Instant receivedDate, List<Attachment> attachments, Map<String,String> headers, EmailFlags flags, String folder, int messageNumber, long size)
      Creates an instance of a ReceivedEmail record class.
      Parameters:
      messageId - the value for the messageId record component
      from - the value for the from record component
      fromName - the value for the fromName record component
      to - the value for the to record component
      cc - the value for the cc record component
      bcc - the value for the bcc record component
      replyTo - the value for the replyTo record component
      subject - the value for the subject record component
      textContent - the value for the textContent record component
      htmlContent - the value for the htmlContent record component
      sentDate - the value for the sentDate record component
      receivedDate - the value for the receivedDate record component
      attachments - the value for the attachments record component
      headers - the value for the headers record component
      flags - the value for the flags record component
      folder - the value for the folder record component
      messageNumber - the value for the messageNumber record component
      size - the value for the size record component
  • Method Details

    • hasTextContent

      public boolean hasTextContent()
      Check if email has text content 检查邮件是否有文本内容
      Returns:
      true if has text content | 有文本内容返回true
    • hasHtmlContent

      public boolean hasHtmlContent()
      Check if email has HTML content 检查邮件是否有HTML内容
      Returns:
      true if has HTML content | 有HTML内容返回true
    • getContent

      public String getContent()
      Get the best available content (prefer HTML) 获取最佳可用内容(优先HTML)
      Returns:
      HTML content if available, otherwise text content | HTML内容(如果可用),否则返回文本内容
    • getTextOrHtmlContent

      public String getTextOrHtmlContent()
      Get the best available content (prefer text) 获取最佳可用内容(优先文本)
      Returns:
      text content if available, otherwise HTML content | 文本内容(如果可用),否则返回HTML内容
    • hasAttachments

      public boolean hasAttachments()
      Check if email has attachments 检查邮件是否有附件
      Returns:
      true if has attachments | 有附件返回true
    • getAttachmentCount

      public int getAttachmentCount()
      Get attachment count 获取附件数量
      Returns:
      the attachment count | 附件数量
    • isUnread

      public boolean isUnread()
      Check if email is unread 检查邮件是否未读
      Returns:
      true if unread | 未读返回true
    • isFlagged

      public boolean isFlagged()
      Check if email is flagged/starred 检查邮件是否已标记/星标
      Returns:
      true if flagged | 已标记返回true
    • isAnswered

      public boolean isAnswered()
      Check if email has been answered 检查邮件是否已回复
      Returns:
      true if answered | 已回复返回true
    • getHeader

      public String getHeader(String name)
      Get header value by name 根据名称获取邮件头值
      Parameters:
      name - the header name | 邮件头名称
      Returns:
      the header value or null | 邮件头值或null
    • getAllRecipients

      public List<String> getAllRecipients()
      Get all recipients (to + cc + bcc) 获取所有收件人
      Returns:
      all recipient addresses | 所有收件人地址
    • builder

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

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
    • messageId

      public String messageId()
      Returns the value of the messageId record component.
      Returns:
      the value of the messageId record component
    • from

      public String from()
      Returns the value of the from record component.
      Returns:
      the value of the from record component
    • fromName

      public String fromName()
      Returns the value of the fromName record component.
      Returns:
      the value of the fromName record component
    • to

      public List<String> to()
      Returns the value of the to record component.
      Returns:
      the value of the to record component
    • cc

      public List<String> cc()
      Returns the value of the cc record component.
      Returns:
      the value of the cc record component
    • bcc

      public List<String> bcc()
      Returns the value of the bcc record component.
      Returns:
      the value of the bcc record component
    • replyTo

      public String replyTo()
      Returns the value of the replyTo record component.
      Returns:
      the value of the replyTo record component
    • subject

      public String subject()
      Returns the value of the subject record component.
      Returns:
      the value of the subject record component
    • textContent

      public String textContent()
      Returns the value of the textContent record component.
      Returns:
      the value of the textContent record component
    • htmlContent

      public String htmlContent()
      Returns the value of the htmlContent record component.
      Returns:
      the value of the htmlContent record component
    • sentDate

      public Instant sentDate()
      Returns the value of the sentDate record component.
      Returns:
      the value of the sentDate record component
    • receivedDate

      public Instant receivedDate()
      Returns the value of the receivedDate record component.
      Returns:
      the value of the receivedDate record component
    • attachments

      public List<Attachment> attachments()
      Returns the value of the attachments record component.
      Returns:
      the value of the attachments record component
    • headers

      public Map<String,String> headers()
      Returns the value of the headers record component.
      Returns:
      the value of the headers record component
    • flags

      public EmailFlags flags()
      Returns the value of the flags record component.
      Returns:
      the value of the flags record component
    • folder

      public String folder()
      Returns the value of the folder record component.
      Returns:
      the value of the folder record component
    • messageNumber

      public int messageNumber()
      Returns the value of the messageNumber record component.
      Returns:
      the value of the messageNumber record component
    • size

      public long size()
      Returns the value of the size record component.
      Returns:
      the value of the size record component