EmailReplyParser is a small Java library for parsing plain text email content, based on GitHub's email_reply_parser library.
Run mvn clean test package
. A nice and fresh EmailReplyParser-1.0.jar
file will appear in the EmailReplyParser/target
directory.
I built a release, (see the snapshots dir) using this command: mvn deploy -DaltDeploymentRepository=snapshot-repo::default::file:./snapshots -Dfile=target/EmailReplyParser-1.1.jar -DgroupId=com.edlio.emailreplyparser -DartifactId=EmailReplyParser -Dpackaging=jar -Dversion=1.1
Import the Email and EmailParser classes.
import com.edlio.emailreplyparser.Email;
import com.edlio.emailreplyparser.EmailParser;
Instantiate an EmailParser
object and parse your email:
EmailParser parser = new EmailParser();
Email email = parser.parse(emailString);
You get an Email
object that contains a set of Fragment
objects. The Email
class exposes two methods:
getFragments()
: returns a list of fragments;getVisibleText()
: returns a string which represents the content considered as "visible".getHiddenText()
: returns a string which represents the content considered as "hidden".
The Fragment
represents a part of the full email content, and has the following API:
String content = fragment.getContent();
boolean isSignature = fragment.isSignature();
boolean isQuoted = fragment.isQuoted();
boolean isHiiden = fragment.isHidden();
boolean isEmpty = fragment.isEmpty();
Alternatively, you can rely on the EmailReplyParser
to either parse an email or get its visible content in a single line of code:
Email email = EmailReplayParser.read(emailContentString);
String reply = EmailReplyParser.parseReply(emailContentString);
- GitHub
- William Durand [email protected]
- Edlio
EmailReplyParser is released under the MIT License. See the bundled LICENSE file for details.