Exemplo n.º 1
0
        private void renew_Click(object sender, RoutedEventArgs e)
        {
            ChooseMail SW = new ChooseMail(File.ReadAllText(@"/user.txt"));

            if (M1.IsChecked == true)
            {
                SW.LoadIncomeMessages(ForFunctions, ForFunctions);
                LoadMessages();
            }
            if (M2.IsChecked == true)
            {
                SW.LoadSentMessages(ForFunctions, ForFunctions);
                LoadSentMessages();
            }
            if (M3.IsChecked == true)
            {
                SW.LoadSpamMessages(ForFunctions, ForFunctions);
                LoadSpamMessages();
            }
            if (M4.IsChecked == true)
            {
                SW.LoadTrashMessages(ForFunctions, ForFunctions);
                LoadTrashMessages();
            }
        }
Exemplo n.º 2
0
        private void deleteMS_Click(object sender, RoutedEventArgs e)
        {
            ChooseMail SW     = new ChooseMail(File.ReadAllText(@"/user.txt"));
            string     pochta = Convert.ToString(Chip.Content);

            try
            {
                if (M1.IsChecked == true)
                {
                    using (var _client = new ImapClient())
                    {
                        string IMapAddress = _SuffixData;
                        _client.ServerCertificateValidationCallback = (s, c, h, f) => true;
                        _client.Connect(IMapAddress, 993, true);
                        _client.Authenticate(pochta, _PWData);

                        while (MSList.SelectedItems.Count > 0)
                        {
                            var inb = _client.Inbox;
                            var tr  = _client.GetFolder(SpecialFolder.Trash);

                            var Themes = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Входящие/Theme.txt").ToList();
                            var From   = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Входящие/FromWho.txt").ToList();
                            var Data   = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Входящие/Date.txt").ToList();
                            var ID     = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Входящие/ID.txt").ToList();

                            uid = Themes.Count - ((Convert.ToInt32(IPage.Content) - 1) * 10) - MSList.SelectedIndex - 1;

                            char   strelochka = '>';
                            string email      = From[uid].Substring(From[uid].LastIndexOf('<') + 1, From[uid].Length - From[uid].LastIndexOf('<') - 1);
                            email = email.TrimEnd(strelochka);

                            string MessageID = "C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Входящие/Письма/" + ID[uid] + ".txt";

                            var message = new MimeMessage();
                            message.From.Add(new MailboxAddress(email));
                            message.To.Add(new MailboxAddress(pochta));
                            message.Subject = Themes[uid];
                            var builder = new BodyBuilder();
                            builder.TextBody = MessageID;
                            message.Body     = builder.ToMessageBody();

                            tr.Open(FolderAccess.ReadWrite);
                            tr.Append(message);
                            tr.Close();

                            inb.Open(FolderAccess.ReadWrite);

                            List <string> TThemes = new List <string>(); TThemes.Add(Themes[uid]);
                            List <string> TFrom   = new List <string>(); TFrom.Add(From[uid]);
                            List <string> TData   = new List <string>(); TData.Add(Data[uid]);
                            List <string> TID     = new List <string>(); TID.Add(ID[uid]);

                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/Theme.txt", TThemes);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/FromWho.txt", TFrom);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/Date.txt", TData);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/ID.txt", TID);

                            Themes.RemoveAt(uid);
                            From.RemoveAt(uid);
                            Data.RemoveAt(uid);
                            ID.RemoveAt(uid);

                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Входящие" + "/Theme.txt", Themes);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Входящие" + "/FromWho.txt", From);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Входящие" + "/Date.txt", Data);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Входящие" + "/ID.txt", ID);

                            //MSList.Items.Clear();
                            MSList.Items.RemoveAt(MSList.SelectedIndex);
                            //LoadMessages();

                            inb.AddFlags(uid, MessageFlags.Deleted, false);
                            inb.Expunge();
                            inb.Close();
                        }
                        _client.Disconnect(true);
                        SW.LoadIncomeMessages(ForFunctions, ForFunctions);
                        LoadMessages();
                    }
                }
                if (M2.IsChecked == true)
                {
                    using (var _client = new ImapClient())
                    {
                        string IMapAddress = _SuffixData;
                        _client.ServerCertificateValidationCallback = (s, c, h, f) => true;
                        _client.Connect(IMapAddress, 993, true);
                        _client.Authenticate(pochta, _PWData);

                        while (MSList.SelectedItems.Count > 0)
                        {
                            var inb = _client.GetFolder(SpecialFolder.Sent);
                            var tr  = _client.GetFolder(SpecialFolder.Trash);

                            var Themes = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Исходящие/Theme.txt").ToList();
                            var From   = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Исходящие/FromWho.txt").ToList();
                            var Data   = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Исходящие/Date.txt").ToList();
                            var ID     = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Исходящие/ID.txt").ToList();

                            int uid = Themes.Count - ((Convert.ToInt32(IPage.Content) - 1) * 10) - MSList.SelectedIndex - 1;

                            char   strelochka = '>';
                            string email      = From[uid].Substring(From[uid].LastIndexOf('<') + 1, From[uid].Length - From[uid].LastIndexOf('<') - 1);
                            email = email.TrimEnd(strelochka);

                            string MessageID = "C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Входящие/Письма/" + ID[uid] + ".txt";

                            var message = new MimeMessage();
                            message.From.Add(new MailboxAddress(email));
                            message.To.Add(new MailboxAddress(pochta));
                            message.Subject = Themes[uid];
                            var builder = new BodyBuilder();
                            builder.TextBody = MessageID;
                            message.Body     = builder.ToMessageBody();

                            tr.Open(FolderAccess.ReadWrite);
                            tr.Append(message);
                            tr.Close();

                            inb.Open(FolderAccess.ReadWrite);

                            List <string> TThemes = new List <string>(); TThemes.Add(Themes[uid]);
                            List <string> TFrom   = new List <string>(); TFrom.Add(From[uid]);
                            List <string> TData   = new List <string>(); TData.Add(Data[uid]);
                            List <string> TID     = new List <string>(); TID.Add(ID[uid]);

                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/Theme.txt", TThemes);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/FromWho.txt", TFrom);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/Date.txt", TData);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/ID.txt", TID);

                            Themes.RemoveAt(uid);
                            From.RemoveAt(uid);
                            Data.RemoveAt(uid);
                            ID.RemoveAt(uid);

                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Исходящие" + "/Theme.txt", Themes);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Исходящие" + "/FromWho.txt", From);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Исходящие" + "/Date.txt", Data);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Исходящие" + "/ID.txt", ID);

                            //MSList.Items.Clear();
                            MSList.Items.RemoveAt(MSList.SelectedIndex);
                            //LoadSentMessages();

                            inb.AddFlags(uid, MessageFlags.Deleted, false);
                            inb.Expunge();
                            inb.Close();
                        }
                        _client.Disconnect(true);
                        SW.LoadSentMessages(ForFunctions, ForFunctions);
                        LoadSentMessages();
                    }
                }
                if (M3.IsChecked == true)
                {
                    using (var _client = new ImapClient())
                    {
                        string IMapAddress = _SuffixData;
                        _client.ServerCertificateValidationCallback = (s, c, h, f) => true;
                        _client.Connect(IMapAddress, 993, true);
                        _client.Authenticate(pochta, _PWData);

                        while (MSList.SelectedItems.Count > 0)
                        {
                            var inb = _client.GetFolder(SpecialFolder.Junk);
                            var tr  = _client.GetFolder(SpecialFolder.Trash);

                            var Themes = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Спам/Theme.txt").ToList();
                            var From   = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Спам/FromWho.txt").ToList();
                            var Data   = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Спам/Date.txt").ToList();
                            var ID     = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Спам/ID.txt").ToList();

                            int uid = Themes.Count - ((Convert.ToInt32(IPage.Content) - 1) * 10) - MSList.SelectedIndex - 1;

                            char   strelochka = '>';
                            string email      = From[uid].Substring(From[uid].LastIndexOf('<') + 1, From[uid].Length - From[uid].LastIndexOf('<') - 1);
                            email = email.TrimEnd(strelochka);

                            string MessageID = "C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Входящие/Письма/" + ID[uid] + ".txt";

                            var message = new MimeMessage();
                            message.From.Add(new MailboxAddress(email));
                            message.To.Add(new MailboxAddress(pochta));
                            message.Subject = Themes[uid];
                            var builder = new BodyBuilder();
                            builder.TextBody = MessageID;
                            message.Body     = builder.ToMessageBody();

                            tr.Open(FolderAccess.ReadWrite);
                            tr.Append(message);
                            tr.Close();

                            inb.Open(FolderAccess.ReadWrite);

                            List <string> TThemes = new List <string>(); TThemes.Add(Themes[uid]);
                            List <string> TFrom   = new List <string>(); TFrom.Add(From[uid]);
                            List <string> TData   = new List <string>(); TData.Add(Data[uid]);
                            List <string> TID     = new List <string>(); TID.Add(ID[uid]);

                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/Theme.txt", TThemes);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/FromWho.txt", TFrom);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/Date.txt", TData);
                            File.AppendAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/ID.txt", TID);

                            Themes.RemoveAt(uid);
                            From.RemoveAt(uid);
                            Data.RemoveAt(uid);
                            ID.RemoveAt(uid);

                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Спам" + "/Theme.txt", Themes);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Спам" + "/FromWho.txt", From);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Спам" + "/Date.txt", Data);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Спам" + "/ID.txt", ID);

                            //MSList.Items.Clear();
                            MSList.Items.RemoveAt(MSList.SelectedIndex);
                            //LoadSpamMessages();

                            inb.AddFlags(uid, MessageFlags.Deleted, false);
                            inb.Expunge();
                            inb.Close();
                        }
                        _client.Disconnect(true);
                        SW.LoadSpamMessages(ForFunctions, ForFunctions);
                        LoadSpamMessages();
                    }
                }
                if (M4.IsChecked == true)
                {
                    using (var _client = new ImapClient())
                    {
                        string IMapAddress = _SuffixData;
                        _client.ServerCertificateValidationCallback = (s, c, h, f) => true;
                        _client.Connect(IMapAddress, 993, true);
                        _client.Authenticate(pochta, _PWData);

                        while (MSList.SelectedItems.Count > 0)
                        {
                            var inb = _client.GetFolder(SpecialFolder.Trash);

                            var Themes = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Корзина/Theme.txt").ToList();
                            var From   = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Корзина/FromWho.txt").ToList();
                            var Data   = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Корзина/Date.txt").ToList();
                            var ID     = File.ReadLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/Корзина/ID.txt").ToList();

                            int uid = Themes.Count - ((Convert.ToInt32(IPage.Content) - 1) * 10) - MSList.SelectedIndex - 1;

                            inb.Open(FolderAccess.ReadWrite);

                            Themes.RemoveAt(uid);
                            From.RemoveAt(uid);
                            Data.RemoveAt(uid);
                            ID.RemoveAt(uid);

                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/Theme.txt", Themes);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/FromWho.txt", From);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/Date.txt", Data);
                            File.WriteAllLines("C:/KursachMailClient/" + _EMailData + "/" + Chip.Content + "/" + "Корзина" + "/ID.txt", ID);

                            //MSList.Items.Clear();
                            MSList.Items.RemoveAt(MSList.SelectedIndex);
                            //LoadTrashMessages();

                            inb.AddFlags(uid, MessageFlags.Deleted, false);
                            inb.Expunge();
                            inb.Close();
                        }
                        _client.Disconnect(true);
                        SW.LoadTrashMessages(ForFunctions, ForFunctions);
                        LoadTrashMessages();
                    }
                }
            }
            catch (Exception ex) { }
        }