Implemented desktop OAuth2 account setup for Google and Microsoft. The flow uses the system browser and PKCE; access and refresh tokens stay in the main process and encrypted account store. OAuth connections use fixed provider endpoints, and existing password-based accounts remain supported. Android remains password-based in this phase.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
function createMailConnections({ ImapFlow, createTransport, oauthTokenManager }) {
|
||||
async function imapClient(account, options = {}) {
|
||||
const isOAuth = account.authMethod === 'oauth2';
|
||||
const auth = isOAuth
|
||||
? { user: account.email, accessToken: await oauthTokenManager.getAccessToken(account) }
|
||||
: { user: account.email, pass: account.password };
|
||||
return new ImapFlow({
|
||||
host: account.imapHost,
|
||||
port: account.imapPort,
|
||||
secure: Boolean(account.imapSecure),
|
||||
doSTARTTLS: !account.imapSecure,
|
||||
auth,
|
||||
tls: { rejectUnauthorized: true },
|
||||
logger: false,
|
||||
connectionTimeout: 15000,
|
||||
greetingTimeout: 10000,
|
||||
socketTimeout: 20000,
|
||||
...options
|
||||
});
|
||||
}
|
||||
|
||||
async function smtpTransport(account) {
|
||||
const isOAuth = account.authMethod === 'oauth2';
|
||||
const auth = isOAuth
|
||||
? {
|
||||
type: 'OAuth2',
|
||||
user: account.email,
|
||||
accessToken: await oauthTokenManager.getAccessToken(account),
|
||||
expires: account.oauthAccessTokenExpiresAt
|
||||
}
|
||||
: { user: account.email, pass: account.password };
|
||||
const secure = Boolean(account.smtpSecure);
|
||||
return createTransport({
|
||||
host: account.smtpHost,
|
||||
port: account.smtpPort,
|
||||
secure,
|
||||
requireTLS: !secure,
|
||||
auth,
|
||||
tls: { rejectUnauthorized: true, servername: account.smtpHost },
|
||||
connectionTimeout: 15000,
|
||||
greetingTimeout: 10000,
|
||||
socketTimeout: 20000
|
||||
});
|
||||
}
|
||||
|
||||
return Object.freeze({ imapClient, smtpTransport });
|
||||
}
|
||||
|
||||
module.exports = { createMailConnections };
|
||||
Reference in New Issue
Block a user