Noticed this in my production app today as well. The change log did not give a clue as to what happened, but I found the problem in the new documentation for managing threads:
- The requested
threadId
must be specified on the Message
or Draft.Message
you supply with your request.
- The
References
and In-Reply-To
headers must be set in compliance with the RFC 2822 standard.
- The
Subject
headers must match.
In other words, the threadId
needs to be supplied. I don't know if this is a bug or not, since it is not documented in the sending message-documentation that was updated on the same day.
I want to respond to the latest message in my inbox. Let's get the relevant information:
Request 1:
maxResults = 1
fields = messages/id
GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1&fields=messages%2Fid
Response 1:
{
"messages": [
{
"id": "15071b210a1ac883",
"threadId": "15071a4886871a10"
}
]
}
Request 2:
format = metadata
metadataHeaders = In-Reply-To,References,Message-ID,Subject
fields = payload/headers
GET https://www.googleapis.com/gmail/v1/users/me/messages/15071b210a1ac883?format=metadata&metadataHeaders=In-Reply-To&metadataHeaders=References&metadataHeaders=Message-ID&metadataHeaders=Subject&fields=payload%2Fheaders
Response:
{
"payload": {
"headers": [
{
"name": "In-Reply-To",
"value": "<CADsZLRyej6wRwCNYv91+dBu9uYhuqYo4pEqOpt41NftXJJqC7g@mail.gmail.com>"
},
{
"name": "References",
"value": "<CADsZLRyej6wRwCNYv91+dBu9uYhuqYo4pEqOpt41NftXJJqC7g@mail.gmail.com>"
},
{
"name": "Message-ID",
"value": "<CADsZLRzipMRrQv-A9m-r-EJafXXm1eS9ihw3ZD5g8ybfj+LYeg@mail.gmail.com>"
},
{
"name": "Subject",
"value": "Re: Perculiar"
}
]
}
}
All that is left is to create a message with all this data in the right places:
Request 3:
POST https:
Content-Type: multipart/related; boundary="foo_bar_baz"
--foo_bar_baz
Content-Type: application/json; charset=UTF-8
{
"threadId": "15071a4886871a10"
}
--foo_bar_baz
Content-Type: message/rfc822
Content-Type: multipart/mixed; boundary="foo_bar"
In-Reply-To: <CADsZLRzipMRrQv-A9m-r-EJafXXm1eS9ihw3ZD5g8ybfj+LYeg@mail.gmail.com>
References: <CADsZLRyej6wRwCNYv91+dBu9uYhuqYo4pEqOpt41NftXJJqC7g@mail.gmail.com> <CADsZLRzipMRrQv-A9m-r-EJafXXm1eS9ihw3ZD5g8ybfj+LYeg@mail.gmail.com>
From: [email protected]
To: [email protected]
Subject: Re: Perculiar
--foo_bar
Content-Type: text/html; charset="UTF-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
<div dir="ltr"><b> This is where the message text goes </b></div>
--foo_bar
Content-Type: image/png
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="cool.png"
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAADd9JREFUeNrsWnuQXFWZ/+6j+/ZzeiYzk5lkHkkIM3nikIeTEARqNYRSKRXcxQGxLAqipiJBUlIqurvlupavKikpdpFQiFVLJOADUcLKbBCVoCRAkCSEJJPJTCbT8+qeft7345z9zr2nZzoyIRMS/7CKmzq5nb73nvs9f9/v+zoCpRT+kQ8R/sGP9xR4T4ELPOTKh3k3P3xeD9av69rg2lYPUc11rm4sclU95RlWiNi2IIbDVFIUR5BjRUGMDohKZJ+sKLvKA2/8+XzeMbbrc2f8eybAkc9X4zndy+91imqPdrR/WWt7k9x5SRMsbaqDtvooiFIIcqYAQ1lTyBXK4Ym82pgpW435ktpdGhveotS2HBXk8C4zO/Dti+UBoaLVuTwwZ/3Kzzv54rYkoUuvXLFA/PT72yBrhuHwiAlH00UYSGdhMl8G3XYgJAkQCYmQikehtjYFDakoKIIDRwYzkB7LeLYnHEd73m+XJn58oR6YlQK1XR1PSJOFj1+3boly/aoO2HtChRcOj8PpsRwQ1+Z3EXwDewvBFxG2sX8Gtr9AIRmNQGtjEloaknBiaBQGhkZNTww/c/qRf7mpuWcH/bsoULd61WK3lN/ZUR9b94UPLYcDaQl+tf806OUyEOKyLZlsvpDsD1QE5p/Z3gJXCNj9hIAkS3BpcxLmJmV4vW8McmXtVWqWP00k5fhFzQEmvKjmnr66o2nFxrVdsGPvBBwbHAJiab5FBQZggfS+4QUOahVFqCD4lyn3DiWBEq6uw5ETeRhPRuDyRXXQN0zWpifMp6g+eQON1h+/aDBq5/I71y9qWrGiowv+4xcDcOzkMBCbCS8E4lbOuAT8zASmU98z3QTuIeoLT6mD8lu4TABHg8zEKPxx30FoVAxoTAjLQQw/jhYPXZQkTnZ2PHFpTeimz1x3JXzzl/3gajm0nhMIGjzmC0ccDwVygXoeF5KHkJ8DHt6FZ4kpwe4xgTomPoMKuAYqYeGeFgieC0vb62EwtBxKA68+Pb773
--foo_bar--
--foo_bar_baz--
This results in a new message with an attachment threaded like before:
