Initial commit
This commit is contained in:
commit
3162e89b5d
5 changed files with 72 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
32
Cargo.lock
generated
Normal file
32
Cargo.lock
generated
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "imf-codec"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"nom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "imf-codec"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nom = "7"
|
6
rfc822.eml
Normal file
6
rfc822.eml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
From: someone@example.com
|
||||||
|
To: someone_else@example.com
|
||||||
|
Subject: An RFC 822 formatted message
|
||||||
|
|
||||||
|
This is the plain text body of the message. Note the blank line
|
||||||
|
between the header information and the body of the message.
|
24
src/main.rs
Normal file
24
src/main.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
use nom::{
|
||||||
|
IResult,
|
||||||
|
character::complete::alphanumeric1,
|
||||||
|
bytes::complete::tag,
|
||||||
|
bytes::complete::take_until1,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct HeaderField {
|
||||||
|
pub name: String,
|
||||||
|
pub body: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_header_field(input: &str) -> IResult<&str, HeaderField> {
|
||||||
|
let (input, name) = alphanumeric1(input)?;
|
||||||
|
let (input, _) = tag(": ")(input)?;
|
||||||
|
let (input, body) = take_until1("\r\n")(input)?;
|
||||||
|
Ok((input, HeaderField { name: name.to_string(), body: body.to_string() }))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let header_fields = "Subject: Hello\r\n World";
|
||||||
|
println!("{:?}", parse_header_field(header_fields));
|
||||||
|
}
|
Loading…
Reference in a new issue