2019-06-28 19:34:40 +03:00
|
|
|
/*
|
|
|
|
* meli - imap module.
|
|
|
|
*
|
|
|
|
* Copyright 2019 Manos Pitsidianakis
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2020-08-28 00:24:43 +03:00
|
|
|
|
|
|
|
use super::protocol_parser::SelectResponse;
|
2020-02-26 10:54:10 +02:00
|
|
|
use crate::backends::{
|
2020-09-22 14:14:11 +03:00
|
|
|
BackendMailbox, LazyCountSet, Mailbox, MailboxHash, MailboxPermissions, SpecialUsageMailbox,
|
2020-02-26 10:54:10 +02:00
|
|
|
};
|
2019-12-17 14:12:41 +02:00
|
|
|
use crate::error::*;
|
|
|
|
use std::sync::{Arc, Mutex, RwLock};
|
2019-06-28 19:34:40 +03:00
|
|
|
|
2019-09-11 17:57:55 +03:00
|
|
|
#[derive(Debug, Default, Clone)]
|
2020-02-26 10:54:10 +02:00
|
|
|
pub struct ImapMailbox {
|
2020-08-28 00:24:43 +03:00
|
|
|
pub hash: MailboxHash,
|
|
|
|
pub imap_path: String,
|
|
|
|
pub path: String,
|
|
|
|
pub name: String,
|
|
|
|
pub parent: Option<MailboxHash>,
|
|
|
|
pub children: Vec<MailboxHash>,
|
2020-02-06 01:49:18 +02:00
|
|
|
pub separator: u8,
|
2019-12-17 14:12:41 +02:00
|
|
|
pub usage: Arc<RwLock<SpecialUsageMailbox>>,
|
2020-08-28 00:24:43 +03:00
|
|
|
pub select: Arc<RwLock<Option<SelectResponse>>>,
|
2019-12-10 23:54:19 +02:00
|
|
|
pub no_select: bool,
|
2019-12-17 14:12:41 +02:00
|
|
|
pub is_subscribed: bool,
|
2019-09-06 12:54:12 +03:00
|
|
|
|
2020-02-26 10:54:10 +02:00
|
|
|
pub permissions: Arc<Mutex<MailboxPermissions>>,
|
2020-06-24 17:47:08 +03:00
|
|
|
pub exists: Arc<Mutex<LazyCountSet>>,
|
|
|
|
pub unseen: Arc<Mutex<LazyCountSet>>,
|
2020-11-29 15:52:48 +02:00
|
|
|
pub warm: Arc<Mutex<bool>>,
|
2019-06-28 19:34:40 +03:00
|
|
|
}
|
|
|
|
|
2020-02-26 10:54:10 +02:00
|
|
|
impl ImapMailbox {
|
2020-02-06 01:49:18 +02:00
|
|
|
pub fn imap_path(&self) -> &str {
|
|
|
|
&self.imap_path
|
|
|
|
}
|
2020-11-29 15:52:48 +02:00
|
|
|
|
|
|
|
/// Establish that mailbox contents have been fetched at least once during this execution
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn set_warm(&self, new_value: bool) {
|
|
|
|
*self.warm.lock().unwrap() = new_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Mailbox contents have been fetched at least once during this execution
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn is_warm(&self) -> bool {
|
|
|
|
*self.warm.lock().unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Mailbox contents have not been fetched at all during this execution
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn is_cold(&self) -> bool {
|
|
|
|
!self.is_warm()
|
|
|
|
}
|
2020-02-06 01:49:18 +02:00
|
|
|
}
|
|
|
|
|
2020-02-26 10:54:10 +02:00
|
|
|
impl BackendMailbox for ImapMailbox {
|
|
|
|
fn hash(&self) -> MailboxHash {
|
2019-06-28 19:34:40 +03:00
|
|
|
self.hash
|
|
|
|
}
|
|
|
|
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
&self.name
|
|
|
|
}
|
|
|
|
|
|
|
|
fn path(&self) -> &str {
|
|
|
|
&self.path
|
|
|
|
}
|
|
|
|
|
|
|
|
fn change_name(&mut self, s: &str) {
|
|
|
|
self.name = s.to_string();
|
|
|
|
}
|
|
|
|
|
2020-02-26 10:54:10 +02:00
|
|
|
fn children(&self) -> &[MailboxHash] {
|
2019-06-28 19:34:40 +03:00
|
|
|
&self.children
|
|
|
|
}
|
|
|
|
|
2020-02-26 10:54:10 +02:00
|
|
|
fn clone(&self) -> Mailbox {
|
2019-12-17 14:12:41 +02:00
|
|
|
Box::new(std::clone::Clone::clone(self))
|
2019-06-28 19:34:40 +03:00
|
|
|
}
|
|
|
|
|
2019-12-11 00:15:36 +02:00
|
|
|
fn special_usage(&self) -> SpecialUsageMailbox {
|
2019-12-17 14:12:41 +02:00
|
|
|
*self.usage.read().unwrap()
|
2019-12-11 00:15:36 +02:00
|
|
|
}
|
|
|
|
|
2020-02-26 10:54:10 +02:00
|
|
|
fn parent(&self) -> Option<MailboxHash> {
|
2019-06-28 19:34:40 +03:00
|
|
|
self.parent
|
|
|
|
}
|
2019-11-11 00:47:23 +02:00
|
|
|
|
2020-02-26 10:54:10 +02:00
|
|
|
fn permissions(&self) -> MailboxPermissions {
|
2019-11-11 00:47:23 +02:00
|
|
|
*self.permissions.lock().unwrap()
|
|
|
|
}
|
2019-12-17 14:12:41 +02:00
|
|
|
fn is_subscribed(&self) -> bool {
|
|
|
|
self.is_subscribed
|
|
|
|
}
|
|
|
|
fn set_is_subscribed(&mut self, new_val: bool) -> Result<()> {
|
|
|
|
self.is_subscribed = new_val;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_special_usage(&mut self, new_val: SpecialUsageMailbox) -> Result<()> {
|
|
|
|
*self.usage.write()? = new_val;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn count(&self) -> Result<(usize, usize)> {
|
2020-06-24 17:47:08 +03:00
|
|
|
Ok((self.unseen.lock()?.len(), self.exists.lock()?.len()))
|
2019-12-17 14:12:41 +02:00
|
|
|
}
|
2019-06-28 19:34:40 +03:00
|
|
|
}
|