Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2546|回复: 0
打印 上一主题 下一主题

常用 功能代码 快查

[复制链接]

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
跳转到指定楼层
楼主
发表于 2016-3-27 23:34:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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);

        }
    }
  },


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-11-23 04:55 , Processed in 0.058914 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表