public override void Open()
        {
            base.Open();
            MailConnection.EmailStreamReader = new StreamReader(MailConnection.TcpClient.GetStream());
            MailConnection.EmailStream       = MailConnection.TcpClient.GetStream();
            LoggerHolders.ConsoleLogger.Log(MailConnection.EmailStreamReader.ReadLine());
            MailCommand command = MailConnection.CreateCommand();

            command.Command = "STARTTLS";
            command.ExecuteCommand();

            LoggerHolders.ConsoleLogger.Log(command.Response);

            var sslStrm = new SslStream(MailConnection.TcpClient.GetStream(), false);

            try
            {
                sslStrm.AuthenticateAsClient(MailConnection.Host);
            }
            catch (AuthenticationException ex)
            {
                LoggerHolders.ConsoleLogger.Log("Exception", LogType.Critical, ex);
                if (ex.InnerException != null)
                {
                    LoggerHolders.ConsoleLogger.Log("Exception", LogType.Critical, ex.InnerException);
                }
                MailConnection.TcpClient.Close();
            }

            MailConnection.EmailStream       = sslStrm;
            MailConnection.EmailStreamReader = new StreamReader(sslStrm);
        }
Beispiel #2
0
        public override void LogOut()
        {
            MailCommand command = Connection.CreateCommand();

            command.Command = Pop3.POP3_QUIT;
            command.ExecuteCommand();
        }
Beispiel #3
0
        public override void LogOut()
        {
            MailCommand command = Connection.CreateCommand();

            command.Command = Imap.IMAP_LOGOUT;
            command.ExecuteCommand();
            LoggerHolders.ConsoleLogger.Log(command.Response, LogType.Debug);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            string        result = "";
            string        url    = @"http://*****:*****@gmail.com", Password = securePass });



            MailCommand command = client.Connection.CreateCommand();

            command.Command = "AUTHENTICATE XOAUTH DQAAAA0BAACM5VezEB1fG75L4oTHjEnfHS-YuSLBUe_OKL9QFCcgxqP7SLkk_6AFgCqFdNWnId_ohkmTShCeb5rkgdZR5zceaMoIPDyCY4rWkyMjY8S-2vmkXSgHLUTmhZyZLPT3j7rAnEou-QEdHxjKpqiZ8a04QiOqvhIOWmN9JEWBxSYqdM5eIH8xG4pz19c6TWUhq1PJCYCyNsU384uNyFanJ-tg0z9c1dF1mgqLscbYZz82RKsZAPyu9Um2VrWWSW9r_56_OW7JJT709cte1jx0h29HEhF5J_4LZ1Md5bGHUFJQPS7-gJBLJApaVxWZfhpc_r19sNzaqdZYsIuUxRM65jiYXPomvozXSK4ASonS1cXu3g";
            command.ExecuteCommand();
            LoggerHolders.ConsoleLogger.Log(command.Response);
            command.Command = "RETR 300";
            command.ExecuteCommand(true);
            LoggerHolders.ConsoleLogger.Log(command.Response);
            StreamWriter writer = new StreamWriter(@"C:\fetch.log");

            writer.Write(command.Response);
            writer.Close();



            //MailProviderFactory emailFactory = new ImapProviderFactory();
            //MailConnection connection = emailFactory.CreateConnection();
            ////connection.Host = config.Imap.Host;
            ////connection.IsSslAuthentication = config.Imap.IsSslAuthentication;
            ////connection.Port = config.Imap.Port;
            ////connection.SecureTypeConnection = new SslMailConnection();
            //connection.Host = "imap.mail.ru";
            //connection.IsSslAuthentication = true;
            //connection.Port = 143;
            //SecureMailConnectionDecorator sslMailConnection = new TlsMailConnectionDecorator();
            //sslMailConnection.MailConnection = connection;
            //sslMailConnection.Open();
            //MailClient client = emailFactory.CreateClient();
            //client.Authenticate(new MailUserInfo() { Email = "*****@*****.**", Password = securePass });

            //connection.Host = "imap.mail.ru";
            //connection.IsSslAuthentication = true;
            //connection.Port = 143;
            //connection.Open();
            //MailClient client = emailFactory.CreateClient();
            //MailCommand com = client.Connection.CreateCommand();
            //com.Command = "STARTTLS";
            //com.ExecuteCommand();

            //var ssl = client.Connection._tcpClient.GetStream();
            //client.Connection._emailStream = ssl;
            //client.Connection._emailsStreamReader = new StreamReader(ssl);
            //Console.WriteLine(client.Connection._emailsStreamReader.ReadLine());



            //Thread.Sleep(5000);

            //com.Command = "CAPABILITY";
            //com.ExecuteCommand();



            //LoggerHolders.ConsoleLogger.Log(com.Response, LogType.Debug);


            //client.Authenticate(new MailUserInfo() { Email = "*****@*****.**", Password = securePass });
            //com.Command = "AUTH PLAIN";
            //com.ExecuteCommand();

            //////MailCommand command = client.Connection.CreateCommand();
            ////////command.Command = "STATUS INBOX (messages)";
            ////////command.ExecuteCommand();
            ////////LoggerHolders.ConsoleLogger.Log(command.Response);

            //////command.Command = "SELECT INBOX";
            //////command.ExecuteCommand();
            //////LoggerHolders.ConsoleLogger.Log(command.Response);

            //////command.Command = "FETCH " + 5343 + " (body[header.fields (from subject date)])";
            //////command.ExecuteCommand();
            //////LoggerHolders.ConsoleLogger.Log(command.Response, LogType.Debug);
            ///
            ///
            ///



            //StreamReader readerHeader = new StreamReader(@"C:\header.txt");

            //string header = readerHeader.ReadToEnd();
            //readerHeader.Close();
            //LoggerHolders.ConsoleLogger.Log(header, LogType.Info);

            ////string pat =
            ////    @"Subject: (?<encodedName>(=\?[A-Za-z0-9-]+\?(B|Q|b|q)\?.+\?=[\s]*)+)";

            ////Regex regex = new Regex(pat);
            ////Match match = regex.Match(header);

            ////Console.WriteLine(match.Groups["encodedName"].Value);

            //IMailMessageBuilder builder = new ReceiveMailMessageBuilder(header);
            //MailMessageDirector director = new MailMessageDirector(builder);
            //director.ConstructMailMessage();
            //MailMessage messageHeader = builder.GetMailMessage();
            //LoggerHolders.ConsoleLogger.Log(string.Format("From: {0} <{1}>\nSubject: {2}\nDate: {3}\n{4}",
            //    messageHeader.FromName, messageHeader.From, messageHeader.Subject, messageHeader.Date,
            //    messageHeader.DateLocal), LogType.Debug);

            Console.ReadLine();
        }
