|
1.遍历账号文件夹
Components.utils.import("resource:///modules/mailServices.js");
var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
.getService(Components.interfaces.nsIMsgAccountManager);
var accounts = acctMgr.accounts;
for (var i = 0; i < accounts.Count(); i++) {
var account = accounts.GetElementAt(i);
account = account.QueryInterface(Components.interfaces.nsIMsgAccount);
var rootFolder = account.incomingServer.rootFolder; // nsIMsgFolder
Application.console.log(rootFolder.prettiestName);
if (rootFolder.hasSubFolders) {
var subFolders = rootFolder.subFolders; // nsIMsgFolder
while(subFolders.hasMoreElements()) {
var folder = subFolders.getNext().QueryInterface(Components.interfaces.nsIMsgFolder);
Application.console.log(folder.prettiestName);
}
}
}
上面为非递归版,即不会列出子邮件下的子邮件夹下面为递归遍历:
buildTreeInfos: function() {
var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
.getService(Components.interfaces.nsIMsgAccountManager);
var accounts = acctMgr.accounts;
for (var i = 0; i < accounts.Count(); i++) {
var account = accounts.GetElementAt(i);
account = account.QueryInterface(Components.interfaces.nsIMsgAccount);
var rootFolder = account.incomingServer.rootFolder; // nsIMsgFolder
//Application.console.log();
////////////////
var treeItem = this.createTreeItem(rootFolder,true, true, rootFolder.prettiestName,false, rootFolder.prettiestName);
var accountchildren = this.createTreeChildren();
treeItem.appendChild(accountchildren);
this.gmailChild.appendChild(treeItem); //主账号
////////////////
if (rootFolder.hasSubFolders) {
var subFolders = rootFolder.subFolders; // nsIMsgFolder
while(subFolders.hasMoreElements()) {
////////////////
var folder = subFolders.getNext().QueryInterface(Components.interfaces.nsIMsgFolder);
var treeItem = this.createTreeItem(folder,folder.subFolders.hasMoreElements(), false, folder.prettiestName,false, folder.prettiestName);
var children = this.createTreeChildren();
treeItem.appendChild(children);
accountchildren.appendChild(treeItem);
this.buildTreefromSubFolder(folder,children);
//////////////////////
//Application.console.log(folder.prettiestName);
}
}
}
},
//递归遍历邮件夹
buildTreefromSubFolder: function (rootFolder,prevNode ){
if ( rootFolder.hasSubFolders )
{
var subFolders = rootFolder.subFolders;
while(subFolders.hasMoreElements()) {
var folder = subFolders.getNext().QueryInterface(Components.interfaces.nsIMsgFolder);
var treeItem = this.createTreeItem(folder,folder.subFolders.hasMoreElements(), false, folder.prettiestName,false, folder.prettiestName);
var children = this.createTreeChildren();
treeItem.appendChild(children);
if (prevNode){
prevNode.appendChild(treeItem);
} else {
this.gmailChild.appendChild(treeItem);
}
findFolder = this.buildTreefromSubFolder(folder,children);
}
}
},
|
|