|
|
|
@ -34,9 +34,9 @@ mod watch;
|
|
|
|
|
pub use watch::*;
|
|
|
|
|
mod cache;
|
|
|
|
|
pub mod managesieve;
|
|
|
|
|
//mod untagged;
|
|
|
|
|
mod untagged;
|
|
|
|
|
|
|
|
|
|
use crate::async_workers::{Async, AsyncBuilder, AsyncStatus, WorkContext};
|
|
|
|
|
use crate::async_workers::{Async, WorkContext};
|
|
|
|
|
use crate::backends::BackendOp;
|
|
|
|
|
use crate::backends::RefreshEvent;
|
|
|
|
|
use crate::backends::RefreshEventKind::{self, *};
|
|
|
|
@ -46,7 +46,7 @@ use crate::conf::AccountSettings;
|
|
|
|
|
use crate::email::*;
|
|
|
|
|
use crate::error::{MeliError, Result, ResultIntoMeliError};
|
|
|
|
|
use futures::lock::Mutex as FutureMutex;
|
|
|
|
|
use futures::Stream;
|
|
|
|
|
use futures::stream::Stream;
|
|
|
|
|
use std::collections::{hash_map::DefaultHasher, BTreeMap};
|
|
|
|
|
use std::collections::{BTreeSet, HashMap, HashSet};
|
|
|
|
|
use std::future::Future;
|
|
|
|
@ -174,9 +174,6 @@ pub struct ImapType {
|
|
|
|
|
can_create_flags: Arc<Mutex<bool>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use futures::pin_mut;
|
|
|
|
|
use futures::stream::StreamExt;
|
|
|
|
|
|
|
|
|
|
impl MailBackend for ImapType {
|
|
|
|
|
fn get_async(
|
|
|
|
|
&mut self,
|
|
|
|
@ -315,392 +312,22 @@ impl MailBackend for ImapType {
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get(&mut self, mailbox: &Mailbox) -> Async<Result<Vec<Envelope>>> {
|
|
|
|
|
fn get(&mut self, _mailbox: &Mailbox) -> Async<Result<Vec<Envelope>>> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
|
let mut w = AsyncBuilder::new();
|
|
|
|
|
let handle = {
|
|
|
|
|
let tx = w.tx();
|
|
|
|
|
let uid_store = self.uid_store.clone();
|
|
|
|
|
let can_create_flags = self.can_create_flags.clone();
|
|
|
|
|
let mailbox_hash = mailbox.hash();
|
|
|
|
|
let (permissions, mailbox_path, mailbox_exists, no_select, unseen) = {
|
|
|
|
|
let f = &self.uid_store.mailboxes.read().unwrap()[&mailbox_hash];
|
|
|
|
|
(
|
|
|
|
|
f.permissions.clone(),
|
|
|
|
|
f.imap_path().to_string(),
|
|
|
|
|
f.exists.clone(),
|
|
|
|
|
f.no_select,
|
|
|
|
|
f.unseen.clone(),
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
let connection = self.connection.clone();
|
|
|
|
|
let closure = move |_work_context| {
|
|
|
|
|
if no_select {
|
|
|
|
|
tx.send(AsyncStatus::Payload(Ok(Vec::new()))).unwrap();
|
|
|
|
|
tx.send(AsyncStatus::Finished).unwrap();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let _tx = tx.clone();
|
|
|
|
|
if let Err(err) = (move || {
|
|
|
|
|
let tx = _tx;
|
|
|
|
|
let mut our_unseen: BTreeSet<EnvelopeHash> = Default::default();
|
|
|
|
|
let mut valid_hash_set: HashSet<EnvelopeHash> = HashSet::default();
|
|
|
|
|
let cached_hash_set: HashSet<EnvelopeHash> =
|
|
|
|
|
(|| -> Result<HashSet<EnvelopeHash>> {
|
|
|
|
|
if !uid_store.cache_headers {
|
|
|
|
|
return Ok(HashSet::default());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let uidvalidities = uid_store.uidvalidity.lock().unwrap();
|
|
|
|
|
|
|
|
|
|
let v = if let Some(v) = uidvalidities.get(&mailbox_hash) {
|
|
|
|
|
v
|
|
|
|
|
} else {
|
|
|
|
|
return Ok(HashSet::default());
|
|
|
|
|
};
|
|
|
|
|
let cached_envs: (cache::MaxUID, Vec<(UID, Envelope)>);
|
|
|
|
|
cache::save_envelopes(uid_store.account_hash, mailbox_hash, *v, &[])
|
|
|
|
|
.chain_err_summary(|| {
|
|
|
|
|
"Could not save envelopes in cache in get()"
|
|
|
|
|
})?;
|
|
|
|
|
cached_envs =
|
|
|
|
|
cache::get_envelopes(uid_store.account_hash, mailbox_hash, *v)
|
|
|
|
|
.chain_err_summary(|| {
|
|
|
|
|
"Could not get envelopes in cache in get()"
|
|
|
|
|
})?;
|
|
|
|
|
let (_max_uid, envelopes) = debug!(cached_envs);
|
|
|
|
|
let ret = envelopes.iter().map(|(_, env)| env.hash()).collect();
|
|
|
|
|
if !envelopes.is_empty() {
|
|
|
|
|
let mut payload = vec![];
|
|
|
|
|
for (uid, env) in envelopes {
|
|
|
|
|
if !env.is_seen() {
|
|
|
|
|
our_unseen.insert(env.hash());
|
|
|
|
|
}
|
|
|
|
|
uid_store
|
|
|
|
|
.hash_index
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.insert(env.hash(), (uid, mailbox_hash));
|
|
|
|
|
uid_store
|
|
|
|
|
.uid_index
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.insert((mailbox_hash, uid), env.hash());
|
|
|
|
|
payload.push(env);
|
|
|
|
|
}
|
|
|
|
|
debug!("sending cached payload for {}", mailbox_hash);
|
|
|
|
|
|
|
|
|
|
unseen.lock().unwrap().insert_set(our_unseen.clone());
|
|
|
|
|
tx.send(AsyncStatus::Payload(Ok(payload))).unwrap();
|
|
|
|
|
}
|
|
|
|
|
Ok(ret)
|
|
|
|
|
})()
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
|
|
|
|
|
let mut conn = connection.lock()?;
|
|
|
|
|
debug!("locked for get {}", mailbox_path);
|
|
|
|
|
let mut response = String::with_capacity(8 * 1024);
|
|
|
|
|
|
|
|
|
|
conn.create_uid_msn_cache(mailbox_hash, 1);
|
|
|
|
|
/* first SELECT the mailbox to get READ/WRITE permissions (because EXAMINE only
|
|
|
|
|
* returns READ-ONLY for both cases) */
|
|
|
|
|
conn.select_mailbox(mailbox_hash, &mut response)
|
|
|
|
|
.chain_err_summary(|| {
|
|
|
|
|
format!("Could not select mailbox {}", mailbox_path)
|
|
|
|
|
})?;
|
|
|
|
|
let mut examine_response = protocol_parser::select_response(&response)
|
|
|
|
|
.chain_err_summary(|| {
|
|
|
|
|
format!(
|
|
|
|
|
"Could not parse select response for mailbox {}",
|
|
|
|
|
mailbox_path
|
|
|
|
|
)
|
|
|
|
|
})?;
|
|
|
|
|
*can_create_flags.lock().unwrap() = examine_response.can_create_flags;
|
|
|
|
|
debug!(
|
|
|
|
|
"mailbox: {} examine_response: {:?}",
|
|
|
|
|
mailbox_path, examine_response
|
|
|
|
|
);
|
|
|
|
|
{
|
|
|
|
|
let mut uidvalidities = uid_store.uidvalidity.lock().unwrap();
|
|
|
|
|
|
|
|
|
|
let v = uidvalidities
|
|
|
|
|
.entry(mailbox_hash)
|
|
|
|
|
.or_insert(examine_response.uidvalidity);
|
|
|
|
|
if uid_store.cache_headers {
|
|
|
|
|
let _ = cache::save_envelopes(
|
|
|
|
|
uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
examine_response.uidvalidity,
|
|
|
|
|
&[],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
*v = examine_response.uidvalidity;
|
|
|
|
|
let mut permissions = permissions.lock().unwrap();
|
|
|
|
|
permissions.create_messages = !examine_response.read_only;
|
|
|
|
|
permissions.remove_messages = !examine_response.read_only;
|
|
|
|
|
permissions.set_flags = !examine_response.read_only;
|
|
|
|
|
permissions.rename_messages = !examine_response.read_only;
|
|
|
|
|
permissions.delete_messages = !examine_response.read_only;
|
|
|
|
|
permissions.delete_messages = !examine_response.read_only;
|
|
|
|
|
mailbox_exists
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.set_not_yet_seen(examine_response.exists);
|
|
|
|
|
}
|
|
|
|
|
if examine_response.exists == 0 {
|
|
|
|
|
if uid_store.cache_headers {
|
|
|
|
|
for &env_hash in &cached_hash_set {
|
|
|
|
|
conn.add_refresh_event(RefreshEvent {
|
|
|
|
|
account_hash: uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
kind: RefreshEventKind::Remove(env_hash),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
let _ = cache::save_envelopes(
|
|
|
|
|
uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
examine_response.uidvalidity,
|
|
|
|
|
&[],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
tx.send(AsyncStatus::Payload(Ok(Vec::new()))).unwrap();
|
|
|
|
|
tx.send(AsyncStatus::Finished).unwrap();
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
/* reselecting the same mailbox with EXAMINE prevents expunging it */
|
|
|
|
|
conn.examine_mailbox(mailbox_hash, &mut response)?;
|
|
|
|
|
if examine_response.uidnext == 0 {
|
|
|
|
|
/* UIDNEXT shouldn't be 0, since exists != 0 at this point */
|
|
|
|
|
conn.send_command(
|
|
|
|
|
format!("STATUS \"{}\" (UIDNEXT)", mailbox_path).as_bytes(),
|
|
|
|
|
)?;
|
|
|
|
|
conn.read_response(&mut response, RequiredResponses::STATUS)?;
|
|
|
|
|
let (_, status) = protocol_parser::status_response(response.as_bytes())?;
|
|
|
|
|
if let Some(uidnext) = status.uidnext {
|
|
|
|
|
if uidnext == 0 {
|
|
|
|
|
return Err(MeliError::new(
|
|
|
|
|
"IMAP server error: zero UIDNEXt with nonzero exists.",
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
examine_response.uidnext = uidnext;
|
|
|
|
|
} else {
|
|
|
|
|
return Err(MeliError::new("IMAP server did not reply with UIDNEXT"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let mut max_uid_left: usize = examine_response.uidnext - 1;
|
|
|
|
|
|
|
|
|
|
let mut tag_lck = uid_store.tag_index.write().unwrap();
|
|
|
|
|
|
|
|
|
|
while max_uid_left > 0 {
|
|
|
|
|
let mut envelopes = vec![];
|
|
|
|
|
debug!("{} max_uid_left= {}", mailbox_hash, max_uid_left);
|
|
|
|
|
if max_uid_left == 1 {
|
|
|
|
|
debug!("UID FETCH 1 (UID FLAGS ENVELOPE BODYSTRUCTURE)");
|
|
|
|
|
conn.send_command(b"UID FETCH 1 (UID FLAGS ENVELOPE BODYSTRUCTURE)")?;
|
|
|
|
|
} else {
|
|
|
|
|
conn.send_command(
|
|
|
|
|
debug!(format!(
|
|
|
|
|
"UID FETCH {}:{} (UID FLAGS ENVELOPE BODYSTRUCTURE)",
|
|
|
|
|
std::cmp::max(
|
|
|
|
|
std::cmp::max(max_uid_left.saturating_sub(500), 1),
|
|
|
|
|
1
|
|
|
|
|
),
|
|
|
|
|
max_uid_left
|
|
|
|
|
))
|
|
|
|
|
.as_bytes(),
|
|
|
|
|
)?
|
|
|
|
|
};
|
|
|
|
|
conn.read_response(&mut response, RequiredResponses::FETCH_REQUIRED)
|
|
|
|
|
.chain_err_summary(|| {
|
|
|
|
|
format!(
|
|
|
|
|
"Could not parse fetch response for mailbox {}",
|
|
|
|
|
mailbox_path
|
|
|
|
|
)
|
|
|
|
|
})?;
|
|
|
|
|
debug!(
|
|
|
|
|
"fetch response is {} bytes and {} lines",
|
|
|
|
|
response.len(),
|
|
|
|
|
response.lines().collect::<Vec<&str>>().len()
|
|
|
|
|
);
|
|
|
|
|
let (_, v, _) = protocol_parser::uid_fetch_responses(&response)?;
|
|
|
|
|
debug!("responses len is {}", v.len());
|
|
|
|
|
for UidFetchResponse {
|
|
|
|
|
uid,
|
|
|
|
|
message_sequence_number,
|
|
|
|
|
flags,
|
|
|
|
|
envelope,
|
|
|
|
|
..
|
|
|
|
|
} in v
|
|
|
|
|
{
|
|
|
|
|
let mut env = envelope.unwrap();
|
|
|
|
|
let mut h = DefaultHasher::new();
|
|
|
|
|
h.write_usize(uid);
|
|
|
|
|
h.write(mailbox_path.as_bytes());
|
|
|
|
|
env.set_hash(h.finish());
|
|
|
|
|
debug!(
|
|
|
|
|
"env hash {} {} UID = {} MSN = {}",
|
|
|
|
|
env.hash(),
|
|
|
|
|
env.subject(),
|
|
|
|
|
uid,
|
|
|
|
|
message_sequence_number
|
|
|
|
|
);
|
|
|
|
|
valid_hash_set.insert(env.hash());
|
|
|
|
|
if let Some((flags, keywords)) = flags {
|
|
|
|
|
if !flags.intersects(Flag::SEEN) {
|
|
|
|
|
our_unseen.insert(env.hash());
|
|
|
|
|
}
|
|
|
|
|
env.set_flags(flags);
|
|
|
|
|
for f in keywords {
|
|
|
|
|
let hash = tag_hash!(f);
|
|
|
|
|
if !tag_lck.contains_key(&hash) {
|
|
|
|
|
tag_lck.insert(hash, f);
|
|
|
|
|
}
|
|
|
|
|
env.labels_mut().push(hash);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
uid_store
|
|
|
|
|
.msn_index
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.entry(mailbox_hash)
|
|
|
|
|
.or_default()
|
|
|
|
|
.insert(message_sequence_number - 1, uid);
|
|
|
|
|
uid_store
|
|
|
|
|
.hash_index
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.insert(env.hash(), (uid, mailbox_hash));
|
|
|
|
|
uid_store
|
|
|
|
|
.uid_index
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.insert((mailbox_hash, uid), env.hash());
|
|
|
|
|
envelopes.push((uid, env));
|
|
|
|
|
}
|
|
|
|
|
max_uid_left =
|
|
|
|
|
std::cmp::max(std::cmp::max(max_uid_left.saturating_sub(500), 1), 1);
|
|
|
|
|
debug!("sending payload for {}", mailbox_hash);
|
|
|
|
|
if uid_store.cache_headers {
|
|
|
|
|
cache::save_envelopes(
|
|
|
|
|
uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
examine_response.uidvalidity,
|
|
|
|
|
&envelopes
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|(uid, env)| (*uid, env))
|
|
|
|
|
.collect::<SmallVec<[(UID, &Envelope); 1024]>>(),
|
|
|
|
|
)
|
|
|
|
|
.chain_err_summary(|| {
|
|
|
|
|
format!(
|
|
|
|
|
"Could not save envelopes in cache for mailbox {}",
|
|
|
|
|
mailbox_path
|
|
|
|
|
)
|
|
|
|
|
})?;
|
|
|
|
|
}
|
|
|
|
|
for &env_hash in cached_hash_set.difference(&valid_hash_set) {
|
|
|
|
|
conn.add_refresh_event(RefreshEvent {
|
|
|
|
|
account_hash: uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
kind: RefreshEventKind::Remove(env_hash),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
let progress = envelopes.len();
|
|
|
|
|
unseen
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.insert_set(our_unseen.iter().cloned().collect());
|
|
|
|
|
mailbox_exists.lock().unwrap().insert_existing_set(
|
|
|
|
|
envelopes.iter().map(|(_, env)| env.hash()).collect::<_>(),
|
|
|
|
|
);
|
|
|
|
|
tx.send(AsyncStatus::Payload(Ok(envelopes
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|(_, env)| env)
|
|
|
|
|
.collect::<Vec<Envelope>>())))
|
|
|
|
|
.unwrap();
|
|
|
|
|
tx.send(AsyncStatus::ProgressReport(progress)).unwrap();
|
|
|
|
|
if max_uid_left == 1 {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
drop(conn);
|
|
|
|
|
Ok(())
|
|
|
|
|
})() {
|
|
|
|
|
debug!("sending error payload for {}: {:?}", mailbox_hash, &err);
|
|
|
|
|
tx.send(AsyncStatus::Payload(Err(err))).unwrap();
|
|
|
|
|
}
|
|
|
|
|
tx.send(AsyncStatus::Finished).unwrap();
|
|
|
|
|
};
|
|
|
|
|
Box::new(closure)
|
|
|
|
|
};
|
|
|
|
|
w.build(handle)
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn refresh(
|
|
|
|
|
&mut self,
|
|
|
|
|
mailbox_hash: MailboxHash,
|
|
|
|
|
sender: RefreshEventConsumer,
|
|
|
|
|
_mailbox_hash: MailboxHash,
|
|
|
|
|
_sender: RefreshEventConsumer,
|
|
|
|
|
) -> Result<Async<()>> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
|
let inbox = self
|
|
|
|
|
.uid_store
|
|
|
|
|
.mailboxes
|
|
|
|
|
.read()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.get(&mailbox_hash)
|
|
|
|
|
.map(std::clone::Clone::clone)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let main_conn = self.connection.clone();
|
|
|
|
|
*self.uid_store.sender.write().unwrap() = Some(sender);
|
|
|
|
|
let uid_store = self.uid_store.clone();
|
|
|
|
|
let account_name = self.account_name.clone();
|
|
|
|
|
let w = AsyncBuilder::new();
|
|
|
|
|
let closure = move |work_context: WorkContext| {
|
|
|
|
|
let thread = std::thread::current();
|
|
|
|
|
let mut conn = match try_lock(&main_conn, Some(std::time::Duration::new(2, 0))) {
|
|
|
|
|
Ok(conn) => conn,
|
|
|
|
|
Err(err) => {
|
|
|
|
|
uid_store
|
|
|
|
|
.sender
|
|
|
|
|
.read()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.as_ref()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.send(RefreshEvent {
|
|
|
|
|
account_hash: uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
kind: RefreshEventKind::Failure(err.clone()),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
work_context
|
|
|
|
|
.set_name
|
|
|
|
|
.send((
|
|
|
|
|
thread.id(),
|
|
|
|
|
format!("refreshing {} imap connection", account_name.as_str(),),
|
|
|
|
|
))
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
work_context
|
|
|
|
|
.set_status
|
|
|
|
|
.send((thread.id(), "refresh".to_string()))
|
|
|
|
|
.unwrap();
|
|
|
|
|
//watch::examine_updates(&inbox, &mut conn, &uid_store, &work_context)
|
|
|
|
|
// .ok()
|
|
|
|
|
// .take();
|
|
|
|
|
};
|
|
|
|
|
Ok(w.build(Box::new(closure)))
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn watch(
|
|
|
|
|
&self,
|
|
|
|
|
sender: RefreshEventConsumer,
|
|
|
|
|
work_context: WorkContext,
|
|
|
|
|
_sender: RefreshEventConsumer,
|
|
|
|
|
_work_context: WorkContext,
|
|
|
|
|
) -> Result<std::thread::ThreadId> {
|
|
|
|
|
Ok(std::thread::current().id())
|
|
|
|
|
//Err(MeliError::new("Unimplemented."))
|
|
|
|
@ -742,51 +369,6 @@ impl MailBackend for ImapType {
|
|
|
|
|
|
|
|
|
|
fn mailboxes(&self) -> Result<HashMap<MailboxHash, Mailbox>> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
|
{
|
|
|
|
|
let mailboxes = self.uid_store.mailboxes.read().unwrap();
|
|
|
|
|
if !mailboxes.is_empty() {
|
|
|
|
|
return Ok(mailboxes
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|(h, f)| (*h, Box::new(Clone::clone(f)) as Mailbox))
|
|
|
|
|
.collect());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let new_mailboxes = ImapType::imap_mailboxes(&self.connection)?;
|
|
|
|
|
let mut mailboxes = self.uid_store.mailboxes.write()?;
|
|
|
|
|
*mailboxes = new_mailboxes;
|
|
|
|
|
let mut invalid_configs = vec![];
|
|
|
|
|
for m in mailboxes.values() {
|
|
|
|
|
if m.is_subscribed() != (self.is_subscribed)(m.path()) {
|
|
|
|
|
invalid_configs.push((m.path(), m.is_subscribed()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !invalid_configs.is_empty() {
|
|
|
|
|
let mut err_string = format!("{}: ", self.account_name);
|
|
|
|
|
for (m, server_value) in invalid_configs.iter() {
|
|
|
|
|
err_string.extend(format!(
|
|
|
|
|
"Mailbox `{}` is {}subscribed on server but {}subscribed in your configuration. These settings have to match.\n",
|
|
|
|
|
if *server_value { "" } else { "not " },
|
|
|
|
|
if *server_value { "not " } else { "" },
|
|
|
|
|
m
|
|
|
|
|
).chars());
|
|
|
|
|
}
|
|
|
|
|
return Err(MeliError::new(err_string));
|
|
|
|
|
}
|
|
|
|
|
mailboxes.retain(|_, f| (self.is_subscribed)(f.path()));
|
|
|
|
|
let keys = mailboxes.keys().cloned().collect::<HashSet<MailboxHash>>();
|
|
|
|
|
let mut uid_lock = self.uid_store.uidvalidity.lock().unwrap();
|
|
|
|
|
for f in mailboxes.values_mut() {
|
|
|
|
|
uid_lock.entry(f.hash()).or_default();
|
|
|
|
|
f.children.retain(|c| keys.contains(c));
|
|
|
|
|
}
|
|
|
|
|
drop(uid_lock);
|
|
|
|
|
Ok(mailboxes
|
|
|
|
|
.iter()
|
|
|
|
|
.filter(|(_, f)| f.is_subscribed)
|
|
|
|
|
.map(|(h, f)| (*h, Box::new(Clone::clone(f)) as Mailbox))
|
|
|
|
|
.collect())
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn operation(&self, hash: EnvelopeHash) -> Result<Box<dyn BackendOp>> {
|
|
|
|
@ -810,7 +392,7 @@ impl MailBackend for ImapType {
|
|
|
|
|
)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn save(&self, bytes: &[u8], mailbox_hash: MailboxHash, flags: Option<Flag>) -> Result<()> {
|
|
|
|
|
fn save(&self, _bytes: &[u8], _mailbox_hash: MailboxHash, _flags: Option<Flag>) -> Result<()> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
|
let path = {
|
|
|
|
@ -867,7 +449,7 @@ impl MailBackend for ImapType {
|
|
|
|
|
|
|
|
|
|
fn create_mailbox(
|
|
|
|
|
&mut self,
|
|
|
|
|
mut path: String,
|
|
|
|
|
_path: String,
|
|
|
|
|
) -> Result<(MailboxHash, HashMap<MailboxHash, Mailbox>)> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
@ -924,7 +506,7 @@ impl MailBackend for ImapType {
|
|
|
|
|
|
|
|
|
|
fn delete_mailbox(
|
|
|
|
|
&mut self,
|
|
|
|
|
mailbox_hash: MailboxHash,
|
|
|
|
|
_mailbox_hash: MailboxHash,
|
|
|
|
|
) -> Result<HashMap<MailboxHash, Mailbox>> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
@ -967,7 +549,11 @@ impl MailBackend for ImapType {
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_mailbox_subscription(&mut self, mailbox_hash: MailboxHash, new_val: bool) -> Result<()> {
|
|
|
|
|
fn set_mailbox_subscription(
|
|
|
|
|
&mut self,
|
|
|
|
|
_mailbox_hash: MailboxHash,
|
|
|
|
|
_new_val: bool,
|
|
|
|
|
) -> Result<()> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
|
let mut mailboxes = self.uid_store.mailboxes.write().unwrap();
|
|
|
|
@ -1000,11 +586,7 @@ impl MailBackend for ImapType {
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn rename_mailbox(
|
|
|
|
|
&mut self,
|
|
|
|
|
mailbox_hash: MailboxHash,
|
|
|
|
|
mut new_path: String,
|
|
|
|
|
) -> Result<Mailbox> {
|
|
|
|
|
fn rename_mailbox(&mut self, _mailbox_hash: MailboxHash, _new_path: String) -> Result<Mailbox> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
|
let mut mailboxes = self.uid_store.mailboxes.write().unwrap();
|
|
|
|
@ -1045,7 +627,7 @@ impl MailBackend for ImapType {
|
|
|
|
|
|
|
|
|
|
fn set_mailbox_permissions(
|
|
|
|
|
&mut self,
|
|
|
|
|
mailbox_hash: MailboxHash,
|
|
|
|
|
_mailbox_hash: MailboxHash,
|
|
|
|
|
_val: crate::backends::MailboxPermissions,
|
|
|
|
|
) -> Result<()> {
|
|
|
|
|
unimplemented!()
|
|
|
|
@ -1062,8 +644,8 @@ impl MailBackend for ImapType {
|
|
|
|
|
|
|
|
|
|
fn search(
|
|
|
|
|
&self,
|
|
|
|
|
query: crate::search::Query,
|
|
|
|
|
mailbox_hash: Option<MailboxHash>,
|
|
|
|
|
_query: crate::search::Query,
|
|
|
|
|
_mailbox_hash: Option<MailboxHash>,
|
|
|
|
|
) -> Result<SmallVec<[EnvelopeHash; 512]>> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
/*
|
|
|
|
@ -1455,116 +1037,6 @@ fn get_cached_envs(
|
|
|
|
|
Ok((ret, payload))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn get_initial_max_uid(
|
|
|
|
|
connection: &Arc<FutureMutex<ImapConnection>>,
|
|
|
|
|
mailbox_hash: MailboxHash,
|
|
|
|
|
cached_hash_set: &HashSet<EnvelopeHash>,
|
|
|
|
|
can_create_flags: &Arc<Mutex<bool>>,
|
|
|
|
|
our_unseen: &mut BTreeSet<EnvelopeHash>,
|
|
|
|
|
valid_hash_set: &mut HashSet<EnvelopeHash>,
|
|
|
|
|
uid_store: &UIDStore,
|
|
|
|
|
) -> Result<usize> {
|
|
|
|
|
let (permissions, mailbox_path, mailbox_exists, no_select, unseen) = {
|
|
|
|
|
let f = &uid_store.mailboxes.read().unwrap()[&mailbox_hash];
|
|
|
|
|
(
|
|
|
|
|
f.permissions.clone(),
|
|
|
|
|
f.imap_path().to_string(),
|
|
|
|
|
f.exists.clone(),
|
|
|
|
|
f.no_select,
|
|
|
|
|
f.unseen.clone(),
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
let mut conn = connection.lock().await;
|
|
|
|
|
debug!("locked for get {}", mailbox_path);
|
|
|
|
|
let mut response = String::with_capacity(8 * 1024);
|
|
|
|
|
|
|
|
|
|
conn.create_uid_msn_cache(mailbox_hash, 1).await?;
|
|
|
|
|
/* first SELECT the mailbox to get READ/WRITE permissions (because EXAMINE only
|
|
|
|
|
* returns READ-ONLY for both cases) */
|
|
|
|
|
conn.select_mailbox(mailbox_hash, &mut response, true)
|
|
|
|
|
.await
|
|
|
|
|
.chain_err_summary(|| format!("Could not select mailbox {}", mailbox_path))?;
|
|
|
|
|
let mut examine_response =
|
|
|
|
|
protocol_parser::select_response(&response).chain_err_summary(|| {
|
|
|
|
|
format!(
|
|
|
|
|
"Could not parse select response for mailbox {}",
|
|
|
|
|
mailbox_path
|
|
|
|
|
)
|
|
|
|
|
})?;
|
|
|
|
|
*can_create_flags.lock().unwrap() = examine_response.can_create_flags;
|
|
|
|
|
debug!(
|
|
|
|
|
"mailbox: {} examine_response: {:?}",
|
|
|
|
|
mailbox_path, examine_response
|
|
|
|
|
);
|
|
|
|
|
{
|
|
|
|
|
let mut uidvalidities = uid_store.uidvalidity.lock().unwrap();
|
|
|
|
|
|
|
|
|
|
let v = uidvalidities
|
|
|
|
|
.entry(mailbox_hash)
|
|
|
|
|
.or_insert(examine_response.uidvalidity);
|
|
|
|
|
if uid_store.cache_headers {
|
|
|
|
|
let _ = cache::save_envelopes(
|
|
|
|
|
uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
examine_response.uidvalidity,
|
|
|
|
|
&[],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
*v = examine_response.uidvalidity;
|
|
|
|
|
let mut permissions = permissions.lock().unwrap();
|
|
|
|
|
permissions.create_messages = !examine_response.read_only;
|
|
|
|
|
permissions.remove_messages = !examine_response.read_only;
|
|
|
|
|
permissions.set_flags = !examine_response.read_only;
|
|
|
|
|
permissions.rename_messages = !examine_response.read_only;
|
|
|
|
|
permissions.delete_messages = !examine_response.read_only;
|
|
|
|
|
permissions.delete_messages = !examine_response.read_only;
|
|
|
|
|
mailbox_exists
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.set_not_yet_seen(examine_response.exists);
|
|
|
|
|
}
|
|
|
|
|
if examine_response.exists == 0 {
|
|
|
|
|
if uid_store.cache_headers {
|
|
|
|
|
for &env_hash in cached_hash_set {
|
|
|
|
|
conn.add_refresh_event(RefreshEvent {
|
|
|
|
|
account_hash: uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
kind: RefreshEventKind::Remove(env_hash),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
let _ = cache::save_envelopes(
|
|
|
|
|
uid_store.account_hash,
|
|
|
|
|
mailbox_hash,
|
|
|
|
|
examine_response.uidvalidity,
|
|
|
|
|
&[],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Ok(0);
|
|
|
|
|
}
|
|
|
|
|
/* reselecting the same mailbox with EXAMINE prevents expunging it */
|
|
|
|
|
conn.examine_mailbox(mailbox_hash, &mut response, false)
|
|
|
|
|
.await?;
|
|
|
|
|
if examine_response.uidnext == 0 {
|
|
|
|
|
/* UIDNEXT shouldn't be 0, since exists != 0 at this point */
|
|
|
|
|
conn.send_command(format!("STATUS \"{}\" (UIDNEXT)", mailbox_path).as_bytes())
|
|
|
|
|
.await?;
|
|
|
|
|
conn.read_response(&mut response, RequiredResponses::STATUS)
|
|
|
|
|
.await?;
|
|
|
|
|
let (_, status) = protocol_parser::status_response(response.as_bytes())?;
|
|
|
|
|
if let Some(uidnext) = status.uidnext {
|
|
|
|
|
if uidnext == 0 {
|
|
|
|
|
return Err(MeliError::new(
|
|
|
|
|
"IMAP server error: zero UIDNEXt with nonzero exists.",
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
examine_response.uidnext = uidnext;
|
|
|
|
|
} else {
|
|
|
|
|
return Err(MeliError::new("IMAP server did not reply with UIDNEXT"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(examine_response.uidnext - 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn get_hlpr(
|
|
|
|
|
connection: &Arc<FutureMutex<ImapConnection>>,
|
|
|
|
|
mailbox_hash: MailboxHash,
|
|
|
|
@ -1585,6 +1057,10 @@ async fn get_hlpr(
|
|
|
|
|
f.unseen.clone(),
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
if no_select {
|
|
|
|
|
*max_uid = Some(0);
|
|
|
|
|
return Ok(Vec::new());
|
|
|
|
|
}
|
|
|
|
|
let mut conn = connection.lock().await;
|
|
|
|
|
debug!("locked for get {}", mailbox_path);
|
|
|
|
|
let mut response = String::with_capacity(8 * 1024);
|
|
|
|
|