aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/util/fixWriter.go2
-rw-r--r--pkg/util/fixWriter_test.go47
2 files changed, 48 insertions, 1 deletions
diff --git a/pkg/util/fixWriter.go b/pkg/util/fixWriter.go
index 51637eb..d78b618 100644
--- a/pkg/util/fixWriter.go
+++ b/pkg/util/fixWriter.go
@@ -59,5 +59,5 @@ func (f fixWriter) Write(p []byte) (n int, err error) {
// 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}
+ return fixWriter{w}
}
diff --git a/pkg/util/fixWriter_test.go b/pkg/util/fixWriter_test.go
new file mode 100644
index 0000000..91961be
--- /dev/null
+++ b/pkg/util/fixWriter_test.go
@@ -0,0 +1,47 @@
+package util
+
+import (
+ "bytes"
+ "io"
+ "testing"
+)
+
+func TestFixWriter_Write(t *testing.T) {
+ tests := []struct {
+ before string
+ after string
+ }{
+ {"", ""},
+ {"foo", "foo"},
+ {"foo\r", "foo\r\n"},
+ {"foo\n", "foo\r\n"},
+ {"foo\r\n", "foo\r\n"},
+ {"\r", "\r\n"},
+ {"\n", "\r\n"},
+ {"\r\n", "\r\n"},
+ {"foo\rbar", "foo\r\nbar"},
+ {"foo\nbar", "foo\r\nbar"},
+ {"foo\r\nbar", "foo\r\nbar"},
+ {"\r\r", "\r\n\r\n"},
+ {"\n\n", "\r\n\r\n"},
+ {"\r\r\n", "\r\n\r\n"},
+ {"\n\r", "\r\n\r\n"},
+ {"\rbar", "\r\nbar"},
+ {"\nbar", "\r\nbar"},
+ {"\r\nbar", "\r\nbar"},
+ }
+ for _, tt := range tests {
+ t.Run(tt.before, func(t *testing.T) {
+ b := bytes.Buffer{}
+ w := FixWriter(&b)
+ if _, err := io.WriteString(w, tt.before); err != nil {
+ t.Errorf("Error: %v", err)
+ return
+ }
+ res := b.String()
+ if tt.after != res {
+ t.Errorf("Expected: %q, got: %q", tt.after, res)
+ }
+ })
+ }
+}
.go?h=v1.5.2&id=95d79341bff3c66c6d32b373994d3a1be26295b9&follow=1'>Issue #46: Make the resulting email body not to include single \r or \n. This...René 'Necoro' Neumann2-2/+66 2021-01-20Bump github.com/PuerkitoBio/goquery from 1.6.0 to 1.6.1dependabot[bot]2-3/+3 2021-01-09Bump github.com/google/uuid from 1.1.2 to 1.1.4dependabot[bot]2-3/+3 2021-01-09Bump github.com/emersion/go-message from 0.14.0 to 0.14.1 (#42)dependabot[bot]2-3/+3 2020-11-28Bump github.com/emersion/go-message from 0.13.0 to 0.14.0 (#38)dependabot[bot]2-3/+9 2020-11-28Bump github.com/google/go-cmp from 0.5.2 to 0.5.4 (#37)dependabot[bot]2-3/+3 2020-11-23Fix release.ymlv0.5.2René 'Necoro' Neumann1-3/+10 2020-11-23Prepare v0.5.2René 'Necoro' Neumann3-3/+8 2020-11-20Bump github.com/gabriel-vasile/mimetype from 1.1.1 to 1.1.2dependabot[bot]2-3/+3 2020-11-04Clean dependabot.ymlRené 'Necoro' Neumann1-4/+0