compress

package module
v0.0.0-...-14809af Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: MIT Imports: 7 Imported by: 2

README

go-imap-compress

GoDoc

The IMAP COMPRESS Extension for go-imap

Usage

package main

import (
		"log"

		"github.com/emersion/go-imap/client"
		"github.com/emersion/go-imap-compress"
)

func main() {
	log.Println("Connecting to server...")

	// Connect to server
	c, err := client.DialTLS("mail.example.org:993", nil)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Connected")

	// Don't forget to logout
	defer c.Logout()

	// Login
	if err := c.Login("username", "password"); err != nil {
		log.Fatal(err)
	}

	// Enable compression if possible
	comp := compress.NewClient(c)
	if ok, err := comp.SupportCompress(compress.Deflate); err != nil {
		log.Fatal(err)
	} else if ok {
		if err := comp.Compress(compress.Deflate); err != nil {
			log.Fatal(err)
		} else {
			log.Printf("Compression enabled: %t", comp.IsCompress())
		}
	}

	// Continue using c with compression enabled
}

License

MIT

Documentation

Overview

The IMAP COMPRESS Extension, as defined in RFC 4978.

Index

Constants

View Source
const Capability = "COMPRESS"

The COMPRESS capability.

View Source
const Deflate = "DEFLATE"

The DEFLATE algorithm, defined in RFC 1951.

Variables

View Source
var ErrAlreadyEnabled = errors.New("COMPRESS is already enabled")

ErrAlreadyEnabled is returned by Client.Compress when compression has already been enabled on the client.

Functions

func NewExtension

func NewExtension() server.Extension

NewExtension creates a new COMPRESS server extension.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a COMPRESS client.

func NewClient

func NewClient(c *client.Client) *Client

NewClient creates a new client.

func (*Client) Compress

func (c *Client) Compress(mech string) error

Compress instructs the server to use the named compression mechanism for all commands and/or responses.

func (*Client) IsCompress

func (c *Client) IsCompress() bool

IsCompressed checks if this client's connection is compressed.

func (*Client) SupportCompress

func (c *Client) SupportCompress(mech string) (bool, error)

SupportCompress checks if the server supports a compression mechanism.

type Command

type Command struct {
	// Name of the compression mechanism.
	Mechanism string
}

A COMPRESS command.

func (*Command) Command

func (cmd *Command) Command() *imap.Command

func (*Command) Parse

func (cmd *Command) Parse(fields []interface{}) (err error)

type Handler

type Handler struct {
	Command
}

func (*Handler) Handle

func (h *Handler) Handle(conn server.Conn) error

func (*Handler) Upgrade

func (h *Handler) Upgrade(conn server.Conn) error

type NotSupportedError

type NotSupportedError struct {
	Mechanism string
}

A NotSupportedError is returned by Client.Compress when the provided compression mechanism is not supported.

func (NotSupportedError) Error

func (err NotSupportedError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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