mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-26 04:50:25 +00:00
plug missing other backend features
This commit is contained in:
parent
9f6a9a1333
commit
20f6973c55
7 changed files with 329 additions and 4 deletions
261
src/backend.rs
261
src/backend.rs
|
@ -11,8 +11,26 @@ use email::{
|
||||||
account::AccountConfig,
|
account::AccountConfig,
|
||||||
config::Config,
|
config::Config,
|
||||||
email::{
|
email::{
|
||||||
envelope::list::{imap::ListEnvelopesImap, maildir::ListEnvelopesMaildir},
|
envelope::{
|
||||||
message::send_raw::{sendmail::SendRawMessageSendmail, smtp::SendRawMessageSmtp},
|
get::{imap::GetEnvelopeImap, maildir::GetEnvelopeMaildir},
|
||||||
|
list::{imap::ListEnvelopesImap, maildir::ListEnvelopesMaildir},
|
||||||
|
},
|
||||||
|
flag::{
|
||||||
|
add::{imap::AddFlagsImap, maildir::AddFlagsMaildir},
|
||||||
|
remove::{imap::RemoveFlagsImap, maildir::RemoveFlagsMaildir},
|
||||||
|
set::{imap::SetFlagsImap, maildir::SetFlagsMaildir},
|
||||||
|
},
|
||||||
|
message::{
|
||||||
|
add_raw::imap::AddRawMessageImap,
|
||||||
|
add_raw_with_flags::{
|
||||||
|
imap::AddRawMessageWithFlagsImap, maildir::AddRawMessageWithFlagsMaildir,
|
||||||
|
},
|
||||||
|
copy::{imap::CopyMessagesImap, maildir::CopyMessagesMaildir},
|
||||||
|
get::imap::GetMessagesImap,
|
||||||
|
move_::{imap::MoveMessagesImap, maildir::MoveMessagesMaildir},
|
||||||
|
peek::{imap::PeekMessagesImap, maildir::PeekMessagesMaildir},
|
||||||
|
send_raw::{sendmail::SendRawMessageSendmail, smtp::SendRawMessageSmtp},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
folder::{
|
folder::{
|
||||||
add::{imap::AddFolderImap, maildir::AddFolderMaildir},
|
add::{imap::AddFolderImap, maildir::AddFolderMaildir},
|
||||||
|
@ -360,6 +378,33 @@ impl BackendBuilder {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let get_envelope = deserialized_account_config
|
||||||
|
.envelope
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|envelope| envelope.get.as_ref())
|
||||||
|
.and_then(|get| get.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match get_envelope {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder.with_get_envelope(|ctx| {
|
||||||
|
ctx.maildir.as_ref().and_then(GetEnvelopeMaildir::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_get_envelope(|ctx| ctx.imap.as_ref().and_then(GetEnvelopeImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder.with_get_envelope(|ctx| {
|
||||||
|
ctx.notmuch.as_ref().and_then(GetEnvelopeNotmuch::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
let list_envelopes = deserialized_account_config
|
let list_envelopes = deserialized_account_config
|
||||||
.envelope
|
.envelope
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -387,6 +432,83 @@ impl BackendBuilder {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let add_flags = deserialized_account_config
|
||||||
|
.flag
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|flag| flag.add.as_ref())
|
||||||
|
.and_then(|add| add.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match add_flags {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_add_flags(|ctx| ctx.maildir.as_ref().and_then(AddFlagsMaildir::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_add_flags(|ctx| ctx.imap.as_ref().and_then(AddFlagsImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_add_flags(|ctx| ctx.notmuch.as_ref().and_then(AddFlagsNotmuch::new));
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let set_flags = deserialized_account_config
|
||||||
|
.flag
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|flag| flag.set.as_ref())
|
||||||
|
.and_then(|set| set.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match set_flags {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_set_flags(|ctx| ctx.maildir.as_ref().and_then(SetFlagsMaildir::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_set_flags(|ctx| ctx.imap.as_ref().and_then(SetFlagsImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_set_flags(|ctx| ctx.notmuch.as_ref().and_then(SetFlagsNotmuch::new));
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let remove_flags = deserialized_account_config
|
||||||
|
.flag
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|flag| flag.remove.as_ref())
|
||||||
|
.and_then(|remove| remove.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match remove_flags {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder.with_remove_flags(|ctx| {
|
||||||
|
ctx.maildir.as_ref().and_then(RemoveFlagsMaildir::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_remove_flags(|ctx| ctx.imap.as_ref().and_then(RemoveFlagsImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder.with_remove_flags(|ctx| {
|
||||||
|
ctx.notmuch.as_ref().and_then(RemoveFlagsNotmuch::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
let send_msg = deserialized_account_config
|
let send_msg = deserialized_account_config
|
||||||
.message
|
.message
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -409,6 +531,141 @@ impl BackendBuilder {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let add_msg = deserialized_account_config
|
||||||
|
.message
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|msg| msg.add.as_ref())
|
||||||
|
.and_then(|add| add.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match add_msg {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder.with_add_raw_message_with_flags(|ctx| {
|
||||||
|
ctx.maildir
|
||||||
|
.as_ref()
|
||||||
|
.and_then(AddRawMessageWithFlagsMaildir::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_add_raw_message(|ctx| ctx.imap.as_ref().and_then(AddRawMessageImap::new))
|
||||||
|
.with_add_raw_message_with_flags(|ctx| {
|
||||||
|
ctx.imap.as_ref().and_then(AddRawMessageWithFlagsImap::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder.with_add_raw_message(|ctx| {
|
||||||
|
ctx.notmuch.as_ref().and_then(AddRawMessageNotmuch::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let peek_msgs = deserialized_account_config
|
||||||
|
.message
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|msg| msg.peek.as_ref())
|
||||||
|
.and_then(|peek| peek.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match peek_msgs {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder.with_peek_messages(|ctx| {
|
||||||
|
ctx.maildir.as_ref().and_then(PeekMessagesMaildir::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_peek_messages(|ctx| ctx.imap.as_ref().and_then(PeekMessagesImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder.with_peek_messages(|ctx| {
|
||||||
|
ctx.notmuch.as_ref().and_then(PeekMessagesNotmuch::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let get_msgs = deserialized_account_config
|
||||||
|
.message
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|msg| msg.get.as_ref())
|
||||||
|
.and_then(|get| get.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match get_msgs {
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_get_messages(|ctx| ctx.imap.as_ref().and_then(GetMessagesImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder.with_get_messages(|ctx| {
|
||||||
|
ctx.notmuch.as_ref().and_then(GetMessagesNotmuch::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let copy_msgs = deserialized_account_config
|
||||||
|
.message
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|msg| msg.copy.as_ref())
|
||||||
|
.and_then(|copy| copy.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match copy_msgs {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder.with_copy_messages(|ctx| {
|
||||||
|
ctx.maildir.as_ref().and_then(CopyMessagesMaildir::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_copy_messages(|ctx| ctx.imap.as_ref().and_then(CopyMessagesImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder.with_copy_messages(|ctx| {
|
||||||
|
ctx.notmuch.as_ref().and_then(CopyMessagesNotmuch::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let move_msgs = deserialized_account_config
|
||||||
|
.message
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|msg| msg.move_.as_ref())
|
||||||
|
.and_then(|move_| move_.backend.as_ref())
|
||||||
|
.or_else(|| deserialized_account_config.backend.as_ref());
|
||||||
|
|
||||||
|
match move_msgs {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder.with_move_messages(|ctx| {
|
||||||
|
ctx.maildir.as_ref().and_then(MoveMessagesMaildir::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_move_messages(|ctx| ctx.imap.as_ref().and_then(MoveMessagesImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch-backend")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder.with_move_messages(|ctx| {
|
||||||
|
ctx.notmuch.as_ref().and_then(MoveMessagesNotmuch::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Self(backend_builder))
|
Ok(Self(backend_builder))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,11 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::BackendKind, config::prelude::*, domain::config::FolderConfig,
|
backend::BackendKind,
|
||||||
email::envelope::config::EnvelopeConfig, message::config::MessageConfig,
|
config::prelude::*,
|
||||||
|
domain::config::FolderConfig,
|
||||||
|
email::envelope::{config::EnvelopeConfig, flag::config::FlagConfig},
|
||||||
|
message::config::MessageConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Represents all existing kind of account config.
|
/// Represents all existing kind of account config.
|
||||||
|
@ -58,6 +61,7 @@ pub struct DeserializedAccountConfig {
|
||||||
|
|
||||||
pub folder: Option<FolderConfig>,
|
pub folder: Option<FolderConfig>,
|
||||||
pub envelope: Option<EnvelopeConfig>,
|
pub envelope: Option<EnvelopeConfig>,
|
||||||
|
pub flag: Option<FlagConfig>,
|
||||||
pub message: Option<MessageConfig>,
|
pub message: Option<MessageConfig>,
|
||||||
|
|
||||||
#[cfg(feature = "imap-backend")]
|
#[cfg(feature = "imap-backend")]
|
||||||
|
|
|
@ -5,9 +5,15 @@ use crate::backend::BackendKind;
|
||||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct EnvelopeConfig {
|
pub struct EnvelopeConfig {
|
||||||
pub list: Option<EnvelopeListConfig>,
|
pub list: Option<EnvelopeListConfig>,
|
||||||
|
pub get: Option<EnvelopeGetConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct EnvelopeListConfig {
|
pub struct EnvelopeListConfig {
|
||||||
pub backend: Option<BackendKind>,
|
pub backend: Option<BackendKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct EnvelopeGetConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
|
}
|
||||||
|
|
25
src/domain/email/envelope/flag/config.rs
Normal file
25
src/domain/email/envelope/flag/config.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use ::serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::backend::BackendKind;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct FlagConfig {
|
||||||
|
pub add: Option<FlagAddConfig>,
|
||||||
|
pub set: Option<FlagSetConfig>,
|
||||||
|
pub remove: Option<FlagRemoveConfig>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct FlagAddConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct FlagSetConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct FlagRemoveConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
|
}
|
1
src/domain/email/envelope/flag/mod.rs
Normal file
1
src/domain/email/envelope/flag/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod config;
|
|
@ -1 +1,2 @@
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod flag;
|
||||||
|
|
|
@ -4,10 +4,41 @@ use crate::backend::BackendKind;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct MessageConfig {
|
pub struct MessageConfig {
|
||||||
|
pub add: Option<MessageAddConfig>,
|
||||||
pub send: Option<MessageSendConfig>,
|
pub send: Option<MessageSendConfig>,
|
||||||
|
pub peek: Option<MessagePeekConfig>,
|
||||||
|
pub get: Option<MessageGetConfig>,
|
||||||
|
pub copy: Option<MessageCopyConfig>,
|
||||||
|
#[serde(rename = "move")]
|
||||||
|
pub move_: Option<MessageMoveConfig>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct MessageAddConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct MessageSendConfig {
|
pub struct MessageSendConfig {
|
||||||
pub backend: Option<BackendKind>,
|
pub backend: Option<BackendKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct MessagePeekConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct MessageGetConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct MessageCopyConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct MessageMoveConfig {
|
||||||
|
pub backend: Option<BackendKind>,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue