use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class AttachmentInfoExtractorTest method extractInfoForDb__withTextMimeType__shouldReturnTxtExtension.
@Test
public void extractInfoForDb__withTextMimeType__shouldReturnTxtExtension() throws Exception {
MimeBodyPart part = new MimeBodyPart();
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain");
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
// MimeUtility.getExtensionByMimeType("text/plain"); -> "txt"
assertEquals("noname.txt", attachmentViewInfo.displayName);
assertEquals("text/plain", attachmentViewInfo.mimeType);
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class AttachmentInfoExtractorTest method extractInfoForDb__withDispositionInvalidSizeParam__shouldReturnUnknownSize.
@Test
public void extractInfoForDb__withDispositionInvalidSizeParam__shouldReturnUnknownSize() throws Exception {
MimeBodyPart part = new MimeBodyPart();
part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment" + "; size=\"notanint\"");
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
assertEquals(AttachmentViewInfo.UNKNOWN_SIZE, attachmentViewInfo.size);
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class AttachmentInfoExtractorTest method extractInfoForDb__withDispositionSizeParam__shouldReturnThatSize.
@Test
public void extractInfoForDb__withDispositionSizeParam__shouldReturnThatSize() throws Exception {
MimeBodyPart part = new MimeBodyPart();
part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment" + "; size=\"" + TEST_SIZE + "\"");
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
assertEquals(TEST_SIZE, attachmentViewInfo.size);
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class PreviewTextExtractorTest method extractPreview_withEmptyBody_shouldThrow.
@Test(expected = PreviewExtractionException.class)
public void extractPreview_withEmptyBody_shouldThrow() throws Exception {
Part part = new MimeBodyPart(null, "text/plain");
previewTextExtractor.extractPreview(part);
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class MessageTest method binaryBodyPart.
private MimeBodyPart binaryBodyPart() throws IOException, MessagingException {
String encodedTestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
BinaryTempFileBody tempFileBody = new BinaryTempFileBody(MimeUtil.ENC_BASE64);
InputStream in = new ByteArrayInputStream(encodedTestString.getBytes("UTF-8"));
OutputStream out = tempFileBody.getOutputStream();
try {
IOUtils.copy(in, out);
} finally {
out.close();
}
MimeBodyPart bodyPart = new MimeBodyPart(tempFileBody, "application/octet-stream");
bodyPart.setEncoding(MimeUtil.ENC_BASE64);
return bodyPart;
}
Aggregations