diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-16 00:16:35 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-16 00:16:35 +0100 |
commit | c2b6e7ff346e3373a4e33c946594bb6f08393ad3 (patch) | |
tree | 584016f7eda2672f8c25645d05cc3be9d9e9b999 | |
parent | 9d927b399e409990003b25efa8ca7395e9cad021 (diff) | |
download | feed2imap-go-c2b6e7ff346e3373a4e33c946594bb6f08393ad3.tar.gz feed2imap-go-c2b6e7ff346e3373a4e33c946594bb6f08393ad3.tar.bz2 feed2imap-go-c2b6e7ff346e3373a4e33c946594bb6f08393ad3.zip |
Issue #46: Move and rename writer; add comments
-rw-r--r-- | internal/feed/mail.go | 4 | ||||
-rw-r--r-- | pkg/rfc822/writer.go (renamed from pkg/util/fixWriter.go) | 23 | ||||
-rw-r--r-- | pkg/rfc822/writer_test.go (renamed from pkg/util/fixWriter_test.go) | 6 |
3 files changed, 21 insertions, 12 deletions
diff --git a/internal/feed/mail.go b/internal/feed/mail.go index 0bc7d37..3010bfb 100644 --- a/internal/feed/mail.go +++ b/internal/feed/mail.go @@ -23,7 +23,7 @@ import ( "github.com/Necoro/feed2imap-go/internal/msg" "github.com/Necoro/feed2imap-go/pkg/config" "github.com/Necoro/feed2imap-go/pkg/log" - "github.com/Necoro/feed2imap-go/pkg/util" + "github.com/Necoro/feed2imap-go/pkg/rfc822" "github.com/Necoro/feed2imap-go/pkg/version" ) @@ -98,7 +98,7 @@ func (item *item) writeContentPart(w *message.Writer, typ string, tpl template.T } defer partW.Close() - if err = tpl.Execute(util.FixWriter(w), item); err != nil { + if err = tpl.Execute(rfc822.Writer(w), item); err != nil { return fmt.Errorf("writing %s part: %w", typ, err) } diff --git a/pkg/util/fixWriter.go b/pkg/rfc822/writer.go index d78b618..07751ea 100644 --- a/pkg/util/fixWriter.go +++ b/pkg/rfc822/writer.go @@ -1,15 +1,25 @@ -package util +// Package rfc822 provides a writer that ensures the intrinsics of RFC 822. +// +// Rationale +// +// Cyrus IMAP really cares about the hard specifics of RFC 822, namely not allowing single \r and \n. +// +// See also: https://www.cyrusimap.org/imap/reference/faqs/interop-barenewlines.html +// and: https://github.com/Necoro/feed2imap-go/issues/46 +// +// NB: This package currently only cares about the newlines. +package rfc822 import "io" -type fixWriter struct { +type rfc822Writer struct { w io.Writer } var lf = []byte{'\n'} var cr = []byte{'\r'} -func (f fixWriter) Write(p []byte) (n int, err error) { +func (f rfc822Writer) Write(p []byte) (n int, err error) { crFound := false start := 0 @@ -56,8 +66,7 @@ func (f fixWriter) Write(p []byte) (n int, err error) { return } -// Cyrus IMAP really cares about single \r and \n. -// Implement this fixer to change them into \r\n. -func FixWriter(w io.Writer) io.Writer { - return fixWriter{w} +// Writer creates a new RFC 822 conform writer. +func Writer(w io.Writer) io.Writer { + return rfc822Writer{w} } diff --git a/pkg/util/fixWriter_test.go b/pkg/rfc822/writer_test.go index 91961be..7beae8d 100644 --- a/pkg/util/fixWriter_test.go +++ b/pkg/rfc822/writer_test.go @@ -1,4 +1,4 @@ -package util +package rfc822 import ( "bytes" @@ -6,7 +6,7 @@ import ( "testing" ) -func TestFixWriter_Write(t *testing.T) { +func TestRfc822Writer_Write(t *testing.T) { tests := []struct { before string after string @@ -33,7 +33,7 @@ func TestFixWriter_Write(t *testing.T) { for _, tt := range tests { t.Run(tt.before, func(t *testing.T) { b := bytes.Buffer{} - w := FixWriter(&b) + w := Writer(&b) if _, err := io.WriteString(w, tt.before); err != nil { t.Errorf("Error: %v", err) return |