当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.List方法代码示例

本文整理汇总了Golang中code/google/com/p/go-imap/go1/imap.Client.List方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.List方法的具体用法?Golang Client.List怎么用?Golang Client.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code/google/com/p/go-imap/go1/imap.Client的用法示例。


在下文中一共展示了Client.List方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetFolders

//= Return list of IMAP folders
func GetFolders(client *imap.Client) ([]*Folder, error) {

	folders := make([]*Folder, 0)

	cmd, err := imap.Wait(client.List("", "*"))
	if err != nil {
		return folders, err
	}

	for idx := range cmd.Data {
		info := cmd.Data[idx].MailboxInfo()
		fol := new(Folder)
		fol.Name = info.Name
		for flag, boo := range info.Attrs {
			fmt.Println(info.Name, boo, flag)
			if info.Name == "INBOX" && boo {
				fol.Type = "inbox"

			} else if flag == "\\Junk" && boo {
				fol.Type = "junk"

			} else if flag == "\\Trash" && boo {
				fol.Type = "trash"

			} else if flag == "\\Sent" && boo {
				fol.Type = "sent"

			} else if flag == "\\Drafts" && boo {
				fol.Type = "drafts"
			}

		}
		folders = append(folders, fol)
	}

	return folders, nil
}
开发者ID:daffodil,项目名称:go-mailkit,代码行数:38,代码来源:folder.go

示例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)
		}
	}
}
开发者ID:kaihendry,项目名称:go-imap,代码行数:89,代码来源:example_test.go


注:本文中的code/google/com/p/go-imap/go1/imap.Client.List方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。