Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ description = "MBOX reader."
repository = "https://github.com/meh/rust-mailbox"
keywords = ["mail", "mbox"]

edition = "2021"

[dependencies]
bitflags = "0.9"
owning_ref = "0.3"
bitflags = "1.3"
owning_ref = "0.4"
fnv = "1"

nom = "3.0"
nom = "7"
casing = "0.1"
chrono = "0.4"
mime = "0.3"
10 changes: 5 additions & 5 deletions examples/read.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate mailbox;

use std::fs::File;
use std::env;
use std::fs::File;

fn main() {
let mbox = mailbox::read(File::open(env::args().nth(1).expect("no file given")).unwrap());
let mbox = mailbox::read(File::open(env::args().nth(1).expect("no file given")).unwrap());

for mail in mbox {
println!("{:?}", mail);
}
for mail in mbox {
println!("{:?}", mail);
}
}
84 changes: 42 additions & 42 deletions examples/status.rs
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
extern crate mailbox;
use mailbox::header;

use std::fs::File;
use std::env;
use std::fs::File;

#[derive(Eq, PartialEq, Copy, Clone, Default, Debug)]
pub struct Status {
pub total: usize,
pub seen: usize,
pub old: usize,
pub answered: usize,
pub flagged: usize,
pub draft: usize,
pub deleted: usize,
pub total: usize,
pub seen: usize,
pub old: usize,
pub answered: usize,
pub flagged: usize,
pub draft: usize,
pub deleted: usize,
}

fn main() {
let mut status = Status::default();
let mut status = Status::default();

for path in env::args().skip(1) {
for mail in mailbox::read(File::open(path).unwrap()).body(false) {
if let Ok(mail) = mail {
let mut current = header::Status::empty();
for path in env::args().skip(1) {
for mail in mailbox::read(File::open(path).unwrap()).body(false) {
if let Ok(mail) = mail {
let mut current = header::Status::empty();

if let Some(Ok(s)) = mail.headers().get::<header::Status>() {
current |= s;
}
if let Some(Ok(s)) = mail.headers().get::<header::Status>() {
current |= s;
}

if let Some(Ok(s)) = mail.headers().get_from::<header::Status, _>("X-Status") {
current |= s;
}
if let Some(Ok(s)) = mail.headers().get_from::<header::Status, _>("X-Status") {
current |= s;
}

status.total += 1;
status.total += 1;

if current.contains(header::status::SEEN) {
status.seen += 1;
}
if current.contains(header::status::Status::SEEN) {
status.seen += 1;
}

if current.contains(header::status::OLD) {
status.old += 1;
}
if current.contains(header::status::Status::OLD) {
status.old += 1;
}

if current.contains(header::status::ANSWERED) {
status.answered += 1;
}
if current.contains(header::status::Status::ANSWERED) {
status.answered += 1;
}

if current.contains(header::status::FLAGGED) {
status.flagged += 1;
}
if current.contains(header::status::Status::FLAGGED) {
status.flagged += 1;
}

if current.contains(header::status::DRAFT) {
status.draft += 1;
}
if current.contains(header::status::Status::DRAFT) {
status.draft += 1;
}

if current.contains(header::status::DELETED) {
status.deleted += 1;
}
}
}
}
if current.contains(header::status::Status::DELETED) {
status.deleted += 1;
}
}
}
}

println!("{:#?}", status);
println!("{:#?}", status);
}
10 changes: 5 additions & 5 deletions examples/stream.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate mailbox;

use std::fs::File;
use std::env;
use std::fs::File;

fn main() {
let path = env::args().nth(1).expect("no file given");
let path = env::args().nth(1).expect("no file given");

for entry in mailbox::stream::entries(File::open(path).unwrap()) {
println!("{:?}", entry);
}
for entry in mailbox::stream::entries(File::open(path).unwrap()) {
println!("{:?}", entry);
}
}
44 changes: 22 additions & 22 deletions src/header/bcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,40 @@
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.

use super::Header;
use crate::stream::entry::header;
use crate::util::Address;
use std::io;
use std::ops::Deref;
use stream::entry::header;
use util::Address;
use super::Header;

pub struct Bcc(Vec<Address>);

impl Header for Bcc {
#[inline(always)]
fn name() -> &'static str {
"Bcc"
}
#[inline(always)]
fn name() -> &'static str {
"Bcc"
}

#[inline]
fn parse(values: &[header::Item]) -> io::Result<Self> {
let mut to = Vec::new();
let string = values[0].clone();
#[inline]
fn parse(values: &[header::Item]) -> io::Result<Self> {
let mut to = Vec::new();
let string = values[0].clone();

for slice in string.split(',') {
let start = slice.as_ptr() as usize - string.as_ptr() as usize;
let end = start + slice.len();
for slice in string.split(',') {
let start = slice.as_ptr() as usize - string.as_ptr() as usize;
let end = start + slice.len();

to.push(try!(Address::new(string.clone().map(|s| &s[start..end]))));
}
to.push(Address::new(string.clone().map(|s| &s[start..end]))?);
}

Ok(Bcc(to))
}
Ok(Bcc(to))
}
}

impl Deref for Bcc {
type Target = [Address];
type Target = [Address];

fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target {
&self.0
}
}
44 changes: 22 additions & 22 deletions src/header/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,40 @@
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.

use super::Header;
use crate::stream::entry::header;
use crate::util::Address;
use std::io;
use std::ops::Deref;
use stream::entry::header;
use util::Address;
use super::Header;

pub struct Cc(Vec<Address>);

impl Header for Cc {
#[inline(always)]
fn name() -> &'static str {
"Cc"
}
#[inline(always)]
fn name() -> &'static str {
"Cc"
}

#[inline]
fn parse(values: &[header::Item]) -> io::Result<Self> {
let mut to = Vec::new();
let string = values[0].clone();
#[inline]
fn parse(values: &[header::Item]) -> io::Result<Self> {
let mut to = Vec::new();
let string = values[0].clone();

for slice in string.split(',') {
let start = slice.as_ptr() as usize - string.as_ptr() as usize;
let end = start + slice.len();
for slice in string.split(',') {
let start = slice.as_ptr() as usize - string.as_ptr() as usize;
let end = start + slice.len();

to.push(try!(Address::new(string.clone().map(|s| &s[start..end]))));
}
to.push(Address::new(string.clone().map(|s| &s[start..end]))?);
}

Ok(Cc(to))
}
Ok(Cc(to))
}
}

impl Deref for Cc {
type Target = [Address];
type Target = [Address];

fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target {
&self.0
}
}
33 changes: 17 additions & 16 deletions src/header/content_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,33 @@
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.

use super::Header;
use crate::stream::entry::header;
use std::io;
use std::ops::Deref;
use stream::entry::header;
use super::Header;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct ContentLength(pub usize);

impl Header for ContentLength {
#[inline(always)]
fn name() -> &'static str {
"Content-Length"
}
#[inline(always)]
fn name() -> &'static str {
"Content-Length"
}

#[inline]
fn parse(values: &[header::Item]) -> io::Result<Self> {
Ok(ContentLength(try!(values[0].parse().map_err(|_|
io::Error::new(io::ErrorKind::InvalidInput, "invalid content length")))))
}
#[inline]
fn parse(values: &[header::Item]) -> io::Result<Self> {
Ok(ContentLength(values[0].parse().map_err(|_| {
io::Error::new(io::ErrorKind::InvalidInput, "invalid content length")
})?))
}
}

impl Deref for ContentLength {
type Target = usize;
type Target = usize;

#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
}
Loading