Esempio n. 1
0
 private void AccountMailAddress_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         DialogResult Res = MessageBox.Show("Delete this account from " + ProgramInfo.App.Name + "?", "Delete account?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (Res == DialogResult.Yes)
         {
             try
             {
                 String PathImport = Path.Combine(Operations.GlobalVarriable.UserToken, MailAdress);
                 if (Directory.Exists(PathImport))
                 {
                     Dispose();
                     Directory.Delete(PathImport, true);
                     Operations.GlobalVarriable.MailsAddressList.Remove(MailAdress);
                     Operations.Fast.UpdateAccountsList();
                     SuccessBox.Show("Successfully deleted!");
                 }
             }
             catch (Exception)
             {
                 FailBox.Show();
             }
         }
     }
     else
     {
         if (UserClicked != null)
         {
             UserClicked(sender, e);
         }
         /////////
         String PathImport = System.IO.Path.Combine(Operations.GlobalVarriable.UserToken, MailAdress);
         if (System.IO.Directory.Exists(PathImport))
         {
             Operations.GlobalVarriable.ListOfActiveAccounts.Add(MailAdress);
             WorkSpace.WorkSpace WorkSpace = new WorkSpace.WorkSpace((String.IsNullOrEmpty(DisplayName) ? MailAdress : DisplayName)
                                                                     , Avatar, MailAdress, PathImport);
             WorkSpace.ShowDialog();
         }
         /////////
     }
 }
Esempio n. 2
0
        // Function to get token
        public bool Get()
        {
            // Convert this string to Stream to read at Gmail API
            MemoryStream StreamJson = new MemoryStream(Encoding.ASCII.GetBytes(ConfigGmail.JsonContent_Gmail));

            try
            {
                // Create temp folder to save user token after request
                string NewUserFolder = string.Empty;
                NewUserFolder = Path.Combine(GlobalVarriable.UserToken, Fast.CreateNewRandomFolderName());
                // If this folder existed then auto generate new folder path
                while (File.Exists(NewUserFolder))
                {
                    NewUserFolder = Path.Combine(GlobalVarriable.UserToken, Fast.CreateNewRandomFolderName());
                }
                // Set value for UserCredential (Credential: Chứng chỉ)
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(StreamJson).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(NewUserFolder, true)).Result;
                // Create Gmail API service. (servis: Dịch vụ)
                var service = new GmailService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName
                });
                // Define parameters of request
                UsersResource.GetProfileRequest UserProfile = service.Users.GetProfile("me");
                // User detail
                Profile NewAccount    = UserProfile.Execute();
                string  UserEmail     = NewAccount.EmailAddress;
                string  MessagesTotal = NewAccount.MessagesTotal.ToString();
                string  ThreadsTotal  = NewAccount.ThreadsTotal.ToString();
                // Get user avatar form uri, covert to bitmap and save to User Space
                GmailAccountInfo.SendRequest(UserEmail); // sendrequest
                bool UpdateAccount = false;
                if (Directory.Exists(Path.Combine(Path.GetDirectoryName(NewUserFolder), UserEmail)))
                {
                    UpdateAccount = true;
                    Directory.Delete(Path.Combine(Path.GetDirectoryName(NewUserFolder), UserEmail), true);
                }
                // Change Folder random name to user's mail address name
                Directory.Move(NewUserFolder, Path.Combine(Path.GetDirectoryName(NewUserFolder), UserEmail));
                // Update NewUserFolder
                NewUserFolder = Path.Combine(Path.GetDirectoryName(NewUserFolder), UserEmail);
                GmailAccountInfo.get.Avatar.Save(Path.Combine(NewUserFolder, "Avatar.jpg"), ImageFormat.Jpeg);
                string UserContentGenerate =
                    Convert.ToBase64String(Encoding.UTF8.GetBytes(GmailAccountInfo.get.DisplayName)) // DisplayName
                    + "|" +
                    ThreadsTotal.ToString()                                                          // Total Thread
                    + "|" +
                    MessagesTotal.ToString();                                                        // Total Messages
                FileStream file     = new FileStream(Path.Combine(NewUserFolder, "Old.info"), FileMode.OpenOrCreate);
                byte[]     ForWrite = Encoding.ASCII.GetBytes(UserContentGenerate);
                file.Write(ForWrite, 0, ForWrite.Length);
                file.Close();
                // Should be add a case that if this Email had had before!
                //
                //
                // If Mail address had had before -> Out
                if (GlobalVarriable.MailsAddressList.IndexOf(UserEmail) != -1)
                {
                    return(false);
                }
                // Add this email to MailsAddressList
                GlobalVarriable.MailsAddressList.Add(UserEmail);
                // Update this account to List
                Fast.UpdateAccountsList();
                SuccessBox.Show("Successfully added!");
                // End of connections
                service.Dispose();
                return(true);
            }
            catch (Exception e)
            {
                // If have any bugs
                Console.WriteLine(e);
                FailBox.Show();
                return(false);
            }
        }
