Пример #1
0
        public void OkCommand(object ownerWindow)
        {
            MailProviderFactory emailFactory = null;

            switch (_selectedReceiveConfiguration.Protocol)
            {
                case EmailProtocolType.Imap:
                    emailFactory = new ImapProviderFactory();
                    break;
                case EmailProtocolType.Pop3:
                    emailFactory = new Pop3ProviderFactory();
                    break;
                default:
                    break;
            }

            MailConnection connection = emailFactory.CreateConnection();
            connection.Host = _selectedReceiveConfiguration.Host;
            connection.IsSslAuthentication = _selectedReceiveConfiguration.IsSslAuthentication;
            connection.Port = _selectedReceiveConfiguration.Port;
            ////connection.Open();
            SslMailConnectionDecorator sslMailConnectionDecorator = new SslMailConnectionDecorator();
            sslMailConnectionDecorator.MailConnection = connection;
            sslMailConnectionDecorator.Open();
            MailClient client = emailFactory.CreateClient();
            client.Authenticate(new MailUserInfo() { Email = _login, Password = _securePassword });

            new MainWindow() { DataContext = new MainWindowVM(client) }.Show();
            ((Window)ownerWindow).Close();
        }
Пример #2
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();
        }