Documentation
¶
Overview ¶
models/mailbox.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Email ¶
type Email struct {
ID string `gorm:"column:id;type:varchar(50);primaryKey" json:"id"`
MailboxID string `gorm:"column:mailbox_id;type:varchar(50);index;not null" json:"mailboxId"`
Provider enum.EmailProvider `gorm:"column:provider;type:varchar(50);index;not null" json:"provider"`
Direction enum.EmailDirection `gorm:"column:direction;type:varchar(20);index;not null" json:"direction"`
Status enum.EmailStatus `gorm:"column:status;type:varchar(20);index" json:"status"`
Folder string `gorm:"column:folder;type:varchar(100);index;not null" json:"folder"`
ImapUID uint32 `gorm:"column:imap_uid;index" json:"imapUid"`
MessageID string `gorm:"column:message_id;uniqueIndex;type:varchar(255);not null" json:"messageId"`
ThreadID string `gorm:"column:thread_id;type:varchar(255);index" json:"threadId"`
InReplyTo string `gorm:"column:in_reply_to;type:varchar(255);index" json:"inReplyTo"`
References pq.StringArray `gorm:"column:references;type:text[]" json:"references"`
// Core email metadata
Subject string `gorm:"column:subject;type:varchar(1000)" json:"subject"`
FromAddress string `gorm:"column:from_address;type:varchar(255);index" json:"fromAddress"`
FromName string `gorm:"column:from_name;type:varchar(255)" json:"fromName"`
FromDomain string `gorm:"column:from_domain;type:varchar(255)" json:"fromDomain"`
ReplyTo string `gorm:"column:reply_to;type:varchar(255);index" json:"replyTo"`
ToAddresses pq.StringArray `gorm:"column:to_addresses;type:text[]" json:"toAddresses"`
CcAddresses pq.StringArray `gorm:"column:cc_addresses;type:text[]" json:"ccAddresses"`
BccAddresses pq.StringArray `gorm:"column:bcc_addresses;type:text[]" json:"bccAddresses"`
// Content
BodyText string `gorm:"column:body_text;type:text" json:"bodyText"`
BodyHTML string `gorm:"column:body_html;type:text" json:"bodyHtml"`
HasAttachment bool `gorm:"column:has_attachment;default:false" json:"hasAttachment"`
// Send Details
StatusDetail string `gorm:"column:status_detail;type:text" json:"statusDetail"` // Error message or delivery info
SendAttempts int `gorm:"column:send_attempts;default:0" json:"sendAttempts"` // Number of send attempts
// Time information
SentAt *time.Time `gorm:"column:sent_at;type:timestamp;index" json:"sentAt"`
ReceivedAt *time.Time `gorm:"column:received_at;type:timestamp;index" json:"receivedAt"`
LastAttemptAt *time.Time `gorm:"column:last_attempt_at;type:timestamp" json:"lastAttemptAt"` // When last send attempt occurred
ScheduledFor *time.Time `gorm:"column:scheduled_for;type:timestamp;index" json:"scheduledFor"` // For scheduled sends
// Extensions and provider-specific data
GmailLabels pq.StringArray `gorm:"column:gmail_labels;type:text[]" json:"gmailLabels"`
OutlookCategories pq.StringArray `gorm:"column:outlook_categories;type:text[]" json:"outlookCategories"`
MailstackFlags pq.StringArray `gorm:"column:mailstack_flags;type:text[]" json:"mailstackFlags"`
// Raw data
RawHeaders JSONMap `gorm:"column:raw_headers;type:jsonb" json:"rawHeaders"`
Envelope JSONMap `gorm:"column:envelope;type:jsonb" json:"envelope"`
BodyStructure JSONMap `gorm:"column:body_structure;type:jsonb" json:"bodyStructure"`
// Classification
Classification enum.EmailClassification `gorm:"column:classification;type:varchar(50);index" json:"classification"`
ClassificationReason string `gorm:"column:classification_reason;type:text" json:"classificationReason"`
// Standard timestamps
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:current_timestamp" json:"updatedAt"`
}
Email represents a raw email message stored in the database
func (*Email) AllRecepients ¶
func (*Email) BuildHeaders ¶
BuildHeaders creates a map of headers for an outgoing email
func (*Email) HasRichContent ¶
func (*Email) Headers ¶
func (e *Email) Headers() (*EmailHeaders, error)
type EmailAttachment ¶
type EmailAttachment struct {
ID string `gorm:"type:varchar(50);primaryKey"`
EmailID string `gorm:"type:varchar(50);index;not null"`
Direction string `gorm:"type:varchar(10);index;not null"` // "inbound" or "outbound"
Filename string `gorm:"type:varchar(500)"`
ContentType string `gorm:"type:varchar(255)"`
ContentID string `gorm:"type:varchar(255)"` // For inline attachments
Size int `gorm:"default:0"`
IsInline bool `gorm:"default:false"`
// Storage options
StorageService string `gorm:"type:varchar(50)"` // "s3", "azure", "local", etc.
StorageBucket string `gorm:"type:varchar(255)"` // For cloud storage
StorageKey string `gorm:"type:varchar(1000)"` // If stored in S3/blob storage
// Additional fields for inbound attachments
ContentDisposition string `gorm:"type:varchar(100)"` // attachment, inline, etc.
EncodingType string `gorm:"type:varchar(50)"` // base64, quoted-printable, etc.
// Security and verification
ContentHash string `gorm:"type:varchar(64)"` // SHA-256 hash of content
ScanStatus string `gorm:"type:varchar(20)"` // clean, infected, pending, etc.
ScanTimestamp *time.Time
// Standard timestamps
CreatedAt time.Time
UpdatedAt time.Time
}
EmailAttachment represents an attachment to an email
func (*EmailAttachment) BeforeCreate ¶
func (e *EmailAttachment) BeforeCreate(tx *gorm.DB) error
func (EmailAttachment) TableName ¶
func (EmailAttachment) TableName() string
TableName overrides the table name for EmailAttachment
type EmailHeaders ¶
type EmailHeaders struct {
AutoSubmitted bool
ContentDescription string
DeliveryStatus bool
ListUnsubscribe bool
Precedence string
ReturnPath string
ReturnPathExists bool
XAutoreply string
XAutoresponse string
XLoop bool
XFailedRecipients []string
ReplyTo string
ReplyToExists bool
Sender string
ForwardedFor string
DKIM []string
SPF string
DMARC string
}
EmailHeaders represents specific email header information needed for processing
type EmailThread ¶
type EmailThread struct {
ID string `gorm:"column:id;type:varchar(50);primaryKey" json:"id"`
Subject string `gorm:"column:subject;type:varchar(1000)" json:"subject"`
Participants pq.StringArray `gorm:"column:participants;type:text[]" json:"participants"`
MessageCount int `gorm:"column:message_count;default:0" json:"messageCount"`
MailboxID string `gorm:"column:mailbox_id;type:varchar(50);index" json:"mailboxId"`
LastMessageID string `gorm:"column:last_message_id;type:varchar(50)" json:"lastMessageId"`
HasAttachments bool `gorm:"column:has_attachments;default:false" json:"hasAttachments"`
LastMessageAt *time.Time `gorm:"column:last_message_at;type:timestamp" json:"lastMessageAt"`
FirstMessageAt *time.Time `gorm:"column:first_message_at;type:timestamp" json:"firstMessageAt"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp" json:"updatedAt"`
}
func (*EmailThread) BeforeCreate ¶
func (e *EmailThread) BeforeCreate(tx *gorm.DB) error
func (EmailThread) TableName ¶
func (EmailThread) TableName() string
type JSONMap ¶
type JSONMap map[string]interface{}
JSONMap represents a JSON object that can be stored in PostgreSQL
type Mailbox ¶
type Mailbox struct {
ID string `gorm:"column:id;type:varchar(50);primaryKey" json:"id"`
Tenant string `gorm:"column:tenant;type:varchar(255)" json:"tenant"`
UserID string `gorm:"column:user_id;type:varchar(255);index" json:"userId"`
Provider enum.EmailProvider `gorm:"column:provider;type:varchar(50);index;not null" json:"provider"`
EmailAddress string `gorm:"column:email_address;type:varchar(255);index" json:"emailAddress"`
MailboxUser string `gorm:"column:mailbox_user;type:varchar(255);index" json:"mailboxUser"`
MailboxDomain string `gorm:"column:mailbox_domain;type:varchar(255);index" json:"mailboxDomain"`
// Common connection properties
InboundEnabled bool `gorm:"column:inbound_enabled;default:true" json:"inboundEnabled"`
OutboundEnabled bool `gorm:"column:outbound_enabled;default:true" json:"outboundEnabled"`
// Protocol-specific configurations (null for API-based providers)
ImapServer string `gorm:"column:imap_server;type:varchar(255)" json:"imapServer"`
ImapPort int `gorm:"column:imap_port" json:"imapPort"`
ImapUsername string `gorm:"column:imap_username;type:varchar(255)" json:"imapUsername"`
ImapPassword string `gorm:"column:imap_password;type:varchar(255)" json:"imapPassword"`
ImapSecurity enum.EmailSecurity `gorm:"column:imap_security;type:varchar(50)" json:"imapSecurity"`
SmtpServer string `gorm:"column:smtp_server;type:varchar(255)" json:"smtpServer"`
SmtpPort int `gorm:"column:smtp_port" json:"smtpPort"`
SmtpUsername string `gorm:"column:smtp_username;type:varchar(255)" json:"smtpUsername"`
SmtpPassword string `gorm:"column:smtp_password;type:varchar(255)" json:"smtpPassword"`
SmtpSecurity enum.EmailSecurity `gorm:"column:smtp_security;type:varchar(50)" json:"smtpSecurity"`
// OAuth specific fields (for Google, Microsoft, etc.)
OAuthClientID string `gorm:"column:oauth_client_id;type:varchar(255)" json:"oauthClientId"`
OAuthClientSecret string `gorm:"column:oauth_client_secret;type:varchar(255)" json:"oauthClientSecret"`
OAuthRefreshToken string `gorm:"column:oauth_refresh_token;type:varchar(1000)" json:"oauthRefreshToken"`
OAuthAccessToken string `gorm:"column:oauth_access_token;type:varchar(1000)" json:"oauthAccessToken"`
OAuthTokenExpiry *time.Time `gorm:"column:oauth_token_expiry;type:timestamp" json:"oauthTokenExpiry"`
OAuthScope string `gorm:"column:oauth_scope;type:varchar(500)" json:"oauthScope"`
// Email sending configuration
DefaultFromName string `gorm:"column:default_from_name;type:varchar(255)" json:"defaultFromName"`
ReplyToAddress string `gorm:"column:reply_to_address;type:varchar(255)" json:"replyToAddress"`
SignatureHTML string `gorm:"column:signature_html;type:text" json:"signatureHtml"`
SignaturePlain string `gorm:"column:signature_plain;type:text" json:"signaturePlain"`
// Sync configuration
SyncEnabled bool `gorm:"column:sync_enabled;default:true" json:"syncEnabled"`
SyncFolders pq.StringArray `gorm:"column:sync_folders;type:text[]" json:"syncFolders"`
// Status tracking
ConnectionStatus string `gorm:"column:connection_status;type:varchar(50)" json:"connectionStatus"`
LastConnectionCheck *time.Time `gorm:"column:last_connection_check;type:timestamp" json:"lastConnectionCheck"`
ErrorMessage string `gorm:"column:error_message;type:text" json:"errorMessage"`
// Send rate limits
DailySendQuota int `gorm:"column:daily_quota;default:2000" json:"dailyQuota"`
DailySendCount int `gorm:"column:daily_send_count;default:0" json:"dailySendCount"`
QuotaResetAt *time.Time `gorm:"column:quota_reset_at;type:timestamp" json:"quotaResetAt"`
// Standard timestamps
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:current_timestamp" json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
}
Mailbox represents an email account configuration with provider-specific settings
type MailboxSyncState ¶
type MailboxSyncState struct {
ID string `gorm:"column:id;type:uuid;primaryKey;default:gen_random_uuid()"`
MailboxID string `gorm:"column:mailbox_id;type:varchar(50);index;not null"`
FolderName string `gorm:"column:folder_name;type:varchar(100);index;not null"`
LastUID uint32 `gorm:"column:last_uid;not null"`
LastSync time.Time `gorm:"column:last_sync;type:timestamp;not null"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:current_timestamp"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:current_timestamp"`
}
MailboxSyncState represents the synchronization state for a mailbox folder
func (MailboxSyncState) TableName ¶
func (MailboxSyncState) TableName() string
Click to show internal directories.
Click to hide internal directories.