Iterate over gmail threads and add a label with addlabel
<p>I wish to run this standalone code twice a day, but cannot solve the exception on the addLabel, which is "impossible to find the method", any suggestion? I tried to change the for cycle as well as to assign a var to the threads[i] but nothing changed. </p>

<pre><code>function salvaNote(){

var d = new Date();
d.setMonth(d.getMonth()-6);
var n = d.getFullYear() + "/" + addZero(d.getMonth()+1) + "/" + addZero(d.getDate()); 
var folderName = 'tavoloTecnico';
labelName = GmailApp.createLabel('tavoloTecnico');  
var query = 'in:anywhere from:mariano.casillo@mit.gov.it OR     from:donato.castigliego@mit.gov.it has:attachment subject:previsioni filename:xls '+ 'after:'+n;
var threads = GmailApp.search(query);
var quanteMail = threads.length;

    for ( var i = 0 ; i &lt; quanteMail; i++) {
    threads[i].addLabel(labelName);
    var mesgs = threads[i].getMessages();
    for(var j in mesgs){

        var attachments = mesgs[j].getAttachments();
    for(var k in attachments){
        var attachment = attachments[k];
        var attachmentBlob = attachment.copyBlob();
        var file = DriveApp.createFile(attachmentBlob);
        DriveApp.getFoldersByName(folderName).next().addFile(file);
    }
    }
}
}
</code></pre>