2013-03-30 01:35:37 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
2013-04-01 18:03:41 +02:00
|
|
|
|
using System.Runtime.InteropServices;
|
2013-03-30 01:35:37 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2015-03-26 20:20:48 +01:00
|
|
|
|
using Outlook = Microsoft.Office.Interop.Outlook;
|
2013-03-30 01:35:37 +01:00
|
|
|
|
|
2013-06-27 20:30:15 +02:00
|
|
|
|
namespace Outlook2013TodoAddIn.Forms
|
2013-03-30 01:35:37 +01:00
|
|
|
|
{
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
2014-10-23 18:44:12 +02:00
|
|
|
|
/// New form to display new email notifications
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// </summary>
|
2013-03-30 01:35:37 +01:00
|
|
|
|
public partial class NewMailAlert : Form
|
|
|
|
|
{
|
2013-04-01 19:35:28 +02:00
|
|
|
|
#region "Variables"
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// To control how long the form displays
|
|
|
|
|
/// </summary>
|
2013-04-01 18:03:41 +02:00
|
|
|
|
private Timer timer;
|
2013-04-01 19:35:28 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Don't close the for if the mouse is over it
|
|
|
|
|
/// </summary>
|
2015-02-24 17:45:33 +01:00
|
|
|
|
#endregion "Variables"
|
2013-04-01 18:03:41 +02:00
|
|
|
|
private bool mouseIsOver = false;
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region "Properties"
|
|
|
|
|
|
|
|
|
|
/// Attached email message to open or flag
|
|
|
|
|
/// </summary>
|
2013-03-30 01:35:37 +01:00
|
|
|
|
public Microsoft.Office.Interop.Outlook.MailItem Email { get; set; }
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether to show without the form activation
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override bool ShowWithoutActivation
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 18:44:12 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is used so we can show without activation and be the TopMost form
|
|
|
|
|
/// The TopMost property of the form MUST be set to false for this to work
|
|
|
|
|
/// https://connect.microsoft.com/VisualStudio/feedback/details/401311/showwithoutactivation-is-not-supported-with-topmost
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override CreateParams CreateParams
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
CreateParams value = base.CreateParams;
|
2015-02-24 17:45:33 +01:00
|
|
|
|
value.ExStyle |= Constants.WS_EX_TOPMOST;
|
2014-10-23 18:44:12 +02:00
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
#endregion "Properties"
|
|
|
|
|
|
|
|
|
|
#region "Methods"
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Default constructor
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="newMail">Mail item</param>
|
|
|
|
|
/// <param name="interval">Time in ms to keep the alert on</param>
|
|
|
|
|
public NewMailAlert(Microsoft.Office.Interop.Outlook.MailItem newMail, int interval)
|
2013-03-30 01:35:37 +01:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2015-03-26 20:20:48 +01:00
|
|
|
|
this.LoadFolders();
|
2013-04-01 19:35:28 +02:00
|
|
|
|
this.Email = newMail; // Assign it to open or flag later
|
|
|
|
|
this.lnkSender.Text = newMail.Sender.Name;
|
|
|
|
|
this.lnkSubject.Text = newMail.Subject;
|
|
|
|
|
this.txtBody.Text = newMail.Body;
|
2013-04-01 18:03:41 +02:00
|
|
|
|
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width - 10;
|
|
|
|
|
this.Top = Screen.PrimaryScreen.WorkingArea.Height - this.Height - 10;
|
|
|
|
|
this.timer = new Timer();
|
|
|
|
|
timer.Interval = interval;
|
|
|
|
|
timer.Tick += timer_Tick;
|
|
|
|
|
timer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button delete clicked
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-03-30 01:35:37 +01:00
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Email.Delete();
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button flag clicked
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-03-30 01:35:37 +01:00
|
|
|
|
private void btnFlag_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Microsoft.Office.Interop.Outlook.OlFlagIcon.olYellowFlagIcon
|
2013-07-18 20:16:35 +02:00
|
|
|
|
this.Email.FlagRequest = Constants.FollowUp;
|
2013-03-30 01:35:37 +01:00
|
|
|
|
this.Email.Save();
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button envelope clicked
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-03-30 01:35:37 +01:00
|
|
|
|
private void btnEnvelope_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-04-01 18:03:41 +02:00
|
|
|
|
this.ShowEmail();
|
2013-03-30 01:35:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button close clicked
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-03-30 01:35:37 +01:00
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
2013-04-01 18:03:41 +02:00
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sender hyperlink clicked
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">LinkLabelLinkClickedEventArgs</param>
|
|
|
|
|
private void lnkSender_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
2013-04-01 18:03:41 +02:00
|
|
|
|
{
|
2013-04-01 19:35:28 +02:00
|
|
|
|
this.ShowEmail();
|
2013-04-01 18:03:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Subject hyperlink clicked
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">LinkLabelLinkClickedEventArgs</param>
|
|
|
|
|
private void lnkSubject_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
2013-04-01 18:03:41 +02:00
|
|
|
|
{
|
|
|
|
|
this.ShowEmail();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Body textbox clicked
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
|
|
|
|
private void txtBody_Click(object sender, EventArgs e)
|
2013-04-01 18:03:41 +02:00
|
|
|
|
{
|
|
|
|
|
this.ShowEmail();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Show the email and close the form
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ShowEmail()
|
2013-04-01 18:03:41 +02:00
|
|
|
|
{
|
2013-04-01 19:35:28 +02:00
|
|
|
|
this.Email.Display();
|
|
|
|
|
this.Close();
|
2013-04-01 18:03:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Process timer ticks
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-04-01 18:03:41 +02:00
|
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!mouseIsOver)
|
|
|
|
|
{
|
|
|
|
|
timer.Stop();
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Processed when the mouse enters the form
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ea">EventArgs</param>
|
|
|
|
|
protected override void OnMouseEnter(EventArgs ea)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseEnter(ea);
|
|
|
|
|
Point mousePos = PointToClient(Cursor.Position);
|
|
|
|
|
mouseIsOver = ClientRectangle.Contains(mousePos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Processed when the mouse exits the form
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ea">EventArgs</param>
|
|
|
|
|
protected override void OnMouseLeave(EventArgs ea)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseLeave(ea);
|
|
|
|
|
Point mousePos = PointToClient(Cursor.Position);
|
|
|
|
|
mouseIsOver = ClientRectangle.Contains(mousePos);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-26 20:20:48 +01:00
|
|
|
|
/// <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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 19:35:28 +02:00
|
|
|
|
#endregion "Methods"
|
2013-03-30 01:35:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|