Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add In-reply-to header for message grouping #13

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ To send email user need to create a sender first and then use `Send` method. The
To []string // From email field
Subject string // Email subject
UnsubscribeLink string // POST, https://support.google.com/mail/answer/81126 -> "Use one-click unsubscribe"
InReplyTo string // Identifier for email group (category), used for email grouping
Attachments []string // Attachments path
InlineImages []string // Embedding directly to email body. Autogenerated Content-Id (cid) equals to file name
}
Expand Down
5 changes: 5 additions & 0 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Params struct {
To []string // From email field
Subject string // Email subject
UnsubscribeLink string // POST, https://support.google.com/mail/answer/81126 -> "Use one-click unsubscribe"
InReplyTo string // Identifier for email group (category), used for email grouping
Attachments []string // Attachments path
InlineImages []string // InlineImages images path
}
Expand Down Expand Up @@ -218,6 +219,10 @@ func (em *Sender) buildMessage(text string, params Params) (message string, err
message = addHeader(message, "List-Unsubscribe", "<"+params.UnsubscribeLink+">")
}

if params.InReplyTo != "" {
message = addHeader(message, "In-reply-to", "<"+params.InReplyTo+">")
}

withAttachments := len(params.Attachments) > 0
withInlineImg := len(params.InlineImages) > 0

Expand Down
3 changes: 2 additions & 1 deletion email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,11 @@ func TestEmail_buildMessageWithMIME(t *testing.T) {
To: []string{"[email protected]"},
Subject: "non-ascii symbols: Привет",
UnsubscribeLink: "https://example.com/unsubscribe",
InReplyTo: "[email protected]",
})
require.NoError(t, err)
assert.Contains(t, msg, "Content-Transfer-Encoding: quoted-printable\nContent-Type: text/html; charset=\"UTF-8\"", msg)
assert.Contains(t, msg, "From: [email protected]\nTo: [email protected]\nSubject: =?utf-8?b?bm9uLWFzY2lpIHN5bWJvbHM6INCf0YDQuNCy0LXRgg==?=\nList-Unsubscribe-Post: List-Unsubscribe=One-Click\nList-Unsubscribe: <https://example.com/unsubscribe>\nMIME-version: 1.0", msg)
assert.Contains(t, msg, "From: [email protected]\nTo: [email protected]\nSubject: =?utf-8?b?bm9uLWFzY2lpIHN5bWJvbHM6INCf0YDQuNCy0LXRgg==?=\nList-Unsubscribe-Post: List-Unsubscribe=One-Click\nList-Unsubscribe: <https://example.com/unsubscribe>\nIn-reply-to: <[email protected]>\nMIME-version: 1.0", msg)
assert.Contains(t, msg, "\n\nthis is a test\r\n12345\r\n", msg)
assert.Contains(t, msg, "Date: ", msg)
}
Expand Down