IMAP を使用したメッセージ添付ファイルの操作
Contents
[
Hide
]
IMAP クライアントを使用したメッセージ添付ファイルの一覧表示
添付ファイルの名前やサイズなどの情報を、添付データを取得せずに取得するには、以下の API 機能を使用します:
- ImapAttachmentInfo - 添付情報を表します。
- ImapAttachmentInfoCollection - ImapAttachmentInfo のコレクションを表します。
- listAttachments(int sequenceNumber) - メッセージ内の各添付ファイルの情報を取得します。
以下のコードサンプルは、IMAP クライアントを使用してサーバーからメールメッセージとその添付ファイルの情報を取得し、各メッセージの添付ファイル詳細を表示する方法を示します。IMAP プロトコルを使用してメールメッセージの添付ファイルにアクセスし、処理することができます。
ImapMessageInfoCollection messageInfoCollection = imapClient.listMessages();
for (ImapMessageInfo message : messageInfoCollection) {
ImapAttachmentInfoCollection attachmentInfoCollection =
imapClient.listAttachments(message.getSequenceNumber());
for (ImapAttachmentInfo attachmentInfo : attachmentInfoCollection) {
System.out.println(
"Attachment: " + attachmentInfo.getName() + " (size: " + attachmentInfo.getSize() + ")");
}
}