Bypass internal exceptions during MAPI To MIME conversion

Hello,

A customer recently encountered the following exception during a MAPI to MIME message conversion (using the MAPIMessage.ToMailMessage() method):

Aspose.Email.AsposeException: Start date 11/29/2023 4:30:00 PM not valid for this rule - Recur every 3 month(s) on the Tuesday on the 3rd set position(s) on until 11/29/2023 12:00:00 AM. If you want to ignore an exception and want to proceed further then you can use: ExceptionManager.IgnoreList.Add(@“RecurrenceRule\InvalidStartDate”)

Currently, the result is an email that is not converted, which is not acceptable from our product. The issue is only a wrong-formatted “start-date” parameter, which from a practical point of view may simply be replaced by a default value. As said before, there must be a result, a “readable” converted email, even if it is and will never be a perfect conversion because of the initial unrecoverable issue.

Unfortunately I cannot reproduce the issue and was wondering about the ExceptionManager.IgnoreList.Add() method from the exception message above:

  1. Does this IgnoreList actually allows skipping internal exceptions like this (using the “@“RecurrenceRule\InvalidStartDate” parameter in our case), and continue the conversion process anyway, to finally get an although imperfect, converted email anyway?
  2. When reading this thread: Error loading ICS - #4 by australian.dev.nerds , it seems the @“RecurrenceRule\InvalidStartDate” parameter must be more specific, using a special GUID I don’t understand either: *ExceptionManager.IgnoreList.Add(@“Appointment\Load\InvalidStartDate\355e983b-0513-444d-b1c3-79da4867b54e”); *. Did you update the API for a more general use case, skipping this GUID, like in the exception message above?

Thank you in advance for your answers.

To address your questions regarding the use of the ExceptionManager.IgnoreList during the MAPI to MIME conversion process:

  1. Yes, the IgnoreList can be utilized to skip specific internal exceptions, including the one related to the invalid start date in your case. By adding the entry ExceptionManager.IgnoreList.Add(@"RecurrenceRule\InvalidStartDate"), you should be able to continue the conversion process despite encountering this specific exception. This allows you to obtain a converted email, albeit it may not be perfect due to the underlying issue.

  2. Regarding the specificity of the parameter, it is true that earlier versions of the API required a more precise identifier, including the specific invalid start date. However, the API has been updated to allow for more general use cases, enabling you to bypass exceptions without needing to specify the exact invalid date. This means you can use the more general entry as mentioned above, which should work for your scenario.

For further details on how to implement this, you can refer to the documentation on the ExceptionManager and examples provided for ignoring exceptions.

If you have any more questions or need further assistance, feel free to ask!

Sources:
[1]: AsposeException is throwing exception when reading data from the iCalender file

Thank you very much for your quick (and satisfying) answers!

You’re welcome! If you have any more questions, feel free to ask.

Hello again,

I followed this post, and added the following C# code to the project, of course before any MAPI to MIME conversion (using MapiMessage.ToMailMessage() method) is proceeded :

ExceptionManager.IgnoreList.Add("MapiMessage\\ToMailMessage");

Yet a customer still encountered the almost same exception as described in the first post:

  • MapiMessage.ToMailMessage (MailConversionOptions options)
    Aspose.Email.AsposeException: Start date 5/13/2024 8:30:00 PM not valid for this rule - Recur every month on the 11th day(s) of the month. If you want to ignore an exception and want to proceed further then you can use: ExceptionManager.IgnoreList.Add(@“RecurrenceRule\InvalidStartDate”)*

Can you please explain what is wrong with this code implementation?
From what I understood:

  1. Using the “MapiMessage\\ToMailMessage” parameter prevents from any inner exception to stop the conversion process when using the MapiMessage.ToMailMessage() conversion method.
  2. The ExceptionManager.IgnoreList.Add(“”) method is not related to any MapiMessage instance (for example), and can be set anywhere “freely” in the project before a conversion.

Thank you for your answer.

Hello @anthonypr,

It seems, the string “MapiMessage\ToMailMessage” is not specific enough to target the exact exception you want to ignore. To target this exception, you need to use a more specific string, like “RecurrenceRule\InvalidStartDate”, as suggested in the exception message.

Your current setup is correct in that you call it before any conversion happens, but the string you pass should match the part of the exception message you want to ignore.

I understand that you’d prefer to suppress all exceptions occurring during the execution of the ToMailMessage method. Let me discuss this matter with the developers on Monday, and I’ll get back to you with more details afterward.

The post stated that you can bypass MapiMessage.Load() inner exceptions using the “MapiMessage\Load” parameter, which from my point of view was analog to MapiMessage.ToMailMessage() with “MapiMessage\ToMailMessage”, since an external message is “converted” into an email class with possible parameter mistakes.

I thought about a workaround: if the inner exception message always contains the following part:

If you want to ignore an exception and want to proceed further then you can use: ExceptionManager.IgnoreList.Add(“parameter”)

, it may be possible to first catch the exception, get the right “IgnoreList parameter” value from the exception message, then use the “ExceptionManager.IgnoreList.Add(“parameter”) code” with that value in order to retry a conversion that wouldn’t be canceled this time.

Do all the inner exceptions from our case provide the "If you want to ignore an exception and want to proceed further then you can use: ExceptionManager.IgnoreList.Add(“p”) " part?
This would resolve the gobal issue.

Hello @anthonypr ,

I see what you mean, I’ll pass this information on to our developers.

Thank you for clarifying.

Hello @anthonypr ,

The GUID in the error path uniquely identifies the error, while the first part of path used to group errors.
If you need to ignore only a specific error, specify its unique path with the GUID:

ExceptionManager.IgnoreList.Add(@"Appointment\Load\InvalidStartDate\355e983b-0513-444d-b1c3-79da4867b54e");

If you need to ignore all Appointment loading errors:

ExceptionManager.IgnoreList.Add(@"Appointment\Load");

You can also use your own custom exception handler:

ExceptionManager.IgnoreExceptionsHandler = (exception, path) => { return path.Equals(@"Appointment\Load"); };

You can also ignore all errors:

ExceptionManager.IgnoreAll = true;

Collect a log of ignored errors:

ExceptionManager.IgnoreExceptionsLogHandler = message => { Console.WriteLine("--- EXCEPTION IGNORED ---" + message); };"

Thank you for your answer.

In this release note, you are describing the structure of the parameter to be used with the ExceptionManager.IgnoreList.Add(parameter) method (right after : “Set a callback to handle exceptions:”):

exception path: {Module}\{Method}\{Action}\{GUID}

Later the documentation is using the following example:

//Ignore all exceptions on MailMessage.Load
ExceptionManager.IgnoreList.Add(“MailMessage\Load”);

Which means the “\{Action}\{GUID}” part is in fact not always needed.

I used:

ExceptionManager.IgnoreList.Add(“MapiMessage\ToMailMessage”)

, so with:
Module = MapiMessage; Method = ToMailMessage.

From what I understand above, this should work. But as said previously, a customer encountered an inner exception during the MapiMessage.ToMailMessage() code.

You’re right—using "MapiMessage\ToMailMessage" should ignore exceptions for the MapiMessage.ToMailMessage() method.
We’ll look into this to investigate why adding ExceptionManager.IgnoreList.Add("MapiMessage\\ToMailMessage") isn’t working as it should in your case.