2019-07-03 16:37:26 +08:00
|
|
|
/* eslint no-console:0 */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2020-05-16 00:02:24 +08:00
|
|
|
const rawpath = process.argv[2];
|
2019-07-03 16:37:26 +08:00
|
|
|
const config = require('wild-config');
|
2020-05-16 00:02:24 +08:00
|
|
|
const { ImapFlow } = require('imapflow');
|
2019-07-03 16:37:26 +08:00
|
|
|
|
|
|
|
const raw = require('fs').readFileSync(rawpath);
|
|
|
|
console.log('Processing %s of %s bytes', rawpath, raw.length);
|
|
|
|
|
2020-05-16 00:02:24 +08:00
|
|
|
const client = new ImapFlow({
|
|
|
|
host: '127.0.0.1',
|
|
|
|
port: config.imap.port,
|
|
|
|
secure: config.imap.secure,
|
2019-07-03 16:37:26 +08:00
|
|
|
auth: {
|
|
|
|
user: 'myuser',
|
|
|
|
pass: 'verysecret'
|
|
|
|
},
|
|
|
|
tls: {
|
|
|
|
rejectUnauthorized: false
|
2020-05-16 00:02:24 +08:00
|
|
|
},
|
|
|
|
clientInfo: {
|
|
|
|
name: 'My Client',
|
|
|
|
version: '0.1'
|
2019-07-03 16:37:26 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-16 00:02:24 +08:00
|
|
|
client.on('error', err => {
|
2019-07-03 16:37:26 +08:00
|
|
|
console.log(err);
|
|
|
|
process.exit(1);
|
2020-05-16 00:02:24 +08:00
|
|
|
});
|
2019-07-03 16:37:26 +08:00
|
|
|
|
2020-05-16 00:02:24 +08:00
|
|
|
client
|
|
|
|
.connect()
|
|
|
|
.then(() => client.append('INBOX', raw))
|
|
|
|
.then(() => client.mailboxOpen('INBOX'))
|
|
|
|
.then(mailbox => client.fetchOne(mailbox.exists, { bodyStructure: true, source: true }))
|
|
|
|
.then(data => {
|
|
|
|
console.log(data);
|
|
|
|
console.log('<<<%s>>>', data.source.toString());
|
|
|
|
return process.exit(0);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
process.exit(1);
|
2019-07-03 16:37:26 +08:00
|
|
|
});
|