Skip to content

Commit

Permalink
Merge pull request #3 from voedoo/master
Browse files Browse the repository at this point in the history
Added bcc and reply-to.
  • Loading branch information
dev-nodasoft authored Jul 23, 2019
2 parents e15de2b + d727d2f commit 143289a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions eazye.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type Email struct {
From *mail.Address `json:"from"`
To []*mail.Address `json:"to"`
Cc []*mail.Address `json:"cc"`
Bcc []*mail.Address `json:"bcc"`
ReplyTo *mail.Address `json:"reply_to"`
InternalDate time.Time `json:"internal_date"`
Precedence string `json:"precedence"`
Subject string `json:"subject"`
Expand Down Expand Up @@ -427,9 +429,18 @@ func NewEmail(msgFields imap.FieldMap) (Email, error) {
return email, fmt.Errorf("unable to parse from address: %s", err)
}

var replyTo *mail.Address
if replyToHeader := msg.Header.Get("Reply-To"); replyToHeader != "" {
replyTo, err = mail.ParseAddress(replyToHeader)
if err != nil {
return email, fmt.Errorf("unable to parse reply-to address: %s", err)
}
}

var (
to []*mail.Address
cc []*mail.Address
to []*mail.Address
cc []*mail.Address
bcc []*mail.Address
)
if toHeader := msg.Header.Get("To"); toHeader != "" {
to, err = mail.ParseAddressList(toHeader)
Expand All @@ -445,13 +456,22 @@ func NewEmail(msgFields imap.FieldMap) (Email, error) {
}
}

if bccHeader := msg.Header.Get("Bcc"); bccHeader != "" {
cc, err = mail.ParseAddressList(bccHeader)
if err != nil {
return email, fmt.Errorf("unable to parse bcc address: %s", err)
}
}

email = Email{
Message: msg,
InternalDate: imap.AsDateTime(msgFields["INTERNALDATE"]),
Precedence: msg.Header.Get("Precedence"),
From: from,
To: to,
Cc: cc,
Bcc: bcc,
ReplyTo: replyTo,
Subject: parseSubject(msg.Header.Get("Subject")),
}

Expand Down

0 comments on commit 143289a

Please sign in to comment.