sortthread

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 12 Imported by: 7

README

go-imap-sortthread

GoDoc builds.sr.ht status

SORT and THREAD extensions for go-imap

License

MIT

Documentation

Overview

Package sortthread implements SORT and THREAD for go-imap.

SORT and THREAD are defined in RFC 5256.

Index

Examples

Constants

View Source
const (
	SortArrival SortField = "ARRIVAL"
	SortCc                = "CC"
	SortDate              = "DATE"
	SortFrom              = "FROM"
	SortSize              = "SIZE"
	SortSubject           = "SUBJECT"
	SortTo                = "TO"
)
View Source
const SortCapability = "SORT"

Variables

View Source
var ErrUnsupportedBackend = errors.New("sortthread: backend not supported")
View Source
var ThreadCapabilities = []string{"THREAD=ORDEREDSUBJECT", "THREAD=REF", "THREAD=REFERENCES"}

Functions

func GetBaseSubject added in v1.1.0

func GetBaseSubject(subject string) (string, bool)

GetBaseSubject returns the base subject of the given string according to Section 2.1. The returned string is suitable for comparison with other base subjects. The returned bool indicates whether the subject is a reply or a forward.

func NewSortExtension added in v1.2.0

func NewSortExtension() server.Extension

func NewThreadExtension added in v1.2.0

func NewThreadExtension() server.Extension

Types

type SortClient

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

SortClient is a SORT client.

Example
// Assuming c is an IMAP client
var c *client.Client

// Create a new SORT client
sc := sortthread.NewSortClient(c)

// Check the server supports the extension
ok, err := sc.SupportSort()
if err != nil {
	log.Fatal(err)
} else if !ok {
	log.Fatal("Server doesn't support SORT")
}

// Send a SORT command: search for the first 10 messages, sort them by
// ascending sender and then by descending size
sortCriteria := []sortthread.SortCriterion{
	{Field: sortthread.SortFrom},
	{Field: sortthread.SortSize, Reverse: true},
}
searchCriteria := imap.NewSearchCriteria()
searchCriteria.SeqNum = new(imap.SeqSet)
searchCriteria.SeqNum.AddRange(1, 10)
uids, err := sc.UidSort(sortCriteria, searchCriteria)
if err != nil {
	log.Fatal(err)
}

log.Println(uids)
Output:

func NewSortClient

func NewSortClient(c *client.Client) *SortClient

NewClient creates a new SORT client.

func (*SortClient) Sort

func (c *SortClient) Sort(sortCriteria []SortCriterion, searchCriteria *imap.SearchCriteria) ([]uint32, error)

func (*SortClient) SupportSort

func (c *SortClient) SupportSort() (bool, error)

SupportSort returns true if the remote server supports the extension.

func (*SortClient) UidSort

func (c *SortClient) UidSort(sortCriteria []SortCriterion, searchCriteria *imap.SearchCriteria) ([]uint32, error)

type SortCommand

type SortCommand struct {
	SortCriteria   []SortCriterion
	Charset        string
	SearchCriteria *imap.SearchCriteria
}

SortCommand is a SORT command.

func (*SortCommand) Command

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

func (*SortCommand) Parse

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

type SortCriterion

type SortCriterion struct {
	Field   SortField
	Reverse bool
}

SortCriterion is a criterion that can be used to sort messages.

type SortField

type SortField string

SortField is a field that can be used to sort messages.

type SortHandler added in v1.2.0

type SortHandler struct {
	SortCommand
}

func (*SortHandler) Handle added in v1.2.0

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

func (*SortHandler) UidHandle added in v1.2.0

func (h *SortHandler) UidHandle(conn server.Conn) error

type SortMailbox added in v1.2.0

type SortMailbox interface {
	backend.Mailbox
	Sort(uid bool, sortCrit []SortCriterion, searchCrit *imap.SearchCriteria) ([]uint32, error)
}

type SortResponse

type SortResponse struct {
	Ids []uint32
}

func (*SortResponse) Handle

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

func (*SortResponse) WriteTo

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

type Thread

type Thread struct {
	Id       uint32
	Children []*Thread
}

type ThreadAlgorithm

type ThreadAlgorithm string

ThreadAlgorithm is the algorithm used by the server to sort messages

const (
	OrderedSubject ThreadAlgorithm = "ORDEREDSUBJECT"
	References                     = "REFERENCES"
)

type ThreadBackend added in v1.2.0

type ThreadBackend interface {
	backend.Backend
	SupportedThreadAlgorithms() []ThreadAlgorithm
}

type ThreadClient

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

ThreadClient is a THREAD client.

Example
// Assuming c is an IMAP client
var c *client.Client

// Create a new THREAD client
sc := sortthread.NewThreadClient(c)

// Check the server supports the extension
ok, err := sc.SupportThread()
if err != nil {
	log.Fatal(err)
} else if !ok {
	log.Fatal("Server doesn't support THREAD")
}

layoutISO := "2006-01-02"
searchCriteria := imap.NewSearchCriteria()
date, _ := time.Parse(layoutISO, "2019-07-05")
searchCriteria.Since = date
threads, err := sc.UidThread(sortthread.References, searchCriteria)
if err != nil {
	log.Fatal(err)
}

log.Println(threads)
Output:

func NewThreadClient

func NewThreadClient(c *client.Client) *ThreadClient

NewClient creates a new THREAD client

func (*ThreadClient) SupportThread

func (c *ThreadClient) SupportThread() (bool, error)

SupportThread returns true if the remote server supports the extension.

func (*ThreadClient) Thread

func (c *ThreadClient) Thread(algorithm ThreadAlgorithm, searchCriteria *imap.SearchCriteria) ([]*Thread, error)

func (*ThreadClient) UidThread

func (c *ThreadClient) UidThread(algorithm ThreadAlgorithm, searchCriteria *imap.SearchCriteria) ([]*Thread, error)

type ThreadCommand

type ThreadCommand struct {
	Algorithm      ThreadAlgorithm
	Charset        string
	SearchCriteria *imap.SearchCriteria
}

ThreadCommand is a THREAD command.

func (*ThreadCommand) Command

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

func (*ThreadCommand) Parse added in v1.2.0

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

type ThreadHandler added in v1.2.0

type ThreadHandler struct {
	ThreadCommand
}

func (*ThreadHandler) Handle added in v1.2.0

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

func (*ThreadHandler) UidHandle added in v1.2.0

func (h *ThreadHandler) UidHandle(conn server.Conn) error

type ThreadMailbox added in v1.2.0

type ThreadMailbox interface {
	backend.Mailbox
	Thread(uid bool, threading ThreadAlgorithm, searchCrit *imap.SearchCriteria) ([]*Thread, error)
}

type ThreadResponse

type ThreadResponse struct {
	Threads []*Thread
}

func (*ThreadResponse) Handle

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

func (*ThreadResponse) WriteTo added in v1.2.0

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

Jump to

Keyboard shortcuts

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