Skip to content

Commit 4369581

Browse files
committed
stripAngleBrackets
1 parent db320a3 commit 4369581

File tree

4 files changed

+91
-2
lines changed

4 files changed

+91
-2
lines changed

apps/backend/src/lib/Mailer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import SMTPTransport from "nodemailer/lib/smtp-transport"
22
import { SmtpSettings } from "../../prisma/client"
33
import nodemailer from "nodemailer"
4+
import { stripAngleBrackets } from "../utils/message-id"
45

56
type SendMailOptions = {
67
from: string
@@ -88,7 +89,9 @@ export class Mailer {
8889

8990
let response: SendEmailResponse = {
9091
success: false,
91-
messageId: result.messageId,
92+
messageId: result.messageId
93+
? stripAngleBrackets(result.messageId)
94+
: undefined,
9295
from: options.from,
9396
}
9497

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { describe, it, expect } from "vitest"
2+
import { stripAngleBrackets } from "./message-id"
3+
4+
describe("stripAngleBrackets", () => {
5+
it("should remove angle brackets from both ends", () => {
6+
const messageId = "<abc123@smtp.server.com>"
7+
const result = stripAngleBrackets(messageId)
8+
expect(result).toBe("abc123@smtp.server.com")
9+
})
10+
11+
it("should remove only opening angle bracket", () => {
12+
const messageId = "<abc123@smtp.server.com"
13+
const result = stripAngleBrackets(messageId)
14+
expect(result).toBe("abc123@smtp.server.com")
15+
})
16+
17+
it("should remove only closing angle bracket", () => {
18+
const messageId = "abc123@smtp.server.com>"
19+
const result = stripAngleBrackets(messageId)
20+
expect(result).toBe("abc123@smtp.server.com")
21+
})
22+
23+
it("should handle message ID without angle brackets", () => {
24+
const messageId = "abc123@smtp.server.com"
25+
const result = stripAngleBrackets(messageId)
26+
expect(result).toBe("abc123@smtp.server.com")
27+
})
28+
29+
it("should handle empty string", () => {
30+
const messageId = ""
31+
const result = stripAngleBrackets(messageId)
32+
expect(result).toBe("")
33+
})
34+
35+
it("should handle string with only angle brackets", () => {
36+
const messageId = "<>"
37+
const result = stripAngleBrackets(messageId)
38+
expect(result).toBe("")
39+
})
40+
41+
it("should handle string with only opening bracket", () => {
42+
const messageId = "<"
43+
const result = stripAngleBrackets(messageId)
44+
expect(result).toBe("")
45+
})
46+
47+
it("should handle string with only closing bracket", () => {
48+
const messageId = ">"
49+
const result = stripAngleBrackets(messageId)
50+
expect(result).toBe("")
51+
})
52+
53+
it("should not remove angle brackets from middle of string", () => {
54+
const messageId = "<abc<def>ghi@smtp.server.com>"
55+
const result = stripAngleBrackets(messageId)
56+
expect(result).toBe("abc<def>ghi@smtp.server.com")
57+
})
58+
59+
it("should handle complex message ID formats", () => {
60+
const messageId = "<20240101120000.ABC123@mail.example.com>"
61+
const result = stripAngleBrackets(messageId)
62+
expect(result).toBe("20240101120000.ABC123@mail.example.com")
63+
})
64+
65+
it("should handle message ID with UUID format", () => {
66+
const messageId = "<550e8400-e29b-41d4-a716-446655440000@smtp.provider.com>"
67+
const result = stripAngleBrackets(messageId)
68+
expect(result).toBe(
69+
"550e8400-e29b-41d4-a716-446655440000@smtp.provider.com"
70+
)
71+
})
72+
73+
it("should handle multiple consecutive angle brackets", () => {
74+
const messageId = "<<abc123@smtp.server.com>>"
75+
const result = stripAngleBrackets(messageId)
76+
expect(result).toBe("<abc123@smtp.server.com>")
77+
})
78+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Strips angle brackets from message IDs
3+
* Email message IDs are often wrapped in angle brackets like <abc123@smtp.server.com>
4+
* This function removes those brackets to get the clean message ID
5+
*/
6+
export function stripAngleBrackets(messageId: string): string {
7+
return messageId.replace(/^<|>$/g, "")
8+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.9.20-beta.7",
2+
"version": "0.9.20-beta.8",
33
"name": "letterspace",
44
"private": true,
55
"scripts": {

0 commit comments

Comments
 (0)