Documentation
¶
Overview ¶
Implements the IMAP IDLE extension, as defined in RFC 2177.
Index ¶
Examples ¶
Constants ¶
View Source
const Capability = "IDLE"
The IDLE capability.
Variables ¶
This section is empty.
Functions ¶
func NewExtension ¶
Types ¶
type Client ¶
type Client struct { // LogoutTimeout is used to avoid being logged out by the server when idling. // Each LogoutTimeout, the idle command is restarted. If set to zero, this // behavior is disabled. LogoutTimeout time.Duration // contains filtered or unexported fields }
Client is an IDLE client.
func (*Client) Idle ¶
Idle indicates to the server that the client is ready to receive unsolicited mailbox update messages. When the client wants to send commands again, it must first close stop.
Example ¶
// Let's assume c is an IMAP client var c *client.Client // Select a mailbox if _, err := c.Select("INBOX", false); err != nil { log.Fatal(err) } idleClient := idle.NewClient(c) // Create a channel to receive mailbox updates updates := make(chan client.Update) c.Updates = updates // Check support for the IDLE extension if ok, err := idleClient.SupportIdle(); err == nil && ok { // Start idling stopped := false stop := make(chan struct{}) done := make(chan error, 1) go func() { done <- idleClient.Idle(stop) }() // Listen for updates for { select { case update := <-updates: log.Println("New update:", update) if !stopped { close(stop) stopped = true } case err := <-done: if err != nil { log.Fatal(err) } log.Println("Not idling anymore") return } } } else { // Fallback: call periodically c.Noop() }
Output:
func (*Client) IdleWithFallback ¶
IdleWithFallback tries to idle if the server supports it. If it doesn't, it falls back to polling. If pollInterval is zero, a sensible default will be used.
Example ¶
// Let's assume c is an IMAP client var c *client.Client // Select a mailbox if _, err := c.Select("INBOX", false); err != nil { log.Fatal(err) } idleClient := idle.NewClient(c) // Create a channel to receive mailbox updates updates := make(chan client.Update) c.Updates = updates // Start idling done := make(chan error, 1) go func() { done <- idleClient.IdleWithFallback(nil, 0) }() // Listen for updates for { select { case update := <-updates: log.Println("New update:", update) case err := <-done: if err != nil { log.Fatal(err) } log.Println("Not idling anymore") return } }
Output:
func (*Client) SupportIdle ¶
SupportIdle checks if the server supports the IDLE extension.
type IdleClient ¶
type IdleClient = Client
IdleClient is an alias used to compose multiple client extensions.
Click to show internal directories.
Click to hide internal directories.