If anybody is following my travails in attempting to create a message in Gmail using the migration API, I did make a bit of progress. The Content-Length value in the http header needs to be increased by the magic value of 22. I have no idea where this comes from, and it has no relation to the size of the message. But I am able to post a message now.
Now my latest problem is that the API will not accept an attachment. An example is below. This same exact data, when sent into Gmail via IMAP,
works fine. The error returned is 400 bad request, and the error message is "Permanent failure: BadAttachment". So now what is the problem?
--Next_Item:_(A3CB49KFSA19)/1
Content-type: application/octet-stream;
name="X.VBS"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="X.VBS"
U2V0IFdTSFNoZWxsID0gV1NjcmlwdC5DcmVhdGVPYmplY3QoIldTY3JpcHQuU2hlbGwiKQ0K
DQpTZXQgYXBwT3V0bCA9IFdzY3JpcHQuQ3JlYXRlT2JqZWN0KCJPdXRsb29rLkFwcGxpY2F0
aW9uIikNCg0KU2V0IG1haU1haWwgPSBhcHBPdXRsLkNyZWF0ZUl0ZW0oMCkNCg0KbWFpTWFp
bC5SZWNpcGllbnRzLkFkZCgiQ2xheXRvbi5FYW1lcy5AYWNhZGlhLWlucy5jb20iKQ0KDQpt
YWlNYWlsLlN1YmplY3QgPSAiVGVzdGluZyBPdXRsb29rIEVNQUlMIFRlc3QgIzAwMCINCg0K
bWFpTWFpbC5Cb2R5ID0gIkNhbiBZb3UgU2VlIFRoaXMgLSBOb3RlIFRoZXJlIGlzIG5vIEZS
T00gYWRkcmVzcyAtIHBsZWFzZSBsZXQgRGVubmlzIFJlZGZpZWxkIGtub3cgeW91IGdvdCB0
aGlzLiINCg0KbWFpTWFpbC5BdHRhY2htZW50cy5BZGQoIkM6XHRlbXBceC52YnMiKQ0KDQpt
YWlNYWlsLlNlbmQNCg0KDQpTZXQgYXBwT3V0bCA9IE5vdGhpbmcNClNldCBtYWlNYWlsID0g
Tm90aGluZw0KU2V0IHJlY01lc3NhZ2UgPSBOb3RoaW5nDQoNCg==
--Next_Item:_(A3CB49KFSA19)/1--