mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
feat(account): Prioritize dedicated name field for IMAP authentication username #28
Refactor account authentication logic to prioritize the `name` field over the `email` field during the IMAP connection phase. - The `name` field now serves as the primary IMAP login credential and is no longer treated purely as an optional, descriptive field. - If the `name` field is empty or unset, the system will fall back to using the full `email` address for authentication. - This change supports IMAP providers that require a username different from the full email address (e.g., employee ID, specific account name).
This commit is contained in:
@@ -67,6 +67,7 @@ impl ImapConnectionManager {
|
||||
) -> BichonResult<Session<Box<dyn SessionStream>>> {
|
||||
assert_eq!(account.account_type, AccountType::IMAP);
|
||||
let imap = account.imap.as_ref().unwrap();
|
||||
let username = account.name.clone().unwrap_or(account.email.clone());
|
||||
match &imap.auth.auth_type {
|
||||
AuthType::Password => {
|
||||
let password = &imap.auth.password.clone().ok_or_else(|| {
|
||||
@@ -77,7 +78,7 @@ impl ImapConnectionManager {
|
||||
})?;
|
||||
|
||||
let password = decrypt!(&password)?;
|
||||
client.login(&account.email, &password).await
|
||||
client.login(&username, &password).await
|
||||
}
|
||||
AuthType::OAuth2 => {
|
||||
let record = OAuth2AccessToken::get(self.account_id).await?;
|
||||
@@ -89,7 +90,7 @@ impl ImapConnectionManager {
|
||||
)
|
||||
})?;
|
||||
client
|
||||
.authenticate(OAuth2::new(account.email.clone(), access_token))
|
||||
.authenticate(OAuth2::new(username, access_token))
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user