2025-01-24 07:08:59 +00:00
|
|
|
// 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 {
|
2025-01-25 06:40:23 +00:00
|
|
|
return ErrorsClientIsNotConnected
|
2025-01-24 07:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|