Skip to content

Commit a398d71

Browse files
author
Alexander Krotov
committed
Add Socket::Plain variant
Constant values are the same as desktop uses. Invalid flags are converted to STARTTLS.
1 parent fce5816 commit a398d71

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

src/configure/mod.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ pub fn loginparam_new_to_old(context: &Context, servers: &LoginParamNew) -> Opti
395395
p.mail_port = imap.port as i32;
396396
p.imap_certificate_checks = CertificateChecks::AcceptInvalidCertificates;
397397
p.server_flags |= match imap.socket {
398+
provider::Socket::Plain => DC_LP_SMTP_SOCKET_PLAIN,
398399
provider::Socket::STARTTLS => DC_LP_IMAP_SOCKET_STARTTLS,
399400
provider::Socket::SSL => DC_LP_IMAP_SOCKET_SSL,
400401
};
@@ -404,8 +405,9 @@ pub fn loginparam_new_to_old(context: &Context, servers: &LoginParamNew) -> Opti
404405
p.send_port = smtp.port as i32;
405406
p.smtp_certificate_checks = CertificateChecks::AcceptInvalidCertificates;
406407
p.server_flags |= match smtp.socket {
407-
provider::Socket::STARTTLS => DC_LP_SMTP_SOCKET_STARTTLS as i32,
408-
provider::Socket::SSL => DC_LP_SMTP_SOCKET_SSL as i32,
408+
provider::Socket::Plain => DC_LP_SMTP_SOCKET_PLAIN,
409+
provider::Socket::STARTTLS => DC_LP_SMTP_SOCKET_STARTTLS,
410+
provider::Socket::SSL => DC_LP_SMTP_SOCKET_SSL,
409411
};
410412

411413
info!(context, "offline autoconfig found: {}", p);
@@ -421,11 +423,12 @@ pub fn loginparam_old_to_new(p: LoginParam) -> LoginParamNew {
421423
addr: p.addr.clone(),
422424
imap: vec![ServerParams {
423425
protocol: Protocol::IMAP,
424-
socket: if 0 != p.server_flags & DC_LP_IMAP_SOCKET_STARTTLS {
425-
provider::Socket::STARTTLS
426-
} else {
427-
provider::Socket::SSL
428-
}, // TODO what about plain? And if no socket was specified in the LoginParam?
426+
socket: match p.server_flags & DC_LP_IMAP_SOCKET_FLAGS as i32 {
427+
DC_LP_IMAP_SOCKET_PLAIN => provider::Socket::Plain,
428+
DC_LP_IMAP_SOCKET_STARTTLS => provider::Socket::STARTTLS,
429+
DC_LP_IMAP_SOCKET_SSL => provider::Socket::SSL,
430+
_ => Default::default(),
431+
},
429432
port: p.mail_port as u16,
430433
hostname: p.mail_server,
431434
username_pattern: if p.mail_user.contains('@') {
@@ -436,11 +439,12 @@ pub fn loginparam_old_to_new(p: LoginParam) -> LoginParamNew {
436439
}],
437440
smtp: vec![ServerParams {
438441
protocol: Protocol::SMTP,
439-
socket: if 0 != p.server_flags as usize & DC_LP_SMTP_SOCKET_STARTTLS {
440-
provider::Socket::STARTTLS
441-
} else {
442-
provider::Socket::SSL
443-
}, // TODO what about plain? And if no socket was specified in the LoginParam?
442+
socket: match p.server_flags & DC_LP_SMTP_SOCKET_FLAGS as i32 {
443+
DC_LP_SMTP_SOCKET_PLAIN => provider::Socket::Plain,
444+
DC_LP_SMTP_SOCKET_STARTTLS => provider::Socket::STARTTLS,
445+
DC_LP_SMTP_SOCKET_SSL => provider::Socket::SSL,
446+
_ => Default::default(),
447+
},
444448
port: p.send_port as u16,
445449
hostname: p.send_server,
446450
username_pattern: if p.send_user.contains('@') {

src/constants.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,23 @@ pub const DC_LP_IMAP_SOCKET_PLAIN: i32 = 0x400;
213213

214214
/// Connect to SMTP via STARTTLS.
215215
/// If this flag is set, automatic configuration is skipped.
216-
pub const DC_LP_SMTP_SOCKET_STARTTLS: usize = 0x10000;
216+
pub const DC_LP_SMTP_SOCKET_STARTTLS: i32 = 0x10000;
217217

218218
/// Connect to SMTP via SSL.
219219
/// If this flag is set, automatic configuration is skipped.
220-
pub const DC_LP_SMTP_SOCKET_SSL: usize = 0x20000;
220+
pub const DC_LP_SMTP_SOCKET_SSL: i32 = 0x20000;
221221

222222
/// Connect to SMTP unencrypted, this should not be used.
223223
/// If this flag is set, automatic configuration is skipped.
224-
pub const DC_LP_SMTP_SOCKET_PLAIN: usize = 0x40000;
224+
pub const DC_LP_SMTP_SOCKET_PLAIN: i32 = 0x40000;
225225

226226
/// if none of these flags are set, the default is chosen
227227
pub const DC_LP_AUTH_FLAGS: i32 = DC_LP_AUTH_OAUTH2 | DC_LP_AUTH_NORMAL;
228228
/// if none of these flags are set, the default is chosen
229229
pub const DC_LP_IMAP_SOCKET_FLAGS: i32 =
230230
DC_LP_IMAP_SOCKET_STARTTLS | DC_LP_IMAP_SOCKET_SSL | DC_LP_IMAP_SOCKET_PLAIN;
231231
/// if none of these flags are set, the default is chosen
232-
pub const DC_LP_SMTP_SOCKET_FLAGS: usize =
232+
pub const DC_LP_SMTP_SOCKET_FLAGS: i32 =
233233
DC_LP_SMTP_SOCKET_STARTTLS | DC_LP_SMTP_SOCKET_SSL | DC_LP_SMTP_SOCKET_PLAIN;
234234

235235
// QR code scanning (view from Bob, the joiner)

src/provider/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ pub enum Protocol {
2727
#[derive(Debug, PartialEq, Clone)]
2828
#[repr(u8)]
2929
pub enum Socket {
30-
STARTTLS = 1,
31-
SSL = 2,
30+
SSL = 1,
31+
STARTTLS = 2,
32+
Plain = 3,
33+
}
34+
35+
impl Default for Socket {
36+
fn default() -> Self {
37+
Socket::STARTTLS
38+
}
3239
}
3340

3441
#[derive(Debug, PartialEq, Clone)]

0 commit comments

Comments
 (0)