Skip to content

Separate IMAP and SMTP configuration #1835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 32 additions & 35 deletions deltachat-ffi/deltachat.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ char* dc_get_blobdir (const dc_context_t* context);
* - `mail_user` = IMAP-username, guessed if left out
* - `mail_pw` = IMAP-password (always needed)
* - `mail_port` = IMAP-port, guessed if left out
* - `mail_security`= IMAP-socket, one of @ref DC_SOCKET, defaults to #DC_SOCKET_AUTO
* - `send_server` = SMTP-server, guessed if left out
* - `send_user` = SMTP-user, guessed if left out
* - `send_pw` = SMTP-password, guessed if left out
* - `send_port` = SMTP-port, guessed if left out
* - `send_security`= SMTP-socket, one of @ref DC_SOCKET, defaults to #DC_SOCKET_AUTO
* - `server_flags` = IMAP-/SMTP-flags as a combination of @ref DC_LP flags, guessed if left out
* - `imap_certificate_checks` = how to check IMAP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
* - `smtp_certificate_checks` = how to check SMTP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
Expand Down Expand Up @@ -4167,88 +4169,83 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
*/
#define DC_MSG_VIDEOCHAT_INVITATION 70


/**
* @}
*/


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


/**
* Force OAuth2 authorization. This flag does not skip automatic configuration.
* Before calling dc_configure() with DC_LP_AUTH_OAUTH2 set,
* the user has to confirm access at the URL returned by dc_get_oauth2_url().
* Choose socket security automatically.
*/
#define DC_LP_AUTH_OAUTH2 0x2
#define DC_SOCKET_AUTO 0


/**
* Force NORMAL authorization, this is the default.
* If this flag is set, automatic configuration is skipped.
* Connect via SSL/TLS.
*/
#define DC_LP_AUTH_NORMAL 0x4
#define DC_SOCKET_SSL 1


/**
* Connect to IMAP via STARTTLS.
* If this flag is set, automatic configuration is skipped.
* Connect via STARTTLS.
*/
#define DC_LP_IMAP_SOCKET_STARTTLS 0x100
#define DC_SOCKET_STARTTLS 2


/**
* Connect to IMAP via SSL.
* If this flag is set, automatic configuration is skipped.
* Connect unencrypted, this should not be used.
*/
#define DC_LP_IMAP_SOCKET_SSL 0x200

#define DC_SOCKET_PLAIN 3

/**
* Connect to IMAP unencrypted, this should not be used.
* If this flag is set, automatic configuration is skipped.
* @}
*/
#define DC_LP_IMAP_SOCKET_PLAIN 0x400


/**
* Connect to SMTP via STARTTLS.
* If this flag is set, automatic configuration is skipped.
* @defgroup DC_LP DC_LP
*
* Flags for configuring IMAP and SMTP servers.
* These flags are optional
* and may be set together with the username, password etc.
* via dc_set_config() using the key "server_flags".
*
* @addtogroup DC_LP
* @{
*/
#define DC_LP_SMTP_SOCKET_STARTTLS 0x10000


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


/**
* Connect to SMTP unencrypted, this should not be used.
* Force NORMAL authorization, this is the default.
* If this flag is set, automatic configuration is skipped.
*/
#define DC_LP_SMTP_SOCKET_PLAIN 0x40000 ///<
#define DC_LP_AUTH_NORMAL 0x4


/**
* @}
*/

#define DC_LP_AUTH_FLAGS (DC_LP_AUTH_OAUTH2|DC_LP_AUTH_NORMAL) // if none of these flags are set, the default is chosen
#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
#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

/**
* @defgroup DC_CERTCK DC_CERTCK
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ pub enum Config {
MailUser,
MailPw,
MailPort,
MailSecurity,
ImapCertificateChecks,
SendServer,
SendUser,
SendPw,
SendPort,
SendSecurity,
SmtpCertificateChecks,
ServerFlags,

Expand Down
42 changes: 21 additions & 21 deletions src/configure/auto_mozilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//! Documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Autoconfiguration */
use quick_xml::events::{BytesEnd, BytesStart, BytesText};

