export

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package export provides functionality to export email messages in various formats. It defines interfaces and implementations for exporting messages, allowing flexibility in how messages are written to different outputs.

Features

  • Define a standard interface for exporting messages
  • Implement JSON export functionality with customizable encoding

Usage

JSON Export Example:

package main

import (
    "log"
    "os"

    "git.b0zal.io/H0llyW00dzZ/imap/client"
    "git.b0zal.io/H0llyW00dzZ/imap/export"
)

func main() {
    config := &client.Config{
        Username:           "user@example.com",
        Password:           "password",
        Server:             "imap.example.com:993",
        InsecureSkipVerify: true,
    }

    imapClient := client.NewIMAP(config)

    err := imapClient.Connect()
    if err != nil {
        log.Fatalf("Failed to connect: %v", err)
    }
    defer imapClient.Disconnect()

    messageConfig := client.MessageConfig{
        GrabID:      true,
        GrabFrom:    true,
        GrabSubject: true,
        GrabBody:    true,
    }

    file, err := os.Create("messages.json")
    if err != nil {
        log.Fatalf("Failed to create file: %v", err)
    }
    defer file.Close()

    exporter := &export.JSONExporter{Encoder: export.DefaultJSONEncoder}
    err = imapClient.ExportMessagesTo(file, exporter, "INBOX", 10, messageConfig)
    if err != nil {
        log.Fatalf("Failed to export messages: %v", err)
    }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultJSONEncoder

func DefaultJSONEncoder(v any, writer io.Writer) error

DefaultJSONEncoder is the default JSON encoding function using the standard library

Types

type Exporter

type Exporter interface {
	Export(messages []map[string]any, writer io.Writer) error
}

Exporter defines an interface for exporting messages

type JSONEncoderFunc

type JSONEncoderFunc func(v any, writer io.Writer) error

JSONEncoderFunc defines a function type for custom JSON encoding

type JSONExporter

type JSONExporter struct {
	Encoder JSONEncoderFunc
}

JSONExporter implements the Exporter interface for JSON with a custom encoder

func (*JSONExporter) Export

func (e *JSONExporter) Export(messages []map[string]any, writer io.Writer) error

Export writes messages to the writer as a JSON array using the custom JSON encoder

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL