Skip to content

Commit

Permalink
Fixes xhit#70 and allows usage of duplicate recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
mukul-brevo committed Nov 9, 2022
1 parent 93b483a commit d63c47b
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ import (

// Email represents an email message.
type Email struct {
from string
sender string
replyTo string
returnPath string
recipients []string
headers textproto.MIMEHeader
parts []part
attachments []*File
inlines []*File
Charset string
Encoding encoding
Error error
SMTPServer *smtpClient
DkimMsg string
from string
sender string
replyTo string
returnPath string
recipients []string
headers textproto.MIMEHeader
parts []part
attachments []*File
inlines []*File
Charset string
Encoding encoding
Error error
SMTPServer *smtpClient
DkimMsg string
DuplicateRecipientAllowed bool
}

/*
Expand Down Expand Up @@ -138,9 +139,10 @@ const (
// NewMSG creates a new email. It uses UTF-8 by default. All charsets: http://webcheatsheet.com/HTML/character_sets_list.php
func NewMSG() *Email {
email := &Email{
headers: make(textproto.MIMEHeader),
Charset: "UTF-8",
Encoding: EncodingQuotedPrintable,
headers: make(textproto.MIMEHeader),
Charset: "UTF-8",
Encoding: EncodingQuotedPrintable,
DuplicateRecipientAllowed: false,
}

email.AddHeader("MIME-Version", "1.0")
Expand Down Expand Up @@ -317,7 +319,7 @@ func (email *Email) AddAddresses(header string, addresses ...string) *Email {
email.returnPath = address.Address
default:
// check that the address was added to the recipients list
email.recipients, err = addAddress(email.recipients, address.Address)
email.recipients, err = addAddress(email.recipients, address.Address, email.DuplicateRecipientAllowed)
if err != nil {
email.Error = errors.New("Mail Error: " + err.Error() + "; Header: [" + header + "] Address: [" + addresses[i] + "]")
return email
Expand All @@ -343,11 +345,13 @@ func (email *Email) AddAddresses(header string, addresses ...string) *Email {
}

// addAddress adds an address to the address list if it hasn't already been added
func addAddress(addressList []string, address string) ([]string, error) {
// loop through the address list to check for dups
for _, a := range addressList {
if address == a {
return addressList, errors.New("Mail Error: Address: [" + address + "] has already been added")
func addAddress(addressList []string, address string, duplicateRecipientAllowed bool) ([]string, error) {
if !duplicateRecipientAllowed {
// loop through the address list to check for dups
for _, a := range addressList {
if address == a {
return addressList, errors.New("Mail Error: Address: [" + address + "] has already been added")
}
}
}

Expand Down

0 comments on commit d63c47b

Please sign in to comment.