Documentation
¶
Index ¶
- func BuildPaginationResponse(threads []*models.Thread, totalCount, page, limit int) *models.ThreadsResponse
- func GetPaginationLimit(ctx context.Context, pool *pgxpool.Pool, userID string, limitFromQuery int) int
- func GetUserIDFromContext(ctx context.Context, w http.ResponseWriter, pool *pgxpool.Pool) (string, bool)
- func ParsePaginationParams(r *http.Request, defaultLimit int) (page, limit int)
- func VerifyAuthCheck(t *testing.T, handlerFunc http.HandlerFunc, method, url string)
- func WriteJSONResponse(w http.ResponseWriter, data interface{}) bool
- type AttachmentHandler
- type AuthHandler
- type FailingResponseWriter
- type FoldersHandler
- type SearchHandler
- type SettingsHandler
- type TestHandler
- type ThreadHandler
- type ThreadsHandler
- type WebSocketHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildPaginationResponse ¶
func BuildPaginationResponse(threads []*models.Thread, totalCount, page, limit int) *models.ThreadsResponse
BuildPaginationResponse builds the pagination response structure. This is a shared helper function used by multiple handlers for consistent response formatting.
func GetPaginationLimit ¶
func GetPaginationLimit(ctx context.Context, pool *pgxpool.Pool, userID string, limitFromQuery int) int
GetPaginationLimit gets the pagination limit, using user settings if available. If limitFromQuery is provided (> 0), it takes precedence. Otherwise, it uses the user's setting from the database, or defaults to 100. This is a shared helper function used by multiple handlers for consistent pagination limit handling.
func GetUserIDFromContext ¶
func GetUserIDFromContext(ctx context.Context, w http.ResponseWriter, pool *pgxpool.Pool) (string, bool)
GetUserIDFromContext extracts the user's email from context, resolves/creates the DB user, and writes appropriate HTTP errors when it fails. Returns (userID, true) on success. This is a shared helper function used across multiple handlers to ensure consistent error handling for user authentication and user ID resolution.
func ParsePaginationParams ¶
ParsePaginationParams parses page and limit from query parameters. Returns default values (page=1, limit=defaultLimit) if parameters are missing or invalid. This is a shared helper function used by multiple handlers for consistent pagination parsing.
func VerifyAuthCheck ¶
func VerifyAuthCheck(t *testing.T, handlerFunc http.HandlerFunc, method, url string)
VerifyAuthCheck verifies that the handler returns 401 Unauthorized when no user is in context.
func WriteJSONResponse ¶
func WriteJSONResponse(w http.ResponseWriter, data interface{}) bool
WriteJSONResponse writes a JSON response using a buffered approach to prevent partial writes. If encoding fails, it writes an error response and returns false. Otherwise returns true. This ensures atomic responses and consistent error handling across all handlers.
Types ¶
type AttachmentHandler ¶
type AttachmentHandler struct {
// contains filtered or unexported fields
}
AttachmentHandler handles attachment download requests.
func NewAttachmentHandler ¶
func NewAttachmentHandler(pool *pgxpool.Pool, imapService imap.IMAPService) *AttachmentHandler
NewAttachmentHandler creates a new AttachmentHandler instance.
func (*AttachmentHandler) GetAttachment ¶
func (h *AttachmentHandler) GetAttachment(w http.ResponseWriter, r *http.Request)
GetAttachment serves an attachment by fetching it from IMAP. Path: /api/v1/messages/{messageId}/attachments/{attachmentId} The attachmentId is URL-encoded and can be either a content_id or filename.
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler handles authentication-related API requests.
func NewAuthHandler ¶
func NewAuthHandler(pool *pgxpool.Pool) *AuthHandler
NewAuthHandler creates a new AuthHandler instance.
func (*AuthHandler) GetAuthStatus ¶
func (h *AuthHandler) GetAuthStatus(w http.ResponseWriter, r *http.Request)
GetAuthStatus returns the authentication and setup status for the current user.
type FailingResponseWriter ¶
type FailingResponseWriter struct {
http.ResponseWriter
WriteShouldFail bool
}
FailingResponseWriter is a ResponseWriter that fails on Write to test error handling.
type FoldersHandler ¶
type FoldersHandler struct {
// contains filtered or unexported fields
}
FoldersHandler handles IMAP folder-related API requests.
func NewFoldersHandler ¶
func NewFoldersHandler(pool *pgxpool.Pool, encryptor *crypto.Encryptor, imapPool imap.IMAPPool) *FoldersHandler
NewFoldersHandler creates a new FoldersHandler instance.
func (*FoldersHandler) GetFolders ¶
func (h *FoldersHandler) GetFolders(w http.ResponseWriter, r *http.Request)
GetFolders returns the list of IMAP folders for the current user.
type SearchHandler ¶
type SearchHandler struct {
// contains filtered or unexported fields
}
SearchHandler handles search-related API requests.
func NewSearchHandler ¶
func NewSearchHandler(pool *pgxpool.Pool, encryptor *crypto.Encryptor, imapService imap.IMAPService) *SearchHandler
NewSearchHandler creates a new SearchHandler instance.
func (*SearchHandler) Search ¶
func (h *SearchHandler) Search(w http.ResponseWriter, r *http.Request)
Search handles search requests.
type SettingsHandler ¶
type SettingsHandler struct {
// contains filtered or unexported fields
}
SettingsHandler handles user settings-related API requests.
func NewSettingsHandler ¶
func NewSettingsHandler(pool *pgxpool.Pool, encryptor *crypto.Encryptor) *SettingsHandler
NewSettingsHandler creates a new SettingsHandler instance.
func (*SettingsHandler) GetSettings ¶
func (h *SettingsHandler) GetSettings(w http.ResponseWriter, r *http.Request)
GetSettings returns the user settings for the current user.
func (*SettingsHandler) PostSettings ¶
func (h *SettingsHandler) PostSettings(w http.ResponseWriter, r *http.Request)
PostSettings saves or updates the user settings for the current user.
type TestHandler ¶
type TestHandler struct {
// contains filtered or unexported fields
}
TestHandler provides test-only endpoints used by E2E tests. These endpoints are only registered in test environments.
func NewTestHandler ¶
func NewTestHandler(pool *pgxpool.Pool, encryptor *crypto.Encryptor, imapService imapinternal.IMAPService, hub *ws.Hub) *TestHandler
NewTestHandler creates a new TestHandler instance.
func (*TestHandler) AddIMAPMessage ¶
func (h *TestHandler) AddIMAPMessage(w http.ResponseWriter, r *http.Request)
AddIMAPMessage appends a test message to the user's IMAP folder. It is used by E2E tests to simulate new incoming mail.
type ThreadHandler ¶
type ThreadHandler struct {
// contains filtered or unexported fields
}
ThreadHandler handles individual thread-related API requests.
func NewThreadHandler ¶
func NewThreadHandler(pool *pgxpool.Pool, encryptor *crypto.Encryptor, imapService imap.IMAPService) *ThreadHandler
NewThreadHandler creates a new ThreadHandler instance.
func (*ThreadHandler) GetThread ¶
func (h *ThreadHandler) GetThread(w http.ResponseWriter, r *http.Request)
GetThread returns a single email thread with all its messages.
type ThreadsHandler ¶
type ThreadsHandler struct {
// contains filtered or unexported fields
}
ThreadsHandler handles thread-list-related API requests.
func NewThreadsHandler ¶
func NewThreadsHandler(pool *pgxpool.Pool, encryptor *crypto.Encryptor, imapService imap.IMAPService) *ThreadsHandler
NewThreadsHandler creates a new ThreadsHandler instance.
func (*ThreadsHandler) GetThreads ¶
func (h *ThreadsHandler) GetThreads(w http.ResponseWriter, r *http.Request)
GetThreads returns a paginated list of email threads for a folder.
type WebSocketHandler ¶
type WebSocketHandler struct {
// contains filtered or unexported fields
}
WebSocketHandler handles the /api/v1/ws endpoint for real-time updates.
func NewWebSocketHandler ¶
func NewWebSocketHandler(pool *pgxpool.Pool, imapService imap.IMAPService, hub *ws.Hub) *WebSocketHandler
NewWebSocketHandler creates a new WebSocketHandler instance.
func (*WebSocketHandler) Handle ¶
func (h *WebSocketHandler) Handle(w http.ResponseWriter, r *http.Request)
Handle upgrades the HTTP connection to a WebSocket and registers it with the Hub. Authentication depends on VMAIL_AUTH_MODE:
- "header": Uses Remote-Email/Remote-User headers from reverse proxy (Caddy handles auth on upgrade).
- "dev": Uses token from query parameter (?token=...) or Authorization header.