org.apache.james.mime4j.dom.SingleBody Java Examples
The following examples show how to use
org.apache.james.mime4j.dom.SingleBody.
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: MboxReader.java From baleen with Apache License 2.0 | 5 votes |
@Override protected void doGetNext(JCas jCas) throws IOException, CollectionException { if (!attachments.isEmpty()) { // If we have attachments, first process those Map.Entry<String, Body> entry = attachments.firstEntry(); getMonitor().info("Processing attachment {}", entry.getKey()); processBody(jCas, entry.getValue(), entry.getKey()); attachments.remove(entry.getKey()); } else { // No attachments so process the next message String raw = mboxIterator.next().toString(); count++; String uri = "mbox://" + mbox + "#" + count; getMonitor().info("Processing message {}", uri); // Parse message and get body Message msg = messageBuilder.parseMessage(new ByteArrayInputStream(raw.getBytes(charset))); Body body = msg.getBody(); boolean doneBody = false; // Decide how to process body of message if (body instanceof SingleBody) { doneBody = processBody(jCas, body, uri); } else if (body instanceof Multipart) { Multipart mp = (Multipart) body; doneBody = processMultipart(jCas, mp, uri); } // No body found (just attachments? Or invalid message?) if (!doneBody) { throw new IOException("No processable body found"); } } }
Example #2
Source File: ExtractMDNOriginalJMAPMessageId.java From james-project with Apache License 2.0 | 5 votes |
private Optional<MDNReport> parseReport(Entity report) { LOGGER.debug("Parsing report"); try (InputStream inputStream = ((SingleBody) report.getBody()).getInputStream()) { Try<MDNReport> result = MDNReportParser.parse(inputStream, report.getCharset()); if (result.isSuccess()) { return Optional.of(result.get()); } else { LOGGER.error("unable to parse MESSAGE_DISPOSITION_NOTIFICATION part", result.failed().get()); return Optional.empty(); } } catch (IOException e) { LOGGER.error("unable to parse MESSAGE_DISPOSITION_NOTIFICATION part", e); return Optional.empty(); } }