ultisuite-backend/internal/api/mail/service_iface.go
R3D347HR4Y 65fc9e517a Implement outbox management features with scheduling and attachment support
- Added new API endpoints for sending, rescheduling, and canceling scheduled outbox messages.
- Implemented outbox processing logic to handle attachments and manage message statuses.
- Introduced a dead-letter strategy for failed outbox messages, enhancing reliability.
- Updated database schema to support new outbox statuses and dead-letter entries.
- Enhanced unit tests for outbox functionalities, ensuring robust error handling and validation.
- Improved attachment handling in the outbox processor to support inline and regular attachments.
2026-05-22 17:46:30 +02:00

64 lines
4.9 KiB
Go

package mail
import (
"context"
"io"
"time"
"github.com/ultisuite/ulti-backend/internal/api/query"
)
// ServiceAPI is the mail handler service boundary. *Service implements it in production.
type ServiceAPI interface {
ResolveUserID(ctx context.Context, externalID string) (string, error)
ListAccounts(ctx context.Context, externalID string, params query.ListParams) (AccountsList, error)
CreateAccount(ctx context.Context, externalID string, req *createAccountRequest) (string, error)
GetAccount(ctx context.Context, externalID, accountID string) (map[string]any, error)
DeleteAccount(ctx context.Context, externalID, accountID string) error
ListMessages(ctx context.Context, externalID string, filter MessageListFilter, params query.ListParams) (MessagesList, error)
GetMessage(ctx context.Context, externalID, messageID string) (map[string]any, error)
UpdateLabels(ctx context.Context, externalID, messageID string, labels []string) error
UpdateFlags(ctx context.Context, externalID, messageID string, flags []string) error
DeleteMessage(ctx context.Context, externalID, messageID string) error
GetThread(ctx context.Context, externalID, threadID string) (map[string]any, error)
SendMessage(ctx context.Context, userID string, req *sendMessageRequest) (id, status string, err error)
SendOutboxNow(ctx context.Context, userID, outboxID string) (status string, err error)
RescheduleOutbox(ctx context.Context, userID, outboxID string, scheduledAt time.Time) (status string, err error)
CancelScheduledOutbox(ctx context.Context, userID, outboxID string) (status string, err error)
ListDrafts(ctx context.Context, externalID string, params query.ListParams) (DraftsList, error)
GetDraft(ctx context.Context, externalID, draftID string) (map[string]any, error)
CreateDraft(ctx context.Context, userID string, req *draftRequest) (string, error)
UpdateDraft(ctx context.Context, externalID, draftID string, req *draftRequest) error
DeleteDraft(ctx context.Context, externalID, draftID string) error
ListRules(ctx context.Context, externalID string, params query.ListParams) (RulesList, error)
CreateRule(ctx context.Context, userID string, req *createRuleRequest) (string, error)
UpdateRule(ctx context.Context, externalID, ruleID string, req *updateRuleRequest) error
DeleteRule(ctx context.Context, externalID, ruleID string) error
ListWebhooks(ctx context.Context, externalID string, params query.ListParams) (WebhooksList, error)
CreateWebhook(ctx context.Context, externalID string, req *createWebhookRequest, method string) (string, error)
DeleteWebhook(ctx context.Context, externalID, webhookID string) error
ListIdentities(ctx context.Context, externalID, accountID string, params query.ListParams) (IdentitiesList, error)
GetIdentity(ctx context.Context, externalID, identityID string) (map[string]any, error)
CreateIdentity(ctx context.Context, externalID, accountID string, req *createIdentityRequest) (string, error)
UpdateIdentity(ctx context.Context, externalID, identityID string, req *updateIdentityRequest) error
DeleteIdentity(ctx context.Context, externalID, identityID string) error
ListFolders(ctx context.Context, externalID, accountID string, params query.ListParams) (FoldersList, error)
GetFolder(ctx context.Context, externalID, folderID string) (map[string]any, error)
CreateFolder(ctx context.Context, userID string, req *createFolderRequest) (string, error)
UpdateFolder(ctx context.Context, externalID, folderID string, req *updateFolderRequest) error
DeleteFolder(ctx context.Context, externalID, folderID string) error
ListUserLabels(ctx context.Context, externalID string, params query.ListParams) (UserLabelsList, error)
CreateUserLabel(ctx context.Context, externalID string, req *createUserLabelRequest) (string, error)
UpdateUserLabel(ctx context.Context, externalID, labelID string, req *updateUserLabelRequest) error
DeleteUserLabel(ctx context.Context, externalID, labelID string) error
SearchMessages(ctx context.Context, externalID string, filter MessageSearchFilter, params query.ListParams) (MessageSearchResult, error)
ListMessageAttachments(ctx context.Context, externalID, messageID string) ([]map[string]any, error)
MessageAttachmentCIDMap(ctx context.Context, externalID, messageID string) (map[string]string, error)
UploadMessageAttachment(ctx context.Context, externalID, messageID, filename, contentType, contentID string, isInline bool, reader io.Reader, size int64) (string, error)
OpenAttachment(ctx context.Context, externalID, attachmentID string) (filename, contentType string, size int64, isInline bool, body io.ReadCloser, err error)
UploadDraftAttachment(ctx context.Context, externalID, draftID, filename, contentType, contentID string, isInline bool, reader io.Reader, size int64) (string, error)
OpenDraftAttachment(ctx context.Context, externalID, draftID, attachmentID string) (filename, contentType string, body io.ReadCloser, err error)
}
var _ ServiceAPI = (*Service)(nil)