aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-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
2 files changed, 19 insertions, 10 deletions
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
491ba5330d8c4a63b0c6e443d6e073f2be&follow=1'>Splitted windows.pyRené 'Necoro' Neumann10-424/+549 2008-03-12Moved get_dependencies to top package classRené 'Necoro' Neumann4-50/+85 2008-03-11improved performance by caching the use_expand queriesRené 'Necoro' Neumann1-5/+14 2008-03-11use catapult varsRené 'Necoro' Neumann2-4/+6 2008-03-11Updated catapult stuffRené 'Necoro' Neumann5-56/+108 2008-03-10Generate correct KeyNotFoundExceptionRené 'Necoro' Neumann1-2/+2 2008-03-09Small changesRené 'Necoro' Neumann3-1/+4 2008-03-07Better session handlingRené 'Necoro' Neumann1-5/+54 2008-03-07Small changesRené 'Necoro' Neumann1-1/+4 2008-03-07Updated shm module to 1.2René 'Necoro' Neumann1-8/+21 2008-03-07Update TODORené 'Necoro' Neumann1-3/+1 2008-03-07hmm ... yesRené 'Necoro' Neumann1-1/+1 2008-03-06Used better exceptions for configuration parserRené 'Necoro' Neumann1-26/+114 2008-03-06Update translationRené 'Necoro' Neumann2-349/+393 2008-03-06Update createpot.shRené 'Necoro' Neumann1-3/+2 2008-03-06Use 'nofork' instead of 'nolistener'René 'Necoro' Neumann1-3/+3 2008-03-05Install glade files into template dir and not data dirRené 'Necoro' Neumann2-2/+1 2008-03-05Added dependency listRené 'Necoro' Neumann3-117/+237