/// <summary> /// Gets messages info. /// </summary> public Pop3MessagesInfo GetMessagesInfo() { if (!m_Connected) { throw new Exception("You must connect first !"); } if (!m_Authenticated) { throw new Exception("You must authenticate first !"); } Pop3MessagesInfo messagesInfo = new Pop3MessagesInfo(); // Before getting list get UIDL list, then we make full message info (UID,Nr,Size). Hashtable uidlList = GetUidlList(); streamHelper.Write("LIST" + "\r\n"); /* NOTE: If reply is +OK, this is multiline respone and is terminated with '.'. * Examples: * C: LIST * S: +OK 2 messages (320 octets) * S: 1 120 * S: 2 200 * S: . * ... * C: LIST 3 * S: -ERR no such message, only 2 messages in maildrop */ // Read first line of reply, check if it's ok string line = streamHelper.ReadToEnd(); if (line.StartsWith("+OK")) { // Read lines while get only '.' on line itshelf. while (true) { line = streamHelper.ReadToEnd(); // End of data if (line.Trim() == ".") { break; } else { string[] param = line.Trim().Split(new char[] { ' ' }); int nr = Convert.ToInt32(param[0]); long size = Convert.ToInt64(param[1]); messagesInfo.Add(uidlList[nr].ToString(), nr, size); } } } else { throw new Exception("Server returned:" + line); } return(messagesInfo); }
/// <summary> /// Gets messages info. /// </summary> public Pop3MessagesInfo GetMessagesInfo() { if (!m_Connected) { throw new Exception("You must connect first !"); } if (!m_Authenticated) { throw new Exception("You must authenticate first !"); } Pop3MessagesInfo messagesInfo = new Pop3MessagesInfo(); // Before getting list get UIDL list, then we make full message info (UID,Nr,Size). Hashtable uidlList = GetUidlList(); streamHelper.Write("LIST" + "\r\n"); /* NOTE: If reply is +OK, this is multiline respone and is terminated with '.'. Examples: C: LIST S: +OK 2 messages (320 octets) S: 1 120 S: 2 200 S: . ... C: LIST 3 S: -ERR no such message, only 2 messages in maildrop */ // Read first line of reply, check if it's ok string line = streamHelper.ReadToEnd(); if (line.StartsWith("+OK")) { // Read lines while get only '.' on line itshelf. while (true) { line = streamHelper.ReadToEnd(); // End of data if (line.Trim() == ".") { break; } else { string[] param = line.Trim().Split(new char[] { ' ' }); int nr = Convert.ToInt32(param[0]); long size = Convert.ToInt64(param[1]); messagesInfo.Add(uidlList[nr].ToString(), nr, size); } } } else { throw new Exception("Server returned:" + line); } return messagesInfo; }