Jeff McKay
Jeff McKay

Reputation: 295

Gmail "InternalDateSource" query parameter not working

I asked this question last month, and had no response. Isn't Google supposed to be monitoring this forum for Gmail API questions? Is there another place that I could get support (even paid?) I'm kind of desperate. Anyway...

I am using the "insert" API to add a message to Gmail, and using the query parameter internalDateSource=dateHeader. However Gmail seems to ignore the "Date" header that is in my RFC822 data, just substituting the current date. My POST url looks like this:

https://www.googleapis.com/gmail/v1/users/[email protected]/messages?uploadType=multipart&internalDateSource=dateHeader&access_token=XYZ

My uploaded data looks like this:

{ "labelIds": [ "Label_96" ],"raw": "RnJvbTo...tDQr_" }

There is no doubt that the correct "Date" header is in the encoded raw data. (Here is an example):

Date: Wed, 1 Oct 2011 10:47:00 -08:00

Google picks up all the other headers and message data correctly. What am I doing wrong? BTW I did try adding "payload" and "headers" to my json in an attempt to specify a Date header. No change.

Upvotes: 2

Views: 231

Answers (1)

Tholle
Tholle

Reputation: 112787

TL;DR

I think you formatted your Date wrong. It should be

Wed, 1 Oct 2011 10:47:00 -0800

Not

Wed, 1 Oct 2011 10:47:00 -08:00

This question really intrigued me, and I got it to work!

First, I created an example mail, encoded it and made it URL safe:

btoa(
        "Date:  Thu, 1 Jan 1970 01:00:00 -0400\n"
        "Content-Type: text/plain;\n" +
        "to: [email protected]\n" +
        "from: [email protected]\n" +
        "subject: Example Subject Text\n\n" +

        "The actual message text goes here"
  ).replace(/\+/g, '-').replace(/\//g, '_');

I used my own email address instead of [email protected], of course.

Which resulted in the following base64-encoded data:

RGF0ZTogIFRodSwgMSBKYW4gMTk3MCAwMTowMDowMCAtMDQwMApDb250ZW50LVR5cGU6IHRleHQvcGxhaW47CnRvOiBleGFtcGxlQGdtYWlsLmNvbQpmcm9tOiBleGFtcGxlQGdtYWlsLmNvbQpzdWJqZWN0OiBFeGFtcGxlIFN1YmplY3QgVGV4dAoKVGhlIGFjdHVhbCBtZXNzYWdlIHRleHQgZ29lcyBoZXJl

Then, I just mimicked your request:

POST https://www.googleapis.com/gmail/v1/users/me/messages?internalDateSource=dateHeader&key={YOUR_API_KEY}

{
 "raw": "RGF0ZTogIFRodSwgMSBKYW4gMTk3MCAwMTowMDowMCAtMDQwMApDb250ZW50LVR5cGU6IHRleHQvcGxhaW47CnRvOiBlbXRob2xpbkBnbWFpbC5jb20KZnJvbTogZW10aG9saW5AZ21haWwuY29tCnN1YmplY3Q6IEV4YW1wbGUgU3ViamVjdCBUZXh0CgpUaGUgYWN0dWFsIG1lc3NhZ2UgdGV4dCBnb2VzIGhlcmU="
}

Which resulted in a mail on the beginning of the epoch under my "All mail"-label.

Upvotes: 2

Related Questions