Documentation
¶
Overview ¶
Package sortthread implements SORT and THREAD for go-imap.
SORT and THREAD are defined in RFC 5256.
Index ¶
- Constants
- Variables
- func GetBaseSubject(subject string) (string, bool)
- func NewSortExtension() server.Extension
- func NewThreadExtension() server.Extension
- type SortClient
- type SortCommand
- type SortCriterion
- type SortField
- type SortHandler
- type SortMailbox
- type SortResponse
- type Thread
- type ThreadAlgorithm
- type ThreadBackend
- type ThreadClient
- type ThreadCommand
- type ThreadHandler
- type ThreadMailbox
- type ThreadResponse
Examples ¶
Constants ¶
const ( SortArrival SortField = "ARRIVAL" SortCc = "CC" SortDate = "DATE" SortFrom = "FROM" SortSize = "SIZE" SortSubject = "SUBJECT" SortTo = "TO" )
const SortCapability = "SORT"
Variables ¶
var ErrUnsupportedBackend = errors.New("sortthread: backend not supported")
var ThreadCapabilities = []string{"THREAD=ORDEREDSUBJECT", "THREAD=REF", "THREAD=REFERENCES"}
Functions ¶
func GetBaseSubject ¶ added in v1.1.0
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 NewThreadExtension ¶ added in v1.2.0
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 ¶
SortCriterion is a criterion that can be used to sort messages.
type SortHandler ¶ added in v1.2.0
type SortHandler struct {
SortCommand
}
type SortMailbox ¶ added in v1.2.0
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 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
}
type ThreadMailbox ¶ added in v1.2.0
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