fix bare newline error

This commit is contained in:
Erik Winter 2021-08-13 08:45:12 +02:00
parent db077f9717
commit 053647de76
3 changed files with 13 additions and 42 deletions

View File

@ -192,18 +192,18 @@ func (t *Task) FormatBody() string {
} }
} }
body := fmt.Sprintf("\n") body := fmt.Sprintf("\r\n")
for _, f := range order { for _, f := range order {
key := f + FIELD_SEPARATOR key := f + FIELD_SEPARATOR
for i := len(key); i <= keyLen; i++ { for i := len(key); i <= keyLen; i++ {
key += " " key += " "
} }
line := strings.TrimSpace(fmt.Sprintf("%s %s", key, fields[f])) 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 { 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 return body
} }

View File

@ -238,13 +238,7 @@ func TestTaskNextMessage(t *testing.T) {
expMessage: &mstore.Message{ expMessage: &mstore.Message{
Folder: task.FOLDER_NEW, Folder: task.FOLDER_NEW,
Subject: "", Subject: "",
Body: ` Body: "\r\naction:\r\ndue: no date\r\nproject:\r\nversion: 1\r\nid:\r\n",
action:
due: no date
project:
version: 1
id:
`,
}, },
}, },
{ {
@ -260,13 +254,7 @@ id:
expMessage: &mstore.Message{ expMessage: &mstore.Message{
Folder: task.FOLDER_PLANNED, Folder: task.FOLDER_PLANNED,
Subject: "2021-06-22 (tuesday) - project - action", Subject: "2021-06-22 (tuesday) - project - action",
Body: ` Body: "\r\naction: action\r\ndue: 2021-06-22 (tuesday)\r\nproject: project\r\nversion: 4\r\nid: id\r\n",
action: action
due: 2021-06-22 (tuesday)
project: project
version: 4
id: id
`,
}, },
}, },
} { } {
@ -342,13 +330,7 @@ func TestFormatBody(t *testing.T) {
{ {
name: "empty", name: "empty",
task: &task.Task{}, task: &task.Task{},
exp: ` exp: "\r\naction:\r\ndue: no date\r\nproject:\r\nversion: 0\r\nid:\r\n",
action:
due: no date
project:
version: 0
id:
`,
}, },
{ {
name: "filled", name: "filled",
@ -363,18 +345,7 @@ id:
Body: "previous body", Body: "previous body",
}, },
}, },
exp: ` 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",
action: an action
due: 2021-01-30 (saturday)
project: project
version: 6
id: an id
done: true
Previous version:
previous body
`,
}, },
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {

View File

@ -219,12 +219,12 @@ func (im *IMAP) Add(folder, subject, body string) error {
} }
defer im.Close() defer im.Close()
msgStr := fmt.Sprintf(`From: todo <mstore@erikwinter.nl> msgStr := fmt.Sprintf("From: %s\r\nDate: %s\r\nSubject: %s\r\n\r\n%s\r\n",
Date: %s "gte <gte@gettingthings.email>",
Subject: %s time.Now().Format(time.RFC822Z),
subject,
%s`, time.Now().Format(time.RFC822Z), subject, body) body,
)
msg := NewIMAPBody(msgStr) msg := NewIMAPBody(msgStr)
if err := im.client.Append(folder, nil, time.Time{}, imap.Literal(msg)); err != nil { if err := im.client.Append(folder, nil, time.Time{}, imap.Literal(msg)); err != nil {