mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
Cleaned up usage of Recipient/AddressEntry
This commit is contained in:
parent
cc51366c7f
commit
65a46510c1
@ -280,9 +280,13 @@
|
|||||||
<Compile Include="Native\IOleWindow.cs" />
|
<Compile Include="Native\IOleWindow.cs" />
|
||||||
<Compile Include="OutlookConstants.cs" />
|
<Compile Include="OutlookConstants.cs" />
|
||||||
<Compile Include="Stubs\IAddIn.cs" />
|
<Compile Include="Stubs\IAddIn.cs" />
|
||||||
|
<Compile Include="Stubs\IAddressEntry.cs" />
|
||||||
<Compile Include="Stubs\IComWrapper.cs" />
|
<Compile Include="Stubs\IComWrapper.cs" />
|
||||||
|
<Compile Include="Stubs\IRecipient.cs" />
|
||||||
<Compile Include="Stubs\OutlookWrappers\AddInWrapper.cs" />
|
<Compile Include="Stubs\OutlookWrappers\AddInWrapper.cs" />
|
||||||
|
<Compile Include="Stubs\OutlookWrappers\AddressEntryWrapper.cs" />
|
||||||
<Compile Include="Stubs\OutlookWrappers\OutlookItemWrapper.cs" />
|
<Compile Include="Stubs\OutlookWrappers\OutlookItemWrapper.cs" />
|
||||||
|
<Compile Include="Stubs\OutlookWrappers\RecipientWrapper.cs" />
|
||||||
<Compile Include="UI\Outlook\OutlookImageList.cs" />
|
<Compile Include="UI\Outlook\OutlookImageList.cs" />
|
||||||
<Compile Include="UI\Outlook\RibbonToggleButton.cs" />
|
<Compile Include="UI\Outlook\RibbonToggleButton.cs" />
|
||||||
<Compile Include="UI\Outlook\RibbonButton.cs" />
|
<Compile Include="UI\Outlook\RibbonButton.cs" />
|
||||||
|
@ -281,23 +281,25 @@ namespace Acacia.Features.GAB
|
|||||||
/// <param name="cancel"></param>
|
/// <param name="cancel"></param>
|
||||||
private void DoSuppressEvent(IItem item, ref bool cancel)
|
private void DoSuppressEvent(IItem item, ref bool cancel)
|
||||||
{
|
{
|
||||||
|
// TODO: Find and close the inspector
|
||||||
/*if (item != null)
|
/*if (item != null)
|
||||||
{
|
{
|
||||||
foreach (Inspector inspector in App.Inspectors)
|
foreach (Inspector inspector in ThisAddIn.Instance.Inspectors)
|
||||||
{
|
{
|
||||||
if (item.EntryId == inspector.CurrentItem.EntryID)
|
if (item.EntryId == inspector.CurrentItem.EntryID)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
// Show message and cancel event
|
||||||
MessageBox.Show(StringUtil.GetResourceString("GABEvent_Body"),
|
MessageBox.Show(StringUtil.GetResourceString("GABEvent_Body"),
|
||||||
StringUtil.GetResourceString("GABEvent_Title"),
|
StringUtil.GetResourceString("GABEvent_Title"),
|
||||||
MessageBoxButtons.OK,
|
MessageBoxButtons.OK,
|
||||||
MessageBoxIcon.Warning
|
MessageBoxIcon.Warning
|
||||||
);
|
);
|
||||||
cancel = true;*/
|
cancel = true;
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -436,9 +438,12 @@ namespace Acacia.Features.GAB
|
|||||||
GABInfo gabInfo = GABInfo.Get(gab, domainName);
|
GABInfo gabInfo = GABInfo.Get(gab, domainName);
|
||||||
gabInfo.Store(gab);
|
gabInfo.Store(gab);
|
||||||
|
|
||||||
// Hook BeforeMove event to prevent modifications
|
if (SuppressModifications)
|
||||||
// TODO: use ZPushWatcher for this?
|
{
|
||||||
gab.BeforeItemMove += SuppressMoveEventHandler;
|
// Hook BeforeMove event to prevent modifications
|
||||||
|
// TODO: use ZPushWatcher for this?
|
||||||
|
gab.BeforeItemMove += SuppressMoveEventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
return gab;
|
return gab;
|
||||||
}
|
}
|
||||||
@ -446,8 +451,11 @@ namespace Acacia.Features.GAB
|
|||||||
|
|
||||||
private void DisposeGABContacts(IAddressBook gab)
|
private void DisposeGABContacts(IAddressBook gab)
|
||||||
{
|
{
|
||||||
// Unhook the event to prevent the gab lingering in memory
|
if (SuppressModifications)
|
||||||
gab.BeforeItemMove -= SuppressMoveEventHandler;
|
{
|
||||||
|
// Unhook the event to prevent the gab lingering in memory
|
||||||
|
gab.BeforeItemMove -= SuppressMoveEventHandler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GABInfo GetGABContactsFolderInfo(IFolder folder)
|
public static GABInfo GetGABContactsFolderInfo(IFolder folder)
|
||||||
|
@ -90,18 +90,21 @@ namespace Acacia.Features.SendAs
|
|||||||
{
|
{
|
||||||
Logger.Instance.Trace(this, "Checking, Shared folder owner: {0}", shared.Store.UserName);
|
Logger.Instance.Trace(this, "Checking, Shared folder owner: {0}", shared.Store.UserName);
|
||||||
// It's a shared folder, use the owner as the sender if possible
|
// It's a shared folder, use the owner as the sender if possible
|
||||||
// TODO: make a wrapper for this
|
using (IRecipient recip = ThisAddIn.Instance.ResolveRecipient(shared.Store.UserName))
|
||||||
// TODO: remove RawApp access
|
|
||||||
var recip = ThisAddIn.Instance.RawApp.Session.CreateRecipient(shared.Store.UserName);
|
|
||||||
Logger.Instance.Trace(this, "Checking, Shared folder owner recipient: {0}", recip.Name);
|
|
||||||
if (recip != null && recip.Resolve())
|
|
||||||
{
|
{
|
||||||
Logger.Instance.Trace(this, "Sending as: {0}", recip.AddressEntry.Address);
|
Logger.Instance.Trace(this, "Checking, Shared folder owner recipient: {0}", recip.Name);
|
||||||
response.SetSender(recip.AddressEntry);
|
if (recip != null && recip.IsResolved)
|
||||||
}
|
{
|
||||||
else
|
Logger.Instance.Trace(this, "Sending as: {0}", recip.Address);
|
||||||
{
|
using (IAddressEntry address = recip.GetAddressEntry())
|
||||||
Logger.Instance.Trace(this, "Unable to resolve sender");
|
{
|
||||||
|
response.SetSender(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.Instance.Trace(this, "Unable to resolve sender");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,9 @@ namespace Acacia.Stubs
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Miscellaneous methods
|
||||||
|
// TODO: clean this up
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends and receives all accounts.
|
/// Sends and receives all accounts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -51,5 +54,9 @@ namespace Acacia.Stubs
|
|||||||
|
|
||||||
FeatureType GetFeature<FeatureType>()
|
FeatureType GetFeature<FeatureType>()
|
||||||
where FeatureType : Feature;
|
where FeatureType : Feature;
|
||||||
|
|
||||||
|
IRecipient ResolveRecipient(string name);
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Acacia.Stubs
|
||||||
|
{
|
||||||
|
public interface IAddressEntry : IComWrapper
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -33,7 +33,10 @@ namespace Acacia.Stubs
|
|||||||
string SenderEmailAddress { get; }
|
string SenderEmailAddress { get; }
|
||||||
string SenderName { get; }
|
string SenderName { get; }
|
||||||
|
|
||||||
// TODO: make a wrapper for this
|
/// <summary>
|
||||||
void SetSender(Microsoft.Office.Interop.Outlook.AddressEntry addressEntry);
|
/// Sets the sender.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="addressEntry">The address. The caller is responsible for disposing.</param>
|
||||||
|
void SetSender(IAddressEntry addressEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IRecipient.cs
Normal file
21
src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IRecipient.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Acacia.Stubs
|
||||||
|
{
|
||||||
|
public interface IRecipient : IComWrapper
|
||||||
|
{
|
||||||
|
bool IsResolved { get; }
|
||||||
|
|
||||||
|
string Name { get; }
|
||||||
|
string Address { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the address entry. The caller is responsible for disposing it.
|
||||||
|
/// </summary>
|
||||||
|
IAddressEntry GetAddressEntry();
|
||||||
|
}
|
||||||
|
}
|
@ -190,5 +190,19 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
public IRecipient ResolveRecipient(string name)
|
||||||
|
{
|
||||||
|
using (ComRelease com = new ComRelease())
|
||||||
|
{
|
||||||
|
NSOutlook.NameSpace session = com.Add(_app.Session);
|
||||||
|
NSOutlook.Recipient recipient = session.CreateRecipient(name);
|
||||||
|
if (recipient == null)
|
||||||
|
return null;
|
||||||
|
com.Add(recipient);
|
||||||
|
recipient.Resolve();
|
||||||
|
return Mapping.Wrap(com.Remove(recipient));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
using Acacia.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NSOutlook = Microsoft.Office.Interop.Outlook;
|
||||||
|
|
||||||
|
namespace Acacia.Stubs.OutlookWrappers
|
||||||
|
{
|
||||||
|
class AddressEntryWrapper : ComWrapper, IAddressEntry
|
||||||
|
{
|
||||||
|
private NSOutlook.AddressEntry _item;
|
||||||
|
|
||||||
|
internal AddressEntryWrapper(NSOutlook.AddressEntry item)
|
||||||
|
{
|
||||||
|
this._item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal NSOutlook.AddressEntry RawItem { get { return _item; } }
|
||||||
|
|
||||||
|
protected override void DoRelease()
|
||||||
|
{
|
||||||
|
ComRelease.Release(_item);
|
||||||
|
_item = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -42,31 +42,27 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
using (ComRelease com = new ComRelease())
|
string displayName = DLName + " (" + value + ")";
|
||||||
{
|
byte[] oneOffId = CreateOneOffMemberId(DLName, "SMTP", value);
|
||||||
string displayName = DLName + " (" + value + ")";
|
|
||||||
byte[] oneOffId = CreateOneOffMemberId(DLName, "SMTP", value);
|
|
||||||
|
|
||||||
NSOutlook.PropertyAccessor props = com.Add(_item.PropertyAccessor);
|
SetProperties(
|
||||||
props.SetProperties(
|
new string[]
|
||||||
new string[]
|
{
|
||||||
{
|
OutlookConstants.PR_EMAIL1DISPLAYNAME,
|
||||||
OutlookConstants.PR_EMAIL1DISPLAYNAME,
|
OutlookConstants.PR_EMAIL1EMAILADDRESS,
|
||||||
OutlookConstants.PR_EMAIL1EMAILADDRESS,
|
OutlookConstants.PR_EMAIL1ADDRESSTYPE,
|
||||||
OutlookConstants.PR_EMAIL1ADDRESSTYPE,
|
OutlookConstants.PR_EMAIL1ORIGINALDISPLAYNAME,
|
||||||
OutlookConstants.PR_EMAIL1ORIGINALDISPLAYNAME,
|
OutlookConstants.PR_EMAIL1ORIGINALENTRYID
|
||||||
OutlookConstants.PR_EMAIL1ORIGINALENTRYID
|
},
|
||||||
},
|
new object[]
|
||||||
new object[]
|
{
|
||||||
{
|
DLName,
|
||||||
DLName,
|
value,
|
||||||
value,
|
"SMTP",
|
||||||
"SMTP",
|
value,
|
||||||
value,
|
oneOffId
|
||||||
oneOffId
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,12 +91,15 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
private void AddContactMember(IContactItem member)
|
private void AddContactMember(IContactItem member)
|
||||||
{
|
{
|
||||||
string email = member.Email1Address;
|
string email = member.Email1Address;
|
||||||
// TODO: remove RawApp, Recipient wrapper
|
using (IRecipient recipient = ThisAddIn.Instance.ResolveRecipient(email))
|
||||||
NSOutlook.Recipient recipient = ThisAddIn.Instance.RawApp.Session.CreateRecipient(email);
|
{
|
||||||
if (recipient.Resolve())
|
if (recipient.IsResolved)
|
||||||
_item.AddMember(recipient);
|
{
|
||||||
else
|
_item.AddMember(((RecipientWrapper)recipient).RawItem);
|
||||||
Logger.Instance.Warning(this, "Unable to resolve recipient: {0}", email);
|
}
|
||||||
|
else
|
||||||
|
Logger.Instance.Warning(this, "Unable to resolve recipient: {0}", email);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddDistributionListMember(IDistributionList member)
|
private void AddDistributionListMember(IDistributionList member)
|
||||||
|
@ -81,9 +81,9 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetSender(NSOutlook.AddressEntry addressEntry)
|
public void SetSender(IAddressEntry addressEntry)
|
||||||
{
|
{
|
||||||
_item.Sender = addressEntry;
|
_item.Sender = ((AddressEntryWrapper)addressEntry).RawItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -78,6 +78,13 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
return (Type)Wrap(o, mustRelease);
|
return (Type)Wrap(o, mustRelease);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IRecipient Wrap(NSOutlook.Recipient r, bool mustRelease = true)
|
||||||
|
{
|
||||||
|
RecipientWrapper wrapped = new RecipientWrapper(r);
|
||||||
|
wrapped.MustRelease = mustRelease;
|
||||||
|
return wrapped;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: are these not the same now? Differ only on wrong type?
|
// TODO: are these not the same now? Differ only on wrong type?
|
||||||
public static Type WrapOrDefault<Type>(object o, bool mustRelease = true)
|
public static Type WrapOrDefault<Type>(object o, bool mustRelease = true)
|
||||||
where Type : IBase
|
where Type : IBase
|
||||||
|
@ -24,7 +24,7 @@ using NSOutlook = Microsoft.Office.Interop.Outlook;
|
|||||||
|
|
||||||
namespace Acacia.Stubs.OutlookWrappers
|
namespace Acacia.Stubs.OutlookWrappers
|
||||||
{
|
{
|
||||||
public class NoteItemWrapper : OutlookItemWrapper<NSOutlook.NoteItem>, INoteItem
|
class NoteItemWrapper : OutlookItemWrapper<NSOutlook.NoteItem>, INoteItem
|
||||||
{
|
{
|
||||||
internal NoteItemWrapper(NSOutlook.NoteItem item)
|
internal NoteItemWrapper(NSOutlook.NoteItem item)
|
||||||
:
|
:
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
using Acacia.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NSOutlook = Microsoft.Office.Interop.Outlook;
|
||||||
|
|
||||||
|
namespace Acacia.Stubs.OutlookWrappers
|
||||||
|
{
|
||||||
|
class RecipientWrapper : ComWrapper, IRecipient
|
||||||
|
{
|
||||||
|
private NSOutlook.Recipient _item;
|
||||||
|
|
||||||
|
internal RecipientWrapper(NSOutlook.Recipient item)
|
||||||
|
{
|
||||||
|
this._item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal NSOutlook.Recipient RawItem { get { return _item; } }
|
||||||
|
|
||||||
|
protected override void DoRelease()
|
||||||
|
{
|
||||||
|
ComRelease.Release(_item);
|
||||||
|
_item = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsResolved
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _item.Resolved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _item.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Address
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _item.Address;
|
||||||
|
// TODO:? return _item.AddressEntry.Address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAddressEntry GetAddressEntry()
|
||||||
|
{
|
||||||
|
return new AddressEntryWrapper(_item.AddressEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,7 @@ using NSOutlook = Microsoft.Office.Interop.Outlook;
|
|||||||
|
|
||||||
namespace Acacia.Stubs.OutlookWrappers
|
namespace Acacia.Stubs.OutlookWrappers
|
||||||
{
|
{
|
||||||
public class TaskItemWrapper : OutlookItemWrapper<NSOutlook.TaskItem>, ITaskItem
|
class TaskItemWrapper : OutlookItemWrapper<NSOutlook.TaskItem>, ITaskItem
|
||||||
{
|
{
|
||||||
internal TaskItemWrapper(NSOutlook.TaskItem item)
|
internal TaskItemWrapper(NSOutlook.TaskItem item)
|
||||||
:
|
:
|
||||||
|
@ -34,6 +34,12 @@ namespace Acacia.Utils
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Type Remove<Type>(Type t)
|
||||||
|
{
|
||||||
|
objects.Remove(t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
foreach (object o in objects)
|
foreach (object o in objects)
|
||||||
|
Loading…
Reference in New Issue
Block a user