use of org.apache.james.mime4j.message.MessageImpl in project Gargoyle by callakrsos.
the class MimeViewerExam method extracted.
private void extracted(StringBuilder sb, Body body) {
if (body instanceof Multipart) {
Multipart mbody = (Multipart) body;
for (Entity part : mbody.getBodyParts()) {
extracted(sb, part);
}
} else if (body instanceof MessageImpl) {
extracted(sb, body);
} else if (body instanceof TextBody) {
/*
* A text body. Display its contents.
*/
TextBody textBody = (TextBody) body;
try {
Reader r = textBody.getReader();
StringBuilder _sb = new StringBuilder();
int c;
while ((c = r.read()) != -1) {
_sb.append((char) c);
}
System.out.println(_sb.toString());
sb.append(_sb.toString());
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (body instanceof BinaryBody) {
BinaryBody bBody = (BinaryBody) body;
Entity parent = bBody.getParent();
// String dispositionType = parent.getDispositionType();
// String filename = parent.getFilename();
// String contentTransferEncoding = parent.getContentTransferEncoding();
// String mimeType = parent.getMimeType();
Field field = parent.getHeader().getField("Content-ID");
String body2 = field.getBody();
String contentId = body2.replace("<", "").replace(">", "");
StringBuffer buf = new StringBuffer();
try (InputStream is = bBody.getInputStream()) {
int read = -1;
while ((read = is.read()) != -1) {
buf.append((char) read);
}
} catch (IOException e) {
e.printStackTrace();
}
meta.put(contentId, buf.toString());
} else /*
* Ignore Fields </br>
*
* ContentTypeField,AddressListField,DateTimeField UnstructuredField,
* Field
*
*/
{
sb.append(body.toString());
}
}
use of org.apache.james.mime4j.message.MessageImpl in project sling by apache.
the class MessageStoreImplAttachmentsTest method recursiveMultipartMessageTest.
@Test
public void recursiveMultipartMessageTest() throws IOException {
Multipart multipart = new MultipartImpl("mixed");
BodyPart att1 = createRandomBinaryAttachment(100);
multipart.addBodyPart(att1);
BodyPart att2 = createRandomBinaryAttachment(133);
multipart.addBodyPart(att2);
Multipart nestedMultipart = new MultipartImpl("mixed");
BodyPart nBody = createTextBody("Some sample text here...?!", "plain", false);
nestedMultipart.addBodyPart(nBody);
BodyPart nAtt1 = createRandomBinaryAttachment(300);
nestedMultipart.addBodyPart(nAtt1);
BodyPart NAtt2 = createRandomBinaryAttachment(100);
nestedMultipart.addBodyPart(NAtt2);
BodyPart nAtt3 = createTextBody("Some other text here...<br>?!", "html", true);
nestedMultipart.addBodyPart(nAtt3);
BodyPart nestedMessage = new BodyPart();
nestedMessage.setMultipart(nestedMultipart);
multipart.addBodyPart(nestedMessage);
MessageImpl message = new MessageImpl();
message.setMultipart(multipart);
message.setSubject("Template message");
message.setDate(new Date());
message.getHeader().setField(new RawField(LIST_ID, "<list.example.com>"));
assertSaveMessageWithAttachments(message, 5);
}
use of org.apache.james.mime4j.message.MessageImpl in project sling by apache.
the class MessageStoreImplAttachmentsTest method simpleMultipartMessageTest.
@Test
public void simpleMultipartMessageTest() throws IOException {
Multipart multipart = new MultipartImpl("mixed");
BodyPart att0 = createTextBody("This is the first part of the template..", "plain", true);
multipart.addBodyPart(att0);
BodyPart att1 = createRandomBinaryAttachment(200);
multipart.addBodyPart(att1);
BodyPart att2 = createRandomBinaryAttachment(300);
multipart.addBodyPart(att2);
BodyPart att3 = createTextBody("Some sample text here...?!", "html", true);
multipart.addBodyPart(att3);
BodyPart att4 = createRandomBinaryAttachment(100);
multipart.addBodyPart(att4);
BodyPart att5 = createTextBody("Some other text here...?!", "plain", true);
multipart.addBodyPart(att5);
MessageImpl message = new MessageImpl();
message.setMultipart(multipart);
message.setSubject("Template message");
message.setDate(new Date());
message.getHeader().setField(new RawField(LIST_ID, "<list.example.com>"));
assertSaveMessageWithAttachments(message, 6);
}
Aggregations