1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! # Backend
//!
//! The `--backend` global flag: which backend the shared, cross-protocol
//! commands target.
use std::fmt;
use clap::ValueEnum;
/// Selects which backend a cross-protocol command targets.
///
/// `auto` picks the first configured backend the command supports, and a
/// named one pins it, which then bails when the account has no such block
/// or the operation no such arm. The protocol-specific subcommands ignore
/// it entirely.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum)]
pub enum Backend {
/// Let the command pick the first backend it is configured for.
#[default]
Auto,
/// Pin the command to the account's IMAP backend.
Imap,
/// Pin the command to the account's JMAP backend.
Jmap,
/// Pin the command to the account's Gmail backend.
Gmail,
/// Pin the command to the account's Microsoft Graph backend.
Msgraph,
/// Pin the command to the account's Maildir backend.
Maildir,
/// Pin the command to the account's m2dir backend.
M2dir,
/// Pin the command to the account's mbox backend.
Mbox,
/// Pin the command to the account's pimdir backend.
Pimdir,
/// Pin the command to the account's SMTP backend.
Smtp,
/// Pin the command to the account's ManageSieve backend.
Sieve,
}
#[allow(unused)]
impl Backend {
/// Every backend this build compiles in, `auto` aside.
pub const COMPILED: &[Self] = &[
#[cfg(feature = "imap")]
Self::Imap,
#[cfg(feature = "jmap")]
Self::Jmap,
#[cfg(feature = "gmail")]
Self::Gmail,
#[cfg(feature = "msgraph")]
Self::Msgraph,
#[cfg(feature = "maildir")]
Self::Maildir,
#[cfg(feature = "m2dir")]
Self::M2dir,
#[cfg(feature = "mbox")]
Self::Mbox,
#[cfg(feature = "pimdir")]
Self::Pimdir,
#[cfg(feature = "smtp")]
Self::Smtp,
#[cfg(feature = "sieve")]
Self::Sieve,
];
/// Whether the IMAP arm of a shared command may run.
pub fn allows_imap(self) -> bool {
matches!(self, Self::Auto | Self::Imap)
}
/// Whether the JMAP arm of a shared command may run.
pub fn allows_jmap(self) -> bool {
matches!(self, Self::Auto | Self::Jmap)
}
/// Whether the Gmail arm of a shared command may run.
pub fn allows_gmail(self) -> bool {
matches!(self, Self::Auto | Self::Gmail)
}
/// Whether the Microsoft Graph arm of a shared command may run.
pub fn allows_msgraph(self) -> bool {
matches!(self, Self::Auto | Self::Msgraph)
}
/// Whether the Maildir arm of a shared command may run.
pub fn allows_maildir(self) -> bool {
matches!(self, Self::Auto | Self::Maildir)
}
/// Whether the m2dir arm of a shared command may run.
pub fn allows_m2dir(self) -> bool {
matches!(self, Self::Auto | Self::M2dir)
}
/// Whether the mbox arm of a shared command may run.
pub fn allows_mbox(self) -> bool {
matches!(self, Self::Auto | Self::Mbox)
}
/// Whether the pimdir arm of a shared command may run.
pub fn allows_pimdir(self) -> bool {
matches!(self, Self::Auto | Self::Pimdir)
}
/// Whether the SMTP arm of a shared command may run.
pub fn allows_smtp(self) -> bool {
matches!(self, Self::Auto | Self::Smtp)
}
/// Whether the ManageSieve account-check arm may run.
pub fn allows_sieve(self) -> bool {
matches!(self, Self::Auto | Self::Sieve)
}
}
impl fmt::Display for Backend {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Auto => write!(f, "auto"),
Self::Imap => write!(f, "imap"),
Self::Jmap => write!(f, "jmap"),
Self::Gmail => write!(f, "gmail"),
Self::Msgraph => write!(f, "msgraph"),
Self::Maildir => write!(f, "maildir"),
Self::M2dir => write!(f, "m2dir"),
Self::Mbox => write!(f, "mbox"),
Self::Pimdir => write!(f, "pimdir"),
Self::Smtp => write!(f, "smtp"),
Self::Sieve => write!(f, "sieve"),
}
}
}