From 14def3a3a2e091c48a16ffa5577ee446e33e48fd Mon Sep 17 00:00:00 2001 From: gamosoft_cp Date: Thu, 26 Mar 2015 19:20:48 +0000 Subject: [PATCH] Work in progress to allow moving received emails to folders --- Outlook2013TodoAddIn/ComboBoxItem.cs | 51 +++++++++++++++++ .../Forms/NewMailAlert.Designer.cs | 24 ++++++-- Outlook2013TodoAddIn/Forms/NewMailAlert.cs | 56 +++++++++++++++++++ .../Outlook2013TodoAddIn.csproj | 1 + 4 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 Outlook2013TodoAddIn/ComboBoxItem.cs diff --git a/Outlook2013TodoAddIn/ComboBoxItem.cs b/Outlook2013TodoAddIn/ComboBoxItem.cs new file mode 100644 index 0000000..9df5b9c --- /dev/null +++ b/Outlook2013TodoAddIn/ComboBoxItem.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Outlook2013TodoAddIn +{ + /// + /// Class to add combo box items and retrieve them more easily + /// + public class ComboBoxItem + { + #region "Properties" + + /// + /// Text + /// + public string Text { get; set; } + + /// + /// Value + /// + public object Value { get; set; } + + #endregion "Properties" + + #region "Methods" + + /// + /// Default constructor + /// + /// Text + /// Value + public ComboBoxItem(string text, object value) + { + this.Text = text; + this.Value = value; + } + + /// + /// Override to string to display the text entry + /// + /// Text property + public override string ToString() + { + return Text; + } + + #endregion "Methods" + } +} \ No newline at end of file diff --git a/Outlook2013TodoAddIn/Forms/NewMailAlert.Designer.cs b/Outlook2013TodoAddIn/Forms/NewMailAlert.Designer.cs index d89457c..73de3cc 100644 --- a/Outlook2013TodoAddIn/Forms/NewMailAlert.Designer.cs +++ b/Outlook2013TodoAddIn/Forms/NewMailAlert.Designer.cs @@ -35,6 +35,7 @@ this.btnClose = new System.Windows.Forms.Button(); this.lnkSender = new System.Windows.Forms.LinkLabel(); this.lnkSubject = new System.Windows.Forms.LinkLabel(); + this.comboMoveTo = new System.Windows.Forms.ComboBox(); this.SuspendLayout(); // // txtBody @@ -46,6 +47,7 @@ this.txtBody.ReadOnly = true; this.txtBody.Size = new System.Drawing.Size(285, 51); this.txtBody.TabIndex = 2; + this.txtBody.Text = "[Email body preview...]"; this.txtBody.Click += new System.EventHandler(this.txtBody_Click); // // btnDelete @@ -100,10 +102,10 @@ this.lnkSender.AutoSize = true; this.lnkSender.Location = new System.Drawing.Point(85, 5); this.lnkSender.Name = "lnkSender"; - this.lnkSender.Size = new System.Drawing.Size(72, 17); + this.lnkSender.Size = new System.Drawing.Size(75, 17); this.lnkSender.TabIndex = 10; this.lnkSender.TabStop = true; - this.lnkSender.Text = "linkLabel1"; + this.lnkSender.Text = "linkSender"; this.lnkSender.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkSender_LinkClicked); // // lnkSubject @@ -111,17 +113,30 @@ this.lnkSubject.AutoSize = true; this.lnkSubject.Location = new System.Drawing.Point(85, 27); this.lnkSubject.Name = "lnkSubject"; - this.lnkSubject.Size = new System.Drawing.Size(72, 17); + this.lnkSubject.Size = new System.Drawing.Size(76, 17); this.lnkSubject.TabIndex = 11; this.lnkSubject.TabStop = true; - this.lnkSubject.Text = "linkLabel2"; + this.lnkSubject.Text = "linkSubject"; this.lnkSubject.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkSubject_LinkClicked); // + // comboMoveTo + // + this.comboMoveTo.DisplayMember = "Text"; + this.comboMoveTo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboMoveTo.FormattingEnabled = true; + this.comboMoveTo.Location = new System.Drawing.Point(220, 5); + this.comboMoveTo.Name = "comboMoveTo"; + this.comboMoveTo.Size = new System.Drawing.Size(121, 24); + this.comboMoveTo.TabIndex = 12; + this.comboMoveTo.ValueMember = "Value"; + this.comboMoveTo.SelectedIndexChanged += new System.EventHandler(this.comboMoveTo_SelectedIndexChanged); + // // NewMailAlert // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(385, 100); + this.Controls.Add(this.comboMoveTo); this.Controls.Add(this.lnkSubject); this.Controls.Add(this.lnkSender); this.Controls.Add(this.btnClose); @@ -151,5 +166,6 @@ private System.Windows.Forms.Button btnClose; private System.Windows.Forms.LinkLabel lnkSender; private System.Windows.Forms.LinkLabel lnkSubject; + private System.Windows.Forms.ComboBox comboMoveTo; } } \ No newline at end of file diff --git a/Outlook2013TodoAddIn/Forms/NewMailAlert.cs b/Outlook2013TodoAddIn/Forms/NewMailAlert.cs index 2fc2122..bb62658 100644 --- a/Outlook2013TodoAddIn/Forms/NewMailAlert.cs +++ b/Outlook2013TodoAddIn/Forms/NewMailAlert.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Outlook = Microsoft.Office.Interop.Outlook; namespace Outlook2013TodoAddIn.Forms { @@ -72,6 +73,7 @@ namespace Outlook2013TodoAddIn.Forms public NewMailAlert(Microsoft.Office.Interop.Outlook.MailItem newMail, int interval) { InitializeComponent(); + this.LoadFolders(); this.Email = newMail; // Assign it to open or flag later this.lnkSender.Text = newMail.Sender.Name; this.lnkSubject.Text = newMail.Subject; @@ -203,6 +205,60 @@ namespace Outlook2013TodoAddIn.Forms mouseIsOver = ClientRectangle.Contains(mousePos); } + /// + /// Method that loads all the folders in all stores + /// + private void LoadFolders() + { + comboMoveTo.Items.Clear(); + foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores) + { + if (Properties.Settings.Default.Accounts != null && Properties.Settings.Default.Accounts.Contains(store.DisplayName)) + { + Outlook.Folder inboxFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder; + LoadFolders(inboxFolder, ""); + } + } + } + + /// + /// Recursive method to retrieve a folder's data, and all its children (if any) + /// + /// Folder + /// Padding to apply + private void LoadFolders(Outlook.Folder f, string padding) + { + ComboBoxItem cbi = new ComboBoxItem(padding + f.Name, f); + comboMoveTo.Items.Add(cbi); + if (f.Folders.Count != 0) + { + // Get list of folder names and sort alphabetically + List sf = new List(); + foreach (Outlook.Folder subf in f.Folders) sf.Add(subf.Name); + sf.Sort(); + // Recursively call this method to add the children + sf.ForEach(n => + { + LoadFolders(f.Folders[n] as Outlook.Folder, padding + " -"); + }); + } + } + + /// + /// When a folder is selected in the combobox, move the email item there + /// + /// Sender + /// EventArgs + private void comboMoveTo_SelectedIndexChanged(object sender, EventArgs e) + { + if (this.comboMoveTo.SelectedIndex != -1) + { + Outlook.Folder selFolder = (this.comboMoveTo.SelectedItem as ComboBoxItem).Value as Outlook.Folder; + this.Email.Move(selFolder); + this.Close(); + } + } + #endregion "Methods" } } \ No newline at end of file diff --git a/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj b/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj index 8d7132d..496b277 100644 --- a/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj +++ b/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj @@ -183,6 +183,7 @@ can be found. --> + UserControl