Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve recipient addresses of suggested Exchange users #13

Merged
merged 17 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ashie marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
}
Loading