EWS — Determines if the email is a reply or sent

I use the Exchange Web Services managed API 2.2 to monitor user inboxes and must determine if the email is a new item, a reply, or a forwarded message.

I saw various articles about SO, such as how to notice that mail is redirected mail? and is there a way to determine if an email is a reply / reply using ews c #? which help in specific cases, but I still cannot figure out how to distinguish the response from the redirected element.

The first article adds an extra 5 bytes each time (forward or in response), so I don't know what was the last.

The second article suggests using it InReplyTo, however, when I examine the property for forwarded email messages, it contains the sender's email address (but not null).

I have seen other articles, such as this or this , that suggest using advanced properties to check values ​​in PR_ICON_INDEX, PR_LAST_VERB_EXECUTED and PR_LAST_VERB_EXECUTION_TIME.

My code is as follows, but never returns a value for lastVerbExecuted

var lastVerbExecutedProperty = new ExtendedPropertyDefinition(4225, MapiPropertyType.Integer);

var response = service.BindToItems(newMails, new PropertySet(BasePropertySet.IdOnly,  lastVerbExecutedProperty));
var items = response.Select(itemResponse => itemResponse.Item);

foreach (var item in items)
{
    object lastVerb;

    if (item.TryGetProperty(lastVerbExecutedProperty, out lastVerb))
    {
        // do something
    }
}
+4
source share
3 answers

PR_ICON_INDEX, PR_LAST_VERB_EXECUTED PR_LAST_VERB_EXECUTION_TIME , , "". , , "". , , . In-Reply-To Transport, , , - , , .

        FindItemsResults<Item> fiRs = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
        PropertySet fiRsPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
        ExtendedPropertyDefinition PR_TRANSPORT_MESSAGE_HEADERS = new ExtendedPropertyDefinition(0x007D, MapiPropertyType.String);
        fiRsPropSet.Add(PR_TRANSPORT_MESSAGE_HEADERS);
        service.LoadPropertiesForItems(fiRs.Items, fiRsPropSet);
        foreach (Item itItem in fiRs)
        {
            Object TransportHeaderValue = null;
            if(itItem.TryGetProperty(PR_TRANSPORT_MESSAGE_HEADERS,out TransportHeaderValue)) {
                string[] stringSeparators = new string[] { "\r\n" };
                String[] taArray = TransportHeaderValue.ToString().Split(stringSeparators, StringSplitOptions.None);
                for (Int32 txCount = 0; txCount < taArray.Length; txCount++)
                {
                    if (taArray[txCount].Length > 12)
                    {
                        if (taArray[txCount].Substring(0, 12).ToLower() == "in-reply-to:")
                        {
                            String OriginalId = taArray[txCount].Substring(13);
                            Console.WriteLine(OriginalId);
                        }
                    }
                }

            }
        }

Subject, , , .

Glen

+1

ResponeCode

.

private static int IsForwardOrReplyMail(ExchangeService service, EmailMessage messageToCheck)
    {
        try
        {
            // Create extended property definitions for PidTagLastVerbExecuted and PidTagLastVerbExecutionTime.
            ExtendedPropertyDefinition PidTagLastVerbExecuted = new ExtendedPropertyDefinition(0x1081, MapiPropertyType.Integer);
            ExtendedPropertyDefinition PidTagLastVerbExecutionTime = new ExtendedPropertyDefinition(0x1082, MapiPropertyType.SystemTime);

            PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, PidTagLastVerbExecutionTime, PidTagLastVerbExecuted);
            messageToCheck = EmailMessage.Bind(service, messageToCheck.Id, propSet);

            // Determine the last verb executed on the message and display output.
            object responseType;
            messageToCheck.TryGetProperty(PidTagLastVerbExecuted, out responseType);

            if (responseType != null && ((Int32)responseType) == 104)
            {
                //FORWARD
                return 104;
            }
            else if (responseType != null && ((Int32)responseType) == 102)
            {
                //REPLY
                return 102;
            }


        }
        catch (Exception)
        {
            return 0;

            //throw new NotImplementedException();
        }

    }
0

, , EmailMessage InReplyTo, :

EmailMessage mail = ((EmailMessage)Item.Bind(service, new ItemId(UniqueId)));

if (mail.InReplyTo == null)
    return;
else
    ..your code
0

Source: https://habr.com/ru/post/1608494/


All Articles