Beispiel #5
0
        private void LoadFirs100Messages()
        {
            StringBuilder builde  = new StringBuilder(100);
            MailCommand   command = _client.Connection.CreateCommand();

            command.Command = "STATUS INBOX (messages)";
            command.ExecuteCommand();
            LoggerHolders.ConsoleLogger.Log(command.Response);
            string res   = command.Response;
            Match  m     = Regex.Match(res, "[0-9]*[0-9]");
            int    count = Convert.ToInt32(m.ToString());


            command.Command = "SELECT INBOX";
            command.ExecuteCommand();
            LoggerHolders.ConsoleLogger.Log(command.Response);

            for (int i = count; i > count - 2000; i--)
            {
                command.Command = "FETCH " + i + " (body[header.fields (from subject date)])";
                command.ExecuteCommand();

                IMailMessageBuilder builder  = new ReceiveMailMessageBuilder(command.Response);
                MailMessageDirector director = new MailMessageDirector(builder);
                director.ConstructMailMessage();

                if (string.IsNullOrWhiteSpace(builder.GetMailMessage().Subject))
                {
                    builde.AppendLine(command.Response);
                    builde.AppendLine(Environment.NewLine);
                }
                else
                {
                    continue;
                }

                try
                {
                    Application.Current.Dispatcher.InvokeAsync(() =>
                    {
                        _mailMessages.Add(builder.GetMailMessage());
                    });
                }
                catch (Exception ex)
                {
                    LoggerHolders.ConsoleLogger.Log("Exception:", LogType.Error, ex);
                }
            }
            try
            {
                string       path   = @"C:\MAILdump.log";
                StreamWriter writer = new StreamWriter(path);
                writer.Write(builde.ToString());
                writer.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }



            ////IMailMessageBuilder builder = new ReceiveMailMessageBuilder(header);
            ////MailMessageDirector director = new MailMessageDirector(builder);
            ////director.ConstructMailMessage();
            ////MailMessage messageHeader = builder.GetMailMessage();
            //LoggerHolders.ConsoleLogger.Log(string.Format("From: {0} <{1}>\n Subject: {2}\n Date: {3}\n{4}",
            //    messageHeader.FromName, messageHeader.From, messageHeader.Subject, messageHeader.Date,
            //    messageHeader.DateLocal));
        }