~ubuntu-branches/ubuntu/saucy/geary/saucy-updates

« back to all changes in this revision

Viewing changes to src/engine/imap/transport/imap-client-connection.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-03-14 13:48:23 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130314134823-gyk5av1g508zyj8a
Tags: 0.3.0~pr1-0ubuntu1
New upstream version (FFE lp: #1154316), supports multiple account as
well as full conversation views with inline replies

Show diffs side-by-side

added added

removed removed

Lines of Context:
297
297
     */
298
298
    public async void connect_async(Cancellable? cancellable = null) throws Error {
299
299
        if (cx != null) {
300
 
            debug("Already connected to %s", to_string());
 
300
            debug("Already connected/connecting to %s", to_string());
301
301
            
302
302
            return;
303
303
        }
305
305
        cx = yield endpoint.connect_async(cancellable);
306
306
        ios = cx;
307
307
        
 
308
        // issue CONNECTED event and fire signal because the moment the channels are hooked up,
 
309
        // data can start flowing
308
310
        fsm.issue(Event.CONNECTED);
309
311
        
310
312
        connected();
311
313
        
312
 
        yield open_channels_async(cancellable);
 
314
        try {
 
315
            yield open_channels_async();
 
316
        } catch (Error err) {
 
317
            // if this fails, need to close connection because the caller will not call
 
318
            // disconnect_async()
 
319
            try {
 
320
                yield cx.close_async();
 
321
            } catch (Error close_err) {
 
322
                // ignored
 
323
            }
 
324
            
 
325
            fsm.issue(Event.DISCONNECTED);
 
326
            
 
327
            cx = null;
 
328
            ios = null;
 
329
            
 
330
            throw err;
 
331
        }
313
332
    }
314
333
    
315
334
    public async void disconnect_async(Cancellable? cancellable = null) throws Error {
349
368
        }
350
369
    }
351
370
    
352
 
    private async void open_channels_async(Cancellable? cancellable) throws Error {
 
371
    private async void open_channels_async() throws Error {
353
372
        assert(ios != null);
354
373
        assert(ser == null);
355
374
        assert(des == null);
401
420
        yield close_channels_async(cancellable);
402
421
        
403
422
        // wrap connection with TLS connection
404
 
        TlsClientConnection tls_cx = TlsClientConnection.new(cx, cx.get_remote_address());
405
 
        tls_cx.set_validation_flags(TlsCertificateFlags.UNKNOWN_CA);
 
423
        TlsClientConnection tls_cx = yield endpoint.starttls_handshake_async(cx,
 
424
            cx.get_remote_address(), cancellable);
406
425
        
407
426
        ios = tls_cx;
408
427
        
409
 
        // do the handshake
410
 
        yield tls_cx.handshake_async(Priority.DEFAULT, cancellable);
411
 
        
412
428
        // re-open Serializer/Deserializer with the new streams
413
 
        yield open_channels_async(cancellable);
 
429
        yield open_channels_async();
414
430
    }
415
431
    
416
432
    private void on_parameters_ready(RootParameters root) {