本文整理匯總了Golang中code/google/com/p/go-imap/go1/imap.Client.Fetch方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Fetch方法的具體用法?Golang Client.Fetch怎麽用?Golang Client.Fetch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/go-imap/go1/imap.Client
的用法示例。
在下文中一共展示了Client.Fetch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetAllMessages
func GetAllMessages(conn *imap.Client) (*imap.Command, error) {
// get headers and UID for ALL message in src inbox...
allMsgs, _ := imap.NewSeqSet("")
allMsgs.Add("1:*")
cmd, err := imap.Wait(conn.Fetch(allMsgs, "RFC822.HEADER", "UID"))
if err != nil {
return &imap.Command{}, err
}
return cmd, nil
}
示例2: ExampleClient
func ExampleClient() {
//
// Note: most of error handling code is omitted for brevity
//
var (
c *imap.Client
cmd *imap.Command
rsp *imap.Response
)
// Connect to the server
c, _ = imap.Dial("imap.example.com")
// Remember to log out and close the connection when finished
defer c.Logout(30 * time.Second)
// Print server greeting (first response in the unilateral server data queue)
fmt.Println("Server says hello:", c.Data[0].Info)
c.Data = nil
// Enable encryption, if supported by the server
if c.Caps["STARTTLS"] {
c.StartTLS(nil)
}
// Authenticate
if c.State() == imap.Login {
c.Login("[email protected]", "mysupersecretpassword")
}
// List all top-level mailboxes, wait for the command to finish
cmd, _ = imap.Wait(c.List("", "%"))
// Print mailbox information
fmt.Println("\nTop-level mailboxes:")
for _, rsp = range cmd.Data {
fmt.Println("|--", rsp.MailboxInfo())
}
// Check for new unilateral server data responses
for _, rsp = range c.Data {
fmt.Println("Server data:", rsp)
}
c.Data = nil
// Open a mailbox (synchronous command - no need for imap.Wait)
c.Select("INBOX", true)
fmt.Print("\nMailbox status:\n", c.Mailbox)
// Fetch the headers of the 10 most recent messages
set, _ := imap.NewSeqSet("")
if c.Mailbox.Messages >= 10 {
set.AddRange(c.Mailbox.Messages-9, c.Mailbox.Messages)
} else {
set.Add("1:*")
}
cmd, _ = c.Fetch(set, "RFC822.HEADER")
// Process responses while the command is running
fmt.Println("\nMost recent messages:")
for cmd.InProgress() {
// Wait for the next response (no timeout)
c.Recv(-1)
// Process command data
for _, rsp = range cmd.Data {
header := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.HEADER"])
if msg, _ := mail.ReadMessage(bytes.NewReader(header)); msg != nil {
fmt.Println("|--", msg.Header.Get("Subject"))
}
}
cmd.Data = nil
// Process unilateral server data
for _, rsp = range c.Data {
fmt.Println("Server data:", rsp)
}
c.Data = nil
}
// Check command completion status
if rsp, err := cmd.Result(imap.OK); err != nil {
if err == imap.ErrAborted {
fmt.Println("Fetch command aborted")
} else {
fmt.Println("Fetch error:", rsp.Info)
}
}
}