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.
This commit is contained in:
Winni Neessen 2023-10-13 15:06:54 +02:00
parent f60b689b03
commit 1a9141074a
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D
4 changed files with 46 additions and 5 deletions

View file

@ -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)
}

View file

@ -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 {

View file

@ -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"

View file

@ -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"},