2016-12-21 12:53:16 +01:00
|
|
|
|
/// Copyright 2016 Kopano b.v.
|
|
|
|
|
///
|
|
|
|
|
/// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
/// it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
/// as published by the Free Software Foundation.
|
|
|
|
|
///
|
|
|
|
|
/// This program is distributed in the hope that it will be useful,
|
|
|
|
|
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
|
/// GNU Affero General Public License for more details.
|
|
|
|
|
///
|
|
|
|
|
/// You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
/// along with this program.If not, see<http://www.gnu.org/licenses/>.
|
|
|
|
|
///
|
|
|
|
|
/// Consult LICENSE file for details
|
|
|
|
|
|
|
|
|
|
using Acacia.Features.DebugSupport;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Acacia.Utils;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-02-08 15:40:48 +01:00
|
|
|
|
using NSOutlook = Microsoft.Office.Interop.Outlook;
|
2016-12-21 12:53:16 +01:00
|
|
|
|
|
|
|
|
|
namespace Acacia.Stubs.OutlookWrappers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper for Outlook wrapper implementations
|
|
|
|
|
/// </summary>
|
2017-06-07 10:38:36 +02:00
|
|
|
|
abstract class OutlookWrapper<ItemType> : ComWrapper<ItemType>, IBase
|
2016-12-21 12:53:16 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region Construction / Destruction
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a wrapper.
|
|
|
|
|
/// </summary>
|
2017-02-10 11:15:58 +01:00
|
|
|
|
internal OutlookWrapper(ItemType item) : base(item)
|
2016-12-21 12:53:16 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties implementation
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the wrapped item's property accessor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The property accessor. The caller is responsible for disposing this.</returns>
|
2017-02-08 15:40:48 +01:00
|
|
|
|
abstract protected NSOutlook.PropertyAccessor GetPropertyAccessor();
|
2016-12-21 12:53:16 +01:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2017-06-07 10:38:36 +02:00
|
|
|
|
#region IBase implementation
|
|
|
|
|
|
|
|
|
|
public bool IsDeleted
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
string deletedEntryId;
|
|
|
|
|
using (IStore store = GetStore())
|
|
|
|
|
{
|
|
|
|
|
using (IFolder deleted = store.GetDefaultFolder(DefaultFolder.DeletedItems))
|
|
|
|
|
deletedEntryId = deleted.EntryID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IFolder current = Parent;
|
|
|
|
|
while (current != null)
|
|
|
|
|
{
|
|
|
|
|
if (current.EntryID == deletedEntryId)
|
|
|
|
|
{
|
|
|
|
|
current.Dispose();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
IFolder parent = current.Parent;
|
|
|
|
|
current.Dispose();
|
|
|
|
|
current = parent;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract string EntryID { get; }
|
|
|
|
|
public abstract IFolder Parent { get; }
|
|
|
|
|
public abstract string ParentEntryID { get; }
|
|
|
|
|
|
|
|
|
|
virtual public string StoreID
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
using (IStore store = GetStore())
|
|
|
|
|
{
|
|
|
|
|
return store.StoreID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual public string StoreDisplayName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
using (IStore store = GetStore())
|
|
|
|
|
{
|
|
|
|
|
return store.DisplayName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2016-12-21 12:53:16 +01:00
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
public string[] AttrCategories
|
|
|
|
|
{
|
|
|
|
|
// Get the categories using the MAPI property. If using the C# property, they get concatenated
|
|
|
|
|
// into a string which must be parsed again.
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-07-05 16:21:23 +02:00
|
|
|
|
return (string[])GetProperty(OutlookConstants.PR_CATEGORIES);
|
2016-12-21 12:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-07-05 16:21:23 +02:00
|
|
|
|
SetProperty(OutlookConstants.PR_CATEGORIES, value);
|
2016-12-21 12:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AttrHidden
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-01-25 14:49:00 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-05 16:21:23 +02:00
|
|
|
|
return (bool)GetProperty(OutlookConstants.PR_ATTR_HIDDEN);
|
2017-01-25 14:49:00 +01:00
|
|
|
|
}
|
|
|
|
|
catch(System.Exception)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-12-21 12:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-07-05 16:21:23 +02:00
|
|
|
|
SetProperty(OutlookConstants.PR_ATTR_HIDDEN, value);
|
2016-12-21 12:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object GetProperty(string property)
|
|
|
|
|
{
|
2017-07-05 16:21:23 +02:00
|
|
|
|
NSOutlook.PropertyAccessor props = GetPropertyAccessor();
|
2016-12-21 12:53:16 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-05 16:21:23 +02:00
|
|
|
|
object val = props.GetProperty(property);
|
2016-12-21 12:53:16 +01:00
|
|
|
|
if (val is DBNull)
|
|
|
|
|
return null;
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2017-02-15 11:32:37 +01:00
|
|
|
|
catch(System.Exception) { return null; }
|
2017-07-05 16:21:23 +02:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
ComRelease.Release(props);
|
|
|
|
|
}
|
2016-12-21 12:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetProperty(string property, object value)
|
|
|
|
|
{
|
2017-07-05 16:21:23 +02:00
|
|
|
|
NSOutlook.PropertyAccessor props = GetPropertyAccessor();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
props.SetProperty(property, value);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
ComRelease.Release(props);
|
|
|
|
|
}
|
2016-12-21 12:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetProperties(string[] properties, object[] values)
|
|
|
|
|
{
|
2017-07-05 16:21:23 +02:00
|
|
|
|
NSOutlook.PropertyAccessor props = GetPropertyAccessor();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
props.SetProperties(properties, values);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
ComRelease.Release(props);
|
|
|
|
|
}
|
2016-12-21 12:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public override abstract string ToString();
|
2017-06-07 10:38:36 +02:00
|
|
|
|
public abstract IStore GetStore();
|
|
|
|
|
public abstract void Delete();
|
2016-12-21 12:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|