use std::sync::{Arc, Mutex};
use crate::{
backends::{
BackendMailbox, LazyCountSet, Mailbox, MailboxHash, MailboxPermissions, SpecialUsageMailbox,
},
error::*,
UnixTimestamp,
};
#[derive(Clone, Debug, Default)]
pub struct NntpMailbox {
pub(super) hash: MailboxHash,
pub(super) nntp_path: String,
pub high_watermark: Arc<Mutex<usize>>,
pub low_watermark: Arc<Mutex<usize>>,
pub exists: Arc<Mutex<LazyCountSet>>,
pub unseen: Arc<Mutex<LazyCountSet>>,
pub latest_article: Arc<Mutex<Option<UnixTimestamp>>>,
}
impl NntpMailbox {
pub fn nntp_path(&self) -> &str {
&self.nntp_path
}
}
impl BackendMailbox for NntpMailbox {
fn hash(&self) -> MailboxHash {
self.hash
}
fn name(&self) -> &str {
&self.nntp_path
}
fn path(&self) -> &str {
&self.nntp_path
}
fn children(&self) -> &[MailboxHash] {
&[]
}
fn clone(&self) -> Mailbox {
Box::new(std::clone::Clone::clone(self))
}
fn special_usage(&self) -> SpecialUsageMailbox {
SpecialUsageMailbox::default()
}
fn parent(&self) -> Option<MailboxHash> {
None
}
fn permissions(&self) -> MailboxPermissions {
MailboxPermissions::default()
}
fn is_subscribed(&self) -> bool {
true
}
fn set_is_subscribed(&mut self, _new_val: bool) -> Result<()> {
Err(Error::new("Cannot set subscription in NNTP."))
}
fn set_special_usage(&mut self, _new_val: SpecialUsageMailbox) -> Result<()> {
Err(Error::new("Cannot set special usage in NNTP."))
}
fn count(&self) -> Result<(usize, usize)> {
Ok((self.unseen.lock()?.len(), self.exists.lock()?.len()))
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
}