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

« back to all changes in this revision

Viewing changes to src/engine/imap/transport/imap-client-session.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:
87
87
    }
88
88
    
89
89
    private class SelectParams : AsyncParams {
90
 
        public string mailbox;
 
90
        public Geary.Imap.MailboxParameter mailbox;
91
91
        public bool is_select;
92
92
        
93
 
        public SelectParams(string mailbox, bool is_select, Cancellable? cancellable, SourceFunc cb) {
 
93
        public SelectParams(Geary.Imap.MailboxParameter mailbox, bool is_select, Cancellable? cancellable, SourceFunc cb) {
94
94
            base (cancellable, cb);
95
95
            
96
96
            this.mailbox = mailbox;
243
243
    public ClientSession(Endpoint imap_endpoint, bool imap_server_pipeline) {
244
244
        this.imap_endpoint = imap_endpoint;
245
245
        this.imap_server_pipeline = imap_server_pipeline;
 
246
        allow_idle = imap_server_pipeline;
246
247
        
247
248
        not_connected_err = new ImapError.NOT_CONNECTED("Not connected to %s", imap_endpoint.to_string());
248
249
        
264
265
            new Geary.State.Mapping(State.CONNECTING, Event.DISCONNECT, on_disconnect),
265
266
            new Geary.State.Mapping(State.CONNECTING, Event.CONNECTED, on_connected),
266
267
            new Geary.State.Mapping(State.CONNECTING, Event.CONNECT_DENIED, on_connect_denied),
267
 
            new Geary.State.Mapping(State.CONNECTING, Event.SEND_ERROR, on_send_error),
268
 
            new Geary.State.Mapping(State.CONNECTING, Event.RECV_ERROR, on_recv_error),
 
268
            new Geary.State.Mapping(State.CONNECTING, Event.SEND_ERROR, on_connecting_send_recv_error),
 
269
            new Geary.State.Mapping(State.CONNECTING, Event.RECV_ERROR, on_connecting_send_recv_error),
269
270
            
270
271
            new Geary.State.Mapping(State.NOAUTH, Event.LOGIN, on_login),
271
272
            new Geary.State.Mapping(State.NOAUTH, Event.SEND_CMD, on_send_command),
555
556
     */
556
557
    public async CommandResponse login_async(Geary.Credentials credentials, Cancellable? cancellable = null)
557
558
        throws Error {
558
 
        LoginParams params = new LoginParams(credentials.user, credentials.pass, cancellable,
 
559
        LoginParams params = new LoginParams(credentials.user, credentials.pass ?? "", cancellable,
559
560
            login_async.callback);
560
561
        fsm.issue(Event.LOGIN, null, params);
561
562
        
672
673
    }
673
674
    
674
675
    private uint on_login_failed(uint state, uint event, void *user) {
 
676
        // don't fire signals inside state transition handlers
 
677
        fsm.do_post_transition(on_signal_login_failed);
 
678
        
 
679
        return State.NOAUTH;
 
680
    }
 
681
    
 
682
    private void on_signal_login_failed() {
675
683
        login_failed();
676
 
        
677
 
        return State.NOAUTH;
678
684
    }
679
685
    
680
686
    //
722
728
     *
723
729
     * This will *not* break a connection out of IDLE mode; a command must be sent as well to force
724
730
     * the connection back to de-idled state.
 
731
     *
 
732
     * Note that this overrides other heuristics ClientSession uses about allowing idle, so use
 
733
     * with caution.
725
734
     */
726
735
    public void allow_idle_when_selected(bool allow_idle) {
727
736
        this.allow_idle = allow_idle;
809
818
    }
810
819
    
811
820
    public bool supports_idle() {
812
 
        return get_capabilities().has_capability("idle");
 
821
        return get_capabilities().has_capability(Capabilities.IDLE);
813
822
    }
814
823
    
815
824
    //
899
908
        Cancellable? cancellable) throws Error {
900
909
        string? old_mailbox = current_mailbox;
901
910
        
902
 
        SelectParams params = new SelectParams(mailbox, is_select, cancellable,
903
 
            select_examine_async.callback);
 
911
        SelectParams params = new SelectParams(new Geary.Imap.MailboxParameter(mailbox),
 
912
            is_select, cancellable, select_examine_async.callback);
904
913
        fsm.issue(Event.SELECT, null, params);
905
914
        
906
915
        if (params.do_yield)
923
932
        
924
933
        SelectParams params = (SelectParams) object;
925
934
        
926
 
        if (current_mailbox != null && current_mailbox == params.mailbox)
 
935
        if (current_mailbox != null && current_mailbox == params.mailbox.decode())
927
936
            return state;
928
937
        
929
938
        // TODO: Currently don't handle situation where one mailbox is selected and another is
959
968
        SelectParams params = (SelectParams) object;
960
969
        
961
970
        assert(current_mailbox == null);
962
 
        current_mailbox = params.mailbox;
 
971
        current_mailbox = params.mailbox.decode();
963
972
        current_mailbox_readonly = !params.is_select;
964
973
        
965
974
        return State.SELECTED;
1124
1133
    }
1125
1134
    
1126
1135
    private uint on_disconnected(uint state, uint event) {
1127
 
        drop_connection();
 
1136
        // don't do inside signal handler -- although today drop_connection() doesn't fire signals or call
 
1137
        // callbacks, it could in the future
 
1138
        fsm.do_post_transition(on_drop_connection);
1128
1139
        
1129
1140
        // although we could go to the DISCONNECTED state, that implies the object can be reused ...
1130
1141
        // while possible, that requires all state (not just the FSM) be reset at this point, and
1134
1145
        return State.BROKEN;
1135
1146
    }
1136
1147
    
 
1148
    private void on_drop_connection() {
 
1149
        drop_connection();
 
1150
    }
 
1151
    
1137
1152
    //
1138
1153
    // error handling
1139
1154
    //
1140
1155
    
 
1156
    // use different error handler when connecting because, if connect_async() fails, there's no
 
1157
    // requirement for the user to call disconnect_async() and cleaning up... this prevents leaving the
 
1158
    //  FSM in the CONNECTING state, causing an assertion when this object is destroyed
 
1159
    private uint on_connecting_send_recv_error(uint state, uint event, void *user, Object? object, Error? err) {
 
1160
        assert(err != null);
 
1161
        
 
1162
        debug("[%s] Connecting send error, dropping client connection: %s", to_full_string(), err.message);
 
1163
        
 
1164
        fsm.do_post_transition(() => { drop_connection(); });
 
1165
        
 
1166
        return State.BROKEN;
 
1167
    }
 
1168
    
1141
1169
    private uint on_send_error(uint state, uint event, void *user, Object? object, Error? err) {
1142
1170
        assert(err != null);
1143
1171