quota

package module
v0.0.0-...-6190748 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 7 Imported by: 3

README

go-imap-quota

GoDoc

QUOTA extension for go-imap

Usage

package main

import (
	"log"

	"github.com/emersion/go-imap-quota"
)

func main() {
	// Connect to IMAP server

	// Create a quota client
	qc := quota.NewClient(c)

	// Check for server support
	if !qc.SupportsQuota() {
		log.Fatal("Client doesn't support QUOTA extension")
	}

	// Retrieve quotas for INBOX
	quotas, err := qc.GetQuotaRoot("INBOX")
	if err != nil {
		log.Fatal(err)
	}

	// Print quotas
	log.Println("Quotas for INBOX:")
	for _, quota := range quotas {
		log.Printf("* %q, resources:\n", quota.Name)
		for name, usage := range quota.Resources {
			log.Printf("  * %v: %v/%v used\n", name, usage[0], usage[1])
		}
	}
}

License

MIT

Documentation

Overview

Implements the IMAP QUOTA extension, as defined in RFC 2087.

Index

Constants

View Source
const (
	// Sum of messages' RFC822.SIZE, in units of 1024 octets
	ResourceStorage = "STORAGE"
	// Number of messages
	ResourceMessage = "MESSAGE"
)

Resources defined in RFC 2087 section 3.

View Source
const Capability = "QUOTA"

The QUOTA capability name.

Variables

View Source
var (
	ErrUnsupportedBackend = errors.New("quota: backend not supported")
)

Functions

func NewExtension

func NewExtension() server.Extension

Types

type Client

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

Client is a QUOTA client.

func NewClient

func NewClient(c *client.Client) *Client

NewClient creates a new client.

func (*Client) GetQuota

func (c *Client) GetQuota(root string) (*Status, error)

GetQuota returns a quota root's resource usage and limits.

func (*Client) GetQuotaRoot

func (c *Client) GetQuotaRoot(mailbox string) ([]*Status, error)

GetQuotaRoot returns the list of quota roots for a mailbox.

func (*Client) SetQuota

func (c *Client) SetQuota(root string, resources map[string]uint32) error

SetQuota changes the resource limits for the specified quota root. Any previous resource limits for the named quota root are discarded.

func (*Client) SupportQuota

func (c *Client) SupportQuota() (bool, error)

SupportQuota checks if the server supports the QUOTA extension.

type GetCommand

type GetCommand struct {
	Root string
}

The GETQUOTA command. See RFC 2087 section 4.2.

func (*GetCommand) Command

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

func (*GetCommand) Parse

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

type GetHandler

type GetHandler struct {
	GetCommand
}

func (*GetHandler) Handle

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

type GetRootCommand

type GetRootCommand struct {
	Mailbox string
}

The GETQUOTAROOT command. See RFC 2087 section 4.3.

func (*GetRootCommand) Command

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

func (*GetRootCommand) Parse

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

type GetRootHandler

type GetRootHandler struct {
	GetRootCommand
}

func (*GetRootHandler) Handle

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

type Mailbox

type Mailbox interface {
	// ListQuotas returns the currently active quotas for this mailbox.
	ListQuotas() ([]string, error)
}

type MailboxRoots

type MailboxRoots struct {
	Name  string
	Roots []string
}

func (*MailboxRoots) Format

func (m *MailboxRoots) Format() (fields []interface{})

func (*MailboxRoots) Parse

func (m *MailboxRoots) Parse(fields []interface{}) error

type Response

type Response struct {
	Quotas []*Status
}

A QUOTA response. See RFC 2087 section 5.1.

func (*Response) Handle

func (r *Response) Handle(resp imap.Resp) error

func (*Response) WriteTo

func (r *Response) WriteTo(w *imap.Writer) error

type RootResponse

type RootResponse struct {
	Mailbox *MailboxRoots
}

A QUOTAROOT response. See RFC 2087 section 5.1.

func (*RootResponse) Handle

func (r *RootResponse) Handle(resp imap.Resp) error

func (*RootResponse) WriteTo

func (r *RootResponse) WriteTo(w *imap.Writer) (err error)

type SetCommand

type SetCommand struct {
	Root      string
	Resources map[string]uint32
}

The SETQUOTA command. See RFC 2087 section 4.1.

func (*SetCommand) Command

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

func (*SetCommand) Parse

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

type SetHandler

type SetHandler struct {
	SetCommand
}

func (*SetHandler) Handle

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

type Status

type Status struct {
	// The quota name.
	Name string
	// The quota resources. Each resource is indexed by its name and contains its
	// current usage as well as its limit.
	Resources map[string][2]uint32
}

A quota status.

func (*Status) Format

func (rs *Status) Format() (fields []interface{})

func (*Status) Parse

func (rs *Status) Parse(fields []interface{}) error

type User

type User interface {
	// GetQuota returns the quota with the specified name.
	GetQuota(name string) (*Status, error)

	// SetQuota registers or updates a quota for this user with a set of resources
	// and their limit. The resource limits for the named quota root are changed
	// to be the specified limits. Any previous resource limits for the named
	// quota root are discarded.
	SetQuota(name string, resources map[string]uint32) error
}

Jump to

Keyboard shortcuts

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