1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 13:37:40 +02:00
Conflicts:
	src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj
	src/AcaciaZPushPlugin/AcaciaZPushPlugin/Native/MAPI/Property.cs
	src/AcaciaZPushPlugin/AcaciaZPushPlugin/Native/MAPI/Restriction.cs
	src/AcaciaZPushPlugin/AcaciaZPushPlugin/SearchQuery.cs
	src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IFolder.cs
	src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs
This commit is contained in:
Patrick Simpson 2017-02-23 10:15:51 +01:00
commit 2f0e46f18d
11 changed files with 113 additions and 24 deletions

View File

@ -297,6 +297,7 @@
<Compile Include="Stubs\IItemEvents.cs" /> <Compile Include="Stubs\IItemEvents.cs" />
<Compile Include="Stubs\IItems.cs" /> <Compile Include="Stubs\IItems.cs" />
<Compile Include="Stubs\IOutlookWindow.cs" /> <Compile Include="Stubs\IOutlookWindow.cs" />
<Compile Include="Stubs\IPicture.cs" />
<Compile Include="Stubs\IRecipient.cs" /> <Compile Include="Stubs\IRecipient.cs" />
<Compile Include="Stubs\IStores.cs" /> <Compile Include="Stubs\IStores.cs" />
<Compile Include="Stubs\ISyncObject.cs" /> <Compile Include="Stubs\ISyncObject.cs" />
@ -309,6 +310,7 @@
<Compile Include="Stubs\OutlookWrappers\ItemEventsWrapper.cs" /> <Compile Include="Stubs\OutlookWrappers\ItemEventsWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\ItemsWrapper.cs" /> <Compile Include="Stubs\OutlookWrappers\ItemsWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\OutlookItemWrapper.cs" /> <Compile Include="Stubs\OutlookWrappers\OutlookItemWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\PictureWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\RecipientWrapper.cs" /> <Compile Include="Stubs\OutlookWrappers\RecipientWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\StoresWrapper.cs" /> <Compile Include="Stubs\OutlookWrappers\StoresWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\SyncObjectWrapper.cs" /> <Compile Include="Stubs\OutlookWrappers\SyncObjectWrapper.cs" />

View File

@ -22,6 +22,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -68,8 +69,7 @@ namespace Acacia.Features.SecondaryContacts
public override void Startup() public override void Startup()
{ {
Watcher.WatchFolder(new FolderRegistrationSecondaryContacts(this), Watcher.WatchFolder(new FolderRegistrationSecondaryContacts(this), OnUnpatchedFolderDiscovered);
OnUnpatchedFolderDiscovered);
} }
private void OnUnpatchedFolderDiscovered(IFolder folder) private void OnUnpatchedFolderDiscovered(IFolder folder)
@ -93,7 +93,7 @@ namespace Acacia.Features.SecondaryContacts
// Stage 1 // Stage 1
// Sync type // Sync type
Logger.Instance.Trace(this, "Setting sync type"); Logger.Instance.Trace(this, "Settin7g sync type");
folder.SetProperty(OutlookConstants.PR_EAS_SYNCTYPE, (int)OutlookConstants.SyncType.UserContact); folder.SetProperty(OutlookConstants.PR_EAS_SYNCTYPE, (int)OutlookConstants.SyncType.UserContact);
// Container type // Container type
@ -102,15 +102,42 @@ namespace Acacia.Features.SecondaryContacts
// Make it invisible. // Make it invisible.
folder.AttrHidden = true; folder.AttrHidden = true;
folder.Save();
Logger.Instance.Debug(this, "Patched secondary contacts folder: {0}", strippedName); Logger.Instance.Debug(this, "Patched secondary contacts folder: {0}", strippedName);
// Register and show a warning, if not already done. WarnRestart(folder);
// Note that patching may be done multiple times. }
if (!_warnedFolders.Contains(folder.EntryID)) // If _warnedFolders does not contain the folder (and it's hidden), this means Outlook was restarted.
{ else if (!_warnedFolders.Contains(folder.EntryID))
_warnedFolders.Add(folder.EntryID); {
// Stage 2
if (MessageBox.Show(StringUtil.GetResourceString("SecondaryContactsPatched_Body", strippedName), // Patch the name
Logger.Instance.Trace(this, "Patching name");
folder.Name = strippedName;
// Show it
folder.AttrHidden = false;
Logger.Instance.Debug(this, "Shown secondary contacts folder: {0}", strippedName);
}
Logger.Instance.Debug(this, "Patching done: {0}: {1}", strippedName, folder.AttrHidden);
}
private DateTime? _lastWarning;
private void WarnRestart(IFolder folder)
{
// Register and show a warning, if not already done.
// Note that patching may be done multiple times.
if (!_warnedFolders.Contains(folder.EntryID))
{
_warnedFolders.Add(folder.EntryID);
// TODO: configurable constant for warning time
if (_lastWarning == null || DateTime.Now - _lastWarning >= TimeSpan.FromHours(1))
{
_lastWarning = DateTime.Now;
if (MessageBox.Show(StringUtil.GetResourceString("SecondaryContactsPatched_Body", folder.Name),
StringUtil.GetResourceString("SecondaryContactsPatched_Title"), StringUtil.GetResourceString("SecondaryContactsPatched_Title"),
MessageBoxButtons.YesNo, MessageBoxButtons.YesNo,
MessageBoxIcon.Warning MessageBoxIcon.Warning
@ -120,19 +147,6 @@ namespace Acacia.Features.SecondaryContacts
} }
} }
} }
// If _warnedFolders does not contain the folder (and it's hidden), this means Outlook was restarted.
else if (!_warnedFolders.Contains(folder.EntryID))
{
// Stage 2
// Patch the name
Logger.Instance.Trace(this, "Patching name");
folder.Name = strippedName;
// Show it
folder.AttrHidden = false;
Logger.Instance.Debug(this, "Shown secondary contacts folder: {0}", strippedName);
}
} }
} }
} }

