meli/melib/src/mailbox.rs

81 lines
2.2 KiB
Rust
Raw Normal View History

/*
* meli - mailbox module.
*
* Copyright 2017 Manos Pitsidianakis
2017-09-01 12:24:32 +00:00
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
2018-08-06 19:20:34 +00:00
/*!
* Mail related code.
*
* This module handles reading emails from various backends, handling account data etc
*/
2019-05-26 12:54:45 +00:00
use crate::backends::Folder;
pub use crate::collection::*;
pub use crate::email::*;
use fnv::{FnvHashMap, FnvHashSet};
2017-10-01 14:31:20 +00:00
/// `Mailbox` represents a folder of mail.
2019-05-14 18:47:47 +00:00
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct Mailbox {
2019-05-14 18:47:47 +00:00
#[serde(skip_serializing, skip_deserializing)]
2018-07-11 20:12:25 +00:00
pub folder: Folder,
name: String,
pub envelopes: FnvHashSet<EnvelopeHash>,
has_sent: bool,
}
2018-08-14 14:36:45 +00:00
impl Mailbox {
pub fn new(folder: Folder, envelopes: &FnvHashMap<EnvelopeHash, Envelope>) -> Mailbox {
let name = folder.name().into();
let envelopes = envelopes.keys().cloned().collect();
Mailbox {
2018-09-17 04:53:16 +00:00
folder,
2018-10-14 16:49:16 +00:00
name,
envelopes,
..Default::default()
}
}
pub fn merge(&mut self, envelopes: &FnvHashMap<EnvelopeHash, Envelope>) {
self.envelopes.extend(envelopes.keys().cloned());
}
pub fn name(&self) -> &str {
&self.name
}
2018-08-23 12:36:52 +00:00
pub fn is_empty(&self) -> bool {
self.envelopes.is_empty()
2018-08-23 12:36:52 +00:00
}
2018-07-11 15:58:57 +00:00
pub fn len(&self) -> usize {
self.envelopes.len()
}
pub fn insert(&mut self, h: EnvelopeHash) {
self.envelopes.insert(h);
}
2018-10-14 16:49:16 +00:00
pub fn rename(&mut self, old_hash: EnvelopeHash, new_hash: EnvelopeHash) {
self.envelopes.remove(&old_hash);
2018-09-05 13:08:11 +00:00
self.envelopes.insert(new_hash);
2018-09-05 13:08:11 +00:00
}
pub fn remove(&mut self, h: EnvelopeHash) {
self.envelopes.remove(&h);
2018-09-05 13:08:11 +00:00
}
}