private async void btnUpload_Click(object sender, EventArgs e)
        {
            TreeNode node = treeViewNodes?.SelectedNode;
            NodeTag  tag  = node?.Tag as NodeTag;

            if (tag != null)
            {
                imgLoad.Visible = true; btnUpload.Enabled = false;
                Controller controller  = new Controller();
                int?       folderCount = node?.Nodes?.Count;
                bool       isUploaded  = await controller.UploadEmail(EmailItem, tag.Id, folderCount);

                if (isUploaded)
                {
                    MessageBox.Show("File(s) uploaded successfully");
                    this.Close();
                }
                else
                {
                    if (string.IsNullOrEmpty(controller.Error))
                    {
                        MessageBox.Show("Error while uploading file, Please try again!!");
                    }
                    else
                    {
                        MessageBox.Show(controller.Error);
                    }
                }
            }
            imgLoad.Visible = false; btnUpload.Enabled = true;
        }
        private async void btnUpload_Click(object sender, EventArgs e)
        {
            TreeNode node = treeViewNodes?.SelectedNode;
            NodeTag tag = node?.Tag as NodeTag;
            if (tag != null)
            {
                imgLoad.Visible = true; btnUploadSelectedFolder.Enabled = false;
                Controller controller = new Controller();
                int? folderCount = node?.Nodes?.Count;
                bool isUploaded;

                //se foldercount > 0 utilizzo l'upload con il datetime
                if (!folderCount.HasValue || folderCount.Value == 0)
                {
                    isUploaded = await controller.UploadEmail(EmailItem, tag.Id, folderCount);
                }
                else
                {
                    isUploaded = await controller.UploadEmailDateTime(EmailItem, tag.Id, DateTime.Now);
                }


                if (isUploaded)
                {
                    Option.Read();
                    DirectorySettings dirSettings = Option.GetDirectorySettings();
                    LastUsedFolder = node.FullPath;
                    LastUsedFolderTag = tag.Id;
                    dirSettings.LastUsedFolder = LastUsedFolder;
                    dirSettings.LastUsedFolderTag = LastUsedFolderTag;
                    Option.SaveDirectorySettings(dirSettings);

                    MessageBox.Show(UserInterfaceStrings.FilesUploadedSuccessfully);
                    this.Close();
                }
                else
                {
                    if (string.IsNullOrEmpty(controller.Error))
                        MessageBox.Show(UserInterfaceStrings.ErrorOnUpload);
                    else
                        MessageBox.Show(controller.Error);
                }
            }
            imgLoad.Visible = false; btnUploadSelectedFolder.Enabled = true;

        }
        private void btnSelectDefaultFolder_Click(object sender, EventArgs e)
        {
            Option.Read();


            DirectorySettings dirSettings = Option.GetDirectorySettings();

            string lastUsedFolderName = String.Empty;
            string lastUsedFolderTag  = String.Empty;

            if (dirSettings != null)
            {
                if (!String.IsNullOrWhiteSpace(dirSettings.LastUsedFolder) && !String.IsNullOrWhiteSpace(dirSettings.LastUsedFolderTag))
                {
                    lastUsedFolderName = dirSettings.LastUsedFolder;
                    lastUsedFolderTag  = dirSettings.LastUsedFolderTag;
                }
            }
            TreeNode node = treeViewNodes?.SelectedNode;
            NodeTag  tag  = node?.Tag as NodeTag;

            if (tag != null && tag.IsFolder)
            {
                DefaultFolderName = node.FullPath;
                DefaultFolderTag  = tag.Id;
                DirectorySettings settings = new DirectorySettings();
                settings.DefaultFolder    = DefaultFolderName;
                settings.DefaultFolderTag = DefaultFolderTag;
                if (!String.IsNullOrWhiteSpace(lastUsedFolderName) && !String.IsNullOrWhiteSpace(lastUsedFolderTag))
                {
                    settings.LastUsedFolder    = lastUsedFolderName;
                    settings.LastUsedFolderTag = lastUsedFolderTag;
                }

                Option.SaveDirectorySettings(settings);

                MessageBox.Show(UserInterfaceStrings.DefaultFolderChanged, UserInterfaceStrings.Settings, MessageBoxButtons.OK);
            }
        }