Commit 1faf3e0a authored by Thomas's avatar Thomas
Browse files

Renaming and reordering

parent 586db39c
......@@ -1752,7 +1752,7 @@ namespace pEp
if (Globals.ThisAddIn.Settings.EnableNativeMethods &&
result.PropertiesToSet.Count > 0)
{
if (mailItem.SetMAPIProperties(result.PropertiesToSet))
if (mailItem.SetPropertiesNative(result.PropertiesToSet))
{
saveItem = true;
}
......@@ -1770,25 +1770,19 @@ namespace pEp
{
if (Globals.ThisAddIn.Settings.EnableNativeMethods)
{
saveItem = Mapi.SetMAPIProperties(attachment,
new MapiProperty.MapiProp[]
{
MapiProperty.PidTagAttachmentHidden,
MapiProperty.PidTagAttachFlags
},
new object[]
{
true,
4
});
saveItem = Mapi.SetPropertiesNative(attachment, new MAPIProperties
{
{ MapiProperty.PidTagAttachmentHidden, true },
{ MapiProperty.PidTagAttachFlags, 4 }
});
}
else
{
saveItem = (MapiHelper.SetProperties(attachment, new MAPIProperties
saveItem = MapiHelper.SetProperties(attachment, new MAPIProperties
{
{ MapiProperty.PidTagAttachmentHidden, true },
{ MapiProperty.PidTagAttachFlags, 4 }
}) == null);
});
}
attachment = null;
......@@ -2197,7 +2191,7 @@ namespace pEp
internal class ProcessingResult
{
public pEpRating Rating { get; set; } = pEpRating.pEpRatingUndefined;
public Dictionary<MapiProperty.MapiProp, object> PropertiesToSet { get; set; } = new Dictionary<MapiProperty.MapiProp, object>();
public MAPIProperties PropertiesToSet { get; set; } = new MAPIProperties();
public bool HiddenAttachments = false;
}
}
......
......@@ -3252,51 +3252,12 @@ namespace pEp
/// Sets the given MAPI properties on the Outlook mail item using native p/invoke methods.
/// </summary>
/// <param name="omi">The Outlook mail item to process with.</param>
/// <param name="properties">The MAPI properties to set.</param>
/// <param name="mapiProperties">The MAPI properties to set.</param>
/// <returns>True if the method succeeds, otherwise false.</returns>
public static bool SetMAPIProperties(this Outlook.MailItem omi,
Dictionary<MapiProperty.MapiProp, object> properties)
public static bool SetPropertiesNative(this Outlook.MailItem omi,
MAPIProperties mapiProperties)
{
bool success = false;
int count = properties?.Count ?? 0;
if (count > 0)
{
try
{
// Create the necessary arrays
MapiProperty.MapiProp[] props = new MapiProperty.MapiProp[count];
object[] values = new object[count];
int i = 0;
foreach (var kvPair in properties)
{
props[i] = kvPair.Key;
values[i] = kvPair.Value;
}
// Use the adequate method
if (count == 1)
{
success = Mapi.SetMAPIProperty(omi, props[0], values[0]);
}
else
{
success = Mapi.SetMAPIProperties(omi, props, values);
}
}
catch (Exception ex)
{
success = false;
Log.Error("MailItemExtensions.SetMAPIProperties: Error occured. " + ex.ToString());
}
}
else
{
Log.Verbose("MailItemExtensions.SetMAPIProperties: No properties found.");
}
return success;
return Mapi.SetPropertiesNative(omi, mapiProperties);
}
/// <summary>
......
......@@ -168,9 +168,9 @@ namespace pEp
/// </summary>
/// <param name="attachment">The Outlook attachment to set the properties to.</param>
/// <param name="properties">The properties to set.</param>
/// <returns>Null if successful or a dictionary of MAPI properties and their returned error messages.</returns>
public static Dictionary<string, object> SetProperties(Outlook.Attachment attachment,
MAPIProperties properties)
/// <returns>True if successful, otherwise false.</returns>
public static bool SetProperties(Outlook.Attachment attachment,
MAPIProperties properties)
{
dynamic result = null;
Outlook.PropertyAccessor propertyAccessor = null;
......@@ -179,18 +179,29 @@ namespace pEp
{
propertyAccessor = attachment.PropertyAccessor;
result = MapiHelper.SetProperties(propertyAccessor, properties);
if (result is Dictionary<string, object> errors)
{
foreach (var error in errors)
{
Log.Error("SetProperties: Error setting attachment property {0} : {1}", error.Key, error.Value);
}
return false;
}
}
catch (Exception ex)
{
result = null;
Log.Error("SetProperties: Error occured. " + ex.ToString());
return false;
}
finally
{
propertyAccessor = null;
}
return result;
return true;
}
/// <summary>
......
This diff is collapsed.
......@@ -843,7 +843,7 @@ namespace pEp
/// <summary>
/// Any MAPI properties to set.
/// </summary>
public Dictionary<MapiProperty.MapiProp, object> PropertiesToSet;
public MAPIProperties PropertiesToSet;
/// <summary>
/// Default constructor.
......@@ -856,22 +856,16 @@ namespace pEp
this.ProcessedMessage = null;
this.ProcessedRating = pEpRating.pEpRatingUndefined;
this.ProcessedStatus = Globals.ReturnStatus.Success;
this.PropertiesToSet = new Dictionary<MapiProperty.MapiProp, object>();
this.PropertiesToSet = new MAPIProperties();
}
/// <summary>
/// Constructs a new ProcessingCompletedEventArgs with the given arguments.
/// </summary>
/// <param name="rating">The rating after the processing completes.</param>
public ProcessingCompletedEventArgs(pEpRating rating)
public ProcessingCompletedEventArgs(pEpRating rating) : this()
{
this.EntryId = null;
this.IsMirror = false;
this.ProcessedDecryptionFlags = pEpDecryptFlags.pEpDecryptFlagsNone;
this.ProcessedMessage = null;
this.ProcessedRating = rating;
this.ProcessedStatus = Globals.ReturnStatus.Success;
this.PropertiesToSet = new Dictionary<MapiProperty.MapiProp, object>();
}
}
......
......@@ -898,15 +898,9 @@ namespace pEp
}
// Set all properties
if (MapiHelper.SetProperties(newAttachment, propertiesToSet) is Dictionary<string, object> errors)
if (MapiHelper.SetProperties(newAttachment, propertiesToSet) == false)
{
foreach (var error in errors)
{
if (error.Value != null)
{
Log.Error("PEPAttachment.AddTo: Error setting MAPI property {0}: {1}", error.Key, (error.Value as int?)?.ToString("X2") ?? "<null>");
}
}
Log.Error("PEPAttachment.AddTo: Error setting one or more MAPI properties.");
}
// Delete temp directory for attachments
......
......@@ -1127,7 +1127,7 @@ namespace pEp
// Set MAPI properties if needed
if (e.PropertiesToSet?.Count > 0)
{
this.CurrentMailItem?.SetMAPIProperties(e.PropertiesToSet);
this.CurrentMailItem?.SetPropertiesNative(e.PropertiesToSet);
}
Log.Verbose("MailItem_ProcessingComplete: Status bar updated with rating " + Enum.GetName(typeof(pEpRating), e.ProcessedRating));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment