Skip to content

Commit 5dcbb88

Browse files
Hocurilink2xtr10s
committed
Separate IMAP and SMTP configuration
Co-Authored-By: link2xt <[email protected]> Co-Authored-By: bjoern <[email protected]>
1 parent 4bd2a90 commit 5dcbb88

File tree

13 files changed

+542
-426
lines changed

13 files changed

+542
-426
lines changed

deltachat-ffi/deltachat.h

+32-35
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,12 @@ char* dc_get_blobdir (const dc_context_t* context);
274274
* - `mail_user` = IMAP-username, guessed if left out
275275
* - `mail_pw` = IMAP-password (always needed)
276276
* - `mail_port` = IMAP-port, guessed if left out
277+
* - `mail_security`= IMAP-socket, one of @ref DC_SOCKET, defaults to #DC_SOCKET_AUTO
277278
* - `send_server` = SMTP-server, guessed if left out
278279
* - `send_user` = SMTP-user, guessed if left out
279280
* - `send_pw` = SMTP-password, guessed if left out
280281
* - `send_port` = SMTP-port, guessed if left out
282+
* - `send_security`= SMTP-socket, one of @ref DC_SOCKET, defaults to #DC_SOCKET_AUTO
281283
* - `server_flags` = IMAP-/SMTP-flags as a combination of @ref DC_LP flags, guessed if left out
282284
* - `imap_certificate_checks` = how to check IMAP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
283285
* - `smtp_certificate_checks` = how to check SMTP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
@@ -4167,88 +4169,83 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
41674169
*/
41684170
#define DC_MSG_VIDEOCHAT_INVITATION 70
41694171

4170-
41714172
/**
41724173
* @}
41734174
*/
41744175

41754176

41764177
/**
4177-
* @defgroup DC_LP DC_LP
4178+
* @defgroup DC_SOCKET DC_SOCKET
41784179
*
4179-
* Flags for configuring IMAP and SMTP servers.
4180-
* These flags are optional
4181-
* and may be set together with the username, password etc.
4182-
* via dc_set_config() using the key "server_flags".
4180+
* These constants configure socket security.
4181+
* To set socket security, use dc_set_config() with the keys "mail_security" and/or "send_security".
4182+
* If no socket-configuration is explicitly specified, #DC_SOCKET_AUTO is used.
41834183
*
4184-
* @addtogroup DC_LP
4184+
* @addtogroup DC_SOCKET
41854185
* @{
41864186
*/
41874187

4188-
41894188
/**
4190-
* Force OAuth2 authorization. This flag does not skip automatic configuration.
4191-
* Before calling dc_configure() with DC_LP_AUTH_OAUTH2 set,
4192-
* the user has to confirm access at the URL returned by dc_get_oauth2_url().
4189+
* Choose socket security automatically.
41934190
*/
4194-
#define DC_LP_AUTH_OAUTH2 0x2
4191+
#define DC_SOCKET_AUTO 0
41954192

41964193

41974194
/**
4198-
* Force NORMAL authorization, this is the default.
4199-
* If this flag is set, automatic configuration is skipped.
4195+
* Connect via SSL/TLS.
42004196
*/
4201-
#define DC_LP_AUTH_NORMAL 0x4
4197+
#define DC_SOCKET_SSL 1
42024198

42034199

42044200
/**
4205-
* Connect to IMAP via STARTTLS.
4206-
* If this flag is set, automatic configuration is skipped.
4201+
* Connect via STARTTLS.
42074202
*/
4208-
#define DC_LP_IMAP_SOCKET_STARTTLS 0x100
4203+
#define DC_SOCKET_STARTTLS 2
42094204

42104205

42114206
/**
4212-
* Connect to IMAP via SSL.
4213-
* If this flag is set, automatic configuration is skipped.
4207+
* Connect unencrypted, this should not be used.
42144208
*/
4215-
#define DC_LP_IMAP_SOCKET_SSL 0x200
4216-
4209+
#define DC_SOCKET_PLAIN 3
42174210

