From 6bd7c7ec34fdeb12b2458e446c86c728e42d26c9 Mon Sep 17 00:00:00 2001 From: Maya Sergeeva Date: Thu, 23 Jun 2022 17:37:05 +0300 Subject: [PATCH] Adding `SetMimeType(typ mime.Type)` method to Message interface. Dependencies update. --- contracts/message.go | 4 ++++ contracts/messageInterface.go | 1 + go.mod | 2 +- go.sum | 4 ++-- mailing.go | 7 ++++++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/contracts/message.go b/contracts/message.go index a303937..b6fc65e 100644 --- a/contracts/message.go +++ b/contracts/message.go @@ -101,6 +101,10 @@ func (mm *Message) SetSubject(sbj string) error { return nil } +func (mm *Message) SetMimeType(typ mime.Type) { + mm.MimeType = typ +} + func (mm *Message) SetHTML(msg []byte) error { if msg == nil { mm.emptyContent() diff --git a/contracts/messageInterface.go b/contracts/messageInterface.go index 7ed9099..a69e48f 100644 --- a/contracts/messageInterface.go +++ b/contracts/messageInterface.go @@ -15,6 +15,7 @@ type MessageInterface interface { SetBccs(addrs mailing.MailAddressListInterface) SetReplyTo(addr mailing.MailAddressInterface) error SetSubject(sbj string) error + SetMimeType(typ mime.Type) SetHTML(msg []byte) error SetPlainText(msg []byte) error AddAttachment(file MessageAttachmentInterface) error diff --git a/go.mod b/go.mod index e9cf9d9..3672e8a 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/mailgun/mailgun-go/v4 v4.6.2 github.com/mattbaird/gochimp v0.0.0-20200820164431-f1082bcdf63f github.com/sendgrid/sendgrid-go v3.11.1+incompatible - github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha2 + github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha3 github.com/stretchr/testify v1.7.1 github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208 github.com/xhit/go-simple-mail/v2 v2.11.0 diff --git a/go.sum b/go.sum index 5f15632..4b8fc57 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ github.com/sendgrid/rest v2.6.9+incompatible h1:1EyIcsNdn9KIisLW50MKwmSRSK+ekuei github.com/sendgrid/rest v2.6.9+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE= github.com/sendgrid/sendgrid-go v3.11.1+incompatible h1:ai0+woZ3r/+tKLQExznak5XerOFoD6S7ePO0lMV8WXo= github.com/sendgrid/sendgrid-go v3.11.1+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8= -github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha2 h1:WT5CvXlGEJ69lIPsBm/anuwoCnEajRwL0ha2aoLCaQM= -github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha2/go.mod h1:/qyni0G7nIAu2Hdp7VW3p+RwjhwvIKJtKdbbN2osywE= +github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha3 h1:KS2lDwGko4ATBvRCq0PSnLcxZvbottU3huqg+hRKm7A= +github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha3/go.mod h1:/qyni0G7nIAu2Hdp7VW3p+RwjhwvIKJtKdbbN2osywE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= diff --git a/mailing.go b/mailing.go index 58cdb51..8129f0e 100644 --- a/mailing.go +++ b/mailing.go @@ -7,6 +7,7 @@ import ( "os" "strings" + "github.com/spacetab-io/configuration-structs-go/v2/errors" "github.com/spacetab-io/configuration-structs-go/v2/mailing" "github.com/spacetab-io/mails-go/contracts" "github.com/spacetab-io/mails-go/providers" @@ -49,7 +50,7 @@ func NewMailing(providerCfg mailing.MailProviderConfigInterface, msgCfg mailing. case mailing.MailProviderSMTP: provider, err = providers.NewSMTP(providerCfg) default: - return Mailing{}, mailing.ErrUnknownProvider + return Mailing{}, errors.ErrUnknownProvider } if err != nil { @@ -64,6 +65,10 @@ func NewMailingForProvider(provider contracts.ProviderInterface, msgCfg mailing. } func (m Mailing) Send(ctx context.Context, msg contracts.MessageInterface) error { + if msg.GetMimeType().IsEmpty() && !m.msgCfg.GetMimeType().IsEmpty() { + msg.SetMimeType(m.msgCfg.GetMimeType()) + } + if msg.GetFrom().IsEmpty() && !m.msgCfg.GetFrom().IsEmpty() { _ = msg.SetFrom(m.msgCfg.GetFrom()) }