summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-06-07 17:52:40 +0200
committerGitHub <noreply@github.com>2017-06-07 17:52:40 +0200
commit4fff92e7c02888567eae3aa34a63c19e9611daf9 (patch)
tree1990de21d7f4db4649b2be253fcd6983c06292de
parent1b15d45e7cf0e63e8370fbf779b12a9fce27412d (diff)
parenta106b8c1f49666bae72118222c28651997ba6c8e (diff)
downloadimag-4fff92e7c02888567eae3aa34a63c19e9611daf9.zip
imag-4fff92e7c02888567eae3aa34a63c19e9611daf9.tar.gz
Merge pull request #960 from matthiasbeyer/libimagmail/use-email-crate
Libimagmail/use email crate
-rw-r--r--libimagmail/Cargo.toml2
-rw-r--r--libimagmail/src/error.rs19
-rw-r--r--libimagmail/src/hasher.rs38
-rw-r--r--libimagmail/src/iter.rs21
-rw-r--r--libimagmail/src/lib.rs21
-rw-r--r--libimagmail/src/mail.rs35
-rw-r--r--libimagmail/src/result.rs19
7 files changed, 134 insertions, 21 deletions
diff --git a/libimagmail/Cargo.toml b/libimagmail/Cargo.toml
index 98452ce..fa9122b 100644
--- a/libimagmail/Cargo.toml
+++ b/libimagmail/Cargo.toml
@@ -15,7 +15,7 @@ homepage = "http://imag-pim.org"
[dependencies]
log = "0.3"
-mailparse = "0.4"
+email = "0.0.17"
semver = "0.5"
toml = "0.4.*"
filters = "0.1.*"
diff --git a/libimagmail/src/error.rs b/libimagmail/src/error.rs
index a11a0a9..8c616fb 100644
--- a/libimagmail/src/error.rs
+++ b/libimagmail/src/error.rs
@@ -1,3 +1,22 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
generate_error_module!(
generate_error_types!(MailError, MailErrorKind,
RefCreationError => "Error creating a reference to a file/directory",
diff --git a/libimagmail/src/hasher.rs b/libimagmail/src/hasher.rs
index dc1df12..8ea3f03 100644
--- a/libimagmail/src/hasher.rs
+++ b/libimagmail/src/hasher.rs
@@ -1,7 +1,26 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
use std::io::Read;
use std::path::PathBuf;
-use mailparse::{MailHeader, parse_mail};
+use email::MimeMessage;
use libimagref::hasher::Hasher;
use libimagref::hasher::DefaultHasher;
@@ -32,27 +51,28 @@ impl Hasher for MailHasher {
fn create_hash<R: Read>(&mut self, pb: &PathBuf, c: &mut R) -> RResult<String> {
use filters::filter::Filter;
+ use email::Header;
let mut s = String::new();
try!(c.read_to_string(&mut s).map_err_into(REK::UTF8Error).map_err_into(REK::IOError));
- parse_mail(&s.as_bytes())
+ MimeMessage::parse(&s)
.map_err(Box::new)
.map_err(|e| MEK::MailParsingError.into_error_with_cause(e))
.map_err_into(REK::RefHashingError)
.and_then(|mail| {
- let has_key = |hdr: &MailHeader, exp: &str|
- hdr.get_key().map(|s| s == exp).unwrap_or(false);
+ let has_key = |hdr: &Header, exp: &str| hdr.name == exp;
- let subject_filter = |hdr: &MailHeader| has_key(hdr, "Subject");
- let from_filter = |hdr: &MailHeader| has_key(hdr, "From");
- let to_filter = |hdr: &MailHeader| has_key(hdr, "To");
+ let subject_filter = |hdr: &Header| has_key(hdr, "Subject");
+ let from_filter = |hdr: &Header| has_key(hdr, "From");
+ let to_filter = |hdr: &Header| has_key(hdr, "To");
let filter = subject_filter.or(from_filter).or(to_filter);
- let mut v = vec![];
+ let mut v : Vec<String> = vec![];
for hdr in mail.headers.iter().filter(|item| filter.filter(item)) {
- let s = try!(hdr.get_value()
+ let s = try!(hdr
+ .get_value()
.map_err(Box::new)
.map_err(|e| REK::RefHashingError.into_error_with_cause(e)));
diff --git a/libimagmail/src/iter.rs b/libimagmail/src/iter.rs
index 365a092..771d45a 100644
--- a/libimagmail/src/iter.rs
+++ b/libimagmail/src/iter.rs
@@ -1,3 +1,22 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
//! Module for the MailIter
//!
//! MailIter is a iterator which takes an Iterator that yields `Ref` and yields itself
@@ -12,7 +31,7 @@ use libimagref::reference::Ref;
use std::marker::PhantomData;
-struct MailIter<'a, I: 'a + Iterator<Item = Ref<'a>>> {
+pub struct MailIter<'a, I: 'a + Iterator<Item = Ref<'a>>> {
_marker: PhantomData<&'a I>,
i: I,
}
diff --git a/libimagmail/src/lib.rs b/libimagmail/src/lib.rs
index 1d88a06..cc25d1f 100644
--- a/libimagmail/src/lib.rs
+++ b/libimagmail/src/lib.rs
@@ -1,5 +1,24 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
#[macro_use] extern crate log;
-extern crate mailparse;
+extern crate email;
extern crate semver;
extern crate toml;
extern crate filters;
diff --git a/libimagmail/src/mail.rs b/libimagmail/src/mail.rs
index b49e0ed..6ee4d57 100644
--- a/libimagmail/src/mail.rs
+++ b/libimagmail/src/mail.rs
@@ -1,14 +1,33 @@
-use std::result::Result as RResult;
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
use std::path::Path;
use std::path::PathBuf;
use std::fs::File;
use std::io::Read;
-use libimagstore::store::{FileLockEntry, Store};
+use libimagstore::store::Store;
use libimagref::reference::Ref;
use libimagref::flags::RefFlags;
-use mailparse::{MailParseError, ParsedMail, parse_mail};
+use email::MimeMessage;
+use email::results::ParsingResult as EmailParsingResult;
use hasher::MailHasher;
use result::Result;
@@ -17,8 +36,8 @@ use error::{MapErrInto, MailErrorKind as MEK};
struct Buffer(String);
impl Buffer {
- pub fn parsed<'a>(&'a self) -> RResult<ParsedMail<'a>, MailParseError> {
- parse_mail(self.0.as_bytes())
+ pub fn parsed(&self) -> EmailParsingResult<MimeMessage> {
+ MimeMessage::parse(&self.0)
}
}
@@ -83,16 +102,14 @@ impl<'a> Mail<'a> {
}
pub fn get_field(&self, field: &str) -> Result<Option<String>> {
- use mailparse::MailHeader;
-
self.1
.parsed()
.map_err_into(MEK::MailParsingError)
.map(|parsed| {
parsed.headers
.iter()
- .filter(|hdr| hdr.get_key().map(|n| n == field).unwrap_or(false))
- .next()
+ .filter(|hdr| hdr.name == field)
+ .nth(0)
.and_then(|field| field.get_value().ok())
})
}
diff --git a/libimagmail/src/result.rs b/libimagmail/src/result.rs
index e771551..7f745ed 100644
--- a/libimagmail/src/result.rs
+++ b/libimagmail/src/result.rs
@@ -1,3 +1,22 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
use std::result::Result as RResult;
use error::MailError;