Skip to content

Commit

Permalink
Merge pull request #2 from joeirimpan/aws-ses
Browse files Browse the repository at this point in the history
fix: Use list append instead of indexing
  • Loading branch information
joeirimpan authored Jun 27, 2022
2 parents 4d865a1 + c033af7 commit 53ac1f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Lightweight HTTP server to handle webhooks from [listmonk](https://listmonk.app)
### Supported messengers

* Pinpoint
* AWS SES

### Development

Expand All @@ -18,7 +19,7 @@ make build

Run the binary which starts a server on :8082
```
./listmonk-messenger.bin --config config.toml --msgr pinpoint
./listmonk-messenger.bin --config config.toml --msgr pinpoint --msgr ses
```

* Setting up webhooks
Expand Down
17 changes: 9 additions & 8 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ func handlePostback(w http.ResponseWriter, r *http.Request) {
}

if len(data.Attachments) > 0 {
a := make([]messenger.Attachment, 0, len(data.Attachments))
for i := 0; i < len(data.Attachments); i++ {
a[i] = messenger.Attachment{
Name: data.Attachments[i].Name,
Header: data.Attachments[i].Header,
Content: make([]byte, len(data.Attachments[i].Content)),
files := make([]messenger.Attachment, 0, len(data.Attachments))
for _, f := range data.Attachments {
a := messenger.Attachment{
Name: f.Name,
Header: f.Header,
Content: make([]byte, len(f.Content)),
}
copy(a[i].Content, data.Attachments[i].Content)
copy(a.Content, f.Content)
files = append(files, a)
}

message.Attachments = a
message.Attachments = files
}

app.logger.DebugWith("sending message").String("provider", provider).String("message", fmt.Sprintf("%#+v", message)).Write()
Expand Down
13 changes: 7 additions & 6 deletions messenger/ses.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ func (s sesMessenger) Push(msg Message) error {
var files []smtppool.Attachment
if msg.Attachments != nil {
files = make([]smtppool.Attachment, 0, len(msg.Attachments))
for i := 0; i < len(msg.Attachments); i++ {
files[i] = smtppool.Attachment{
Filename: msg.Attachments[i].Name,
Header: msg.Attachments[i].Header,
Content: make([]byte, len(msg.Attachments[i].Content)),
for _, f := range msg.Attachments {
a := smtppool.Attachment{
Filename: f.Name,
Header: f.Header,
Content: make([]byte, len(f.Content)),
}
copy(files[i].Content, msg.Attachments[i].Content)
copy(a.Content, f.Content)
files = append(files, a)
}
}

Expand Down

0 comments on commit 53ac1f4

Please sign in to comment.