This commit is contained in:
Expand-sys 2023-02-16 13:58:22 +11:00
parent 4efba37e84
commit aa518c970e
2 changed files with 45 additions and 30 deletions

View file

@ -23,6 +23,18 @@ function sleep(ms) {
}); });
} }
function containsAny(str, substrings) {
for (var i = 0; i != substrings.length; i++) {
var substring = substrings[i];
if (str.indexOf(substring) != - 1) {
return substring;
}
}
return null;
}
async function grabIMAP( async function grabIMAP(
loginSource, loginSource,
loginDest, loginDest,
@ -51,38 +63,41 @@ async function grabIMAP(
return false; return false;
} else { } else {
let arr = source.list() let arr = source.list()
let arr2 = dest.list()
for(let boxes in arr){ for(let boxes in arr){
console.log(boxes) let lock = await source.getMailboxLock(`${boxes}`);
} const folder = Date.now();
let lock = await source.getMailboxLock("INBOX"); let parsed;
const folder = Date.now(); try {
let parsed; const { uid } = await source.fetchOne("*", { uid: true });
try { for (i = 1; i < uid; i++) {
const { uid } = await source.fetchOne("*", { uid: true }); try {
for (i = 1; i < uid; i++) { let { meta, content } = await source.download(i);
try { await content.pipe(
let { meta, content } = await source.download(i); await fs.createWriteStream(path.resolve(__dirname, "./" + id))
await content.pipe( );
await fs.createWriteStream(path.resolve(__dirname, "./" + id)) } catch (e) {
); console.log(e);
} catch (e) { return false;
console.log(e); } finally {
return false; await sleep(100);
} finally { const buf = await Buffer.from(
await sleep(100); await fs.readFileSync(path.resolve(__dirname, "./" + id))
const buf = await Buffer.from( );
await fs.readFileSync(path.resolve(__dirname, "./" + id)) var destbox = arr2.find(a =>a.includes(`${boxes}`));
); await dest.append(`${destbox}`, buf);
await dest.append("INBOX", buf); fs.rmSync(path.resolve(__dirname, "./" + id));
fs.rmSync(path.resolve(__dirname, "./" + id)); }
} }
} catch (e) {
console.log(e);
return false;
} finally {
lock.release();
} }
} catch (e) {
console.log(e);
return false;
} finally {
lock.release();
} }
console.log(arr)
console.log(arr2)
await source.logout(); await source.logout();
await dest.logout(); await dest.logout();
return true; return true;

View file

@ -1,4 +1,4 @@
const URL = "https://a.imapmove.com"; const URL = "http://a.imapmove.com";
const socket = io(URL, { autoConnect: true }); const socket = io(URL, { autoConnect: true });
export default socket; export default socket;