0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Removed from and getDomain methods from prototype

no-issue
This commit is contained in:
Fabien O'Carroll 2019-10-06 18:26:14 +07:00
parent f4dbcb5f35
commit a22d575a9e

View file

@ -17,31 +17,29 @@ function GhostMailer() {
this.transport = nodemailer.createTransport(transport, options);
this.state.usingDirect = transport === 'direct';
}
function getDomain() {
const domain = urlUtils.urlFor('home', true).match(new RegExp('^https?://([^/:?#]+)(?:[/:?#]|$)', 'i'));
return domain && domain[1];
}
GhostMailer.prototype.from = function () {
var from = config.get('mail') && config.get('mail').from,
defaultBlogTitle;
function getFromAddress() {
const configAddress = config.get('mail') && config.get('mail').from;
const address = configAddress;
// If we don't have a from address at all
if (!from) {
if (!address) {
// Default to noreply@[blog.url]
from = 'noreply@' + this.getDomain();
return getFromAddress(`noreply@${getDomain()}`);
}
// If we do have a from address, and it's just an email
if (validator.isEmail(from)) {
defaultBlogTitle = settingsCache.get('title') ? settingsCache.get('title').replace(/"/g, '\\"') : common.i18n.t('common.mail.title', {domain: this.getDomain()});
from = '"' + defaultBlogTitle + '" <' + from + '>';
if (validator.isEmail(address)) {
const defaultBlogTitle = settingsCache.get('title') ? settingsCache.get('title').replace(/"/g, '\\"') : common.i18n.t('common.mail.title', {domain: getDomain()});
return `"${defaultBlogTitle}" <${address}>`;
}
return from;
};
// Moved it to its own module
GhostMailer.prototype.getDomain = function () {
var domain = urlUtils.urlFor('home', true).match(new RegExp('^https?://([^/:?#]+)(?:[/:?#]|$)', 'i'));
return domain && domain[1];
};
return address;
}
// Sends an email message enforcing `to` (blog owner) and `from` fields
// This assumes that api.settings.read('email') was already done on the API level