summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-06-01 01:08:07 +0700
committerShulhan <ms@kilabit.info>2023-06-01 01:08:07 +0700
commita9f6156024d5e7def26640bd6448001d3da19e4e (patch)
tree8002b090b269fe4b9dd634a5d048f3a7f5fb3f0e
parentf9cce15aaf0c9f326b371d53b1b0787c32a7fcaf (diff)
downloadpakakeh.go-a9f6156024d5e7def26640bd6448001d3da19e4e.tar.xz
lib/email: unexport the field ContentType in the field
The field ContentType will be set only when the field Name is "Content-Type" so it's not always exist on each field. To get the field ContentType, use Header.ContentType().
-rw-r--r--lib/email/doc.go12
-rw-r--r--lib/email/field.go7
-rw-r--r--lib/email/field_test.go6
-rw-r--r--lib/email/header.go6
4 files changed, 15 insertions, 16 deletions
diff --git a/lib/email/doc.go b/lib/email/doc.go
index 934ea877..802b58a1 100644
--- a/lib/email/doc.go
+++ b/lib/email/doc.go
@@ -23,13 +23,13 @@
//
// A [Header] contains one or more [Field],
//
-// +-------------+---------------------+
-// | Field |
-// +-------------+------+-------+------+
-// | ContentType | Name | Value | Type |
-// +-------------+------+-------+------+
+// +---------------------+
+// | Field |
+// +------+-------+------+
+// | Name | Value | Type |
+// +------+-------+------+
//
-// [Field] is parsed line that contains key and value separated by ": ".
+// [Field] is parsed line that contains Name and Value separated by ": ".
//
// A [ContentType] is special Field where Name is "Content-Type", and its
// Value is parsed from string "top/sub; <param>; ...".
diff --git a/lib/email/field.go b/lib/email/field.go
index 8d757b52..cbd25530 100644
--- a/lib/email/field.go
+++ b/lib/email/field.go
@@ -17,9 +17,9 @@ import (
// Field represent field name and value in header.
type Field struct {
- // ContentType contains unpacked value of field with Name
+ // contentType contains unpacked value of field with Name
// "Content-Type" or nil if still packed.
- ContentType *ContentType
+ contentType *ContentType
date *time.Time
mboxes []*Mailbox
@@ -508,12 +508,11 @@ func (field *Field) unpackContentType() (err error) {
return nil
}
- ContentType, err := ParseContentType(field.Value)
+ field.contentType, err = ParseContentType(field.Value)
if err != nil {
return err
}
- field.ContentType = ContentType
field.unpacked = true
return nil
diff --git a/lib/email/field_test.go b/lib/email/field_test.go
index ca0a898c..672cf181 100644
--- a/lib/email/field_test.go
+++ b/lib/email/field_test.go
@@ -333,7 +333,7 @@ func TestUnpackMailboxList(t *testing.T) {
}
}
-func TestUnpackContentType(t *testing.T) {
+func TestField_unpackContentType(t *testing.T) {
cases := []struct {
expErr string
exp string
@@ -361,7 +361,7 @@ func TestUnpackContentType(t *testing.T) {
continue
}
- test.Assert(t, "Content-Type", c.exp, field.ContentType.String())
+ test.Assert(t, "Content-Type", c.exp, field.contentType.String())
test.Assert(t, "field.unpacked", true, field.unpacked)
err = field.unpack()
@@ -370,7 +370,7 @@ func TestUnpackContentType(t *testing.T) {
continue
}
- test.Assert(t, "Content-Type", c.exp, field.ContentType.String())
+ test.Assert(t, "Content-Type", c.exp, field.contentType.String())
test.Assert(t, "field.unpacked", true, field.unpacked)
}
}
diff --git a/lib/email/header.go b/lib/email/header.go
index 492ecebd..a8d6565a 100644
--- a/lib/email/header.go
+++ b/lib/email/header.go
@@ -108,14 +108,14 @@ func (hdr *Header) ContentType() *ContentType {
if f.Type != FieldTypeContentType {
continue
}
- if f.ContentType == nil {
+ if f.contentType == nil {
err := f.unpack()
if err != nil {
log.Println("ContentType: ", err)
return nil
}
}
- return f.ContentType
+ return f.contentType
}
return nil
}
@@ -265,7 +265,7 @@ func (hdr *Header) WriteTo(w io.Writer) (n int, err error) {
)
for _, f = range hdr.fields {
if f.Type == FieldTypeContentType {
- m, err = fmt.Fprintf(w, "%s: %s\r\n", f.Name, f.ContentType.String())
+ m, err = fmt.Fprintf(w, "%s: %s\r\n", f.Name, f.contentType.String())
} else if f.Type == FieldTypeMessageID {
m, err = fmt.Fprintf(w, "%s: <%s>\r\n", f.Name, f.oriValue)
} else {