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:
rustmailer
2025-12-03 03:48:39 +08:00
parent 3a2b42f5c3
commit 454950374f
22 changed files with 25 additions and 7 deletions
+3 -2
View File
@@ -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
}
}