如何使用 ImapX lib 获取 gmail 的所有文件夹名称?我在http://hellowebapps.com/2010-02-09/imapx-net-library-to-manage-imap-folders/中阅读但未找到获取所有文件夹部分。
问问题
4383 次
3 回答
0
您可以迭代 SubFolder 集合,并可以获得所有这些 gamail 文件夹及其路径。一个例子:
var client = new ImapClient(...);
client.Connection();
client.LogIn(...);
foreach (var item in WalkFolderTree(client.Folders))
{
Console.WriteLine(item.FolderPath);
}
client.LogOut();
您必须自定义实现遍历代码,例如:
public IEnumerable<Folder> WalkFolderTree(FolderCollection folders)
{
foreach (var item in folders)
{
if (item.HasChildren)
{
WalkFolderTree(item.SubFolder);
}
yield return item;
}
}
然后它将列出所有文件夹,例如:
INBOX
...
[Gmail]
[Gmail]/All Mail
[Gmail]/Drafts
[Gmail]/Sent Mail
[Gmail]/Spam
[Gmail]/Starred
[Gmail]/Trash
于 2011-05-05T14:15:39.227 回答
0
这是获取所有文件夹列表的方法...
FolderCollection folders = client.GetFolders();
foreach (Folder myfolder in folders)
{
MessageBox.Show(myfolder.Name);
}
然后使用名称:
ImapX.MessageCollection messages = client.Folders["Spam"].Search("ALL", true);
请注意,文件夹名称区分大小写...
于 2011-04-26T10:12:42.927 回答
0
就是这样:
public List<string> getMailboxes(string emailAddress, string emailPassword)
{
var client = new ImapClient("imap.gmail.com", 993, true, true);
if (client.Connect())
{
if (client.Login(emailAddress, emailPassword))
{
//get all parent folers
var folders = client.Folders;
foreach (var parentFolder in folders)
{
//get parent folder path
var parentPath = parentFolder.Path;
//check if every parent folder has subfolder
if (parentFolder.HasChildren)
{
var subfolders = parentFolder.SubFolders;
foreach(var subfolder in subfolders)
{
var subPath = subfolder.Path;
}
}
}
}
}
}
于 2017-07-08T04:26:05.053 回答