2017-07-28 14:45:19 +00:00
|
|
|
/*
|
|
|
|
* meli - mailbox module.
|
|
|
|
*
|
|
|
|
* Copyright 2017 Manos Pitsidianakis
|
2017-09-01 12:24:32 +00:00
|
|
|
*
|
2017-07-28 14:45:19 +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::*;
|
2019-09-08 08:05:25 +00:00
|
|
|
pub use crate::email::*;
|
2019-05-25 23:34:03 +00:00
|
|
|
use fnv::{FnvHashMap, FnvHashSet};
|
2019-09-08 08:05:25 +00:00
|
|
|
|
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)]
|
2017-09-16 12:05:28 +00:00
|
|
|
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,
|
2018-09-22 13:56:50 +00:00
|
|
|
name: String,
|
2019-05-25 23:34:03 +00:00
|
|
|
pub envelopes: FnvHashSet<EnvelopeHash>,
|
2018-09-09 23:21:46 +00:00
|
|
|
has_sent: bool,
|
2017-07-28 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 14:36:45 +00:00
|
|
|
impl Mailbox {
|
2019-07-28 15:52:45 +00:00
|
|
|
pub fn new(folder: Folder, envelopes: &FnvHashMap<EnvelopeHash, Envelope>) -> Mailbox {
|
2018-09-22 13:56:50 +00:00
|
|
|
let name = folder.name().into();
|
2019-05-25 23:34:03 +00:00
|
|
|
let envelopes = envelopes.keys().cloned().collect();
|
2019-07-28 15:52:45 +00:00
|
|
|
Mailbox {
|
2018-09-17 04:53:16 +00:00
|
|
|
folder,
|
2018-10-14 16:49:16 +00:00
|
|
|
name,
|
2019-05-25 23:34:03 +00:00
|
|
|
envelopes,
|
2018-09-09 23:21:46 +00:00
|
|
|
..Default::default()
|
2019-07-28 15:52:45 +00:00
|
|
|
}
|
2017-07-28 14:45:19 +00:00
|
|
|
}
|
2018-09-22 13:56:50 +00:00
|
|
|
|
2019-09-08 08:05:25 +00:00
|
|
|
pub fn merge(&mut self, envelopes: &FnvHashMap<EnvelopeHash, Envelope>) {
|
|
|
|
self.envelopes.extend(envelopes.keys().cloned());
|
|
|
|
}
|
|
|
|
|
2018-09-22 13:56:50 +00:00
|
|
|
pub fn name(&self) -> &str {
|
|
|
|
&self.name
|
|
|
|
}
|
|
|
|
|
2018-08-23 12:36:52 +00:00
|
|
|
pub fn is_empty(&self) -> bool {
|
2019-05-25 23:34:03 +00:00
|
|
|
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 {
|
2019-05-25 23:34:03 +00:00
|
|
|
self.envelopes.len()
|
2017-07-28 14:45:19 +00:00
|
|
|
}
|
2019-05-25 23:34:03 +00:00
|
|
|
pub fn insert(&mut self, h: EnvelopeHash) {
|
|
|
|
self.envelopes.insert(h);
|
2018-09-07 06:44:37 +00:00
|
|
|
}
|
2018-10-14 16:49:16 +00:00
|
|
|
pub fn rename(&mut self, old_hash: EnvelopeHash, new_hash: EnvelopeHash) {
|
2019-05-25 23:34:03 +00:00
|
|
|
self.envelopes.remove(&old_hash);
|
2018-09-05 13:08:11 +00:00
|
|
|
|
2019-05-25 23:34:03 +00:00
|
|
|
self.envelopes.insert(new_hash);
|
2018-09-05 13:08:11 +00:00
|
|
|
}
|
2019-05-25 23:34:03 +00:00
|
|
|
pub fn remove(&mut self, h: EnvelopeHash) {
|
|
|
|
self.envelopes.remove(&h);
|
2018-09-05 13:08:11 +00:00
|
|
|
}
|
2017-07-28 14:45:19 +00:00
|
|
|
}
|