From 06aff07a03af621064168f31796bb45cc54ddf59 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 13 Mar 2022 19:24:46 +0100 Subject: [PATCH] Added Importance header functions --- header.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ msg.go | 11 +++++++++++ 2 files changed, 67 insertions(+) diff --git a/header.go b/header.go index 548e121..42ec928 100644 --- a/header.go +++ b/header.go @@ -6,6 +6,9 @@ type Header string // AddrHeader represents a address related mail Header field name type AddrHeader string +// Importance represents a Importance/Priority value string +type Importance int + // List of common generic header field names const ( // HeaderContentDisposition is the "Content-Disposition" header @@ -24,6 +27,9 @@ const ( // See: https://www.rfc-editor.org/rfc/rfc822#section-5.1 HeaderDate Header = "Date" + // HeaderImportance represents the "Importance" field + HeaderImportance Header = "Importance" + // HeaderInReplyTo represents the "In-Reply-To" field HeaderInReplyTo Header = "In-Reply-To" @@ -44,11 +50,20 @@ const ( // HeaderPrecedence is the "Precedence" header field HeaderPrecedence Header = "Precedence" + // HeaderPriority represents the "Priority" field + HeaderPriority Header = "Priority" + // HeaderReplyTo is the "Reply-To" header field HeaderReplyTo Header = "Reply-To" // HeaderSubject is the "Subject" header field HeaderSubject Header = "Subject" + + // HeaderXMSMailPriority is the "X-MSMail-Priority" header field + HeaderXMSMailPriority Header = "X-MSMail-Priority" + + // HeaderXPriority is the "X-Priority" header field + HeaderXPriority Header = "X-Priority" ) // List of common generic header field names @@ -65,3 +80,44 @@ const ( // HeaderTo is the "Receipient" header field HeaderTo AddrHeader = "To" ) + +// List of Importance values +const ( + ImportanceLow Importance = iota + ImportanceNormal + ImportanceHigh + ImportanceNonUrgent + ImportanceUrgent +) + +// NumString returns the importance number string based on the Importance +func (i Importance) NumString() string { + switch i { + case ImportanceNonUrgent: + return "0" + case ImportanceLow: + return "0" + case ImportanceHigh: + return "1" + case ImportanceUrgent: + return "1" + default: + return "" + } +} + +// String returns the importance string based on the Importance +func (i Importance) String() string { + switch i { + case ImportanceNonUrgent: + return "non-urgent" + case ImportanceLow: + return "low" + case ImportanceHigh: + return "high" + case ImportanceUrgent: + return "urgent" + default: + return "" + } +} diff --git a/msg.go b/msg.go index 8788822..e17fc33 100644 --- a/msg.go +++ b/msg.go @@ -301,6 +301,17 @@ func (m *Msg) SetDate() { m.SetHeader(HeaderDate, ts) } +// SetImportance sets the Msg Importance/Priority header to given Importance +func (m *Msg) SetImportance(i Importance) { + if i == ImportanceNormal { + return + } + m.SetHeader(HeaderImportance, i.String()) + m.SetHeader(HeaderPriority, i.NumString()) + m.SetHeader(HeaderXPriority, i.NumString()) + m.SetHeader(HeaderXMSMailPriority, i.NumString()) +} + // GetSender returns the currently set FROM address. If f is true, it will return the full // address string including the address name, if set func (m *Msg) GetSender(ff bool) (string, error) {