When setting MapiMessage flags, I notice that the method SetMessageFlags() clears all previous flags and sets to whatever is passed in. This is limiting; there should be a way to apply a single flag or remove a single flag at a time.
Because of this, I have to set all the flags once at the end of all my MapiMessage setup code with extra logic, like so:
msg.SetMessageFlags(
MapiMessageFlags.MSGFLAG_UNMODIFIED |
MapiMessageFlags.MSGFLAG_READ |
((sentDate <= DateTime.MinValue) ? MapiMessageFlags.MSGFLAG_UNSENT : 0) |
((msg.Attachments.Count > 0) ? MapiMessageFlags.MSGFLAG_HASATTACH : 0)
);
It is not possible to do something like this, because each call to SetMessageFlags() will clear the previous flags:
msg.SetMessageFlag(MapiMessageFlags.MSGFLAG_READ);
…
if (sentDate <= DateTime.MinValue) msg.SetMessageFlag(MapiMessageFlags.MSGFLAG_READ);
…
msg.SetMessageFlag(MapiMessageFlags.MSGFLAG_HASATTACH);
I noticed this problem when adding attachments to MapiMessage by calling MapiMessage.Attachments.Add(); Aspose.Email is calling SetMessageFlags() internally and therefore clears all my previously set flags, which is not nice
I recommend one of two solutions:
1. Add a SetMessageFlag(flag, boolean) method.
This way we can set a single flag on or off.
msg.SetMessageFlag(MapiMessageFlags.MSGFLAG_UNSENT, true);
msg.SetMessageFlag(MapiMessageFlags.MSGFLAG_UNSENT, false);
2. Add a GetMessageFlags() method.
This way we can set a single flag be doing something like this:
msg.SetMessageFlags(msg.GetMessageFlags() | MapiMessageFlags.MSGFLAG_UNSENT);
msg.SetMessageFlags(msg.GetMessageFlags() & ~MapiMessageFlags.MSGFLAG_UNSENT);
Hi
Sorry to report, but we actually do need the functionality to get the message flags from a MapiMessage. This functionality is not currently exposed in the Aspose.Email API. We need to be able to check if a message is read or unread, etc.
So we need some functionality like this:
bool isread = msg.GetMessageFlag(MSGFLAG_READ);
bool issent = !msg.GetMessageFlag(MSGFLAG_UNSENT);
or this:
bool isread = msg.GetMessageFlags() & MSGFLAG_READ;
bool issent = !msg.GetMessageFlags() & MSGFLAG_UNSENT;
It would be nice if both GetMessageFlag(flag) and SetMessageFlag(flag, bool) are implemented. They are simple to add, and necessary functionality.
Thanks!
Actually, in the mean time, I guess we could just get the PR_MESSAGE_FLAGS property in MapiMessage, and then test the bits with the MSGFLAG_READ, etc.
But the GetMessageFlag() would be nice
public static bool GetMessageFlag(MapiMessage msg, MapiMessageFlags flag)
{
bool? output = null;
try
{
long? flags = msg.GetPropertyLong(MapiPropertyTag.PR_MESSAGE_FLAGS);
if (flags != null && flags > 0)
{
output = (((long)flags & (long)flag) > 0);
}
}
catch (Exception ex)
{
log.Error(“Failed to GetMessageFlag for MapiMessage.”, ex);
}
return output ?? false;
}
Hi,
Hi,
bool isread = (msg.Flags & MapiMessageFlags.MSGFLAG_READ) == MapiMessageFlags.MSGFLAG_READ;
bool issent = (msg.Flags & MapiMessageFlags.MSGFLAG_UNSENT) != MapiMessageFlags.MSGFLAG_UNSENT;
Sure, it works.
Hopefully it is just a lightweight property wrapping an int or long, and not wrapping the entire MAPI property accessing. In general I try not to make heavyweight properties that can throw exceptions, because developers will access the property in a statement. If it can throw an exception, I usually make it a method or function.
Thanks
Hi,
The issues you have found earlier (filed as NETWORKNET-33306) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
Is there an analog to:
public MapiMessageFlags Flags