- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Node.js 的 IMAP 模块来解析 IMAP 电子邮件的正文。我可以将正文作为原始 HTML 数据返回给我,但这包括标签和其他不必要的数据。我想要输入的文本(删除任何 div、样式等)
这是我目前使用的代码:
openInbox(function(err, box) {
if (err) throw err;
var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM)','TEXT'] });
f.on('message', function(msg, seqno) {
console.log('Message #%d', seqno);
var prefix = '(#' + seqno + ') ';
msg.on('body', function(stream, info) {
if (info.which === 'TEXT')
console.log(prefix + '\n\nBody [%s] found, %d total bytes\n\n\n', inspect(info.which), info.size);
var buffer = '', count = 0;
stream.on('data', function(chunk) {
count += chunk.length;
buffer += chunk.toString('utf8');
if (info.which === 'TEXT')
console.log(prefix + 'Body [%s] (%d/%d)', inspect(info.which), count, info.size);
});
stream.once('end', function() {
if (info.which !== 'TEXT')
console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
else
console.log(prefix + 'Body [%s] Finished', inspect(info.which));
console.log('\n\n\n\n'+buffer.toString()+'\n\n\n\n\n\n');
});
});
msg.once('attributes', function(attrs) {
console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));
});
msg.once('end', function() {
console.log(prefix + 'Finished');
});
});
f.once('error', function(err) {
console.log('Fetch error: ' + err);
});
f.once('end', function() {
console.log('Done fetching all messages!');
imap.end();
});
});
有没有一种方法可以解析为没有任何标签或其他 HTML 信息的纯文本?
最佳答案
有一个 Node 模块是为此设计的: https://www.npmjs.com/package/html-to-text
var htmlToText = require('html-to-text');
var text = htmlToText.fromString('<h1>Hello World</h1>', {
wordwrap: 130
});
console.log(text);
它还能很好地将表格解析为文本。
关于javascript - 如何从 Node.js IMAP 模块中的正文获取纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31122350/
我有一堆代码执行 IMAP 命令“search, idle, done, search, idle, done, search, ...”。 是否有可能某些消息在搜索和空闲命令之间到达,因此只能在空闲
(使用IMAP命令,而不借助任何其他邮件程序包) 最佳答案 我不确定您对imap的了解程度如何,但是基本上在登录后,“选择”源邮箱,“复制”邮件,然后“删除”邮件(如果是,则“删除”旧邮箱)现在是空的
我正在编写一个 IMAP 爬虫,它是开源应用程序的一部分,对于增量爬网,我想使用消息 UID 来确定我是否已经看到了特定消息。 现在我找到了 a post从 2007 年开始说 IMAP UID 并不
我注意到 libcurl 支持 IMAP,但在文档和示例中没有找到任何内容 http://curl.haxx.se/libcurl/c/imap.html很穷。有谁知道如何在这个库中使用这个协议(pr
IMAP UID 是否保证为数字?我读过 RFC3501 中的部分,它说: Unique identifiers are assigned in a strictly ascending fashio
IMAP UID 是否保证为数字?我读过 RFC3501 中的部分,它说: Unique identifiers are assigned in a strictly ascending fashio
我正在使用开源 IMAP C# 库 IMapX (http://hellowebapps.com/products/imapx/)。当我试图从收件箱中获取电子邮件时,需要花费很多时间。有没有办法根据接
我正在尝试使用 Limilabs imap 库连接到电子邮件; tcpc = new System.Net.Sockets.TcpClient("imap.gmail.com", 993); 工作
我正在尝试使用 imap 方法通过 php 打开电子邮件,但它给我一个错误无法打开流 {imap.gmail.com:993/imap/ssl}INBOX,这是我的代码 $hostname = '{i
有没有办法确定给定电子邮件地址的 POP 或 IMAP 服务器?我正在为非技术用户构建一个应用程序,我真的不想打扰他们询问他们的 IMAP/POP 服务器。 mail2web.com这样做,但我不确定
如何确定通过 APPEND 添加的消息的 UID到邮箱?通过 STATUS我可以事先得到下一个值的预测,我可以 SEARCH之后,但依赖这些会引入竞争条件,因为可能在这些命令之间添加了其他消息。 最佳
这个搜索查询对我来说似乎有效: UID SEARCH OR ( OR ( OR (FROM "def@gmail.com") (FROM "abc@gmail.com")) (FROM "ghi@gm
我正在使用以下代码以编程方式验证电子邮件。 Properties properties = new Properties(); Session emailSession = Session.getDe
我正在使用 OpenSSL 连接到邮件服务器。 POP3 工作正常,但 IMAP 有问题。基于 CAPABILITY 命令服务器支持 PLAIN、NTLM 和 GSS-API 认证方法。 我想使用 P
我正在使用以下代码建立 IMAP 连接。我想阅读电子邮件。我读了这个文件 link无法从这里继续。 我的代码: #lang racket (define imap-server "*****") (d
在尝试使用 php 的 imap 函数时,我无法连接到 Gmail 的 imap 服务器。我正在使用: $mail = imap_open('{imap.gmail.com:993/imap/ssl/
我试图更好地理解 Gmail API . stated benefits 之一Gmail API 的最大特点是它可以“提供比 IMAP 显着的性能改进”。 Gmail API 和协议(protocol
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在制作一个支持 POP3 和 IMAP 的邮件客户端。我正在使用 vmime api 用 C++ 对客户端进行编程。我的问题是:同步邮件的最佳方式是什么? 我认为标识符是个好方法,但我不知道同步邮
我正在制作一个支持 POP3 和 IMAP 的邮件客户端。我正在使用 vmime api 用 C++ 对客户端进行编程。我的问题是:同步邮件的最佳方式是什么? 我认为标识符是个好方法,但我不知道同步邮
我是一名优秀的程序员,十分优秀!