Exemplo n.º 1
0
        public override object PullDataFromServer(SslStream ssl, int flag)
        {
            ImapConsole console = new ImapConsole(ssl);

            console.SendCommand(new ImapGetTextOfLetter(flag));
            string letterText = (string)console.ExecuteCommand();

            return letterText;
        }
Exemplo n.º 2
0
        public override SslStream Authenticate(Profile user)
        {
            ImapConsole console = new ImapConsole();
            SslStream ssl = console.SetSSLConnectionAndReturn(user);
            console.SendCommand(new ImapAuthenticate(user));
            console.ExecuteCommand();

            return ssl;
        }
Exemplo n.º 3
0
        public Letter CheckLetterByIMAP(Profile user, int letterNum)
        {
            Letter newLetter = new Letter();
            newLetter.SetId();
            newLetter.ProfileId = user.Id;
            newLetter.To = user.Adress;
            newLetter.Category = "Inbox";

            bool subjectFound = false;
            bool dateFound = false;
            bool fromFound = false;

            ImapConsole console = new ImapConsole();
            console.SetSSLConnection(user);
            console.SendCommand(new ImapAuthenticate(user));
            console.ExecuteCommand();

            this.ImapRequest("$ SELECT INBOX\r\n");

            console.SendCommand(new ImapGetHeaderOfLetter(letterNum));
            List<string> letterHeader = (List<string>)console.ExecuteCommand();

            foreach (string line in letterHeader)
            {
                if (!fromFound && line.Contains("From: "))
                {
                    string thisLine = line;
                    if (line.Contains("<"))
                    {
                        thisLine = line.Substring(line.IndexOf('<') + 1, line.IndexOf('>') - line.IndexOf('<') - 1);
                        newLetter.From = thisLine;
                    }
                    else
                    {
                        newLetter.From = thisLine.Substring(6);
                    }

                    fromFound = true;
                }

                if (!dateFound && line.Length > 6 && line.Substring(0, 6) == "Date: ")
                {
                    string thisLine = line;
                    if (line.Contains("+"))
                    {
                        thisLine = line.Substring(0, line.IndexOf('+'));
                    }
                    else if (line.Contains("-"))
                    {
                        thisLine = line.Substring(0, line.IndexOf('-'));
                    }
                    
                    newLetter.SendingTime = Convert.ToDateTime(thisLine.Substring(6));
                    dateFound = true;
                }

                if (!subjectFound && line.Contains("Subject: "))
                {
                    newLetter.Subject = line.Substring(9).Replace("\r", string.Empty);
                    if (newLetter.Subject.Substring(0, 5) == "=?utf")
                    {
                        newLetter.Subject = newLetter.Subject.Substring(10, newLetter.Subject.Length - 10);
                        interpreterContext iC = new interpreterContext(newLetter.Subject);
                        DefaultExpression ex = new DefaultExpression();
                        ex.Interpret(iC);
                        newLetter.Subject = ex.UseEncoding(iC);
                    }

                    subjectFound = true;
                }

                if (subjectFound && dateFound && fromFound)
                {
                    break;
                }
            }

            console.SetSSLConnection(user);
            console.SendCommand(new ImapAuthenticate(user));
            console.ExecuteCommand();
            this.ImapRequest("$ SELECT INBOX\r\n");

            console.SendCommand(new ImapGetTextOfLetter(letterNum));
            newLetter.Body = (string)console.ExecuteCommand();

            return newLetter;
        }
Exemplo n.º 4
0
        public int GetTotalLetterNum(Profile user)
        {
            int result = 0;
            ImapConsole console = new ImapConsole();
            console.SetSSLConnection(user);
            console.SendCommand(new ImapAuthenticate(user));
            console.ExecuteCommand();
            this.ImapRequest("$ SELECT INBOX\r\n");
            string answer = this.ImapRequest("$ STATUS INBOX (MESSAGES)\r\n");
            foreach (string line in answer.Split('\n'))
            {
                if (line.Contains("EXISTS"))
                {
                    result = Convert.ToInt32(line.Substring(2, line.IndexOf('E') - 2));
                    this.ImapRequest("$ LOGOUT\r\n");
                }
            }

            return result;
        }