1use std::{io, path::PathBuf};
2
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Error)]
10pub enum Error {
11 #[error("missing PGP configuration")]
12 PgpMissingConfigurationError,
13
14 #[cfg(feature = "compiler")]
15 #[error("cannot parse MML body")]
16 ParseMmlError(Vec<chumsky::error::Rich<'static, char>>, String),
17 #[cfg(feature = "compiler")]
18 #[error("cannot compile template")]
19 WriteCompiledPartToVecError(#[source] io::Error),
20 #[cfg(feature = "compiler")]
21 #[error("cannot read attachment at {1:?}")]
22 ReadAttachmentError(#[source] io::Error, PathBuf),
23
24 #[cfg(feature = "pgp")]
25 #[error("cannot sign part using pgp: missing sender")]
26 PgpSignMissingSenderError,
27
28 #[cfg(all(feature = "pgp-native", feature = "keyring"))]
29 #[error("cannot get pgp secret key from keyring")]
30 GetSecretKeyFromKeyringError(#[source] secret::keyring::Error),
31
32 #[cfg(feature = "pgp-native")]
33 #[error("cannot read pgp secret key from keyring")]
34 ReadSecretKeyFromKeyringError(pgp::Error),
35
36 #[cfg(feature = "pgp-native")]
37 #[error("cannot read pgp secret key from path {1}")]
38 ReadSecretKeyFromPathError(pgp::Error, PathBuf),
39
40 #[cfg(feature = "pgp-native")]
41 #[error("cannot get pgp secret key passphrase from keyring")]
42 GetSecretKeyPassphraseFromKeyringError(#[source] secret::Error),
43
44 #[cfg(all(feature = "pgp-native", feature = "keyring"))]
45 #[error("cannot get pgp secret key from keyring")]
46 GetPgpSecretKeyFromKeyringError(#[source] secret::keyring::Error),
47
48 #[error("cannot get native pgp secret key of {0}")]
49 GetNativePgpSecretKeyNoneError(String),
50 #[error("cannot find native pgp public key of {0}")]
51 FindPgpPublicKeyError(String),
52
53 #[cfg(feature = "pgp-native")]
54 #[error("cannot encrypt data using native pgp")]
55 EncryptNativePgpError(#[source] pgp::Error),
56
57 #[cfg(feature = "pgp-native")]
58 #[error("cannot decrypt data using native pgp")]
59 DecryptNativePgpError(#[source] pgp::Error),
60
61 #[cfg(feature = "pgp-native")]
62 #[error("cannot sign data using native pgp")]
63 SignNativePgpError(#[source] pgp::Error),
64
65 #[cfg(feature = "pgp-native")]
66 #[error("cannot read native pgp signature")]
67 ReadNativePgpSignatureError(#[source] pgp::Error),
68
69 #[cfg(feature = "pgp-native")]
70 #[error("cannot verify native pgp signature")]
71 VerifyNativePgpSignatureError(#[source] pgp::Error),
72
73 #[cfg(feature = "pgp-native")]
74 #[error("cannot read native pgp secret key")]
75 ReadNativePgpSecretKeyError(#[source] pgp::Error),
76
77 #[error("cannot parse MIME message")]
78 ParseMimeMessageError,
79 #[error("cannot save attachment at {1}")]
80 WriteAttachmentError(#[source] io::Error, PathBuf),
81 #[error("cannot build email")]
82 WriteMessageError(#[source] io::Error),
83 #[error("cannot parse pgp decrypted part")]
84 ParsePgpDecryptedPartError,
85 #[error("cannot decrypt part using pgp: missing recipient")]
86 PgpDecryptMissingRecipientError,
87
88 #[error("cannot parse template")]
89 ParseMessageError,
90 #[error("cannot parse MML message: empty body")]
91 ParseMmlEmptyBodyError,
92 #[error("cannot parse MML message: empty body content")]
93 ParseMmlEmptyBodyContentError,
94 #[error("cannot compile MML message to vec")]
95 CompileMmlMessageToVecError(#[source] io::Error),
96 #[error("cannot compile MML message to string")]
97 CompileMmlMessageToStringError(#[source] io::Error),
98
99 #[error("cannot parse raw email")]
100 ParseRawEmailError,
101 #[error("cannot build email")]
102 BuildEmailError(#[source] io::Error),
103
104 #[cfg(feature = "pgp-commands")]
105 #[error("cannot encrypt data using commands")]
106 EncryptCommandError(#[source] process::Error),
107
108 #[cfg(feature = "pgp-commands")]
109 #[error("cannot decrypt data using commands")]
110 DecryptCommandError(#[source] process::Error),
111
112 #[cfg(feature = "pgp-commands")]
113 #[error("cannot sign data using commands")]
114 SignCommandError(#[source] process::Error),
115
116 #[cfg(feature = "pgp-commands")]
117 #[error("cannot verify data using commands")]
118 VerifyCommandError(#[source] process::Error),
119
120 #[cfg(feature = "pgp-gpg")]
121 #[error("cannot get gpg context")]
122 GetContextError(#[source] gpgme::Error),
123
124 #[cfg(feature = "pgp-gpg")]
125 #[error("cannot get gpg home dir path from {0}")]
126 GetHomeDirPathError(PathBuf),
127
128 #[cfg(feature = "pgp-gpg")]
129 #[error("cannot set gpg home dir at {1}")]
130 SetHomeDirError(#[source] gpgme::Error, PathBuf),
131
132 #[cfg(feature = "pgp-gpg")]
133 #[error("cannot encrypt data using gpg")]
134 EncryptGpgError(#[source] gpgme::Error),
135
136 #[cfg(feature = "pgp-gpg")]
137 #[error("cannot decrypt data using gpg")]
138 DecryptGpgError(#[source] gpgme::Error),
139
140 #[cfg(feature = "pgp-gpg")]
141 #[error("cannot sign data using gpg")]
142 SignGpgError(#[source] gpgme::Error),
143
144 #[cfg(feature = "pgp-gpg")]
145 #[error("cannot verify data using gpg")]
146 VerifyGpgError(#[source] gpgme::Error),
147}