Gmail から添付ファイル付きのメールをダウンロードしようとすると、テスト メールに添付ファイルとしてテキスト ファイルが含まれます。
添付ファイルの部分は、テキスト添付ファイルのコンテンツ タイプと、ファイル名さえも正しく返します。ただし、アタッチメント InputStream のループ条件が非ゼロになることはありません。
少し試行錯誤した後、テキスト/プレーンのコンテンツは、パーツの getContent メソッドを使用して利用できることがわかりました (以下の例では、呼び出しを導入しています)。
att_mbp.getContent()
添付のテキスト ファイルの内容を返します)
if (BodyPart.ATTACHMENT.equalsIgnoreCase(att_mbp.getDisposition())) {
att_mbp.getContentType();
// process each attachment
// read the filename
file = att_mbp.getFileName();
InputStream stream = att_mbp.getInputStream();
BufferedInputStream br = new BufferedInputStream(stream);
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(file));
while (br.available() > 0) {
// this loop is never executed for text/plain
bout.write(br.read());
}
bout.flush();
bout.close();
}
私の質問は - テキスト/プレーンの添付ファイルの本文が getContent() からのみ利用可能であり、添付された InputStream インスタンスからも利用できないのはなぜですか?