summaryrefslogtreecommitdiffstats
path: root/melib/src/email/parser.rs
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-11-18 13:00:43 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-11-18 13:00:43 +0200
commitfc2d9a684dac1a4b0bbb93a51a499c5607402fa1 (patch)
treed6389f17dd4afd6b32e3c3aefde9dd95f11ee8d7 /melib/src/email/parser.rs
parentb2cd4f4b7ae9181b9fcf2522771a315249a451e1 (diff)
melib/imap: set has_attachments based on BODYSTRUCTURE
fetch BODYSTRUCTURE along with ENVELOPE from server and set has_attachments based on the MIME structure of the envelope. Notes: BODYSTRUCTURE returns the MIME structure of the envelope without the data, so if it includes a multipart/mixed it *should* have attachments. ENVELOPE returns basic headers of the message like Sender, Subject, Date etc.
Diffstat (limited to 'melib/src/email/parser.rs')
-rw-r--r--melib/src/email/parser.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs
index 747ac747..ef03353e 100644
--- a/melib/src/email/parser.rs
+++ b/melib/src/email/parser.rs
@@ -53,6 +53,7 @@ pub trait BytesExt {
fn ltrim(&self) -> &Self;
fn trim(&self) -> &Self;
fn find(&self, needle: &[u8]) -> Option<usize>;
+ fn rfind(&self, needle: &[u8]) -> Option<usize>;
fn replace(&self, from: &[u8], to: &[u8]) -> Vec<u8>;
}
@@ -79,6 +80,12 @@ impl BytesExt for [u8] {
self.windows(needle.len())
.position(|window| window == needle)
}
+
+ fn rfind(&self, needle: &[u8]) -> Option<usize> {
+ self.windows(needle.len())
+ .rposition(|window| window == needle)
+ }
+
fn replace(&self, from: &[u8], to: &[u8]) -> Vec<u8> {
let mut ret = self.to_vec();
if let Some(idx) = self.find(from) {