Skip to content

Commit 61ec54e

Browse files
committed
Move things around, optimize uses
1 parent 3b4ad42 commit 61ec54e

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

src/configure/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ use crate::constants::*;
1313
use crate::context::Context;
1414
use crate::dc_tools::*;
1515
use crate::imap::Imap;
16-
use crate::login_param::{CertificateChecks, LoginParam};
16+
use crate::login_param::{CertificateChecks, LoginParam, LoginParamNew, ServerParams};
1717
use crate::message::Message;
1818
use crate::oauth2::*;
1919
use crate::smtp::Smtp;
2020
use crate::{chat, e2ee, provider};
2121

2222
use auto_mozilla::moz_autoconfigure;
2323
use auto_outlook::outlk_autodiscover;
24-
use provider::Server;
25-
use provider::{ImapServers, LoginParamNew, Protocol, ServerParams, SmtpServers, UsernamePattern};
26-
use std::rc::Rc;
24+
use provider::{Protocol, UsernamePattern};
2725

2826
macro_rules! progress {
2927
($context:tt, $progress:expr) => {

src/login_param.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
use std::borrow::Cow;
44
use std::fmt;
55

6-
use crate::context::Context;
6+
use crate::{
7+
context::Context,
8+
provider::{Protocol, Socket, UsernamePattern},
9+
};
710

811
#[derive(Copy, Clone, Debug, Display, FromPrimitive)]
912
#[repr(i32)]
@@ -25,6 +28,39 @@ impl Default for CertificateChecks {
2528
}
2629
}
2730

31+
#[derive(Debug)]
32+
pub struct ServerParams {
33+
pub protocol: Protocol,
34+
pub socket: Socket,
35+
pub hostname: String,
36+
pub port: u16,
37+
pub username_pattern: UsernamePattern,
38+
}
39+
40+
pub type ImapServers = Vec<ServerParams>;
41+
pub type SmtpServers = Vec<ServerParams>;
42+
43+
#[derive(Debug)]
44+
pub struct LoginParamNew {
45+
pub addr: String,
46+
pub imap: ImapServers,
47+
pub smtp: SmtpServers,
48+
}
49+
50+
impl ServerParams {
51+
pub fn apply_username_pattern(&self, addr: String) -> String {
52+
match self.username_pattern {
53+
UsernamePattern::EMAIL => addr,
54+
UsernamePattern::EMAILLOCALPART => {
55+
if let Some(at) = addr.find('@') {
56+
return addr.split_at(at).0.to_string();
57+
}
58+
addr
59+
}
60+
}
61+
}
62+
}
63+
2864
#[derive(Default, Debug, Clone)]
2965
pub struct LoginParam {
3066
pub addr: String,

src/provider/mod.rs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ mod data;
44

55
use crate::config::Config;
66
use crate::dc_tools::EmailAddress;
7-
use crate::provider::data::PROVIDER_DATA;
7+
use crate::{
8+
login_param::{ImapServers, ServerParams, SmtpServers},
9+
provider::data::PROVIDER_DATA,
10+
};
811

912
#[derive(Debug, Copy, Clone, PartialEq, ToPrimitive)]
1013
#[repr(u8)]
@@ -51,39 +54,6 @@ pub struct Server {
5154
pub username_pattern: UsernamePattern,
5255
}
5356

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>;
65-
66-
#[derive(Debug)]
67-
pub struct LoginParamNew {
68-
pub addr: String,
69-
pub imap: ImapServers,
70-
pub smtp: SmtpServers,
71-
}
72-
73-
impl ServerParams {
74-
pub fn apply_username_pattern(&self, addr: String) -> String {
75-
match self.username_pattern {
76-
UsernamePattern::EMAIL => addr,
77-
UsernamePattern::EMAILLOCALPART => {
78-
if let Some(at) = addr.find('@') {
79-
return addr.split_at(at).0.to_string();
80-
}
81-
addr
82-
}
83-
}
84-
}
85-
}
86-
8757
#[derive(Debug)]
8858
pub struct ConfigDefault {
8959
pub key: Config,

0 commit comments

Comments
 (0)