mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-21 21:30:50 +01:00
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:
parent
f60b689b03
commit
1a9141074a
4 changed files with 46 additions and 5 deletions
15
encoding.go
15
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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"},
|
||||
|
|
Loading…
Reference in a new issue