42184211
/**
4219-
* Connect to IMAP unencrypted, this should not be used.
4220-
* If this flag is set, automatic configuration is skipped.
4212+
* @}
42214213
*/
4222-
#define DC_LP_IMAP_SOCKET_PLAIN 0x400
42234214

42244215

42254216
/**
4226-
* Connect to SMTP via STARTTLS.
4227-
* If this flag is set, automatic configuration is skipped.
4217+
* @defgroup DC_LP DC_LP
4218+
*
4219+
* Flags for configuring IMAP and SMTP servers.
4220+
* These flags are optional
4221+
* and may be set together with the username, password etc.
4222+
* via dc_set_config() using the key "server_flags".
4223+
*
4224+
* @addtogroup DC_LP
4225+
* @{
42284226
*/
4229-
#define DC_LP_SMTP_SOCKET_STARTTLS 0x10000
42304227

42314228

42324229
/**
4233-
* Connect to SMTP via SSL.
4234-
* If this flag is set, automatic configuration is skipped.
4230+
* Force OAuth2 authorization. This flag does not skip automatic configuration.
4231+
* Before calling dc_configure() with DC_LP_AUTH_OAUTH2 set,
4232+
* the user has to confirm access at the URL returned by dc_get_oauth2_url().
42354233
*/
4236-
#define DC_LP_SMTP_SOCKET_SSL 0x20000
4234+
#define DC_LP_AUTH_OAUTH2 0x2
42374235

42384236

42394237
/**
4240-
* Connect to SMTP unencrypted, this should not be used.
4238+
* Force NORMAL authorization, this is the default.
42414239
* If this flag is set, automatic configuration is skipped.
42424240
*/
4243-
#define DC_LP_SMTP_SOCKET_PLAIN 0x40000 ///<
4241+
#define DC_LP_AUTH_NORMAL 0x4
4242+
42444243

42454244
/**
42464245
* @}
42474246
*/
42484247

42494248
#define DC_LP_AUTH_FLAGS (DC_LP_AUTH_OAUTH2|DC_LP_AUTH_NORMAL) // if none of these flags are set, the default is chosen
4250-
#define DC_LP_IMAP_SOCKET_FLAGS (DC_LP_IMAP_SOCKET_STARTTLS|DC_LP_IMAP_SOCKET_SSL|DC_LP_IMAP_SOCKET_PLAIN) // if none of these flags are set, the default is chosen
4251-
#define DC_LP_SMTP_SOCKET_FLAGS (DC_LP_SMTP_SOCKET_STARTTLS|DC_LP_SMTP_SOCKET_SSL|DC_LP_SMTP_SOCKET_PLAIN) // if none of these flags are set, the default is chosen
42524249

42534250
/**
42544251
* @defgroup DC_CERTCK DC_CERTCK

src/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ pub enum Config {
2525
MailUser,
2626
MailPw,
2727
MailPort,
28+
MailSecurity,
2829
ImapCertificateChecks,
2930
SendServer,
3031
SendUser,
3132
SendPw,
3233
SendPort,
34+
SendSecurity,
3335
SmtpCertificateChecks,
3436
ServerFlags,
3537

src/configure/auto_mozilla.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//! Documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Autoconfiguration */
44
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
55

6-
use crate::constants::*;
76
use crate::context::Context;
87
use crate::login_param::LoginParam;
8+
use crate::provider::Socket;
99

1010
use super::read_url::read_url;
1111
use super::Error;
@@ -83,10 +83,10 @@ fn parse_xml(in_emailaddr: &str, xml_raw: &str) -> Result<LoginParam, Error> {
8383
buf.clear();
8484
}
8585

