mirror of
https://github.com/chatmail/core.git
synced 2026-04-23 00:16:34 +03:00
Implement socks5 support
This adds following settings: - Socks5Enabled - Socks5Host - Socks5Port - Socks5User - Socks5Password Currently http requests and dns requests are not getting executed as they currently can't get tunneled through socks5 proxy. Therefore gmail with oauth2 wont work through tor.
This commit is contained in:
35
src/imap.rs
35
src/imap.rs
@@ -27,6 +27,7 @@ use crate::events::EventType;
|
||||
use crate::headerdef::{HeaderDef, HeaderDefMap};
|
||||
use crate::job::{self, Action};
|
||||
use crate::login_param::{CertificateChecks, LoginParam, ServerLoginParam};
|
||||
use crate::login_param::{ServerAddress, Socks5Config};
|
||||
use crate::message::{self, update_server_uid, MessageState};
|
||||
use crate::mimeparser;
|
||||
use crate::oauth2::dc_get_oauth2_access_token;
|
||||
@@ -142,6 +143,7 @@ impl FolderMeaning {
|
||||
struct ImapConfig {
|
||||
pub addr: String,
|
||||
pub lp: ServerLoginParam,
|
||||
pub socks5_config: Option<Socks5Config>,
|
||||
pub strict_tls: bool,
|
||||
pub oauth2: bool,
|
||||
pub selected_folder: Option<String>,
|
||||
@@ -165,6 +167,7 @@ impl Imap {
|
||||
/// `addr` is used to renew token if OAuth2 authentication is used.
|
||||
pub async fn new(
|
||||
lp: &ServerLoginParam,
|
||||
socks5_config: Option<Socks5Config>,
|
||||
addr: &str,
|
||||
oauth2: bool,
|
||||
provider_strict_tls: bool,
|
||||
@@ -183,6 +186,7 @@ impl Imap {
|
||||
let config = ImapConfig {
|
||||
addr: addr.to_string(),
|
||||
lp: lp.clone(),
|
||||
socks5_config,
|
||||
strict_tls,
|
||||
oauth2,
|
||||
selected_folder: None,
|
||||
@@ -222,6 +226,7 @@ impl Imap {
|
||||
|
||||
let imap = Self::new(
|
||||
¶m.imap,
|
||||
param.socks5_config.clone(),
|
||||
¶m.addr,
|
||||
param.server_flags & DC_LP_AUTH_OAUTH2 != 0,
|
||||
param.provider.map_or(false, |provider| provider.strict_tls),
|
||||
@@ -261,7 +266,20 @@ impl Imap {
|
||||
let imap_server: &str = config.lp.server.as_ref();
|
||||
let imap_port = config.lp.port;
|
||||
|
||||
match Client::connect_insecure((imap_server, imap_port)).await {
|
||||
let connection = if let Some(socks5_config) = &config.socks5_config {
|
||||
Client::connect_insecure_socks5(
|
||||
&ServerAddress {
|
||||
host: imap_server.to_string(),
|
||||
port: imap_port,
|
||||
},
|
||||
socks5_config.clone(),
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
Client::connect_insecure((imap_server, imap_port)).await
|
||||
};
|
||||
|
||||
match connection {
|
||||
Ok(client) => {
|
||||
if config.lp.security == Socket::Starttls {
|
||||
client.secure(imap_server, config.strict_tls).await
|
||||
@@ -276,7 +294,20 @@ impl Imap {
|
||||
let imap_server: &str = config.lp.server.as_ref();
|
||||
let imap_port = config.lp.port;
|
||||
|
||||
Client::connect_secure((imap_server, imap_port), imap_server, config.strict_tls).await
|
||||
if let Some(socks5_config) = &config.socks5_config {
|
||||
Client::connect_secure_socks5(
|
||||
&ServerAddress {
|
||||
host: imap_server.to_string(),
|
||||
port: imap_port,
|
||||
},
|
||||
config.strict_tls,
|
||||
socks5_config.clone(),
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
Client::connect_secure((imap_server, imap_port), imap_server, config.strict_tls)
|
||||
.await
|
||||
}
|
||||
};
|
||||
|
||||
let login_res = match connection_res {
|
||||
|
||||
Reference in New Issue
Block a user