Skip to content

Commit

Permalink
[BACK-2760] Punycode email addresses before sending.
Browse files Browse the repository at this point in the history
  • Loading branch information
lostlevels committed Dec 4, 2023
1 parent ccec1a4 commit dc62ca1
Show file tree
Hide file tree
Showing 28 changed files with 36,972 additions and 4 deletions.
14 changes: 11 additions & 3 deletions clients/sesNotifier.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package clients

import (
"fmt"
"log"
"net/http"

"golang.org/x/net/idna"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
Expand Down Expand Up @@ -78,7 +82,11 @@ func NewSesNotifier(cfg *SesNotifierConfig) (*SesNotifier, error) {
func (c *SesNotifier) Send(to []string, subject string, msg string) (int, string) {
var toAwsAddress = make([]*string, len(to))
for i, x := range to {
toAwsAddress[i] = aws.String(x)
encodedAddress, err := idna.ToASCII(x)
if err != nil {
return http.StatusBadRequest, fmt.Sprintf(`unable to Punycode email "%s": %v`, x, err)
}
toAwsAddress[i] = aws.String(encodedAddress)
}

input := &ses.SendEmailInput{
Expand Down Expand Up @@ -127,7 +135,7 @@ func (c *SesNotifier) Send(to []string, subject string, msg string) (int, string
log.Println(err.Error())
}

return 400, result.String()
return http.StatusBadRequest, fmt.Sprintf("%s: %s", result.String(), err.Error())
}
return 200, result.String()
return http.StatusOK, result.String()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
go.mongodb.org/mongo-driver v1.11.1
go.uber.org/fx v1.13.1
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20220513224357-95641704303c
)

require (
Expand Down Expand Up @@ -48,7 +49,6 @@ require (
go.uber.org/dig v1.10.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220513224357-95641704303c // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/jcmturner/aescts.v1 v1.0.1 // indirect
Expand Down
14 changes: 14 additions & 0 deletions vendor/golang.org/x/net/idna/go118.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dc62ca1

Please sign in to comment.