Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
Upload v1.0.1
  • Loading branch information
MatthewHana committed Oct 10, 2023
1 parent 74fab8f commit 657e3bb
Show file tree
Hide file tree
Showing 29 changed files with 2,719 additions and 0 deletions.
41 changes: 41 additions & 0 deletions OutlookDSD/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.Office.Interop.Outlook;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace OutlookDSD
{
public static class Helper
{
const string HEADER_TRANSPORT_SCHEMA = "http://schemas.microsoft.com/mapi/proptag/0x007D001E";
const string HEADER_REGEX_PATTERN = @"^(?<header_key>[-A-Za-z0-9]+)(?<seperator>:[ \t]*)(?<header_value>([^\r\n]|\r\n[ \t]+)*)(?<terminator>\r\n)";

public static ILookup<string, string> Email_GetHeaders(MailItem emailItem)
{
var headerString = (string)emailItem.PropertyAccessor.GetProperty(HEADER_TRANSPORT_SCHEMA);
var headerMatches = Regex.Matches(headerString, HEADER_REGEX_PATTERN, RegexOptions.Multiline).Cast<Match>();
return headerMatches.ToLookup(
h => h.Groups["header_key"].Value,
h => h.Groups["header_value"].Value
);
}

public static string ListToSentence(List<string> list)
{
if (list.Count == 0)
{
return String.Empty;
}
else if (list.Count > 1)
{
return String.Join(", ", list.ToArray(), 0, list.Count - 1) + ", and " + list.LastOrDefault();
}
else
{
return list.First();
}

}
}
}
163 changes: 163 additions & 0 deletions OutlookDSD/InfoBar.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 138 additions & 0 deletions OutlookDSD/InfoBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace OutlookDSD
{
partial class InfoBar
{
#region Form Region Factory

[Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Note)]
[Microsoft.Office.Tools.Outlook.FormRegionName("OutlookDSD.InfoBar")]
public partial class InfoBarFactory
{

// Occurs before the form region is initialized.
// To prevent the form region from appearing, set e.Cancel to true.
// Use e.OutlookItem to get a reference to the current Outlook item.
private void InfoBarFactory_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
{
Outlook.MailItem emailItem = (Outlook.MailItem)e.OutlookItem;

if (emailItem == null)
{
e.Cancel = true;
return;
}
}
}

#endregion

private void InfoBar_FormRegionShowing(object sender, System.EventArgs e)
{
Outlook.MailItem emailItem = (Outlook.MailItem) OutlookItem;

if (emailItem == null)
{
OutlookFormRegion.Visible = false;
return;
}

// Only show on emails.
if (emailItem.MessageClass != "IPM.Note")
{
OutlookFormRegion.Visible = false;
return;
}

// Don't show for any draft emails.
if(emailItem.Sent == false)
{
OutlookFormRegion.Visible = false;
return;
}

// Now we check our settings to see if the user wants the bar to show
string settingCheck = "bar_show";
bool showBar = (bool) Properties.Settings.Default[settingCheck];
if (showBar == false)
{
OutlookFormRegion.Visible = false;
return;
}

// We don't need to worry about multiple messages being selected in explorer mode
// because Outlook only displays one anyway.

Validator validator = new Validator(emailItem);
Dictionary<string, string[]> results = validator.Results();

List<string> failed = new List<string>();
List<string> missing = new List<string>();
List<string> error = new List<string>();
List<string> pass = new List<string>();

// Iterate through each mechanism in result and add them to the appropriate list based on their result
foreach (string mechanism in results.Keys)
{
string mechanismResult = results[mechanism][0];
string mechanismUpper = mechanism.ToUpper();
switch (mechanismResult)
{
case Validator.RESULT_PASS:
pass.Add(mechanismUpper);
break;
case Validator.RESULT_FAIL:
failed.Add(mechanismUpper);
break;
case Validator.RESULT_NONE:
missing.Add(mechanismUpper);
break;
default:
case Validator.RESULT_ERROR:
error.Add(mechanismUpper);
break;

}
}

int badMechanismsCount = error.Count + failed.Count + missing.Count;

// If all mechnaisms are good then don't display anything.
if (badMechanismsCount == 0)
{
OutlookFormRegion.Visible = false;
return;
}

// Otherwise we're going to show the warning bar
OutlookFormRegion.Visible = true;


List<string> messages = new List<string>();
if(failed.Count > 0)
{
messages.Add("This email has failed " + Helper.ListToSentence(failed) + " validation.");
}
if (missing.Count > 0)
{
messages.Add("This email is missing " + Helper.ListToSentence(missing) + " validation.");
}
if(error.Count > 0)
{
messages.Add("There was an error analysing " + Helper.ListToSentence(error) + " validation.");
}
messageLabel.Text = String.Join(" ", messages.ToArray());
}

// Occurs when the form region is closed.
// Use this.OutlookItem to get a reference to the current Outlook item.
// Use this.OutlookFormRegion to get a reference to the form region.
private void InfoBar_FormRegionClosed(object sender, System.EventArgs e)
{
}

}
}
Loading

0 comments on commit 657e3bb

Please sign in to comment.