From ba8ef9adf6effc40674765f995d19e9cfd1a8636 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Mon, 23 May 2022 22:41:29 +0000 Subject: [PATCH] fix(config/imap): get first line for password (#374) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(config/imap): get first line for password Fixes #373 * fix(config/smtp): get first line password Co-authored-by: Clément DOUIN --- cli/src/config/account_config.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cli/src/config/account_config.rs b/cli/src/config/account_config.rs index 22a0052..29cb3a0 100644 --- a/cli/src/config/account_config.rs +++ b/cli/src/config/account_config.rs @@ -238,11 +238,12 @@ impl<'a> AccountConfig { /// Builds the user account SMTP credentials. pub fn smtp_creds(&self) -> Result { let passwd = run_cmd(&self.smtp_passwd_cmd).context("cannot run SMTP passwd cmd")?; - let passwd = passwd - .trim_end_matches(|c| c == '\r' || c == '\n') - .to_owned(); + let passwd = passwd.lines().next().context("cannot find password")?; - Ok(SmtpCredentials::new(self.smtp_login.to_owned(), passwd)) + Ok(SmtpCredentials::new( + self.smtp_login.to_owned(), + passwd.to_owned(), + )) } /// Encrypts a file. @@ -374,10 +375,8 @@ impl ImapBackendConfig { /// Gets the IMAP password of the user account. pub fn imap_passwd(&self) -> Result { let passwd = run_cmd(&self.imap_passwd_cmd).context("cannot run IMAP passwd cmd")?; - let passwd = passwd - .trim_end_matches(|c| c == '\r' || c == '\n') - .to_owned(); - Ok(passwd) + let passwd = passwd.lines().next().context("cannot find password")?; + Ok(passwd.to_string()) } }