Discuz! Board

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

账号、邮件、服务等关联及常用获取方法

[复制链接]

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
跳转到指定楼层
楼主
发表于 2015-11-5 23:14:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_examples
  1. var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
  2.                         .getService(Components.interfaces.nsIMsgAccountManager);
  3. var accounts = acctMgr.accounts;
  4. for (var i = 0; i < accounts.length; i++) {
  5.   var account = accounts.queryElementAt(i, Components.interfaces.nsIMsgAccount);
  6.   var rootFolder = account.incomingServer.rootFolder; // nsIMsgFolder
  7.   Application.console.log(rootFolder.prettiestName);
  8.   if (rootFolder.hasSubFolders) {
  9.     var subFolders = rootFolder.subFolders; // nsIMsgFolder
  10.     while(subFolders.hasMoreElements()) {
  11.       var folder = subFolders.getNext().QueryInterface(Components.interfaces.nsIMsgFolder);
  12.       Application.console.log(folder.prettiestName);
  13.     }
  14.   }
  15. }
复制代码
回复

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
沙发
 楼主| 发表于 2015-11-5 23:16:11 | 只看该作者
获取邮件夹方法
  1. 1.根据rdf获取
  2. /*
  3.    var rdf = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService(Components.interfaces.nsIRDFService);
  4.    let identity = getCurrentIdentity();
  5.    var sent_folder="identity."+identity.key+".fcc_folder";
  6.     const Cc = Components.classes;
  7.     const Ci = Components.interfaces;
  8.     let prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("mail.");
  9.     var sendfolder = prefBranch.getCharPref(sent_folder);
  10.     var folder = rdf.GetResource(sendfolder).QueryInterface(Components.interfaces.nsIMsgFolder);
  11.     if (folder.flags & Components.interfaces.nsMsgFolderFlags.SentMail)
  12.     {
  13.        var tmc = folder.getTotalMessages(false);
  14.        var sentfoldermsgCount ="identity."+identity.key+".fcc_folder_msgCount";
  15.        prefBranch.setIntPref(sentfoldermsgCount,tmc);
  16.     }
  17. */
  18. //这里根据调用的位置不同,获取已发送邮件夹的方法不同
  19.    // if ( gFolderTreeView == undefined)
  20.     {
  21.       var folders = GetSelectedMsgFolders(); //方法2
  22.       if( folders.length > 0)
  23.       {
  24.         var rootFolder = folders[0].rootFolder;
  25.         let allfolders = rootFolder.subFolders;
  26.         while(allfolders.hasMoreElements())
  27.         {
  28.           let folder = allfolders.getNext();
  29.           folder = folder.QueryInterface(Components.interfaces.nsIMsgFolder);
  30.           if( folder.isSpecialFolder(Components.interfaces.nsMsgFolderFlags.SentMail, false) )
  31.           {
  32.             this.numTotalMessages += folder.getTotalMessages (true);
  33.             this.buildUpFolderList ( folder );
  34.           }

  35.         }
  36.       }
  37.     }
  38.    /* else
  39.     {
  40.       var rdf = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService(Components.interfaces.nsIRDFService);
  41.        let identity = getCurrentIdentity();
  42.        var sent_folder="identity."+identity.key+".fcc_folder";
  43.         const Cc = Components.classes;
  44.         const Ci = Components.interfaces;
  45.         let prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("mail.");
  46.         var sendfolder = prefBranch.getCharPref(sent_folder);
  47.         var folder = rdf.GetResource(sendfolder).QueryInterface(Components.interfaces.nsIMsgFolder);
  48.         if (folder.flags & Components.interfaces.nsMsgFolderFlags.SentMail)
  49.           {
  50.             this.numTotalMessages += folder.getTotalMessages (true);
  51.             this.buildUpFolderList ( folder );
  52.           }
  53.     }
  54. */
复制代码
回复 支持 反对

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
板凳
 楼主| 发表于 2015-11-5 23:22:32 | 只看该作者
smtp服务器获取
  1. function initSmtpSettings_richinfo() {
  2.         var smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"]
  3.                               .getService(Components.interfaces.nsISmtpService);
  4.         var servers = smtpService.smtpServers;
  5.         while (servers.hasMoreElements())
  6.   {
  7.     var server = servers.getNext();
  8.     if (server instanceof Components.interfaces.nsISmtpServer)
  9.     {
  10.       if(server.key == document.getElementById("identity.smtpServerKey").value)
  11.       {
  12.               initSmtpSettings_ri(server);
  13.        break;
  14.             }
  15.     }
  16.   }
  17. }


  18. if (server) {
  19.             
  20.         gSmtpHostname_ri.value = server.hostname;
  21.         gSmtpDescription_ri.value = server.description;
  22.         gSmtpPort_ri.value = server.port ? server.port : "";
  23.         gSmtpUsername_ri.value = server.username;
  24.         gSmtpAuthMethod_ri.value = server.authMethod;
  25.         gSmtpSocketType_ri.value = (server.socketType < 4) ? server.socketType : 1;
复制代码
回复 支持 反对

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
地板
 楼主| 发表于 2016-3-8 14:25:49 | 只看该作者
  1. 数据floderID判断是不是特定邮件夹
  2. const { GlodaDatastore } = Cu.import('resource:///modules/gloda/datastore.js', {})
  3. const { Gloda } = Cu.import('resource:///modules/gloda/public.js', {})

  4. exports.getXPCOMFolderFromFolderID = (folderID) => {
  5.   let glodaFolder = GlodaDatastore._mapFolderID(folderID)
  6.   return glodaFolder.getXPCOMFolder()
  7. }

  8. exports.isConversationFolder = (folderID) => {
  9.   try {
  10.     let folder = exports.getXPCOMFolderFromFolderID(folderID)
  11.     folder.QueryInterface(Ci.nsIMsgFolder)
  12.     if (folder.isSpecialFolder(Ci.nsMsgFolderFlags.Trash, true)) {
  13.       return false
  14.     }
  15.     if (folder.isSpecialFolder(Ci.nsMsgFolderFlags.Drafts, true)) {
  16.       return false
  17.     }
  18.   } catch (e) {
  19.     console.log(e + e.stack)
  20.   }
  21.   return true
  22. }

  23. //  根据邮件夹获取当前账号所有folderID
  24. function getAccountFolderIDs (folder) {
  25.   let account = folder.server
  26.   let AccountFolderIDs = []
  27.   let allfolders = account.rootFolder.subFolders
  28.   while (allfolders.hasMoreElements()) {
  29.     let folder = allfolders.getNext()
  30.     folder = folder.QueryInterface(Ci.nsIMsgFolder)
  31.     let accountFolderID = getFolderID(folder)
  32.     AccountFolderIDs.push(accountFolderID)
  33.   }
  34.   return AccountFolderIDs
  35. }
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

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