use crate::constants::*;
use crate::context::Context;
use crate::login_param::LoginParam;
use crate::provider::Socket;

use super::read_url::read_url;
use super::Error;
Expand Down Expand Up @@ -83,10 +83,10 @@ fn parse_xml(in_emailaddr: &str, xml_raw: &str) -> Result<LoginParam, Error> {
buf.clear();
}

if moz_ac.out.mail_server.is_empty()
|| moz_ac.out.mail_port == 0
|| moz_ac.out.send_server.is_empty()
|| moz_ac.out.send_port == 0
if moz_ac.out.imap.server.is_empty()
|| moz_ac.out.imap.port == 0
|| moz_ac.out.smtp.server.is_empty()
|| moz_ac.out.smtp.port == 0
{
Err(Error::IncompleteAutoconfig(moz_ac.out))
} else {
Expand Down Expand Up @@ -130,37 +130,37 @@ fn moz_autoconfigure_text_cb<B: std::io::BufRead>(

match moz_ac.tag_server {
MozServer::Imap => match moz_ac.tag_config {
MozConfigTag::Hostname => moz_ac.out.mail_server = val,
MozConfigTag::Port => moz_ac.out.mail_port = val.parse().unwrap_or_default(),
MozConfigTag::Username => moz_ac.out.mail_user = val,
MozConfigTag::Hostname => moz_ac.out.imap.server = val,
MozConfigTag::Port => moz_ac.out.imap.port = val.parse().unwrap_or_default(),
MozConfigTag::Username => moz_ac.out.imap.user = val,
MozConfigTag::Sockettype => {
let val_lower = val.to_lowercase();
if val_lower == "ssl" {
moz_ac.out.server_flags |= DC_LP_IMAP_SOCKET_SSL as i32
moz_ac.out.imap.security = Socket::SSL;
}
if val_lower == "starttls" {
moz_ac.out.server_flags |= DC_LP_IMAP_SOCKET_STARTTLS as i32
moz_ac.out.imap.security = Socket::STARTTLS;
}
if val_lower == "plain" {
moz_ac.out.server_flags |= DC_LP_IMAP_SOCKET_PLAIN as i32
moz_ac.out.imap.security = Socket::Plain;
}
}
_ => {}
},
MozServer::Smtp => match moz_ac.tag_config {
MozConfigTag::Hostname => moz_ac.out.send_server = val,
MozConfigTag::Port => moz_ac.out.send_port = val.parse().unwrap_or_default(),
MozConfigTag::Username => moz_ac.out.send_user = val,
MozConfigTag::Hostname => moz_ac.out.smtp.server = val,
MozConfigTag::Port => moz_ac.out.smtp.port = val.parse().unwrap_or_default(),
MozConfigTag::Username => moz_ac.out.smtp.user = val,
MozConfigTag::Sockettype => {
let val_lower = val.to_lowercase();
if val_lower == "ssl" {
moz_ac.out.server_flags |= DC_LP_SMTP_SOCKET_SSL as i32
moz_ac.out.smtp.security = Socket::SSL;
}
if val_lower == "starttls" {
moz_ac.out.server_flags |= DC_LP_SMTP_SOCKET_STARTTLS as i32
moz_ac.out.smtp.security = Socket::STARTTLS;
}
if val_lower == "plain" {
moz_ac.out.server_flags |= DC_LP_SMTP_SOCKET_PLAIN as i32
moz_ac.out.smtp.security = Socket::Plain;
}
}
_ => {}
Expand Down Expand Up @@ -314,9 +314,9 @@ mod tests {
</webMail>
</clientConfig>";
let res = parse_xml("[email protected]", xml_raw).expect("XML parsing failed");
assert_eq!(res.mail_server, "outlook.office365.com");
assert_eq!(res.mail_port, 993);
assert_eq!(res.send_server, "smtp.office365.com");
assert_eq!(res.send_port, 587);
assert_eq!(res.imap.server, "outlook.office365.com");
assert_eq!(res.imap.port, 993);
assert_eq!(res.smtp.server, "smtp.office365.com");
assert_eq!(res.smtp.port, 587);
}
}
36 changes: 18 additions & 18 deletions src/configure/auto_outlook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use quick_xml::events::BytesEnd;

use crate::constants::*;
use crate::context::Context;
use crate::login_param::LoginParam;
use crate::provider::Socket;

use super::read_url::read_url;
use super::Error;
Expand All @@ -15,7 +15,7 @@ struct OutlookAutodiscover {
pub out_smtp_set: bool,
pub config_type: Option<String>,
pub config_server: String,
pub config_port: i32,
pub config_port: u16,
pub config_ssl: String,
pub config_redirecturl: Option<String>,
}
Expand Down Expand Up @@ -98,10 +98,10 @@ fn parse_xml(xml_raw: &str) -> Result<ParsingResult, Error> {
let res = if outlk_ad.config_redirecturl.is_none()
|| outlk_ad.config_redirecturl.as_ref().unwrap().is_empty()
{
if outlk_ad.out.mail_server.is_empty()
|| outlk_ad.out.mail_port == 0
|| outlk_ad.out.send_server.is_empty()
|| outlk_ad.out.send_port == 0
if outlk_ad.out.imap.server.is_empty()
|| outlk_ad.out.imap.port == 0
|| outlk_ad.out.smtp.server.is_empty()
|| outlk_ad.out.smtp.port == 0
{
return Err(Error::IncompleteAutoconfig(outlk_ad.out));
}
Expand Down Expand Up @@ -142,23 +142,23 @@ fn outlk_autodiscover_endtag_cb(event: &BytesEnd, outlk_ad: &mut OutlookAutodisc
let ssl_on = outlk_ad.config_ssl == "on";
let ssl_off = outlk_ad.config_ssl == "off";
if type_ == "imap" && !outlk_ad.out_imap_set {
outlk_ad.out.mail_server =
outlk_ad.out.imap.server =
std::mem::replace(&mut outlk_ad.config_server, String::new());
outlk_ad.out.mail_port = port;
outlk_ad.out.imap.port = port;
if ssl_on {
outlk_ad.out.server_flags |= DC_LP_IMAP_SOCKET_SSL as i32
outlk_ad.out.imap.security = Socket::SSL
} else if ssl_off {
outlk_ad.out.server_flags |= DC_LP_IMAP_SOCKET_PLAIN as i32
outlk_ad.out.imap.security = Socket::Plain
}
outlk_ad.out_imap_set = true
} else if type_ == "smtp" && !outlk_ad.out_smtp_set {
outlk_ad.out.send_server =
outlk_ad.out.smtp.server =
std::mem::replace(&mut outlk_ad.config_server, String::new());
outlk_ad.out.send_port = outlk_ad.config_port;
outlk_ad.out.smtp.port = outlk_ad.config_port;
if ssl_on {
outlk_ad.out.server_flags |= DC_LP_SMTP_SOCKET_SSL as i32
outlk_ad.out.smtp.security = Socket::SSL
} else if ssl_off {
outlk_ad.out.server_flags |= DC_LP_SMTP_SOCKET_PLAIN as i32
outlk_ad.out.smtp.security = Socket::Plain
}
outlk_ad.out_smtp_set = true
}
Expand Down Expand Up @@ -229,10 +229,10 @@ mod tests {

match res {
ParsingResult::LoginParam(lp) => {
assert_eq!(lp.mail_server, "example.com");
assert_eq!(lp.mail_port, 993);
assert_eq!(lp.send_server, "smtp.example.com");
assert_eq!(lp.send_port, 25);
assert_eq!(lp.imap.server, "example.com");
assert_eq!(lp.imap.port, 993);
assert_eq!(lp.smtp.server, "smtp.example.com");
assert_eq!(lp.smtp.port, 25);
}
ParsingResult::RedirectUrl(_) => {
panic!("RedirectUrl is not expected");
Expand Down
Loading