Example #1
0
        // Display the folder browser dialog
        public static Dictionary <object, object> ShowBrowserDialog()
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog()
            {
                Description = "Choose the destination folder for the selected emails."
            };

            fbd.RootFolder   = Environment.SpecialFolder.Desktop;
            fbd.SelectedPath = SaveMailModel.GetRecentLocation();
            DialogResult dialogResult = fbd.ShowDialog();

            return(SaveMailModel.GetPath(dialogResult, fbd.SelectedPath));
        }
Example #2
0
        // Invoke a sanity check for the path and save e-mails to drive
        public static string SaveSelected(Dictionary <object, object> savePath, List <object> emailItems, Folder inbox, String inboxFolderName, Boolean moveItems)
        {
            int savedNumber = 0;

            foreach (MailItem email in emailItems)
            {
                string pathCheckResult = SaveMailModel.PathCheck(savePath, email);

                if (!pathCheckResult.Equals("pathInvalid") && !pathCheckResult.Equals("saveCancelled"))
                {
                    if (email.ReceivedByName == null)
                    {
                        string emailDestination = SaveMailModel.GetEmailAddress(email, "outgoing");
                        email.SaveAs(savePath["selectedPath"] + "\\" + email.ReceivedTime.ToString("yyyy-MM-dd HHmm") + " " + emailDestination + " " + pathCheckResult + ".msg", OlSaveAsType.olMSG);
                    }
                    else
                    {
                        string emailSender = SaveMailModel.GetEmailAddress(email, "incoming");
                        email.SaveAs(savePath["selectedPath"] + "\\" + email.ReceivedTime.ToString("yyyy-MM-dd HHmm") + " " + emailSender + " " + pathCheckResult + ".msg", OlSaveAsType.olMSG);
                    }

                    if (moveItems)
                    {
                        email.Move(inbox.Folders[inboxFolderName]);
                        SaveMailLogger.LogAction("Moving item to " + inboxFolderName + " folder");
                    }

                    SaveMailLogger.LogAction("Saving item " + (savedNumber + 1) + " with " + email.Size.ToString() + " bytes");
                    savedNumber++;
                }
                else
                {
                    return(pathCheckResult);
                }
            }

            SaveMailLogger.LogAction("Saved to location: " + savePath["selectedPath"]);
            SaveMailLogger.LogAction("Total saved: " + savedNumber);
            return("saveSuccess");
        }
Example #3
0
        // Main method with at event listener for the plugin button
        private void SaveSelectedButton_Click(object sender, RibbonControlEventArgs e)
        {
            SaveMailLogger.LogAction("Plugin Activated!");

            List <object> selectedEmails = SaveMailModel.GetSelectedEmails();

            SaveMailLogger.LogAction("Selected " + selectedEmails.Count + " emails.");

            Folder inbox = (Folder) new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

            string inboxFolderName = "Saved Mail";

            CreateSavedMailFolder(inbox, inboxFolderName);

            bool moveItems = false;

            if (selectedEmails.Count != 0)
            {
                string currentFolder = ((MailItem)selectedEmails[0]).Parent.FolderPath.ToString();

                SaveMailLogger.LogAction("Selected from: " + currentFolder);

                Dictionary <object, object> savePath = SaveMailView.ShowBrowserDialog();

                if ((DialogResult)savePath["dialogResult"] == DialogResult.OK && currentFolder.Substring(currentFolder.Length - "Inbox".Length).Equals("Inbox") && SaveMailView.Question())
                {
                    moveItems = true;
                    SaveMailLogger.LogAction("Attempting to move selected out of the inbox...");
                }

                SaveMailView.Confirmation(SaveSelected(savePath, selectedEmails, inbox, inboxFolderName, moveItems));
            }
            else
            {
                SaveMailView.Confirmation("invalidSelection");
            }
        }