Skip to content

Commit

Permalink
fix triamail
Browse files Browse the repository at this point in the history
  • Loading branch information
hajonsoft committed Mar 5, 2024
1 parent ec78c01 commit bb43a2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hajonsoft-eagle",
"version": "2.6.22",
"version": "2.6.23",
"description": "HAJonSoft node app to submit passengers to visa systems",
"main": "index.js",
"scripts": {
Expand Down
9 changes: 8 additions & 1 deletion src/lib/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ const nshFromEmail = "[email protected]";
const nskFromEmail = "[email protected]";
const messages = {};

function getHostName(recipient) {
if (recipient.includes("@triamail.com")) {
return "mail.privateemail.com";
}
return `mail.${recipient.split("@")[1]}`;
}

async function fetchNusukIMAPOTP(recipient, password, subject, callback, isNotVirtualEmail) {
var imap = new Imap({
user: isNotVirtualEmail ? recipient : `admin@${recipient.split("@")[1]}`,
password: password,
host: `mail.${recipient.split("@")[1]}`,
host: getHostName(recipient),
port: 993,
tls: true,
tlsOptions: { rejectUnauthorized: false },
Expand Down
31 changes: 19 additions & 12 deletions src/nsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ const URLS = {
SIGNOUT: "https://hajj.nusuk.sa/Account/Signout",
};

function getOTPEmailAddress(email) {
if (email.includes(".gmail") || email.includes(".yahoo") || email.includes(".outlook")) {
const domain = data.system.username.includes("@")
? data.system.username.split("@")[1]
: data.system.username;
return `admin@${domain}`
}
return email;
}

function getLogFile() {
const logFolder = path.join(getPath("log"), data.info.munazim);
if (!fs.existsSync(logFolder)) {
Expand Down Expand Up @@ -800,6 +810,12 @@ async function loginOrRegister(selectedTraveler) {

async function getOTPCode() {
const passenger = data.travellers[util.getSelectedTraveler()];
await page.$eval(
"#otpForm > label",
(el, email) =>
(el.innerText = `${email.split('/')[0]}`),
passenger.email || emailAddress
);
if (!canGetCode(passenger.email || emailAddress, data.system.username)) {
await util.infoMessage(page, "Manual code required or try again!");
return;
Expand All @@ -821,7 +837,7 @@ async function getOTPCode() {
try {
if (pageMode.includes("Registration") || pageMode.includes("التسجيل")) {
await fetchNusukIMAPOTP(
getOTPEmailAddress((passenger.email || emailAddress).split('/')[0])
getOTPEmailAddress((passenger.email || emailAddress).split('/')[0]),
(passenger.email || emailAddress).includes('/') ? (passenger.email || emailAddress).split('/')[1] : data.system.adminEmailPassword,
["Email Activation", "تفعيل البريد الالكتروني"],
pasteOTPCode,
Expand All @@ -832,7 +848,7 @@ async function getOTPCode() {
pageMode.includes("التثبت من رمز التحقق")
) {
await fetchNusukIMAPOTP(
getOTPEmailAddress((passenger.email || emailAddress).split('/')[0])
getOTPEmailAddress((passenger.email || emailAddress).split('/')[0]),
(passenger.email || emailAddress).includes('/') ? (passenger.email || emailAddress).split('/')[1] : data.system.adminEmailPassword,
["One Time Password", "رمز سري لمرة واحدة"],
pasteOTPCode,
Expand Down Expand Up @@ -994,6 +1010,7 @@ async function loginPassenger(selectedTraveler) {
const rawData = fs.readFileSync(getPath("data.json"), "utf-8");
var data = JSON.parse(rawData);
const passenger = data.travellers[selectedTraveler];
await page.waitForTimeout(1000);
await util.commit(
page,
[
Expand Down Expand Up @@ -1587,14 +1604,4 @@ async function runParallel() {
await page.browser().close();
}

function getOTPEmailAddress(email) {
if (email.includes(".gmail") || email.includes(".yahoo") || email.includes(".outlook")) {
const domain = data.system.username.includes("@")
? data.system.username.split("@")[1]
: data.system.username;
return `admin@${domain}`
}
return email;
}

module.exports = { send };

0 comments on commit bb43a2e

Please sign in to comment.