How to parse attachment and update properties from email connection

Hi,

I have the following scenario:

- Email-connection is polling Outlook inbox for new emails.

- Imported email causes the creation of new Document with some class ABC.

- The email has some body content that should be parsed after the email has been imported and few properties on the new Document-object should be updated from the body content.

I have created an event handler with attributes:

[EventHandler(MFEventHandlerType.MFEventHandlerAfterCreateNewObjectFinalize, Class = Aliases.Classes.ABC)]

and this gets triggered after the Document/ABC is created.

In this event handler I schedule a one-time task with TaskManager.AddTask(...) and in the Task-handler I call an extension method that does the actual processing. I pass the ID of the newly created Document-object as the directive for the task and deserialize the object ID from the env.Input in my extension method. No problems so far, my extension method gets called from the task handler and I do get the correct ID for the document object. In the extension method I do call the doc.StartRequireCheckedOut() before trying to access the attached files.

Now I need to get the message body (i.e. the Messages.html-file attached to the Document) but when I try to do that in my extension method, I always get the error:

System.Runtime.InteropServices.COMException (0x80040001): The file has not been committed yet. (File: 81 Version: 2)

And I think it comes from this line:

var bodyContent = vault.ObjectFileOperations.GetTextContentForFile(doc.ObjVer, messageFile.FileVer);

In this case doc is the ObjVerEX pointing to new document and messageFile is the ObjectFile pointing to the Messages.html-file.

Should this logic work? If not, then what would be the logical way to parse the email body and update some properties on the new Document-object after it has been created from the email? Or do I just have some obvious error in my logic that I'm not seeing?

In the desktop client I do see the new Document just fine and there is a Messages.html-file attached to the Document-object and it has the expected content.

- Petri