@@ -51,8 +51,17 @@ pub struct Server {
51
51
pub username_pattern : UsernamePattern ,
52
52
}
53
53
54
- pub type ImapServers = Vec < Server > ;
55
- pub type SmtpServers = Vec < Server > ;
54
+ #[ derive( Debug ) ]
55
+ pub struct ServerParams {
56
+ pub protocol : Protocol ,
57
+ pub socket : Socket ,
58
+ pub hostname : String ,
59
+ pub port : u16 ,
60
+ pub username_pattern : UsernamePattern ,
61
+ }
62
+
63
+ pub type ImapServers = Vec < ServerParams > ;
64
+ pub type SmtpServers = Vec < ServerParams > ;
56
65
57
66
#[ derive( Debug ) ]
58
67
pub struct LoginParamNew {
@@ -61,7 +70,7 @@ pub struct LoginParamNew {
61
70
pub smtp : SmtpServers ,
62
71
}
63
72
64
- impl Server {
73
+ impl ServerParams {
65
74
pub fn apply_username_pattern ( & self , addr : String ) -> String {
66
75
match self . username_pattern {
67
76
UsernamePattern :: EMAIL => addr,
@@ -94,11 +103,17 @@ pub struct Provider {
94
103
}
95
104
96
105
impl Provider {
97
- pub fn get_server ( & self , protocol : Protocol ) -> Vec < Server > {
106
+ pub fn get_server ( & self , protocol : Protocol ) -> Vec < ServerParams > {
98
107
self . server
99
108
. iter ( )
100
109
. filter ( |s| s. protocol == protocol)
101
- . cloned ( )
110
+ . map ( |s| ServerParams {
111
+ protocol : s. protocol . clone ( ) ,
112
+ socket : s. socket . clone ( ) ,
113
+ hostname : s. hostname . to_string ( ) ,
114
+ port : s. port ,
115
+ username_pattern : s. username_pattern . clone ( ) ,
116
+ } )
102
117
. collect ( )
103
118
}
104
119
@@ -148,13 +163,13 @@ mod tests {
148
163
149
164
let provider =
get_provider_info ( "[email protected] " ) . unwrap ( ) ;
150
165
assert ! ( provider. status == Status :: OK ) ;
151
- let server = provider. get_imap_server ( ) [ 0 ] ;
166
+ let server = & provider. get_imap_server ( ) [ 0 ] ;
152
167
assert_eq ! ( server. protocol, Protocol :: IMAP ) ;
153
168
assert_eq ! ( server. socket, Socket :: STARTTLS ) ;
154
169
assert_eq ! ( server. hostname, "imap.nauta.cu" ) ;
155
170
assert_eq ! ( server. port, 143 ) ;
156
171
assert_eq ! ( server. username_pattern, UsernamePattern :: EMAIL ) ;
157
- let server = provider. get_smtp_server ( ) [ 0 ] ;
172
+ let server = & provider. get_smtp_server ( ) [ 0 ] ;
158
173
assert_eq ! ( server. protocol, Protocol :: SMTP ) ;
159
174
assert_eq ! ( server. socket, Socket :: STARTTLS ) ;
160
175
assert_eq ! ( server. hostname, "smtp.nauta.cu" ) ;
0 commit comments