Skip to content

Commit

Permalink
fix(addrview): ZMS-189 (#39)
Browse files Browse the repository at this point in the history
* fix logical error with tempfail

* fix subject issue when using api. add debugJson to gelf

* safer delete with check

* Add better SMTP error message

* make message shorter

* comment

* check for aliases, fix normalization

* comment refactor

* addrview constists of unameview + @ + domain. Fix bugs
  • Loading branch information
NickOvt authored Nov 15, 2024
1 parent 0c051a7 commit 20c1604
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@ const loggelfForEveryUser = (app, short_message, data) => {
};

const normalizeAddress = (authenticatedUser, returnAsObject) => {
let user = authenticatedUser.substr(0, authenticatedUser.lastIndexOf('@')).normalize('NFC').toLowerCase().trim();
let domain = authenticatedUser.substr(authenticatedUser.lastIndexOf('@') + 1);
let addr = user.trim() + '@' + addressTools.normalizeDomain(domain);
const user = authenticatedUser.substr(0, authenticatedUser.lastIndexOf('@')).normalize('NFC').toLowerCase().trim();
const domain = authenticatedUser.substr(authenticatedUser.lastIndexOf('@') + 1);
const addr = user.trim() + '@' + addressTools.normalizeDomain(domain);
const unameview = user.trim().replace(/\./g, '');
const addrview = unameview + '@' + domain;

if (returnAsObject) {
return {
user,
unameview,
addrview,
domain,
addr
};
Expand Down Expand Up @@ -162,12 +166,12 @@ module.exports.init = async app => {
// check for alias
let aliasData = await app.db.users.collection('domainaliases').findOne({ alias: addrObj.domain });

let addrview = authenticatedUser; // default to addrview query as-is without alias
let addrview = addrObj.addrview; // default to addrview query as-is without alias

if (aliasData) {
// got alias data
const aliasDomain = aliasData.domain;
addrview = addrObj.user + '@' + aliasDomain; // set new query addrview
addrview = addrObj.unameview + '@' + aliasDomain; // set new query addrview
}

const addressData = await app.db.users.collection('addresses').findOne({ addrview });
Expand Down

0 comments on commit 20c1604

Please sign in to comment.