-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.js
32 lines (28 loc) · 997 Bytes
/
parse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
const util = require('util');
const fs = require('fs');
const simpleParser = require('mailparser').simpleParser;
var mailattach = []
// regex to get email address from string
// Because mail.email returns email: 'Hello world! <[email protected]>'
var regExp = /([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/;
module.exports = function mailparser(data){
return new Promise(function(resolve, reject){
simpleParser(data)
.then(mail => {
console.log(mail.from.text)
for (var attach in mail.attachments){
mailattach.push({
attachment : mail.attachments[attach],
date : mail.date,
email : regExp.exec(mail.from.text)[1]
});
}
resolve(mailattach);
})
.catch(err => {
console.log("parse error :",err);
reject(err);
});
})
}