const axios = require("axios")
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
const EmailType = "Domain"
const getEmail = async () => {
try {
const response = await axios.post('https://22.do/zh/mailbox/generate', `type=${EmailType}`, { headers })
if (response.status === 200 && response.data.data) {
const email = response.data.data.address.email
console.log("获取邮箱成功:", email)
return email
} else {
console.log("获取邮箱失败,请检查Cookie!")
return false
}
} catch (e) {
console.log("获取邮箱失败,程序性出错!", String(e).slice(0, 100))
return false
}
}
const refreshEmail = async (email) => {
try {
const response = await axios.post('https://22.do/zh/mailbox/check', null,
{
headers: {
"cookie": `mail=${email}`
}
}
)
if (response.status === 200 && response.data) {
if (response.data.action && response.data.action == 'OK') {
return response.data.Msg[0]
} else {
return false
}
} else {
console.log("刷新邮件失败,请检查Cookie!")
return false
}
} catch (e) {
console.log("刷新邮件失败,程序性出错!")
return false
}
}
const mailAnalyze = async (email) => {
try {
let mailRefreshStatus = false
let refreshNum = 0
while (!mailRefreshStatus) {
if (refreshNum > 24) {
console.log("获取验证码失败,请检查Cookie!")
return false
}
refreshNum++
console.log(`第${refreshNum}次刷新邮件`)
const mailRefreshStatusTemp = await refreshEmail(email)
if (mailRefreshStatusTemp) {
mailRefreshStatus = true
return await getMail(mailRefreshStatusTemp.mailId)
}
sleep(5000)
}
return false
} catch (e) {
console.log("获取验证码失败,程序性出错!")
return false
}
}
const getMail = async (mailID) => {
try {
const response = await axios.get(`https://22.do/zh/content/${mailID}/html`)
const content = response.data
if (response.status === 200 && content) {
return content
} else {
console.log("请检查Cookie!")
return false
}
} catch (e) {
console.log("程序性出错!")
return false
}
}
const Analyze = (mail, regex = /.*/, type = false) => {
const mailStr = String(mail)
const match = mailStr.match(regex)
if (match) {
if (type) {
return match
} else {
return match[0]
}
}
return false
}
const getContent = async (email, regex = /.*/, type = false) => {
console.log(`444444444444444444`);
const mail = await mailAnalyze(email)
if (mail) {
return await Analyze(mail, regex, type)
} else {
return false
}
}
const sleep = (ms) => {
const start = Date.now()
while (Date.now() - start < ms) {
}
}
module.exports = {
getEmail,
getContent
}
const main = async () => {
const email = "rossanad.aoudky.l.42@gmail.com";
console.log(`使用邮箱: ${email}`);
const regex = "/.*/";
const type = false;
const content = await getContent(email, regex, type);
console.log(`123123123123123123123123123123`);
if (content) {
console.log(`提取的邮件内容: ${content}`);
} else {
console.log('未能提取到符合条件的内容');
}
};
main();