Skip to content

Commit

Permalink
Reply-To can have multiple emails (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryzcy authored Jan 11, 2023
1 parent 8a50ec9 commit 1ba0975
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
3 changes: 2 additions & 1 deletion functions/emailReceive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"strings"
"time"

"github.com/aws/aws-lambda-go/events"
Expand Down Expand Up @@ -72,7 +73,7 @@ func receiveEmail(ctx context.Context, ses events.SimpleEmailService) {

for _, header := range ses.Mail.Headers {
if header.Name == "Reply-To" {
item["ReturnPath"] = &types.AttributeValueMemberS{Value: header.Value}
item["ReplyTo"] = &types.AttributeValueMemberSS{Value: strings.Split(header.Value, ",")}
}
}

Expand Down
8 changes: 4 additions & 4 deletions functions/emailRestore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ func restoreEmail(ctx context.Context, cli *client, messageID string) error {
item["To"] = &dynamodbTypes.AttributeValueMemberSS{Value: cleanAddresses(envelope.GetHeaderValues("To"), false)}
item["ReturnPath"] = &dynamodbTypes.AttributeValueMemberS{Value: cleanAddress(envelope.GetHeader("Return-Path"), true)}

replyTo := envelope.GetHeader("Reply-To")
if replyTo != "" {
replyTo = cleanAddress(replyTo, true)
item["ReplyTo"] = &dynamodbTypes.AttributeValueMemberS{Value: replyTo}
replyTo := envelope.GetHeaderValues("Reply-To")
if len(replyTo) > 0 {
replyTo = cleanAddresses(replyTo, true)
item["ReplyTo"] = &dynamodbTypes.AttributeValueMemberSS{Value: replyTo}
}

item["Text"] = &dynamodbTypes.AttributeValueMemberS{Value: envelope.Text}
Expand Down
31 changes: 31 additions & 0 deletions internal/email/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ type GetResult struct {
Inlines *types.Files `json:"inlines,omitempty"`
}

// GetResult represents the result of get method
type GetResult2 struct {
MessageID string `json:"messageID"`
Type string `json:"type"`
Subject string `json:"subject"`
From []string `json:"from"`
To []string `json:"to"`
Text string `json:"text"`
HTML string `json:"html"`

// Inbox email attributes
TimeReceived string `json:"timeReceived,omitempty"`
DateSent string `json:"dateSent,omitempty"`
Source string `json:"source,omitempty"`
Destination []string `json:"destination,omitempty"`
ReturnPath string `json:"returnPath,omitempty"`
Verdict *EmailVerdict `json:"verdict,omitempty"`
Unread *bool `json:"unread,omitempty"`
}

type EmailVerdict struct {
Spam bool `json:"spam"`
DKIM bool `json:"dkim"`
Expand All @@ -67,6 +87,17 @@ func Get(ctx context.Context, api GetItemAPI, messageID string) (*GetResult, err
if len(resp.Item) == 0 {
return nil, ErrNotFound
}

// for backward compatibility, ReplyTo may be in string format,
// then we need to convert it to string set
if replyTo, ok := resp.Item["ReplyTo"]; ok {
if _, ok := replyTo.(*dynamodbTypes.AttributeValueMemberS); ok {
resp.Item["ReplyTo"] = &dynamodbTypes.AttributeValueMemberSS{
Value: []string{replyTo.(*dynamodbTypes.AttributeValueMemberS).Value},
}
}
}

result := new(GetResult)
err = attributevalue.UnmarshalMap(resp.Item, result)
if err != nil {
Expand Down

0 comments on commit 1ba0975

Please sign in to comment.