drafts.create in objective-c using GTLQueryGmail

元气小坏坏 提交于 2019-12-24 02:44:08

问题


I seem to be confused on how to use GTMMIMEDocument.h to set the raw message data for a new draft. In the example I'll post below I'm trying to set the headers for To, From and Subject but they seem to end up in the message body data instead of with the other headers.
Any help on what I'm doing wrong is much appreciated. Thanks.

Query method:

//message body to save
NSData *messageBody = [self.messagebox.text dataUsingEncoding:NSUTF8StringEncoding];

//create mimemessage
GTMMIMEDocument *email = [GTMMIMEDocument MIMEDocument];
NSArray *headers = @[@"To",@"From",@"Subject"];
NSArray *values = @[@"listserveproject2014dh@googlegroups.com",self.auth.userEmail,@"test email"];
NSDictionary *partheaders = [NSDictionary dictionaryWithObjects:values forKeys:headers];
[email addPartWithHeaders:partheaders body:messageBody];

//generate input stream
NSInputStream *inputstream = nil;
unsigned long long length = nil;
NSString *boundary = [[NSString alloc] init];
[email generateInputStream:&inputstream length:&length boundary:&boundary];

//get rawdata
uint8_t *buffer = malloc(sizeof(uint8_t));
[inputstream read:buffer maxLength:NSUIntegerMax];
NSData *rawdata = [NSData dataWithBytes:buffer length:length];

//create query
GTLGmailDraft *draft = [[GTLGmailDraft alloc] init];
GTLGmailMessage *message = [[GTLGmailMessage alloc] init];

message.raw = GTLEncodeWebSafeBase64(rawdata);
draft.message = message;

//GTLUploadParameters *parameters = [GTLUploadParameters uploadParametersWithData:rawdata MIMEType:@"message/rfc822"];
GTLQueryGmail *query = [GTLQueryGmail queryForUsersDraftsCreateWithUploadParameters:nil];
query.draft = draft;

...execute query

This is the response it gets:

{
"id": "r-2881802111797802342",
"message": {
 "id": "149a2aa34d4def95",
 "threadId": "149a2aa34d4def95",
 "labelIds": [
   "DRAFT"
 ],
 "snippet": "--END_OF_PART From: dhill4554@gmail.com Subject: test email To: listserveproject2014dh@googlegroups.",
 "historyId": "919257",
 "payload": {
   "partId": "",
   "mimeType": "text/plain",
   "filename": "",
   "headers": [
    {
     "name": "Received",
     "value": "from 58891527906-b79qq2lqjudtsj32n8ldpkup78uquol6.apps.googleusercontent.com named unknown by gmailapi.google.com with HTTPREST; Tue, 11 Nov 2014 22:21:43 -0800"
    },
    {
     "name": "Date",
     "value": "Tue, 11 Nov 2014 22:21:43 -0800"
    },
    {
     "name": "Message-Id",
     "value": "<CAOabQUdz8wzxQ29HbJq6xeRsSuu1iH6iRi9=A23vYHJencNdoQ@mail.gmail.com>"
    },
    {
     "name": "From",
     "value": "dhill4554@gmail.com"
    }
   ],
"body": {
  "size": 136,
  "data":  "LS1FTkRfT0ZfUEFSVA0KRnJvbTogZGhpbGw0NTU0QGdtYWlsLmNvbQ0KU3ViamVjdDogdGVzdCBlbWFpbA0KVG86IGxpc3RzZXJ2ZXByb2plY3QyMDE0ZGhAZ29vZ2xlZ3JvdXBzLmNvbQ0KDQptZXNzYWdlDQotLUVORF9PRl9QQVJULS0NCg=="
 }
},
"sizeEstimate": 466
}
}

And here's what the raw data looks like decoded(the message body is "message"):

--END_OF_PART
From: dhill4554@gmail.com
Subject: test email
To: listserveproject2014dh@googlegroups.com

message
--END_OF_PART--

来源:https://stackoverflow.com/questions/26881735/drafts-create-in-objective-c-using-gtlquerygmail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!