Respect autoload mailbox setting
parent
106dae3334
commit
651dda67cf
|
@ -218,7 +218,9 @@ example:
|
||||||
.It Ic alias Ar String
|
.It Ic alias Ar String
|
||||||
(optional) show a different name for this mailbox in the UI
|
(optional) show a different name for this mailbox in the UI
|
||||||
.It Ic autoload Ar boolean
|
.It Ic autoload Ar boolean
|
||||||
(optional) load this mailbox on startup (not functional yet)
|
(optional) load this mailbox on startup
|
||||||
|
.\" default value
|
||||||
|
.Pq Em true
|
||||||
.It Ic subscribe Ar boolean
|
.It Ic subscribe Ar boolean
|
||||||
(optional) watch this mailbox for updates
|
(optional) watch this mailbox for updates
|
||||||
.\" default value
|
.\" default value
|
||||||
|
|
|
@ -391,6 +391,13 @@ impl Collection {
|
||||||
pub fn contains_key(&self, env_hash: &EnvelopeHash) -> bool {
|
pub fn contains_key(&self, env_hash: &EnvelopeHash) -> bool {
|
||||||
self.envelopes.read().unwrap().contains_key(env_hash)
|
self.envelopes.read().unwrap().contains_key(env_hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_mailbox(&mut self, mailbox_hash: MailboxHash) {
|
||||||
|
if !self.mailboxes.contains_key(&mailbox_hash) {
|
||||||
|
self.mailboxes.insert(mailbox_hash, Default::default());
|
||||||
|
self.threads.insert(mailbox_hash, Threads::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index<&MailboxHash> for Collection {
|
impl Index<&MailboxHash> for Collection {
|
||||||
|
|
|
@ -1010,8 +1010,11 @@ impl Listing {
|
||||||
|
|
||||||
for (i, &(depth, mailbox_hash)) in a.entries.iter().enumerate() {
|
for (i, &(depth, mailbox_hash)) in a.entries.iter().enumerate() {
|
||||||
if mailboxes[&mailbox_hash].is_subscribed() {
|
if mailboxes[&mailbox_hash].is_subscribed() {
|
||||||
match context.accounts[a.index].status(mailbox_hash) {
|
match context.accounts[a.index][&mailbox_hash].status {
|
||||||
Ok(_) => {
|
crate::conf::accounts::MailboxStatus::Failed(_) => {
|
||||||
|
lines.push((depth, i, mailbox_hash, None));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
lines.push((
|
lines.push((
|
||||||
depth,
|
depth,
|
||||||
i,
|
i,
|
||||||
|
@ -1019,9 +1022,6 @@ impl Listing {
|
||||||
mailboxes[&mailbox_hash].count().ok().map(|(v, _)| v),
|
mailboxes[&mailbox_hash].count().ok().map(|(v, _)| v),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Err(_) => {
|
|
||||||
lines.push((depth, i, mailbox_hash, None));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl MailListingTrait for CompactListing {
|
||||||
|
|
||||||
// Get mailbox as a reference.
|
// Get mailbox as a reference.
|
||||||
//
|
//
|
||||||
match context.accounts[self.cursor_pos.0].status(self.cursor_pos.1) {
|
match context.accounts[self.cursor_pos.0].load(self.cursor_pos.1) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let default_cell = {
|
let default_cell = {
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl MailListingTrait for ConversationsListing {
|
||||||
}
|
}
|
||||||
// Get mailbox as a reference.
|
// Get mailbox as a reference.
|
||||||
//
|
//
|
||||||
match context.accounts[self.cursor_pos.0].status(self.cursor_pos.1) {
|
match context.accounts[self.cursor_pos.0].load(self.cursor_pos.1) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let default_cell = {
|
let default_cell = {
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl MailListingTrait for PlainListing {
|
||||||
|
|
||||||
// Get mailbox as a reference.
|
// Get mailbox as a reference.
|
||||||
//
|
//
|
||||||
match context.accounts[self.cursor_pos.0].status(self.cursor_pos.1) {
|
match context.accounts[self.cursor_pos.0].load(self.cursor_pos.1) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let default_cell = {
|
let default_cell = {
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl MailListingTrait for ThreadListing {
|
||||||
|
|
||||||
// Get mailbox as a reference.
|
// Get mailbox as a reference.
|
||||||
//
|
//
|
||||||
match context.accounts[self.cursor_pos.0].status(self.cursor_pos.1) {
|
match context.accounts[self.cursor_pos.0].load(self.cursor_pos.1) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let default_cell = {
|
let default_cell = {
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub enum MailboxStatus {
|
||||||
|
|
||||||
impl Default for MailboxStatus {
|
impl Default for MailboxStatus {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
MailboxStatus::Parsing(0, 0)
|
MailboxStatus::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ impl MailboxEntry {
|
||||||
match self.status {
|
match self.status {
|
||||||
MailboxStatus::Available => self.name().to_string(),
|
MailboxStatus::Available => self.name().to_string(),
|
||||||
MailboxStatus::Failed(ref e) => e.to_string(),
|
MailboxStatus::Failed(ref e) => e.to_string(),
|
||||||
MailboxStatus::None => "Not subscribed, is this a bug?".to_string(),
|
MailboxStatus::None => "Retrieving mailbox".to_string(),
|
||||||
MailboxStatus::Parsing(done, total) => {
|
MailboxStatus::Parsing(done, total) => {
|
||||||
format!("Parsing messages. [{}/{}]", done, total)
|
format!("Parsing messages. [{}/{}]", done, total)
|
||||||
}
|
}
|
||||||
|
@ -334,6 +334,7 @@ impl Account {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
mailbox_entries.entry(*h).and_modify(|entry| {
|
mailbox_entries.entry(*h).and_modify(|entry| {
|
||||||
|
if entry.conf.mailbox_conf.autoload {
|
||||||
entry.status = MailboxStatus::Parsing(0, 0);
|
entry.status = MailboxStatus::Parsing(0, 0);
|
||||||
entry.worker = Account::new_worker(
|
entry.worker = Account::new_worker(
|
||||||
f.clone(),
|
f.clone(),
|
||||||
|
@ -341,9 +342,9 @@ impl Account {
|
||||||
&self.work_context,
|
&self.work_context,
|
||||||
self.notify_fn.clone(),
|
self.notify_fn.clone(),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
collection.mailboxes.insert(*h, Default::default());
|
collection.new_mailbox(*h);
|
||||||
collection.threads.insert(*h, Threads::default());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build_mailboxes_order(&mut tree, &mailbox_entries, &mut mailboxes_order);
|
build_mailboxes_order(&mut tree, &mailbox_entries, &mut mailboxes_order);
|
||||||
|
@ -716,7 +717,49 @@ impl Account {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_mailbox(&mut self, mailbox_hash: MailboxHash, payload: Result<Vec<Envelope>>) {
|
pub fn load(&mut self, mailbox_hash: MailboxHash) -> result::Result<(), usize> {
|
||||||
|
if mailbox_hash == 0 {
|
||||||
|
return Err(0);
|
||||||
|
}
|
||||||
|
loop {
|
||||||
|
match self
|
||||||
|
.mailbox_entries
|
||||||
|
.get_mut(&mailbox_hash)
|
||||||
|
.unwrap()
|
||||||
|
.worker
|
||||||
|
.as_mut()
|
||||||
|
{
|
||||||
|
None => {
|
||||||
|
return match self.mailbox_entries[&mailbox_hash].status {
|
||||||
|
MailboxStatus::Available | MailboxStatus::Parsing(_, _)
|
||||||
|
if self.collection.mailboxes.contains_key(&mailbox_hash) =>
|
||||||
|
{
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
MailboxStatus::None => {
|
||||||
|
let handle = Account::new_worker(
|
||||||
|
self.mailbox_entries[&mailbox_hash].ref_mailbox.clone(),
|
||||||
|
&mut self.backend,
|
||||||
|
&self.work_context,
|
||||||
|
self.notify_fn.clone(),
|
||||||
|
);
|
||||||
|
self.mailbox_entries
|
||||||
|
.entry(mailbox_hash)
|
||||||
|
.and_modify(|entry| {
|
||||||
|
entry.worker = handle;
|
||||||
|
});
|
||||||
|
self.collection.new_mailbox(mailbox_hash);
|
||||||
|
Err(0)
|
||||||
|
}
|
||||||
|
_ => Err(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(ref mut w) => match debug!(w.poll()) {
|
||||||
|
Ok(AsyncStatus::NoUpdate) => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Ok(AsyncStatus::Payload(payload)) => {
|
||||||
|
debug!("got payload in status for {}", mailbox_hash);
|
||||||
if payload.is_err() {
|
if payload.is_err() {
|
||||||
self.mailbox_entries
|
self.mailbox_entries
|
||||||
.entry(mailbox_hash)
|
.entry(mailbox_hash)
|
||||||
|
@ -726,7 +769,7 @@ impl Account {
|
||||||
self.sender
|
self.sender
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StartupCheck(mailbox_hash)))
|
.send(ThreadEvent::UIEvent(UIEvent::StartupCheck(mailbox_hash)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
return;
|
return Err(0);
|
||||||
}
|
}
|
||||||
let envelopes = payload
|
let envelopes = payload
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -747,37 +790,6 @@ impl Account {
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StartupCheck(mailbox_hash)))
|
.send(ThreadEvent::UIEvent(UIEvent::StartupCheck(mailbox_hash)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn status(&mut self, mailbox_hash: MailboxHash) -> result::Result<(), usize> {
|
|
||||||
if mailbox_hash == 0 {
|
|
||||||
return Err(0);
|
|
||||||
}
|
|
||||||
loop {
|
|
||||||
match self
|
|
||||||
.mailbox_entries
|
|
||||||
.get_mut(&mailbox_hash)
|
|
||||||
.unwrap()
|
|
||||||
.worker
|
|
||||||
.as_mut()
|
|
||||||
{
|
|
||||||
None => {
|
|
||||||
return if self.mailbox_entries[&mailbox_hash].status.is_available()
|
|
||||||
|| (self.mailbox_entries[&mailbox_hash].status.is_parsing()
|
|
||||||
&& self.collection.mailboxes.contains_key(&mailbox_hash))
|
|
||||||
{
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(0)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Some(ref mut w) => match debug!(w.poll()) {
|
|
||||||
Ok(AsyncStatus::NoUpdate) => {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Ok(AsyncStatus::Payload(envs)) => {
|
|
||||||
debug!("got payload in status for {}", mailbox_hash);
|
|
||||||
self.load_mailbox(mailbox_hash, envs);
|
|
||||||
}
|
|
||||||
Ok(AsyncStatus::Finished) => {
|
Ok(AsyncStatus::Finished) => {
|
||||||
debug!("got finished in status for {}", mailbox_hash);
|
debug!("got finished in status for {}", mailbox_hash);
|
||||||
self.mailbox_entries
|
self.mailbox_entries
|
||||||
|
|
19
src/state.rs
19
src/state.rs
|
@ -37,7 +37,6 @@ use fnv::FnvHashMap;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::result;
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use termion::raw::IntoRawMode;
|
use termion::raw::IntoRawMode;
|
||||||
use termion::screen::AlternateScreen;
|
use termion::screen::AlternateScreen;
|
||||||
|
@ -129,20 +128,6 @@ impl Context {
|
||||||
pub fn restore_input(&self) {
|
pub fn restore_input(&self) {
|
||||||
self.input.restore(self.sender.clone());
|
self.input.restore(self.sender.clone());
|
||||||
}
|
}
|
||||||
pub fn account_status(
|
|
||||||
&mut self,
|
|
||||||
idx_a: usize,
|
|
||||||
mailbox_hash: MailboxHash,
|
|
||||||
) -> result::Result<(), usize> {
|
|
||||||
match self.accounts[idx_a].status(mailbox_hash) {
|
|
||||||
Ok(()) => {
|
|
||||||
self.replies
|
|
||||||
.push_back(UIEvent::MailboxUpdate((idx_a, mailbox_hash)));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Err(n) => Err(n),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_online(&mut self, account_pos: usize) -> Result<()> {
|
pub fn is_online(&mut self, account_pos: usize) -> Result<()> {
|
||||||
let Context {
|
let Context {
|
||||||
|
@ -379,7 +364,7 @@ impl State {
|
||||||
pub fn refresh_event(&mut self, event: RefreshEvent) {
|
pub fn refresh_event(&mut self, event: RefreshEvent) {
|
||||||
let hash = event.hash();
|
let hash = event.hash();
|
||||||
if let Some(&idxa) = self.context.mailbox_hashes.get(&hash) {
|
if let Some(&idxa) = self.context.mailbox_hashes.get(&hash) {
|
||||||
if self.context.accounts[idxa].status(hash).is_err() {
|
if self.context.accounts[idxa].load(hash).is_err() {
|
||||||
self.context.replies.push_back(UIEvent::from(event));
|
self.context.replies.push_back(UIEvent::from(event));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -932,7 +917,7 @@ impl State {
|
||||||
}
|
}
|
||||||
UIEvent::WorkerProgress(mailbox_hash) => {
|
UIEvent::WorkerProgress(mailbox_hash) => {
|
||||||
if let Some(&account_idx) = self.context.mailbox_hashes.get(&mailbox_hash) {
|
if let Some(&account_idx) = self.context.mailbox_hashes.get(&mailbox_hash) {
|
||||||
let _ = self.context.accounts[account_idx].status(mailbox_hash);
|
let _ = self.context.accounts[account_idx].load(mailbox_hash);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue