Search code examples
iosobjective-cgmailgmail-api

How can I detect read unread mails using gmail api?


I am working on a mailbox app and I am getting following response as an object of "GTLGmailMessage" for a gmail message as following :- I had gone through the api documentation but I was unable to find any solution.

Is there any way to detect the mail is read or unread.

{
historyId = 80237;
id = 152589a56bea2515;
internalDate = 1453185455000;
labelIds =     (
    INBOX,
    IMPORTANT,
    "CATEGORY_UPDATES"
);
payload =     {
    body =         {
        data = DQp———— — dG9bmtzIQ0K;
        size = 732;
    };
    filename = "";
    headers =         (
                    {
            name = "Delivered-To";
            value = "[email protected]";
        },
                    {
            name = Received;
            value = "by 10.37.100.68 with SMTP id y65csp2443890ybb;        Mon, 18 Jan 2016 22:37:35 -0800 (PST)";
        },
                    {
            name = "X-Received";
            value = "by 10.13.239.129 with SMTP id y123mr16831747ywe.167.1453185455680;        Mon, 18 Jan 2016 22:37:35 -0800 (PST)";
        },
                    {
            name = "Return-Path";
            value = "<[email protected]>";
        },
                    {
            name = Received;
            value = "from github-smtp2b-ext-cp1-prd.iad.github.net (github-smtp2-ext3.iad.github.net. [192.30.252.194])        by mx.google.com with ESMTPS id q63si16585388ywb.331.2016.01.18.22.37.35        for <[email protected]>        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);        Mon, 18 Jan 2016 22:37:35 -0800 (PST)";
        },
                    {
            name = "Received-SPF";
            value = "pass (google.com: domain of [email protected] designates 192.30.252.194 as permitted sender) client-ip=192.30.252.194;";
        },
                    {
            name = "Authentication-Results";
            value = "mx.google.com;       spf=pass (google.com: domain of [email protected] designates 192.30.252.194 as permitted sender) [email protected];       dkim=pass (test mode) [email protected];       dmarc=pass (p=NONE dis=NONE) header.from=github.com";
        },
                    {
            name = Date;
            value = "Mon, 18 Jan 2016 22:37:35 -0800";
        },
                    {
            name = "DKIM-Signature";
            value = "v=1; a=rsa-sha256; c=relaxed/relaxed; d=github.com; s=pf2014; t=1453185455; bh=PQFrfD7nxfJCQgsdom7s6/TMtuIlEPwr4GKz/BVEYNE=; h=From:To:Subject:From; b=PbKfqrQfPtJzh2YsK2RqLPahAYL8Wk40aW1GnqZqNCZp0dehGTRCByYDg4HT93m89\t NK+BbCDbcSgkiII6NnBildbsorKfenoVE2jTS21fllusq1Oflmyayo1GyRvGOkFEd1\t WCgQlsicXhXniFDza60ibwwcABXyB/yVCcnrrpGk=";
        },
                    {
            name = From;
            value = "GitHub <[email protected]>";
        },
                    {
            name = To;
            value = "[email protected]";
        },
                    {
            name = "Message-ID";
            value = "<569dd9af5be8b_5b613f8adf71f29c19092@github-lowworker7-cp1-prd.iad.github.net.mail>";
        },
                    {
            name = Subject;
            value = "[GitHub] Subscribed to SendOTP/iOS notifications";
        },
                    {
            name = "Mime-Version";
            value = "1.0";
        },
                    {
            name = "Content-Type";
            value = "text/plain; charset=UTF-8";
        },
                    {
            name = "Content-Transfer-Encoding";
            value = "quoted-printable";
        },
                    {
            name = "X-Auto-Response-Suppress";
            value = All;
        }
    );
    mimeType = "text/plain";
    partId = "";
};
sizeEstimate = 2601;
snippet = "Hey there, we&#39;re just writing to let you know that you&#39;ve been automatically subscribed to a";
threadId = 152589a56bea2515;

}

How can I detect weather mail is read or unread.

Thanks in Advance.


Solution

  • You can check for the UNREAD-label in the labelIds-array in the response.

    Request

    GET https://www.googleapis.com/gmail/v1/users/me/messages/152d4596db9906f8
    

    Response

    {
     "id": "152d4596db9906f8",
     "threadId": "152d4596db9906f8",
     "labelIds": [
      "SENT",
      "INBOX",
      "IMPORTANT",
      "UNREAD"
     ],
     "snippet": "Cool message, buddy.", ...
    }