Hussain Chhatriwala
Hussain Chhatriwala

Reputation: 849

How can I show complete mail details using gmail Api iOS

I want to display the complete mail details like normal mailbox.

As per my understanding there might be a link which can be loaded on web view. So from where will I find the link.

And text can be fetched from decoding body.

But I am unable to understand from where can i fetch the proper details.

I am able to access the mail body using following code.

for(GTLGmailMessagePart* part in payload.parts)
{
    GTLGmailMessagePartBody* body = part.body;
   // NSLog(@"body =%@",body);
    NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:body.data options:0];
    NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
    NSLog(@"decodedString ----   %@--- for index %ld", decodedString,(long)indexPath.row); // foo         NSLog(@"%@", base64String); // Zm9v
}

But for some mail this detail comes empty but there might be some link which i can load on web view.

Can any one help me to how can I fetch and show proper details on the view.

Thanks in Advance.

Upvotes: 0

Views: 216

Answers (1)

denny
denny

Reputation: 199

Lack of documents and samples, it's an issue for GTLGmail API. Here is my working code.

//... get part
let body : GTLGmailMessagePartBody = part.body
let bodyAttachmentId = body.attachmentId
let bodyData : String! = body.data
let bodySize = body.size

//Use GTLDecodeWebSafeBase64
if bodyData != nil
{
    let decodedData = GTLDecodeWebSafeBase64(bodyData)
    let decodedString = NSString(data: decodedData!, encoding: NSUTF8StringEncoding)

    print("after decoded: \(decodedString)")
}

Upvotes: 1

Related Questions