My simple POP3 client (set up for Gmail) isn't downloading all of my messages...
Any idea why?
I have 350 messages in my inbox and the program only says 296 of them show up.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Net.Security;
using System.IO;
using System.Data;
namespace POP3Sharp
{
class Program
{
static void Main(string[] args)
{
PopGmail mail = new PopGmail();
Console.Write("Email: ");
string email = Console.ReadLine();
Console.Write("Password: ");
string password = Console.ReadLine();
Console.WriteLine("Connecting.");
if (!mail.Connect("pop.gmail.com", 995))
{
Console.WriteLine("Connect failed, attempted connection to pop.gmail.com on port 995 (client).");
return;
}
Console.WriteLine("Connected.");
if (!mail.Login(email, password))
{
Console.WriteLine("Login failed, valid username/pass? POP3 enabled on gmail settings?");
return;
}
int messageCount = mail.GetMailCount();
Console.WriteLine("Number of email messages reported: " + messageCount.ToString());
//for(int i = 1; i <= messageCount; i++)
//{
// byte[] bt = Encoding.ASCII.GetBytes(mail.GetMessage(i));
// FileStream fs = new FileStream("Emails\\" + i.ToString() + ".txt", System.IO.FileMode.Create);
// fs.Write(bt, 0, bt.Length);
// fs.Close();
//}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
mail.Disconnect();
}
}
}
and more importantly,
POPGmail.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Security;
using System.Net.Sockets;
using System.Web;
using System.Windows.Forms;
namespace POP3Sharp
{
class PopGmail
{
TcpClient m_tcpClient = new TcpClient();
SslStream m_sslStream;
int m_mailCount;
byte[] m_buffer = new byte[8172];
public PopGmail()
{
m_mailCount = -1;
}
/// <summary>
/// Connect to pop3 server "host" using "port" and auth SSL as client.
/// </summary>
/// <param name="host"></param>
/// <param name="port"></param>
/// <returns></returns>
public bool Connect(string host, int …