【问题标题】:Get only a particular message in Gmail API仅在 Gmail API 中获取特定邮件
【发布时间】:2016-04-17 12:56:53
【问题描述】:

所以我想做的是通过 Gmail API 从我的 Gmail 帐户获取邮件,但是收到的邮件会附加到它所回复的邮件。

发生了什么:(示例消息)

完成。

请告诉我你的想法。

问候 ABC

2016 年 1 月 8 日星期五,John Doe 写道: 我以为这是早些时候完成的? 2016 年 1 月 8 日下午 5:01,ABC 写道:

请让我们知道我可以和谁谈谈完成这项工作。

问候,

ABC

我想要什么:

完成。

请告诉我你的想法。

问候, ABC

【问题讨论】:

  • 恐怕这就是 Gmail 的工作方式。原始消息实际上是实际响应的一部分,因此您必须自己将其删除。有ways to remove it,但要让它适用于所有类型的消息是很棘手的。
  • @Tholle 你能推荐一些更多的策略吗?
  • @devpro 恐怕没有可显示的代码,因为我仍在从 GMAIL API 参考中探索此功能。
  • @RahulDhawani 抱歉,我从来没有自己做过,所以我不知道 :(
  • 取决于您尝试构建的应用程序 - 您可以在对话模式下通过 Gmail UI 访问它。您可以使用 InboxSDK 之类的东西来访问正文或抓取 DOM。如果您不打算为您的应用使用 Chrome 扩展程序,那么这将是不合适的。

标签: api gmail gmail-api


【解决方案1】:

我只能通过使用 org.jsoup.Jsoup 操作修改收到的 HTML 消息来摆脱 Java 中的那些。这是从现有代码中截取的,所以希望我没有忘记一些东西:

final Document doc = Jsoup.parse(gmail_message);

// Remove first gmail_quote div if exists, to clean up long threads.
if (null != doc.select("div.gmail_quote").first())
{
   doc.select("div.gmail_quote").first().remove();
}

// Remove any inline images from message as they are included as attachments
while (null != (doc.select("img[src^=cid:]").first())
{
   doc.select("img[src^=cid:]").first().remove();
}

// We remove any scripts in message
while (null != doc.select("script").first())
{
   doc.select("script").first().remove();
}

// We remove any iframes
while (null != doc.select("iframe").first())
{
   doc.select("iframe").first().remove();
}

message_text.setValue(doc.toString());

我已经有一段时间没有看到任何内联邮件了,除了来自非 Gmail 用户的邮件,这种情况很少见。我也摆脱了那些讨厌的内联图像。如您所见,我在这里做了一些香蕉,并删除了脚本和 iframe。嗯。 ;)

我希望这在某种程度上有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-08
    • 2015-08-25
    • 1970-01-01
    • 2018-03-26
    • 2023-04-10
    • 2014-08-26
    • 2023-02-04
    • 2014-08-22
    相关资源
    最近更新 更多