org.apache.james.mime4j.stream.BodyDescriptor Java Examples
The following examples show how to use
org.apache.james.mime4j.stream.BodyDescriptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MboxHandler.java From SnowGraph with Apache License 2.0 | 6 votes |
@Override public void body(BodyDescriptor bd, InputStream is) throws MimeException, IOException { String r = ""; byte[] buffer = new byte[200]; String s; int len; try { while ((len = is.read(buffer)) != -1) { if (len != 200) { byte buffer2[] = new byte[len]; System.arraycopy(buffer, 0, buffer2, 0, len); s = new String(buffer2); } else { s = new String(buffer); } if (s != null) r += s; } } catch (Exception e) { e.printStackTrace(); } mailInfo.body = r; //System.out.println("body"); //System.out.println(r); }
Example #2
Source File: MessageContentExtractorTest.java From holdmail with Apache License 2.0 | 6 votes |
@Test public void shouldSetSequenceWithEachNewPart() throws Exception{ BodyDescriptor bodyMock = mock(BodyDescriptor.class); ByteArrayInputStream streamMock = new ByteArrayInputStream(new byte[] {}); MessageContentExtractor extractor = new MessageContentExtractor(); extractor.startHeader(); extractor.body(bodyMock, streamMock); assertThat(getCurrentSequence(extractor)).containsExactly(1); extractor.startHeader(); extractor.body(bodyMock, streamMock); assertThat(getCurrentSequence(extractor)).containsExactly(1, 2); extractor.startHeader(); extractor.body(bodyMock, streamMock); assertThat(getCurrentSequence(extractor)).containsExactly(1, 2, 3); }
Example #3
Source File: Common.java From email-mime-parser with Apache License 2.0 | 6 votes |
public static String getAttachmentNameFromDispositionParameters(BodyDescriptor bd) { //Refer RFC : 2047 for mime word decoding //Refer RFC : 2183 for Content-Disposition Header Field String attachmentName = null; if (bd instanceof MaximalBodyDescriptor) { attachmentName = getDecodedWord(((MaximalBodyDescriptor) bd).getContentDispositionFilename()); if (StringUtils.isEmpty(attachmentName)) { //Handling case where RFC 2183 is not properly implemented by tech.blueglacier.email creating client. attachmentName = getDecodedWord(((MaximalBodyDescriptor) bd).getContentDispositionParameters().get("name")); } //Added case for supporting RFC 2184 'Parameter Value Character Set and Language Information' // this is currently not supported in mime4j (version 0.7.2) if (StringUtils.isEmpty(attachmentName)) { attachmentName = getDecodedDispositionFileName(bd); } } return attachmentName; }
Example #4
Source File: AutomaticallySentMailDetectorImpl.java From james-project with Apache License 2.0 | 5 votes |
private AbstractContentHandler createMdnContentHandler(final ResultCollector resultCollector) { return new AbstractContentHandler() { @Override public void body(BodyDescriptor bodyDescriptor, InputStream inputStream) throws MimeException, IOException { if (bodyDescriptor.getMimeType().equalsIgnoreCase("message/disposition-notification")) { resultCollector.setResult(MDNReportParser.parse(inputStream, bodyDescriptor.getCharset()) .map(report -> report.getDispositionField().getSendingMode() == DispositionSendingMode.Automatic) .getOrElse(() -> false)); } } }; }
Example #5
Source File: Email.java From email-mime-parser with Apache License 2.0 | 5 votes |
public void fillEmailContents(BodyDescriptor bd, InputStream is){ LOGGER.info("mime part received"); if(addPlainTextEmailBody(bd,is)){} else if(addHTMLEmailBody(bd,is)){} else if(addCalendar(bd,is)){} else{ addAttachments(bd,is); } }
Example #6
Source File: Email.java From email-mime-parser with Apache License 2.0 | 5 votes |
private boolean addCalendar(BodyDescriptor bd, InputStream is) { boolean isBodySet = false; BodyDescriptor calendarBodyDescriptor = bd; if(calendarBody == null){ if(isCalendarBody(calendarBodyDescriptor)){ calendarBody = new CalendarBody(bd,is); isBodySet = true; LOGGER.info("Email calendar body identified"); } } return isBodySet; }
Example #7
Source File: Common.java From email-mime-parser with Apache License 2.0 | 5 votes |
public static String getAttachmentName(BodyDescriptor bd){ // Content tech.blueglacier.disposition 'filename' is more standard, so it's taken as default first String attachmentName = Common.getAttachmentNameFromDispositionParameters(bd); if(attachmentName == null || attachmentName.isEmpty()){ // Content type 'name' is other alternative so it's taken as alternative too attachmentName = Common.getAttachmentNameFromContentTypeParmaeters(bd); } return attachmentName; }
Example #8
Source File: Email.java From email-mime-parser with Apache License 2.0 | 5 votes |
private boolean addHTMLEmailBody(BodyDescriptor bd, InputStream is) { boolean isBodySet = false; BodyDescriptor emailHTMLBodyDescriptor = bd; if(htmlEmailBody == null){ if(isHTMLBody(emailHTMLBodyDescriptor)){ htmlEmailBody = new HtmlEmailBody(bd,is); isBodySet = true; LOGGER.info("Email html body identified"); } }else{ if(isHTMLBody(emailHTMLBodyDescriptor)){ if(multipartStack.peek().getBodyDescriptor().getMimeType().equalsIgnoreCase("multipart/mixed")){ InputStream mainInputStream; try { mainInputStream = concatInputStream(is, htmlEmailBody.getIs()); } catch (IOException e) { throw new RuntimeException(e); } htmlEmailBody.setIs(mainInputStream); }else{ addAttachments(new HtmlEmailBody(bd,is)); } isBodySet = true; } } return isBodySet; }
Example #9
Source File: Common.java From email-mime-parser with Apache License 2.0 | 5 votes |
public static String getAttachmentNameFromContentTypeParmaeters(BodyDescriptor bd) { String attachmentName = null; if(bd instanceof MaximalBodyDescriptor){ Map<String, String> contentTypeParameters = ((MaximalBodyDescriptor)bd).getContentTypeParameters(); String nameKey = null; if(contentTypeParameters.containsKey(nameKey = "name") || contentTypeParameters.containsKey(nameKey = "NAME") || contentTypeParameters.containsKey(nameKey = "Name")){ attachmentName = contentTypeParameters.get(nameKey); } attachmentName = getDecodedWord(attachmentName); } return attachmentName; }
Example #10
Source File: Common.java From email-mime-parser with Apache License 2.0 | 5 votes |
private static String getDecodedDispositionFileName(BodyDescriptor bd){ String attachmentName = null; try { attachmentName = ContentDispositionDecoder.decodeDispositionFileName(((MaximalBodyDescriptor)bd).getContentDispositionParameters()); } catch (MimeException e) { throw new RuntimeException(e); } return attachmentName; }
Example #11
Source File: Email.java From email-mime-parser with Apache License 2.0 | 5 votes |
private boolean addPlainTextEmailBody(BodyDescriptor bd, InputStream is) { boolean isBodySet = false; BodyDescriptor emailPlainBodyDescriptor = bd; if(plainTextEmailBody == null){ if(isPlainTextBody(emailPlainBodyDescriptor)){ plainTextEmailBody = new PlainTextEmailBody(bd,is); isBodySet = true; LOGGER.info("Email plain text body identified"); } }else{ if(isPlainTextBody(emailPlainBodyDescriptor)){ if(multipartStack.peek().getBodyDescriptor().getMimeType().equalsIgnoreCase("multipart/mixed")){ InputStream mainInputStream; try { mainInputStream = concatInputStream(is,plainTextEmailBody.getIs()); } catch (IOException e) { throw new RuntimeException(e); } plainTextEmailBody.setIs(mainInputStream); }else{ addAttachments(new PlainTextEmailBody(bd,is)); } isBodySet = true; } } return isBodySet; }
Example #12
Source File: CustomContentHandler.java From email-mime-parser with Apache License 2.0 | 5 votes |
@Override public void body(BodyDescriptor bd, InputStream is) throws MimeException, IOException { // Gracefully switching off the case of email attached within an email if (email.getMessageStack().peek().getEmailMessageTypeHierarchy() == EmailMessageTypeHierarchy.parent) { email.fillEmailContents(bd, is); } }
Example #13
Source File: Attachment.java From email-mime-parser with Apache License 2.0 | 4 votes |
public BodyDescriptor getBd() { return bd; }
Example #14
Source File: MboxHandler.java From SnowGraph with Apache License 2.0 | 4 votes |
@Override public void startMultipart(BodyDescriptor bd) throws MimeException { }
Example #15
Source File: CustomContentHandler.java From email-mime-parser with Apache License 2.0 | 4 votes |
public void startMultipart(BodyDescriptor bd) throws MimeException { email.getMultipartStack().push(new MultipartType(bd)); }
Example #16
Source File: HtmlEmailBody.java From email-mime-parser with Apache License 2.0 | 4 votes |
public HtmlEmailBody(BodyDescriptor bd, InputStream is) { super(bd, is); }
Example #17
Source File: Attachment.java From email-mime-parser with Apache License 2.0 | 4 votes |
public Attachment(BodyDescriptor bd, InputStream is) { this.bd = bd; attachmentSize = 0; setIs(is); }
Example #18
Source File: EmailAttachment.java From email-mime-parser with Apache License 2.0 | 4 votes |
public EmailAttachment(BodyDescriptor bd, InputStream is){ super(bd, is); }
Example #19
Source File: Email.java From email-mime-parser with Apache License 2.0 | 4 votes |
private boolean isPlainTextBody(BodyDescriptor emailPlainBodyDescriptor) { String bodyName = Common.getAttachmentName(emailPlainBodyDescriptor); return (emailPlainBodyDescriptor.getMimeType().equalsIgnoreCase("text/plain") && bodyName == null); }
Example #20
Source File: Email.java From email-mime-parser with Apache License 2.0 | 4 votes |
private boolean isCalendarBody(BodyDescriptor emailCalendarBodyDescriptor) { String bodyName = Common.getAttachmentName(emailCalendarBodyDescriptor); return (emailCalendarBodyDescriptor.getMimeType().equalsIgnoreCase("text/calendar") && bodyName == null); }
Example #21
Source File: Email.java From email-mime-parser with Apache License 2.0 | 4 votes |
private boolean isHTMLBody(BodyDescriptor emailHTMLBodyDescriptor) { String bodyName = Common.getAttachmentName(emailHTMLBodyDescriptor); return (emailHTMLBodyDescriptor.getMimeType().equalsIgnoreCase("text/html") && bodyName == null); }
Example #22
Source File: Email.java From email-mime-parser with Apache License 2.0 | 4 votes |
private void addAttachments(BodyDescriptor bd, InputStream is) { attachments.add(new EmailAttachment(bd,is)); LOGGER.info("Email attachment identified"); }
Example #23
Source File: CalendarBody.java From email-mime-parser with Apache License 2.0 | 4 votes |
public CalendarBody(BodyDescriptor bd, InputStream is) { super(bd, is); }
Example #24
Source File: MultipartType.java From email-mime-parser with Apache License 2.0 | 4 votes |
public BodyDescriptor getBodyDescriptor() { return bodyDiscriptor; }
Example #25
Source File: MultipartType.java From email-mime-parser with Apache License 2.0 | 4 votes |
public MultipartType(BodyDescriptor bodyDescriptor){ this.bodyDiscriptor = bodyDescriptor; }
Example #26
Source File: PlainTextEmailBody.java From email-mime-parser with Apache License 2.0 | 4 votes |
public PlainTextEmailBody(BodyDescriptor bd, InputStream is) { super(bd, is); }
Example #27
Source File: MessageContentExtractor.java From holdmail with Apache License 2.0 | 3 votes |
@Override public void body(BodyDescriptor bd, InputStream is) throws IOException { nextPotentialPart.setContent(is); bodyParts.addPart(nextPotentialPart); }