簡體   English   中英

如何使用AE.Net.Mail獲取郵箱列表?

[英]How to get list of mailboxes using AE.Net.Mail?

我正在嘗試使用AE.Net.Mail獲取郵箱列表,但我找不到任何文檔。 ListMailboxes方法接受引用字符串和模式字符串。 我不確定這兩個參數應該是什么。

using (var imap = new AE.Net.Mail.ImapClient(host, username, password, AE.Net.Mail.ImapClient.AuthMethods.Login, port, isSSL))
{
    List<Mailbox> boxes = imap.ListMailboxes("", ""); // string reference, string parameter
}

我發現這個工作:

var listMailboxes = imap.ListMailboxes(string.Empty, "*");

foreach (var listMailbox in listMailboxes)
{
    var mailbox = listMailbox.Name;                    
}

ImapClient.ListMailboxes方法是IMAP LIST命令的一個非常薄的包裝器。

public Mailbox[] ListMailboxes(string reference, string pattern) 
{
    IdlePause();

    var x = new List<Mailbox>();
    string command = GetTag() + "LIST " + reference.QuoteString() + " " + pattern.QuoteString();
    string reg = "\\* LIST \\(([^\\)]*)\\) \\\"([^\\\"]+)\\\" \\\"?([^\\\"]+)\\\"?";
    string response = SendCommandGetResponse(command);
    Match m = Regex.Match(response, reg);
    while (m.Groups.Count > 1) 
    {
        Mailbox mailbox = new Mailbox(m.Groups[3].ToString());
        x.Add(mailbox);
        response = GetResponse();
        m = Regex.Match(response, reg);
    }
    IdleResume();
    return x.ToArray();
}

IMAP RFC的第6.3.8節包含一些示例,說明IMAP服務器通常如何解釋這些參數(“郵箱名稱”是pattern參數):

Reference     Mailbox Name  Interpretation
------------  ------------  --------------
~smith/Mail/  foo.*         ~smith/Mail/foo.*
archive/      %             archive/%
#news.        comp.mail.*   #news.comp.mail.*
~smith/Mail/  /usr/doc/foo  /usr/doc/foo
archive/      ~fred/Mail/*  ~fred/Mail/*

雖然它也對Reference參數說了以下內容:

注意:引用參數的解釋是實現定義的。 這取決於服務器實現是否具有“當前工作目錄”的概念和引導“突破字符”,它覆蓋當前工作目錄。

因此,根據您的服務器實現,這些示例可能有效,也可能無效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM