Questions tagged [mime4j]

mime4j is a Java Library for handling E-Mail according to rfc822 and MIME format is part of the Apache James project. The current (2014-07-18) stable version is 0.7.2

Summary Taken from: https://james.apache.org/mime4j/

Apache James Mime4J provides a parser, MimeStreamParser , for e-mail message streams in plain rfc822 and MIME format. The parser uses a callback mechanism to report parsing events such as the start of an entity header, the start of a body, etc. If you are familiar with the SAX XML parser interface you should have no problem getting started with mime4j.

The parser only deals with the structure of the message stream. It won't do any decoding of base64 or quoted-printable encoded header fields and bodies. This is intentional - the parser should only provide the most basic functionality needed to build more complex parsers. However, mime4j does include facilities to decode bodies and fields and the Message class described below handles decoding of fields and bodies transparently.

The parser has been designed to be extremely tolerant against messages violating the standards. It has been tested using a large corpus (>5000) of e-mail messages. As a benchmark the widely used perl MIME::Tools parser has been used. mime4j and MIME:Tools rarely differ (<25 in those 5000). When they do (which only occurs for illegally formatted spam messages) we think mime4j does a better job.

mime4j can also be used to build a tree representation of an e-mail message using the Message class. Using this facility mime4j automatically handles the decoding of fields and bodies and uses temporary files for large attachments. This representation is similar to the representation constructed by the JavaMail API:s but is more tolerant to messages violating the standards.

Using mime4j with Maven

    <!-- EMail handling -->
    <dependency>
        <groupId>org.apache.james</groupId>
        <artifactId>apache-mime4j-core</artifactId>
        <version>0.7.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.james</groupId>
        <artifactId>apache-mime4j-dom</artifactId>
        <version>0.7.2</version>
    </dependency>

Issues

https://issues.apache.org/jira/browse/MIME4J

Mailinglist

https://james.apache.org/mime4j/mail-lists.html

29 questions
5
votes
3 answers

Mime4j: DefaultMessageBuilder fails to parse mbox content

I've downloaded mime4j 0.8.0 snapshot from subversion and built it with maven. The relevant jars I generated can be found here. Now I try to parse a toy mbox file from mime4j test. I use this sample code. Briefly: final File mbox = new…
zvisofer
  • 1,346
  • 18
  • 41
2
votes
2 answers

Parsing e-mails

I am trying to split mail-files like this one: Message-ID: <53197.1075859003723.JavaMail.evans@thyme> Date: Tue, 23 Oct 2001 10:31:09 -0700 (PDT) From: scott.dozier@enron.com To: tom.donohoe@enron.com, bonnie.chang@enron.com,…
Ablia
  • 317
  • 1
  • 3
  • 14
2
votes
1 answer

apache-mime4j: UnstructuredField cannot be cast to ContentTypeField

I have the below groovy code which checks the mime type of a byte [], below apache references are part of apache-mime4j-0.6.jar import org.apache.james.mime4j.message.Message import org.apache.james.mime4j.message.Multipart import…
OTUser
  • 3,788
  • 19
  • 69
  • 127
2
votes
1 answer

How to connect to mail server to use mime4j?

I am trying to move from Javamail to mime4j in the hope of having less trouble parsing mail. However I haven't managed to find out how to connect to a mail server to then use mime4j to parse messages. Javamail provides session and connections to a…
2
votes
1 answer

Parse MIME sender in Java (RFC 822)

MIME message senders appear in formats such as: "John Doe" I'm trying to figure out how to extract the string "johndoe@gmail.com" in the above examples, although I will also need the "johndoe" and "gmail.com"…
djechlin
  • 59,258
  • 35
  • 162
  • 290
2
votes
0 answers

Parsing mbox file in java

I downloaded a mailing list archive from SourceForge. Mailing lists are each automatically archived to a mbox file. So now I need to extract the body from mbox file using Java. Is there a mailbox parser in Java? Thanks
user
  • 245
  • 1
  • 5
  • 13
1
vote
2 answers

Is there an accepted maximum line length for SMTP header fields?

Question What is a good value to use as "max header line length" if there's no standard? Is there some kind of informal standard for what the maximum length of an SMTP header line should be? Context I use Mime4J for parsing SMTP messages. Recently,…
Shorn
  • 19,077
  • 15
  • 90
  • 168
1
vote
0 answers

How to turn off inbuilt decoding in MIME4j?

I am writing a groovy code to get image/attachments from the MIME message and I want to use writeTo and writeBody methods in the MessageWriter class. How do I turn off or override the decoding in writeTo and writeBody methods outputs in the…
MojoCode
  • 11
  • 1
1
vote
0 answers

MIME-attach in java SOAPMessage

Before I asked about how to create MIME-atachment text/xml in Java and now, I have one simple question. If I have this MIME structure: Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml; start="" --MIME_boundary…
Giymose
  • 201
  • 1
  • 6
  • 21
1
vote
2 answers

MboxIterator not in Apache Mime4J

I downloaded the binaries of the latest stable version of apache-mime4j (0.7.2). Yet, I fail to compile the next code since MboxIterator & CharBufferWrapper classes are not found. final File mbox = new File("path/name.mbox"); for (CharBufferWrapper…
zvisofer
  • 1,346
  • 18
  • 41
1
vote
0 answers

add footer/signature to mail in Java

In one of my Java applications I have to forward e-mails. So, I get e-mails (plain text or multipart) with any content (maybe also attachments). I edit their subject, from- and to-header and send them via SMTP. I already implemented this using…
Ethan Leroy
  • 15,804
  • 9
  • 41
  • 63
1
vote
1 answer

Event-based parsing in MIME4J - how to populate a new Message from the InputStream?

I am working with MIME4J to read MIME events from an email stack dump. I am attempting to read a given message event, as defined by the START_MESSAGE and END_MESSAGE headers, as an entire event, as I will be moving the process to a distributed…
RDXdev
  • 31
  • 4
1
vote
0 answers

Multipart encoding for encryption

I am using Mime4J to mime-encode a message. I have a text part, and attachments, which I add to a MultipartImpl object. My problem is this: all of the examples I can find involve attaching the MultipartImpl object to a MessageImpl object, ready for…
Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59
1
vote
2 answers

parsing email with mime4j

I encountered a problem when parsing email with mime4j. The email has an attachment, and I use MimeStreamParser to parse it. The parser does not call startMultipart method at all. Instead, it only calls body method once, and the BodyDescriptor is…
user2713323
  • 11
  • 1
  • 3
1
vote
2 answers

Retrieving email attachment filename with mime4j

I'm trying to use mime4j to parse emails, all is working fine, however I'm not able to get the file name of the attachment. Unfortunately the BodyDescriptor doesn't include this information in the content disposition, or content type fields. I have…
Chris
  • 923
  • 1
  • 8
  • 11
1
2