webapi: implement adding "alternative files" to messages sent with the Send method

with new field "AlternativeFiles" in the JSON body, or with "alternativefile" form file uploads.

can be used if there is a (full) alternative representation (alternative to
text and/or html part), like a calendar item, or PDF file.

for issue #188 by morki
This commit is contained in:
Mechiel Lukkien
2024-08-23 12:00:25 +02:00
parent 62bd2f4427
commit 6c488ead0b
4 changed files with 40 additions and 11 deletions

View File

@ -181,6 +181,13 @@ func TestServer(t *testing.T) {
},
Extra: map[string]string{"a": "123"},
Headers: [][2]string{{"x-custom", "header"}},
AlternativeFiles: []webapi.File{
{
Name: "x.ics",
ContentType: "text/calendar",
Data: base64.StdEncoding.EncodeToString([]byte("ics data...")),
},
},
InlineFiles: []webapi.File{
{
Name: "x.png",
@ -228,8 +235,15 @@ func TestServer(t *testing.T) {
sendReqBuf, err := json.Marshal(fdSendReq)
tcheckf(t, err, "send request")
mp.WriteField("request", string(sendReqBuf))
// One alternative file.
pw, err := mp.CreateFormFile("alternativefile", "test.ics")
tcheckf(t, err, "create alternative ics file")
_, err = fmt.Fprint(pw, "ICS...")
tcheckf(t, err, "write ics")
// Two inline PDFs.
pw, err := mp.CreateFormFile("inlinefile", "test.pdf")
pw, err = mp.CreateFormFile("inlinefile", "test.pdf")
tcheckf(t, err, "create inline pdf file")
_, err = fmt.Fprint(pw, "%PDF-")
tcheckf(t, err, "write pdf")