Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Retreiving attachment from digitally signed messages

$
0
0

Managed API 2.0 / VS2012 / Exchange 2010SP2

I'm working for an insurance company and we receive many signed emails. We have automatic document storage solutions that extract documents from emails and store them in a separate server. We have a problem with signed emails where the extraction cannot manage to get at the attachments in signed emails (multipart/signed mime type).

When we traverse the attachment collections on these emails they invariably only contain one attachment, which is the smime content. When we load that content into a new instance of EmailMessage and save it, that email also only contains that very same attachment, making it all look a bit like a pandora's box.

Following is a code snippet that I've been tinkering with to try to resolve this issue.

            var msg = new EmailMessage(service);
            // Create and load a new message with the mime content of the p7m attachment (containerAttachment)
            msg.Save(containerMessage.ParentFolderId);
            msg.Load(PropertySet);
            msg.MimeContent = new MimeContent("ascii", containerAttachment.Content);
            // Update the message to the server
            msg.Update(ConflictResolutionMode.AlwaysOverwrite);
            msg.Load(PropertySet);
            foreach (FileAttachment attachment in msg.Attachments)
            {
                // Now lets get at the juicy attachments within
                var m = new EmailMessage(service);
                m.Save(containerMessage.ParentFolderId);
                m.Load(PropertySet);
                m.MimeContent = new MimeContent("ascii", attachment.Content);
                m.Update(ConflictResolutionMode.AlwaysOverwrite);
                m.Load(PropertySet);
                // Oh, no, at this point the only attachment is identical to the original container attachment....
                var c = msg.Attachments.Count;
            }

I'd be grateful for any pointers in the right direction



Viewing all articles
Browse latest Browse all 7132

Trending Articles