Documentation
¶
Index ¶
- func UnfoldHeaders(contents string) string
- type Attachment
- type AttachmentHeader
- type ISMTPMessagePart
- type MailAddressCollection
- type MailItem
- type SMTPMessagePart
- func (messagePart *SMTPMessagePart) AddBody(body string) error
- func (messagePart *SMTPMessagePart) AddHeaders(headers textproto.MIMEHeader) error
- func (messagePart *SMTPMessagePart) BuildMessages(body string) error
- func (messagePart *SMTPMessagePart) ContentIsMultipart() (bool, error)
- func (messagePart *SMTPMessagePart) GetBody() string
- func (messagePart *SMTPMessagePart) GetBoundary() (string, error)
- func (messagePart *SMTPMessagePart) GetBoundaryFromHeaderString(header string) (string, error)
- func (messagePart *SMTPMessagePart) GetContentDisposition() string
- func (messagePart *SMTPMessagePart) GetContentType() string
- func (messagePart *SMTPMessagePart) GetFilenameFromContentDisposition() string
- func (messagePart *SMTPMessagePart) GetHeader(key string) string
- func (messagePart *SMTPMessagePart) GetMessageParts() []ISMTPMessagePart
- func (messagePart *SMTPMessagePart) ParseMessages(body string, boundary string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnfoldHeaders ¶
UnfoldHeaders follows the RFC-2822, which defines "folding" as the process of breaking up large header lines into multiple lines. Long Subject lines or Content-Type lines (with boundaries) sometimes do this. This function will "unfold" them into a single line.
Types ¶
type Attachment ¶
type Attachment struct {
ID uuid.UUID `db:"id" json:"id"`
MailID string `db:"mailitem_id" json:"mailId"`
MailItem *MailItem `belongs_to:"mailitem" json:"-"`
FileName string `db:"file_name" json:"fileName"`
ContentType string `db:"content_type" json:"contentType"`
Contents string `db:"contents" json:"contents"`
CreatedAt time.Time `db:"created_at" json:"-"`
UpdatedAt time.Time `db:"updated_at" json:"-"`
Headers *AttachmentHeader `db:"-" json:"headers"`
}
An Attachment is any content embedded in the mail data that is not considered the body.
func NewAttachment ¶
func NewAttachment(headers *AttachmentHeader, contents string, xss sanitizer.IXSSServiceProvider) *Attachment
NewAttachment creates a new Attachment object.
func (*Attachment) IsContentBase64 ¶
func (a *Attachment) IsContentBase64() bool
IsContentBase64 returns true/false if the content of this attachment resembles a base64 encoded string.
func (*Attachment) Sanitize ¶
func (a *Attachment) Sanitize(xss sanitizer.IXSSServiceProvider)
func (Attachment) TableName ¶
func (a Attachment) TableName() string
func (*Attachment) Validate ¶
func (a *Attachment) Validate(tx *pop.Connection) (*validate.Errors, error)
Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
type AttachmentHeader ¶
type AttachmentHeader struct {
ContentType string `db:"content_type" json:"contentType"`
MIMEVersion string `db:"mime_version" json:"mimeVersion"`
ContentTransferEncoding string `db:"content_transfer_encoding" json:"contentTransferEncoding"`
ContentDisposition string `db:"content_disposition" json:"contentDisposition"`
FileName string `db:"file_name" json:"fileName"`
Body string `db:"body" json:"body"`
Logger *slog.Logger `db:"-" json:"-"`
}
AttachmentHeader provides information that describes an attachment. It has information such as the type of content, file name, etc...
func NewAttachmentHeader ¶
func NewAttachmentHeader(contentType, mimeVersion, contentTransferEncoding, contentDisposition, fileName, body string) *AttachmentHeader
NewAttachmentHeader creates a new AttachmentHeader object
func (*AttachmentHeader) Parse ¶
func (attachmentHeader *AttachmentHeader) Parse(contents string)
Parse processes a set of attachment headers. Splits lines up and figures out what header data goes into what structure key. Most headers follow this format:
Header-Name: Some value here\r\n
type ISMTPMessagePart ¶
type ISMTPMessagePart interface {
AddBody(body string) error
AddHeaders(headerSet textproto.MIMEHeader) error
BuildMessages(body string) error
ContentIsMultipart() (bool, error)
GetBody() string
GetBoundary() (string, error)
GetBoundaryFromHeaderString(header string) (string, error)
GetContentDisposition() string
GetContentType() string
GetFilenameFromContentDisposition() string
GetHeader(key string) string
GetMessageParts() []ISMTPMessagePart
ParseMessages(body string, boundary string) error
}
An ISMTPMessagePart represents a single message/content from a DATA transmission from an SMTP client. This contains the headers and body content. It also contains a reference to a collection of sub-messages, if any. This allows us to support the recursive tree-like nature of the MIME protocol.
type MailAddressCollection ¶
type MailAddressCollection []string
MailAddressCollection is a set of email address.
func NewMailAddressCollection ¶
func NewMailAddressCollection() MailAddressCollection
NewMailAddressCollection returns a new MailAddressCollection.
func NewMailAddressCollectionFromStringList ¶
func NewMailAddressCollectionFromStringList(addresses string) MailAddressCollection
NewMailAddressCollectionFromStringList takes a list of delimited email address and breaks it into a collection of mail addresses.
func (*MailAddressCollection) Scan ¶
func (c *MailAddressCollection) Scan(value any) error
Scan implements the sql.Scanner interface. It allows to read the string slice from the database value.
type MailItem ¶
type MailItem struct {
ID uuid.UUID `db:"id" json:"id"`
DateSent string `db:"date_sent" json:"dateSent"`
FromAddress string `db:"from_address" json:"fromAddress"`
ToAddresses MailAddressCollection `db:"to_addresses" json:"toAddresses"`
Subject string `db:"subject" json:"subject"`
XMailer string `db:"xmailer" json:"xmailer"`
MIMEVersion string `db:"mime_version" json:"mimeVersion"`
Body string `db:"body" json:"body"`
ContentType string `db:"content_type" json:"contentType"`
Boundary string `db:"boundary" json:"boundary"`
TransferEncoding string `db:"transfer_encoding" json:"transferEncoding"`
Attachments []*Attachment `has_many:"attachment" json:"-"`
CreatedAt time.Time `db:"created_at" json:"-"`
UpdatedAt time.Time `db:"updated_at" json:"-"`
Message *SMTPMessagePart `db:"-" json:"-"`
InlineAttachments []*Attachment `db:"-" json:"-"`
TextBody string `db:"-" json:"-"`
HTMLBody string `db:"-" json:"-"`
}
MailItem is a struct describing a parsed mail item. This is populated after an incoming client connection has finished sending mail data to this server.
func NewEmptyMailItem ¶
NewEmptyMailItem creates an empty mail object.
func NewMailItem ¶
func NewMailItem( id uuid.UUID, dateSent string, fromAddress string, toAddresses MailAddressCollection, subject, xMailer, body, contentType, boundary string, attachments []*Attachment, logger *slog.Logger, ) *MailItem
NewMailItem creates a new MailItem object.
func (*MailItem) Sanitize ¶
func (m *MailItem) Sanitize(xss sanitizer.IXSSServiceProvider)
type SMTPMessagePart ¶
type SMTPMessagePart struct {
Message *mail.Message
MessageParts []ISMTPMessagePart
// contains filtered or unexported fields
}
An SMTPMessagePart represents a single message/content from a DATA transmission from an SMTP client. This contains the headers and body content. It also contains a reference to a collection of sub-messages, if any. This allows us to support the recursive tree-like nature of the MIME protocol.
func NewSMTPMessagePart ¶
func NewSMTPMessagePart(logger *slog.Logger) *SMTPMessagePart
NewSMTPMessagePart returns a new instance of this struct
func (*SMTPMessagePart) AddBody ¶
func (messagePart *SMTPMessagePart) AddBody(body string) error
AddBody adds body content
func (*SMTPMessagePart) AddHeaders ¶
func (messagePart *SMTPMessagePart) AddHeaders(headers textproto.MIMEHeader) error
AddHeaders takes a header set and adds it to this message part.
func (*SMTPMessagePart) BuildMessages ¶
func (messagePart *SMTPMessagePart) BuildMessages(body string) error
BuildMessages pulls the message body from the data transmission and stores the whole body. If the message type is multipart it then attempts to parse the parts.
func (*SMTPMessagePart) ContentIsMultipart ¶
func (messagePart *SMTPMessagePart) ContentIsMultipart() (bool, error)
ContentIsMultipart returns true if the Content-Type header contains "multipart"
func (*SMTPMessagePart) GetBody ¶
func (messagePart *SMTPMessagePart) GetBody() string
GetBody retrieves the body portion of the message
func (*SMTPMessagePart) GetBoundary ¶
func (messagePart *SMTPMessagePart) GetBoundary() (string, error)
GetBoundary returns the message boundary string
func (*SMTPMessagePart) GetBoundaryFromHeaderString ¶
func (messagePart *SMTPMessagePart) GetBoundaryFromHeaderString(header string) (string, error)
GetBoundaryFromHeaderString returns the boundary marker defined in the header
func (*SMTPMessagePart) GetContentDisposition ¶
func (messagePart *SMTPMessagePart) GetContentDisposition() string
GetContentDisposition returns the value of the Content-Disposition header
func (*SMTPMessagePart) GetContentType ¶
func (messagePart *SMTPMessagePart) GetContentType() string
GetContentType returns the value from the Content-Type header
func (*SMTPMessagePart) GetFilenameFromContentDisposition ¶
func (messagePart *SMTPMessagePart) GetFilenameFromContentDisposition() string
GetFilenameFromContentDisposition returns a filename from a Content-Disposition header
func (*SMTPMessagePart) GetHeader ¶
func (messagePart *SMTPMessagePart) GetHeader(key string) string
GetHeader returns the value of a specified header key
func (*SMTPMessagePart) GetMessageParts ¶
func (messagePart *SMTPMessagePart) GetMessageParts() []ISMTPMessagePart
GetMessageParts returns any additional sub-messages related to this message
func (*SMTPMessagePart) ParseMessages ¶
func (messagePart *SMTPMessagePart) ParseMessages(body string, boundary string) error
ParseMessages parses messages in an SMTP body