86-
if moz_ac.out.mail_server.is_empty()
87-
|| moz_ac.out.mail_port == 0
88-
|| moz_ac.out.send_server.is_empty()
89-
|| moz_ac.out.send_port == 0
86+
if moz_ac.out.imap.server.is_empty()
87+
|| moz_ac.out.imap.port == 0
88+
|| moz_ac.out.smtp.server.is_empty()
89+
|| moz_ac.out.smtp.port == 0
9090
{
9191
Err(Error::IncompleteAutoconfig(moz_ac.out))
9292
} else {
@@ -130,37 +130,37 @@ fn moz_autoconfigure_text_cb<B: std::io::BufRead>(
130130

131131
match moz_ac.tag_server {
132132
MozServer::Imap => match moz_ac.tag_config {
133-
MozConfigTag::Hostname => moz_ac.out.mail_server = val,
134-
MozConfigTag::Port => moz_ac.out.mail_port = val.parse().unwrap_or_default(),
135-
MozConfigTag::Username => moz_ac.out.mail_user = val,
133+
MozConfigTag::Hostname => moz_ac.out.imap.server = val,
134+
MozConfigTag::Port => moz_ac.out.imap.port = val.parse().unwrap_or_default(),
135+
MozConfigTag::Username => moz_ac.out.imap.user = val,
136136
MozConfigTag::Sockettype => {
137137
let val_lower = val.to_lowercase();
138138
if val_lower == "ssl" {
139-
moz_ac.out.server_flags |= DC_LP_IMAP_SOCKET_SSL as i32
139+
moz_ac.out.imap.security = Socket::SSL;
140140
}
141141
if val_lower == "starttls" {
142-
moz_ac.out.server_flags |= DC_LP_IMAP_SOCKET_STARTTLS as i32
142+
moz_ac.out.imap.security = Socket::STARTTLS;
143143
}
144144
if val_lower == "plain" {
145-
moz_ac.out.server_flags |= DC_LP_IMAP_SOCKET_PLAIN as i32
145+
moz_ac.out.imap.security = Socket::Plain;
146146
}
147147
}
148148
_ => {}
149149
},
150150
MozServer::Smtp => match moz_ac.tag_config {
151-
MozConfigTag::Hostname => moz_ac.out.send_server = val,
152-
MozConfigTag::Port => moz_ac.out.send_port = val.parse().unwrap_or_default(),
153-
MozConfigTag::Username => moz_ac.out.send_user = val,
151+
MozConfigTag::Hostname => moz_ac.out.smtp.server = val,
152+
MozConfigTag::Port => moz_ac.out.smtp.port = val.parse().unwrap_or_default(),
153+
MozConfigTag::Username => moz_ac.out.smtp.user = val,
154154
MozConfigTag::Sockettype => {
155155
let val_lower = val.to_lowercase();
156156
if val_lower == "ssl" {
157-
moz_ac.out.server_flags |= DC_LP_SMTP_SOCKET_SSL as i32
157+
moz_ac.out.smtp.security = Socket::SSL;
158158
}
159159
if val_lower == "starttls" {
160-
moz_ac.out.server_flags |= DC_LP_SMTP_SOCKET_STARTTLS as i32
160+
moz_ac.out.smtp.security = Socket::STARTTLS;
161161
}
162162
if val_lower == "plain" {
163-
moz_ac.out.server_flags |= DC_LP_SMTP_SOCKET_PLAIN as i32
163+
moz_ac.out.smtp.security = Socket::Plain;
164164
}
165165
}
166166
_ => {}
@@ -314,9 +314,9 @@ mod tests {
314314
</webMail>
315315
</clientConfig>";
316316
let res = parse_xml("[email protected]", xml_raw).expect("XML parsing failed");
317-
assert_eq!(res.mail_server, "outlook.office365.com");
318-
assert_eq!(res.mail_port, 993);
319-
assert_eq!(res.send_server, "smtp.office365.com");
320-
assert_eq!(res.send_port, 587);
317+
assert_eq!(res.imap.server, "outlook.office365.com");
318+
assert_eq!(res.imap.port, 993);
319+
assert_eq!(res.smtp.server, "smtp.office365.com");
320+
assert_eq!(res.smtp.port, 587);
321321
}
322322
}

src/configure/auto_outlook.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
33
use quick_xml::events::BytesEnd;
44

5-
use crate::constants::*;
65
use crate::context::Context;
76
use crate::login_param::LoginParam;
7+
use crate::provider::Socket;
88

99
use super::read_url::read_url;
1010
use super::Error;
@@ -15,7 +15,7 @@ struct OutlookAutodiscover {
1515
pub out_smtp_set: bool,
1616
pub config_type: Option<String>,
1717
pub config_server: String,
18-
pub config_port: i32,
18+
pub config_port: u16,
1919
pub config_ssl: String,
2020
pub config_redirecturl: Option<String>,
2121
}
@@ -98,10 +98,10 @@ fn parse_xml(xml_raw: &str) -> Result<ParsingResult, Error> {
9898
let res = if outlk_ad.config_redirecturl.is_none()
9999
|| outlk_ad.config_redirecturl.as_ref().unwrap().is_empty()
100100
{
101-
if outlk_ad.out.mail_server.is_empty()
102-
|| outlk_ad.out.mail_port == 0
103-
|| outlk_ad.out.send_server.is_empty()
104-
|| outlk_ad.out.send_port == 0
101+
if outlk_ad.out.imap.server.is_empty()
102+
|| outlk_ad.out.imap.port == 0
103+
|| outlk_ad.out.smtp.server.is_empty()
104+
|| outlk_ad.out.smtp.port == 0
105105
{
106106
return Err(Error::IncompleteAutoconfig(outlk_ad.out));
107107
}
@@ -142,23 +142,23 @@ fn outlk_autodiscover_endtag_cb(event: &BytesEnd, outlk_ad: &mut OutlookAutodisc
142142
let ssl_on = outlk_ad.config_ssl == "on";
143143
let ssl_off = outlk_ad.config_ssl == "off";
144144
if type_ == "imap" && !outlk_ad.out_imap_set {
145-
outlk_ad.out.mail_server =
145+
outlk_ad.out.imap.server =
146146
std::mem::replace(&mut outlk_ad.config_server, String::new());
147-
outlk_ad.out.mail_port = port;
147+
outlk_ad.out.imap.port = port;
148148
if ssl_on {
149-
outlk_ad.out.server_flags |= DC_LP_IMAP_SOCKET_SSL as i32
149+
outlk_ad.out.imap.security = Socket::SSL
150150
} else if ssl_off {
151-
outlk_ad.out.server_flags |= DC_LP_IMAP_SOCKET_PLAIN as i32
151+
outlk_ad.out.imap.security = Socket::Plain
152152
}
153153
outlk_ad.out_imap_set = true
154154
} else if type_ == "smtp" && !outlk_ad.out_smtp_set {
155-
outlk_ad.out.send_server =
155+
outlk_ad.out.smtp.server =
156156
std::mem::replace(&mut outlk_ad.config_server, String::new());
157-
outlk_ad.out.send_port = outlk_ad.config_port;
157+
outlk_ad.out.smtp.port = outlk_ad.config_port;
158158
if ssl_on {
159-
outlk_ad.out.server_flags |= DC_LP_SMTP_SOCKET_SSL as i32
159+
outlk_ad.out.smtp.security = Socket::SSL
160160
} else if ssl_off {
161-
outlk_ad.out.server_flags |= DC_LP_SMTP_SOCKET_PLAIN as i32
161+
outlk_ad.out.smtp.security = Socket::Plain
162162
}
163163
outlk_ad.out_smtp_set = true
164164
}
@@ -229,10 +229,10 @@ mod tests {
229229

230230
match res {
231231
ParsingResult::LoginParam(lp) => {
232-
assert_eq!(lp.mail_server, "example.com");
233-
assert_eq!(lp.mail_port, 993);
234-
assert_eq!(lp.send_server, "smtp.example.com");
235-
assert_eq!(lp.send_port, 25);
232+
assert_eq!(lp.imap.server, "example.com");
233+
assert_eq!(lp.imap.port, 993);
234+
assert_eq!(lp.smtp.server, "smtp.example.com");
235+
assert_eq!(lp.smtp.port, 25);
236236
}
237237
ParsingResult::RedirectUrl(_) => {
238238
panic!("RedirectUrl is not expected");

0 commit comments

Comments
 (0)