Skip to content

Instantly share code, notes, and snippets.

@luxigo
Created November 12, 2021 12:08
Show Gist options
  • Save luxigo/7a9a1a785637a50b3ef2c06be6d87d26 to your computer and use it in GitHub Desktop.
Save luxigo/7a9a1a785637a50b3ef2c06be6d87d26 to your computer and use it in GitHub Desktop.
Copy missing mails after migration using IMAP
var imaps=require('imap-simple');
var src,dst;
imaps.connect({
imap: {
user: '***********',
password: '********',
host: '***********',
port: 993,
tls: true,
debug: function(msg) {
console.log(msg)
}
}
})
.then(function(con){
src=con;
return src.openBox('INBOX');
})
.then(function(){
return imaps.connect({
imap: {
user: '****************',
password: '********',
host: '***********',
port: 993,
tls: true,
debug: function(msg) {
console.log(msg)
}
}
})
})
.then(function(con){
dst=con;
return dst.openBox('INBOX');
})
.then(function(){
return src.search(['ALL', ['SINCE', 'July 27 2021'], ['BEFORE', 'October 10, 2021']],{
headers: { parse: false },
bodies: ''
})
})
.then(function(results){
function loop(){
if (!results.length) {
console.log('All done!');
return;
}
var result=results.shift()
var flags=[];
if (result && result.attributes && result.attributes.flags) {
console.log(result.attributes.flags);
result.attributes.flags.filter(function(flag){
return flag!='//Forwarded';
});
}
dst.append(result.parts[0].body,{
flags: flags,
date: result.attributes.date
})
.then(function(){
loop();
})
.catch(function(err){
throw err;
});
}
loop();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment