Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UniqueBody is not very unique?

I'm trying to read the content of an email in HTML. My problem though, is that my body is not very unique though I'm loading the EmailMessageSchema.UniqueBody.

Here's my expected solution:

var props = new PropertySet(BasePropertySet.IdOnly, 
    EmailMessageSchema.UniqueBody,
    EmailMessageSchema.Subject,
    EmailMessageSchema.To,
    EmailMessageSchema.From
    /*Futher properties if needed*/);

props.RequestedBodyType = BodyType.HTML;

var message = EmailMessage.Bind(subscription.Service, item.ItemId, props);

// Should be unique
var uniqueBody = message.UniqueBody.Text;

When debugging and investigate my uniqueBody variable, I can clearly see that this is not unique. It takes the entire body of the email prior to the current email (as the current email is a response, i wouldn't expect to get the content of the email responded to).

I'm not sure I understand the concept of the EmailMessageSchema.UniqueBody property, or perhaps I'm simply doing something wrong?

So, how do I get the unique body of a reply email, without it's parents body?

like image 326
Detilium Avatar asked Mar 13 '17 11:03

Detilium


Video Answer


1 Answers

Explanation:

As defined in the documentation (link here), UniqueBody is:

the body part that is unique to the conversation that this item is part of

The main part of this sentence is the idea of conversation: it is a notion from your mailbox, not from the message. As a consequence, the field UniqueBody will give you only the newest part of a message after an initial one.

For the 1st message, even if it includes several messages (due to a forward or reply), UniqueBody will contain everything.


Sample:

I used my external address "mailA" to forward a message from "mailB" to "mailEWS" which will be the address where I query emails with EWS. I added a comment on this forward, named "Forwarded email sample".

Here is what I got when getting the message in "mailEWS":

<html>
   <body>
      <div>
         <div>
            <div dir="ltr">
               <span dir="ltr">
                  Forwarded email sample
                  <div>
                     <br>
                     <div>
                        Test from MailB &lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;:<br>
                        <div style="margin:0 0 0 0.8ex;padding-left:1ex;border-left:1px solid #CCCCCC;">Dear user,<br>
                           <br>
                           Content of initial email from mailB<br>
                           <br>
                           Sincerely,<br>
                           Test<br>
                        </div>
                     </div>
                  </div>
               </span>
            </div>
         </div>
      </div>
   </body>
</html>

As you can see I got the original message and the comment on the forward.

Then:

  • mailEWS replies (text = "reply 1"
  • mailA replies on that reply (reply text is "Reply from external address")

So I got a new message in my mailEWS mailbox, when getting the UniqueBody with EWS:

<html>
   <body>
      <div>
         <div>
            <div dir="ltr"><span dir="ltr">Reply from external address</span></div>
            <div><br>
            </div>
         </div>
      </div>
   </body>
</html>

As you can see, I get only the newest part of the message in the conversation, not all the previous replies (but those items are in Body field)

like image 119
Nicolas R Avatar answered Sep 19 '22 16:09

Nicolas R