2014-12-05 66 views
0

我检查使用邮件通知邮箱:转换邮件已将附件提交

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

var imap = { 
     username: "[email protected]", 
     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(); 

而且我能够得到的所有文字,但我的主要目标是获取附件。 我想我也得到了attachement,因为我有机会获得这个信息

attachments: 
    [ { contentType: 'application/pdf', 
     fileName: 'hardcorefilename.pdf', 
     contentDisposition: 'attachment', 
     transferEncoding: 'base64', 
     generatedFileName: 'helios-ip-integration-document-fw260.pdf', 
     contentId: '[email protected]', 
     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文档?

回答

1

发现它!

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

如果这是你的问题的答案,接受它 – user902383 2014-12-05 12:54:25

+0

我不能。 “您可以在2天内接受您自己的答案” – 2014-12-05 12:58:47

+0

您可以...但不是现在 – user902383 2014-12-05 12:59:52