2018-10-25 15:51:47 +02:00
|
|
|
package messenger
|
|
|
|
|
2020-09-20 13:01:24 +02:00
|
|
|
import (
|
|
|
|
"net/textproto"
|
|
|
|
|
|
|
|
"github.com/knadh/listmonk/models"
|
|
|
|
)
|
2019-07-18 09:10:48 +02:00
|
|
|
|
2018-10-25 15:51:47 +02:00
|
|
|
// Messenger is an interface for a generic messaging backend,
|
|
|
|
// for instance, e-mail, SMS etc.
|
|
|
|
type Messenger interface {
|
|
|
|
Name() string
|
2020-08-01 14:24:51 +02:00
|
|
|
Push(Message) error
|
2018-10-25 15:51:47 +02:00
|
|
|
Flush() error
|
2020-07-08 13:00:14 +02:00
|
|
|
Close() error
|
2018-10-25 15:51:47 +02:00
|
|
|
}
|
2019-07-18 09:10:48 +02:00
|
|
|
|
2020-08-01 14:24:51 +02:00
|
|
|
// Message is the message pushed to a Messenger.
|
|
|
|
type Message struct {
|
|
|
|
From string
|
|
|
|
To []string
|
|
|
|
Subject string
|
2020-09-20 13:01:24 +02:00
|
|
|
ContentType string
|
2020-08-01 14:24:51 +02:00
|
|
|
Body []byte
|
2021-01-30 10:29:21 +01:00
|
|
|
AltBody []byte
|
2020-08-01 14:24:51 +02:00
|
|
|
Headers textproto.MIMEHeader
|
|
|
|
Attachments []Attachment
|
2020-09-20 13:01:24 +02:00
|
|
|
|
|
|
|
Subscriber models.Subscriber
|
|
|
|
|
|
|
|
// Campaign is generally the same instance for a large number of subscribers.
|
|
|
|
Campaign *models.Campaign
|
2020-08-01 14:24:51 +02:00
|
|
|
}
|
|
|
|
|
2019-07-18 09:10:48 +02: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 09:00:51 +02: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 07:41:47 +02:00
|
|
|
h.Set("Content-Transfer-Encoding", encoding)
|
2019-07-21 09:00:51 +02:00
|
|
|
return h
|
|
|
|
}
|