diff options
| author | Shulhan <ms@kilabit.info> | 2022-02-21 01:43:49 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-02-24 00:00:25 +0700 |
| commit | 3008d44e258b26a94247d03fe4ae9eac297f9c6f (patch) | |
| tree | 2f4ca4667a87e237d87902ab11735ddbfaf16e80 | |
| parent | 7ecd6092e1ec52a548c68161dd9f04d0af39e63f (diff) | |
| download | pakakeh.go-3008d44e258b26a94247d03fe4ae9eac297f9c6f.tar.xz | |
lib/email: realign all structs
The only exported type that changes is the type Field, from consuming
128 to 120 bytes (-8 bytes).
Its only -8 bytes but it will used multiple times in the Header.
The rest changes are on the test files.
| -rw-r--r-- | lib/email/contenttype_test.go | 2 | ||||
| -rw-r--r-- | lib/email/field.go | 17 | ||||
| -rw-r--r-- | lib/email/field_test.go | 10 | ||||
| -rw-r--r-- | lib/email/message_test.go | 7 |
4 files changed, 19 insertions, 17 deletions
diff --git a/lib/email/contenttype_test.go b/lib/email/contenttype_test.go index 8ebf7198..2dd36a58 100644 --- a/lib/email/contenttype_test.go +++ b/lib/email/contenttype_test.go @@ -12,9 +12,9 @@ import ( func TestParseContentType(t *testing.T) { cases := []struct { - in []byte expErr string exp string + in []byte }{{ exp: "text/plain; charset=us-ascii", }, { diff --git a/lib/email/field.go b/lib/email/field.go index a57a7ba0..b0a94d47 100644 --- a/lib/email/field.go +++ b/lib/email/field.go @@ -20,8 +20,13 @@ import ( // Field represent field name and value in header. // type Field struct { - // Type of field, the numeric representation of field name. - Type FieldType + // ContentType contains unpacked value of field with Name + // "Content-Type" or nil if still packed. + ContentType *ContentType + + date *time.Time + mboxes []*Mailbox + // Name contains "relaxed" canonicalization of field name. Name []byte // Value contains "relaxed" canonicalization of field value. @@ -32,12 +37,8 @@ type Field struct { // oriValue contains "simple" canonicalization of field value. oriValue []byte - date *time.Time - mboxes []*Mailbox - - // ContentType contains unpacked value of field with Name - // "Content-Type" or nil if still packed. - ContentType *ContentType + // Type of field, the numeric representation of field name. + Type FieldType // true if field.unpack has been called, false when field.setValue is // called again. diff --git a/lib/email/field_test.go b/lib/email/field_test.go index ee08dffc..52fcac6d 100644 --- a/lib/email/field_test.go +++ b/lib/email/field_test.go @@ -142,10 +142,10 @@ func TestParseField(t *testing.T) { func TestUnpackDate(t *testing.T) { cases := []struct { - desc string - value []byte exp time.Time expErr string + desc string + value []byte }{{ desc: "With empty value", expErr: "unpackDate: empty date", @@ -256,9 +256,9 @@ func TestUnpackDate(t *testing.T) { func TestUnpackMailbox(t *testing.T) { cases := []struct { - in []byte expErr string exp string + in []byte }{{ in: []byte("Sender: local\r\n"), expErr: `ParseMailboxes "local": empty or invalid address`, @@ -291,9 +291,9 @@ func TestUnpackMailbox(t *testing.T) { func TestUnpackMailboxList(t *testing.T) { cases := []struct { - in []byte expErr string exp string + in []byte }{{ in: []byte("From: \r\n"), expErr: "email: empty field value at 'From: \r\n'", @@ -323,9 +323,9 @@ func TestUnpackMailboxList(t *testing.T) { func TestUnpackContentType(t *testing.T) { cases := []struct { - in []byte expErr string exp string + in []byte }{{ in: []byte("Content-Type: text;\r\n"), expErr: "ParseContentType: missing subtype", diff --git a/lib/email/message_test.go b/lib/email/message_test.go index 5822d5b1..26ad9f81 100644 --- a/lib/email/message_test.go +++ b/lib/email/message_test.go @@ -114,9 +114,9 @@ func TestMessageDKIMVerify(t *testing.T) { t.Skip() cases := []struct { + expStatus *dkim.Status inFile string expErr string - expStatus *dkim.Status }{{ inFile: "testdata/message-dkimverify-00.txt", expStatus: &dkim.Status{ @@ -157,11 +157,12 @@ func TestMessageDKIMSign(t *testing.T) { canonSimple := dkim.CanonSimple cases := []struct { + sig *dkim.Signature + expStatus *dkim.Status + inFile string - sig *dkim.Signature expBodyHash string expSignature string - expStatus *dkim.Status }{{ inFile: "testdata/message-dkimsign-00.txt", sig: &dkim.Signature{ |
