diff --git a/email.go b/email.go index a7374ed..ebfcff8 100644 --- a/email.go +++ b/email.go @@ -22,6 +22,7 @@ type Email struct { subject string replyTo Recipient attachments []Attachment + tags []Tag } func (e *Email) Validate() error { @@ -85,11 +86,17 @@ func (e *Email) Validate() error { } } + for _, t := range e.tags { + if t.IsEmpty() { + return ErrEmptyTag + } + } + return nil } func (e Email) copy() *Email { - return &Email{e.from, e.to, e.cc, e.bcc, e.body, e.subject, e.replyTo, e.attachments} + return &Email{e.from, e.to, e.cc, e.bcc, e.body, e.subject, e.replyTo, e.attachments, e.tags} } func (e Email) MarshalJSON() ([]byte, error) { @@ -111,6 +118,7 @@ func (e Email) MarshalJSON() ([]byte, error) { Subject string `json:"subject,omitempty"` ReplyTo Sender `json:"replyTo"` Attachments []Attachment `json:"attachment,omitempty"` + Tags []Tag `json:"tags,omitempty"` }{ Sender: e.from, To: e.to, @@ -119,6 +127,7 @@ func (e Email) MarshalJSON() ([]byte, error) { Subject: e.subject, ReplyTo: e.replyTo, Attachments: e.attachments, + Tags: e.tags, }) if err != nil { return nil, err @@ -190,6 +199,12 @@ func (b *EmailBuilder) AppendAttachment(attachment Attachment) *EmailBuilder { return b } +func (b *EmailBuilder) AppendTag(tag Tag) *EmailBuilder { + b.email.tags = append(b.email.tags, tag) + + return b +} + func (b *EmailBuilder) Build() *Email { return b.email } diff --git a/email_test.go b/email_test.go index 53f1cdc..607d425 100644 --- a/email_test.go +++ b/email_test.go @@ -84,6 +84,18 @@ func TestEmaiValidate(t *testing.T) { return e }, err: ErrSubjectRequired, + }, { + name: "empty tag", + email: func() *Email { + e := email.copy() + + e.tags = []Tag{ + Tag(""), + } + + return e + }, + err: ErrEmptyTag, }} for _, test := range tests { diff --git a/tag.go b/tag.go new file mode 100644 index 0000000..b14cffd --- /dev/null +++ b/tag.go @@ -0,0 +1,17 @@ +package visimail + +import "errors" + +var ( + ErrEmptyTag = errors.New("tag is empty") +) + +type Tag string + +func (t Tag) IsEmpty() bool { + return t == "" +} + +func (t Tag) String() string { + return string(t) +}