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

« back to all changes in this revision

Viewing changes to src/engine/imap/transport/imap-client-session-manager.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:
5
5
 */
6
6
 
7
7
public class Geary.Imap.ClientSessionManager {
8
 
    public const int DEFAULT_MIN_POOL_SIZE = 2;
 
8
    public const int DEFAULT_MIN_POOL_SIZE = 4;
9
9
    
10
 
    private AccountSettings settings;
 
10
    private AccountInformation account_information;
11
11
    private int min_pool_size;
12
12
    private Gee.HashSet<ClientSession> sessions = new Gee.HashSet<ClientSession>();
13
13
    private Geary.NonblockingMutex sessions_mutex = new Geary.NonblockingMutex();
20
20
    
21
21
    public signal void login_failed();
22
22
    
23
 
    public ClientSessionManager(AccountSettings settings, int min_pool_size = DEFAULT_MIN_POOL_SIZE) {
24
 
        this.settings = settings;
 
23
    public ClientSessionManager(AccountInformation account_information,
 
24
        int min_pool_size = DEFAULT_MIN_POOL_SIZE) {
 
25
        this.account_information = account_information;
25
26
        this.min_pool_size = min_pool_size;
26
27
        
 
28
        account_information.notify["imap-credentials"].connect(on_imap_credentials_notified);
 
29
        
 
30
        adjust_session_pool.begin();
 
31
    }
 
32
    
 
33
    ~ClientSessionManager() {
 
34
        account_information.notify["imap-credentials"].disconnect(on_imap_credentials_notified);
 
35
    }
 
36
    
 
37
    private void on_imap_credentials_notified() {
 
38
        authentication_failed = false;
27
39
        adjust_session_pool.begin();
28
40
    }
29
41
    
43
55
            try {
44
56
                yield create_new_authorized_session(null);
45
57
            } catch (Error err) {
46
 
                debug("Unable to create authorized session to %s: %s", settings.imap_endpoint.to_string(), err.message);
 
58
                debug("Unable to create authorized session to %s: %s",
 
59
                    account_information.get_imap_endpoint().to_string(), err.message);
47
60
                
48
61
                break;
49
62
            }
93
106
        ClientSession session = yield get_authorized_session_async(cancellable);
94
107
        
95
108
        ListResults results = ListResults.decode(yield session.send_command_async(
96
 
            new ListCommand.wildcarded("", "%", session.get_capabilities().has_capability("XLIST")),
 
109
            new ListCommand.wildcarded("", new Geary.Imap.MailboxParameter("%"),
 
110
                session.get_capabilities().has_capability("XLIST")),
97
111
            cancellable));
98
112
        
99
113
        if (results.status_response.status != Status.OK)
111
125
        ClientSession session = yield get_authorized_session_async(cancellable);
112
126
        
113
127
        ListResults results = ListResults.decode(yield session.send_command_async(
114
 
            new ListCommand(specifier, session.get_capabilities().has_capability("XLIST")),
 
128
            new ListCommand(new Geary.Imap.MailboxParameter(specifier),
 
129
                session.get_capabilities().has_capability("XLIST")),
115
130
            cancellable));
116
131
        
117
132
        if (results.status_response.status != Status.OK)
124
139
        ClientSession session = yield get_authorized_session_async(cancellable);
125
140
        
126
141
        ListResults results = ListResults.decode(yield session.send_command_async(
127
 
            new ListCommand(path, session.get_capabilities().has_capability("XLIST")),
 
142
            new ListCommand(new Geary.Imap.MailboxParameter(path),
 
143
                session.get_capabilities().has_capability("XLIST")),
128
144
            cancellable));
129
145
        
130
146
        return (results.status_response.status == Status.OK) && (results.get_count() == 1);
135
151
        ClientSession session = yield get_authorized_session_async(cancellable);
136
152
        
137
153
        ListResults results = ListResults.decode(yield session.send_command_async(
138
 
            new ListCommand(path, session.get_capabilities().has_capability("XLIST")),
 
154
            new ListCommand(new Geary.Imap.MailboxParameter(path),
 
155
                session.get_capabilities().has_capability("XLIST")),
139
156
            cancellable));
140
157
        
141
158
        if (results.status_response.status != Status.OK)
149
166
        ClientSession session = yield get_authorized_session_async(cancellable);
150
167
        
151
168
        StatusResults results = StatusResults.decode(yield session.send_command_async(
152
 
            new StatusCommand(path, types), cancellable));
 
169
            new StatusCommand(new Geary.Imap.MailboxParameter(path), types), cancellable));
