Update: Umm, something seems to have happened. Now my Inbox has gone from 36,000+ to 353,000+ messages in it. Huh? What on earth is going on here.
I've never archived my Gmail Inbox and as a result have 36,000+ messages in it. I'd like to archive all messages over 60 days old, and no way I'm doing it manually.
So after some googling I found a google-script that could do it, below. However, GmailApp.moveThreadsToArchive(threads);
can apparently can only be called on up to 100 threads at a time, so I've tried wrangle it into a while loop that calls it many times on 100 threads a time:
/**
* Archives Emails older than a given time interval
* src: http://www.quora.com/Gmail/Is-there-a-way-to-auto-archive-emails-after-a-certain-number-of-days
*
* example:
* RunAutoArchive('2w')
* RunAutoArchive('1m')
* RunAutoArchive('5y')
*/
function RunAutoArchive(){
// archive messages older than:
var interval='60d';
// number of threads
var threadCount = 0;
var start = 0;
var end = 100;
// find messages older than a certain time
if(interval != ""){
var searchQuery = 'in:Inbox older_than:'+interval;
var threads = GmailApp.search(searchQuery);
threadCount = threads.length;
// if there are any threads
if(threadCount > 0){
while(start <= threadCount){
// move threads to archive
GmailApp.moveThreadsToArchive(threads.slice(start,end));
// increment count
start += 100;
end += 100;
}
}
}
// refresh threads
GmailApp.refreshThreads(threads);
return threadCount;
}
However, it both debugs and runs successfully (very long Execution Transcript ends with [14-01-16 21:40:59:199 PST] Execution succeeded [284.472 seconds total runtime]
), but my inbox remains unchanged - 36,000+ unarchived messages remain.
Any suggestions what might be wrong?