diff --git a/core/server/data/migrations/versions/4.0/21-sanitize-email-batches-provider-id.js b/core/server/data/migrations/versions/4.0/21-sanitize-email-batches-provider-id.js new file mode 100644 index 0000000000..660fcdb9e3 --- /dev/null +++ b/core/server/data/migrations/versions/4.0/21-sanitize-email-batches-provider-id.js @@ -0,0 +1,8 @@ +const logging = require('../../../../../shared/logging'); +const {createIrreversibleMigration} = require('../../utils'); + +module.exports = createIrreversibleMigration(async (knex) => { + logging.info('Sanitizing provider_id values in email_batches'); + + await knex.raw('UPDATE email_batches SET provider_id = REPLACE(REPLACE(provider_id, "<", ""), ">", "")'); +}); diff --git a/core/server/services/bulk-email/index.js b/core/server/services/bulk-email/index.js index 466647871f..5b3358c06f 100644 --- a/core/server/services/bulk-email/index.js +++ b/core/server/services/bulk-email/index.js @@ -168,7 +168,7 @@ module.exports = { // update batch success status return await emailBatchModel.save({ status: 'submitted', - provider_id: sendResponse.id + provider_id: sendResponse.id.trim().replace(/^<|>$/g, '') }, Object.assign({}, knexOptions, {patch: true})); } catch (error) { // update batch failed status diff --git a/core/server/services/email-analytics/providers/mailgun.js b/core/server/services/email-analytics/providers/mailgun.js index 23e8fcc186..bbe50f57ba 100644 --- a/core/server/services/email-analytics/providers/mailgun.js +++ b/core/server/services/email-analytics/providers/mailgun.js @@ -114,11 +114,7 @@ class EmailAnalyticsMailgunProvider { } normalizeEvent(event) { - // TODO: clean up the <> surrounding email_batches.provider_id values let providerId = event.message && event.message.headers && event.message.headers['message-id']; - if (providerId) { - providerId = `<${providerId}>`; - } return { type: event.event, diff --git a/test/utils/fixtures/data-generator.js b/test/utils/fixtures/data-generator.js index d43da95400..a02040e821 100644 --- a/test/utils/fixtures/data-generator.js +++ b/test/utils/fixtures/data-generator.js @@ -478,8 +478,7 @@ DataGenerator.Content = { { id: ObjectId.generate(), email_id: null, // emails[0] relation added later - // TODO: cleanup <> in provider_id - provider_id: '', + provider_id: 'email1@testing.mailgun.net', status: 'submitted' } ],