Work in progress to allow moving received emails to folders

This commit is contained in:
gamosoft_cp 2015-03-26 19:20:48 +00:00
parent 2e0c440d5d
commit 14def3a3a2
4 changed files with 128 additions and 4 deletions

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Outlook2013TodoAddIn
{
/// <summary>
/// Class to add combo box items and retrieve them more easily
/// </summary>
public class ComboBoxItem
{
#region "Properties"
/// <summary>
/// Text
/// </summary>
public string Text { get; set; }
/// <summary>
/// Value
/// </summary>
public object Value { get; set; }
#endregion "Properties"
#region "Methods"
/// <summary>
/// Default constructor
/// </summary>
/// <param name="text">Text</param>
/// <param name="value">Value</param>
public ComboBoxItem(string text, object value)
{
this.Text = text;
this.Value = value;
}
/// <summary>
/// Override to string to display the text entry
/// </summary>
/// <returns>Text property</returns>
public override string ToString()
{
return Text;
}
#endregion "Methods"
}
}

View File

@ -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;
}
}

View File

@ -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);
}
/// <summary>
/// Method that loads all the folders in all stores
/// </summary>
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, "");
}
}
}
/// <summary>
/// Recursive method to retrieve a folder's data, and all its children (if any)
/// </summary>
/// <param name="f">Folder</param>
/// <param name="padding">Padding to apply</param>
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<string> sf = new List<string>();
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 + " -");
});
}
}
/// <summary>
/// When a folder is selected in the combobox, move the email item there
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param>
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"
}
}

View File

@ -183,6 +183,7 @@
can be found.
-->
<ItemGroup>
<Compile Include="ComboBoxItem.cs" />
<Compile Include="Constants.cs" />
<Compile Include="CustomCalendar.cs">
<SubType>UserControl</SubType>