From f4f8450d166f1a836eea202dd0340d2156d3dfe9 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 19 Jun 2022 16:21:11 +0200 Subject: [PATCH] feat: embed the vikunja logo as inline attachment --- go.mod | 2 +- pkg/mail/send_mail.go | 7 +++++++ pkg/modules/migration/trello/trello.go | 4 ++-- pkg/modules/migration/wunderlist/wunderlist.go | 2 +- pkg/notifications/logo.png | Bin 0 -> 7222 bytes pkg/notifications/mail_render.go | 10 +++++++++- pkg/routes/api/v1/task_attachment.go | 2 +- pkg/swagger/docs.go | 2 +- 8 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 pkg/notifications/logo.png diff --git a/go.mod b/go.mod index 2f90961b..038fde27 100644 --- a/go.mod +++ b/go.mod @@ -87,4 +87,4 @@ replace ( gopkg.in/fsnotify.v1 => github.com/kolaente/fsnotify v1.4.10-0.20200411160148-1bc3c8ff4048 // See https://github.com/fsnotify/fsnotify/issues/328 and https://github.com/golang/go/issues/26904 ) -go 1.15 +go 1.16 diff --git a/pkg/mail/send_mail.go b/pkg/mail/send_mail.go index 7324110a..a693e798 100644 --- a/pkg/mail/send_mail.go +++ b/pkg/mail/send_mail.go @@ -20,6 +20,7 @@ import ( "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/version" + "io" "github.com/wneessen/go-mail" ) @@ -34,6 +35,7 @@ type Opts struct { ContentType ContentType Boundary string Headers []*header + Embeds map[string]io.Reader } // ContentType represents mail content types @@ -78,10 +80,15 @@ func getMessage(opts *Opts) *mail.Msg { _ = m.From(opts.From) _ = m.To(opts.To) m.Subject(opts.Subject) + for _, h := range opts.Headers { m.SetHeader(h.Field, h.Content) } + for name, content := range opts.Embeds { + m.EmbedReader(name, content) + } + switch opts.ContentType { case ContentTypePlain: m.SetBodyString("text/plain", opts.Message) diff --git a/pkg/modules/migration/trello/trello.go b/pkg/modules/migration/trello/trello.go index c443d3c6..81be1758 100644 --- a/pkg/modules/migration/trello/trello.go +++ b/pkg/modules/migration/trello/trello.go @@ -242,12 +242,12 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board, token string) (fullV log.Debugf("[Trello Migration] Converted label %s from card %s", label.ID, card.ID) } - // Attachments + // Embeds if len(card.Attachments) > 0 { log.Debugf("[Trello Migration] Downloading %d card attachments from card %s", len(card.Attachments), card.ID) } for _, attachment := range card.Attachments { - if attachment.MimeType == "" { // Attachments can also be not downloadable - the mime type is empty in that case. + if attachment.MimeType == "" { // Embeds can also be not downloadable - the mime type is empty in that case. log.Debugf("[Trello Migration] Attachment %s does not have a mime type, not downloading", attachment.ID) continue } diff --git a/pkg/modules/migration/wunderlist/wunderlist.go b/pkg/modules/migration/wunderlist/wunderlist.go index fea6722e..7a1a9d16 100644 --- a/pkg/modules/migration/wunderlist/wunderlist.go +++ b/pkg/modules/migration/wunderlist/wunderlist.go @@ -181,7 +181,7 @@ func convertListForFolder(listID int, list *list, content *wunderlistContents) ( } } - // Attachments + // Embeds for _, f := range content.files { if f.TaskID == t.ID { // Download the attachment and put it in the file diff --git a/pkg/notifications/logo.png b/pkg/notifications/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..0b62ea0b439be33d91c455762432a55cd4b3c257 GIT binary patch literal 7222 zcmV-69LeK}P)f9Lil$&z=x$Tk?-gn&s15Vjd$fDj&e5H=ea$iO!b zc+8Ml@)4E^1Z;x|VJ46X69O+l7?zjCGw|>i!tMxL-EAYl$ntJ$v83+4_q;z^YxnKF zTS(6ReIKY*x9U{2+^4JR)H$bwF-K+2at;-nBY?07rotj%8Za5C8~ATG&@=GgR+NYu zL=2nOgz)B_7TZWhrnxFsp2#!utZh$L2S6US5dZFa2f9 zbaB~FshXk(uhqc5BXc&vS;yjI12TwEq36<72FmTA2gE(2}? z=A}Om&xKPD2af^wy$DIW^uCS_!D*j`N7g{w_Eed|d%!&%vv{1_r3~pVF8dD^Q}p1q z8tAdO5x5bUn*MxxJ^bJT_{I^#WvAZ-Z?%=)=i|#@X)|>7!M7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cL%V^lL{SILu^rKP1Mo=7B4MfGQS#xqjpo0erA zQ)s?C%je6m?%1#`Z#&ECB;7i$T2V_;EEZd9c|6Ag?-tRln@rERov9gpwIoET$R&T- z*jAtuq{mlBpkX#OQyQt6(ul8is^jt7AQjK!o-rT_{*YA*+qQ3Egs-!}i@741ilHwM zc#hE@jLq>t;Mcj@7%5BtNLQ%mBaujJt~T@L&AV|RCDI^CD|N|aPTJbq`l8Y3w*1oo9iva18nq?w4} z<#V^C41HB%!pM$In z95EgP%(tQ5NUgr!tEs73``&x+4F!TMYHIqT$F@%f-ibsazZx}F&b?Y+MVvEpmP;iR zU9C8p=)>yUi+A!|#PD*|t+1uAlygNR!sYENWLz7(TqXvUQuI<8m5%m6NnlJU&px zsGWkhVK$!Hsl(4IFgE8-xu@kxnQ&*YF5`~@x8Dq}KD*Eu^9qobVN?{MDj|h4M|ioa zmB5Y{9%~@p07lJZ3}0qmgKAvZAj-x-4;cv{TwIF9G|iI?k7pwy8Sc5FI%W}(8L5QZ zSIGYbD(+S}@~R|F>_d~4u_YCA?Ngyx2G_U!tK-G>E-po(BL9eUzQKg5=5Y?M9F94| zCFRIa(G*kDN4!<>Pr{D(V#ibQ@pfV#rS7&1y~wdpRCspl3dwoAsB4-bGsDc!s+5NAt^|swyuyr z2wW%*iQx;Swn}%RO`A0OjJ_y@_YF90>)le7ODtSm#tQ{co$V{-IT22!#ET5_&gf+j zF72MvKdQkApRAB^noX*+%*V{*lki_3VRXhjFu{E$Q^ zdH4cOm$f?}Qe8!F&d3YuFb3GG%K2MX$qlTQD&6Pe;xaxdNznmf_e=klmGalXIhrR) z{s9fuGsXcdo|n2rE-T7QBw5n2N~)Sg$His5QnI2CvSp<_t#z0J-$QV8XDd#vs%4-Mm^iRPkUe4pesPDmT<

- Vikunja + Vikunja

@@ -84,6 +86,9 @@ const mailTemplateHTML = ` ` +//go:embed logo.png +var logo []byte + // RenderMail takes a precomposed mail message and renders it into a ready to send mail.Opts object func RenderMail(m *Mail) (mailOpts *mail.Opts, err error) { @@ -155,6 +160,9 @@ func RenderMail(m *Mail) (mailOpts *mail.Opts, err error) { Message: plainContent.String(), HTMLMessage: htmlContent.String(), Boundary: boundary, + Embeds: map[string]io.Reader{ + "logo.png": bytes.NewBuffer(logo), + }, } return mailOpts, nil diff --git a/pkg/routes/api/v1/task_attachment.go b/pkg/routes/api/v1/task_attachment.go index d74357b4..982be34c 100644 --- a/pkg/routes/api/v1/task_attachment.go +++ b/pkg/routes/api/v1/task_attachment.go @@ -36,7 +36,7 @@ import ( // @Param id path int true "Task ID" // @Param files formData string true "The file, as multipart form file. You can pass multiple." // @Security JWTKeyAuth -// @Success 200 {object} models.Message "Attachments were uploaded successfully." +// @Success 200 {object} models.Message "Embeds were uploaded successfully." // @Failure 403 {object} models.Message "No access to the task." // @Failure 404 {object} models.Message "The task does not exist." // @Failure 500 {object} models.Message "Internal error" diff --git a/pkg/swagger/docs.go b/pkg/swagger/docs.go index d7a0e6b3..d8237b49 100644 --- a/pkg/swagger/docs.go +++ b/pkg/swagger/docs.go @@ -4791,7 +4791,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "Attachments were uploaded successfully.", + "description": "Embeds were uploaded successfully.", "schema": { "$ref": "#/definitions/models.Message" }