Documentation
¶
Index ¶
- Constants
- Variables
- func GetDestinations(destinationsJSON string) ([]string, error)
- func SetDeliveryProcessor(processor DeliveryProcessor)
- func SetDestinations(destinations []string) (string, error)
- type AdminUserRequest
- type AliasService
- func (s *AliasService) Count(ctx context.Context) (int64, error)
- func (s *AliasService) CountByDomain(ctx context.Context, domainID int64) (int64, error)
- func (s *AliasService) Create(ctx context.Context, alias *domain.Alias) error
- func (s *AliasService) Delete(ctx context.Context, id int64) error
- func (s *AliasService) GetByEmail(ctx context.Context, email string) (*domain.Alias, error)
- func (s *AliasService) GetByID(ctx context.Context, id int64) (*domain.Alias, error)
- func (s *AliasService) List(ctx context.Context, offset, limit int) ([]*domain.Alias, error)
- func (s *AliasService) ListAll(ctx context.Context) ([]*domain.Alias, error)
- func (s *AliasService) ListByDomain(ctx context.Context, domainID int64) ([]*domain.Alias, error)
- func (s *AliasService) Update(ctx context.Context, alias *domain.Alias) error
- type Attachment
- type AuditLogFilter
- type AuditService
- func (s *AuditService) DeleteOldLogs(ctx context.Context, retentionDays int) (int64, error)
- func (s *AuditService) GetLogs(ctx context.Context, filter AuditLogFilter) ([]*domain.AuditLog, error)
- func (s *AuditService) Log(ctx context.Context, log *domain.AuditLog) error
- func (s *AuditService) LogAction(ctx context.Context, userID *int64, ...) error
- func (s *AuditService) LogSecurityEvent(ctx context.Context, action, resourceType string, success bool, ...) error
- type DANEService
- func (s *DANEService) ClearCache(ctx context.Context) (int64, error)
- func (s *DANEService) LookupTLSA(ctx context.Context, domainName string, port int) ([]*domain.DANETLSARecord, error)
- func (s *DANEService) SetResolver(resolver string)
- func (s *DANEService) VerifyTLSConnection(ctx context.Context, domainName string, port int, ...) (bool, error)
- type DANEServiceConfig
- type DKIMKeyResult
- type DeliveryProcessor
- type DomainService
- func (s *DomainService) Create(ctx context.Context, domain *domain.Domain) error
- func (s *DomainService) CreateDomainFromTemplate(domainName string) (*domain.Domain, error)
- func (s *DomainService) Delete(ctx context.Context, id int64) error
- func (s *DomainService) EnsureDefaultTemplate() error
- func (s *DomainService) GenerateDKIMKeys(ctx context.Context, id int64, keyType string, keySize int) (*DKIMKeyResult, error)
- func (s *DomainService) GetAntivirusConfig(domainName string) (*domain.AntivirusConfig, error)
- func (s *DomainService) GetByID(ctx context.Context, id int64) (*domain.Domain, error)
- func (s *DomainService) GetDKIMConfig(domainName string) (*domain.DKIMConfig, error)
- func (s *DomainService) GetDefaultTemplate() (*domain.Domain, error)
- func (s *DomainService) List(ctx context.Context, offset, limit int) ([]*domain.Domain, error)
- func (s *DomainService) Update(ctx context.Context, domain *domain.Domain) error
- func (s *DomainService) UpdateDefaultTemplate(updates *domain.Domain) error
- type Draft
- type DraftData
- type MTASTSService
- func (s *MTASTSService) ClearCache(ctx context.Context) (int64, error)
- func (s *MTASTSService) CreateTLSReport(ctx context.Context, report *domain.TLSReport) error
- func (s *MTASTSService) EnforcePolicy(ctx context.Context, domainName, mxHostname string) (bool, error)
- func (s *MTASTSService) FetchPolicy(ctx context.Context, domainName string) (*domain.MTASTSPolicy, error)
- func (s *MTASTSService) GetPendingReports(ctx context.Context) ([]*domain.TLSReport, error)
- func (s *MTASTSService) MarkReportSent(ctx context.Context, reportID int64) error
- type MailboxService
- func (s *MailboxService) Create(userID int64, name, specialUse string) error
- func (s *MailboxService) CreateDefaultMailboxes(userID int64) error
- func (s *MailboxService) Delete(id int64) error
- func (s *MailboxService) GetByID(id int64) (*domain.Mailbox, error)
- func (s *MailboxService) GetByName(userID int64, name string) (*domain.Mailbox, error)
- func (s *MailboxService) List(userID int64, subscribed bool) ([]*domain.Mailbox, error)
- func (s *MailboxService) ListMailboxesByUserID(ctx context.Context, userID int) ([]*domain.Mailbox, error)
- func (s *MailboxService) Rename(id int64, newName string) error
- func (s *MailboxService) UpdateSubscription(id int64, subscribed bool) error
- type MailboxServiceInterface
- type MessageService
- func (s *MessageService) Delete(id int64) error
- func (s *MessageService) DeleteDraft(ctx context.Context, draftID, userID int) error
- func (s *MessageService) DeleteMessage(ctx context.Context, messageID, userID int) error
- func (s *MessageService) GetAttachment(ctx context.Context, attachmentID string, userID int) (*Attachment, error)
- func (s *MessageService) GetByID(id int64) (*domain.Message, error)
- func (s *MessageService) GetByMailbox(mailboxID int64, offset, limit int) ([]*domain.Message, error)
- func (s *MessageService) GetDraft(ctx context.Context, draftID, userID int) (*Draft, error)
- func (s *MessageService) GetMessage(ctx context.Context, messageID, userID int) (*domain.Message, error)
- func (s *MessageService) ListDrafts(ctx context.Context, userID int) ([]*Draft, error)
- func (s *MessageService) ListMessages(ctx context.Context, mailboxID, userID, limit, offset int) ([]*domain.Message, error)
- func (s *MessageService) MoveMessage(ctx context.Context, messageID, targetMailboxID, userID int) error
- func (s *MessageService) SaveDraft(ctx context.Context, userID int, draftID *int, data *DraftData) (*Draft, error)
- func (s *MessageService) SearchMessages(ctx context.Context, userID int, query string) ([]*domain.Message, error)
- func (s *MessageService) SendMessage(ctx context.Context, userID int, req *SendMessageRequest) (int, error)
- func (s *MessageService) SetMailboxService(mailboxService *MailboxService)
- func (s *MessageService) SetQueueService(queueService *QueueService)
- func (s *MessageService) SetUserService(userService UserServiceInterface)
- func (s *MessageService) Store(userID, mailboxID, uid int64, messageData []byte) (*domain.Message, error)
- func (s *MessageService) StorePhishingResult(ctx context.Context, messageID int64, result *phishing.PhishingResult) error
- func (s *MessageService) Update(message *domain.Message) error
- func (s *MessageService) UpdateFlags(ctx context.Context, messageID, userID int, flags []string, action string) error
- func (s *MessageService) UpdateTaskCompleted(ctx context.Context, messageID int64, completed bool) error
- type MessageServiceInterface
- type PGPService
- func (s *PGPService) DeleteKey(ctx context.Context, keyID int64) error
- func (s *PGPService) GetKey(ctx context.Context, keyID int64) (*domain.PGPKey, error)
- func (s *PGPService) GetKeyByFingerprint(ctx context.Context, userID int64, fingerprint string) (*domain.PGPKey, error)
- func (s *PGPService) GetPrimaryKey(ctx context.Context, userID int64) (*domain.PGPKey, error)
- func (s *PGPService) GetUserKeys(ctx context.Context, userID int64) ([]*domain.PGPKey, error)
- func (s *PGPService) ImportKey(ctx context.Context, userID int64, publicKeyArmored string) (*domain.PGPKey, error)
- func (s *PGPService) SetPrimaryKey(ctx context.Context, keyID int64) error
- type QuarantineService
- func (s *QuarantineService) CleanupOld(age time.Duration) error
- func (s *QuarantineService) Delete(itemID int64) error
- func (s *QuarantineService) List(offset, limit int) ([]*domain.QuarantineMessage, error)
- func (s *QuarantineService) Quarantine(messageID, sender, recipient, subject, reason, messagePath string, ...) error
- func (s *QuarantineService) Release(itemID int64) error
- type QueueService
- func (s *QueueService) CalculateNextRetry(retryCount int, failedAt time.Time) time.Time
- func (s *QueueService) Count(ctx context.Context) (int64, error)
- func (s *QueueService) CountByStatus(ctx context.Context, status string) (int64, error)
- func (s *QueueService) DeleteItem(ctx context.Context, id int64) error
- func (s *QueueService) Enqueue(from string, to []string, message []byte) (string, error)
- func (s *QueueService) GetByID(ctx context.Context, id int64) (*domain.QueueItem, error)
- func (s *QueueService) GetPending() ([]*domain.QueueItem, error)
- func (s *QueueService) GetPendingItems(ctx context.Context) ([]*domain.QueueItem, error)
- func (s *QueueService) IncrementRetry(id int64, currentRetryCount int, failedAt time.Time) error
- func (s *QueueService) List(ctx context.Context, offset, limit int) ([]*domain.QueueItem, error)
- func (s *QueueService) ListByStatus(ctx context.Context, status string, offset, limit int) ([]*domain.QueueItem, error)
- func (s *QueueService) MarkDelivered(id int64) error
- func (s *QueueService) MarkFailed(id int64, errorMsg string) error
- func (s *QueueService) ProcessQueue() error
- func (s *QueueService) ProcessQueueWithContext(ctx context.Context) error
- func (s *QueueService) RecordBounceTelemetry(ctx context.Context, ...) error
- func (s *QueueService) RecordDeliveryTelemetry(ctx context.Context, senderDomain, recipientDomain, ip string) error
- func (s *QueueService) RetryItem(ctx context.Context, id int64) error
- type QueueServiceInterface
- type SecuritySettings
- type SendMessageRequest
- type ServerSettings
- type SettingsService
- func (s *SettingsService) GetSecuritySettings(ctx context.Context) (*SecuritySettings, error)
- func (s *SettingsService) GetServerSettings(ctx context.Context) (*ServerSettings, error)
- func (s *SettingsService) GetTLSSettings(ctx context.Context) (*TLSSettings, error)
- func (s *SettingsService) UpdateSecuritySettings(ctx context.Context, settings *SecuritySettings) error
- func (s *SettingsService) UpdateServerSettings(ctx context.Context, settings *ServerSettings) error
- func (s *SettingsService) UpdateTLSSettings(ctx context.Context, settings *TLSSettings) error
- type SetupService
- func (s *SetupService) CompleteSetup(ctx context.Context) error
- func (s *SetupService) CreateAdminUser(ctx context.Context, req *AdminUserRequest) error
- func (s *SetupService) GetSetupState(ctx context.Context) (*SetupState, error)
- func (s *SetupService) IsSetupComplete(ctx context.Context) (bool, error)
- type SetupState
- type TLSSettings
- type UserService
- func (s *UserService) Authenticate(email, password string) (*domain.User, error)
- func (s *UserService) Count(ctx context.Context) (int64, error)
- func (s *UserService) CountByDomain(ctx context.Context, domainID int64) (int64, error)
- func (s *UserService) Create(user *domain.User, password string) error
- func (s *UserService) CreateWithPassword(user *domain.User, password string) error
- func (s *UserService) Delete(id int64) error
- func (s *UserService) GetByEmail(email string) (*domain.User, error)
- func (s *UserService) GetByID(id int64) (*domain.User, error)
- func (s *UserService) GetDomainByID(ctx context.Context, domainID int64) (*domain.Domain, error)
- func (s *UserService) HashPassword(password string) (string, error)
- func (s *UserService) ListAll() ([]*domain.User, error)
- func (s *UserService) ListPaginated(ctx context.Context, offset, limit int) ([]*domain.User, error)
- func (s *UserService) Update(user *domain.User) error
- func (s *UserService) UpdatePassword(userID int64, newPassword string) error
- func (s *UserService) VerifyPassword(hash, password string) bool
- type UserServiceInterface
- type WebhookService
- func (s *WebhookService) CleanupOldDeliveries(ctx context.Context, olderThanDays int) error
- func (s *WebhookService) ProcessPendingDeliveries(ctx context.Context) error
- func (s *WebhookService) TestWebhook(ctx context.Context, webhookID int64) error
- func (s *WebhookService) TriggerEvent(ctx context.Context, event domain.WebhookEvent, data map[string]interface{}) error
Constants ¶
const ( // StorageThreshold is the size threshold for blob vs file storage (1MB) StorageThreshold = 1024 * 1024 // MaxBlobSize is the maximum size for blob storage MaxBlobSize = 1024 * 1024 )
const DefaultTemplateDomainName = "_default"
Variables ¶
Functions ¶
func GetDestinations ¶
GetDestinations parses JSON destinations into a slice of email addresses
func SetDeliveryProcessor ¶
func SetDeliveryProcessor(processor DeliveryProcessor)
SetDeliveryProcessor sets the delivery processor for queue processing This should be called during application initialization
func SetDestinations ¶
SetDestinations converts a slice of email addresses to JSON format for storage
Types ¶
type AdminUserRequest ¶
type AdminUserRequest struct {
Email string `json:"email"`
Password string `json:"password"`
FullName string `json:"full_name"`
}
AdminUserRequest represents a request to create an admin user
type AliasService ¶
type AliasService struct {
// contains filtered or unexported fields
}
AliasService provides business logic for alias management
func NewAliasService ¶
func NewAliasService(repo repository.AliasRepository) *AliasService
NewAliasService creates a new alias service
func (*AliasService) Count ¶
func (s *AliasService) Count(ctx context.Context) (int64, error)
Count returns the total number of aliases
func (*AliasService) CountByDomain ¶
CountByDomain returns the total number of aliases for a domain
func (*AliasService) Delete ¶
func (s *AliasService) Delete(ctx context.Context, id int64) error
Delete deletes an alias
func (*AliasService) GetByEmail ¶
GetByEmail retrieves an alias by email address
func (*AliasService) ListByDomain ¶
ListByDomain retrieves all aliases for a domain
type Attachment ¶
Attachment represents an email attachment
type AuditLogFilter ¶
type AuditLogFilter struct {
UserID *int64
Action string
ResourceType string
Severity string
StartTime time.Time
EndTime time.Time
Limit int
Offset int
}
AuditLogFilter defines filter criteria for retrieving audit logs
type AuditService ¶
type AuditService struct {
// contains filtered or unexported fields
}
AuditService handles audit logging for admin actions and security events
func NewAuditService ¶
func NewAuditService(db *database.DB, logger *zap.Logger) *AuditService
NewAuditService creates a new audit service
func (*AuditService) DeleteOldLogs ¶
DeleteOldLogs removes audit logs older than the specified retention period
func (*AuditService) GetLogs ¶
func (s *AuditService) GetLogs(ctx context.Context, filter AuditLogFilter) ([]*domain.AuditLog, error)
GetLogs retrieves audit logs with filtering and pagination
func (*AuditService) LogAction ¶
func (s *AuditService) LogAction(ctx context.Context, userID *int64, username, action, resourceType, resourceID string, details interface{}) error
LogAction is a convenience method for logging admin actions
func (*AuditService) LogSecurityEvent ¶
func (s *AuditService) LogSecurityEvent(ctx context.Context, action, resourceType string, success bool, severity string, details interface{}) error
LogSecurityEvent logs a security event with appropriate severity
type DANEService ¶
type DANEService struct {
// contains filtered or unexported fields
}
DANEService handles DANE TLSA record lookups and caching
func NewDANEService ¶
func NewDANEService(db *database.DB, logger *zap.Logger) *DANEService
NewDANEService creates a new DANE service with default configuration
func NewDANEServiceWithConfig ¶
func NewDANEServiceWithConfig(db *database.DB, logger *zap.Logger, cfg *DANEServiceConfig) *DANEService
NewDANEServiceWithConfig creates a new DANE service with custom configuration
func (*DANEService) ClearCache ¶
func (s *DANEService) ClearCache(ctx context.Context) (int64, error)
ClearCache removes expired TLSA records from the cache
func (*DANEService) LookupTLSA ¶
func (s *DANEService) LookupTLSA(ctx context.Context, domainName string, port int) ([]*domain.DANETLSARecord, error)
LookupTLSA performs a DANE TLSA DNS lookup with caching
func (*DANEService) SetResolver ¶
func (s *DANEService) SetResolver(resolver string)
SetResolver sets the DNS resolver address
func (*DANEService) VerifyTLSConnection ¶
func (s *DANEService) VerifyTLSConnection(ctx context.Context, domainName string, port int, tlsState *tls.ConnectionState) (bool, error)
VerifyTLSConnection verifies a TLS connection against DANE TLSA records
type DANEServiceConfig ¶
DANEServiceConfig holds DNS configuration for the DANE service
func DefaultDANEServiceConfig ¶
func DefaultDANEServiceConfig() *DANEServiceConfig
DefaultDANEServiceConfig returns the default DNS configuration
type DKIMKeyResult ¶
type DKIMKeyResult struct {
Selector string `json:"selector"`
PrivateKey string `json:"private_key"`
PublicKey string `json:"public_key"`
DNSRecord string `json:"dns_record"`
DNSName string `json:"dns_name"`
}
DKIMKeyResult contains the generated DKIM keys and DNS record
type DeliveryProcessor ¶
DeliveryProcessor interface defines the contract for queue delivery This is implemented by smtp.DeliveryWorker
type DomainService ¶
type DomainService struct {
// contains filtered or unexported fields
}
DomainService handles domain business logic including default templates
func NewDomainService ¶
func NewDomainService(repos *repository.Repositories, logger *zap.Logger) *DomainService
NewDomainService creates a new domain service
func (*DomainService) CreateDomainFromTemplate ¶
func (s *DomainService) CreateDomainFromTemplate(domainName string) (*domain.Domain, error)
CreateDomainFromTemplate creates a new domain from template with security defaults
func (*DomainService) Delete ¶
func (s *DomainService) Delete(ctx context.Context, id int64) error
Delete deletes a domain
func (*DomainService) EnsureDefaultTemplate ¶
func (s *DomainService) EnsureDefaultTemplate() error
EnsureDefaultTemplate creates default domain template if it doesn't exist
func (*DomainService) GenerateDKIMKeys ¶
func (s *DomainService) GenerateDKIMKeys(ctx context.Context, id int64, keyType string, keySize int) (*DKIMKeyResult, error)
GenerateDKIMKeys generates new DKIM keys for a domain
func (*DomainService) GetAntivirusConfig ¶
func (s *DomainService) GetAntivirusConfig(domainName string) (*domain.AntivirusConfig, error)
GetAntivirusConfig retrieves antivirus configuration for a domain
func (*DomainService) GetDKIMConfig ¶
func (s *DomainService) GetDKIMConfig(domainName string) (*domain.DKIMConfig, error)
GetDKIMConfig retrieves DKIM configuration for a domain
func (*DomainService) GetDefaultTemplate ¶
func (s *DomainService) GetDefaultTemplate() (*domain.Domain, error)
GetDefaultTemplate retrieves the default domain template
func (*DomainService) UpdateDefaultTemplate ¶
func (s *DomainService) UpdateDefaultTemplate(updates *domain.Domain) error
UpdateDefaultTemplate updates the default domain template
type DraftData ¶
type DraftData struct {
To []string
Cc []string
Bcc []string
Subject string
BodyHTML string
BodyText string
InReplyTo string
References string
Attachments []string
}
DraftData represents draft message data
type MTASTSService ¶
type MTASTSService struct {
// contains filtered or unexported fields
}
MTASTSService handles MTA-STS policy fetching, caching, and enforcement
func NewMTASTSService ¶
func NewMTASTSService(db *database.DB, logger *zap.Logger) *MTASTSService
NewMTASTSService creates a new MTA-STS service
func (*MTASTSService) ClearCache ¶
func (s *MTASTSService) ClearCache(ctx context.Context) (int64, error)
ClearCache removes expired MTA-STS policies from the cache
func (*MTASTSService) CreateTLSReport ¶
CreateTLSReport creates a TLS report entry for TLSRPT (RFC 8460)
func (*MTASTSService) EnforcePolicy ¶
func (s *MTASTSService) EnforcePolicy(ctx context.Context, domainName, mxHostname string) (bool, error)
EnforcePolicy checks if an MX hostname is allowed by the MTA-STS policy
func (*MTASTSService) FetchPolicy ¶
func (s *MTASTSService) FetchPolicy(ctx context.Context, domainName string) (*domain.MTASTSPolicy, error)
FetchPolicy fetches and caches an MTA-STS policy for a domain
func (*MTASTSService) GetPendingReports ¶
GetPendingReports retrieves unsent TLS reports
func (*MTASTSService) MarkReportSent ¶
func (s *MTASTSService) MarkReportSent(ctx context.Context, reportID int64) error
MarkReportSent marks a TLS report as sent
type MailboxService ¶
type MailboxService struct {
// contains filtered or unexported fields
}
MailboxService handles mailbox operations
func NewMailboxService ¶
func NewMailboxService(repo repository.MailboxRepository, logger *zap.Logger) *MailboxService
NewMailboxService creates a new mailbox service
func (*MailboxService) Create ¶
func (s *MailboxService) Create(userID int64, name, specialUse string) error
Create creates a new mailbox
func (*MailboxService) CreateDefaultMailboxes ¶
func (s *MailboxService) CreateDefaultMailboxes(userID int64) error
CreateDefaultMailboxes creates default mailboxes for a new user
func (*MailboxService) Delete ¶
func (s *MailboxService) Delete(id int64) error
Delete deletes a mailbox
func (*MailboxService) GetByID ¶
func (s *MailboxService) GetByID(id int64) (*domain.Mailbox, error)
GetByID retrieves a mailbox by ID
func (*MailboxService) ListMailboxesByUserID ¶
func (s *MailboxService) ListMailboxesByUserID(ctx context.Context, userID int) ([]*domain.Mailbox, error)
ListMailboxesByUserID lists all mailboxes for a user (alias for List method)
func (*MailboxService) Rename ¶
func (s *MailboxService) Rename(id int64, newName string) error
Rename renames a mailbox
func (*MailboxService) UpdateSubscription ¶
func (s *MailboxService) UpdateSubscription(id int64, subscribed bool) error
UpdateSubscription updates mailbox subscription status
type MailboxServiceInterface ¶
type MailboxServiceInterface interface {
Create(userID int64, name, specialUse string) error
GetByName(userID int64, name string) (*domain.Mailbox, error)
List(userID int64, subscribedOnly bool) ([]*domain.Mailbox, error)
Delete(mailboxID int64) error
Rename(mailboxID int64, newName string) error
UpdateSubscription(id int64, subscribed bool) error
}
MailboxServiceInterface defines the mailbox service interface
type MessageService ¶
type MessageService struct {
// contains filtered or unexported fields
}
func NewMessageService ¶
func NewMessageService(repo repository.MessageRepository, storagePath string, logger *zap.Logger) *MessageService
NewMessageService creates a new message service
func (*MessageService) Delete ¶
func (s *MessageService) Delete(id int64) error
Delete deletes a message and its file if it exists
func (*MessageService) DeleteDraft ¶
func (s *MessageService) DeleteDraft(ctx context.Context, draftID, userID int) error
DeleteDraft deletes a draft
func (*MessageService) DeleteMessage ¶
func (s *MessageService) DeleteMessage(ctx context.Context, messageID, userID int) error
DeleteMessage moves a message to trash or deletes permanently
func (*MessageService) GetAttachment ¶
func (s *MessageService) GetAttachment(ctx context.Context, attachmentID string, userID int) (*Attachment, error)
GetAttachment retrieves an attachment from a message
func (*MessageService) GetByID ¶
func (s *MessageService) GetByID(id int64) (*domain.Message, error)
GetByID retrieves a message by ID and loads its content
func (*MessageService) GetByMailbox ¶
func (s *MessageService) GetByMailbox(mailboxID int64, offset, limit int) ([]*domain.Message, error)
GetByMailbox retrieves messages for a mailbox
func (*MessageService) GetMessage ¶
func (s *MessageService) GetMessage(ctx context.Context, messageID, userID int) (*domain.Message, error)
GetMessage retrieves a single message by ID with user ownership check
func (*MessageService) ListDrafts ¶
ListDrafts lists all drafts for a user
func (*MessageService) ListMessages ¶
func (s *MessageService) ListMessages(ctx context.Context, mailboxID, userID, limit, offset int) ([]*domain.Message, error)
ListMessages lists messages in a mailbox with pagination
func (*MessageService) MoveMessage ¶
func (s *MessageService) MoveMessage(ctx context.Context, messageID, targetMailboxID, userID int) error
MoveMessage moves a message to a different mailbox
func (*MessageService) SaveDraft ¶
func (s *MessageService) SaveDraft(ctx context.Context, userID int, draftID *int, data *DraftData) (*Draft, error)
SaveDraft saves or updates a draft message
func (*MessageService) SearchMessages ¶
func (s *MessageService) SearchMessages(ctx context.Context, userID int, query string) ([]*domain.Message, error)
SearchMessages searches messages for a user
func (*MessageService) SendMessage ¶
func (s *MessageService) SendMessage(ctx context.Context, userID int, req *SendMessageRequest) (int, error)
SendMessage sends a new message via the queue
func (*MessageService) SetMailboxService ¶
func (s *MessageService) SetMailboxService(mailboxService *MailboxService)
SetMailboxService sets the mailbox service dependency (optional, for drafts/sent)
func (*MessageService) SetQueueService ¶
func (s *MessageService) SetQueueService(queueService *QueueService)
SetQueueService sets the queue service dependency (optional, for sending)
func (*MessageService) SetUserService ¶
func (s *MessageService) SetUserService(userService UserServiceInterface)
SetUserService sets the user service dependency (required for sending)
func (*MessageService) Store ¶
func (s *MessageService) Store(userID, mailboxID, uid int64, messageData []byte) (*domain.Message, error)
Store stores a message with hybrid storage strategy
func (*MessageService) StorePhishingResult ¶
func (s *MessageService) StorePhishingResult(ctx context.Context, messageID int64, result *phishing.PhishingResult) error
StorePhishingResult stores phishing analysis results for audit trail
func (*MessageService) Update ¶
func (s *MessageService) Update(message *domain.Message) error
Update updates an existing message
func (*MessageService) UpdateFlags ¶
func (s *MessageService) UpdateFlags(ctx context.Context, messageID, userID int, flags []string, action string) error
UpdateFlags updates message flags (read, starred, etc)
func (*MessageService) UpdateTaskCompleted ¶
func (s *MessageService) UpdateTaskCompleted(ctx context.Context, messageID int64, completed bool) error
UpdateTaskCompleted handles task completion status updates
type MessageServiceInterface ¶
type MessageServiceInterface interface {
Store(userID, mailboxID, uid int64, messageData []byte) (*domain.Message, error)
GetByID(id int64) (*domain.Message, error)
GetByMailbox(mailboxID int64, offset, limit int) ([]*domain.Message, error)
Delete(id int64) error
Update(message *domain.Message) error
UpdateFlags(ctx context.Context, messageID, userID int, flags []string, action string) error
UpdateTaskCompleted(ctx context.Context, messageID int64, completed bool) error
StorePhishingResult(ctx context.Context, messageID int64, result *phishing.PhishingResult) error
}
MessageServiceInterface defines the message service interface
type PGPService ¶
type PGPService struct {
// contains filtered or unexported fields
}
PGPService handles PGP/GPG key management for email encryption
func NewPGPService ¶
func NewPGPService(db *database.DB, logger *zap.Logger) *PGPService
NewPGPService creates a new PGP service
func (*PGPService) DeleteKey ¶
func (s *PGPService) DeleteKey(ctx context.Context, keyID int64) error
DeleteKey deletes a PGP key
func (*PGPService) GetKeyByFingerprint ¶
func (s *PGPService) GetKeyByFingerprint(ctx context.Context, userID int64, fingerprint string) (*domain.PGPKey, error)
GetKeyByFingerprint retrieves a PGP key by fingerprint
func (*PGPService) GetPrimaryKey ¶
GetPrimaryKey retrieves the primary PGP key for a user
func (*PGPService) GetUserKeys ¶
GetUserKeys retrieves all PGP keys for a user
func (*PGPService) ImportKey ¶
func (s *PGPService) ImportKey(ctx context.Context, userID int64, publicKeyArmored string) (*domain.PGPKey, error)
ImportKey imports a PGP public key for a user
func (*PGPService) SetPrimaryKey ¶
func (s *PGPService) SetPrimaryKey(ctx context.Context, keyID int64) error
SetPrimaryKey sets a key as the primary key for a user
type QuarantineService ¶
type QuarantineService struct {
// contains filtered or unexported fields
}
func NewQuarantineService ¶
func NewQuarantineService(repo repository.QuarantineRepository, logger *zap.Logger) *QuarantineService
func (*QuarantineService) CleanupOld ¶
func (s *QuarantineService) CleanupOld(age time.Duration) error
func (*QuarantineService) Delete ¶
func (s *QuarantineService) Delete(itemID int64) error
func (*QuarantineService) List ¶
func (s *QuarantineService) List(offset, limit int) ([]*domain.QuarantineMessage, error)
func (*QuarantineService) Quarantine ¶
func (s *QuarantineService) Quarantine(messageID, sender, recipient, subject, reason, messagePath string, score float64) error
func (*QuarantineService) Release ¶
func (s *QuarantineService) Release(itemID int64) error
type QueueService ¶
type QueueService struct {
// contains filtered or unexported fields
}
QueueService handles SMTP queue management
func NewQueueService ¶
func NewQueueService(repo repository.QueueRepository, telemetryService *repService.TelemetryService, logger *zap.Logger) *QueueService
NewQueueService creates a new queue service
func NewQueueServiceWithPath ¶
func NewQueueServiceWithPath(repo repository.QueueRepository, telemetryService *repService.TelemetryService, logger *zap.Logger, queuePath string) *QueueService
NewQueueServiceWithPath creates a new queue service with custom queue path (for testing)
func (*QueueService) CalculateNextRetry ¶
CalculateNextRetry calculates next retry time using exponential backoff
func (*QueueService) Count ¶
func (s *QueueService) Count(ctx context.Context) (int64, error)
Count returns total number of queue items
func (*QueueService) CountByStatus ¶
CountByStatus returns total number of queue items with given status
func (*QueueService) DeleteItem ¶
func (s *QueueService) DeleteItem(ctx context.Context, id int64) error
DeleteItem removes a queue item
func (*QueueService) GetPending ¶
func (s *QueueService) GetPending() ([]*domain.QueueItem, error)
GetPending retrieves all pending queue items
func (*QueueService) GetPendingItems ¶
GetPendingItems retrieves all pending queue items (API handler method)
func (*QueueService) IncrementRetry ¶
IncrementRetry increments the retry count and schedules next retry
func (*QueueService) ListByStatus ¶
func (s *QueueService) ListByStatus(ctx context.Context, status string, offset, limit int) ([]*domain.QueueItem, error)
ListByStatus retrieves queue items by status with pagination
func (*QueueService) MarkDelivered ¶
func (s *QueueService) MarkDelivered(id int64) error
MarkDelivered marks a queue item as successfully delivered Note: This should be called by the delivery worker with proper context including recipient domain
func (*QueueService) MarkFailed ¶
func (s *QueueService) MarkFailed(id int64, errorMsg string) error
MarkFailed marks a queue item as permanently failed Note: This should be called by the delivery worker with bounce details
func (*QueueService) ProcessQueue ¶
func (s *QueueService) ProcessQueue() error
ProcessQueue processes pending queue items using the configured delivery processor
func (*QueueService) ProcessQueueWithContext ¶
func (s *QueueService) ProcessQueueWithContext(ctx context.Context) error
ProcessQueueWithContext processes pending queue items with context
func (*QueueService) RecordBounceTelemetry ¶
func (s *QueueService) RecordBounceTelemetry(ctx context.Context, senderDomain, recipientDomain, ip, bounceType, statusCode, response string) error
RecordBounceTelemetry records bounce telemetry This should be called by the delivery worker when delivery fails
func (*QueueService) RecordDeliveryTelemetry ¶
func (s *QueueService) RecordDeliveryTelemetry(ctx context.Context, senderDomain, recipientDomain, ip string) error
RecordDeliveryTelemetry records successful delivery telemetry This should be called by the delivery worker after successful SMTP delivery
type QueueServiceInterface ¶
type QueueServiceInterface interface {
Enqueue(from string, to []string, message []byte) (string, error)
GetPending() ([]*domain.QueueItem, error)
MarkDelivered(id int64) error
MarkFailed(id int64, errorMsg string) error
IncrementRetry(id int64, currentRetryCount int, failedAt time.Time) error
CalculateNextRetry(retryCount int, failedAt time.Time) time.Time
}
QueueServiceInterface defines the queue service interface
type SecuritySettings ¶
type SecuritySettings struct {
JWTSecret string `json:"jwt_secret,omitempty"`
ClamAVEnabled bool `json:"clamav_enabled"`
ClamAVSocketPath string `json:"clamav_socket_path"`
SpamAssassinEnabled bool `json:"spamassassin_enabled"`
SpamAssassinHost string `json:"spamassassin_host"`
SpamAssassinPort int `json:"spamassassin_port"`
RateLimitEnabled bool `json:"rate_limit_enabled"`
RateLimitRequests int `json:"rate_limit_requests"`
RateLimitWindow int `json:"rate_limit_window"`
}
SecuritySettings represents security configuration settings
type SendMessageRequest ¶
type SendMessageRequest struct {
From string
To string
Cc string
Bcc string
Subject string
BodyText string
BodyHTML string
Attachments []string
}
SendMessageRequest represents a request to send a message
type ServerSettings ¶
type ServerSettings struct {
Hostname string `json:"hostname"`
Domain string `json:"domain"`
SMTPSubmissionPort int `json:"smtp_submission_port"`
SMTPRelayPort int `json:"smtp_relay_port"`
SMTPSPort int `json:"smtps_port"`
IMAPPort int `json:"imap_port"`
IMAPSPort int `json:"imaps_port"`
APIPort int `json:"api_port"`
MaxMessageSize int64 `json:"max_message_size"`
}
ServerSettings represents server configuration settings
type SettingsService ¶
type SettingsService struct {
// contains filtered or unexported fields
}
SettingsService handles configuration management operations
func NewSettingsService ¶
NewSettingsService creates a new settings service instance
func (*SettingsService) GetSecuritySettings ¶
func (s *SettingsService) GetSecuritySettings(ctx context.Context) (*SecuritySettings, error)
GetSecuritySettings retrieves current security configuration
func (*SettingsService) GetServerSettings ¶
func (s *SettingsService) GetServerSettings(ctx context.Context) (*ServerSettings, error)
GetServerSettings retrieves current server configuration
func (*SettingsService) GetTLSSettings ¶
func (s *SettingsService) GetTLSSettings(ctx context.Context) (*TLSSettings, error)
GetTLSSettings retrieves current TLS/certificate configuration
func (*SettingsService) UpdateSecuritySettings ¶
func (s *SettingsService) UpdateSecuritySettings(ctx context.Context, settings *SecuritySettings) error
UpdateSecuritySettings updates security configuration
func (*SettingsService) UpdateServerSettings ¶
func (s *SettingsService) UpdateServerSettings(ctx context.Context, settings *ServerSettings) error
UpdateServerSettings updates server configuration
func (*SettingsService) UpdateTLSSettings ¶
func (s *SettingsService) UpdateTLSSettings(ctx context.Context, settings *TLSSettings) error
UpdateTLSSettings updates TLS/certificate configuration
type SetupService ¶
type SetupService struct {
// contains filtered or unexported fields
}
SetupService handles setup wizard operations
func NewSetupService ¶
func NewSetupService( db *database.DB, userRepo repository.UserRepository, domainRepo repository.DomainRepository, logger *zap.Logger, ) *SetupService
NewSetupService creates a new setup service
func (*SetupService) CompleteSetup ¶
func (s *SetupService) CompleteSetup(ctx context.Context) error
CompleteSetup marks the setup wizard as complete
func (*SetupService) CreateAdminUser ¶
func (s *SetupService) CreateAdminUser(ctx context.Context, req *AdminUserRequest) error
CreateAdminUser creates the first admin user and their domain
func (*SetupService) GetSetupState ¶
func (s *SetupService) GetSetupState(ctx context.Context) (*SetupState, error)
GetSetupState retrieves the current setup wizard state
func (*SetupService) IsSetupComplete ¶
func (s *SetupService) IsSetupComplete(ctx context.Context) (bool, error)
IsSetupComplete checks if the setup wizard has been completed
type SetupState ¶
type SetupState struct {
CurrentStep string `json:"current_step"`
CompletedSteps []string `json:"completed_steps"`
SystemConfig *string `json:"system_config,omitempty"`
DomainConfig *string `json:"domain_config,omitempty"`
AdminConfig *string `json:"admin_config,omitempty"`
TLSConfig *string `json:"tls_config,omitempty"`
}
SetupState represents the setup wizard state
type TLSSettings ¶
type TLSSettings struct {
ACMEEnabled bool `json:"acme_enabled"`
ACMEEmail string `json:"acme_email"`
ACMEProvider string `json:"acme_provider"`
ACMEAPIToken string `json:"acme_api_token,omitempty"`
CertFile string `json:"cert_file"`
KeyFile string `json:"key_file"`
}
TLSSettings represents TLS/certificate configuration settings
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService handles user operations
func NewUserService ¶
func NewUserService(repos *repository.Repositories, logger *zap.Logger) *UserService
NewUserService creates a new user service
func (*UserService) Authenticate ¶
func (s *UserService) Authenticate(email, password string) (*domain.User, error)
Authenticate verifies user credentials
func (*UserService) Count ¶
func (s *UserService) Count(ctx context.Context) (int64, error)
Count returns the total number of users
func (*UserService) CountByDomain ¶
CountByDomain returns the total number of users for a domain
func (*UserService) Create ¶
func (s *UserService) Create(user *domain.User, password string) error
Create creates a new user
func (*UserService) CreateWithPassword ¶
func (s *UserService) CreateWithPassword(user *domain.User, password string) error
CreateWithPassword creates a new user with a hashed password (for API handlers)
func (*UserService) Delete ¶
func (s *UserService) Delete(id int64) error
Delete deletes a user (implements UserServiceInterface)
func (*UserService) GetByEmail ¶
func (s *UserService) GetByEmail(email string) (*domain.User, error)
GetByEmail retrieves a user by email (implements UserServiceInterface)
func (*UserService) GetByID ¶
func (s *UserService) GetByID(id int64) (*domain.User, error)
GetByID retrieves a user by ID (implements UserServiceInterface)
func (*UserService) GetDomainByID ¶
GetDomainByID retrieves a domain by ID (helper for user operations that need domain info)
func (*UserService) HashPassword ¶
func (s *UserService) HashPassword(password string) (string, error)
HashPassword hashes a password using bcrypt
func (*UserService) ListAll ¶
func (s *UserService) ListAll() ([]*domain.User, error)
ListAll retrieves all users
func (*UserService) ListPaginated ¶
ListPaginated retrieves users with pagination
func (*UserService) Update ¶
func (s *UserService) Update(user *domain.User) error
Update updates a user (implements UserServiceInterface)
func (*UserService) UpdatePassword ¶
func (s *UserService) UpdatePassword(userID int64, newPassword string) error
UpdatePassword updates a user's password (implements UserServiceInterface)
func (*UserService) VerifyPassword ¶
func (s *UserService) VerifyPassword(hash, password string) bool
VerifyPassword verifies a password against a hash
type UserServiceInterface ¶
type UserServiceInterface interface {
Create(user *domain.User, password string) error
Authenticate(email, password string) (*domain.User, error)
GetByID(id int64) (*domain.User, error)
GetByEmail(email string) (*domain.User, error)
Update(user *domain.User) error
UpdatePassword(userID int64, newPassword string) error
Delete(id int64) error
}
UserServiceInterface defines the user service interface
type WebhookService ¶
type WebhookService struct {
Repo repository.WebhookRepository
// contains filtered or unexported fields
}
WebhookService handles webhook delivery and management
func NewWebhookService ¶
func NewWebhookService(repo repository.WebhookRepository, logger *zap.Logger) *WebhookService
NewWebhookService creates a new webhook service
func (*WebhookService) CleanupOldDeliveries ¶
func (s *WebhookService) CleanupOldDeliveries(ctx context.Context, olderThanDays int) error
CleanupOldDeliveries removes old delivery records
func (*WebhookService) ProcessPendingDeliveries ¶
func (s *WebhookService) ProcessPendingDeliveries(ctx context.Context) error
ProcessPendingDeliveries processes all pending webhook deliveries
func (*WebhookService) TestWebhook ¶
func (s *WebhookService) TestWebhook(ctx context.Context, webhookID int64) error
TestWebhook sends a test payload to a webhook
func (*WebhookService) TriggerEvent ¶
func (s *WebhookService) TriggerEvent(ctx context.Context, event domain.WebhookEvent, data map[string]interface{}) error
TriggerEvent sends an event to all registered webhooks