예제 #1
0
        private async void Button_AddAccount_Click(object sender, EventArgs e)
        {
            RichTextBox_Error.Text = "";
            bool exceptionThrown = false;
            bool emailExists     = false;

            foreach (User user in chooseAccountWindow.mainWindow.allUsers)
            {
                if (Regex.Replace(user.GetEmail(), @"\s+", "").Equals(Regex.Replace(this.TextBox_Email.Text, @"\s+", "")))
                {
                    emailExists = true;
                }
            }
            if (!emailExists)
            {
                ImapClient x = await CheckEmail.Login(this.TextBox_Email.Text, this.TextBox_Password.Text);

                if (x == null)
                {
                    Warning warning = new Warning(this, "Nesėkmingas prisijugimas kuri galėjo įvykti dėl:" + Environment.NewLine
                                                  + "1.Ivedėte neteisingą el. paštą arba slaptažodį" + Environment.NewLine
                                                  + "2.Nepavyko prisijungti prie google serverio" + Environment.NewLine + "3.Blogas interneto ryšys");
                    warning.Show();
                    RichTextBox_Error.Text = "Ivedėte neteisingą el. paštą arba slaptažodį";
                    exceptionThrown        = true;
                }
                if (!exceptionThrown)
                {
                    String email         = StringCipher.Encrypt(this.TextBox_Email.Text, "125847elpu68795");
                    String password      = StringCipher.Encrypt(this.TextBox_Password.Text, "125847elpu62195");
                    string fileDirectory = Directory.GetParent(this.workingDirectory).Parent.FullName + @"\ConfidentialInformation\UsersEmailCredentials.txt";
                    File.WriteAllText(fileDirectory, File.ReadAllText(fileDirectory) + email + " \n " + password + " ");
                    chooseAccountWindow.mainWindow.allUsers.Add(new User(this.TextBox_Email.Text, this.TextBox_Password.Text));
                    chooseAccountWindow.ListBox_Accounts.Items.Add(this.TextBox_Email.Text);
                    chooseAccountWindow.Enabled = true;
                    this.Dispose();
                }
            }
            else
            {
                Warning warning = new Warning(this, "Įrašytas el.paštas jau egzistuoja");
                warning.Show();
            }
        }
예제 #2
0
        private async void Button_ExportAddressList_Click(object sender, EventArgs e)
        {
            bool    correctDate = true;
            Warning DateWarning = new Warning(this, "Neteisinga data");

            if (this.CheckBox_UseDates.Checked)
            {
                if (this.DateTimePicker_DateFrom.Value > this.DateTimePicker_DateTo.Value)
                {
                    if (this.DateTimePicker_DateFrom.Value.Date != this.DateTimePicker_DateTo.Value.Date)
                    {
                        DateWarning = new Warning(this, "Data nuo yra didesnė nei data iki");
                        correctDate = false;
                    }
                }
                else if (DateTime.Now < this.DateTimePicker_DateTo.Value.Date)
                {
                    DateWarning = new Warning(this, "Data iki pasirinkta ateityje");
                    correctDate = false;
                }
                else if (DateTime.Now < this.DateTimePicker_DateFrom.Value.Date)
                {
                    DateWarning = new Warning(this, "Data nuo pasirinkta ateityje");
                    correctDate = false;
                }
            }
            if (!correctDate)
            {
                DateWarning.Show();
            }
            else if (currentUser != null)
            {
                this.Hide();
                string strfoldername      = "C://";
                string workingDirectory   = Environment.CurrentDirectory;
                string projectDirectory   = Directory.GetParent(workingDirectory).Parent.FullName;
                string filePathSavingPath = projectDirectory + @"\PathToAddressList.txt";     //vieta kur bus saugomas pathas į Adresų lista
                string pathToFile         = File.ReadAllText(filePathSavingPath);
                int    lastIndex          = pathToFile.LastIndexOf(@"\");
                pathToFile = pathToFile.Remove(lastIndex);

                if (pathToFile != "")
                {
                    FolderBrowserDialog_DefaultExcelSavingPath.SelectedPath = pathToFile;
                    OpenFileDialog_ExportAddressList.FileName = "";
                }
                else
                {
                    OpenFileDialog_ExportAddressList.InitialDirectory = projectDirectory;
                    OpenFileDialog_ExportAddressList.FileName         = "";
                }
                DialogResult result = FolderBrowserDialog_DefaultExcelSavingPath.ShowDialog(this);

                if (result == DialogResult.OK)
                {
                    List <MimeMessage> allEmails = datePickerEnabled ?
                                                   await CheckEmail.FetchAllMailbotMessages(currentUser.GetEmail(), currentUser.GetPassword(), DateTimePicker_DateFrom.Value, DateTimePicker_DateTo.Value) :
                                                   await CheckEmail.FetchAllMailbotMessages(currentUser.GetEmail(), currentUser.GetPassword());

                    if (allEmails != null)
                    {
                        strfoldername = FolderBrowserDialog_DefaultExcelSavingPath.SelectedPath;

                        emailsToSend = CheckEmail.CollectToEmailsFromMessages(allEmails.ConvertAll(x => x.Body.ToString()));
                        var emailsToSengGrouped = emailsToSend.GroupBy(u => u).Select(grp => new { Text = grp.Key, Count = grp.Count() }).ToList();
                        emailsToSend = new List <string>();
                        foreach (var email in emailsToSengGrouped)
                        {
                            emailsToSend.Add(email.Text);
                        }
                        File.WriteAllText(filePathSavingPath, strfoldername);
                        EmailsSaveWindow saveWindow = new EmailsSaveWindow(this, datePickerEnabled, strfoldername, emailsToSend, DateTimePicker_DateFrom.Value, DateTimePicker_DateTo.Value);
                        saveWindow.Show();
                    }
                    else
                    {
                        this.Show();
                        Warning warning = new Warning(this, "Nesėkmingas išsaugojimas kuris galėjo įvykti dėl:" + Environment.NewLine
                                                      + "1.Nepavyko prisijungti prie google serverio" + Environment.NewLine + "2.Blogas interneto ryšys");
                    }
                }
                else
                {
                    this.Show();
                    this.Enabled = true;
                }
            }
            else
            {
                Warning warningWindow = new Warning(this, "Jūs nepasirinkote vartotojo");
                warningWindow.Show();
            }
        }