### Configure FetchItemBodySection Examples Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/message-data-types.md Common configurations for fetching specific parts or ranges of a message body. ```go // Fetch entire message body &imap.FetchItemBodySection{} // Fetch only message headers &imap.FetchItemBodySection{Specifier: imap.PartSpecifierHeader} // Fetch first part's body &imap.FetchItemBodySection{Part: []int{1}} // Fetch specific headers &imap.FetchItemBodySection{ Specifier: imap.PartSpecifierHeader, HeaderFields: []string{"Subject", "From"}, } // Fetch with byte range (first 1000 bytes) &imap.FetchItemBodySection{ Partial: &imap.SectionPartial{Offset: 0, Size: 1000}, } ``` -------------------------------- ### Implement a Basic IMAP Server Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/README.md Shows how to define a session handler and start an IMAP server using imapserver. ```go package main import ( "log" "github.com/emersion/go-imap/v2" "github.com/emersion/go-imap/v2/imapserver" ) type MySession struct { user string } func (s *MySession) Close() error { return nil } func (s *MySession) Login(username, password string) error { s.user = username return nil } func (s *MySession) Select(mailbox string, options *imap.SelectOptions) (*imap.SelectData, error) { return &imap.SelectData{ NumMessages: 10, Flags: []imap.Flag{imap.FlagSeen}, }, nil } // ... implement other required methods func main() { server := imapserver.New(&imapserver.Options{ NewSession: func(conn *imapserver.Conn) (imapserver.Session, *imapserver.GreetingData, error) { return &MySession{}, &imapserver.GreetingData{}, nil }, }) if err := server.ListenAndServe(":143"); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Execute Store Command Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/mailbox-operations.md Example of adding Seen and Flagged flags to a set of message UIDs. ```go // Mark messages as seen and flagged storeCmd := client.Store( imap.UIDSetNum(uid1, uid2, uid3), &imap.StoreFlags{ Op: imap.StoreFlagsAdd, Silent: false, Flags: []imap.Flag{imap.FlagSeen, imap.FlagFlagged}, }, ) storeCmd.Wait() ``` -------------------------------- ### Execute Fetch Command Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/mailbox-operations.md Example of configuring fetch options to retrieve UID, envelope, flags, body structure, and header sections. ```go opts := &imap.FetchOptions{ UID: true, Envelope: true, Flags: true, BodyStructure: &imap.FetchItemBodyStructure{Extended: true}, BodySection: []*imap.FetchItemBodySection{ {Specifier: imap.PartSpecifierHeader}, }, } fetchCmd := client.Fetch(uids, opts) ``` -------------------------------- ### Fetch BodyStructure Example Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/message-data-types.md Demonstrates fetching and iterating over body structure parts from an IMAP message. ```go opts := &imap.FetchOptions{ BodyStructure: &imap.FetchItemBodyStructure{Extended: true}, } cmd := client.Fetch(imap.UIDSetNum(123), opts) msg := cmd.Next() for item := msg.Next(); item != nil; item = msg.Next() { if bs, ok := item.(*imap.BodyStructureSinglePart); ok { fmt.Printf("Part: %s, Filename: %s\n", bs.MediaType(), bs.Filename()) } } ``` -------------------------------- ### Start the IMAP server with TLS Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Uses the TLS configuration provided in the server's Options. Defaults to :993 if the address is empty. ```go tlsConfig := &tls.Config{ Certificates: []tls.Certificate{cert}, } server := imapserver.New(&imapserver.Options{ NewSession: sessionFactory, TLSConfig: tlsConfig, }) if err := server.ListenAndServeTLS(":993"); err != nil { log.Fatal(err) } ``` -------------------------------- ### Check for group start Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/message-data-types.md Identifies if the address is a start-of-group marker. ```go func (addr *Address) IsGroupStart() bool ``` -------------------------------- ### Get email address string Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/message-data-types.md Returns the formatted email address or empty string for group markers. ```go func (addr *Address) Addr() string ``` -------------------------------- ### Message Search Criteria Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Examples of constructing search criteria for filtering messages. ```go Search(&imap.SearchCriteria{NotFlag: []imap.Flag{imap.FlagSeen}}, nil) ``` ```go Search(&imap.SearchCriteria{Flag: []imap.Flag{imap.FlagFlagged}}, nil) ``` ```go Search(&imap.SearchCriteria{Header: []imap.SearchCriteriaHeaderField{{Key: "From", Value: "user@example.com"}}}, nil) ``` ```go Search(&imap.SearchCriteria{Larger: 1000}, nil) ``` ```go Search(&imap.SearchCriteria{Body: []string{"search term"}}, nil) ``` ```go Search(&imap.SearchCriteria{Since: since, Before: before}, nil) ``` -------------------------------- ### Implement IDLE Push Notifications Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Configures a unilateral data handler to process mailbox updates and starts an IDLE session. ```go // Set up notification handler opts := &imapclient.Options{ UnilateralDataHandler: &imapclient.UnilateralDataHandler{ Mailbox: func(data *imapclient.UnilateralDataMailbox) { if data.NumMessages != nil { fmt.Printf("Message count: %d\n", *data.NumMessages) } }, Expunge: func(seqNum uint32) { fmt.Printf("Expunged: %d\n", seqNum) }, Fetch: func(msg *imapclient.FetchMessageData) { fmt.Printf("New message: %d\n", msg.SeqNum) }, }, } client, _ := imapclient.DialTLS("imap.example.com:993", opts) client.Select("INBOX", nil) // Start idle for 5 minutes stop := make(chan struct{}) go func() { time.Sleep(5 * time.Minute) close(stop) }() if err := client.Idle(stop).Wait(); err != nil { log.Fatal(err) } client.Logout().Wait() ``` -------------------------------- ### Start the IMAP server on a TCP address Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Blocks until the server is closed. If the address is empty, it defaults to :143. ```go if err := server.ListenAndServe(":143"); err != nil { log.Fatal(err) } ``` -------------------------------- ### Enable IDLE Extension on Server Source: https://github.com/emersion/go-imap/wiki/Using-extensions Enable the IDLE extension for an IMAP server instance. This is typically done during server setup or configuration. ```go s.Enable(idle.NewExtension()) ``` -------------------------------- ### Define Message Flags Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/core-types-and-constants.md Standard and custom flags used for marking message properties, where system flags start with \ and custom flags start with $. ```go type Flag string const ( FlagSeen Flag = "\\Seen" FlagAnswered Flag = "\\Answered" FlagFlagged Flag = "\\Flagged" FlagDeleted Flag = "\\Deleted" FlagDraft Flag = "\\Draft" FlagForwarded Flag = "$Forwarded" FlagMDNSent Flag = "$MDNSent" FlagJunk Flag = "$Junk" FlagNotJunk Flag = "$NotJunk" FlagPhishing Flag = "$Phishing" FlagImportant Flag = "$Important" FlagWildcard Flag = "\\*" ) ``` -------------------------------- ### Connect to IMAP with STARTTLS Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Establishes a connection and upgrades to TLS using the STARTTLS command. ```go client, err := imapclient.DialStartTLS("imap.example.com:143", nil) if err != nil { log.Fatal(err) } defer client.Close() ``` -------------------------------- ### Initialize STARTTLS connection Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Establishes a TCP connection and upgrades it to TLS using the STARTTLS capability. ```go conn, _ := net.Dial("tcp", "imap.example.com:143") client, err := imapclient.NewStartTLS(conn, &imapclient.Options{ TLSConfig: &tls.Config{}, }) ``` -------------------------------- ### Initialize IMAP client with New Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Creates a client from an existing network connection. Does not perform I/O operations. ```go conn, _ := net.Dial("tcp", "imap.example.com:143") client := imapclient.New(conn, &imapclient.Options{ DebugWriter: os.Stdout, }) ``` -------------------------------- ### Handle IMAP Errors Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/core-types-and-constants.md Example of type-asserting an error to access IMAP-specific response details. ```go if err := client.Authenticate(saslClient).Wait(); err != nil { if imapErr, ok := err.(*imap.Error); ok { fmt.Printf("IMAP error: %s [%s] %s\n", imapErr.Type, imapErr.Code, imapErr.Text) } } ``` -------------------------------- ### Define Server Options Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Configuration structure for initializing an IMAP server instance. ```go type Options struct { NewSession func(*Conn) (Session, *GreetingData, error) Caps imap.CapSet Logger Logger TLSConfig *tls.Config InsecureAuth bool DebugWriter io.Writer } type Logger interface { Printf(format string, args ...interface{}) } type GreetingData struct { PreAuth bool } ``` -------------------------------- ### Get Mailbox Status Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Retrieves status information for a specific mailbox, such as message counts and UIDs. ```go opts := &imap.StatusOptions{ NumMessages: true, NumUnseen: true, UIDNext: true, UIDValidity: true, } status, err := client.Status("INBOX", opts) if err != nil { log.Fatal(err) } fmt.Printf("Messages: %d\n", *status.NumMessages) fmt.Printf("Unseen: %d\n", *status.NumUnseen) fmt.Printf("Next UID: %d\n", status.UIDNext) ``` -------------------------------- ### New Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Creates a new IMAP server instance with the provided configuration options. ```APIDOC ## func New(options *Options) *Server ### Description Creates a new IMAP server instance. At least one of CapIMAP4rev2 or CapIMAP4rev1 must be supported in the options, otherwise the function will panic. ### Parameters - **options** (*Options) - Required - Server configuration including session factory and capabilities. ### Returns - ***Server** - A new server instance. ``` -------------------------------- ### NewStartTLS Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Creates a new client from an existing connection and upgrades to TLS via STARTTLS. ```APIDOC ## func NewStartTLS(conn net.Conn, options *Options) (*Client, error) ### Description Creates a new client from an existing connection and upgrades to TLS via STARTTLS. ### Parameters - **conn** (net.Conn) - Required - Existing plaintext connection - **options** (*Options) - Optional - Client configuration ### Returns - (*Client, error) - Client with TLS or error ``` -------------------------------- ### Create a new IMAP server instance Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Requires at least one of CapIMAP4rev2 or CapIMAP4rev1 to be supported in the Options, otherwise it will panic. ```go server := imapserver.New(&imapserver.Options{ NewSession: func(conn *imapserver.Conn) (imapserver.Session, *imapserver.GreetingData, error) { return &MySession{}, &imapserver.GreetingData{}, nil }, Caps: imap.CapSet{ imap.CapIMAP4rev2: {}, imap.CapIdle: {}, }, }) ``` -------------------------------- ### Get Selected Mailbox Metadata Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Returns metadata for the currently selected mailbox, or nil if no mailbox is selected. ```go mbox := client.Mailbox() if mbox != nil { fmt.Printf("Selected: %s (%d messages)\n", mbox.Name, mbox.NumMessages) } ``` -------------------------------- ### Execute IMAP Search with Options Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/search-and-filtering.md Demonstrates performing a search with specific return options and accessing the resulting data. ```go criteria := &imap.SearchCriteria{ Flag: []imap.Flag{imap.FlagSeen}, } opts := &imap.SearchOptions{ ReturnCount: true, ReturnMin: true, ReturnMax: true, } result, _ := client.Search(criteria, opts) fmt.Printf("Found %d messages, UIDs %d-%d\n", result.Count, result.Min, result.Max) ``` -------------------------------- ### Connect and Fetch Messages with imapclient Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/README.md Demonstrates establishing a TLS connection, authenticating, selecting a mailbox, and fetching unseen messages. ```go package main import ( "log" "github.com/emersion/go-imap/v2" "github.com/emersion/go-imap/v2/imapclient" ) func main() { // Connect client, err := imapclient.DialTLS("imap.gmail.com:993", nil) if err != nil { log.Fatal(err) } defer client.Close() // Authenticate if err := client.Login("user@gmail.com", "password").Wait(); err != nil { log.Fatal(err) } // Select mailbox data, _ := client.Select("INBOX", nil).Wait() log.Printf("Messages: %d\n", data.NumMessages) // Search criteria := &imap.SearchCriteria{ Flag: []imap.Flag{imap.FlagUnseen}, } results, _ := client.Search(criteria, nil) // Fetch cmd := client.Fetch(results.All, &imap.FetchOptions{ Envelope: true, Flags: true, }) for msg := cmd.Next(); msg != nil; msg = cmd.Next() { // Process message } cmd.Close() client.Logout().Wait() } ``` -------------------------------- ### Authenticate with Credentials Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Performs a standard login using email and password credentials. ```go if err := client.Login("user@example.com", "password").Wait(); err != nil { log.Fatal("Login failed:", err) } log.Println("Authenticated") ``` -------------------------------- ### Check Server Capabilities Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Retrieve and verify server capabilities such as IDLE, MOVE, and authentication mechanisms. ```go caps := client.Caps() // Fetch from server // Check caps.Has(imap.CapIdle) caps.Has(imap.CapMove) caps.Has(imap.CapCondStore) // Get auth mechanisms caps.AuthMechanisms() // []string // Get append limit if limit, ok := caps.AppendLimit(); ok { fmt.Printf("Max append: %d\n", *limit) } ``` -------------------------------- ### Session Create Method Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Creates a new mailbox. ```go func (s Session) Create(mailbox string, options *imap.CreateOptions) error ``` -------------------------------- ### Retrieve and Iterate Namespaces Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Fetch available namespaces from the server and iterate through personal folders. ```go ns, _ := client.Namespace() for _, personal := range ns.Personal { fmt.Printf("Personal namespace: %q (delim: %c)\n", personal.Prefix, personal.Delim) } ``` -------------------------------- ### Importing go-imap packages Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Standard import paths for core types, client, and server functionality. ```go import ( "github.com/emersion/go-imap/v2" // Core types, constants "github.com/emersion/go-imap/v2/imapclient" // Client "github.com/emersion/go-imap/v2/imapserver" // Server ) ``` -------------------------------- ### Session List Method Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Lists mailboxes matching patterns. Must write each matching mailbox to the provided writer. ```go func (s Session) List(w *ListWriter, ref string, patterns []string, options *imap.ListOptions) error ``` -------------------------------- ### New Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Creates a new IMAP client from an existing network connection. ```APIDOC ## func New(conn net.Conn, options *Options) *Client ### Description Creates a new IMAP client from an existing connection. Does not perform I/O. ### Parameters - **conn** (net.Conn) - Required - Existing network connection - **options** (*Options) - Optional - Client configuration (nil for defaults) ### Returns - *Client - A ready-to-use IMAP client ``` -------------------------------- ### Enable Capabilities with ENABLE Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Dynamically enables server-side extensions and retrieves the current set of enabled capabilities. ```go // Enable UTF-8 support if err := client.Enable([]imap.Cap{imap.CapUTF8Accept}).Wait(); err != nil { log.Fatal(err) } // Check enabled capabilities enabledCaps := client.Caps() // After ENABLE, this reflects enabled extensions ``` -------------------------------- ### Establishing IMAP Client Connections Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Methods for connecting to an IMAP server using various security configurations. ```go imapclient.DialTLS("host:993", nil) ``` ```go imapclient.DialStartTLS("host:143", nil) ``` ```go imapclient.DialInsecure("host:143", nil) ``` ```go imapclient.New(conn, nil) ``` -------------------------------- ### Complete IMAP Session Lifecycle in Go Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Demonstrates the full flow of an IMAP session from connection to logout. Requires the imapclient package and proper error handling for each command. ```go func main() { // Connect client, err := imapclient.DialTLS("imap.example.com:993", nil) if err != nil { log.Fatal(err) } defer client.Close() // Authenticate if err := client.Login("user", "pass").Wait(); err != nil { log.Fatal(err) } // Get capabilities caps := client.Caps() fmt.Printf("Capabilities: %v\n", caps) // Select mailbox mboxCmd := client.Select("INBOX", nil) mboxData, err := mboxCmd.Wait() if err != nil { log.Fatal(err) } fmt.Printf("Messages: %d\n", mboxData.NumMessages) // Search criteria := &imap.SearchCriteria{ Flag: []imap.Flag{imap.FlagUnseen}, } data, _ := client.Search(criteria, nil) // Fetch opts := &imap.FetchOptions{ Envelope: true, Flags: true, } cmd := client.Fetch(data.All, opts) for msg := cmd.Next(); msg != nil; msg = cmd.Next() { // Process message... } cmd.Close() // Mark as seen client.Store(data.All, &imap.StoreFlags{ Op: imap.StoreFlagsAdd, Flags: []imap.Flag{imap.FlagSeen}, }, nil).Wait() // Logout client.Logout().Wait() } ``` -------------------------------- ### Manage IMAP Connection Lifecycle Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Demonstrates the standard flow for connecting, authenticating, performing operations, and closing an IMAP session. ```go // Connect and authenticate client, _ := imapclient.DialTLS("imap.example.com:993", nil) defer client.Close() client.Login("user", "pass").Wait() // Operations client.Select("INBOX", nil).Wait() data, _ := client.Search(&imap.SearchCriteria{}, nil) cmd := client.Fetch(data.All, opts) // ... // Close client.Logout().Wait() client.Close() ``` -------------------------------- ### BodyStructureSinglePart Methods Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/message-data-types.md Methods for retrieving filename, media type, and traversing single-part MIME structures. ```go func (bs *BodyStructureSinglePart) Filename() string ``` ```go func (bs *BodyStructureSinglePart) MediaType() string ``` ```go func (bs *BodyStructureSinglePart) Walk(f BodyStructureWalkFunc) ``` -------------------------------- ### Apply SearchCriteria And Method Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/search-and-filtering.md Combines two criteria sets by appending fields to the receiver in-place. ```go func (criteria *SearchCriteria) And(other *SearchCriteria) ``` ```go criteria := &imap.SearchCriteria{ Flag: []imap.Flag{imap.FlagSeen}, } criteria.And(&imap.SearchCriteria{ Body: []string{"important"}, }) // Equivalent to: (\Seen) AND (Body contains "important") data, _ := client.Search(criteria) ``` -------------------------------- ### Session Select Method Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Selects a mailbox for reading and optionally writing. ```go func (s Session) Select(mailbox string, options *imap.SelectOptions) (*imap.SelectData, error) ``` -------------------------------- ### Retrieve Server Capabilities Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Returns server capabilities, implicitly issuing a CAPABILITY command if needed. Blocks until the greeting is received. ```go caps := client.Caps() if caps.Has(imap.CapIdle) { fmt.Println("Server supports IDLE") } ``` -------------------------------- ### Define Store Options and Flags Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/mailbox-operations.md Structures and constants for configuring message flag operations. ```go type StoreOptions struct { UnchangedSince uint64 } type StoreFlagsOp int const ( StoreFlagsSet StoreFlagsOp = iota StoreFlagsAdd StoreFlagsDel ) type StoreFlags struct { Op StoreFlagsOp Silent bool Flags []Flag } ``` -------------------------------- ### Define Fetch Options Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/mailbox-operations.md Structures for configuring message content retrieval parameters. ```go type FetchOptions struct { BodyStructure *FetchItemBodyStructure Envelope bool Flags bool InternalDate bool RFC822Size bool UID bool BodySection []*FetchItemBodySection BinarySection []*FetchItemBinarySection BinarySectionSize []*FetchItemBinarySectionSize ModSeq bool ChangedSince uint64 } type FetchItemBodyStructure struct { Extended bool } ``` -------------------------------- ### Create Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Creates a new mailbox on the IMAP server. ```APIDOC ## func (c *Client) Create(mailbox string) *Command ### Description Creates a mailbox. ### Parameters - **mailbox** (string) - Required - Mailbox name/path ### Returns - **Command** (*Command) - Command handle ``` -------------------------------- ### Session Login Method Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Authenticates the user. Returns ErrAuthFailed for invalid credentials. ```go func (s Session) Login(username, password string) error ``` -------------------------------- ### DialStartTLS Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Connects to an IMAP server with STARTTLS. ```APIDOC ## func DialStartTLS(address string, options *Options) (*Client, error) ### Description Connects to an IMAP server with STARTTLS. ### Parameters - **address** (string) - Required - Host:port address - **options** (*Options) - Optional - Client configuration ### Returns - (*Client, error) - Connected client or error ``` -------------------------------- ### Retrieve Enabled Capabilities Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Returns a copy of the capabilities enabled by the client via the ENABLE command. ```go func (c *Conn) EnabledCaps() imap.CapSet ``` -------------------------------- ### Using SearchRes in IMAP Operations Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/search-and-filtering.md Demonstrates performing a search and subsequently using the SEARCHRES marker to apply store operations to those results. ```go // First search criteria := &imap.SearchCriteria{ Flag: []imap.Flag{imap.FlagSeen}, } client.Search(criteria) // Later: operate on those results without re-searching deleteCmd := client.Store(imap.SearchRes(), &imap.StoreFlags{ Op: imap.StoreFlagsDel, Flags: []imap.Flag{imap.FlagSeen}, }) deleteCmd.Wait() ``` -------------------------------- ### client.Namespace() Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Retrieves the server's namespace configuration, including personal, other, and shared folders. ```APIDOC ## client.Namespace() ### Description Fetches the namespace information from the server, which defines the hierarchy and prefixes for different mailbox types. ### Returns - **NamespaceData** (struct) - Contains slices of Personal, Other, and Shared namespaces. ### Usage Example ```go ns, _ := client.Namespace() for _, personal := range ns.Personal { fmt.Printf("Personal namespace: %q (delim: %c)\n", personal.Prefix, personal.Delim) } ``` -------------------------------- ### IMAP Authentication Methods Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Commands for authenticating a client session. ```go client.Login(username, password).Wait() ``` ```go client.Authenticate(sasl.NewPlainClient("", user, pass)) ``` ```go client.State() ``` -------------------------------- ### STARTTLS (RFC 3501) Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md The STARTTLS capability allows for an explicit TLS upgrade on an existing IMAP connection. ```APIDOC ## STARTTLS (RFC 3501) ### Description Explicit TLS upgrade for an IMAP connection. ### Capability CapStartTLS ### Client Usage ```go conn, _ := net.Dial("tcp", "imap.example.com:143") client, err := imapclient.NewStartTLS(conn, &imapclient.Options{ TLSConfig: &tls.Config{}, }) ``` ``` -------------------------------- ### BodyStructureMultiPart Walk Method Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/message-data-types.md Recursively traverses multi-part MIME structures in depth-first pre-order. ```go func (bs *BodyStructureMultiPart) Walk(f BodyStructureWalkFunc) ``` -------------------------------- ### Connect to IMAP with TLS Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Establishes an implicit TLS connection to an IMAP server on port 993. ```go package main import ( "log" "github.com/emersion/go-imap/v2/imapclient" ) func main() { // Connect with implicit TLS (port 993) client, err := imapclient.DialTLS("imap.gmail.com:993", nil) if err != nil { log.Fatal("Connection failed:", err) } defer client.Close() // Wait for greeting if err := client.WaitGreeting(); err != nil { log.Fatal("Greeting error:", err) } log.Println("Connected") } ``` -------------------------------- ### Configure IMAP Client Options Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Defines the configuration structure for the IMAP client, including TLS, debugging, and connection settings. ```go type Options struct { TLSConfig *tls.Config DebugWriter io.Writer UnilateralDataHandler *UnilateralDataHandler WordDecoder *mime.WordDecoder Dialer *net.Dialer } ``` -------------------------------- ### Caps Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Returns server capabilities, implicitly issuing a CAPABILITY command if not yet available. ```APIDOC ## func (c *Client) Caps() imap.CapSet ### Description Returns server capabilities. Implicitly issues a CAPABILITY command if not yet available. Blocks until greeting is received. ### Returns - **imap.CapSet** - Capability set or nil if error ``` -------------------------------- ### Create Mailbox Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Creates a new mailbox with the specified name. ```go func (c *Client) Create(mailbox string) *Command ``` -------------------------------- ### Serve Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Serves IMAP connections on an existing network listener. ```APIDOC ## func (s *Server) Serve(ln net.Listener) error ### Description Accepts and serves IMAP connections on an existing net.Listener until the listener is closed or the server is shut down. ### Parameters - **ln** (net.Listener) - Required - The network listener to use. ### Returns - **error** - Serving error. ``` -------------------------------- ### Request server capabilities Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Requests server capabilities, usually called implicitly by Caps(). ```go func (c *Client) Capability() *CapabilityCommand ``` -------------------------------- ### Define Connection Structure Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Core methods for interacting with an active client connection. ```go type Conn struct { // ... } func (c *Conn) NetConn() net.Conn func (c *Conn) Bye(text string) error func (c *Conn) EnabledCaps() imap.CapSet ``` -------------------------------- ### Search with Extended Options in Go Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Configures imap.SearchOptions to return metadata like count, minimum, and maximum UIDs. ```go criteria := &imap.SearchCriteria{ Flag: []imap.Flag{imap.FlagUnseen}, } opts := &imap.SearchOptions{ ReturnMin: true, ReturnMax: true, ReturnCount: true, } data, err := client.Search(criteria, opts) if err != nil { log.Fatal(err) } fmt.Printf("Found %d unseen, UIDs %d-%d\n", data.Count, data.Min, data.Max) ``` -------------------------------- ### Configure Fetch Options Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Defines the fetch parameters for retrieving message metadata and body sections. ```go opts := &imap.FetchOptions{ UID: true, Envelope: true, Flags: true, BodyStructure: &imap.FetchItemBodyStructure{Extended: true}, BodySection: []*imap.FetchItemBodySection{ {Specifier: imap.PartSpecifierHeader}, }, } cmd := client.Fetch(numSet, opts) ``` -------------------------------- ### client.Enable Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Enables specific IMAP extensions dynamically. ```APIDOC ## client.Enable ### Description Enables specific capabilities dynamically on the current IMAP connection. ### Parameters - **caps** ([]imap.Cap) - Required - A list of capabilities to enable. ### Example ```go err := client.Enable([]imap.Cap{imap.CapUTF8Accept}).Wait() ``` ``` -------------------------------- ### client.Caps() Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Retrieves the server's capabilities and provides methods to check for specific features or limits. ```APIDOC ## client.Caps() ### Description Fetches the capabilities supported by the IMAP server. Use this to check for feature support like IDLE, MOVE, or CONDSTORE, and to retrieve server-specific limits. ### Methods - **Has(capability string)**: Checks if a specific capability is supported. - **AuthMechanisms()**: Returns a slice of supported authentication mechanisms. - **AppendLimit()**: Returns the maximum append size limit if supported by the server. ``` -------------------------------- ### Display go-imap module structure Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/README.md Visual representation of the package hierarchy for the go-imap/v2 module. ```text github.com/emersion/go-imap/v2 ├── [root] – Core types, constants, capabilities ├── imapclient/ – IMAP client implementation └── imapserver/ – IMAP server framework ``` -------------------------------- ### Session Subscribe Method Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Adds a mailbox to the subscription list. ```go func (s Session) Subscribe(mailbox string) error ``` -------------------------------- ### Namespace Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Returns namespace information. ```APIDOC ## func (s SessionNamespace) Namespace() (*imap.NamespaceData, error) ### Description Returns namespace information. ### Returns - (*imap.NamespaceData, error) ``` -------------------------------- ### Fetch Message Data in Go Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Uses FetchOptions to specify items to retrieve and iterates through the resulting message data. ```go opts := &imap.FetchOptions{ UID: true, Envelope: true, Flags: true, } cmd := client.Fetch(imap.UIDSetNum(1, 2, 3), opts) defer cmd.Close() for msg := cmd.Next(); msg != nil; msg = cmd.Next() { fmt.Printf("SeqNum: %d\n", msg.SeqNum) for item := msg.Next(); item != nil; item = msg.Next() { switch v := item.(type) { case *imap.Envelope: fmt.Printf("Subject: %s\n", v.Subject) } } } ``` -------------------------------- ### Login Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Authenticates the user with a username and password. ```APIDOC ## func (s Session) Login(username, password string) error ### Description Authenticates the user. Return `ErrAuthFailed` for invalid credentials. ### Parameters - **username** (string) - Required - Username - **password** (string) - Required - Password (plaintext) ### Returns - **error** - `ErrAuthFailed`, `nil` on success, or other error ``` -------------------------------- ### Capability() Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Requests server capabilities from the IMAP server. ```APIDOC ## func (c *Client) Capability() ### Description Requests server capabilities. Usually called implicitly by Caps(). ### Returns *CapabilityCommand - Command handle ``` -------------------------------- ### Connect via DialInsecure Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Establishes a plaintext connection to an IMAP server. ```go client, err := imapclient.DialInsecure("imap.example.com:143", nil) if err != nil { log.Fatal(err) } defer client.Close() ``` -------------------------------- ### Command execution pattern Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Standard pattern for command execution where Wait() is used to block until the server responds. ```go type Command struct { // ... } func (cmd *Command) Wait() error ``` -------------------------------- ### Conn.EnabledCaps Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Retrieves the capabilities enabled by the client via the ENABLE command. ```APIDOC ## func (c *Conn) EnabledCaps() imap.CapSet ### Description Returns capabilities that have been enabled via ENABLE command. ### Returns - **imap.CapSet** - Copy of enabled capabilities ``` -------------------------------- ### Execute Extended LIST Command Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Retrieve mailbox lists with filtering options using ListOptions. ```go opts := &imap.ListOptions{ SelectSubscribed: true, // Only subscribed ReturnChildren: true, // Include child info } cmd := client.List("*", "", opts) defer cmd.Close() for mbox := cmd.Next(); mbox != nil; mbox = cmd.Next() { fmt.Printf("%s %v\n", mbox.Mailbox, mbox.Attrs) } ``` -------------------------------- ### FetchWriter Interface Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Used for writing FETCH responses. ```go type FetchWriter struct { // ... } func (w *FetchWriter) WriteFetch(seqNum uint32, items ...interface{}) error ``` -------------------------------- ### Noop() Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Sends a NOOP command to check the connection status. ```APIDOC ## func (c *Client) Noop() ### Description Sends a NOOP command (no operation, used to check connection). ### Returns *Command - Command handle ### Example if err := client.Noop().Wait(); err != nil { fmt.Println("Connection error:", err) } ``` -------------------------------- ### Fetch Basic Message Info in Go Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Retrieves standard message metadata such as UID, Envelope, Flags, and RFC822 size. ```go opts := &imap.FetchOptions{ UID: true, Envelope: true, Flags: true, RFC822Size: true, } cmd := client.Fetch(imap.UIDSetNum(1, 2, 3), opts) defer cmd.Close() for msg := cmd.Next(); msg != nil; msg = cmd.Next() { fmt.Printf("SeqNum: %d\n", msg.SeqNum) for item := msg.Next(); item != nil; item = msg.Next() { switch v := item.(type) { case *imap.Envelope: fmt.Printf(" Subject: %s\n", v.Subject) fmt.Printf(" From: %v\n", v.From) fmt.Printf(" Date: %s\n", v.Date.Format(time.RFC822)) case imap.UID: fmt.Printf(" UID: %d\n", v) case []imap.Flag: fmt.Printf(" Flags: %v\n", v) case uint32: fmt.Printf(" Size: %d\n", v) } } } ``` -------------------------------- ### client.Fetch Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/mailbox-operations.md Retrieves message content and metadata based on FetchOptions. ```APIDOC ## client.Fetch(seqset, options) ### Description Fetches specific data items for messages in the sequence set, such as envelope, flags, or body sections. ### Parameters - **seqset** (imap.SeqSet) - The set of messages to fetch. - **options** (*imap.FetchOptions) - Configuration for which data items to retrieve. ### FetchOptions Fields - **BodyStructure** (*FetchItemBodyStructure) - Fetch MIME structure. - **Envelope** (bool) - Fetch message metadata. - **Flags** (bool) - Fetch message flags. - **InternalDate** (bool) - Fetch internal date. - **RFC822Size** (bool) - Fetch message size. - **UID** (bool) - Fetch message UID. - **BodySection** ([]*FetchItemBodySection) - Fetch specific body sections. - **ChangedSince** (uint64) - Only fetch messages modified since this modseq (requires CONDSTORE). ### Example ```go opts := &imap.FetchOptions{ UID: true, Envelope: true, Flags: true, BodyStructure: &imap.FetchItemBodyStructure{Extended: true}, BodySection: []*imap.FetchItemBodySection{ {Specifier: imap.PartSpecifierHeader}, }, } fetchCmd := client.Fetch(uids, opts) ``` ``` -------------------------------- ### List Mailboxes with Extended Options Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Lists mailboxes with specific filtering and status return options. ```go opts := &imap.ListOptions{ SelectSubscribed: true, ReturnChildren: true, ReturnStatus: &imap.StatusOptions{ NumMessages: true, NumUnseen: true, }, } cmd := client.List("*", "", opts) defer cmd.Close() for mbox := cmd.Next(); mbox != nil; mbox = cmd.Next() { fmt.Printf("%s", mbox.Mailbox) if mbox.Status != nil && mbox.Status.NumUnseen != nil { fmt.Printf(" (%d unseen)", *mbox.Status.NumUnseen) } fmt.Printf("\n") } ``` -------------------------------- ### ListenAndServe Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Listens on a TCP address and serves IMAP connections. ```APIDOC ## func (s *Server) ListenAndServe(addr string) error ### Description Listens on a TCP address and serves IMAP connections. This method blocks until the server is closed. ### Parameters - **addr** (string) - Required - Address to listen on (empty defaults to ":143"). ### Returns - **error** - Listener or serving error. ``` -------------------------------- ### Serve IMAP connections on an existing listener Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Accepts connections until the provided listener is closed or the server is shut down. ```go listener, _ := net.Listen("tcp", ":143") go server.Serve(listener) // ... later ... listener.Close() ``` -------------------------------- ### Implement IMAP Server Session Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/quick-reference.md Defines a custom session structure and implements required methods for authentication and mailbox selection. ```go type MySession struct { user string // ... mailbox store } func (s *MySession) Close() error { return nil } func (s *MySession) Login(username, password string) error { if validPassword(username, password) { s.user = username return nil } return imapserver.ErrAuthFailed } func (s *MySession) Select(mailbox string, options *imap.SelectOptions) (*imap.SelectData, error) { data := &imap.SelectData{ Flags: []imap.Flag{imap.FlagSeen, imap.FlagDeleted, imap.FlagDraft}, PermanentFlags: []imap.Flag{imap.FlagSeen, imap.FlagDeleted, imap.FlagDraft, imap.FlagWildcard}, NumMessages: uint32(len(messages)), UIDValidity: 12345, UIDNext: 100, } return data, nil } // ... implement other required methods func main() { server := imapserver.New(&imapserver.Options{ NewSession: func(conn *imapserver.Conn) (imapserver.Session, *imapserver.GreetingData, error) { return &MySession{}, &imapserver.GreetingData{}, nil }, Caps: imap.CapSet{ imap.CapIMAP4rev2: {}, imap.CapIdle: {}, imap.CapMove: {}, }, }) if err := server.ListenAndServe(":143"); err != nil { log.Fatal(err) } } ``` -------------------------------- ### List IMAP mailboxes Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Lists mailboxes matching a pattern and reference. Use the returned command handle to iterate through results. ```go func (c *Client) List(mailboxName, reference string, options *imap.ListOptions) *ListCommand type ListCommand struct { // ... } func (cmd *ListCommand) Next() *imap.ListData func (cmd *ListCommand) Close() error ``` ```go cmd := client.List("*", "", &imap.ListOptions{ ReturnSubscribed: true, }) defer cmd.Close() for mbox := cmd.Next(); mbox != nil; mbox = cmd.Next() { fmt.Printf("Mailbox: %s, Delim: %c\n", mbox.Mailbox, mbox.Delim) } ``` -------------------------------- ### Implement IDLE Client Notifications Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Use the IDLE extension to receive real-time mailbox updates. Requires checking for CapIdle support before initiating the idle state. ```go // Check for IDLE support if !client.Caps().Has(imap.CapIdle) { log.Fatal("IDLE not supported") } // Set up notification handler opts := &imapclient.Options{ UnilateralDataHandler: &imapclient.UnilateralDataHandler{ Mailbox: func(data *imapclient.UnilateralDataMailbox) { if data.NumMessages != nil { fmt.Printf("Message count: %d\n", *data.NumMessages) } }, Expunge: func(seqNum uint32) { fmt.Printf("Message expunged: %d\n", seqNum) }, }, } client, _ := imapclient.DialTLS("imap.example.com:993", opts) // Idle until interrupted stop := make(chan struct{}) go func() { time.Sleep(5 * time.Minute) close(stop) }() client.Idle(stop).Wait() ``` -------------------------------- ### Select Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Selects a mailbox for reading and optionally writing. ```APIDOC ## func (s Session) Select(mailbox string, options *imap.SelectOptions) (*imap.SelectData, error) ### Description Selects a mailbox for reading (and optionally writing). ### Parameters - **mailbox** (string) - Required - Mailbox name - **options** (*imap.SelectOptions) - Required - Selection options ### Returns - **(*imap.SelectData, error)** - Mailbox info ``` -------------------------------- ### Wait for Server Greeting Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Blocks until the server's initial greeting is received. Must be called before issuing commands unless Caps() is used. ```go if err := client.WaitGreeting(); err != nil { log.Fatal("Server greeting failed:", err) } ``` -------------------------------- ### Perform LIST with STATUS data Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Use ListOptions to request status information like message counts during a mailbox list operation. ```go opts := &imap.ListOptions{ ReturnStatus: &imap.StatusOptions{ NumMessages: true, NumUnseen: true, }, } cmd := client.List("*", "", opts) for mbox := cmd.Next(); mbox != nil; mbox = cmd.Next() { if mbox.Status != nil { fmt.Printf("%s: %d unseen\n", mbox.Mailbox, *mbox.Status.NumUnseen) } } ``` -------------------------------- ### Define IMAP Search Options Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/search-and-filtering.md Defines the configuration structure for IMAP search return values. ```go type SearchOptions struct { ReturnMin bool ReturnMax bool ReturnAll bool ReturnCount bool ReturnSave bool } ``` -------------------------------- ### CapSet Methods Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/core-types-and-constants.md Methods available on the CapSet type to query server capabilities and supported features. ```APIDOC ## CapSet Methods ### Has `func (set CapSet) Has(c Cap) bool` Checks if a specific capability is supported by the server, including handling of implied capabilities. ### Copy `func (set CapSet) Copy() CapSet` Returns a deep copy of the current capability set. ### AuthMechanisms `func (set CapSet) AuthMechanisms() []string` Returns a list of supported SASL authentication mechanisms. ### AppendLimit `func (set CapSet) AppendLimit() (limit *uint32, ok bool)` Returns the server's append size limit if it is available. ### QuotaResourceTypes `func (set CapSet) QuotaResourceTypes() []QuotaResourceType` Returns the list of supported quota resource types. ### ThreadAlgorithms `func (set CapSet) ThreadAlgorithms() []ThreadAlgorithm` Returns the list of supported message threading algorithms. ``` -------------------------------- ### Create, Delete, and Rename Mailbox Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Performs administrative actions on mailboxes. ```go // Create if err := client.Create("Archive").Wait(); err != nil { log.Fatal(err) } // Delete if err := client.Delete("Archive").Wait(); err != nil { log.Fatal(err) } // Rename if err := client.Rename("Archive", "Old").Wait(); err != nil { log.Fatal(err) } ``` -------------------------------- ### Mailbox Listing Structures Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/mailbox-operations.md Defines the options for listing mailboxes and the data returned for each mailbox entry. ```go type ListOptions struct { SelectSubscribed bool SelectRemote bool SelectRecursiveMatch bool SelectSpecialUse bool ReturnSubscribed bool ReturnChildren bool ReturnStatus *StatusOptions ReturnSpecialUse bool } type ListData struct { Attrs []MailboxAttr Delim rune Mailbox string ChildInfo *ListDataChildInfo OldName string Status *StatusData } type ListDataChildInfo struct { Subscribed bool } ``` -------------------------------- ### Login to IMAP server Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Performs plaintext authentication using username and password. ```go func (c *Client) Login(username, password string) *Command ``` ```go if err := client.Login("user@example.com", "password").Wait(); err != nil { log.Fatal("Login failed:", err) } ``` -------------------------------- ### ListWriter Interface Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Used for writing LIST responses. ```go type ListWriter struct { // ... } func (w *ListWriter) WriteList(data *imap.ListData) error ``` -------------------------------- ### Create Custom Client with IDLE Extension Source: https://github.com/emersion/go-imap/wiki/Using-extensions Define a custom IMAP client struct that embeds the base client and the IDLE extension client. This allows for a unified interface to access both standard and extension functionalities. ```go type IMAPClient struct { *client.Client *idle.IdleClient } func NewIMAPClient(c *imap.Client) *IMAPClient { return &IMAPClient{ c, idle.NewClient(c), } } ``` -------------------------------- ### Session Rename Method Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/server-api-reference.md Renames a mailbox. ```go func (s Session) Rename(mailbox, newName string, options *imap.RenameOptions) error ``` -------------------------------- ### Search with Boolean Operators in Go Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/usage-examples.md Demonstrates nesting criteria within an Or slice to implement complex boolean logic. ```go // (Flagged OR Subject contains "important") AND Unseen criteria := &imap.SearchCriteria{ Or: [][2]imap.SearchCriteria{ { {Flag: []imap.Flag{imap.FlagFlagged}}, {Header: []imap.SearchCriteriaHeaderField{ {Key: "Subject", Value: "important"}, }}, }, }, Flag: []imap.Flag{imap.FlagUnseen}, } data, err := client.Search(criteria, nil) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Define BINARY fetch types Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/extension-capabilities.md Structures for handling binary content sections and their sizes during fetch operations. ```go type FetchItemBinarySection struct { Part []int Partial *SectionPartial Peek bool } type FetchItemBinarySectionSize struct { Part []int } ``` -------------------------------- ### Send NOOP command Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Sends a NOOP command to check the connection status. ```go func (c *Client) Noop() *Command ``` ```go if err := client.Noop().Wait(); err != nil { fmt.Println("Connection error:", err) } ``` -------------------------------- ### WaitGreeting Source: https://github.com/emersion/go-imap/blob/v2/_autodocs/client-api-reference.md Blocks until the server's initial greeting is received. Must be called before issuing commands. ```APIDOC ## func (c *Client) WaitGreeting() error ### Description Blocks until the server's initial greeting is received. Must be called before issuing commands, or use Caps() which calls it implicitly. ### Returns - **error** - Greeting error or nil ```