Browse Source

melib/imap: implement refresh()

async
Manos Pitsidianakis 2 years ago
parent
commit
499fd59c6e
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 2
      melib/src/backends.rs
  2. 50
      melib/src/backends/imap.rs
  3. 2
      melib/src/backends/imap/watch.rs
  4. 4
      melib/src/backends/maildir/backend.rs
  5. 6
      src/plugins/backend.rs

2
melib/src/backends.rs

@ -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(

50
melib/src/backends/imap.rs

@ -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(

2
melib/src/backends/imap/watch.rs

@ -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,

4
melib/src/backends/maildir/backend.rs

@ -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

6
src/plugins/backend.rs

@ -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(

Loading…
Cancel
Save