Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Nov 19, 2024
1 parent 664bb07 commit 2ff37d6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ linters:
- mnd
- exportloopref
- err113
- tparallel
- paralleltest

issues:
exclude-rules:
Expand Down
2 changes: 1 addition & 1 deletion internal/email/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (client *Client) SendEmail(ctx context.Context, email *Email) error {

err = json.NewDecoder(resp.Body).Decode(&commError)
if err != nil {
return err
return fmt.Errorf("failed to decode error response: %w", err)
}

return fmt.Errorf("status code: %d, error message: %s", resp.StatusCode, commError.Error.Message)
Expand Down
22 changes: 11 additions & 11 deletions internal/email/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ type Client struct {
}

type Email struct {
Recipients Recipients `json:"recipients"`
SenderAddress string `json:"senderAddress"`
Content Content `json:"content"`
Tracking bool `json:"disableUserEngagementTracking"`
Importance string `json:"importance"`
ReplyTo []EmailAddress `json:"replyTo"`
Recipients Recipients `json:"recipients"`
SenderAddress string `json:"senderAddress"`
Content Content `json:"content"`
Tracking bool `json:"disableUserEngagementTracking"`
Importance string `json:"importance"`
ReplyTo []Address `json:"replyTo"`
}

type Recipients struct {
To []EmailAddress `json:"to"`
CC []EmailAddress `json:"cc"`
BCC []EmailAddress `json:"bcc"`
To []Address `json:"to"`
CC []Address `json:"cc"`
BCC []Address `json:"bcc"`
}

type EmailAddress struct {
type Address struct {
DisplayName string `json:"displayName"`
Address string `json:"address"`
}
Expand All @@ -42,7 +42,7 @@ type ErrorResponse struct {
Error CommunicationError `json:"error"`
}

// CommunicationError contains the error code and message
// CommunicationError contains the error code and message.
type CommunicationError struct {
Code string `json:"code"`
Message string `json:"message"`
Expand Down
10 changes: 6 additions & 4 deletions internal/smtp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ func (s *Server) Shutdown() error {
}

// handleConnection processes an SMTP client connection.
//
//nolint:gocognit
func (s *Server) handleConnection(conn net.Conn) error {

Check failure on line 115 in internal/smtp/server.go

View workflow job for this annotation

GitHub Actions / lint

cyclomatic complexity 39 of func `(*Server).handleConnection` is high (> 30) (gocyclo)
var (
err error
Expand Down Expand Up @@ -316,8 +318,8 @@ func parseMailData(data string) (*MailMessage, error) {
return ""
}

from := getHeader("From")
to := getHeader("To")
mailFrom := getHeader("From")
mailTo := getHeader("To")
subject := getHeader("Subject")

contentType := getHeader("Content-Type")
Expand All @@ -328,8 +330,8 @@ func parseMailData(data string) (*MailMessage, error) {
}

mailMessage := &MailMessage{
From: from,
To: to,
From: mailFrom,
To: mailTo,
Subject: subject,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/smtp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Your Name`,

msg := []byte(fmt.Sprintf("From: %s\r\nTo: %s\r\n"+
"Subject: %s\r\n"+
"%s\r\n", test.from, test.to, test.subject, test.body))
"%s\r\n", test.from, test.to, test.subject, body))

err := smtp.SendMail("localhost:1515", nil, test.from, []string{test.to}, msg)
require.NoError(t, err)
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ func run(logger *slog.Logger) error {
return emailClient.SendEmail(context.Background(), &email.Email{
SenderAddress: mail.From,
Recipients: email.Recipients{
To: []email.EmailAddress{
{mail.To, mail.To},
To: []email.Address{
{
Address: mail.To,
DisplayName: mail.To,
},
},
},
Content: email.Content{
Expand Down

0 comments on commit 2ff37d6

Please sign in to comment.