gpt4 book ai didi

node.js - 将邮件附件转换为文件

转载 作者:太空宇宙 更新时间:2023-11-03 23:38:59 24 4
gpt4 key购买 nike

我正在使用邮件通知程序检查邮箱:

var notifier = require('mail-notifier');

var imap = {
username: "hardcoreuser@stuff.whatever",
password: "hardcorepassword",
host: "hardcorehost",
port: 143, // imap port
tls: false,
tlsOptions: { rejectUnauthorized: false }
};

notifier(imap).on('mail',function(mail){
console.log("GOT MAIL");
console.log(mail);

}).start();

我能够获取所有文本,但我的主要目标是获取附件。我想我也收到了附件,因为我可以访问此信息

attachments:
[ { contentType: 'application/pdf',
fileName: 'hardcorefilename.pdf',
contentDisposition: 'attachment',
transferEncoding: 'base64',
generatedFileName: 'helios-ip-integration-document-fw260.pdf',
contentId: 'ba0391e4323aa65cb1204e41aa36a82d@mailparser',
checksum: '2ad15bae0d1c33bcdf2f35d4839061db',
length: 789634,
content: <Buffer 25 50 44 46 2d 31 2e 35 0d 0a 25 b5 b5 b5 b5 0d 0a 31 20
30 20 6f 62 6a 0d 0a 3c 3c 2f 54 79 70 65 2f 43 61 74 61 6c 6f 67 2f 50 61 67 6
5 73 20 32 20 30 ...> } ] }

我试图找到一个可以做到这一点的模块,但没有成功。如何将编码内容转换为 pdf 文档?

最佳答案

找到了!

require("fs").writeFile("out.pdf", mail.attachments[0].content, 'base64', function(err) {
console.log(err);
});

关于node.js - 将邮件附件转换为文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27315711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com