2018-10-25 13:51:47 +00:00
|
|
|
package messenger
|
|
|
|
|
2020-09-20 11:01:24 +00:00
|
|
|
import (
|
|
|
|
"net/textproto"
|
|
|
|
|
|
|
|
"github.com/knadh/listmonk/models"
|
|
|
|
)
|
2019-07-18 07:10:48 +00:00
|
|
|
|
2018-10-25 13:51:47 +00:00
|
|
|
// Messenger is an interface for a generic messaging backend,
|
|
|
|
// for instance, e-mail, SMS etc.
|
|
|
|
type Messenger interface {
|
|
|
|
Name() string
|
2020-08-01 12:24:51 +00:00
|
|
|
Push(Message) error
|
2018-10-25 13:51:47 +00:00
|
|
|
Flush() error
|
2020-07-08 11:00:14 +00:00
|
|
|
Close() error
|
2018-10-25 13:51:47 +00:00
|
|
|
}
|
2019-07-18 07:10:48 +00:00
|
|
|
|
2020-08-01 12:24:51 +00:00
|
|
|
// Message is the message pushed to a Messenger.
|
|
|
|
type Message struct {
|
|
|
|
From string
|
|
|
|
To []string
|
|
|
|
Subject string
|
2020-09-20 11:01:24 +00:00
|
|
|
ContentType string
|
2020-08-01 12:24:51 +00:00
|
|
|
Body []byte
|
2021-01-30 09:29:21 +00:00
|
|
|
AltBody []byte
|
2020-08-01 12:24:51 +00:00
|
|
|
Headers textproto.MIMEHeader
|
|
|
|
Attachments []Attachment
|
2020-09-20 11:01:24 +00:00
|
|
|
|
|
|
|
Subscriber models.Subscriber
|
|
|
|
|
|
|
|
// Campaign is generally the same instance for a large number of subscribers.
|
|
|
|
Campaign *models.Campaign
|
2020-08-01 12:24:51 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 07:10:48 +00:00
|
|
|
// Attachment represents a file or blob attachment that can be
|
|
|
|
// sent along with a message by a Messenger.
|
|
|
|
type Attachment struct {
|
|
|
|
Name string
|
|
|
|
Header textproto.MIMEHeader
|
|
|
|
Content []byte
|
|
|
|
}
|
2019-07-21 07:00:51 +00:00
|
|
|
|
|
|
|
// MakeAttachmentHeader is a helper function that returns a
|
|
|
|
// textproto.MIMEHeader tailored for attachments, primarily
|
|
|
|
// email. If no encoding is given, base64 is assumed.
|
|
|
|
func MakeAttachmentHeader(filename, encoding string) textproto.MIMEHeader {
|
|
|
|
if encoding == "" {
|
|
|
|
encoding = "base64"
|
|
|
|
}
|
|
|
|
h := textproto.MIMEHeader{}
|
|
|
|
h.Set("Content-Disposition", "attachment; filename="+filename)
|
|
|
|
h.Set("Content-Type", "application/json; name=\""+filename+"\"")
|
2019-10-25 05:41:47 +00:00
|
|
|
h.Set("Content-Transfer-Encoding", encoding)
|
2019-07-21 07:00:51 +00:00
|
|
|
return h
|
|
|
|
}
|