microsoft-graph-apioutlook-restapi

How do I get a usable email message reference id from headers to use in a Microsoft Graph query?


I am trying to use the references message ID in email headers of a forwarded email in Office 365 to then find the original email that has that message ID.

The references ID in the forwarded email's headers would show something like what's shown below. Note I'm obtaining these headers from Microsoft Graph by adding &$select=internetMessageHeaders to my query using sender/subject to find the forwarded email.

{
  "name": "References",
  "value": "<CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7w@mail.gmail.com>"
}

However, if I take this and use it in a query like https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq '<CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7w@mail.gmail.com>'

I do not receive any results.

If I hunt down the original email in Microsoft Graph using sender and subject, I see the following for the internetMessageId field for the original email:

{
  "name": "Message-ID",
  "value": "<CAOLK2SC6s9Me05kYRqeuEHKK8DrQbXx34ScT0AzGOFFLMdRapg@mail.gmail.com>"
}

Does anyone have any ideas on what Office 365 or Microsoft Graph is doing to change CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7w into CAOLK2SC6s9Me05kYRqeuEHKK8DrQbXx34ScT0AzGOFFLMdRapg? It looks like some sort of encoding, but I haven't been able to reproduce it.

Ultimately I would like to be able to transform what I'm getting in the references ID header such that I can turn around and use that ID to find the original email using Microsoft Graph.


Solution

  • I discovered the issue. In my test message-ID I have the characters = and +

    These characters must be URL encoded to %3D and %2B before being used in the $filter query. When they are URL encoded, I am able to find the original email using MS Graph.