ImapClient.GetAllHeaders C# (CSharp) Method

GetAllHeaders() public method

public GetAllHeaders ( string mailbox, bool seen = true ) : List
mailbox string
seen bool
return List
    public List<Message> GetAllHeaders(string mailbox, bool seen = true)
    {
        SelectMailbox(mailbox);
        string tagStr = GetTag();
        writestreamdata(tagStr + "FETCH 1:* (BODY" + (seen ? "" : ".PEEK") + "[HEADER])\r\n");
        List<string> headerdata = readstreamdata(tagStr + "OK");
        List<Message> headers = new List<Message>();
        Message currentMsg = null;
        foreach (string header in headerdata)
        {
            Regex r = new Regex("[*] [0-9]+ FETCH [(]BODY[\\[]HEADER[\\]] [{](?<UID>[0-9]+)[}]\r\n");
            Match m = r.Match(header);
            if (m.Groups["UID"] != null && m.Groups["UID"].Value != null && m.Groups["UID"].Value.Length > 0)
            {
                if (currentMsg != null)
                {
                    headers.Add(currentMsg);
                }
                currentMsg = new Message();
                currentMsg.UID = m.Groups["UID"].Value;
                Regex r1 = new Regex("[*] (?<ID>[0-9]+) FETCH .+");
                Match m1 = r1.Match(header);
                if (m1.Groups["ID"] != null && m1.Groups["ID"].Value != null && m1.Groups["ID"].Value.Length > 0)
                {
                    currentMsg.ID = m1.Groups["ID"].Value;
                }
            }
            else
            {
                r = new Regex("Date[:] (?<Date>[A-z]+, [0-9]+ [A-z]+ [0-9]+ [0-9]+[:][0-9]+[:][0-9]+) .+\r\n");
                m = r.Match(header);
                if (m.Groups["Date"] != null && m.Groups["Date"].Value != null && m.Groups["Date"].Value.Length > 0)
                {
                    currentMsg.Date = DateTime.Parse(m.Groups["Date"].Value);
                }
                else
                {
                    if (header.StartsWith("From: "))
                    {
                        currentMsg.From = header.Substring(6, header.Length - 8);
                    }
                    else
                    {
                        if (header.StartsWith("To: "))
                        {
                            currentMsg.To = header.Substring(4, header.Length - 6);
                        }
                        else
                        {
                            if (header.StartsWith("Subject: "))
                            {
                                currentMsg.Subject = header.Substring(9, header.Length - 11);
                            }
                        }
                    }
                }
            }
        }
        headers.Add(currentMsg);
        return headers;
    }

Usage Example

コード例 #1
0
 public void getEmailHeaders(string canvasid, int windowid)
 {
     ImapClient imp = new ImapClient(ccl.InputParams[2].ToString(), 993, ccl.InputParams[0].ToString(), ccl.InputParams[1].ToString(), true);
     List<ImapClient.Message> headers = imp.GetAllHeaders(ccl.InputParams[3].ToString());
     int count = 0;
     foreach (ImapClient.Message msg in headers)
     {
         List<object> arlmsg = new List<object>();
         arlmsg.Add(msg.From);
         arlmsg.Add(msg.Subject);
         arlmsg.Add("");
         arlmsg.Add(msg.Date.ToString());
         arlmsg.Add("");
         arlmsg.Add(msg.ID);
         parameters.Add(arlmsg);
         count++;
     }
     imp.Logout();
 }
All Usage Examples Of ImapClient::GetAllHeaders