Skip to content

Commit

Permalink
Merge pull request #45 from fterh/improve-sender-representation
Browse files Browse the repository at this point in the history
Improve how sender's name and email address are represented
  • Loading branch information
fterh authored May 1, 2020
2 parents 1fc014f + 8d91087 commit 1e5fa9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/forwardInbound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import repackageReceivedAttachments from "./repackageReceivedAttachments";
import sendEmail from "./sendEmail";
import senderAddressEncodeDecode from "./senderAddressEncodeDecode";

export const representNameAndEmailAddress = (
name: string,
emailAddress: string
): string => {
if (name === "") {
return emailAddress;
}
return `${name} [${emailAddress}]`;
};

/**
* Generates forwarded email's "from" header information
* that encapsualtes original sender's name and email address.
Expand All @@ -30,7 +40,7 @@ export const generateFromHeader = (
}

return {
name: `${replyToName} [${replyToEmailAddress}]`,
name: representNameAndEmailAddress(replyToName, replyToEmailAddress),
address: senderAddressEncodeDecode.encodeEmailAddress(
aliasValue,
replyToEmailAddress
Expand Down
11 changes: 10 additions & 1 deletion tests/lib/forwardInbound.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { email as myEmail, operationalDomain } from "../../lib/env";
import forwardInbound, { generateFromHeader } from "../../lib/forwardInbound";
import forwardInbound, {
generateFromHeader,
representNameAndEmailAddress
} from "../../lib/forwardInbound";
// @ts-ignore: We're using Jest's ES6 class mocks (https://jestjs.io/docs/en/es6-class-mocks)
import { didReceiveEmailSpy } from "../../lib/models/Alias";
import { INVALID_ALIAS } from "../../lib/models/__mocks__/Alias";
Expand Down Expand Up @@ -162,3 +165,9 @@ it("should not throw if the alias does not exist", async () => {

await expect(res).resolves.toBeUndefined();
});

it("should not bracket the email address if there is no name", () => {
expect(representNameAndEmailAddress("", "[email protected]")).toBe(
"[email protected]"
);
});

0 comments on commit 1e5fa9f

Please sign in to comment.