0

I would like to implement the following use case as a Chrome extension:

  • user visits gmail
  • exension checks current email body for a keyword
  • if a keyword is present, a gmail filter is added and saved (adding label, archiving, the details are not important here)

The first part sounds easier: there is gmail API to work with and even a gmail.js project that should make it easier.

Adding filter seems to be much harder. There is email settings API doing precisely what I want but I am fairly sure it is usable only by business accounts (custom email domains, won't work for gmail.com). I want the solution to be more universal.

One thing I thought of was to use browser automation - upon seeing the trigger keyword, the script automatically clicks 'Add filter' link, waits for AJAX, sets filter parameters and confirms.

An example of simulated user activity is in this answer

This could happen either on gmail page behind the popup ('Please wait, adjusting filters') or in background tab to keep it from interfering with user's flow. This seems like ugly workaround for me, though.

Is there a more straightforward or simply better approach that I'm missing?

4

1 回答 1

1

经过更多的实验和恢复一个较旧的 github 项目后,我发现为登录用户设置过滤器可以简单地通过从当前会话向 gmail 发出特定的 POST 消息来实现。

我不完全理解此请求中使用的参数(如果有人有更好的信息,请分享),但我找到了一个非常有帮助的示例代码。

gmail.js 社区中广泛讨论的第二个问题是,Gmail 安全策略将阻止您注入自己的脚本。这被这个样板项目中显示的方法绕过

我编译了这些解决方案来解决我的特定用例。这是我的解决方案的示例项目,它应该可以开箱即用 - 如果有疑问,请参阅自述文件。

于 2015-04-20T21:00:45.103 回答