summaryrefslogtreecommitdiffstats
path: root/melib/src
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-04-04 15:06:48 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:43 +0300
commit067a8e5c81be602bdec4c4b2625c6b040223515d (patch)
treeed9537c6b10e6b9cc763990f3d3ac25cfbb5eeda /melib/src
parentee4462881e2a0c9fdbb12fe0e33067e3052ef04d (diff)
Run clippy for 2018 edition
Diffstat (limited to 'melib/src')
-rw-r--r--melib/src/mailbox/backends/maildir/backend.rs28
-rw-r--r--melib/src/mailbox/email.rs2
-rw-r--r--melib/src/mailbox/thread.rs80
3 files changed, 45 insertions, 65 deletions
diff --git a/melib/src/mailbox/backends/maildir/backend.rs b/melib/src/mailbox/backends/maildir/backend.rs
index 35e507fe..caf9e43f 100644
--- a/melib/src/mailbox/backends/maildir/backend.rs
+++ b/melib/src/mailbox/backends/maildir/backend.rs
@@ -217,8 +217,8 @@ impl MailBackend for MaildirType {
}
}
/* Update */
- DebouncedEvent::NoticeWrite(mut pathbuf)
- | DebouncedEvent::Write(mut pathbuf) => {
+ DebouncedEvent::NoticeWrite(pathbuf)
+ | DebouncedEvent::Write(pathbuf) => {
let folder_hash = get_path_hash!(pathbuf);
let mut hash_indexes_lock = hash_indexes.lock().unwrap();
let index_lock = &mut hash_indexes_lock.entry(folder_hash).or_default();
@@ -258,8 +258,8 @@ impl MailBackend for MaildirType {
let op = Box::new(MaildirOp::new(new_hash, hash_indexes.clone(), folder_hash));
if let Some(env) = Envelope::from_token(op, new_hash) {
if cfg!(feature = "debug_log") {
-eprintln!("{}\t{}", new_hash, pathbuf.display());
-}
+ eprintln!("{}\t{}", new_hash, pathbuf.display());
+ }
index_lock.insert(new_hash, pathbuf);
/* Send Write notice */
@@ -268,16 +268,14 @@ eprintln!("{}\t{}", new_hash, pathbuf.display());
hash: folder_hash,
kind: Update(old_hash, Box::new(env)),
});
- } else {
- if cfg!(feature = "debug_log") {
-eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", new_hash, pathbuf.as_path().display());
-}
+ } else if cfg!(feature = "debug_log") {
+ eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", new_hash, pathbuf.as_path().display());
}
}
}
/* Remove */
- DebouncedEvent::NoticeRemove(mut pathbuf)
- | DebouncedEvent::Remove(mut pathbuf) => {
+ DebouncedEvent::NoticeRemove(pathbuf)
+ | DebouncedEvent::Remove(pathbuf) => {
let folder_hash = get_path_hash!(pathbuf);
let mut hash_indexes_lock = hash_indexes.lock().unwrap();
let index_lock = hash_indexes_lock.entry(folder_hash).or_default();
@@ -296,7 +294,7 @@ eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`",
});
}
/* Envelope hasn't changed, so handle this here */
- DebouncedEvent::Rename(mut src, mut dest) => {
+ DebouncedEvent::Rename(src, dest) => {
let folder_hash = get_path_hash!(src);
let old_hash: EnvelopeHash = get_file_hash(src.as_path());
let new_hash: EnvelopeHash = get_file_hash(dest.as_path());
@@ -517,7 +515,7 @@ impl MaildirType {
};
for chunk in files.chunks(chunk_size) {
let cache_dir = cache_dir.clone();
- let mut tx = tx.clone();
+ let tx = tx.clone();
let map = map.clone();
let root_path = root_path.clone();
let s = scope.builder().name(name.clone()).spawn(move || {
@@ -548,7 +546,7 @@ impl MaildirType {
let result: result::Result<Envelope, _> = bincode::deserialize_from(reader);
if let Ok(env) = result {
let mut map = map.lock().unwrap();
- let mut map = map.entry(folder_hash).or_default();;
+ let map = map.entry(folder_hash).or_default();;
let hash = env.hash();
map.insert(hash, file.clone());
local_r.push(env);
@@ -558,12 +556,12 @@ impl MaildirType {
let hash = get_file_hash(file);
{
let mut map = map.lock().unwrap();
- let mut map = map.entry(folder_hash).or_default();
+ let map = map.entry(folder_hash).or_default();
(*map).insert(hash, PathBuf::from(file));
}
let op =
Box::new(MaildirOp::new(hash, map.clone(), folder_hash));
- if let Some(mut e) = Envelope::from_token(op, hash)
+ if let Some(e) = Envelope::from_token(op, hash)
{
if let Ok(cached) =
cache_dir.place_cache_file(file_name)
diff --git a/melib/src/mailbox/email.rs b/melib/src/mailbox/email.rs
index 86af2283..82576f78 100644
--- a/melib/src/mailbox/email.rs
+++ b/melib/src/mailbox/email.rs
@@ -544,7 +544,7 @@ impl Envelope {
eprintln!("error in parsing mail\n");
}
let error_msg = b"Mail cannot be shown because of errors.";
- let mut builder = AttachmentBuilder::new(error_msg);
+ let builder = AttachmentBuilder::new(error_msg);
return builder.build();
}
};
diff --git a/melib/src/mailbox/thread.rs b/melib/src/mailbox/thread.rs
index c9a1c55c..1eb87661 100644
--- a/melib/src/mailbox/thread.rs
+++ b/melib/src/mailbox/thread.rs
@@ -93,27 +93,29 @@ macro_rules! make {
}
/* Strip common prefixes from subjects */
-trait SubjectPrefix<'a> {
- fn strip_prefixes(&'a mut self) -> bool;
+trait SubjectPrefix {
+ fn is_a_reply(&self) -> bool;
+ fn strip_prefixes(&mut self);
}
-impl<'a> SubjectPrefix<'a> for &'a [u8] {
- fn strip_prefixes(&'a mut self) -> bool {
- let mut ret: bool = false;
+impl SubjectPrefix for &[u8] {
+ fn is_a_reply(&self) -> bool {
+ self.starts_with(b"RE: ")
+ || self.starts_with(b"Re: ")
+ || self.starts_with(b"FW: ")
+ || self.starts_with(b"Fw: ")
+ }
+
+ fn strip_prefixes(&mut self) {
let result = {
let mut slice = self.trim();
- let mut end_prefix_idx = 0;
loop {
if slice.starts_with(b"RE: ")
|| slice.starts_with(b"Re: ")
|| slice.starts_with(b"FW: ")
|| slice.starts_with(b"Fw: ")
{
- if end_prefix_idx == 0 {
- ret = true;
- }
slice = &slice[3..];
- end_prefix_idx += 3;
continue;
}
if slice.starts_with(b"FWD: ")
@@ -121,24 +123,21 @@ impl<'a> SubjectPrefix<'a> for &'a [u8] {
|| slice.starts_with(b"fwd: ")
{
slice = &slice[4..];
- end_prefix_idx += 4;
continue;
}
if slice.starts_with(b" ") || slice.starts_with(b"\t") || slice.starts_with(b"\r") {
+ //FIXME just trim whitespace
slice = &slice[1..];
- end_prefix_idx += 1;
continue;
}
if slice.starts_with(b"[")
&& !(slice.starts_with(b"[PATCH") || slice.starts_with(b"[RFC"))
{
if let Some(pos) = slice.find(b"]") {
- end_prefix_idx += pos;
slice = &slice[pos..];
continue;
}
slice = &slice[1..];
- end_prefix_idx += 1;
continue;
}
break;
@@ -146,7 +145,6 @@ impl<'a> SubjectPrefix<'a> for &'a [u8] {
slice
};
*self = result;
- ret
}
}
@@ -576,38 +574,24 @@ impl Threads {
t.create_root_set(collection);
t.build_collection(collection);
- for (i, _t) in t.thread_nodes.iter().enumerate() {
- if cfg!(feature = "debug_log") {
+ if cfg!(feature = "debug_log") {
+ for (i, _t) in t.thread_nodes.iter().enumerate() {
eprintln!("Thread #{}, children {}", i, _t.children.len());
- }
- if !_t.children.is_empty() {
- if cfg!(feature = "debug_log") {
+ if !_t.children.is_empty() {
eprintln!("{:?}", _t.children);
}
- }
- if let Some(m) = _t.message {
- if cfg!(feature = "debug_log") {
+ if let Some(m) = _t.message {
eprintln!("\tmessage: {}", collection[&m].subject());
- }
- } else {
- if cfg!(feature = "debug_log") {
+ } else {
eprintln!("\tNo message");
}
}
- }
- if cfg!(feature = "debug_log") {
eprintln!("\n");
- }
- for (i, _t) in t.tree.borrow().iter().enumerate() {
- if cfg!(feature = "debug_log") {
+ for (i, _t) in t.tree.borrow().iter().enumerate() {
eprintln!("Tree #{} id {}, children {}", i, _t.id, _t.children.len());
- }
- if let Some(m) = t.thread_nodes[_t.id].message {
- if cfg!(feature = "debug_log") {
+ if let Some(m) = t.thread_nodes[_t.id].message {
eprintln!("\tmessage: {}", collection[&m].subject());
- }
- } else {
- if cfg!(feature = "debug_log") {
+ } else {
eprintln!("\tNo message");
}
}
@@ -621,7 +605,7 @@ impl Threads {
let mut root_set: Vec<usize> = Vec::with_capacity(collection.len());
/* Find the root set */
- 'root_set: for v in self.message_ids.values() {
+ for v in self.message_ids.values() {
if self.thread_nodes[*v].parent.is_none() {
root_set.push(*v);
}
@@ -652,7 +636,7 @@ impl Threads {
/* "If there is no message in the Container, then the Container will have at least
* one child Container, and that Container will have a message. Use the subject of
* that message instead." */
- let mut msg_idx = self.thread_nodes[self.thread_nodes[r].children[0]]
+ let msg_idx = self.thread_nodes[self.thread_nodes[r].children[0]]
.message
.unwrap();
let envelope = &collection[&msg_idx];
@@ -663,7 +647,8 @@ impl Threads {
/* References of this envelope can be empty but if the subject contains a ``Re:``
* prefix, it's a reply */
let mut stripped_subj = subject.to_mut().as_bytes();
- is_re |= stripped_subj.strip_prefixes();
+ is_re |= stripped_subj.is_a_reply();
+ stripped_subj.strip_prefixes();
if stripped_subj.is_empty() {
continue;
@@ -711,7 +696,8 @@ impl Threads {
};
let mut subject = subject.to_mut().as_bytes();
- is_re |= subject.strip_prefixes();
+ is_re |= subject.is_a_reply();
+ subject.strip_prefixes();
if subject.is_empty() {
continue;
}
@@ -975,11 +961,7 @@ impl Threads {
let mut stack = Vec::with_capacity(32);
let no_parent: bool = if let Some(node) = self.thread_nodes.get(node_idx) {
- if node.parent.is_none() {
- true
- } else {
- false
- }
+ node.parent.is_none()
} else {
false
};
@@ -1058,7 +1040,7 @@ impl Threads {
fn inner_subsort_by(&self, subsort: (SortField, SortOrder), collection: &Envelopes) {
let tree = &mut self.tree.borrow_mut();
- for mut t in tree.iter_mut() {
+ for t in tree.iter_mut() {
t.children.sort_by(|a, b| match subsort {
(SortField::Date, SortOrder::Desc) => {
let a = &self.thread_nodes[a.id];
@@ -1316,10 +1298,10 @@ fn node_build(
*/
let mut subject = collection[&hash].subject();
let mut subject = subject.to_mut().as_bytes();
- let subject = subject.strip_prefixes();
+ subject.strip_prefixes();
let mut parent_subject = collection[&parent_hash].subject();
let mut parent_subject = parent_subject.to_mut().as_bytes();
- let parent_subject = parent_subject.strip_prefixes();
+ parent_subject.strip_prefixes();
if subject == parent_subject {
thread_nodes[idx].show_subject = false;
}