@@ -6,16 +6,17 @@ use std::sync::LazyLock;
66
77use anyhow:: { Context as _, Result , anyhow, bail, ensure} ;
88pub use dclogin_scheme:: LoginOptions ;
9+ pub ( crate ) use dclogin_scheme:: login_param_from_login_qr;
910use deltachat_contact_tools:: { ContactAddress , addr_normalize, may_be_valid_addr} ;
1011use percent_encoding:: { NON_ALPHANUMERIC , percent_decode_str, percent_encode} ;
1112use serde:: Deserialize ;
1213
13- pub ( crate ) use self :: dclogin_scheme:: configure_from_login_qr;
1414use crate :: config:: Config ;
1515use crate :: contact:: { Contact , ContactId , Origin } ;
1616use crate :: context:: Context ;
1717use crate :: events:: EventType ;
1818use crate :: key:: Fingerprint ;
19+ use crate :: login_param:: { EnteredCertificateChecks , EnteredLoginParam , EnteredServerLoginParam } ;
1920use crate :: net:: http:: post_empty;
2021use crate :: net:: proxy:: { DEFAULT_SOCKS_PORT , ProxyConfig } ;
2122use crate :: token;
@@ -651,10 +652,13 @@ struct CreateAccountErrorResponse {
651652 reason : String ,
652653}
653654
654- /// take a qr of the type DC_QR_ACCOUNT, parse it's parameters,
655- /// download additional information from the contained url and set the parameters.
656- /// on success, a configure::configure() should be able to log in to the account
657- pub ( crate ) async fn set_account_from_qr ( context : & Context , qr : & str ) -> Result < ( ) > {
655+ /// Takes a QR with `DCACCOUNT:` scheme, parses its parameters,
656+ /// downloads additional information from the contained URL
657+ /// and returns the login parameters.
658+ pub ( crate ) async fn login_param_from_account_qr (
659+ context : & Context ,
660+ qr : & str ,
661+ ) -> Result < EnteredLoginParam > {
658662 let url_str = qr
659663 . get ( DCACCOUNT_SCHEME . len ( ) ..)
660664 . context ( "Invalid DCACCOUNT scheme" ) ?;
@@ -669,14 +673,19 @@ pub(crate) async fn set_account_from_qr(context: &Context, qr: &str) -> Result<(
669673 . with_context ( || {
670674 format ! ( "Cannot create account, response is malformed:\n {response_text:?}" )
671675 } ) ?;
672- context
673- . set_config_internal ( Config :: Addr , Some ( & email) )
674- . await ?;
675- context
676- . set_config_internal ( Config :: MailPw , Some ( & password) )
677- . await ?;
678676
679- Ok ( ( ) )
677+ let param = EnteredLoginParam {
678+ addr : email,
679+ imap : EnteredServerLoginParam {
680+ password,
681+ ..Default :: default ( )
682+ } ,
683+ smtp : Default :: default ( ) ,
684+ certificate_checks : EnteredCertificateChecks :: Strict ,
685+ oauth2 : false ,
686+ } ;
687+
688+ Ok ( param)
680689 } else {
681690 match serde_json:: from_str :: < CreateAccountErrorResponse > ( & response_text) {
682691 Ok ( error) => Err ( anyhow ! ( error. reason) ) ,
@@ -693,7 +702,10 @@ pub(crate) async fn set_account_from_qr(context: &Context, qr: &str) -> Result<(
693702/// Sets configuration values from a QR code.
694703pub async fn set_config_from_qr ( context : & Context , qr : & str ) -> Result < ( ) > {
695704 match check_qr ( context, qr) . await ? {
696- Qr :: Account { .. } => set_account_from_qr ( context, qr) . await ?,
705+ Qr :: Account { .. } => {
706+ let mut param = login_param_from_account_qr ( context, qr) . await ?;
707+ context. add_transport_inner ( & mut param) . await ?
708+ }
697709 Qr :: Proxy { url, .. } => {
698710 let old_proxy_url_value = context
699711 . get_config ( Config :: ProxyUrl )
@@ -781,7 +793,8 @@ pub async fn set_config_from_qr(context: &Context, qr: &str) -> Result<()> {
781793 context. scheduler . interrupt_inbox ( ) . await ;
782794 }
783795 Qr :: Login { address, options } => {
784- configure_from_login_qr ( context, & address, options) . await ?
796+ let mut param = login_param_from_login_qr ( & address, options) ?;
797+ context. add_transport_inner ( & mut param) . await ?
785798 }
786799 _ => bail ! ( "QR code does not contain config" ) ,
787800 }
0 commit comments