gmail-safe
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -10,2 +10,3 @@ #!/usr/local/bin/node | ||
EE = require('events').EventEmitter, | ||
async = require('async'), | ||
fs = require('node-fs'); | ||
@@ -26,3 +27,4 @@ | ||
required: true, | ||
type: "string" | ||
type: "string", | ||
metavar: "USERNAME" | ||
}) | ||
@@ -34,4 +36,10 @@ .option('password',{ | ||
required: true, | ||
type: "string" | ||
type: "string", | ||
metavar: "PASSWORD" | ||
}) | ||
.option('incremental', { | ||
flag: true, | ||
abbr: 'i', | ||
help: "Only download emails which have not already been downloaded." | ||
}) | ||
.parse(); | ||
@@ -42,6 +50,6 @@ | ||
// Script-level 'globals'. I don't like these, but they seem idiomatic. | ||
var db = null; | ||
var redis = null; | ||
var work_path = null; | ||
var gm = null; | ||
var db; | ||
var redis; | ||
var work_path; | ||
var gm; | ||
@@ -58,4 +66,9 @@ | ||
// Create a helper to get to die on errors for callbacks. | ||
var die = function(err) { | ||
if(err) { | ||
mainloop.emit('exit',err); | ||
} | ||
} | ||
// For some reason, possibly an error, close it all down. | ||
@@ -70,3 +83,3 @@ // It is safe to call process.exit() here, although note | ||
// This handler MUST block, and MUST NOT return. IE, it cannot | ||
// be asynchronous. (For one, there might well not be a next tick.) | ||
// be asynchronous. (Obviously, as there won't be a next tick.) | ||
mainloop.once('exit',function(err) { | ||
@@ -90,10 +103,2 @@ // Cleanup | ||
// Create a helper to get to die on errors for callbacks. | ||
var die = function(err) { | ||
if(err) { | ||
mainloop.emit('exit',err); | ||
} | ||
} | ||
// Main entrant | ||
@@ -115,5 +120,22 @@ mainloop.once('main',function() { | ||
mainloop.on('imap_connect', function() { | ||
var fetcher = gm.get(); // Fetch ALL the mails! (apologies to Ms. Allie) | ||
db.get('latest_email_date',function(err,result) { | ||
mainloop.emit('fetch',result); | ||
}); | ||
}); | ||
// fetch - after finding the previously stored email date (or none), fetch. | ||
mainloop.on('fetch',function(previous_email_date) { | ||
var fetcher; | ||
var bar; | ||
if (opts.incremental && previous_email_date) { | ||
// Fetch only the emails since the date stored in redis | ||
console.log("Only fetching emails after", previous_email_date); | ||
console.log("(Note: due to a small and hard-to-trace bug probably stemming from the curiously hard to define properties of server time, some of these emails might be already downloaded. This shouldn't be an issue.)") | ||
fetcher = gm.get({'since':previous_email_date}); | ||
} else { | ||
console.log("Fetching ALL emails (this may take some time)"); | ||
fetcher = gm.get(); // Fetch ALL the mails! (apologies to Ms. Allie) | ||
} | ||
fetcher.once('end',function(){ | ||
@@ -123,9 +145,13 @@ console.log(); | ||
}); | ||
fetcher.on('fetching',function(ids) { | ||
console.log("Fetching",ids.length,"emails (this may take some time)..."); | ||
console.log(); | ||
bar = new ProgressBar('[:bar] :percent (:elapsed/:finish) :eta', { | ||
total: ids.length, | ||
width: 40, | ||
}); | ||
fetcher.on('fetching',function(ids,cancel) { | ||
if (ids.length > 0) { | ||
console.log("Fetching ",ids.length,"emails."); | ||
bar = new ProgressBar('[:bar] :percent (:elapsed/:finish) :eta', { | ||
total: ids.length, | ||
width: 40, | ||
}); | ||
} else { | ||
console.log("Nothing to fetch."); | ||
cancel(); | ||
} | ||
}); | ||
@@ -144,2 +170,8 @@ fetcher.on('fetched',function(msg){ | ||
}; | ||
// For now, we just store each sequential email as the most recent date | ||
// without checking to see if it's actually a more recent date. This is | ||
// ok because at the moment, the consequence of getting this wrong is | ||
// very small - we'd likely only be wrong by one or two emails at most | ||
// and the consequence is just downloading two extra emails in that case | ||
db.set('latest_email_date',storeobj.date, die); | ||
@@ -155,6 +187,17 @@ // I would like to use db.HMSET, but it is being very weird. | ||
mainloop.on('close',function() { | ||
db.quit(); | ||
gm.logout(die); | ||
mainloop.emit('exit'); | ||
}) | ||
async.parallel([ | ||
function(done) { | ||
db.quit(function(err,res) { | ||
done(err); | ||
}); | ||
}, | ||
function(done) { | ||
gm.logout(function(err) { | ||
done(err); | ||
}) | ||
} | ||
],function(err) { | ||
mainloop.emit('exit',err); | ||
}); | ||
}); | ||
@@ -224,2 +267,3 @@ | ||
db = redis_client.createClient(36127,"127.0.0.1"); | ||
db.on("error",die); | ||
@@ -226,0 +270,0 @@ // Create a blank gmail object |
{ | ||
"name": "gmail-safe", | ||
"preferGlobal": "true", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"author": "Erich Blume <blume.erich@gmail.com>", | ||
@@ -24,2 +24,3 @@ "description": "Intelligent backup client for GMail.", | ||
"redis": "0.7.x", | ||
"async": "0.1.x", | ||
"progress2": "0.1.x" | ||
@@ -26,0 +27,0 @@ }, |
@@ -40,3 +40,3 @@ gmail-safe | ||
- Is designed from the ground up to be run in the background, eg. as a background (cron) job. (Ok, in this very early release this still needs a tiny bit of work, but it's going to get there very soon.) | ||
- Supports Google Application-Specific Passwords so people with two-factor authentication can still use it. (This comes *gratis*, it just replaces your normal password.) | ||
- Supports Google Application-Specific Passwords so people with two-factor authentication can still use it. (This comes *gratis* with IMAP, it just replaces your normal password.) | ||
@@ -56,2 +56,4 @@ Installation | ||
Note: be sure to install `gmail-safe` using `npm install -g gmail-safe` - without the -g (which tells npm to install the gmail_safe executable globally) or the environment will break and `gmail-safe` will not function. If you know why, please file an issue to help point me in the right direction. | ||
Plannead Features | ||
@@ -58,0 +60,0 @@ ----------------- |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13383
240
66
1
7
+ Addedasync@0.1.x