* make modest_text_utils_get_display_date return a ptr to
[modest] / src / modest-account-mgr-helpers.h
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMIT
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30
31 #ifndef __MODEST_ACCOUNT_MGR_HELPERS_H__
32 #define __MODEST_ACCOUNT_MGR_HELPERS_H__
33
34 #include <modest-account-mgr.h>
35 #include <modest-tny-account-store.h>
36
37 #include <tny-account.h>
38 #include <tny-store-account.h>
39 #include <tny-transport-account.h>
40
41 G_BEGIN_DECLS
42
43 typedef struct {
44         gchar            *account_name;
45         gchar            *hostname;
46         gchar            *username;
47         gchar            *uri; /*< Only for mbox and maildir accounts. */
48         ModestTransportStoreProtocol    proto; /*< The store or transport. Not ORed. */
49         gchar            *password;
50         time_t            last_updated;
51         gint              port; /* Or 0, if the default should be used. */
52         ModestAuthProtocol   secure_auth;
53         ModestConnectionProtocol   security;
54 } ModestServerAccountData;
55
56 typedef struct {
57         gchar            *account_name;
58         gchar            *display_name;
59         gchar            *fullname;
60         gchar            *email;
61         gboolean         is_enabled;
62         gboolean         is_default;
63         ModestServerAccountData *transport_account;
64         ModestServerAccountData *store_account;
65 } ModestAccountData;
66
67
68
69 /**
70  * modest_account_mgr_get_account_data:
71  * @self: a ModestAccountMgr instance
72  * @name: the name of the account
73  * 
74  * get information about an account
75  *
76  * Returns: a ModestAccountData structure with information about the account.
77  * the data should not be changed, and be freed with modest_account_mgr_free_account_data
78  * The function does a sanity check, an if it's not returning NULL,
79  * it is a valid account
80  */
81 ModestAccountData *modest_account_mgr_get_account_data     (ModestAccountMgr *self,
82                                                             const gchar* name);
83
84 /**
85  * modest_account_mgr_set_first_account_as_default:
86  * @self: a ModestAccountMgr instance
87  * 
88  * Guarantees that at least one account, if there are any accounts, is the default,
89  * so that modest_account_mgr_get_default_account() will return non-NULL if there 
90  * are any accounts.
91  *
92  * Returns: TRUE if succeeded, FALSE otherwise
93  */
94 gboolean
95 modest_account_mgr_set_first_account_as_default  (ModestAccountMgr *self);
96
97 /** Get the first one, alphabetically, by title. */
98 gchar* 
99 modest_account_mgr_get_first_account_name (ModestAccountMgr *self);
100
101 /**
102  * modest_account_mgr_free_account_data:
103  * @self: a ModestAccountMgr instance
104  * @data: a ModestAccountData instance
105  * 
106  * free the account data structure
107  */
108 void       modest_account_mgr_free_account_data     (ModestAccountMgr *self,
109                                                      ModestAccountData *data);
110
111 /**
112  * modest_account_mgr_set_enabled
113  * @self: a ModestAccountMgr instance
114  * @name: the account name 
115  * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
116  * 
117  * enable/disabled an account
118  *
119  * Returns: TRUE if it worked, FALSE otherwise
120  */
121 gboolean modest_account_mgr_set_enabled (ModestAccountMgr *self, const gchar* name,
122                                          gboolean enabled);
123
124 /**
125  * modest_account_mgr_get_enabled:
126  * @self: a ModestAccountMgr instance
127  * @name: the account name to check
128  *
129  * check whether a certain account is enabled
130  *
131  * Returns: TRUE if it is enabled, FALSE otherwise
132  */
133 gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name);
134
135 /**
136  * modest_account_mgr_set_signature
137  * @self: a ModestAccountMgr instance
138  * @name: the account name to check
139  * @signature: the signature text 
140  * @use_signature: Whether the signature should be used.
141  * 
142  * Sets the signature text for the account.
143  *
144  * Returns: TRUE if it worked, FALSE otherwise
145  */
146 gboolean modest_account_mgr_set_signature (ModestAccountMgr *self, const gchar* name, 
147         const gchar* signature, gboolean use_signature);
148
149 /**
150  * modest_account_mgr_get_signature:
151  * @self: a ModestAccountMgr instance
152  * @name: the account name
153  * @use_signature: Pointer to a gboolean taht will be set to TRUE if the signature should be used.
154  *
155  * Gets the signature text for this account.
156  *
157  * Returns: The signature text, which should be freed with g_free().
158  */
159 gchar* modest_account_mgr_get_signature (ModestAccountMgr *self, const gchar* name, 
160         gboolean* use_signature);
161         
162 /**
163  * modest_account_mgr_get_store_protocol:
164  * @self: a ModestAccountMgr instance
165  * @name: the account name
166  *
167  * Gets the protocol type (For instance, POP or IMAP) used for the store server account.
168  *
169  * Returns: The protocol type.
170  */
171 ModestTransportStoreProtocol modest_account_mgr_get_store_protocol (ModestAccountMgr *self, const gchar* name);
172
173 /**
174  * modest_account_mgr_set_connection_specific_smtp
175  * @self: a ModestAccountMgr instance
176  * @connection_name: A libconic IAP connection name
177  * @server_account_name: a server account name to use for this connection.
178  * 
179  * Specify a server account to use with the specific connection for this account.
180  *
181  * Returns: TRUE if it worked, FALSE otherwise
182  */
183 gboolean modest_account_mgr_set_connection_specific_smtp (ModestAccountMgr *self, 
184                                          const gchar* connection_name, const gchar* server_account_name);
185
186 /**
187  * modest_account_mgr_remove_connection_specific_smtp
188  * @self: a ModestAccountMgr instance
189  * @connection_name: A libconic IAP connection name
190  * 
191  * Disassociate a server account to use with the specific connection for this account.
192  *
193  * Returns: TRUE if it worked, FALSE otherwise
194  */                              
195 gboolean modest_account_mgr_remove_connection_specific_smtp (ModestAccountMgr *self, 
196         const gchar* connection_name);
197
198 /**
199  * modest_account_mgr_get_use_connection_specific_smtp
200  * @self: a ModestAccountMgr instance
201  * @account_name: the account name
202  * @result: Whether this account should use connection-specific smtp server accounts.
203  */
204 gboolean modest_account_mgr_get_use_connection_specific_smtp (ModestAccountMgr *self, const gchar* account_name);
205
206 /**
207  * modest_account_mgr_set_use_connection_specific_smtp
208  * @self: a ModestAccountMgr instance
209  * @account_name: the account name
210  * @new_value: New value that indicates if if this account should use connection-specific smtp server accounts.
211  * @result: TRUE if it succeeded, FALSE otherwise
212  */
213 gboolean modest_account_mgr_set_use_connection_specific_smtp (ModestAccountMgr *self, 
214                                                               const gchar* account_name,
215                                                               gboolean new_value);
216
217 /**
218  * modest_account_mgr_get_connection_specific_smtp
219  * @self: a ModestAccountMgr instance
220  * @connection_name: A libconic IAP connection name
221  * 
222  * Retrieve a server account to use with this specific connection for this account.
223  *
224  * Returns: a server account name to use for this connection, or NULL if none is specified.
225  */                      
226 gchar* modest_account_mgr_get_connection_specific_smtp (ModestAccountMgr *self, 
227                                                         const gchar* connection_name);
228
229
230 /**
231  * modest_account_mgr_get_server_account_username:
232  * @self: a ModestAccountMgr instance
233  * @account_name: The name of a server account.
234  *
235  * Gets the username this server account.
236  *
237  * Returns: The username.
238  */
239 gchar* modest_account_mgr_get_server_account_username (ModestAccountMgr *self, 
240                                                        const gchar* account_name);
241
242 /**
243  * modest_account_mgr_set_server_account_username:
244  * @self: a ModestAccountMgr instance
245  * @account_name: The name of a server account.
246  * @username: The new username.
247  *
248  * Sets the username this server account.
249  */
250 void modest_account_mgr_set_server_account_username (ModestAccountMgr *self, 
251                                                      const gchar* account_name, 
252                                                      const gchar* username);
253
254 /**
255  * modest_account_mgr_get_server_account_username_has_succeeded:
256  * @self: a ModestAccountMgr instance
257  * @account_name: The name of a server account.
258  *
259  * Whether a connection has ever been successfully made to this account with 
260  * the current username. This can be used to avoid asking again for the username 
261  * when asking a second time for a non-stored password.
262  *
263  * Returns: TRUE if the username is known to be correct.
264  */
265 gboolean modest_account_mgr_get_server_account_username_has_succeeded (ModestAccountMgr *self, 
266                                                                        const gchar* account_name);
267
268 /**
269  * modest_account_mgr_set_server_account_username_has_succeeded:
270  * @self: a ModestAccountMgr instance
271  * @account_name: The name of a server account.
272  * @succeeded: Whether the username has succeeded
273  *
274  * Sets whether the username is known to be correct.
275  */
276 void modest_account_mgr_set_server_account_username_has_succeeded (ModestAccountMgr *self, 
277                                                                    const gchar* account_name, 
278                                                                    gboolean succeeded);
279         
280 /**
281  * modest_account_mgr_set_server_account_password:
282  * @self: a ModestAccountMgr instance
283  * @account_name: The name of a server account.
284  * @password: The new password.
285  *
286  * Sets the password for this server account.
287  */
288 void modest_account_mgr_set_server_account_password (ModestAccountMgr *self, 
289                                                      const gchar* account_name, 
290                                                      const gchar* password);
291         
292 /**
293  * modest_account_mgr_get_server_account_password:
294  * @self: a ModestAccountMgr instance
295  * @account_name: The name of a server account.
296  *
297  * Gets the password for this server account from the account settings.
298  */
299 gchar* modest_account_mgr_get_server_account_password (ModestAccountMgr *self, 
300                                                        const gchar* account_name);
301
302 /**
303  * modest_account_mgr_get_server_account_has_password:
304  * @self: a ModestAccountMgr instance
305  * @account_name: The name of a server account.
306  *
307  * Gets whether a password has been set for this server account in the account settings.
308  */
309 gboolean modest_account_mgr_get_server_account_has_password (ModestAccountMgr *self, 
310                                                              const gchar* account_name);         
311
312 /**
313  * modest_server_account_modest_account_mgr_get_server_account_hostname:
314  * @self: a ModestAccountMgr instance
315  * @account_name: The name of a server account.
316  *
317  * Gets the hostname this server account.
318  *
319  * Returns: The hostname.
320  */
321 gchar* modest_account_mgr_get_server_account_hostname (ModestAccountMgr *self, 
322                                                        const gchar* account_name);
323
324 /**
325  * modest_server_account_modest_account_mgr_set_server_account_hostname:
326  * @self: a ModestAccountMgr instance
327  * @account_name: The name of a server account.
328  * @hostname: The new hostname
329  *
330  * Sets the hostname this server account.
331  */
332 void  modest_account_mgr_set_server_account_hostname (ModestAccountMgr *self, 
333                                                       const gchar* account_name,
334                                                       const gchar *hostname);
335
336 /**
337  * modest_account_mgr_get_server_account_secure_auth:
338  * @self: a ModestAccountMgr instance
339  * @account_name: The name of a server account.
340  *
341  * Gets the secure authentication method for this server account.
342  *
343  * Returns: The secure authentication enum value.
344  */
345 ModestAuthProtocol modest_account_mgr_get_server_account_secure_auth (ModestAccountMgr *self, 
346                                                                       const gchar* account_name);
347
348 /**
349  * modest_server_account_data_get_secure_auth:
350  * @self: a ModestAccountMgr instance
351  * @account_name: The name of a server account.
352  * @secure_auth: The secure authentication enum value.
353  *
354  * Gets the secure authentication method for this server account.
355  */
356 void modest_account_mgr_set_server_account_secure_auth (ModestAccountMgr *self, 
357                                                         const gchar* account_name, 
358                                                         ModestAuthProtocol secure_auth);
359         
360 /**
361  * modest_server_account_data_get_security:
362  * @self: a ModestAccountMgr instance
363  * @account_name: The name of a server account.
364  *
365  * Gets the security method for this server account.
366  *
367  * Returns: The security enum value.
368  */
369 ModestConnectionProtocol modest_account_mgr_get_server_account_security (ModestAccountMgr *self, 
370                                                                          const gchar* account_name);
371
372 /**
373  * modest_account_mgr_set_server_account_security:
374  * @self: a ModestAccountMgr instance
375  * @secure_auth: The security enum value.
376  *
377  * Gets the security method for this server account.
378  */
379 void modest_account_mgr_set_server_account_security (ModestAccountMgr *self, 
380                                                      const gchar* account_name, 
381                                                      ModestConnectionProtocol security);
382
383 ModestServerAccountData* modest_account_mgr_get_server_account_data (ModestAccountMgr *self, 
384                                                                      const gchar* name);
385
386 void modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
387                                                   ModestServerAccountData* data);
388
389 /**
390  * modest_account_mgr_get_from_string
391  * @self: a #ModestAccountMgr instance
392  * @name: the account name
393  *
394  * get the From: string for some account; ie. "Foo Bar" <foo.bar@cuux.yy>"
395  *
396  * Returns: the newly allocated from-string, or NULL in case of error
397  */
398 gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name);
399
400
401 /**
402  * modest_account_mgr_get_unused_account_name
403  * @self: a #ModestAccountMgr instance
404  * @name: The initial account name
405  *
406  * get an unused account name, based on a starting string.
407  *
408  * Returns: the newly allocated name.
409  */
410 gchar* modest_account_mgr_get_unused_account_name (ModestAccountMgr *self, 
411                                                    const gchar* starting_name,
412                                                    gboolean server_account);
413
414 /**
415  * modest_account_mgr_get_unused_account_display name
416  * @self: a #ModestAccountMgr instance
417  * @name: The initial account display name
418  *
419  * get an unused account display name, based on a starting string.
420  *
421  * Returns: the newly allocated name.
422  */
423 gchar* modest_account_mgr_get_unused_account_display_name (ModestAccountMgr *self, 
424                                                            const gchar* starting_name);
425
426 /**
427  * modest_account_mgr_set_server_account_security:
428  * @self: a ModestAccountMgr instance
429  * @secure_auth: The security enum value.
430  *
431  * Gets the security method for this server account.
432  */
433 void modest_account_mgr_set_leave_on_server (ModestAccountMgr *self, 
434                                              const gchar* account_name, 
435                                              gboolean leave_on_server);
436
437 gboolean modest_account_mgr_get_leave_on_server (ModestAccountMgr *self, 
438                                                  const gchar* account_name);
439
440 gint  modest_account_mgr_get_last_updated (ModestAccountMgr *self, 
441                                            const gchar* account_name);
442
443 void  modest_account_mgr_set_last_updated (ModestAccountMgr *self, 
444                                            const gchar* account_name,
445                                            gint time);
446
447 gint  modest_account_mgr_get_retrieve_limit (ModestAccountMgr *self, 
448                                              const gchar* account_name);
449
450 void  modest_account_mgr_set_retrieve_limit (ModestAccountMgr *self, 
451                                              const gchar* account_name,
452                                              gint limit_retrieve);
453
454 gint  modest_account_mgr_get_server_account_port (ModestAccountMgr *self, 
455                                                   const gchar* account_name);
456
457 void  modest_account_mgr_set_server_account_port (ModestAccountMgr *self, 
458                                                   const gchar *account_name,
459                                                   gint port_num);
460
461 gchar* modest_account_mgr_get_server_account_name (ModestAccountMgr *self, 
462                                                    const gchar *account_name,
463                                                    TnyAccountType account_type);
464
465 gchar* modest_account_mgr_get_retrieve_type (ModestAccountMgr *self, 
466                                              const gchar *account_name);
467
468 void  modest_account_mgr_set_retrieve_type (ModestAccountMgr *self, 
469                                             const gchar *account_name,
470                                             const gchar *retrieve_type);
471
472 void  modest_account_mgr_set_user_fullname (ModestAccountMgr *self, 
473                                             const gchar *account_name,
474                                             const gchar *fullname);
475
476 void  modest_account_mgr_set_user_email (ModestAccountMgr *self, 
477                                          const gchar *account_name,
478                                          const gchar *email);
479
480 G_END_DECLS
481
482 #endif /* __MODEST_ACCOUNT_MGR_H__ */