Java Code Examples for org.apache.james.mime4j.message.DefaultMessageBuilder#setMimeEntityConfig()

The following examples show how to use org.apache.james.mime4j.message.DefaultMessageBuilder#setMimeEntityConfig() . 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: MessageParser.java    From james-project with Apache License 2.0 6 votes vote down vote up
public List<ParsedAttachment> retrieveAttachments(InputStream fullContent) throws IOException {
    DefaultMessageBuilder defaultMessageBuilder = new DefaultMessageBuilder();
    defaultMessageBuilder.setMimeEntityConfig(MimeConfig.PERMISSIVE);
    defaultMessageBuilder.setDecodeMonitor(DecodeMonitor.SILENT);
    Message message = defaultMessageBuilder.parseMessage(fullContent);
    Body body = message.getBody();
    try {
        if (isAttachment(message, Context.BODY)) {
            return ImmutableList.of(retrieveAttachment(message));
        }

        if (body instanceof Multipart) {
            Multipart multipartBody = (Multipart) body;
            return listAttachments(multipartBody, Context.fromSubType(multipartBody.getSubType()))
                .collect(Guavate.toImmutableList());
        } else {
            return ImmutableList.of();
        }
    } finally {
        body.dispose();
    }
}
 
Example 2
Source File: MboxReader.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
protected void doInitialize(UimaContext context) throws ResourceInitializationException {

  // Initialise charset for MBOX processing
  try {
    charset = Charset.forName(charsetName);
  } catch (UnsupportedCharsetException | IllegalCharsetNameException ce) {
    getMonitor().warn("Unsupported charset, {}. UTF-8 will be used.", charsetName, ce);
    charset = StandardCharsets.UTF_8;
  }

  // Initialise MBOX iterator
  try {
    mboxIterator =
        MboxIterator.fromFile(mbox)
            .charset(charset)
            .maxMessageSize(messageSize)
            .build()
            .iterator();
  } catch (IOException ioe) {
    throw new ResourceInitializationException(ioe);
  }

  // Initialise message parser
  messageBuilder = new DefaultMessageBuilder();
  messageBuilder.setContentDecoding(true);

  MimeConfig config = new MimeConfig.Builder().setMaxLineLen(10000).build();
  messageBuilder.setMimeEntityConfig(config);

  // Build list of extensions to ignore
  for (String s : ignoreExtensions) {
    ignoreExtensionsList.add(s.trim().toLowerCase());
  }
}
 
Example 3
Source File: DeletedMessageConverter.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Optional<Message> parseMessage(org.apache.james.mailbox.store.mail.model.Message message) throws IOException {
    DefaultMessageBuilder messageBuilder = new DefaultMessageBuilder();
    messageBuilder.setMimeEntityConfig(MimeConfig.PERMISSIVE);
    messageBuilder.setDecodeMonitor(DecodeMonitor.SILENT);
    try {
        return Optional.ofNullable(messageBuilder.parseMessage(message.getFullContent()));
    } catch (MimeIOException e) {
        LOGGER.warn("Can not parse the message {}", message.getMessageId(), e);
        return Optional.empty();
    }
}
 
Example 4
Source File: MessageSearches.java    From james-project with Apache License 2.0 5 votes vote down vote up
private HeaderImpl buildTextHeaders(MailboxMessage message) throws IOException, MimeIOException {
    DefaultMessageBuilder defaultMessageBuilder = new DefaultMessageBuilder();
    defaultMessageBuilder.setMimeEntityConfig(MimeConfig.PERMISSIVE);
    Message headersMessage = defaultMessageBuilder
        .parseMessage(message.getHeaderContent());
    HeaderImpl headerImpl = new HeaderImpl();
    addFrom(headerImpl, headersMessage.getFrom());
    addAddressList(headerImpl, headersMessage.getTo());
    addAddressList(headerImpl, headersMessage.getCc());
    addAddressList(headerImpl, headersMessage.getBcc());
    headerImpl.addField(Fields.subject(headersMessage.getSubject()));
    return headerImpl;
}
 
Example 5
Source File: SendMDNProcessor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Message retrieveOriginalMessage(JmapMDN mdn, MailboxSession mailboxSession) throws MailboxException, IOException, MessageNotFoundException {
    List<MessageResult> messages = messageIdManager.getMessage(mdn.getMessageId(), FetchGroup.HEADERS, mailboxSession);

    if (messages.size() == 0) {
        throw new MessageNotFoundException();
    }

    DefaultMessageBuilder messageBuilder = new DefaultMessageBuilder();
    messageBuilder.setMimeEntityConfig(MimeConfig.PERMISSIVE);
    messageBuilder.setDecodeMonitor(DecodeMonitor.SILENT);
    return messageBuilder.parseMessage(messages.get(0).getHeaders().getInputStream());
}
 
Example 6
Source File: EnvelopeTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Message toMime4JMessage(String messageAsString) throws IOException {
    DefaultMessageBuilder defaultMessageBuilder = new DefaultMessageBuilder();
    defaultMessageBuilder.setMimeEntityConfig(MimeConfig.PERMISSIVE);
    defaultMessageBuilder.setDecodeMonitor(DecodeMonitor.SILENT);
    return defaultMessageBuilder.parseMessage(
        new ByteArrayInputStream(messageAsString.getBytes(StandardCharsets.UTF_8)));
}