There is an npm module called emailreplyparser which is ported from the ruby ββgithub library that does this. As you note, the formats used for this are not standard and, therefore, any solution will be rather fragile and imperfect, but whaddayagonnado?
Here is an example when I take the JSON response received from the new Gmail API and successfully access only the new response text of this message.
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();
Please note that there may be some interesting fragments if the author alternates the response text and fragments of the quoted message.
Peter Lyons
source share