2014-04-10 10:57:33 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
module.exports = function (db, log) {
|
|
|
|
|
|
|
|
function accountDeleted(uid, email) {
|
|
|
|
log.info({ op: 'accountDeleted', uid: uid, email: email })
|
|
|
|
}
|
|
|
|
|
|
|
|
function gotError(email, err) {
|
|
|
|
log.error({ op: 'databaseError', email: email, err: err })
|
|
|
|
}
|
|
|
|
|
2014-04-11 10:54:41 +04:00
|
|
|
function deleteAccountIfUnverified(record) {
|
2014-04-10 10:57:33 +04:00
|
|
|
if (!record.emailVerified) {
|
|
|
|
db.deleteAccount(record)
|
|
|
|
.done(
|
|
|
|
accountDeleted.bind(null, record.uid, record.email),
|
|
|
|
gotError.bind(null, record.email)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleBounce(message) {
|
|
|
|
var recipients = []
|
|
|
|
if (message.bounce && message.bounce.bounceType === 'Permanent') {
|
|
|
|
recipients = message.bounce.bouncedRecipients
|
|
|
|
}
|
|
|
|
else if (message.complaint && message.complaint.complaintFeedbackType === 'abuse') {
|
2014-04-16 06:53:57 +04:00
|
|
|
recipients = message.complaint.complainedRecipients
|
2014-04-10 10:57:33 +04:00
|
|
|
}
|
|
|
|
for (var i = 0; i < recipients.length; i++) {
|
|
|
|
var email = recipients[i].emailAddress
|
|
|
|
log.info({ op: 'handleBounce', email: email, bounce: !!message.bounce })
|
|
|
|
db.emailRecord(email)
|
|
|
|
.done(
|
2014-04-11 10:54:41 +04:00
|
|
|
deleteAccountIfUnverified,
|
2014-04-10 10:57:33 +04:00
|
|
|
gotError.bind(null, email)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handleBounce
|
|
|
|
}
|