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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for ReceivedEmail ReceivedEmail构建器 -
Constructor Summary
ConstructorsConstructorDescriptionReceivedEmail(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 aReceivedEmailrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theattachmentsrecord component.bcc()Returns the value of thebccrecord component.static ReceivedEmail.Builderbuilder()Create a new builder 创建新的构建器cc()Returns the value of theccrecord component.final booleanIndicates whether some other object is "equal to" this one.flags()Returns the value of theflagsrecord component.folder()Returns the value of thefolderrecord component.from()Returns the value of thefromrecord component.fromName()Returns the value of thefromNamerecord component.Get all recipients (to + cc + bcc) 获取所有收件人intGet attachment count 获取附件数量Get the best available content (prefer HTML) 获取最佳可用内容(优先HTML)Get header value by name 根据名称获取邮件头值Get the best available content (prefer text) 获取最佳可用内容(优先文本)booleanCheck if email has attachments 检查邮件是否有附件final inthashCode()Returns a hash code value for this object.booleanCheck if email has HTML content 检查邮件是否有HTML内容booleanCheck if email has text content 检查邮件是否有文本内容headers()Returns the value of theheadersrecord component.Returns the value of thehtmlContentrecord component.booleanCheck if email has been answered 检查邮件是否已回复booleanCheck if email is flagged/starred 检查邮件是否已标记/星标booleanisUnread()Check if email is unread 检查邮件是否未读Returns the value of themessageIdrecord component.intReturns the value of themessageNumberrecord component.Returns the value of thereceivedDaterecord component.replyTo()Returns the value of thereplyTorecord component.sentDate()Returns the value of thesentDaterecord component.longsize()Returns the value of thesizerecord component.subject()Returns the value of thesubjectrecord component.Returns the value of thetextContentrecord component.to()Returns the value of thetorecord component.final StringtoString()Returns a string representation of this record class.
-
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 aReceivedEmailrecord class.- Parameters:
messageId- the value for themessageIdrecord componentfrom- the value for thefromrecord componentfromName- the value for thefromNamerecord componentto- the value for thetorecord componentcc- the value for theccrecord componentbcc- the value for thebccrecord componentreplyTo- the value for thereplyTorecord componentsubject- the value for thesubjectrecord componenttextContent- the value for thetextContentrecord componenthtmlContent- the value for thehtmlContentrecord componentsentDate- the value for thesentDaterecord componentreceivedDate- the value for thereceivedDaterecord componentattachments- the value for theattachmentsrecord componentheaders- the value for theheadersrecord componentflags- the value for theflagsrecord componentfolder- the value for thefolderrecord componentmessageNumber- the value for themessageNumberrecord componentsize- the value for thesizerecord 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
Get the best available content (prefer HTML) 获取最佳可用内容(优先HTML)- Returns:
- HTML content if available, otherwise text content | HTML内容(如果可用),否则返回文本内容
-
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
-
getAllRecipients
-
builder
Create a new builder 创建新的构建器- Returns:
- the builder | 构建器
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
messageId
Returns the value of themessageIdrecord component.- Returns:
- the value of the
messageIdrecord component
-
from
Returns the value of thefromrecord component.- Returns:
- the value of the
fromrecord component
-
fromName
Returns the value of thefromNamerecord component.- Returns:
- the value of the
fromNamerecord component
-
to
-
cc
-
bcc
-
replyTo
Returns the value of thereplyTorecord component.- Returns:
- the value of the
replyTorecord component
-
subject
Returns the value of thesubjectrecord component.- Returns:
- the value of the
subjectrecord component
-
textContent
Returns the value of thetextContentrecord component.- Returns:
- the value of the
textContentrecord component
-
htmlContent
Returns the value of thehtmlContentrecord component.- Returns:
- the value of the
htmlContentrecord component
-
sentDate
Returns the value of thesentDaterecord component.- Returns:
- the value of the
sentDaterecord component
-
receivedDate
Returns the value of thereceivedDaterecord component.- Returns:
- the value of the
receivedDaterecord component
-
attachments
Returns the value of theattachmentsrecord component.- Returns:
- the value of the
attachmentsrecord component
-
headers
-
flags
Returns the value of theflagsrecord component.- Returns:
- the value of the
flagsrecord component
-
folder
Returns the value of thefolderrecord component.- Returns:
- the value of the
folderrecord component
-
messageNumber
public int messageNumber()Returns the value of themessageNumberrecord component.- Returns:
- the value of the
messageNumberrecord component
-
size
public long size()Returns the value of thesizerecord component.- Returns:
- the value of the
sizerecord component
-