imap/client/export_messages.go
H0llyW00dzZ 4c74ebc1c7 Improve [Imap] [Client] Error Handling (#16)
- [+] feat(config.go): add error variables for client connection and body reading failures
- [+] refactor(export_messages.go, list_mailboxes.go, list_messages.go): replace error messages with new error variables

Reviewed-on: #16
Co-authored-by: H0llyW00dzZ <h0llyw00dzz@pm.me>
Co-committed-by: H0llyW00dzZ <h0llyw00dzz@pm.me>
2025-01-25 06:40:23 +00:00

30 lines
872 B
Go

// 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)
}