mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-01 10:33:14 +08:00
[isomorphic-core] Ensure smtp config exists
Summary: We previously weren't saving the smtp settings for cloud gmail accounts, and even though we fixed that, we still need to be able to handle the accounts that were authed before that fix went out. This diff changes `smtpConfig()` to always call `credentialsForProvider` instead of depending on what was saved in the database. Test Plan: manual Reviewers: juan, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D3980
This commit is contained in:
parent
fad1671d6e
commit
d415e7792e
2 changed files with 13 additions and 8 deletions
|
@ -93,6 +93,7 @@ function credentialsForProvider({provider, settings, email}) {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
SUPPORTED_PROVIDERS,
|
SUPPORTED_PROVIDERS,
|
||||||
|
credentialsForProvider,
|
||||||
imapAuthRouteConfig() {
|
imapAuthRouteConfig() {
|
||||||
return {
|
return {
|
||||||
description: 'Authenticates a new account.',
|
description: 'Authenticates a new account.',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const atob = require('atob')
|
const atob = require('atob')
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const {JSONColumn, JSONArrayColumn} = require('../database-types');
|
const {JSONColumn, JSONArrayColumn} = require('../database-types');
|
||||||
const {SUPPORTED_PROVIDERS} = require('../auth-helpers');
|
const {SUPPORTED_PROVIDERS, credentialsForProvider} = require('../auth-helpers');
|
||||||
|
|
||||||
const {DB_ENCRYPTION_ALGORITHM, DB_ENCRYPTION_PASSWORD} = process.env;
|
const {DB_ENCRYPTION_ALGORITHM, DB_ENCRYPTION_PASSWORD} = process.env;
|
||||||
|
|
||||||
|
@ -117,10 +117,15 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
},
|
},
|
||||||
|
|
||||||
smtpConfig() {
|
smtpConfig() {
|
||||||
const {smtp_host, smtp_port, ssl_required} = this.connectionSettings;
|
const {connectionSettings, connectionCredentials} = credentialsForProvider({
|
||||||
|
provider: this.provider,
|
||||||
|
settings: this.decryptedCredentials(),
|
||||||
|
email: this.emailAddress,
|
||||||
|
});
|
||||||
|
const {smtp_host, smtp_port, smtp_username, ssl_required} = connectionSettings;
|
||||||
let config = {}
|
let config = {}
|
||||||
if (this.connectionSettings.smtp_custom_config) {
|
if (connectionSettings.smtp_custom_config) {
|
||||||
config = this.connectionSettings.smtp_custom_config
|
config = connectionSettings.smtp_custom_config
|
||||||
} else {
|
} else {
|
||||||
config = {
|
config = {
|
||||||
host: smtp_host,
|
host: smtp_host,
|
||||||
|
@ -129,15 +134,14 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.provider === 'gmail') {
|
if (this.provider === 'gmail') {
|
||||||
const {xoauth2} = this.decryptedCredentials();
|
const {xoauth2} = connectionCredentials;
|
||||||
if (!xoauth2) {
|
if (!xoauth2) {
|
||||||
throw new Error("Missing XOAuth2 Token")
|
throw new Error("Missing XOAuth2 Token")
|
||||||
}
|
}
|
||||||
const {imap_username} = this.connectionSettings;
|
|
||||||
const token = this.bearerToken(xoauth2);
|
const token = this.bearerToken(xoauth2);
|
||||||
config.auth = { user: imap_username, xoauth2: token }
|
config.auth = { user: smtp_username, xoauth2: token }
|
||||||
} else if (SUPPORTED_PROVIDERS.has(this.provider)) {
|
} else if (SUPPORTED_PROVIDERS.has(this.provider)) {
|
||||||
const {smtp_username, smtp_password} = this.decryptedCredentials();
|
const {smtp_password} = connectionCredentials
|
||||||
config.auth = { user: smtp_username, pass: smtp_password}
|
config.auth = { user: smtp_username, pass: smtp_password}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`${this.provider} not yet supported`)
|
throw new Error(`${this.provider} not yet supported`)
|
||||||
|
|
Loading…
Reference in a new issue