|
emailWizard.js validateAndFinish self.finish(); finish : function() { curAccount =createAccountInBackend(this.getConcreteConfig(), true, this._email); let folder = curAccount.incomingServer.rootMsgFolder; let server = curAccount.incomingServer; if ("imap" == server.type) { else if ("pop3" == server.type) { this.startPop3FetchMsg(server, folder);{ server.getNewMessages(folder, null, null);} } createInBackend.js createAccountInBackend { //创建收信服务 var accountManager = Cc["@mozilla.org/messenger/account-manager;1"] .getService(Ci.nsIMsgAccountManager); var inServer = accountManager.createIncomingServer //创建发信服务 outServer = smtpManager.createSmtpServer(); //创建identity var identity = accountManager.createIdentity(); //创建账号并记录收信服务器不同于验证过程,验证过程没有这步 var account = accountManager.createAccount(); account.incomingServer = inServer; // will create folder //设置账号的identity account.addIdentity(identity); setFolders(identity, inServer); //保存账号信息 accountManager.saveAccountInfo(); return account; } |
第一阶段总结: 验证接收成功失败的回调函数 function verifyLogon(config, inServer, alter, msgWindow, successCallback, errorCallback) 回调函数在verifyConfig.js验证函数内部转换成js对象 listener let listener = new urlListener(config, inServer, alter, msgWindow, successCallback, errorCallback); listener对象实现 nsIUrlListener 接口 //nsIUrlListener OnStartRunningUrl: function(aUrl) OnStopRunningUrl: function(aUrl, aExitCode) { this._log.info("Finished verifyConfig resulted in " + aExitCode); if (Components.isSuccessCode(aExitCode))//判断返回的退出码 { this._cleanup(); this.mSuccessCallback(this.mConfig); //登录成功,完成成功函数的回调 } } --------C++后端关于listener对象的传递与处理机制------------- js: let listener = new urlListener(config, inServer, alter, msgWindow, successCallback, errorCallback); msgWindow.notificationCallbacks = listener;//注意这里有一个回调通知的保存和恢复 let uri = inServer.verifyLogon(listener, msgWindow); c++: //aUrlListener对应js中的listener nsPop3IncomingServer::VerifyLogon(nsIUrlListener *aUrlListener,nsIMsgWindow *aMsgWindow, nsIURI **aURL) { nsCOMPtr<nsIPop3Service> pop3Service = do_GetService(kCPop3ServiceCID, &rv); return pop3Service->VerifyLogon(this, aUrlListener, aMsgWindow, aURL); } nsPop3Service::VerifyLogon(nsIMsgIncomingServer *aServer,nsIUrlListener *aUrlListener,nsIMsgWindow *aMsgWindow, nsIURI **aURL) { //组建url并把listener对象封装进去 char *urlSpec = PR_smprintf("pop3://%s@%s:%d/?verifyLogon",escapedUsername.get(), popHost.get(), popPort); //构造结果示例:pop3://13342978053@pop3.139.com:110/?verifyLogon nsCOMPtr<nsIURI> url; rv = BuildPop3Url(urlSpec, nullptr, popServer, aUrlListener, getter_AddRefs(url), aMsgWindow); } nsPop3Service::BuildPop3Url(const char *urlSpec, nsIMsgFolder *inbox, nsIPop3IncomingServer *server, nsIUrlListener *aUrlListener,nsIURI **aUrl,nsIMsgWindow *aMsgWindow) { nsCOMPtr<nsIPop3URL> pop3Url = do_CreateInstance(kPop3UrlCID, &rv); rv = CallQueryInterface(pop3Url, aUrl); nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(pop3Url); //上面接口的获取参看nsIPop3URL的继承关系 class nsPop3URL : public nsIPop3URL, public nsMsgMailNewsUrl mailnewsurl->RegisterListener(aUrlListener); } //注册后查看后面是处理的 \mailnews\base\util\nsMsgMailNewsUrl.cpp nsMsgMailNewsUrl::RegisterListener(nsIUrlListener *aUrlListener) { mUrlListeners.AppendElement(aUrlListener); } //发送通知的宏 #define NOTIFY_URL_LISTENERS(propertyfunc_, params_) \ PR_BEGIN_MACRO \ nsTObserverArray<nsCOMPtr<nsIUrlListener> >::ForwardIterator iter(mUrlListeners); \ while (iter.HasMore()) { \ nsCOMPtr<nsIUrlListener> listener = iter.GetNext(); \ listener->propertyfunc_ params_; \ } \ PR_END_MACRO //跟踪何时调用这个宏 nsresult nsMsgMailNewsUrl::SetUrlState(bool aRunningUrl, nsresult aExitCode) { { if (m_runningUrl) { NOTIFY_URL_LISTENERS(OnStartRunningUrl, (this)); } else { NOTIFY_URL_LISTENERS(OnStopRunningUrl, (this, aExitCode)); mUrlListeners.Clear(); } } //协议中何时调用 nsPop3Protocol.cpp#4119 case POP3_FREE: mailnewsurl->SetUrlState(false, m_pop3ConData->urlStatus); |
+OK richmail system v10(32d255323e8d829-c3ed4) AUTH -ERR Bad sequence of commands CAPA -ERR Bad sequence of commands USER 13342978053@139.com +OK PASS cccccpassword +OK login success STAT +OK 3 140231 QUIT +OK dewey POP3 server signing off 前端createAccountInBackend 进行上面几个命令后, 前端js文件 createInBackend.js function createAccountInBackend(config, isPublicEmailAddr, curEmailAddr) account.incomingServer = inServer; // will create folder 调用下面c++代码 会进入邮件夹创建 nsMsgAccount::SetIncomingServer(nsIMsgIncomingServer *aIncomingServer) |
15.运行当前协议 m_pop3Server->SetRunningProtocol(this); { m_runningProtocol = aProtocol; } 16.调用父类执行 return nsMsgProtocol:: LoadUrl(aURL); // Ouput stream for writing commands to the socket nsCOMPtr<nsIOutputStream> m_outputStream; // this will be obtained from the transport interface nsCOMPtr<nsIInputStream> m_inputStream; // Ouput stream for writing commands to the socket nsCOMPtr<nsITransport> m_transport; nsCOMPtr<nsIRequest> m_request; nsresult nsMsgProtocol:: LoadUrl(nsIURI * aURL, nsISupports * aConsumer) { //从transport获取输入流 nsCOMPtr<nsIInputStream> m_inputStream; rv = m_transport->OpenInputStream(0, 0, 0, getter_AddRefs(m_inputStream)); ///inputStream关联 pump 提供异步方法 nsCOMPtr<nsIInputStreamPump> pump; rv = NS_NewInputStreamPump(getter_AddRefs(pump), m_inputStream, -1, m_readCount); m_request = pump; // keep a reference to the pump so we can cancel it //注册有数据的通知 // put us in a state where we are always notified of incoming data rv = pump->AsyncRead(this, urlSupports); } |
|
|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )
GMT+8, 2024-11-23 09:02 , Processed in 0.063667 second(s), 23 queries .
Powered by Discuz! X3
© 2001-2013 Comsenz Inc.