How to insert message with Content-Type message/rfc2822 using Gmail API? - gmail-api

I wanna write a small application that copy Gmail messages from one user folder to another. My approach is next:
Get raw message data to temporary placeholder;
Compose message using raw message data from the previous step;
Add message to required folder.
I can get raw message data as RFC 2822 formatted and base64url encoded string using this get request.
Also I can insert message to user mailbox with insert request. As documentation states, I can use one of the next two approaches:
use /upload URL (then I need an uploadType string and I should have a content-type of message/rfc822);
not using /upload URL and simply set message metadata in the request body -
something like the next JSON:
{
"labelIds": [
"INBOX",
"CATEGORY_PROMOTIONS"
],
"raw": "UmVjZWl2ZWQ6IGZyb20gMjkyODI0MTMyMDgyDQoJ..."
}
Unfortunately, when I don't use /upload URL (approach (2)) I can't insert message with attachment bigger than 5MB. But if I use /upload URL (approach (1)) I get response with error
"Media type 'message/rfc2822' is not supported. Valid media types: [message/rfc822]".
How can I support insertion of messages to Gmail without restriction on messages attachment size?

Related

Sending data to Devo with HTTP requests are received with unknown tags: "unknown.unknown"

I am trying to send data to Devo with HTTP requests. The request works and 204 status is received. I am following Devo docs where this method is explained.
I can search the data in Devo but it is contained in unknown.unknown table. What am I doing wrong?
http://http-us.logtrust.io/event/MY_DOMAIN/token!MY_TOKEN/local1/XXXX.test.example?hello_world_message
Previously I created the token with target table: XXXX.test.* (where XXXX is the name of the project).
After spending some time I found the answer in one of the Devo docs:
https://docs.devo.com/confluence/ndt/supported-technologies/special-devo-tags-and-data-tables
The problem was I was using "XXXX.test" as tag when first and second positions of the tags define the technology to parse the data. In this case, it is a custom application so it is necessary to use "my.app".
Before execute request it was necessary to create a new token for the new tags to use: "my.app.test.*"
Now I can visualize the data in Devo.

Microsoft graph API --> To see if the message is a reply

I am using the graph API to retrieve the mail from mail folders. For example I got a mail, I will change or edit the subject line and store the conversation id for future use. if I got the reply mail for the same email chain I got different conversation id. How to handle this, I need to find out the reply mail.
"subject": "Test",
"conversationId": "AAQkADU1YWM2MjMyLTVkOGQtNDdiMy05YWM4LTE4NTNlYzg1ZWRiNwAQADofdbq8_JtJkY8M5wnunlU=",
reply msg:
"subject": "Re: Test1",
"conversationId": "AAQkADU1YWM2MjMyLTVkOGQtNDdiMy05YWM4LTE4NTNlYzg1ZWRiNwAQAHu3pWtxNmBFjdfyjYaVGKc=",
I need to find this ts reply message.
I'd suggest you use the In-Reply-To header https://wesmorgan.blogspot.com/2012/07/understanding-email-headers-part-ii.html in that way you can relate multiple replies (to the same replied to message) in a Message chain etc. You can either get the In-Reply-To header by requesting the InternetHeaders https://learn.microsoft.com/en-us/graph/api/resources/internetmessageheader?view=graph-rest-1.0 (this will return all the headers) or you can request the extended property to just get that one property eg
https://graph.microsoft.com/v1.0/users('user#domain.com')/MailFolders('Inbox')/messages/?$select=ReceivedDateTime,Sender,Subject,IsRead,inferenceClassification,InternetMessageId,parentFolderId,hasAttachments,webLink&$Top=10&$expand=SingleValueExtendedProperties($filter=(Id%20eq%20'String%200x1042'))

POST multipart/form-data with NodeRed HTTP request

I'm trying to generate a HTTP Webrequest in NodeRed that will upload a file to a website via a normal upload form. I guess i knwo how to upload a file, but i do not know how to pass the other input fieds i have to fill also.
I only found how to set http headers:
msg.headers["content-type"] = "multipart/form-data";
This is what i have so far:
I have also tried in "the missing part" to write the FormData and send the Request manually. (https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects)
But also no luck with that. Only received an Error that FormData is unknown...
In the function node, before sending msg, set request header like this
msg.headers = {
"content-type":"application/x-www-form-urlencoded"
}

libcurl imaps doesn't returns Header Field "Content-Transfer-Encoding" or "Content-Type"

I have been trying to detect encoding of an email manually, to see whether the email that i have just fetched needed to be base64 decoded or not, but that wasn't a complete solution.
So now I'm trying to download the headers (fields) of an email first, check them what kind of email it is and then proceed to decoding it with base64 in case the header says that it is a base64 encoded email or just skip it if it is a plain text or HTML text.
The problem is that the libcurl commands for fetching these fields doesn't really work, most of the time the "Content-Type" returns just an empty string or says that it is a multipart/alternative but when i check the email manually it is just a plain text which obviously doesn't need to be decoded.??
"Content-Type" field multipart/alternative usually have different parts like text, html, base64 encoded text, attachments etc.
In cases of multipart/alternative the "Content-Transfer-Encoding" field doesn't return anything at all, and this is the most important header field for me to know what it contains.
My imaps request to Gmail account looks like this:
curl_easy_setopt(curl, CURLOPT_URL,"imaps://imap.gmail.com:993/INBOX;UID=33;SECTION=HEADER.FIELDS%%20(Content-Transfer-Encoding%%20Subject%%20From%%20Content-Type)");
Which returns this:
Subject: my subject
From: myname
Content-Type: multipart/alternative; boundary="001a114930a049c6da05dskdls9"
As you can see it doesn't returns the "Content-Transfer-Encoding" field.
This email actually contains the word "Yup" only, so it is a plain text and no attachments, when checked by clicking on the "show original" message in browser.
Sys info:
Linux, C , libcurl, gmail

Getting more data from messages.get in C#

I'm having trouble getting more than just the snippet for text data for the message I am trying to retrieve using the Gmail API. Here is the piece of test code I am working with:
public string GetMail()
{
GmailService service = (GmailService)HttpContext.Current.Session["service"];
Message messageFeed = service.Users.Messages.List("me").Execute().Messages.First();
UsersResource.MessagesResource.GetRequest getReq = new UsersResource.MessagesResource.GetRequest(service, "me", messageFeed.Id);
getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Full;
Message message = getReq.Execute();
return message.Raw;
}
For some reason, when I call message.Raw, it is returning null. I am able to retrieve other properties as what the format=minimal setting would based off of the API playground example I was playing with.
However in my code, I am setting the format enum to "full", yet I am still unable to retrieve the full data of the message.
Am I completely missing something here?
Seems like you're mixing up formats and response types. If you want the raw message as a string in Message.raw then you need to set:
getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
If you want the parsed message back (in the "payload" field) then you can use getReq.Format of Full like you have.
Acceptable values are:
"full": Returns the parsed email message content in the payload field and the raw field is not used. (default)
"minimal": Only returns email message metadata such as identifiers and labels, it does not return the email headers, body, or payload.
"raw": Returns the entire email message content in the raw field as a string and the payload field is not used. This includes the identifiers, labels, metadata, MIME structure, and small body parts (typically less than 2KB).
from: https://developers.google.com/gmail/api/v1/reference/users/messages/get

Resources