|
沙发
楼主 |
发表于 2016-3-27 22:29:32
|
只看该作者
- //针对私有协议的配置思路:
- 1.继续时,直接调用接口,获取到账号所对应的imap地址、端口、加密方式的设置,然后直接在界面上显示设置,就不用再做猜测式匹配。
- 2.上面配置完成后,直接进行登录验证(不安全的证书提示一下)。
- 3.控制安全例外的触发和弹出活动
- 触发:进行用户名和密码验证时,imap可通过verifyConfig函数触发,而smtp的js调用没有调通,只有发邮件时才触发。参考
- //this.validate4badCert_IN(); //this.validate4badCert_OUT();
- 弹出窗口的控制:
- verifyConfig.js
- notifyCertProblem: function(socketInfo, status, targetSite) {
- me.informUserOfCertError(socketInfo, targetSite);
- }
- informUserOfCertError : function(socketInfo, targetSite) {
- window.openDialog("chrome://pippki/content/exceptionDialog.xul",
- "","chrome,centerscreen,modal", params);
- }
- // called by onHalfManualTest()
- validate4badCert_IN : function()
- {
- var configFilledIn = this.getConcreteConfig();
- var self = this;
- // logic function defined in verifyConfig.js
- verifyConfig(
- configFilledIn,
- // guess login config?
- configFilledIn.source != AccountConfig.kSourceXML,
- // TODO Instead, the following line would be correct, but I cannot use it,
- // because some other code doesn't adhere to the expectations/specs.
- // Find out what it was and fix it.
- //concreteConfig.source == AccountConfig.kSourceGuess,
- this._parentMsgWindow,
- function(successfulConfig) // success
- {
- setTimeout(self.onHalfManualTest2(), 5000);
-
- /* self.stopSpinner(successfulConfig.incoming.password ?
- "password_ok" : null);
- // the auth might have changed, so we
- // should back-port it to the current config.
- self._currentConfig.incoming.auth = successfulConfig.incoming.auth;
- self._currentConfig.outgoing.auth = successfulConfig.outgoing.auth;
- self._currentConfig.incoming.username = successfulConfig.incoming.username;
- self._currentConfig.outgoing.username = successfulConfig.outgoing.username;
- self.finish();*/
- },
- function(e) // failed
- {
- /*
- self.showErrorStatus("config_unverifiable");
- // TODO bug 555448: wrong error msg, there may be a 1000 other
- // reasons why this failed, and this is misleading users.
- // self.setError("passworderror", "user_pass_invalid");
- // TODO use switchToMode(), see above
- // give user something to proceed after fixing
- _enable("create_button");
- // hidden in non-manual mode, so it's fine to enable
- _enable("half-manual-test_button");
- _enable("advanced-setup_button");
- */
- });
- },
- validate4badCert_OUT : function()
- {
- // var configFilledIn = this.getConcreteConfig();
- var configFilledIn = this.getUserConfig();
- var self = this;
- // logic function defined in verifyConfig.js
- verifyConfig_smtp(
- configFilledIn,
- // guess login config?
- configFilledIn.source != AccountConfig.kSourceXML,
- // TODO Instead, the following line would be correct, but I cannot use it,
- // because some other code doesn't adhere to the expectations/specs.
- // Find out what it was and fix it.
- //concreteConfig.source == AccountConfig.kSourceGuess,
- this._parentMsgWindow,
- function(successfulConfig) // success
- {
- alert("success");
- //setTimeout(self.onHalfManualTest2(), 5000);
-
- /* self.stopSpinner(successfulConfig.incoming.password ?
- "password_ok" : null);
- // the auth might have changed, so we
- // should back-port it to the current config.
- self._currentConfig.incoming.auth = successfulConfig.incoming.auth;
- self._currentConfig.outgoing.auth = successfulConfig.outgoing.auth;
- self._currentConfig.incoming.username = successfulConfig.incoming.username;
- self._currentConfig.outgoing.username = successfulConfig.outgoing.username;
- self.finish();*/
- },
- function(e) // failed
- {
- /*
- self.showErrorStatus("config_unverifiable");
- // TODO bug 555448: wrong error msg, there may be a 1000 other
- // reasons why this failed, and this is misleading users.
- // self.setError("passworderror", "user_pass_invalid");
- // TODO use switchToMode(), see above
- // give user something to proceed after fixing
- _enable("create_button");
- // hidden in non-manual mode, so it's fine to enable
- _enable("half-manual-test_button");
- _enable("advanced-setup_button");
- */
- });
- },
- function verifyConfig_smtp(config, alter, msgWindow, successCallback, errorCallback)
- {
- //config.outgoing.auth = 3;
- alert("verifyConfig_smtp");
- ddump(debugObject(config, "config", 3));
- assert(config instanceof AccountConfig,
- "BUG: Arg 'config' needs to be an AccountConfig object");
- assert(typeof(alter) == "boolean");
- assert(typeof(successCallback) == "function");
- assert(typeof(errorCallback) == "function");
- var smtpManager = Cc["@mozilla.org/messengercompose/smtp;1"].getService(Ci.nsISmtpService);
- //let username = config.outgoing.auth > 1 ? config.outgoing.username : null;
- let username = config.outgoing.username ;
- let outServer = smtpManager.findServer(username, config.outgoing.hostname);
- if (outServer)
- {
- errorCallback("outServer exists");
- alert("outServer exists");
- return;
- }
- outServer = smtpManager.createSmtpServer();
- outServer.hostname = config.outgoing.hostname;
- outServer.port = config.outgoing.port;
- outServer.authMethod = config.outgoing.auth;
- //if (config.outgoing.auth > 1)
- // {
- // alert(222222);
- outServer.username = username;
- outServer.password = config.incoming.password;
- if (config.rememberPassword && config.incoming.password.length)
- rememberPassword(outServer, config.incoming.password);
- // }
- if (config.outgoing.socketType == 1) // no SSL
- outServer.socketType = Ci.nsMsgSocketType.plain;
- else if (config.outgoing.socketType == 2) // SSL / TLS
- outServer.socketType = Ci.nsMsgSocketType.SSL;
- else if (config.outgoing.socketType == 3) // STARTTLS
- outServer.socketType = Ci.nsMsgSocketType.alwaysSTARTTLS;
- // API problem: <http://mxr.mozilla.org/seamonkey ... tpServer.idl#93>
- outServer.description = config.displayName;
- if (config.password)
- outServer.password = config.outgoing.password;
- // hack - save away the old callbacks.
- let saveCallbacks = msgWindow.notificationCallbacks;
- // set our own callbacks - this works because verifyLogon will
- // synchronously create the transport and use the notification callbacks.
- let listener = new urlListener(config, outServer, alter, msgWindow,
- successCallback, errorCallback);
- // our listener listens both for the url and cert errors.
- msgWindow.notificationCallbacks = listener;
- // try to work around bug where backend is clearing password.
- try {
- outServer.password = config.outgoing.password;
- let uri = outServer.verifyLogon(listener, msgWindow);
- //smtpManager.verifyLogon(outServer, listener, msgWindow);
- // clear msgWindow so url won't prompt for passwords.
- //uri.QueryInterface(Ci.nsIMsgMailNewsUrl).msgWindow = null;
- }
- finally {
- // restore them
- msgWindow.notificationCallbacks = saveCallbacks;
- }
- };
复制代码 |
|