From 3d16034c449a96b25a12d9b1dfb2f0a5b1635d00 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 8 Jun 2024 09:38:14 +0200 Subject: [PATCH] Add configurable domain part for message ids Fixes #1 --- config.yaml.example | 1 + internal/notifications/mailnotifier.go | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/config.yaml.example b/config.yaml.example index 4947c72..8887942 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -7,6 +7,7 @@ mail_config: smtp_host: localhost smtp_port: 25 base_url: https://motions.cacert.org + domain: motions.cacert.org notice_mail_address: cacert-board@lists.cacert.org vote_notice_mail_address: cacert-board-votes@lists.cacert.org notification_sender_address: returns@cacert.org diff --git a/internal/notifications/mailnotifier.go b/internal/notifications/mailnotifier.go index 082b578..6ac3b79 100644 --- a/internal/notifications/mailnotifier.go +++ b/internal/notifications/mailnotifier.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright 2017-2024 CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,6 +38,7 @@ type MailConfig struct { SMTPHost string `yaml:"smtp_host"` SMTPPort int `yaml:"smtp_port"` SMTPTimeOut time.Duration `yaml:"smtp_timeout,omitempty"` + Domain string `yaml:"message_id_domain"` NotificationSenderAddress string `yaml:"notification_sender_address"` NoticeMailAddress string `yaml:"notice_mail_address"` VoteNoticeMailAddress string `yaml:"vote_notice_mail_address"` @@ -202,10 +203,10 @@ func voteNoticeRecipient(mc *MailConfig) recipientData { } } -func motionReplyHeaders(m *models.Motion) map[string][]string { +func motionReplyHeaders(m *models.Motion, mc *MailConfig) map[string][]string { return map[string][]string{ - "References": {fmt.Sprintf("<%s>", m.Tag)}, - "In-Reply-To": {fmt.Sprintf("<%s>", m.Tag)}, + "References": {fmt.Sprintf("<%s@%s>", m.Tag, mc.Domain)}, + "In-Reply-To": {fmt.Sprintf("<%s@%s>", m.Tag, mc.Domain)}, } } @@ -247,7 +248,7 @@ func (c *ClosedDecisionNotification) GetNotificationContent(mc *MailConfig) *Not *models.Motion }{Motion: c.Decision}, subject: fmt.Sprintf("Re: %s - %s - finalized", c.Decision.Tag, c.Decision.Title), - headers: motionReplyHeaders(c.Decision), + headers: motionReplyHeaders(c.Decision, mc), recipients: []recipientData{defaultRecipient(mc)}, } } @@ -275,14 +276,14 @@ func (n NewDecisionNotification) GetNotificationContent(mc *MailConfig) *Notific UnvotedURL: unvotedURL, }, subject: fmt.Sprintf("%s - %s", n.Decision.Tag, n.Decision.Title), - headers: n.getHeaders(), + headers: n.getHeaders(mc), recipients: []recipientData{defaultRecipient(mc)}, } } -func (n NewDecisionNotification) getHeaders() map[string][]string { +func (n NewDecisionNotification) getHeaders(mc *MailConfig) map[string][]string { return map[string][]string{ - "Message-ID": {fmt.Sprintf("<%s>", n.Decision.Tag)}, + "Message-ID": {fmt.Sprintf("<%s@%s>", n.Decision.Tag, mc.Domain)}, } } @@ -309,7 +310,7 @@ func (u UpdateDecisionNotification) GetNotificationContent(mc *MailConfig) *Noti UnvotedURL: unvotedURL, }, subject: fmt.Sprintf("%s - %s", u.Decision.Tag, u.Decision.Title), - headers: motionReplyHeaders(u.Decision), + headers: motionReplyHeaders(u.Decision, mc), recipients: []recipientData{defaultRecipient(mc)}, } } @@ -333,7 +334,7 @@ func (d DirectVoteNotification) GetNotificationContent(mc *MailConfig) *Notifica Choice: d.Choice, }, subject: fmt.Sprintf("Re: %s - %s", d.Decision.Tag, d.Decision.Title), - headers: motionReplyHeaders(d.Decision), + headers: motionReplyHeaders(d.Decision, mc), recipients: []recipientData{voteNoticeRecipient(mc)}, } } @@ -363,7 +364,7 @@ func (p ProxyVoteNotification) GetNotificationContent(mc *MailConfig) *Notificat Justification: p.Justification, }, subject: fmt.Sprintf("Re: %s - %s", p.Decision.Tag, p.Decision.Title), - headers: motionReplyHeaders(p.Decision), + headers: motionReplyHeaders(p.Decision, mc), recipients: []recipientData{voteNoticeRecipient(mc)}, } } @@ -381,7 +382,7 @@ func (w WithDrawMotionNotification) GetNotificationContent(mc *MailConfig) *Noti Name string }{Motion: w.Motion, Name: w.Voter.Name}, subject: fmt.Sprintf("Re: %s - %s", w.Motion.Tag, w.Motion.Title), - headers: motionReplyHeaders(w.Motion), + headers: motionReplyHeaders(w.Motion, mc), recipients: []recipientData{defaultRecipient(mc)}, } }