Files
LambdaMail/services/protocols/internal/infrastructure/postgres/message_query_repository.go
T
Lucas Rayan 67bbe7a50a refactor(mail): IMAP and the webmail read folders and messages through one MailStore
The folder list and the message list were two queries over the same tables. IMAP
took a folder's message count from a cached column and the webmail counted rows,
so the two could disagree. Both now ask MailStore, which counts the messages.
2026-10-16 13:22:05 -03:00

34 lines
908 B
Go

package postgres
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
"lambdamail/protocols/internal/application/port"
)
// MessageQueryRepository lists a folder's messages for IMAP FETCH, through the
// same MailStore listing the webmail uses.
type MessageQueryRepository struct {
store *MailStore
}
func NewMessageQueryRepository(pool *pgxpool.Pool) *MessageQueryRepository {
return &MessageQueryRepository{store: NewMailStore(pool)}
}
func (r *MessageQueryRepository) ListMessages(ctx context.Context, folderID string) ([]port.MessageRecord, error) {
messages, err := r.store.Messages(ctx, folderID, MessageQuery{})
if err != nil {
return nil, err
}
var out []port.MessageRecord
for _, m := range messages {
out = append(out, port.MessageRecord{
UID: m.UID, BlobID: m.BlobID, SizeBytes: m.Size, ReceivedAt: m.ReceivedAt, Flags: m.Flags, ModSeq: m.ModSeq,
})
}
return out, nil
}