Get Last Email Content From Graph Message - microsoft-graph-api

I am wanting to get just the most recent message from an email using Graph. So I don't want the whole email chain, just the body or text content of the most recent email. Is this possible without HTML parsing?
thanks

If you use the UniqueBody property https://learn.microsoft.com/en-au/graph/api/resources/message?view=graph-rest-1.0 that should contain what your after eg
https://graph.microsoft.com/v1.0/me/messages?select=subject,receivedDateTime,conversationid,uniquebody

Related

Find the email aliases a message was actually sent to

Is there a way to get the email aliases address to which an email was originally sent from Microsoft Graph?
We have a single email account like main#company.com along with the multiple other associated email addresses (email aliases). Emails send to any of the aliases go to a to the same inbox as main#company.com.
If we send an email to alias#company.com and look at the message using https://graph.microsoft.com/v1.0/me/messages, it shows mail#company.com as the email address. We need to detect if it was sent to alias#company.com.
The information for the allies can be found in the email header and there is a potential workaround in the Outlook API:
https://outlook.office.com/api/v2.0/me/mailfolders/inbox/messages/{messageId}?$select=Subject,SingleValueExtendedProperties &$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x7D')
This returns an unstructured result which needs to be parsed and it is not very convenient. We are looking if there is a more direct way to get this from Microsoft Graph.
You can use the same $filter with Microsoft Graph. You simply need to switch PropertyId to simply id:
?$select=subject&$expand=singleValueExtendedProperties($filter=id eq 'String 0x7D')
Also note that don't need to both select and expand the singleValueExtendedProperties collection. Expanding will ensure it gets included.

How can I determine the original message of a reply?

Using Microsoft Graph, how can I determine which message an outgoing message is a reply to?
The internetMessageHeaders property is not available for items in the Sent Items folder of mailboxes (using the Graph API, at least -- they are available using EWS or IMAP). If it were, I'd look for the in-reply-to header. In the absence of this, is there something in the standard Graph message properties that will tell me this?
You can check the "Subject" or "bodyPreview" to check if the content contains "RE:", if the answer is yes, the message is reply to.
You can group the message by conversationId and then order by lastModifiedDateTime. This way can check if the message is the original one, if it is not ,it will be reply-to/follow-up one.
Get the message list first(/me/messages or /users/{id | userPrincipalName}/messages and so on), and then foreach the message id to call reply api(/users/{id | userPrincipalName}/messages/{id}/reply and so on). The result in the reply is a reply to.
To Test this, you can use the Graph Explorer first and then paste the JSON to a JSON viewer tool. For further use, you need to use net/java and so on to handle.
API reference: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/message
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/message_reply

MailCore2 - Fetch message content without downloading images or attachments?

I want to provide a preview of a user's messages, but I don't wish to download attachments just in order to do that.
The information I need is:
Subject
Date
Sender information (display name if available, email address)
Plain-text message
By calling the method fetchMessagesByNumberOperationWithFolder: with request kind MCOIMAPMessagesRequestKindHeaders, I get the date and subject, but it's very slow to return if any of the messages have attachments. By calling it with request kind MCOIMAPMessagesRequestKindUid, it returns very quickly, with just the Uid (and the current date, as a placeholder). From there, I still need to get the subject, the date and the sender.
Now I'm still trying to get this information, while avoiding downloading message attachments.
Calling fetchParsedMessageOperationWithFolder: or fetchMessageOperationWithFolder: both download the message with attachments, and are thus very slow to return.
Because fetchMessageOperationWithFolder: completes with a NSData object, checking the size of the given object reveals it to be the size of a regular message, plus its' attachment.
What can I do to get the information I need, without downloading any attachments?
EDIT: Calling requiredPartsForRendering could give me the content of the email, but in order to retrieve the Date and sender information, I'd still have to have a request kind of MCOIMAPMessagesRequestKindHeaders, which would download the attachment.
So to clarify:
I want to get the following information from an IMAP email, without downloading the email attachments:
Subject
Date
Sender information (display name if available, email address)
Plain-text message
The following methods should be helpful to you:
-[MCOAbstractMessage requiredPartsForRendering] will return the message parts that you needs to fetch to be able to show the text content of the message.
-[MCOIMAPSession fetchMessageAttachmentOperationWithFolder:uid:partID:encoding:] will help you fetch each of those parts.
-[MCOIMAPMessage htmlRenderingWithFolder:delegate:] will return the rendered content as HTML (or nil if you don't provide all the content of the parts through the delegate.
-[NSString mco_flattenHTML] is also useful if you'd like to convert the HTML to a unformatted string.

Rails Action Mailer - Strip footer information

Users can receive an email that is sent to a list of people. They are given a warning that they can unsubscribe from this listing at any time. The user can Reply All which will be sent back to the server and resent to everyone else. However, the footer still remains in their reply.
I am using ActionMailer to send the emails. They are multipart HTML emails.
What is the easiest way to strip this information? Ideally, I would want it so that any part of the reply message is not built into the message part.
Edit: More information
Think of this as a support ticketing. I would only want to create a new record containing the reply information instead of the chain of replies already in the ticket. For example, if the first email sent has "i need help!", the second reply would contain, "help with what?". The third reply would be "i dunno... i'm bored".
The ticket model would have three records:
Record 1
id = 1
message = "i need help!"
Record 2
id = 2
message = "help with what?"
Record 3
id = 3
message = "i dunno... i'm bored"
edit
doc = Nokogiri::HTML(message.html_part.body.decoded)
doc.xpath("//blockquote").remove
I was able to strip the contents by using a as part of the message. However, the issue that I'm having now is below. Various email clients will add their own line of reply. For example, Outlook adds this.
Gmail adds this
Since these items will be included in the new stripping of the blockquote, how can i parse this part of the reply out as well to prevent having a garbled ticket record with junk data.

How do I get the date a text message was sent to my Twilio number?

I try to get and analyse data from text with the Twilio API. With their example, I can get the phone number from the text is sent, but I would like to get the datetime and the body of the message.
For the phone nmber you just have to use that:
$phone = $_REQUEST['From'];
It works also for To and Body but I tried with DateSent and it's not working.
$date = $_REQUEST['DateSent'];
Do you have an idea about what could be the word to get it?
According to the Twilio Docs the date is not sent as a parameter. However, you can use the Rest API to retrieve the SMS using the $_REQUEST['SmsSid'], and the returned data will contain a DateCreated.
Note: As John commented, unless you really need the 'official' timestamp, it's essentially the current time. Also note that if you try to query the API for a message that just came in, it may not have propagated, so you may not not get the data you're requesting.
If there's some use case where you can't just use the current timestamp, that would be interesting.

Resources