• Stars
    star
    181
  • Rank 212,110 (Top 5 %)
  • Language
    Rust
  • License
    BSD Zero Clause L...
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust library to parse mail files

mailparse

Build Status Crate

A simple parser for MIME email messages.

API

The primary entry point for this library is the following function:

    parse_mail(&[u8]) -> Result<ParsedMail, MailParseError>

This function takes the raw message data, including headers and body, and returns a structured object to more easily access pieces of the email message. There are other public functions that allow parsing smaller parts of the message as well; refer to the full documentation.

The library is designed to process real-world email data such as might be obtained by using the FETCH command on an IMAP server, or in a Maildir. As such, this library should successfully handle any valid MIME-formatted message, although it may not follow all the strict requirements in the various specifications that cover the format (predominantly IETF RFCs 822, 2045, 2047, 2822, and 5322). As an example, this library accepts raw message data which uses \n (ASCII LF) as line delimiters rather than the RFC-mandated \r\n (ASCII CRLF) line delimiters.

Example usage

    use mailparse::*;
    let parsed = parse_mail(concat!(
            "Subject: This is a test email\n",
            "Content-Type: multipart/alternative; boundary=foobar\n",
            "Date: Sun, 02 Oct 2016 07:06:22 -0700 (PDT)\n",
            "\n",
            "--foobar\n",
            "Content-Type: text/plain; charset=utf-8\n",
            "Content-Transfer-Encoding: quoted-printable\n",
            "\n",
            "This is the plaintext version, in utf-8. Proof by Euro: =E2=82=AC\n",
            "--foobar\n",
            "Content-Type: text/html\n",
            "Content-Transfer-Encoding: base64\n",
            "\n",
            "PGh0bWw+PGJvZHk+VGhpcyBpcyB0aGUgPGI+SFRNTDwvYj4gdmVyc2lvbiwgaW4g \n",
            "dXMtYXNjaWkuIFByb29mIGJ5IEV1cm86ICZldXJvOzwvYm9keT48L2h0bWw+Cg== \n",
            "--foobar--\n",
            "After the final boundary stuff gets ignored.\n").as_bytes())
        .unwrap();
    assert_eq!(parsed.headers.get_first_value("Subject"),
        Some("This is a test email".to_string()));
    assert_eq!(parsed.subparts.len(), 2);
    assert_eq!(parsed.subparts[0].get_body().unwrap(),
        "This is the plaintext version, in utf-8. Proof by Euro: \u{20AC}");
    assert_eq!(parsed.subparts[1].headers[1].get_value(), "base64");
    assert_eq!(parsed.subparts[1].ctype.mimetype, "text/html");
    assert!(parsed.subparts[1].get_body().unwrap().starts_with("<html>"));
    assert_eq!(dateparse(parsed.headers.get_first_value("Date").unwrap().as_str()).unwrap(), 1475417182);

Documentation

See the rustdoc at docs.rs.

MSRV policy

Currently the minimum supported Rust version (MSRV) is 1.51.0. MSRV increases will be kept to a minimum, and will always be accompanied with a minor version bump.

Support mailparse

If you want to support development of mailparse, please do so by donating your money, time, and/or energy to fighting climate change. A quick and easy way is to send a donation to Replant.ca Environmental, where every dollar gets a tree planted!

More Repositories

1

cafebabe

A java class file parser
Rust
38
star
2

maildir

A simple library to deal with maildir folders
Rust
24
star
3

quoted-printable

Quoted-printable decoder in Rust
Rust
10
star
4

khaki

A tool to write rust "scripts" with less boilerplate
Rust
7
star
5

bugmash

A dashboard for those flooded with bugmail
PHP
6
star
6

query-parser

A search query parser
Rust
6
star
7

fennec-addon-javaddon

A java addon for fennec
JavaScript
4
star
8

awsy-armv6

AWSY test runner for fennec
Java
4
star
9

rust-cgi

Create CGI programs in Rust with hyper's http types
Rust
4
star
10

pimple-android

Code to create a separate contacts and calendar database in Android
Java
3
star
11

moz-scripts

Assorted scripts and configs for mozilla builds
Shell
3
star
12

t_est

Just a test repo
Rust
1
star
13

20220627-okhttp-durationunit

Reproducer for okhttp3 5.0 bug
Shell
1
star
14

butterdish

3D printed butter dish
OpenSCAD
1
star
15

supercollapser

Rust
1
star
16

pdadb-scraper

Shell
1
star
17

telemetry-analysis

Stuff to help with analyzing telemetry data
Jupyter Notebook
1
star
18

mailparse-bin

This has moved to the mailparse repo, as examples/dump_mail.rs
Rust
1
star
19

cargo-vendor-replace

Rust
1
star
20

jsontest

Rust
1
star
21

circdep

Demonstration of gradle classpath mixing multiple versions of the same project
Shell
1
star
22

aboutlogcat

Fennec addon that adds an about:logcat page
Java
1
star
23

moviemaker

Cartoon movie maker
HTML
1
star
24

rendertrace

Render a viewport trace
HTML
1
star
25

mnumonic

A rust library to convert between numbers/bytes and a human-memorable phrase
Rust
1
star
26

cargo-bug-2

Rust
1
star
27

blocktastic

Rust
1
star
28

datetimeutils

A zero-dependency crate with some date/time/calendar utilities
Rust
1
star
29

rustc-ap-proc_macro

Copy of libproc_macro from rust-lang/rustc/ as a standalone library
Rust
1
star
30

20230205-kotlincompile-task

Reproducer for https://github.com/gradle/gradle/issues/23792
Kotlin
1
star
31

cargo-bug

Rust
1
star
32

alphablaster

Simple typing tutor game to blow up falling letters
JavaScript
1
star
33

20220720-kotlin-compiler-regression

Minimal reproducer case for a kotlin compiler regression in 1.7.0
Kotlin
1
star
34

20221015-incremental-compilation-failure

Standalone reproducer for https://youtrack.jetbrains.com/issue/KT-54467
Kotlin
1
star