153
170
        
154
171
        if (results.status_response.status != Status.OK)
155
172
            throw new ImapError.SERVER_ERROR("Server error: %s", results.to_string());
157
174
        return results;
158
175
    }
159
176
    
160
 
    public async Mailbox select_mailbox(string path, Cancellable? cancellable = null) throws Error {
161
 
        return yield select_examine_mailbox(path, true, cancellable);
162
 
    }
163
 
    
164
 
    public async Mailbox examine_mailbox(string path, Cancellable? cancellable = null) throws Error {
165
 
        return yield select_examine_mailbox(path, false, cancellable);
166
 
    }
167
 
    
168
 
    public async Mailbox select_examine_mailbox(string path, bool is_select,
169
 
        Cancellable? cancellable = null) throws Error {
 
177
    public async Mailbox select_mailbox(Geary.FolderPath path, string? delim,
 
178
        Cancellable? cancellable = null) throws Error {
 
179
        return yield select_examine_mailbox(path, delim, true, cancellable);
 
180
    }
 
181
    
 
182
    public async Mailbox examine_mailbox(Geary.FolderPath path, string? delim,
 
183
        Cancellable? cancellable = null) throws Error {
 
184
        return yield select_examine_mailbox(path, delim, false, cancellable);
 
185
    }
 
186
    
 
187
    public async Mailbox select_examine_mailbox(Geary.FolderPath path, string? delim,
 
188
        bool is_select, Cancellable? cancellable = null) throws Error {
170
189
        Gee.HashSet<SelectedContext> contexts = is_select ? selected_contexts : examined_contexts;
171
 
        SelectedContext new_context = yield select_examine_async(path, is_select, cancellable);
 
190
        SelectedContext new_context = yield select_examine_async(
 
191
            path.get_fullpath(delim), is_select, cancellable);
172
192
        
173
193
        if (!contexts.contains(new_context)) {
174
194
            // Can't use the ternary operator due to this bug:
182
202
            assert(added);
183
203
        }
184
204
        
185
 
        return new Mailbox(new_context);
 
205
        return new Mailbox(new_context, path);
186
206
    }
187
207
    
188
208
    private void on_selected_context_freed(Geary.ReferenceSemantics semantics) {
222
242
        if (authentication_failed)
223
243
            throw new ImapError.UNAUTHENTICATED("Invalid ClientSessionManager credentials");
224
244
        
225
 
        ClientSession new_session = new ClientSession(settings.imap_endpoint, settings.imap_server_pipeline);
 
245
        ClientSession new_session = new ClientSession(account_information.get_imap_endpoint(),
 
246
            account_information.imap_server_pipeline);
226
247
        
227
248
        // add session to pool before launching all the connect activity so error cases can properly
228
249
        // back it out
240
261
        }
241
262
        
242
263
        try {
243
 
            yield new_session.initiate_session_async(settings.imap_credentials, cancellable);
 
264
            yield new_session.initiate_session_async(account_information.imap_credentials, cancellable);
244
265
        } catch (Error err) {
245
266
            debug("[%s] Initiate session failure: %s", new_session.to_string(), err.message);
246
267
            
365
386
     * Use only for debugging and logging.
366
387
     */
367
388
    public string to_string() {
368
 
        return settings.imap_endpoint.to_string();
 
389
        return account_information.get_imap_endpoint().to_string();
369
390
    }
370
391
}
371
392