melib: move backends out of the backends module

No reason to have such a deep module tree.
pull/262/head
Manos Pitsidianakis 2023-07-22 22:16:01 +03:00
parent 9216e7bc65
commit 1e084c1d85
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
49 changed files with 97 additions and 78 deletions

View File

@ -460,7 +460,7 @@ define_commands!([
let (input, _) = is_a(" ")(input)?;
let (input, path) = quoted_argument(input.trim())?;
let (input, _) = eof(input)?;
Ok((input, Listing(ExportMbox(Some(melib::backends::mbox::MboxFormat::MboxCl2), path.to_string().into()))))
Ok((input, Listing(ExportMbox(Some(melib::mbox::MboxFormat::MboxCl2), path.to_string().into()))))
}
)
},

View File

@ -49,7 +49,7 @@ pub enum ListingAction {
MoveTo(MailboxPath),
MoveToOtherAccount(AccountName, MailboxPath),
Import(PathBuf, MailboxPath),
ExportMbox(Option<melib::backends::mbox::MboxFormat>, PathBuf),
ExportMbox(Option<melib::mbox::MboxFormat>, PathBuf),
Delete,
OpenInNewTab,
Tag(TagAction),

View File

@ -670,7 +670,7 @@ pub trait MailListingTrait: ListingTrait {
let fut: Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>> =
Box::pin(async move {
let cl = async move {
use melib::backends::mbox::MboxMetadata;
use melib::mbox::MboxMetadata;
let bytes: Vec<Vec<u8>> = try_join_all(futures?).await?;
let envs: Vec<_> = envs_to_set
.iter()

View File

@ -31,7 +31,7 @@ extern crate serde_json;
extern crate smallvec;
extern crate termion;
use melib::{backends::imap::managesieve::ManageSieveConnection, Result};
use melib::{imap::managesieve::ManageSieveConnection, Result};
#[macro_use]
pub mod types;

View File

@ -22,20 +22,6 @@
pub mod utf7;
use smallvec::SmallVec;
#[cfg(feature = "imap")]
pub mod imap;
#[cfg(feature = "nntp")]
pub mod nntp;
#[cfg(feature = "notmuch")]
pub mod notmuch;
#[cfg(feature = "notmuch")]
pub use self::notmuch::NotmuchDb;
#[cfg(feature = "jmap")]
pub mod jmap;
#[cfg(feature = "maildir")]
pub mod maildir;
#[cfg(feature = "mbox")]
pub mod mbox;
use std::{
any::Any,
borrow::Cow,
@ -45,20 +31,13 @@ use std::{
future::Future,
ops::Deref,
pin::Pin,
sync::{Arc, RwLock},
sync::Arc,
};
use futures::stream::Stream;
#[cfg(feature = "imap")]
pub use self::imap::ImapType;
#[cfg(feature = "maildir")]
use self::maildir::MaildirType;
#[cfg(feature = "mbox")]
use self::mbox::MboxType;
#[cfg(feature = "nntp")]
pub use self::nntp::NntpType;
use super::email::{Envelope, EnvelopeHash, Flag};
use crate::{
conf::AccountSettings,
error::{Error, ErrorKind, Result},
@ -153,6 +132,8 @@ impl Backends {
};
#[cfg(feature = "maildir")]
{
use crate::maildir::MaildirType;
b.register(
"maildir".to_string(),
Backend {
@ -163,6 +144,8 @@ impl Backends {
}
#[cfg(feature = "mbox")]
{
use crate::mbox::MboxType;
b.register(
"mbox".to_string(),
Backend {
@ -173,26 +156,32 @@ impl Backends {
}
#[cfg(feature = "imap")]
{
use crate::imap::ImapType;
b.register(
"imap".to_string(),
Backend {
create_fn: Box::new(|| Box::new(|f, i, ev| imap::ImapType::new(f, i, ev))),
validate_conf_fn: Box::new(imap::ImapType::validate_config),
create_fn: Box::new(|| Box::new(|f, i, ev| ImapType::new(f, i, ev))),
validate_conf_fn: Box::new(ImapType::validate_config),
},
);
}
#[cfg(feature = "nntp")]
{
use crate::nntp::NntpType;
b.register(
"nntp".to_string(),
Backend {
create_fn: Box::new(|| Box::new(|f, i, ev| nntp::NntpType::new(f, i, ev))),
validate_conf_fn: Box::new(nntp::NntpType::validate_config),
create_fn: Box::new(|| Box::new(|f, i, ev| NntpType::new(f, i, ev))),
validate_conf_fn: Box::new(NntpType::validate_config),
},
);
}
#[cfg(feature = "notmuch")]
{
use crate::notmuch::NotmuchDb;
b.register(
"notmuch".to_string(),
Backend {
@ -203,11 +192,13 @@ impl Backends {
}
#[cfg(feature = "jmap")]
{
use crate::jmap::JmapType;
b.register(
"jmap".to_string(),
Backend {
create_fn: Box::new(|| Box::new(|f, i, ev| jmap::JmapType::new(f, i, ev))),
validate_conf_fn: Box::new(jmap::JmapType::validate_config),
create_fn: Box::new(|| Box::new(|f, i, ev| JmapType::new(f, i, ev))),
validate_conf_fn: Box::new(JmapType::validate_config),
},
);
}
@ -675,8 +666,8 @@ impl EnvelopeHashBatch {
#[derive(Default, Clone)]
pub struct LazyCountSet {
not_yet_seen: usize,
set: BTreeSet<EnvelopeHash>,
pub not_yet_seen: usize,
pub set: BTreeSet<EnvelopeHash>,
}
impl fmt::Debug for LazyCountSet {
@ -744,21 +735,7 @@ impl LazyCountSet {
}
}
#[test]
fn test_lazy_count_set() {
let mut new = LazyCountSet::default();
assert_eq!(new.len(), 0);
new.set_not_yet_seen(10);
assert_eq!(new.len(), 10);
for i in 0..10 {
assert!(new.insert_existing(EnvelopeHash(i)));
}
assert_eq!(new.len(), 10);
assert!(!new.insert_existing(EnvelopeHash(10)));
assert_eq!(new.len(), 10);
}
pub struct IsSubscribedFn(Box<dyn Fn(&str) -> bool + Send + Sync>);
pub struct IsSubscribedFn(pub Box<dyn Fn(&str) -> bool + Send + Sync>);
impl std::fmt::Debug for IsSubscribedFn {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@ -772,3 +749,22 @@ impl std::ops::Deref for IsSubscribedFn {
&self.0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_lazy_count_set() {
let mut new = LazyCountSet::default();
assert_eq!(new.len(), 0);
new.set_not_yet_seen(10);
assert_eq!(new.len(), 10);
for i in 0..10 {
assert!(new.insert_existing(EnvelopeHash(i)));
}
assert_eq!(new.len(), 10);
assert!(!new.insert_existing(EnvelopeHash(10)));
assert_eq!(new.len(), 10);
}
}

View File

@ -284,7 +284,7 @@ pub mod parser {
}
pub fn sieve_name(input: &[u8]) -> IResult<&[u8], &[u8]> {
crate::backends::imap::protocol_parser::string_token(input)
crate::imap::protocol_parser::string_token(input)
}
// *(sieve-name [SP "ACTIVE"] CRLF)

View File

@ -899,11 +899,11 @@ impl MailBackend for ImapType {
}))
}
fn as_any(&self) -> &dyn Any {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}

View File

@ -26,16 +26,15 @@ use imap_codec::{command::CommandBody, search::SearchKey, sequence::SequenceSet}
use super::{ImapConnection, MailboxSelection, UID};
use crate::{
backends::{
imap::protocol_parser::{
generate_envelope_hash, FetchResponse, ImapLineSplit, RequiredResponses,
UntaggedResponse,
},
BackendMailbox, RefreshEvent,
RefreshEventKind::{self, *},
TagHash,
},
email::common_attributes,
error::*,
imap::protocol_parser::{
generate_envelope_hash, FetchResponse, ImapLineSplit, RequiredResponses, UntaggedResponse,
},
};
impl ImapConnection {

View File

@ -20,22 +20,24 @@
*/
use std::{
collections::{HashMap, HashSet},
collections::{BTreeSet, HashMap, HashSet},
convert::TryFrom,
pin::Pin,
str::FromStr,
sync::{Arc, Mutex, RwLock},
time::{Duration, Instant},
};
use futures::lock::Mutex as FutureMutex;
use futures::{lock::Mutex as FutureMutex, Stream};
use isahc::{config::RedirectPolicy, AsyncReadResponseExt, HttpClient};
use serde_json::Value;
use smallvec::SmallVec;
use crate::{
backends::*,
conf::AccountSettings,
email::*,
error::{Error, Result},
error::{Error, ErrorKind, Result},
utils::futures::{sleep, timeout},
Collection,
};
@ -499,11 +501,11 @@ impl MailBackend for JmapType {
}))
}
fn as_any(&self) -> &dyn Any {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}

View File

@ -27,8 +27,8 @@ use serde_json::{value::RawValue, Value};
use super::*;
use crate::{
backends::jmap::rfc8620::bool_false,
email::address::{Address, MailboxAddress},
jmap::rfc8620::bool_false,
utils::datetime,
};

View File

@ -19,7 +19,7 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
use crate::backends::jmap::{
use crate::jmap::{
protocol::Method,
rfc8620::{Object, ResultField},
};

View File

@ -158,6 +158,18 @@ pub mod utils;
#[cfg(feature = "gpgme")]
pub mod gpgme;
#[cfg(feature = "imap")]
pub mod imap;
#[cfg(feature = "jmap")]
pub mod jmap;
#[cfg(feature = "maildir")]
pub mod maildir;
#[cfg(feature = "mbox")]
pub mod mbox;
#[cfg(feature = "nntp")]
pub mod nntp;
#[cfg(feature = "notmuch")]
pub mod notmuch;
#[cfg(feature = "smtp")]
pub mod smtp;

View File

@ -25,6 +25,7 @@
//! specification. <https://cr.yp.to/proto/maildir.html>
use futures::prelude::Stream;
use smallvec::SmallVec;
use super::{MaildirMailbox, MaildirOp, MaildirPathTrait};
use crate::{
@ -1063,11 +1064,11 @@ impl MailBackend for MaildirType {
)
}
fn as_any(&self) -> &dyn Any {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
}

View File

@ -26,14 +26,16 @@ pub use self::backend::*;
mod stream;
use std::{
collections::hash_map::DefaultHasher,
collections::HashMap,
fs,
hash::{Hash, Hasher},
io::{BufReader, Read},
path::{Path, PathBuf},
sync::{Arc, Mutex},
sync::{Arc, Mutex, RwLock},
};
use futures::stream::Stream;
use smallvec::SmallVec;
pub use stream::*;
use crate::{
@ -41,6 +43,7 @@ use crate::{
email::Flag,
error::{Error, Result},
utils::shellexpand::ShellExpandTrait,
AccountSettings, Envelope, EnvelopeHash,
};
/// `BackendOp` implementor for Maildir

View File

@ -32,7 +32,7 @@ use futures::{
};
use super::*;
use crate::backends::maildir::backend::move_to_cur;
use crate::maildir::backend::move_to_cur;
type Payload = Pin<Box<dyn Future<Output = Result<Vec<Envelope>>> + Send + 'static>>;

View File

@ -150,12 +150,16 @@ use crate::{
};
extern crate notify;
use futures::Stream;
use smallvec::SmallVec;
use std::{
collections::hash_map::HashMap,
fs::File,
io::{BufReader, Read},
os::unix::io::AsRawFd,
path::{Path, PathBuf},
pin::Pin,
str::FromStr,
sync::{mpsc::channel, Arc, Mutex, RwLock},
};
@ -1175,11 +1179,11 @@ impl MailBackend for MboxType {
))
}
fn as_any(&self) -> &dyn Any {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}

View File

@ -57,7 +57,7 @@ use crate::{
email::*,
error::{Error, Result, ResultIntoError},
utils::futures::timeout,
Collection,
Collection, ErrorKind,
RefreshEventKind::NewFlags,
};
pub type UID = usize;
@ -508,11 +508,11 @@ impl MailBackend for NntpType {
Err(Error::new("NNTP doesn't support deletion."))
}
fn as_any(&self) -> &dyn Any {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}

View File

@ -27,8 +27,8 @@ pub use inner::*;
#[cfg(feature = "sqlite3")]
mod inner {
use crate::{
backends::nntp::UID,
email::Flag,
nntp::UID,
utils::sqlite3::{self, Connection, DatabaseDescription},
EnvelopeHash, MailboxHash, Result,
};

View File

@ -25,9 +25,11 @@ use std::{
io::Read,
os::unix::ffi::OsStrExt,
path::{Path, PathBuf},
pin::Pin,
sync::{Arc, Mutex, RwLock},
};
use futures::Stream;
use smallvec::SmallVec;
use crate::{
@ -36,7 +38,7 @@ use crate::{
email::{Envelope, EnvelopeHash, Flag},
error::{Error, Result},
utils::shellexpand::ShellExpandTrait,
Collection,
Collection, ErrorKind,
};
macro_rules! call {
@ -798,7 +800,7 @@ impl MailBackend for NotmuchDb {
.as_ref()
.unwrap_or(&self.path)
.to_path_buf();
MaildirType::save_to_mailbox(path, bytes, flags)?;
crate::maildir::MaildirType::save_to_mailbox(path, bytes, flags)?;
Ok(Box::pin(async { Ok(()) }))
}
@ -976,11 +978,11 @@ impl MailBackend for NotmuchDb {
self.collection.clone()
}
fn as_any(&self) -> &dyn Any {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}