From 053647de76de3da7d9c6ca3ae4dd2cea57092cf4 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Fri, 13 Aug 2021 08:45:12 +0200 Subject: [PATCH] fix bare newline error --- internal/task/task.go | 6 +++--- internal/task/task_test.go | 37 ++++--------------------------------- pkg/mstore/imap.go | 12 ++++++------ 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/internal/task/task.go b/internal/task/task.go index e7f9f18..3627083 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -192,18 +192,18 @@ func (t *Task) FormatBody() string { } } - body := fmt.Sprintf("\n") + body := fmt.Sprintf("\r\n") for _, f := range order { key := f + FIELD_SEPARATOR for i := len(key); i <= keyLen; i++ { key += " " } line := strings.TrimSpace(fmt.Sprintf("%s %s", key, fields[f])) - body += fmt.Sprintf("%s\n", line) + body += fmt.Sprintf("%s\r\n", line) } if t.Message != nil { - body += fmt.Sprintf("\nPrevious version:\n\n%s\n", t.Message.Body) + body += fmt.Sprintf("\r\nPrevious version:\r\n\r\n%s\r\n", t.Message.Body) } return body } diff --git a/internal/task/task_test.go b/internal/task/task_test.go index 0b00bf6..23a51be 100644 --- a/internal/task/task_test.go +++ b/internal/task/task_test.go @@ -238,13 +238,7 @@ func TestTaskNextMessage(t *testing.T) { expMessage: &mstore.Message{ Folder: task.FOLDER_NEW, Subject: "", - Body: ` -action: -due: no date -project: -version: 1 -id: -`, + Body: "\r\naction:\r\ndue: no date\r\nproject:\r\nversion: 1\r\nid:\r\n", }, }, { @@ -260,13 +254,7 @@ id: expMessage: &mstore.Message{ Folder: task.FOLDER_PLANNED, Subject: "2021-06-22 (tuesday) - project - action", - Body: ` -action: action -due: 2021-06-22 (tuesday) -project: project -version: 4 -id: id -`, + Body: "\r\naction: action\r\ndue: 2021-06-22 (tuesday)\r\nproject: project\r\nversion: 4\r\nid: id\r\n", }, }, } { @@ -342,13 +330,7 @@ func TestFormatBody(t *testing.T) { { name: "empty", task: &task.Task{}, - exp: ` -action: -due: no date -project: -version: 0 -id: -`, + exp: "\r\naction:\r\ndue: no date\r\nproject:\r\nversion: 0\r\nid:\r\n", }, { name: "filled", @@ -363,18 +345,7 @@ id: Body: "previous body", }, }, - exp: ` -action: an action -due: 2021-01-30 (saturday) -project: project -version: 6 -id: an id -done: true - -Previous version: - -previous body -`, + exp: "\r\naction: an action\r\ndue: 2021-01-30 (saturday)\r\nproject: project\r\nversion: 6\r\nid: an id\r\ndone: true\r\n\r\nPrevious version:\r\n\r\nprevious body\r\n", }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/mstore/imap.go b/pkg/mstore/imap.go index a352ebf..4dc4386 100644 --- a/pkg/mstore/imap.go +++ b/pkg/mstore/imap.go @@ -219,12 +219,12 @@ func (im *IMAP) Add(folder, subject, body string) error { } defer im.Close() - msgStr := fmt.Sprintf(`From: todo -Date: %s -Subject: %s - -%s`, time.Now().Format(time.RFC822Z), subject, body) - + msgStr := fmt.Sprintf("From: %s\r\nDate: %s\r\nSubject: %s\r\n\r\n%s\r\n", + "gte ", + time.Now().Format(time.RFC822Z), + subject, + body, + ) msg := NewIMAPBody(msgStr) if err := im.client.Append(folder, nil, time.Time{}, imap.Literal(msg)); err != nil {