yopmail-helper
Version:
yopmail helper. It will help you receive the mail content.
57 lines (49 loc) • 1.83 kB
JavaScript
const {getYp} = require('../permission/yp');
const {getYj} = require('../permission/yj');
const {getVersion} = require('../permission/version');
const axios = require('axios');
const {createGetMailCookies} = require('../permission/cookies');
const {getInboxUrl} = require('../baseUrl');
const {parse} = require('node-html-parser');
async function getInboxHtml(mailAddress) {
const yp = await getYp();
const yj = await getYj();
const ver = await getVersion();
const response = await axios({
headers: {
'Cookie': await createGetMailCookies(),
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
},
method: 'get',
url: getInboxUrl(mailAddress, yp, yj, ver),
});
return response.data;
}
async function getInbox(mailAddress) {
mailAddress = (mailAddress.split('@')[0] || '').toLowerCase() || mailAddress;
const htmlPage = await getInboxHtml(mailAddress);
if (htmlPage.includes('captcha') || htmlPage.includes('g-recaptcha') || htmlPage.includes('cf-challenge')) {
console.warn('YOPmail is showing a CAPTCHA or Cloudflare challenge. Scraping might be blocked.');
}
const data = parse(htmlPage);
const mails = data.querySelectorAll('.m');
const mailsInfo = [];
mails?.forEach(
(mail) => {
const id = mail.getAttribute('id');
const title = mail.querySelector('.lmf')?.textContent;
const summary = mail.querySelector('.lms')?.textContent;
const time = mail.querySelector('.lmh')?.textContent;
const mailInfo = {};
mailInfo.id = id;
mailInfo.title = title;
mailInfo.summary = summary;
mailInfo.time = time;
mailsInfo.push(mailInfo);
},
);
return mailsInfo;
}
module.exports = {
getInbox,
};