node.js - 从电子邮件回复中删除原始消息

标签 node.js email

我的应用程序接收来自用户的电子邮件。例如,来自 gmail 的响应是这样的:

This is some new text

On Sun, Apr 1, 2012 at 3:32 AM, My app <
4f77ed3860c258a567aeabf8@myapp.com> wrote:

> Original...
> message..

当然,这种处理因客户而异。

现在我正在识别“4f77ed3860c258a567aeabf8”并丢弃之后的所有内容,因为我知道他们发送到哪个电子邮件地址。这不是通用解决方案,但适用于我的目的,除了在“原始消息”行中出现换行符时,如上例所示。

是否有更好的标准方法从用户对电子邮件的回复中删除过去的消息?

最佳答案

有一个名为 emailreplyparser 的 npm 模块,它是从执行此操作的 github ruby​​ 库移植的。正如您所指出的,用于此的格式不是标准的,因此任何解决方案都将非常脆弱和不完美,但是whaddayagonnado

这是一个示例,我从新的 Gmail API 获取 JSON 响应并成功访问给定消息的新回复文本。

var erp = require('emailreplyparser').EmailReplyParser.read;
var message = require('./sample_message.json');
var buffer = new Buffer(message.payload.parts[0].body.data, 'base64');
var body = buffer.toString();
//body is the whole message, the new text and the quoted reply portion
// console.log(body);
var parsed = erp(body);
//this has just the text of the reply itself
console.log(parsed.fragments[0].content);

请注意,如果作者将回复文本和引用的消息片段交织在一起,可能会出现几个有趣的片段。

关于node.js - 从电子邮件回复中删除原始消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9966904/

相关文章:

php - Laravel 5.4 Markdown 邮件字符问题

C# MailKit HTML 电子邮件以纯文本形式接收

java - 无法发送富文本电子邮件 - Thymeleaf + Spring 4

php - 通过电子邮件请求系统

javascript - 使用 Node 6.3 设置 Koa 2

c# - 如何使nodejs代码在asp.net core(带有JavascriptService)应用程序中调用csharp代码?

node.js - JSDoc3 和 NodeJS 链接到模块中的类型

php - 邮件传递失败 : returning message to sender

javascript - Node Grunt.js 'Warning: connect is not defined Use '

node.js - Passport-jwt token 过期