@@ -4,83 +4,75 @@ use serde::Deserialize;
4
4
use serde:: Serialize ;
5
5
use yerpc:: TypeDef ;
6
6
7
+ /// Login parameters entered by the user.
8
+
7
9
#[ derive( Serialize , Deserialize , TypeDef , schemars:: JsonSchema ) ]
8
10
#[ serde( rename_all = "camelCase" ) ]
9
- pub struct EnteredServerLoginParam {
10
- /// Server hostname or IP address.
11
- pub server : String ,
11
+ pub struct EnteredLoginParam {
12
+ /// Email address.
13
+ pub addr : String ,
12
14
13
- /// Server port.
14
- ///
15
- /// 0 if not specified.
16
- pub port : u16 ,
15
+ /// Password.
16
+ pub password : String ,
17
17
18
- /// Socket security .
19
- pub security : Socket ,
18
+ /// Imap server hostname or IP address .
19
+ pub imap_server : Option < String > ,
20
20
21
- /// Username.
22
- ///
23
- /// Empty string if not specified.
24
- pub user : String ,
21
+ /// Imap server port.
22
+ pub imap_port : Option < u16 > ,
25
23
26
- /// Password.
27
- pub password : String ,
28
- }
24
+ /// Imap socket security.
25
+ pub imap_security : Option < Socket > ,
29
26
30
- impl From < dc:: EnteredServerLoginParam > for EnteredServerLoginParam {
31
- fn from ( param : dc:: EnteredServerLoginParam ) -> Self {
32
- Self {
33
- server : param. server ,
34
- port : param. port ,
35
- security : param. security . into ( ) ,
36
- user : param. user ,
37
- password : param. password ,
38
- }
39
- }
40
- }
27
+ /// Imap username.
28
+ pub imap_user : Option < String > ,
41
29
42
- impl From < EnteredServerLoginParam > for dc:: EnteredServerLoginParam {
43
- fn from ( param : EnteredServerLoginParam ) -> Self {
44
- Self {
45
- server : param. server ,
46
- port : param. port ,
47
- security : param. security . into ( ) ,
48
- user : param. user ,
49
- password : param. password ,
50
- }
51
- }
52
- }
30
+ /// SMTP server hostname or IP address.
31
+ pub smtp_server : Option < String > ,
53
32
54
- /// Login parameters entered by the user.
33
+ /// SMTP server port.
34
+ pub smtp_port : Option < u16 > ,
55
35
56
- #[ derive( Serialize , Deserialize , TypeDef , schemars:: JsonSchema ) ]
57
- #[ serde( rename_all = "camelCase" ) ]
58
- pub struct EnteredLoginParam {
59
- /// Email address.
60
- pub addr : String ,
36
+ /// SMTP socket security.
37
+ pub smtp_security : Option < Socket > ,
61
38
62
- /// IMAP settings .
63
- pub imap : EnteredServerLoginParam ,
39
+ /// SMTP username .
40
+ pub smtp_user : Option < String > ,
64
41
65
- /// SMTP settings.
66
- pub smtp : EnteredServerLoginParam ,
42
+ /// SMTP Password.
43
+ ///
44
+ /// Only needs to be specified if different than IMAP password.
45
+ pub smtp_password : Option < String > ,
67
46
68
47
/// TLS options: whether to allow invalid certificates and/or
69
- /// invalid hostnames
70
- pub certificate_checks : EnteredCertificateChecks ,
48
+ /// invalid hostnames.
49
+ /// Default: Automatic
50
+ pub certificate_checks : Option < EnteredCertificateChecks > ,
71
51
72
- /// If true, login via OAUTH2 (not recommended anymore)
73
- pub oauth2 : bool ,
52
+ /// If true, login via OAUTH2 (not recommended anymore).
53
+ /// Default: false
54
+ pub oauth2 : Option < bool > ,
74
55
}
75
56
76
57
impl From < dc:: EnteredLoginParam > for EnteredLoginParam {
77
58
fn from ( param : dc:: EnteredLoginParam ) -> Self {
59
+ let imap_security: Socket = param. imap . security . into ( ) ;
60
+ let smtp_security: Socket = param. smtp . security . into ( ) ;
61
+ let certificate_checks: EnteredCertificateChecks = param. certificate_checks . into ( ) ;
78
62
Self {
79
63
addr : param. addr ,
80
- imap : param. imap . into ( ) ,
81
- smtp : param. smtp . into ( ) ,
82
- certificate_checks : param. certificate_checks . into ( ) ,
83
- oauth2 : param. oauth2 ,
64
+ password : param. imap . password ,
65
+ imap_server : param. imap . server . into_option ( ) ,
66
+ imap_port : param. imap . port . into_option ( ) ,
67
+ imap_security : imap_security. into_option ( ) ,
68
+ imap_user : param. imap . user . into_option ( ) ,
69
+ smtp_server : param. smtp . server . into_option ( ) ,
70
+ smtp_port : param. smtp . port . into_option ( ) ,
71
+ smtp_security : smtp_security. into_option ( ) ,
72
+ smtp_user : param. smtp . user . into_option ( ) ,
73
+ smtp_password : param. smtp . password . into_option ( ) ,
74
+ certificate_checks : certificate_checks. into_option ( ) ,
75
+ oauth2 : param. oauth2 . into_option ( ) ,
84
76
}
85
77
}
86
78
}
@@ -91,18 +83,31 @@ impl TryFrom<EnteredLoginParam> for dc::EnteredLoginParam {
91
83
fn try_from ( param : EnteredLoginParam ) -> Result < Self > {
92
84
Ok ( Self {
93
85
addr : param. addr ,
94
- imap : param. imap . into ( ) ,
95
- smtp : param. smtp . into ( ) ,
96
- certificate_checks : param. certificate_checks . into ( ) ,
97
- oauth2 : param. oauth2 ,
86
+ imap : dc:: EnteredServerLoginParam {
87
+ server : param. imap_server . unwrap_or_default ( ) ,
88
+ port : param. imap_port . unwrap_or_default ( ) ,
89
+ security : param. imap_security . unwrap_or_default ( ) . into ( ) ,
90
+ user : param. imap_user . unwrap_or_default ( ) ,
91
+ password : param. password ,
92
+ } ,
93
+ smtp : dc:: EnteredServerLoginParam {
94
+ server : param. smtp_server . unwrap_or_default ( ) ,
95
+ port : param. smtp_port . unwrap_or_default ( ) ,
96
+ security : param. smtp_security . unwrap_or_default ( ) . into ( ) ,
97
+ user : param. smtp_user . unwrap_or_default ( ) ,
98
+ password : param. smtp_password . unwrap_or_default ( ) ,
99
+ } ,
100
+ certificate_checks : param. certificate_checks . unwrap_or_default ( ) . into ( ) ,
101
+ oauth2 : param. oauth2 . unwrap_or_default ( ) ,
98
102
} )
99
103
}
100
104
}
101
105
102
- #[ derive( Serialize , Deserialize , TypeDef , schemars:: JsonSchema ) ]
106
+ #[ derive( Serialize , Deserialize , TypeDef , schemars:: JsonSchema , Default , PartialEq ) ]
103
107
#[ serde( rename_all = "camelCase" ) ]
104
108
pub enum Socket {
105
109
/// Unspecified socket security, select automatically.
110
+ #[ default]
106
111
Automatic ,
107
112
108
113
/// TLS connection.
@@ -137,12 +142,13 @@ impl From<Socket> for dc::Socket {
137
142
}
138
143
}
139
144
140
- #[ derive( Serialize , Deserialize , TypeDef , schemars:: JsonSchema ) ]
145
+ #[ derive( Serialize , Deserialize , TypeDef , schemars:: JsonSchema , Default , PartialEq ) ]
141
146
#[ serde( rename_all = "camelCase" ) ]
142
147
pub enum EnteredCertificateChecks {
143
148
/// `Automatic` means that provider database setting should be taken.
144
149
/// If there is no provider database setting for certificate checks,
145
150
/// check certificates strictly.
151
+ #[ default]
146
152
Automatic ,
147
153
148
154
/// Ensure that TLS certificate is valid for the server hostname.
@@ -177,3 +183,19 @@ impl From<EnteredCertificateChecks> for dc::EnteredCertificateChecks {
177
183
}
178
184
}
179
185
}
186
+
187
+ trait IntoOption < T > {
188
+ fn into_option ( self ) -> Option < T > ;
189
+ }
190
+ impl < T > IntoOption < T > for T
191
+ where
192
+ T : Default + std:: cmp:: PartialEq ,
193
+ {
194
+ fn into_option ( self ) -> Option < T > {
195
+ if self == T :: default ( ) {
196
+ None
197
+ } else {
198
+ Some ( self )
199
+ }
200
+ }
201
+ }
0 commit comments