imap/README.md
H0llyW00dzZ 464fdc1bbd
First Commit
- [+] feat: add initial implementation of IMAP client package with support for single and multiple user management
- [+] chore: add .gitignore file to exclude binaries, IDE files, and environment configurations
- [+] docs: add README file with project description, features, installation, usage examples, and license information
- [+] docs: add BSD 3-Clause License file
- [+] feat(client): implement configuration and connection handling for IMAP clients
- [+] feat(client): implement message listing functionality for single and multiple users
- [+] feat(client): add support for secure TLS connections in IMAP client
- [+] feat(client): create helper functions for initializing single and multi-user IMAP clients
- [+] chore: initialize Go module and add dependencies for IMAP and byte buffer pooling
2025-01-24 11:26:48 +07:00

2.7 KiB

IMAP Client Package

This package 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.

Features

  • Connect and disconnect from an IMAP server
  • List messages in a specified mailbox
  • Manage multiple users with separate IMAP clients

Installation

To install the package, use go get:

go get git.b0zal.io/H0llyW00dzZ/imap

Usage

Single User

package main

import (
	"fmt"
	"log"

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

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,
	}

	messages, err := imapClient.ListMessages("INBOX", 10, messageConfig)
	if err != nil {
		log.Fatalf("Failed to list messages: %v", err)
	}

	for _, msg := range messages {
		fmt.Printf("ID: %s, From: %v, Subject: %s, Body: %s\n", msg.ID, msg.From, msg.Subject, msg.Body)
	}
}

Multiple Users

package main

import (
	"fmt"
	"log"

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

func main() {
	multiUserIMAP := client.NewMultiUserIMAP()

	multiUserIMAP.AddUser("user1@example.com", "password1", "imap.example.com:993", true)
	multiUserIMAP.AddUser("user2@example.com", "password2", "imap.example.com:993", true)

	err := multiUserIMAP.ConnectUser("user1@example.com")
	if err != nil {
		log.Fatalf("Failed to connect user1: %v", err)
	}
	defer multiUserIMAP.DisconnectUser("user1@example.com")

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

	messages, err := multiUserIMAP.ListUserMessages("user1@example.com", "INBOX", 10, messageConfig)
	if err != nil {
		log.Fatalf("Failed to list messages for user1: %v", err)
	}

	for _, msg := range messages {
		fmt.Printf("ID: %s, From: %v, Subject: %s, Body: %s\n", msg.ID, msg.From, msg.Subject, msg.Body)
	}
}

TODO

  • Implement functionality to send emails.
  • Add support for folder management (create, delete, rename).
  • Enhance error handling and logging.
  • Support for message search and filtering.
  • Implement message deletion and flagging.
  • Add more tests for edge cases and concurrent access.

License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.