Esempio n. 3
0
        private void DownloadNow()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(DownloadNow));
                return;
            }
            DialogResult A = MessageBox.Show("Download '" + FileNameX + "'?", "DOWLOAD?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (A == DialogResult.No)
            {
                CallDefaultIcon();
                return;
            }
            // OpenDialog to select local
            FolderBrowserDialog Folder = new FolderBrowserDialog();

            Folder.ShowNewFolderButton = true;
            Folder.Description         = "Select folder to save this file!";
            Folder.ShowDialog();
            if (String.IsNullOrEmpty(Folder.SelectedPath))
            {
                MessageBox.Show("No path selected!", "EMPTY!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CallDefaultIcon();
                return;
            }
            // Finish all pre then download
            Attachments DownloadAtt = new Attachments();

            string[] TempData = DownloadAtt.Download(AttachmentId);
            if (IsEncrypted == true)
            {
                DialogResult ask = MessageBox.Show("This file is encrypted! Do you want decrypt it now?", "DECRYPT THIS FILE?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (ask == DialogResult.Yes)
                {
                    // Check key
                    EnterKey KeyIn = new EnterKey();
                    while (true)
                    {
                        Operations.Content.Message.CurrentPassword = string.Empty;
                        KeyIn.ShowDialog();
                        if (Operations.Content.Message.CurrentPassword == string.Empty)
                        {
                            MessageBox.Show("This content is WhiteSpace or Empty!",
                                            "NO CONTENT", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            continue;
                        }
                        #region For Decrypt
                        byte[] Temp;
                        switch (Operations.GlobalVarriable.KindOfCrypt)
                        {
                        case 0:
                        {
                            Temp = Operations.AES.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }

                        case 1:
                        {
                            Temp = Operations.DES.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }

                        case 2:
                        {
                            Temp = Operations.TwoFish.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }

                        case 3:
                        {
                            Temp = Operations.BlowFish.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }

                        default:
                            Temp = Operations.AES.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }
                        #endregion
                        if (Temp == null)
                        {
                            DialogResult C = MessageBox.Show("Wrong password! Do you want to try again?", "TRY AGAIN?", MessageBoxButtons.YesNo,
                                                             MessageBoxIcon.Question);
                            if (C == DialogResult.No)
                            {
                                DialogResult D = MessageBox.Show("Try to download without decrypt?", "TRY TO DOWNLOAD?",
                                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (DialogResult.No == D)
                                {
                                    CallDefaultIcon();
                                    return;
                                }
                                else
                                {
                                    Operations.Content.Message.CurrentPassword = string.Empty;
                                    break;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            try
                            {
                                string SavePath = Path.Combine(Folder.SelectedPath, FileNameX);
                                while (File.Exists(SavePath))
                                {
                                    System.Security.Cryptography.MD5 Hash = System.Security.Cryptography.MD5.Create();
                                    SavePath = Folder.SelectedPath + "\\" +
                                               Path.GetFileNameWithoutExtension(FileNameX) +
                                               "_" + BitConverter.ToString(Hash.ComputeHash(
                                                                               Encoding.UTF8.GetBytes(DateTime.Now.ToString()))).Replace("-", "") +
                                               Path.GetExtension(FileNameX);
                                }
                                File.WriteAllBytes(SavePath, Temp);
                                SuccessBox.Show("Successfully decrypted!");
                                Temp        = null;
                                TempData    = null;
                                DownloadAtt = null;
                                CallDefaultIcon();
                                return;
                            }
                            catch (Exception ee)
                            {
                                MessageBox.Show("Can not save '" + FileNameX + "', Try run this program with administration and try again!",
                                                "CAN NOT SAVE!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                CallDefaultIcon();
                                MessageBox.Show(ee.ToString());
                                return;
                            }
                        }
                    }
                }
            }
            // No encrypt
            try
            {
                string SavePath = Path.Combine(Folder.SelectedPath, FileNameX);
                while (File.Exists(SavePath))
                {
                    System.Security.Cryptography.MD5 Hash = System.Security.Cryptography.MD5.Create();
                    SavePath = Folder.SelectedPath + "\\" +
                               Path.GetFileNameWithoutExtension(FileNameX) +
                               "_" + BitConverter.ToString(Hash.ComputeHash(
                                                               Encoding.UTF8.GetBytes(DateTime.Now.ToString()))).Replace("-", "") +
                               Path.GetExtension(FileNameX);
                }
                File.WriteAllBytes(SavePath, Convert.FromBase64String(TempData[0]));
                SuccessBox.Show("Successfully saved!");
                TempData    = null;
                DownloadAtt = null;
                CallDefaultIcon();
                return;
            }
            catch (Exception ee)
            {
                MessageBox.Show("Can not save '" + FileNameX + "', Try run this program with administration and try again!",
                                "CAN NOT SAVE!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                CallDefaultIcon();
                MessageBox.Show(ee.ToString());
                return;
            }
        }
Esempio n. 4
0
 private void SuccessBox_Click(object sender, EventArgs e)
 {
     SuccessBox.Clear();
 }