Exemplo n.º 1
0
        public List <UidlItem> GetUidl()
        {
            lock (this) {
                NetworkStream siso = sock.GetStream();
                SL.WriteLine(siso, "UIDL");

                if ((resp = Resp.ReadFrom(siso)).Ok != true)
                {
                    throw new CommandFailedException();
                }

                List <UidlItem> al = new List <UidlItem>();
                while (true)
                {
                    string s = RL.ReadLine(siso);
                    if (s.StartsWith("."))
                    {
                        break;
                    }
                    string[] cols = s.Split(' ');
                    UidlItem o    = new UidlItem();
                    o.i    = int.Parse(cols[0]);
                    o.uidl = cols[1];
                    al.Add(o);
                }
                return(al);
            }
        }
Exemplo n.º 2
0
        public POP3(String host, int port, String user, String pass)
        {
            sock = new TcpClient();
            sock.Connect(host, port);
            NetworkStream siso = sock.GetStream();

            if ((resp = Resp.ReadFrom(siso)).Ok != true)
            {
                throw new CommException();
            }

            Match M = Regex.Match(resp.Message, "(\\<.+\\>)");

            if (M.Success)
            {
                byte[] hasher = Encoding.ASCII.GetBytes(M.Groups[1].Value + pass);

                SL.WriteLine(siso, "APOP " + user + " " + Ut.H2S(MD5.Create().ComputeHash(hasher)));

                if ((resp = Resp.ReadFrom(siso)).Ok != true)
                {
                    throw new APOPCommandFailedException(resp.Message);
                }
            }
            else
            {
                throw new CommandFailedException();
            }
        }
Exemplo n.º 3
0
        public string Top(int i, int cnt)
        {
            lock (this) {
                NetworkStream siso = sock.GetStream();
                SL.WriteLine(siso, "TOP " + i + " " + cnt);

                if ((resp = Resp.ReadFrom(siso)).Ok != true)
                {
                    throw new CommandFailedException(resp.Message);
                }

                StringBuilder res = new StringBuilder();
                while (true)
                {
                    string s = RL.ReadLine(siso);
                    if (s.Equals("."))
                    {
                        break;
                    }
                    res.Append(s).Append("\r\n");
                }
                return(res.ToString());
            }
        }
Exemplo n.º 4
0
        public string Retrieve(int i)
        {
            lock (this) {
                NetworkStream siso = sock.GetStream();
                SL.WriteLine(siso, "RETR " + i);

                if ((resp = Resp.ReadFrom(siso)).Ok != true)
                {
                    throw new CommandFailedException();
                }

                StringBuilder res = new StringBuilder(1024 * 1024);
                while (true)
                {
                    string s = RL.ReadLine(siso);
                    if (s.Equals("."))
                    {
                        break;
                    }
                    res.Append(s).Append("\r\n");
                }
                return(res.ToString());
            }
        }