Skip to content

Commit

Permalink
Merge pull request #13 from FlexConfirmMail/resolve-recipient
Browse files Browse the repository at this point in the history
Resolve recipient addresses of suggested Exchange users
  • Loading branch information
ashie authored Aug 14, 2023
2 parents aa6e66a + 0988e87 commit 1231a53
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
82 changes: 75 additions & 7 deletions Dialog/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.RegularExpressions;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace FlexConfirmMail.Dialog
Expand All @@ -16,6 +17,16 @@ internal class RecipientInfo : IComparable

public RecipientInfo(Outlook.Recipient recp)
{
recp.Resolve();
QueueLogger.Log("RecipientInfo");
QueueLogger.Log($" Resolved: {recp.Resolved}");
QueueLogger.Log($" Name: {recp.Name}");
QueueLogger.Log($" Type: {recp.Type}");
QueueLogger.Log($" Address: {recp.Address}");
QueueLogger.Log($" AddressEntry.Name: {recp.AddressEntry.Name}");
QueueLogger.Log($" AddressEntry.Address: {recp.AddressEntry.Address}");
QueueLogger.Log($" AddressEntry.DisplayType: {recp.AddressEntry.DisplayType}");
QueueLogger.Log($" AddressEntry.Type: {recp.AddressEntry.Type}");
if (recp.AddressEntry.DisplayType == Outlook.OlDisplayType.olUser
&& recp.AddressEntry.Type == "SMTP")
{
Expand All @@ -39,6 +50,7 @@ public RecipientInfo(Outlook.Recipient recp)

private void FromSMTP(Outlook.Recipient recp)
{
QueueLogger.Log(" => FromSMTP");
Type = GetType(recp);
Address = recp.Address;
Domain = GetDomainFromSMTP(Address);
Expand All @@ -48,24 +60,79 @@ private void FromSMTP(Outlook.Recipient recp)

private void FromExchange(Outlook.Recipient recp)
{
QueueLogger.Log(" => FromExchange");
Outlook.ExchangeUser user = recp.AddressEntry.GetExchangeUser();
if (user == null || string.IsNullOrEmpty(user.PrimarySmtpAddress))
QueueLogger.Log($" user: {user}");

string possibleAddress = "";
if (user == null ||
string.IsNullOrEmpty(user.PrimarySmtpAddress))
{
FromOther(recp);
QueueLogger.Log(" user is null or has no PrimarySmtpAddress: trying to get it via PropertyAccessor");
const string PR_SMTP_ADDRESS = "https://schemas.microsoft.com/mapi/proptag/0x39FE001E";
possibleAddress = GetSMTPAddressViaAccessor(recp, PR_SMTP_ADDRESS);
if (string.IsNullOrEmpty(possibleAddress))
{
const string PR_EMS_PROXY_ADDRESSES = "http://schemas.microsoft.com/mapi/proptag/0x800f101e";
possibleAddress = GetSMTPAddressViaAccessor(recp, PR_EMS_PROXY_ADDRESSES);
}
}
else
{
Type = GetType(recp);
Address = user.PrimarySmtpAddress;
Domain = GetDomainFromSMTP(Address);
Help = Address;
IsSMTP = true;
possibleAddress = user.PrimarySmtpAddress;
}

if (string.IsNullOrEmpty(possibleAddress))
{
QueueLogger.Log(" Couldn't get address: fallback to FromOther");
FromOther(recp);
return;
}
QueueLogger.Log($" => finally resolved addrss: {possibleAddress}");

Type = GetType(recp);
Address = possibleAddress;
Domain = GetDomainFromSMTP(Address);
Help = Address;
IsSMTP = true;
}

private string GetSMTPAddressViaAccessor(Outlook.Recipient recp, string schemaName)
{
try
{
QueueLogger.Log($" Retrieving values for {schemaName}...");
dynamic propertyValue = recp.AddressEntry.PropertyAccessor.GetProperty(schemaName);
if (propertyValue is string[] values)
{
foreach (string value in values)
{
QueueLogger.Log($" value: {value}");
// The recipient may have multiple values with their types like:
// SIP:local@domain
// SMTP:local@domain
// We should accept only SMTP address.
if (!string.IsNullOrEmpty(value) &&
Regex.IsMatch(value, "^(SMTP:)?[^:@]+@.+", RegexOptions.IgnoreCase))
{
return Regex.Replace(value, "^SMTP:", "");
}
}
}
return propertyValue.ToString();
}
catch (Exception ex)
{
QueueLogger.Log($" Failed to GetProperty with {schemaName}: {ex}");
return "";
}
}

private void FromDistList(Outlook.Recipient recp)
{
QueueLogger.Log(" => FromDistList");
Outlook.ExchangeDistributionList dist = recp.AddressEntry.GetExchangeDistributionList();
QueueLogger.Log($" dist: {dist}");
if (dist == null || string.IsNullOrEmpty(dist.PrimarySmtpAddress))
{
FromOther(recp);
Expand All @@ -82,6 +149,7 @@ private void FromDistList(Outlook.Recipient recp)

private void FromOther(Outlook.Recipient recp)
{
QueueLogger.Log($" => FromOther ({recp.AddressEntry.DisplayType})");
switch (recp.AddressEntry.DisplayType)
{
case Outlook.OlDisplayType.olUser:
Expand Down
4 changes: 2 additions & 2 deletions FlexConfirmMail.iss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[Setup]
AppName=FlexConfirmMail
AppVerName=FlexConfirmMail
VersionInfoVersion=22.3.0.0
VersionInfoVersion=22.4.0
AppPublisher=ClearCode Inc.
AppVersion=22.3.0
AppVersion=22.4.0
UninstallDisplayIcon={app}\fcm.ico
DefaultDirName={commonpf}\FlexConfirmMail
ShowLanguageDialog=no
Expand Down
4 changes: 2 additions & 2 deletions Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace FlexConfirmMail
public class Global
{
public static readonly string AppName = "FlexConfirmMail";
public static readonly string Version = "22.3.0";
public static readonly string Version = "22.4.0";
public static readonly string Edition = "Enterprise";
public static readonly bool EnableGPO = true;
}
}
}
4 changes: 2 additions & 2 deletions Global.public.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace FlexConfirmMail
public class Global
{
public static readonly string AppName = "FlexConfirmMail";
public static readonly string Version = "22.3.0";
public static readonly string Version = "22.4.0";
public static readonly string Edition = "Free";
public static readonly bool EnableGPO = false;
}
}
}

0 comments on commit 1231a53

Please sign in to comment.