View File

@ -25,6 +25,7 @@ namespace Acacia.Stubs
{ {
public interface IMSOCommand public interface IMSOCommand
{ {
IPicture GetPicture(Size imageSize);
Bitmap GetImage(Size imageSize); Bitmap GetImage(Size imageSize);
} }

View File

@ -120,5 +120,9 @@ namespace Acacia.Stubs
get; get;
set; set;
} }
void Save();
void SetCustomIcon(IPicture icon);
} }
} }

View File

@ -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 IPicture : IComWrapper
{
}
}

View File

@ -39,6 +39,11 @@ namespace Acacia.Stubs.OutlookWrappers
this._id = id; this._id = id;
} }
public IPicture GetPicture(Size imageSize)
{
return _commands._item.GetImageMso(_id, imageSize.Width, imageSize.Height).Wrap();
}
public Bitmap GetImage(Size imageSize) public Bitmap GetImage(Size imageSize)
{ {
IPictureDisp pict = _commands._item.GetImageMso(_id, imageSize.Width, imageSize.Height); IPictureDisp pict = _commands._item.GetImageMso(_id, imageSize.Width, imageSize.Height);

View File

@ -24,6 +24,7 @@ using Acacia.Utils;
using Acacia.ZPush; using Acacia.ZPush;
using NSOutlook = Microsoft.Office.Interop.Outlook; using NSOutlook = Microsoft.Office.Interop.Outlook;
using Acacia.Native.MAPI; using Acacia.Native.MAPI;
using stdole;
namespace Acacia.Stubs.OutlookWrappers namespace Acacia.Stubs.OutlookWrappers
{ {
@ -56,6 +57,19 @@ namespace Acacia.Stubs.OutlookWrappers
return new FolderWrapper(CloneComObject()); return new FolderWrapper(CloneComObject());
} }
public void Save()
{
IMAPIFolder imapi = _item.MAPIOBJECT as IMAPIFolder;
try
{
imapi.SaveChanges(SaveChangesFlags.FORCE_SAVE);
}
finally
{
ComRelease.Release(imapi);
}
}
internal NSOutlook.Folder RawItem { get { return _item; } } internal NSOutlook.Folder RawItem { get { return _item; } }
protected override NSOutlook.PropertyAccessor GetPropertyAccessor() protected override NSOutlook.PropertyAccessor GetPropertyAccessor()
@ -360,6 +374,11 @@ namespace Acacia.Stubs.OutlookWrappers
} }
} }
public void SetCustomIcon(IPicture icon)
{
_item.SetCustomIcon(((PictureWrapper)icon).RawItem as StdPicture);
}
#endregion #endregion
public ItemType DefaultItemType public ItemType DefaultItemType
@ -395,7 +414,8 @@ namespace Acacia.Stubs.OutlookWrappers
set set
{ {
// TODO
throw new NotImplementedException();
} }
} }
} }

View File

@ -87,6 +87,15 @@ namespace Acacia.Stubs.OutlookWrappers
return wrapped; return wrapped;
} }
public static IPicture Wrap(stdole.IPictureDisp obj, bool mustRelease = true)
{
if (obj == null)
return null;
PictureWrapper wrapped = new PictureWrapper(obj);
wrapped.MustRelease = mustRelease;
return wrapped;
}
// TODO: extension methods for this // TODO: extension methods for this
public static IStore Wrap(NSOutlook.Store obj, bool mustRelease = true) public static IStore Wrap(NSOutlook.Store obj, bool mustRelease = true)
{ {

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Acacia.Stubs.OutlookWrappers
{
class PictureWrapper : ComWrapper<stdole.IPictureDisp>, IPicture
{
internal PictureWrapper(stdole.IPictureDisp item) : base(item)
{
}
internal stdole.IPictureDisp RawItem { get { return _item; } }
}
}

View File

@ -62,5 +62,10 @@ namespace Acacia.Stubs
{ {
return Mapping.WrapOrDefault<WrapType>(o, mustRelease); return Mapping.WrapOrDefault<WrapType>(o, mustRelease);
} }
public static IPicture Wrap(this stdole.IPictureDisp picture)
{
return Mapping.Wrap(picture);
}
} }
} }

View File

@ -157,7 +157,7 @@ namespace Acacia.ZPush
// Hence, fetch all the remaining folder ids, and remove any folder that no longer exists. // Hence, fetch all the remaining folder ids, and remove any folder that no longer exists.
// TODO: move this logic into IFolders? // TODO: move this logic into IFolders?
HashSet<string> remaining = new HashSet<string>(); HashSet<string> remaining = new HashSet<string>();
foreach (IFolder child in _folder.SubFolders) foreach (IFolder child in _folder.SubFolders.DisposeEnum())
{ {
try try
{ {