plug missing other backend features

This commit is contained in:
Clément DOUIN 2023-11-27 15:49:55 +01:00
parent 9f6a9a1333
commit 20f6973c55
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
7 changed files with 329 additions and 4 deletions

View file

@ -11,8 +11,26 @@ use email::{
account::AccountConfig,
config::Config,
email::{
envelope::list::{imap::ListEnvelopesImap, maildir::ListEnvelopesMaildir},
message::send_raw::{sendmail::SendRawMessageSendmail, smtp::SendRawMessageSmtp},
envelope::{
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::{
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
.envelope
.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
.message
.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))
}
}

View file

@ -19,8 +19,11 @@ use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::PathBuf};
use crate::{
backend::BackendKind, config::prelude::*, domain::config::FolderConfig,
email::envelope::config::EnvelopeConfig, message::config::MessageConfig,
backend::BackendKind,
config::prelude::*,
domain::config::FolderConfig,
email::envelope::{config::EnvelopeConfig, flag::config::FlagConfig},
message::config::MessageConfig,
};
/// Represents all existing kind of account config.
@ -58,6 +61,7 @@ pub struct DeserializedAccountConfig {
pub folder: Option<FolderConfig>,
pub envelope: Option<EnvelopeConfig>,
pub flag: Option<FlagConfig>,
pub message: Option<MessageConfig>,
#[cfg(feature = "imap-backend")]

View file

@ -5,9 +5,15 @@ use crate::backend::BackendKind;
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct EnvelopeConfig {
pub list: Option<EnvelopeListConfig>,
pub get: Option<EnvelopeGetConfig>,
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct EnvelopeListConfig {
pub backend: Option<BackendKind>,
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct EnvelopeGetConfig {
pub backend: Option<BackendKind>,
}

View 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>,
}

View file

@ -0,0 +1 @@
pub mod config;

View file

@ -1 +1,2 @@
pub mod config;
pub mod flag;

View file

@ -4,10 +4,41 @@ use crate::backend::BackendKind;
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct MessageConfig {
pub add: Option<MessageAddConfig>,
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)]
pub struct MessageSendConfig {
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>,
}