From 1a9141074a8a057a277469b029e13f0d8d82e311 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 13 Oct 2023 15:06:54 +0200 Subject: [PATCH] Add References header field and improve string methods Added "References" header field to cover more potential use cases and enhance versatility. This field will allow applications to track series of related messages. Test for "References" field has also been added for validation. Also included are string methods for Content-type objects with relevant tests, ensuring accurate string conversion. Unnecessary duplicate method of string conversion for Charset has been removed to streamline the code and improve readability. --- encoding.go | 15 ++++++++++----- encoding_test.go | 32 ++++++++++++++++++++++++++++++++ header.go | 3 +++ header_test.go | 1 + 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/encoding.go b/encoding.go index dff1e6f..0aed3d3 100644 --- a/encoding.go +++ b/encoding.go @@ -152,12 +152,17 @@ const ( MIMERelated MIMEType = "related" ) -// String is a standard method to convert an Encoding into a printable format -func (e Encoding) String() string { - return string(e) -} - // String is a standard method to convert an Charset into a printable format func (c Charset) String() string { return string(c) } + +// String is a standard method to convert an ContentType into a printable format +func (c ContentType) String() string { + return string(c) +} + +// String is a standard method to convert an Encoding into a printable format +func (e Encoding) String() string { + return string(e) +} diff --git a/encoding_test.go b/encoding_test.go index 71624f3..4a3affc 100644 --- a/encoding_test.go +++ b/encoding_test.go @@ -27,6 +27,38 @@ func TestEncoding_String(t *testing.T) { } } +// TestContentType_String tests the string method of the ContentType object +func TestContentType_String(t *testing.T) { + tests := []struct { + name string + ct ContentType + want string + }{ + {"ContentType: text/plain", TypeTextPlain, "text/plain"}, + {"ContentType: text/html", TypeTextHTML, "text/html"}, + { + "ContentType: application/octet-stream", TypeAppOctetStream, + "application/octet-stream", + }, + { + "ContentType: application/pgp-signature", TypePGPSignature, + "application/pgp-signature", + }, + { + "ContentType: application/pgp-encrypted", TypePGPEncrypted, + "application/pgp-encrypted", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.ct.String() != tt.want { + t.Errorf("wrong string for Content-Type returned. Expected: %s, got: %s", + tt.want, tt.ct.String()) + } + }) + } +} + // TestCharset_String tests the string method of the Charset object func TestCharset_String(t *testing.T) { tests := []struct { diff --git a/header.go b/header.go index 4fca337..35c5284 100644 --- a/header.go +++ b/header.go @@ -73,6 +73,9 @@ const ( // HeaderPriority represents the "Priority" field HeaderPriority Header = "Priority" + // HeaderReferences is the "References" header field + HeaderReferences Header = "References" + // HeaderReplyTo is the "Reply-To" header field HeaderReplyTo Header = "Reply-To" diff --git a/header_test.go b/header_test.go index aea2f4c..a060ae6 100644 --- a/header_test.go +++ b/header_test.go @@ -87,6 +87,7 @@ func TestHeader_String(t *testing.T) { {"Header: Organization", HeaderOrganization, "Organization"}, {"Header: Precedence", HeaderPrecedence, "Precedence"}, {"Header: Priority", HeaderPriority, "Priority"}, + {"Header: HeaderReferences", HeaderReferences, "References"}, {"Header: Reply-To", HeaderReplyTo, "Reply-To"}, {"Header: Subject", HeaderSubject, "Subject"}, {"Header: User-Agent", HeaderUserAgent, "User-Agent"},