Skip to content

Commit

Permalink
fix(email-parse): Fixes. Allow for `username[email] login to be parse…
Browse files Browse the repository at this point in the history
…d correctly` (#10)

* fix provenance

* fix urls

* remove randexp

* refactor originhost and transhost, reuse more code. Add incoming data logging config option

* fix example config. Refactor index.js logging

* update README, fix README

* fix typo readme

* allow authenticatedUser in form of username[email] to be parsed correctly

* regex changes

* regex fixes

* remove regex case insensitive
  • Loading branch information
NickOvt authored Aug 15, 2024
1 parent 597c7e7 commit 915bcda
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,27 @@ module.exports.init = async app => {

let sender;

const smtpUsernamePatternRegex = /\[([^\]]+)]/;

try {
if (authenticatedUser.includes('@')) {
if (envelope.userId && authenticatedUser) {
// have both userId and user. Probably webmail. Set sender to the userId straight away
// first check though that the userId is a 24 length hex

if (envelope.userId.length === 24) {
sender = envelope.userId.toString();
}
} else if (authenticatedUser.includes('@')) {
if (smtpUsernamePatternRegex.test(authenticatedUser)) {
// SMTP username[email]

let match = authenticatedUser.match(smtpUsernamePatternRegex);
if (match && match[1]) {
authenticatedUser = match[1]; // is email address
}
}

// SMTP email aadress login
// seems to be an email, no need to resolve, straight acquire the user id from addresses
const addressData = await app.db.users.collection('addresses').findOne({ addrview: addressTools.normalizeAddress(authenticatedUser) });
sender = addressData.user.toString();
Expand Down

0 comments on commit 915bcda

Please sign in to comment.