service

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const DefaultTemplateDomainName = "_default"

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrUserDisabled       = errors.New("user disabled")
	ErrUserNotFound       = errors.New("user not found")
)

Functions

func GetDestinations

func GetDestinations(destinationsJSON string) ([]string, error)

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

func SetDestinations(destinations []string) (string, error)

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

func (s *AliasService) CountByDomain(ctx context.Context, domainID int64) (int64, error)

CountByDomain returns the total number of aliases for a domain

func (*AliasService) Create

func (s *AliasService) Create(ctx context.Context, alias *domain.Alias) error

Create creates a new alias

func (*AliasService) Delete

func (s *AliasService) Delete(ctx context.Context, id int64) error

Delete deletes an alias

func (*AliasService) GetByEmail

func (s *AliasService) GetByEmail(ctx context.Context, email string) (*domain.Alias, error)

GetByEmail retrieves an alias by email address

func (*AliasService) GetByID

func (s *AliasService) GetByID(ctx context.Context, id int64) (*domain.Alias, error)

GetByID retrieves an alias by ID

func (*AliasService) List

func (s *AliasService) List(ctx context.Context, offset, limit int) ([]*domain.Alias, error)

List retrieves aliases with pagination

func (*AliasService) ListAll

func (s *AliasService) ListAll(ctx context.Context) ([]*domain.Alias, error)

ListAll retrieves all aliases

func (*AliasService) ListByDomain

func (s *AliasService) ListByDomain(ctx context.Context, domainID int64) ([]*domain.Alias, error)

ListByDomain retrieves all aliases for a domain

func (*AliasService) Update

func (s *AliasService) Update(ctx context.Context, alias *domain.Alias) error

Update updates an alias

type Attachment

type Attachment struct {
	Filename    string
	ContentType string
	Data        []byte
}

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

func (s *AuditService) DeleteOldLogs(ctx context.Context, retentionDays int) (int64, error)

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) Log

func (s *AuditService) Log(ctx context.Context, log *domain.AuditLog) error

Log creates an audit log entry

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

type DANEServiceConfig struct {
	Resolver        string
	FallbackServers []string
	Timeout         int
	UseTCP          bool
}

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

type DeliveryProcessor interface {
	ProcessQueue(ctx context.Context) error
}

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) Create

func (s *DomainService) Create(ctx context.Context, domain *domain.Domain) error

Create creates a new domain

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) GetByID

func (s *DomainService) GetByID(ctx context.Context, id int64) (*domain.Domain, error)

GetByID retrieves a domain by ID

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) List

func (s *DomainService) List(ctx context.Context, offset, limit int) ([]*domain.Domain, error)

List retrieves all domains

func (*DomainService) Update

func (s *DomainService) Update(ctx context.Context, domain *domain.Domain) error

Update updates an existing domain

func (*DomainService) UpdateDefaultTemplate

func (s *DomainService) UpdateDefaultTemplate(updates *domain.Domain) error

UpdateDefaultTemplate updates the default domain template

type Draft

type Draft struct {
	ID        int
	UserID    int
	Data      *DraftData
	UpdatedAt string
}

Draft represents a draft message

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

func (s *MTASTSService) CreateTLSReport(ctx context.Context, report *domain.TLSReport) error

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

func (s *MTASTSService) GetPendingReports(ctx context.Context) ([]*domain.TLSReport, error)

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) GetByName

func (s *MailboxService) GetByName(userID int64, name string) (*domain.Mailbox, error)

GetByName retrieves a mailbox by name

func (*MailboxService) List

func (s *MailboxService) List(userID int64, subscribed bool) ([]*domain.Mailbox, error)

List lists mailboxes for a user

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) GetDraft

func (s *MessageService) GetDraft(ctx context.Context, draftID, userID int) (*Draft, error)

GetDraft retrieves a specific draft

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

func (s *MessageService) ListDrafts(ctx context.Context, userID int) ([]*Draft, error)

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) GetKey

func (s *PGPService) GetKey(ctx context.Context, keyID int64) (*domain.PGPKey, error)

GetKey retrieves a PGP key by ID

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

func (s *PGPService) GetPrimaryKey(ctx context.Context, userID int64) (*domain.PGPKey, error)

GetPrimaryKey retrieves the primary PGP key for a user

func (*PGPService) GetUserKeys

func (s *PGPService) GetUserKeys(ctx context.Context, userID int64) ([]*domain.PGPKey, error)

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

func (s *QueueService) CalculateNextRetry(retryCount int, failedAt time.Time) time.Time

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

func (s *QueueService) CountByStatus(ctx context.Context, status string) (int64, error)

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) Enqueue

func (s *QueueService) Enqueue(from string, to []string, message []byte) (string, error)

Enqueue adds a message to the delivery queue

func (*QueueService) GetByID

func (s *QueueService) GetByID(ctx context.Context, id int64) (*domain.QueueItem, error)

GetByID retrieves a specific queue item by ID

func (*QueueService) GetPending

func (s *QueueService) GetPending() ([]*domain.QueueItem, error)

GetPending retrieves all pending queue items

func (*QueueService) GetPendingItems

func (s *QueueService) GetPendingItems(ctx context.Context) ([]*domain.QueueItem, error)

GetPendingItems retrieves all pending queue items (API handler method)

func (*QueueService) IncrementRetry

func (s *QueueService) IncrementRetry(id int64, currentRetryCount int, failedAt time.Time) error

IncrementRetry increments the retry count and schedules next retry

func (*QueueService) List

func (s *QueueService) List(ctx context.Context, offset, limit int) ([]*domain.QueueItem, error)

List retrieves queue items with pagination

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

func (*QueueService) RetryItem

func (s *QueueService) RetryItem(ctx context.Context, id int64) error

RetryItem resets a queue item for retry

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

func NewSettingsService(cfg *config.Config, configPath string, logger *zap.Logger) *SettingsService

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

func (s *UserService) CountByDomain(ctx context.Context, domainID int64) (int64, error)

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

func (s *UserService) GetDomainByID(ctx context.Context, domainID int64) (*domain.Domain, error)

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

func (s *UserService) ListPaginated(ctx context.Context, offset, limit int) ([]*domain.User, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL