Skip to content

Commit

Permalink
feat(postback): Add attachment, from email to postback body
Browse files Browse the repository at this point in the history
  • Loading branch information
joeirimpan committed Jun 27, 2022
1 parent 0834ab7 commit a1df02b
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 59 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/paulbellamy/ratecounter v0.2.0 // indirect
github.com/paulbellamy/ratecounter v0.2.0
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/rhnvrm/simples3 v0.8.2
github.com/spf13/cast v1.4.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/rhnvrm/simples3 v0.6.1/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA=
github.com/rhnvrm/simples3 v0.8.1 h1:jL2yCi9P0pA8hFYkyVWZ4cs5RX3AMgcVsXTOqnCj0/w=
github.com/rhnvrm/simples3 v0.8.1/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA=
github.com/rhnvrm/simples3 v0.8.2 h1:O9dj0DLaU8clz4ctuI82k9VH/X+TbtdfKLlivMmF6Xw=
github.com/rhnvrm/simples3 v0.8.2/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
Expand Down
58 changes: 40 additions & 18 deletions internal/messenger/postback/postback.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"net/http"
"net/textproto"
"time"

"github.com/knadh/listmonk/internal/messenger"
Expand All @@ -16,26 +17,34 @@ import (
// postback is the payload that's posted as JSON to the HTTP Postback server.
//easyjson:json
type postback struct {
Subject string `json:"subject"`
ContentType string `json:"content_type"`
Body string `json:"body"`
Recipients []recipient `json:"recipients"`
Campaign *campaign `json:"campaign"`
Subject string `json:"subject"`
ContentType string `json:"content_type"`
Body string `json:"body"`
Recipients []recipient `json:"recipients"`
Campaign *campaign `json:"campaign"`
Attachments []attachment `json:"attachments"`
}

type campaign struct {
UUID string `db:"uuid" json:"uuid"`
Name string `db:"name" json:"name"`
Headers models.Headers `db:"headers" json:"headers"`
Tags []string `db:"tags" json:"tags"`
FromEmail string `json:"from_email"`
UUID string `json:"uuid"`
Name string `json:"name"`
Headers models.Headers `json:"headers"`
Tags []string `json:"tags"`
}

type recipient struct {
UUID string `db:"uuid" json:"uuid"`
Email string `db:"email" json:"email"`
Name string `db:"name" json:"name"`
Attribs models.SubscriberAttribs `db:"attribs" json:"attribs"`
Status string `db:"status" json:"status"`
UUID string `json:"uuid"`
Email string `json:"email"`
Name string `json:"name"`
Attribs models.SubscriberAttribs `json:"attribs"`
Status string `json:"status"`
}

type attachment struct {
Name string `json:"name"`
Header textproto.MIMEHeader `json:"header"`
Content []byte `json:"content"`
}

// Options represents HTTP Postback server options.
Expand Down Expand Up @@ -101,10 +110,23 @@ func (p *Postback) Push(m messenger.Message) error {

if m.Campaign != nil {
pb.Campaign = &campaign{
UUID: m.Campaign.UUID,
Name: m.Campaign.Name,
Headers: m.Campaign.Headers,
Tags: m.Campaign.Tags,
FromEmail: m.Campaign.FromEmail,
UUID: m.Campaign.UUID,
Name: m.Campaign.Name,
Headers: m.Campaign.Headers,
Tags: m.Campaign.Tags,
}
}

if len(m.Attachments) > 0 {
a := make([]attachment, 0, len(m.Attachments))
for i := 0; i < len(m.Attachments); i++ {
a[i] = attachment{
Name: m.Attachments[i].Name,
Header: m.Attachments[i].Header,
Content: make([]byte, len(m.Attachments[i].Content)),
}
copy(a[i].Content, m.Attachments[i].Content)
}
}

Expand Down
Loading

0 comments on commit a1df02b

Please sign in to comment.