imap/client/export_messages.go

30 lines
872 B
Go
Raw Normal View History

// Copyright (c) 2025 H0llyW00dzZ All rights reserved.
//
// By accessing or using this software, you agree to be bound by the terms
// of the License Agreement, which you can find at LICENSE files.
package client
import (
"fmt"
"io"
"git.b0zal.io/H0llyW00dzZ/imap/export"
)
// ExportMessagesTo uses the provided exporter to write messages to the writer
func (c *IMAPClient) ExportMessagesTo(writer io.Writer, exporter export.Exporter, mailbox string, numMessages uint32, config MessageConfig) error {
if c.client == nil {
return ErrorsClientIsNotConnected
}
// Fetch messages based on the provided MessageConfig and number of messages
messages, err := c.ListMessages(mailbox, numMessages, config)
if err != nil {
return fmt.Errorf("failed to list messages: %v", err)
}
// Use the exporter to write messages
return exporter.Export(messages, writer)
}