Autoconfig for aol.com and friends

Ben Bucksch ben.bucksch at beonex.com
Wed Jan 16 02:05:20 UTC 2013


On 15.01.2013 00:21, Jim wrote:
> Gaia email app ... don't support STARTTLS yet

I've implemented IMAP with STARTTLS in pure JS, with Mozilla's 
nsISocketTransport. It's not hard. Here is the code that does STARTTLS, 
and the surrounding code. If you need more context or the full 
implementation, or have questions, just ask me.

   _openConnection : function(successCallback, errorCallback)

   {

     var self = this;

     this._socket.openSocket(function()

     {

       // Wait for server response

       self._socket.receiveIMAP(null, function(line)

       {

         // Got "* OK servername" response

         self._doSTARTTLSIfNecessary(function()

         {

           self._getCAPs(successCallback, errorCallback);

         }, errorCallback);

       },

       function(okMsg)

       {

         // command success: there was no command, so this never comes

       }, errorCallback);

     }, errorCallback);

   },

   _doSTARTTLSIfNecessary : function(successCallback, errorCallback)

   {

     if (this._account.ssl != 3)

     {

       successCallback();

       return;

     }

     // Don't bother checking CAPS. If it's configured in prefs, we require it.

     assert(this._socket._socket instanceof Ci.nsISocketTransport);

     var sslControl = this._socket._socket.securityInfo;

     if (!(sslControl instanceof Ci.nsISSLSocketControl)) // implicitly does QI

       throw new Exception("nsISSLSocketControl not found");

     this._socket.sendAndReceiveIMAP("STARTTLS", null, null,

     function()

     {

       // |Socket| implements SSL notification callbacks

       sslControl.StartTLS(); // apparently sync, blocks UI :-(

       successCallback();

     }, errorCallback);

   },





More information about the tb-planning mailing list