New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

imap-checker

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imap-checker - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6-1

LICENSE

77

index.js

@@ -1,41 +0,64 @@

const mailNotifier = require('mail-notifier');
import imaps from 'imap-simple';
import { simpleParser } from 'mailparser';
import _ from 'lodash';
const imapChecker = (imapConfig, {timeout, from, to, subject}) => {
return new Promise((resolve, reject) => {
const notifier = mailNotifier(imapConfig);
let timeoutFunc;
const sleep = ms => new Promise((resolve) => setTimeout(resolve, ms));
notifier
.on('mail', (mail) => {
const parse = (source, options) => {
return new Promise(resolve => {
simpleParser(source, options, (err, parsed) => resolve(parsed));
});
}
const imapChecker = async (imapConfig, {timeout, from, to, subject}) => {
const config = {
imap: imapConfig
};
const connection = await imaps.connect(config);
await connection.openBox('INBOX');
const searchCriteria = ['UNSEEN'];
const fetchOptions = { bodies: ['HEADER', 'TEXT', ''] };
const startTime = Date.now();
while (true) {
const messages = await connection.search(searchCriteria, fetchOptions);
for (let index = 0; index < messages.length; index++) {
const message = messages[index];
const all = _.find(message.parts, { "which": "" })
const id = message.attributes.uid;
const idHeader = "Imap-Id: " + id + "\r\n";
const mail = await parse(idHeader + all.body);
let matched = true;
if (from && !mail.from.some((element) => element.address === from)) {
if (from && from != mail.from.text) {
matched = false;
}
if (to && !mail.to.some((element) => element.address === to)) {
if (to && to != mail.to.text) {
matched = false;
}
if (subject && !mail.subject.match(new RegExp(subject))) {
if (subject && subject != mail.subject) {
matched = false;
}
if (matched) {
clearTimeout(timeoutFunc);
notifier.stop();
resolve(mail);
return mail;
}
})
.on('connected', () => {
timeoutFunc = setTimeout(() => {
notifier.stop();
console.log(`Timeout when checking for email from: '${from}' to: '${to}' with subject: '${subject}'`);
resolve(null);
}, timeout);
})
.on('error', (err) => {
console.log(`Error when checking for email: ${err.message} \n\n ${err.stack}`);
reject(err);
})
.start();
});
}
const now = Date.now();
if (now - startTime > timeout) {
throw new Error(`TimeoutError: couln't find emails in ${timeout}ms.`);
}
await sleep(1000);
}
};
exports.checkMail = imapChecker;
{
"name": "imap-checker",
"version": "0.0.5",
"version": "0.0.6-1",
"description": "Check the email server and return the matching emails",

@@ -16,4 +16,6 @@ "main": "index.js",

"dependencies": {
"mail-notifier": "^0.5.0"
"imap-simple": "^5.0.0",
"lodash": "^4.17.21",
"mailparser": "^3.2.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc