Gmail API In-Reply-To 不工作(Google 不在一侧处理)

Gmail API In-Reply-To not working(Google not handling on one side)

问题: 当通过 api 发送回复电子邮件时,然后在接收方显示为包含两封电子邮件的线程(good在接收方) 但发件人有两封不同的电子邮件,一封在收件箱中,一封在已发送邮件中(发件人方面的问题)。

例如:

电子邮件从 A 发送到 B。 B 再次发送给 A.

这里 api 我在 "In-Reply-To" 和 "References" 中给出之前的电子邮件消息 ID,(根据 rfc822 格式)这里 Google 正在处理该消息-id 在 A 侧但不在 B 侧。 A 在单个线程中收到的消息是两封邮件,但在 B 的帐户中,它显示为两封单独的电子邮件,一封在收件箱中,一封在已发送邮件中。

Api 使用:

https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=multipart 内容类型:"message/rfc822; boundary=foo_bar_baz"

请求正文为 rfc2822 格式

要使其在发件人端线程化,您还需要将 Message.threadId 字段指定为 send() 调用的一部分。 (不幸的是,这目前不会自动发生。)

今天在我的生产应用程序中也注意到了这一点。 change log did not give a clue as to what happened, but I found the problem in the new documentation for managing threads:

  1. The requested threadId must be specified on the Message or Draft.Message you supply with your request.
  2. The References and In-Reply-To headers must be set in compliance with the RFC 2822 standard.
  3. The Subject headers must match.

换句话说,需要提供threadId。我不知道这是不是一个错误,因为它没有记录在同一天更新的 sending message-文档中。

我想回复收件箱中的最新消息。让我们获取相关信息:

请求 1:

maxResults = 1
fields = messages/id

GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1&fields=messages%2Fid

响应 1:

{
 "messages": [
  {
   "id": "15071b210a1ac883",
   "threadId": "15071a4886871a10"
  }
 ]
}

请求 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

响应:

{
 "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"
   }
  ]
 }
}

剩下的就是创建一条消息,将所有这些数据放在正确的位置:

请求 3:

POST https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=multipart
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: emtholin@gmail.com
To: emtholin@gmail.com
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+/ZzeiYzk5lkHkkIM3nikIeTEARqNYRSKRXcxQGxLAqipiJBUlIqurvlupavKikpdpFQiFVLJOADUc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