melib/imap: implement refresh()

This commit is contained in:
Manos Pitsidianakis 2020-02-22 11:24:36 +02:00
parent bbdc9d69b4
commit 499fd59c6e
No known key found for this signature in database
GPG Key ID: 73627C2F690DF710
5 changed files with 48 additions and 16 deletions

View File

@ -251,7 +251,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
&mut self,
_folder_hash: FolderHash,
_sender: RefreshEventConsumer,
) -> Result<Async<Result<Vec<RefreshEvent>>>> {
) -> Result<Async<()>> {
Err(MeliError::new("Unimplemented."))
}
fn watch(

View File

@ -290,13 +290,49 @@ impl MailBackend for ImapType {
fn refresh(
&mut self,
_folder_hash: FolderHash,
_sender: RefreshEventConsumer,
) -> Result<Async<Result<Vec<RefreshEvent>>>> {
let mut res = String::with_capacity(8 * 1024);
self.connection.lock()?.send_command(b"NOOP")?;
self.connection.lock()?.read_response(&mut res)?;
Err(MeliError::new("Unimplemented."))
folder_hash: FolderHash,
sender: RefreshEventConsumer,
) -> Result<Async<()>> {
self.connection.lock().unwrap().connect()?;
let inbox = self
.folders
.read()
.unwrap()
.get(&folder_hash)
.map(std::clone::Clone::clone)
.unwrap();
let tag_index = self.tag_index.clone();
let main_conn = self.connection.clone();
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 = main_conn.lock().unwrap();
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,
&sender,
&mut conn,
&uid_store,
&work_context,
&tag_index,
)
.ok()
.take();
};
Ok(w.build(Box::new(closure)))
}
fn watch(

View File

@ -516,7 +516,7 @@ pub fn idle(kit: ImapWatchKit) -> Result<()> {
Err(MeliError::new(format!("IDLE connection dropped: {}", err)))
}
fn examine_updates(
pub fn examine_updates(
folder: &ImapFolder,
sender: &RefreshEventConsumer,
conn: &mut ImapConnection,

View File

@ -196,7 +196,7 @@ impl MailBackend for MaildirType {
&mut self,
folder_hash: FolderHash,
sender: RefreshEventConsumer,
) -> Result<Async<Result<Vec<RefreshEvent>>>> {
) -> Result<Async<()>> {
let w = AsyncBuilder::new();
let cache_dir = xdg::BaseDirectories::with_profile("meli", &self.name).unwrap();
@ -207,8 +207,6 @@ impl MailBackend for MaildirType {
let root_path = self.path.to_path_buf();
let map = self.hash_indexes.clone();
let folder_index = self.folder_index.clone();
let cache_dir = cache_dir.clone();
let sender = Arc::new(sender);
Box::new(move |work_context: crate::async_workers::WorkContext| {
work_context

View File

@ -23,9 +23,7 @@ use super::*;
use fnv::FnvHashMap;
use melib::async_workers::{Async, AsyncBuilder, AsyncStatus, WorkContext};
use melib::backends::FolderHash;
use melib::backends::{
Backend, BackendOp, Backends, Folder, MailBackend, RefreshEvent, RefreshEventConsumer,
};
use melib::backends::{Backend, BackendOp, Backends, Folder, MailBackend, RefreshEventConsumer};
use melib::conf::AccountSettings;
use melib::email::{Envelope, EnvelopeHash, Flag};
use melib::error::{MeliError, Result};
@ -184,7 +182,7 @@ impl MailBackend for PluginBackend {
&mut self,
_folder_hash: FolderHash,
_sender: RefreshEventConsumer,
) -> Result<Async<Result<Vec<RefreshEvent>>>> {
) -> Result<Async<()>> {
Err(MeliError::new("Unimplemented."))
}
fn watch(