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 {
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
}

View File

@ -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) {

View File

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