mirror of
https://github.com/stalwartlabs/mail-parser.git
synced 2026-11-28 16:01:16 +00:00
75 lines
2.4 KiB
Rust
75 lines
2.4 KiB
Rust
/*
|
|
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*/
|
|
|
|
use mail_parser::{HeaderName, MessageParser};
|
|
|
|
const MESSAGE: &str = r#"From: Art Vandelay <art@vandelay.com> (Vandelay Industries)
|
|
To: "Colleagues": "James Smythe" <james@vandelay.com>; Friends:
|
|
jane@example.com, =?UTF-8?Q?John_Sm=C3=AEth?= <john@example.com>;
|
|
Date: Sat, 20 Nov 2021 14:22:01 -0800
|
|
Subject: Why not both importing AND exporting? =?utf-8?b?4pi6?=
|
|
Content-Type: multipart/mixed; boundary="festivus";
|
|
|
|
--festivus
|
|
Content-Type: text/html; charset="us-ascii"
|
|
Content-Transfer-Encoding: base64
|
|
|
|
PGh0bWw+PHA+SSB3YXMgdGhpbmtpbmcgYWJvdXQgcXVpdHRpbmcgdGhlICZsZHF1bztle
|
|
HBvcnRpbmcmcmRxdW87IHRvIGZvY3VzIGp1c3Qgb24gdGhlICZsZHF1bztpbXBvcnRpbm
|
|
cmcmRxdW87LDwvcD48cD5idXQgdGhlbiBJIHRob3VnaHQsIHdoeSBub3QgZG8gYm90aD8
|
|
gJiN4MjYzQTs8L3A+PC9odG1sPg==
|
|
--festivus
|
|
Content-Type: message/rfc822
|
|
|
|
From: "Cosmo Kramer" <kramer@kramerica.com>
|
|
Subject: Exporting my book about coffee tables
|
|
Content-Type: multipart/mixed; boundary="giddyup";
|
|
|
|
--giddyup
|
|
Content-Type: text/plain; charset="utf-16"
|
|
Content-Transfer-Encoding: quoted-printable
|
|
|
|
=FF=FE=0C!5=D8"=DD5=D8)=DD5=D8-=DD =005=D8*=DD5=D8"=DD =005=D8"=
|
|
=DD5=D85=DD5=D8-=DD5=D8,=DD5=D8/=DD5=D81=DD =005=D8*=DD5=D86=DD =
|
|
=005=D8=1F=DD5=D8,=DD5=D8,=DD5=D8(=DD =005=D8-=DD5=D8)=DD5=D8"=
|
|
=DD5=D8=1E=DD5=D80=DD5=D8"=DD!=00
|
|
--giddyup
|
|
Content-Type: image/gif; name*1="about "; name*0="Book ";
|
|
name*2*=utf-8''%e2%98%95 tables.gif
|
|
Content-Transfer-Encoding: Base64
|
|
Content-Disposition: attachment
|
|
|
|
R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
|
--giddyup--
|
|
--festivus--
|
|
"#;
|
|
|
|
fn main() {
|
|
// Parse only the message headers
|
|
let _headers = MessageParser::new()
|
|
.parse_headers(MESSAGE)
|
|
.unwrap()
|
|
.headers();
|
|
|
|
// Parse only the message body, ignoring all headers (except MIME headers, which are required to parse the body)
|
|
let _message = MessageParser::new()
|
|
.with_mime_headers()
|
|
.default_header_ignore()
|
|
.parse(MESSAGE)
|
|
.unwrap();
|
|
|
|
// Parse only To, From, Date, and Subject headers. All other headers are parsed as raw.
|
|
let _message = MessageParser::new()
|
|
.with_mime_headers()
|
|
.header_text(HeaderName::Subject)
|
|
.header_address(HeaderName::From)
|
|
.header_address(HeaderName::To)
|
|
.header_date(HeaderName::Date)
|
|
.default_header_raw()
|
|
.parse(MESSAGE)
|
|
.unwrap();
|
|
}
|