From 3d17ce82ff2b45fe0404684839e9bb067a999641 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 24 Jan 2025 07:13:02 +0000 Subject: [PATCH] Update Package Documentation (#5) - [+] feat(docs): update client documentation to include message export functionality and usage examples - [+] feat(docs): add export package documentation with JSON export example - [+] chore(docs.go): add copyright notice and license agreement information Reviewed-on: https://git.b0zal.io/H0llyW00dzZ/imap/pulls/5 Co-authored-by: H0llyW00dzZ Co-committed-by: H0llyW00dzZ --- client/docs.go | 55 ++++++++++++++++++++++++++++++++++++++++--- export/docs.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 export/docs.go diff --git a/client/docs.go b/client/docs.go index 894f784..3646412 100644 --- a/client/docs.go +++ b/client/docs.go @@ -5,11 +5,12 @@ // Package client provides a simple interface to manage IMAP connections // for single or multiple users. It allows you to connect to an IMAP server, -// list messages, and manage multiple user accounts. +// list messages, export messages, and manage multiple user accounts. // // # Features // - Connect and disconnect from an IMAP server // - List messages in a specified mailbox +// - Export messages to various formats // - Manage multiple users with separate IMAP clients // // # Usage @@ -54,7 +55,7 @@ // } // // for _, msg := range messages { -// fmt.Printf("ID: %s, From: %v, Subject: %s, Body: %s\n", msg.ID, msg.From, msg.Subject, msg.Body) +// fmt.Printf("ID: %s, From: %v, Subject: %s, Body: %s\n", msg[client.KeyID], msg[client.KeyFrom], msg[client.KeySubject], msg[client.KeyBody]) // } // } // @@ -94,7 +95,55 @@ // } // // for _, msg := range messages { -// fmt.Printf("ID: %s, From: %v, Subject: %s, Body: %s\n", msg.ID, msg.From, msg.Subject, msg.Body) +// fmt.Printf("ID: %s, From: %v, Subject: %s, Body: %s\n", msg[client.KeyID], msg[client.KeyFrom], msg[client.KeySubject], msg[client.KeyBody]) +// } +// } +// +// Export Messages 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) // } // } package client diff --git a/export/docs.go b/export/docs.go new file mode 100644 index 0000000..22fa3c3 --- /dev/null +++ b/export/docs.go @@ -0,0 +1,64 @@ +// 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 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) +// } +// } +package export