Skip to content

Commit

Permalink
Fixing invalid email pathing for inboxkitten
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCreator committed Aug 16, 2022
1 parent 10ceb88 commit 8ee912c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions api/src/mailgunReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ mailgunReader.prototype.getUrlValidation = function getUrlValidation(email) {
return true;
}



/**
* Get the content of URL and return it, using the mailgun key.
* This is useful for stored emails returned by the event stream.
Expand All @@ -124,10 +122,23 @@ mailgunReader.prototype.getUrl = function getUrl(url) {
*
* @param {String} url
*/
mailgunReader.prototype.getKey = function getKey(key) {

[prefix, key, ...rest] = key.split("-")
// slice the mailgunApi to include the region
mailgunReader.prototype.getKey = function getKey(fullKey) {

// Given the key, lets get the ID, and prefix
let prefix, key;

// Lets check for newer key format
if( fullKey.length > 37 ) {
let pt = fullKey.lastIndexOf("-", fullKey.length - 36);
prefix = fullKey.slice(0,pt);
key = fullKey.slice(pt+1);
} else {
let pt = fullKey.lastIndexOf("-");
prefix = fullKey.slice(0,pt);
key = fullKey.slice(pt+1);
}

// Inject the region to the mailgunApi
let apiUrl = this._config.mailgunApi
apiUrl = apiUrl.replace("://", "://"+prefix+".")
let urlWithParams = apiUrl+"/domains/"+this._config.emailDomain+"/messages/"+key;
Expand Down

0 comments on commit 8ee912c

Please sign in to comment.