2022-10-12 15:47:51 +02:00
|
|
|
package storage
|
2022-07-29 13:23:08 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/mail"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/jhillyerd/enmime"
|
|
|
|
)
|
|
|
|
|
2023-03-31 06:29:04 +02:00
|
|
|
// Message data excluding physical attachments
|
|
|
|
//
|
|
|
|
// swagger:model Message
|
2022-07-29 13:23:08 +02:00
|
|
|
type Message struct {
|
2023-03-31 06:29:04 +02:00
|
|
|
// Unique message database id
|
|
|
|
ID string
|
|
|
|
// Read status
|
|
|
|
Read bool
|
|
|
|
// From address
|
|
|
|
From *mail.Address
|
|
|
|
// To addresses
|
|
|
|
To []*mail.Address
|
|
|
|
// Cc addresses
|
|
|
|
Cc []*mail.Address
|
|
|
|
// Bcc addresses
|
|
|
|
Bcc []*mail.Address
|
2023-03-31 12:34:59 +02:00
|
|
|
// ReplyTo addresses
|
|
|
|
ReplyTo []*mail.Address
|
2023-03-31 06:29:04 +02:00
|
|
|
// Message subject
|
|
|
|
Subject string
|
|
|
|
// Message date if set, else date received
|
|
|
|
Date time.Time
|
|
|
|
// Message tags
|
|
|
|
Tags []string
|
|
|
|
// Message body text
|
|
|
|
Text string
|
|
|
|
// Message body HTML
|
|
|
|
HTML string
|
|
|
|
// Message size in bytes
|
|
|
|
Size int
|
|
|
|
// Inline message attachments
|
|
|
|
Inline []Attachment
|
|
|
|
// Message attachments
|
2022-07-29 13:23:08 +02:00
|
|
|
Attachments []Attachment
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attachment struct for inline and attachments
|
2023-03-31 06:29:04 +02:00
|
|
|
//
|
|
|
|
// swagger:model Attachment
|
2022-07-29 13:23:08 +02:00
|
|
|
type Attachment struct {
|
2023-03-31 06:29:04 +02:00
|
|
|
// attachment part id
|
|
|
|
PartID string
|
|
|
|
// file name
|
|
|
|
FileName string
|
|
|
|
// content type
|
2022-07-29 13:23:08 +02:00
|
|
|
ContentType string
|
2023-03-31 06:29:04 +02:00
|
|
|
// content id
|
|
|
|
ContentID string
|
|
|
|
// size in bytes
|
|
|
|
Size int
|
2022-07-29 13:23:08 +02:00
|
|
|
}
|
|
|
|
|
2022-10-21 11:55:15 +02:00
|
|
|
// MessageSummary struct for frontend messages
|
2023-03-31 06:29:04 +02:00
|
|
|
//
|
|
|
|
// swagger:model MessageSummary
|
2022-10-21 11:55:15 +02:00
|
|
|
type MessageSummary struct {
|
2023-03-31 06:29:04 +02:00
|
|
|
// Unique message database id
|
|
|
|
ID string
|
|
|
|
// Read status
|
|
|
|
Read bool
|
|
|
|
// From address
|
|
|
|
From *mail.Address
|
|
|
|
// To address
|
|
|
|
To []*mail.Address
|
|
|
|
// Cc addresses
|
|
|
|
Cc []*mail.Address
|
|
|
|
// Bcc addresses
|
|
|
|
Bcc []*mail.Address
|
|
|
|
// Email subject
|
|
|
|
Subject string
|
|
|
|
// Created time
|
|
|
|
Created time.Time
|
|
|
|
// Message tags
|
|
|
|
Tags []string
|
|
|
|
// Message size in bytes (total)
|
|
|
|
Size int
|
|
|
|
// Whether the message has any attachments
|
2022-07-29 13:23:08 +02:00
|
|
|
Attachments int
|
|
|
|
}
|
|
|
|
|
2022-10-12 15:47:51 +02:00
|
|
|
// MailboxStats struct for quick mailbox total/read lookups
|
|
|
|
type MailboxStats struct {
|
|
|
|
Total int
|
|
|
|
Unread int
|
2022-11-13 05:45:54 +02:00
|
|
|
Tags []string
|
2022-10-12 15:47:51 +02:00
|
|
|
}
|
|
|
|
|
2022-07-29 13:23:08 +02:00
|
|
|
// AttachmentSummary returns a summary of the attachment without any binary data
|
|
|
|
func AttachmentSummary(a *enmime.Part) Attachment {
|
|
|
|
o := Attachment{}
|
|
|
|
o.PartID = a.PartID
|
|
|
|
o.FileName = a.FileName
|
|
|
|
if o.FileName == "" {
|
|
|
|
o.FileName = a.ContentID
|
|
|
|
}
|
|
|
|
o.ContentType = a.ContentType
|
|
|
|
o.ContentID = a.ContentID
|
|
|
|
o.Size = len(a.Content)
|
|
|
|
|
|
|
|
return o
|
|
|
|
}
|