Split camel-imapx library and merge into camel so that providers can be written on...
[platform/upstream/evolution-data-server.git] / camel / camel-imapx-settings.c
1 /*
2  * camel-imapx-settings.c
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
16  *
17  */
18
19 #include "camel-imapx-settings.h"
20
21 #define MIN_CONCURRENT_CONNECTIONS 1
22 #define MAX_CONCURRENT_CONNECTIONS 7
23
24 #define CAMEL_IMAPX_SETTINGS_GET_PRIVATE(obj) \
25         (G_TYPE_INSTANCE_GET_PRIVATE \
26         ((obj), CAMEL_TYPE_IMAPX_SETTINGS, CamelIMAPXSettingsPrivate))
27
28 struct _CamelIMAPXSettingsPrivate {
29         GMutex *property_lock;
30         gchar *namespace;
31         gchar *shell_command;
32
33         guint batch_fetch_count;
34         guint concurrent_connections;
35
36         gboolean check_all;
37         gboolean check_subscribed;
38         gboolean filter_all;
39         gboolean filter_junk;
40         gboolean filter_junk_inbox;
41         gboolean use_idle;
42         gboolean use_mobile_mode;
43         gboolean use_namespace;
44         gboolean use_qresync;
45         gboolean use_shell_command;
46         gboolean use_subscriptions;
47
48         CamelSortType fetch_order;
49 };
50
51 enum {
52         PROP_0,
53         PROP_AUTH_MECHANISM,
54         PROP_BATCH_FETCH_COUNT,
55         PROP_CHECK_ALL,
56         PROP_CHECK_SUBSCRIBED,
57         PROP_CONCURRENT_CONNECTIONS,
58         PROP_FETCH_ORDER,
59         PROP_FILTER_ALL,
60         PROP_FILTER_JUNK,
61         PROP_FILTER_JUNK_INBOX,
62         PROP_HOST,
63         PROP_MOBILE_MODE,
64         PROP_NAMESPACE,
65         PROP_PORT,
66         PROP_SECURITY_METHOD,
67         PROP_SHELL_COMMAND,
68         PROP_USER,
69         PROP_USE_IDLE,
70         PROP_USE_NAMESPACE,
71         PROP_USE_QRESYNC,
72         PROP_USE_SHELL_COMMAND,
73         PROP_USE_SUBSCRIPTIONS
74 };
75
76 G_DEFINE_TYPE_WITH_CODE (
77         CamelIMAPXSettings,
78         camel_imapx_settings,
79         CAMEL_TYPE_OFFLINE_SETTINGS,
80         G_IMPLEMENT_INTERFACE (
81                 CAMEL_TYPE_NETWORK_SETTINGS, NULL))
82
83 static void
84 imapx_settings_set_property (GObject *object,
85                              guint property_id,
86                              const GValue *value,
87                              GParamSpec *pspec)
88 {
89         switch (property_id) {
90                 case PROP_AUTH_MECHANISM:
91                         camel_network_settings_set_auth_mechanism (
92                                 CAMEL_NETWORK_SETTINGS (object),
93                                 g_value_get_string (value));
94                         return;
95
96                 case PROP_BATCH_FETCH_COUNT:
97                         camel_imapx_settings_set_batch_fetch_count (
98                                 CAMEL_IMAPX_SETTINGS (object),
99                                 g_value_get_uint (value));
100                         return;
101
102                 case PROP_CHECK_ALL:
103                         camel_imapx_settings_set_check_all (
104                                 CAMEL_IMAPX_SETTINGS (object),
105                                 g_value_get_boolean (value));
106                         return;
107
108                 case PROP_CHECK_SUBSCRIBED:
109                         camel_imapx_settings_set_check_subscribed (
110                                 CAMEL_IMAPX_SETTINGS (object),
111                                 g_value_get_boolean (value));
112                         return;
113
114                 case PROP_CONCURRENT_CONNECTIONS:
115                         camel_imapx_settings_set_concurrent_connections (
116                                 CAMEL_IMAPX_SETTINGS (object),
117                                 g_value_get_uint (value));
118                         return;
119
120                 case PROP_FETCH_ORDER:
121                         camel_imapx_settings_set_fetch_order (
122                                 CAMEL_IMAPX_SETTINGS (object),
123                                 g_value_get_enum (value));
124                         return;
125
126                 case PROP_FILTER_ALL:
127                         camel_imapx_settings_set_filter_all (
128                                 CAMEL_IMAPX_SETTINGS (object),
129                                 g_value_get_boolean (value));
130                         return;
131
132                 case PROP_FILTER_JUNK:
133                         camel_imapx_settings_set_filter_junk (
134                                 CAMEL_IMAPX_SETTINGS (object),
135                                 g_value_get_boolean (value));
136                         return;
137
138                 case PROP_FILTER_JUNK_INBOX:
139                         camel_imapx_settings_set_filter_junk_inbox (
140                                 CAMEL_IMAPX_SETTINGS (object),
141                                 g_value_get_boolean (value));
142                         return;
143
144                 case PROP_HOST:
145                         camel_network_settings_set_host (
146                                 CAMEL_NETWORK_SETTINGS (object),
147                                 g_value_get_string (value));
148                         return;
149
150                 case PROP_MOBILE_MODE:
151                         camel_imapx_settings_set_mobile_mode (
152                                 CAMEL_IMAPX_SETTINGS (object),
153                                 g_value_get_boolean (value));
154                         return;
155
156                 case PROP_NAMESPACE:
157                         camel_imapx_settings_set_namespace (
158                                 CAMEL_IMAPX_SETTINGS (object),
159                                 g_value_get_string (value));
160                         return;
161
162                 case PROP_PORT:
163                         camel_network_settings_set_port (
164                                 CAMEL_NETWORK_SETTINGS (object),
165                                 g_value_get_uint (value));
166                         return;
167
168                 case PROP_SECURITY_METHOD:
169                         camel_network_settings_set_security_method (
170                                 CAMEL_NETWORK_SETTINGS (object),
171                                 g_value_get_enum (value));
172                         return;
173
174                 case PROP_SHELL_COMMAND:
175                         camel_imapx_settings_set_shell_command (
176                                 CAMEL_IMAPX_SETTINGS (object),
177                                 g_value_get_string (value));
178                         return;
179
180                 case PROP_USER:
181                         camel_network_settings_set_user (
182                                 CAMEL_NETWORK_SETTINGS (object),
183                                 g_value_get_string (value));
184                         return;
185
186                 case PROP_USE_IDLE:
187                         camel_imapx_settings_set_use_idle (
188                                 CAMEL_IMAPX_SETTINGS (object),
189                                 g_value_get_boolean (value));
190                         return;
191
192                 case PROP_USE_NAMESPACE:
193                         camel_imapx_settings_set_use_namespace (
194                                 CAMEL_IMAPX_SETTINGS (object),
195                                 g_value_get_boolean (value));
196                         return;
197
198                 case PROP_USE_QRESYNC:
199                         camel_imapx_settings_set_use_qresync (
200                                 CAMEL_IMAPX_SETTINGS (object),
201                                 g_value_get_boolean (value));
202                         return;
203
204                 case PROP_USE_SHELL_COMMAND:
205                         camel_imapx_settings_set_use_shell_command (
206                                 CAMEL_IMAPX_SETTINGS (object),
207                                 g_value_get_boolean (value));
208                         return;
209
210                 case PROP_USE_SUBSCRIPTIONS:
211                         camel_imapx_settings_set_use_subscriptions (
212                                 CAMEL_IMAPX_SETTINGS (object),
213                                 g_value_get_boolean (value));
214                         return;
215         }
216
217         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
218 }
219
220 static void
221 imapx_settings_get_property (GObject *object,
222                              guint property_id,
223                              GValue *value,
224                              GParamSpec *pspec)
225 {
226         switch (property_id) {
227                 case PROP_AUTH_MECHANISM:
228                         g_value_take_string (
229                                 value,
230                                 camel_network_settings_dup_auth_mechanism (
231                                 CAMEL_NETWORK_SETTINGS (object)));
232                         return;
233
234                 case PROP_BATCH_FETCH_COUNT:
235                         g_value_set_uint (
236                                 value,
237                                 camel_imapx_settings_get_batch_fetch_count (
238                                 CAMEL_IMAPX_SETTINGS (object)));
239                         return;
240
241                 case PROP_CHECK_ALL:
242                         g_value_set_boolean (
243                                 value,
244                                 camel_imapx_settings_get_check_all (
245                                 CAMEL_IMAPX_SETTINGS (object)));
246                         return;
247
248                 case PROP_CHECK_SUBSCRIBED:
249                         g_value_set_boolean (
250                                 value,
251                                 camel_imapx_settings_get_check_subscribed (
252                                 CAMEL_IMAPX_SETTINGS (object)));
253                         return;
254
255                 case PROP_CONCURRENT_CONNECTIONS:
256                         g_value_set_uint (
257                                 value,
258                                 camel_imapx_settings_get_concurrent_connections (
259                                 CAMEL_IMAPX_SETTINGS (object)));
260                         return;
261
262                 case PROP_FETCH_ORDER:
263                         g_value_set_enum (
264                                 value,
265                                 camel_imapx_settings_get_fetch_order (
266                                 CAMEL_IMAPX_SETTINGS (object)));
267                         return;
268
269                 case PROP_FILTER_ALL:
270                         g_value_set_boolean (
271                                 value,
272                                 camel_imapx_settings_get_filter_all (
273                                 CAMEL_IMAPX_SETTINGS (object)));
274                         return;
275
276                 case PROP_FILTER_JUNK:
277                         g_value_set_boolean (
278                                 value,
279                                 camel_imapx_settings_get_filter_junk (
280                                 CAMEL_IMAPX_SETTINGS (object)));
281                         return;
282
283                 case PROP_FILTER_JUNK_INBOX:
284                         g_value_set_boolean (
285                                 value,
286                                 camel_imapx_settings_get_filter_junk_inbox (
287                                 CAMEL_IMAPX_SETTINGS (object)));
288                         return;
289
290                 case PROP_HOST:
291                         g_value_take_string (
292                                 value,
293                                 camel_network_settings_dup_host (
294                                 CAMEL_NETWORK_SETTINGS (object)));
295                         return;
296
297                 case PROP_MOBILE_MODE:
298                         g_value_set_boolean (
299                                 value,
300                                 camel_imapx_settings_get_mobile_mode (
301                                 CAMEL_IMAPX_SETTINGS (object)));
302                         return;
303
304                 case PROP_NAMESPACE:
305                         g_value_take_string (
306                                 value,
307                                 camel_imapx_settings_dup_namespace (
308                                 CAMEL_IMAPX_SETTINGS (object)));
309                         return;
310
311                 case PROP_PORT:
312                         g_value_set_uint (
313                                 value,
314                                 camel_network_settings_get_port (
315                                 CAMEL_NETWORK_SETTINGS (object)));
316                         return;
317
318                 case PROP_SECURITY_METHOD:
319                         g_value_set_enum (
320                                 value,
321                                 camel_network_settings_get_security_method (
322                                 CAMEL_NETWORK_SETTINGS (object)));
323                         return;
324
325                 case PROP_SHELL_COMMAND:
326                         g_value_take_string (
327                                 value,
328                                 camel_imapx_settings_dup_shell_command (
329                                 CAMEL_IMAPX_SETTINGS (object)));
330                         return;
331
332                 case PROP_USER:
333                         g_value_take_string (
334                                 value,
335                                 camel_network_settings_dup_user (
336                                 CAMEL_NETWORK_SETTINGS (object)));
337                         return;
338
339                 case PROP_USE_IDLE:
340                         g_value_set_boolean (
341                                 value,
342                                 camel_imapx_settings_get_use_idle (
343                                 CAMEL_IMAPX_SETTINGS (object)));
344                         return;
345
346                 case PROP_USE_NAMESPACE:
347                         g_value_set_boolean (
348                                 value,
349                                 camel_imapx_settings_get_use_namespace (
350                                 CAMEL_IMAPX_SETTINGS (object)));
351                         return;
352
353                 case PROP_USE_QRESYNC:
354                         g_value_set_boolean (
355                                 value,
356                                 camel_imapx_settings_get_use_qresync (
357                                 CAMEL_IMAPX_SETTINGS (object)));
358                         return;
359
360                 case PROP_USE_SHELL_COMMAND:
361                         g_value_set_boolean (
362                                 value,
363                                 camel_imapx_settings_get_use_shell_command (
364                                 CAMEL_IMAPX_SETTINGS (object)));
365                         return;
366
367                 case PROP_USE_SUBSCRIPTIONS:
368                         g_value_set_boolean (
369                                 value,
370                                 camel_imapx_settings_get_use_subscriptions (
371                                 CAMEL_IMAPX_SETTINGS (object)));
372                         return;
373         }
374
375         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
376 }
377
378 static void
379 imapx_settings_finalize (GObject *object)
380 {
381         CamelIMAPXSettingsPrivate *priv;
382
383         priv = CAMEL_IMAPX_SETTINGS_GET_PRIVATE (object);
384
385         g_mutex_free (priv->property_lock);
386
387         g_free (priv->namespace);
388         g_free (priv->shell_command);
389
390         /* Chain up to parent's finalize() method. */
391         G_OBJECT_CLASS (camel_imapx_settings_parent_class)->finalize (object);
392 }
393
394 static void
395 camel_imapx_settings_class_init (CamelIMAPXSettingsClass *class)
396 {
397         GObjectClass *object_class;
398
399         g_type_class_add_private (class, sizeof (CamelIMAPXSettingsPrivate));
400
401         object_class = G_OBJECT_CLASS (class);
402         object_class->set_property = imapx_settings_set_property;
403         object_class->get_property = imapx_settings_get_property;
404         object_class->finalize = imapx_settings_finalize;
405
406         /* Inherited from CamelNetworkSettings. */
407         g_object_class_override_property (
408                 object_class,
409                 PROP_AUTH_MECHANISM,
410                 "auth-mechanism");
411
412         g_object_class_install_property (
413                 object_class,
414                 PROP_BATCH_FETCH_COUNT,
415                 g_param_spec_uint (
416                         "batch-fetch-count",
417                         "Batch Fetch Count",
418                         "Number of envelopes to fetch at once",
419                         0,
420                         G_MAXUINT,
421                         500,
422                         G_PARAM_READWRITE |
423                         G_PARAM_CONSTRUCT |
424                         G_PARAM_STATIC_STRINGS));
425
426         g_object_class_install_property (
427                 object_class,
428                 PROP_CHECK_ALL,
429                 g_param_spec_boolean (
430                         "check-all",
431                         "Check All",
432                         "Check all folders for new messages",
433                         FALSE,
434                         G_PARAM_READWRITE |
435                         G_PARAM_CONSTRUCT |
436                         G_PARAM_STATIC_STRINGS));
437
438         g_object_class_install_property (
439                 object_class,
440                 PROP_CHECK_SUBSCRIBED,
441                 g_param_spec_boolean (
442                         "check-subscribed",
443                         "Check Subscribed",
444                         "Check only subscribed folders for new messages",
445                         FALSE,
446                         G_PARAM_READWRITE |
447                         G_PARAM_CONSTRUCT |
448                         G_PARAM_STATIC_STRINGS));
449
450         g_object_class_install_property (
451                 object_class,
452                 PROP_CONCURRENT_CONNECTIONS,
453                 g_param_spec_uint (
454                         "concurrent-connections",
455                         "Concurrent Connections",
456                         "Number of concurrent IMAP connections to use",
457                         MIN_CONCURRENT_CONNECTIONS,
458                         MAX_CONCURRENT_CONNECTIONS,
459                         5,
460                         G_PARAM_READWRITE |
461                         G_PARAM_CONSTRUCT |
462                         G_PARAM_STATIC_STRINGS));
463
464         g_object_class_install_property (
465                 object_class,
466                 PROP_FETCH_ORDER,
467                 g_param_spec_enum (
468                         "fetch-order",
469                         "Fetch Order",
470                         "Order in which new messages should be fetched",
471                         CAMEL_TYPE_SORT_TYPE,
472                         CAMEL_SORT_ASCENDING,
473                         G_PARAM_READWRITE |
474                         G_PARAM_CONSTRUCT |
475                         G_PARAM_STATIC_STRINGS));
476
477         g_object_class_install_property (
478                 object_class,
479                 PROP_FILTER_ALL,
480                 g_param_spec_boolean (
481                         "filter-all",
482                         "Filter All",
483                         "Whether to apply filters in all folders",
484                         FALSE,
485                         G_PARAM_READWRITE |
486                         G_PARAM_CONSTRUCT |
487                         G_PARAM_STATIC_STRINGS));
488
489         g_object_class_install_property (
490                 object_class,
491                 PROP_FILTER_JUNK,
492                 g_param_spec_boolean (
493                         "filter-junk",
494                         "Filter Junk",
495                         "Whether to filter junk from all folders",
496                         FALSE,
497                         G_PARAM_READWRITE |
498                         G_PARAM_CONSTRUCT |
499                         G_PARAM_STATIC_STRINGS));
500
501         g_object_class_install_property (
502                 object_class,
503                 PROP_FILTER_JUNK_INBOX,
504                 g_param_spec_boolean (
505                         "filter-junk-inbox",
506                         "Filter Junk Inbox",
507                         "Whether to filter junk from Inbox only",
508                         FALSE,
509                         G_PARAM_READWRITE |
510                         G_PARAM_CONSTRUCT |
511                         G_PARAM_STATIC_STRINGS));
512
513         g_object_class_install_property (
514                 object_class,
515                 PROP_MOBILE_MODE,
516                 g_param_spec_boolean (
517                         "mobile-mode",
518                         "Mobile Mode",
519                         "Mobile mode which adjusts the IMAPX for Mobile clients",
520                         FALSE,
521                         G_PARAM_READWRITE |
522                         G_PARAM_CONSTRUCT |
523                         G_PARAM_STATIC_STRINGS));
524
525         /* Inherited from CamelNetworkSettings. */
526         g_object_class_override_property (
527                 object_class,
528                 PROP_HOST,
529                 "host");
530
531         g_object_class_install_property (
532                 object_class,
533                 PROP_NAMESPACE,
534                 g_param_spec_string (
535                         "namespace",
536                         "Namespace",
537                         "Custom IMAP namespace",
538                         NULL,
539                         G_PARAM_READWRITE |
540                         G_PARAM_CONSTRUCT |
541                         G_PARAM_STATIC_STRINGS));
542
543         /* Inherited from CamelNetworkSettings. */
544         g_object_class_override_property (
545                 object_class,
546                 PROP_PORT,
547                 "port");
548
549         /* Inherited from CamelNetworkSettings. */
550         g_object_class_override_property (
551                 object_class,
552                 PROP_SECURITY_METHOD,
553                 "security-method");
554
555         g_object_class_install_property (
556                 object_class,
557                 PROP_SHELL_COMMAND,
558                 g_param_spec_string (
559                         "shell-command",
560                         "Shell Command",
561                         "Shell command for connecting to the server",
562                         "ssh -C -l %u %h exec /usr/sbin/imapd",
563                         G_PARAM_READWRITE |
564                         G_PARAM_CONSTRUCT |
565                         G_PARAM_STATIC_STRINGS));
566
567         /* Inherited from CamelNetworkSettings. */
568         g_object_class_override_property (
569                 object_class,
570                 PROP_USER,
571                 "user");
572
573         g_object_class_install_property (
574                 object_class,
575                 PROP_USE_IDLE,
576                 g_param_spec_boolean (
577                         "use-idle",
578                         "Use IDLE",
579                         "Whether to use the IDLE IMAP extension",
580                         TRUE,
581                         G_PARAM_READWRITE |
582                         G_PARAM_CONSTRUCT |
583                         G_PARAM_STATIC_STRINGS));
584
585         g_object_class_install_property (
586                 object_class,
587                 PROP_USE_NAMESPACE,
588                 g_param_spec_boolean (
589                         "use-namespace",
590                         "Use Namespace",
591                         "Whether to use a custom IMAP namespace",
592                         FALSE,
593                         G_PARAM_READWRITE |
594                         G_PARAM_CONSTRUCT |
595                         G_PARAM_STATIC_STRINGS));
596
597         g_object_class_install_property (
598                 object_class,
599                 PROP_USE_QRESYNC,
600                 g_param_spec_boolean (
601                         "use-qresync",
602                         "Use QRESYNC",
603                         "Whether to use the QRESYNC IMAP extension",
604                         TRUE,
605                         G_PARAM_READWRITE |
606                         G_PARAM_CONSTRUCT |
607                         G_PARAM_STATIC_STRINGS));
608
609         g_object_class_install_property (
610                 object_class,
611                 PROP_USE_SHELL_COMMAND,
612                 g_param_spec_boolean (
613                         "use-shell-command",
614                         "Use Shell Command",
615                         "Whether to use a custom shell "
616                         "command to connect to the server",
617                         FALSE,
618                         G_PARAM_READWRITE |
619                         G_PARAM_CONSTRUCT |
620                         G_PARAM_STATIC_STRINGS));
621
622         g_object_class_install_property (
623                 object_class,
624                 PROP_USE_SUBSCRIPTIONS,
625                 g_param_spec_boolean (
626                         "use-subscriptions",
627                         "Use Subscriptions",
628                         "Whether to honor folder subscriptions",
629                         TRUE,
630                         G_PARAM_READWRITE |
631                         G_PARAM_CONSTRUCT |
632                         G_PARAM_STATIC_STRINGS));
633 }
634
635 static void
636 camel_imapx_settings_init (CamelIMAPXSettings *settings)
637 {
638         settings->priv = CAMEL_IMAPX_SETTINGS_GET_PRIVATE (settings);
639         settings->priv->property_lock = g_mutex_new ();
640 }
641
642 /**
643  * camel_imapx_settings_get_batch_fetch_count:
644  * @settings: a #CamelIMAPXSettings
645  *
646  * Returns the number of message envelopes to fetch at once.
647  *
648  * This is a tunable performance parameter and probably should not be
649  * exposed in a graphical user interface.
650  *
651  * Returns: number of message envelopes to fetch at once
652  *
653  * Since: 3.2
654  **/
655 guint
656 camel_imapx_settings_get_batch_fetch_count (CamelIMAPXSettings *settings)
657 {
658         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), 0);
659
660         return settings->priv->batch_fetch_count;
661 }
662
663 /**
664  * camel_imapx_settings_set_batch_fetch_count:
665  * @settings: a #CamelIMAPXSettings
666  * @batch_fetch_count: number of message envelopes to fetch at once
667  *
668  * Sets the number of message envelopes to fetch at once.
669  *
670  * This is a tunable performance parameter and probably should not be
671  * exposed in a graphical user interface.
672  *
673  * Since: 3.2
674  **/
675 void
676 camel_imapx_settings_set_batch_fetch_count (CamelIMAPXSettings *settings,
677                                             guint batch_fetch_count)
678 {
679         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
680
681         settings->priv->batch_fetch_count = batch_fetch_count;
682
683         g_object_notify (G_OBJECT (settings), "batch-fetch-count");
684 }
685
686 /**
687  * camel_imapx_settings_get_check_all:
688  * @settings: a #CamelIMAPXSettings
689  *
690  * Returns whether to check all folders for new messages.
691  *
692  * Returns: whether to check all folders for new messages
693  *
694  * Since: 3.2
695  **/
696 gboolean
697 camel_imapx_settings_get_check_all (CamelIMAPXSettings *settings)
698 {
699         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
700
701         return settings->priv->check_all;
702 }
703
704 /**
705  * camel_imapx_settings_set_check_all:
706  * @settings: a #CamelIMAPXSettings
707  * @check_all: whether to check all folders for new messages
708  *
709  * Sets whether to check all folders for new messages.
710  *
711  * Since: 3.2
712  **/
713 void
714 camel_imapx_settings_set_check_all (CamelIMAPXSettings *settings,
715                                     gboolean check_all)
716 {
717         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
718
719         settings->priv->check_all = check_all;
720
721         g_object_notify (G_OBJECT (settings), "check-all");
722 }
723
724 /**
725  * camel_imapx_settings_get_check_subscribed:
726  * @settings: a #CamelIMAPXSettings
727  *
728  * Returns whether to check only subscribed folders for new messages.
729  * Note that #CamelIMAPXSettings:check-all, if %TRUE, overrides this setting.
730  *
731  * Returns: whether to check only subscribed folders for new messages
732  *
733  * Since: 3.2
734  **/
735 gboolean
736 camel_imapx_settings_get_check_subscribed (CamelIMAPXSettings *settings)
737 {
738         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
739
740         return settings->priv->check_subscribed;
741 }
742
743 /**
744  * camel_imapx_settings_set_check_subscribed:
745  * @settings: a #CamelIMAPXSettings
746  * @check_subscribed: whether to check only subscribed folders for new messages
747  *
748  * Sets whether to check only subscribed folders for new messages.  Note
749  * that #CamelIMAPXSettings:check-all, if %TRUE, overrides this setting.
750  *
751  * Since: 3.2
752  **/
753 void
754 camel_imapx_settings_set_check_subscribed (CamelIMAPXSettings *settings,
755                                            gboolean check_subscribed)
756 {
757         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
758
759         settings->priv->check_subscribed = check_subscribed;
760
761         g_object_notify (G_OBJECT (settings), "check-subscribed");
762 }
763
764 /**
765  * camel_imapx_settings_get_concurrent_connections:
766  * @settings: a #CamelIMAPXSettings
767  * 
768  * Returns the number of concurrent network connections to the IMAP server
769  * to use for faster command/response processing.
770  *
771  * Returns: the number of concurrent connections to use
772  *
773  * Since: 3.2
774  **/
775 guint
776 camel_imapx_settings_get_concurrent_connections (CamelIMAPXSettings *settings)
777 {
778         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), 1);
779
780         return settings->priv->concurrent_connections;
781 }
782
783 /**
784  * camel_imapx_settings_set_concurrent_connections:
785  * @settings: a #CamelIMAPXSettings
786  * @concurrent_connections: the number of concurrent connections to use
787  *
788  * Sets the number of concurrent network connections to the IMAP server to
789  * use for faster command/response processing.
790  *
791  * The minimum number of connections is 1, the maximum is 7.  The
792  * @concurrent_connections value will be clamped to these limits if
793  * necessary.
794  *
795  * Since: 3.2
796  **/
797 void
798 camel_imapx_settings_set_concurrent_connections (CamelIMAPXSettings *settings,
799                                                  guint concurrent_connections)
800 {
801         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
802
803         concurrent_connections = CLAMP (
804                 concurrent_connections,
805                 MIN_CONCURRENT_CONNECTIONS,
806                 MAX_CONCURRENT_CONNECTIONS);
807
808         settings->priv->concurrent_connections = concurrent_connections;
809
810         g_object_notify (G_OBJECT (settings), "concurrent-connections");
811 }
812
813 /**
814  * camel_imapx_settings_get_fetch_order:
815  * @settings: a #CamelIMAPXSettings
816  *
817  * Returns the order in which new messages should be fetched.
818  *
819  * Returns: the order in which new messages should be fetched
820  *
821  * Since: 3.2
822  **/
823 CamelSortType
824 camel_imapx_settings_get_fetch_order (CamelIMAPXSettings *settings)
825 {
826         g_return_val_if_fail (
827                 CAMEL_IS_IMAPX_SETTINGS (settings),
828                 CAMEL_SORT_ASCENDING);
829
830         return settings->priv->fetch_order;
831 }
832
833 /**
834  * camel_imapx_settings_set_fetch_order:
835  * @settings: a #CamelIMAPXSettings
836  * @fetch_order: the order in which new messages should be fetched
837  *
838  * Sets the order in which new messages should be fetched.
839  *
840  * Since: 3.2
841  **/
842 void
843 camel_imapx_settings_set_fetch_order (CamelIMAPXSettings *settings,
844                                       CamelSortType fetch_order)
845 {
846         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
847
848         settings->priv->fetch_order = fetch_order;
849
850         g_object_notify (G_OBJECT (settings), "fetch-order");
851 }
852
853 /**
854  * camel_imapx_settings_get_filter_all:
855  * @settings: a #CamelIMAPXSettings
856  *
857  * Returns whether apply filters in all folders.
858  *
859  * Returns: whether to apply filters in all folders
860  *
861  * Since: 3.4
862  **/
863 gboolean
864 camel_imapx_settings_get_filter_all (CamelIMAPXSettings *settings)
865 {
866         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
867
868         return settings->priv->filter_all;
869 }
870
871 /**
872  * camel_imapx_settings_set_filter_all:
873  * @settings: a #CamelIMAPXSettings
874  * @filter_all: whether to apply filters in all folders
875  *
876  * Sets whether to apply filters in all folders.
877  *
878  * Since: 3.4
879  **/
880 void
881 camel_imapx_settings_set_filter_all (CamelIMAPXSettings *settings,
882                                      gboolean filter_all)
883 {
884         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
885
886         settings->priv->filter_all = filter_all;
887
888         g_object_notify (G_OBJECT (settings), "filter-all");
889 }
890
891 /**
892  * camel_imapx_settings_get_filter_junk:
893  * @settings: a #CamelIMAPXSettings
894  *
895  * Returns whether to automatically find and tag junk messages amongst new
896  * messages in all folders.
897  *
898  * Returns: whether to filter junk in all folders
899  *
900  * Since: 3.2
901  **/
902 gboolean
903 camel_imapx_settings_get_filter_junk (CamelIMAPXSettings *settings)
904 {
905         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
906
907         return settings->priv->filter_junk;
908 }
909
910 /**
911  * camel_imapx_settings_set_filter_junk:
912  * @settings: a #CamelIMAPXSettings
913  * @filter_junk: whether to filter junk in all folders
914  *
915  * Sets whether to automatically find and tag junk messages amongst new
916  * messages in all folders.
917  *
918  * Since: 3.2
919  **/
920 void
921 camel_imapx_settings_set_filter_junk (CamelIMAPXSettings *settings,
922                                       gboolean filter_junk)
923 {
924         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
925
926         settings->priv->filter_junk = filter_junk;
927
928         g_object_notify (G_OBJECT (settings), "filter-junk");
929 }
930
931 /**
932  * camel_imapx_settings_get_filter_junk_inbox:
933  * @settings: a #CamelIMAPXSettings
934  *
935  * Returns whether to automatically find and tag junk messages amongst new
936  * messages in the Inbox folder only.
937  *
938  * Returns: whether to filter junk in Inbox only
939  *
940  * Since: 3.2
941  **/
942 gboolean
943 camel_imapx_settings_get_filter_junk_inbox (CamelIMAPXSettings *settings)
944 {
945         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
946
947         return settings->priv->filter_junk_inbox;
948 }
949
950 /**
951  * camel_imapx_settings_set_filter_junk_inbox:
952  * @settings: a #CamelIMAPXSettings
953  * @filter_junk_inbox: whether to filter junk in Inbox only
954  *
955  * Sets whether to automatically find and tag junk messages amongst new
956  * messages in the Inbox folder only.
957  *
958  * Since: 3.2
959  **/
960 void
961 camel_imapx_settings_set_filter_junk_inbox (CamelIMAPXSettings *settings,
962                                             gboolean filter_junk_inbox)
963 {
964         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
965
966         settings->priv->filter_junk_inbox = filter_junk_inbox;
967
968         g_object_notify (G_OBJECT (settings), "filter-junk-inbox");
969 }
970
971 /**
972  * camel_imapx_settings_get_mobile_mode:
973  * @settings: a #CamelIMAPXSettings
974  *
975  * Returns whether the backend is operating in mobile mode.
976  *
977  * Since: 3.2
978  **/
979 gboolean
980 camel_imapx_settings_get_mobile_mode (CamelIMAPXSettings *settings)
981 {
982         g_return_val_if_fail (
983                 CAMEL_IS_IMAPX_SETTINGS (settings),
984                 CAMEL_SORT_ASCENDING);
985
986         return settings->priv->use_mobile_mode;
987 }
988
989 /**
990  * camel_imapx_settings_set_mobile_mode:
991  * @settings: a #CamelIMAPXSettings
992  * @mobile_mode: whether to operate in mobile mode.
993  *
994  * Sets the mode of operation as mobile or not for the backend.
995  *
996  * Since: 3.2
997  **/
998 void
999 camel_imapx_settings_set_mobile_mode (CamelIMAPXSettings *settings,
1000                                       gboolean mobile_mode)
1001 {
1002         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
1003
1004         settings->priv->use_mobile_mode = mobile_mode;
1005
1006         g_object_notify (G_OBJECT (settings), "mobile-mode");
1007 }
1008
1009 /**
1010  * camel_imapx_settings_get_namespace:
1011  * @settings: a #CamelIMAPXSettings
1012  *
1013  * Returns the custom IMAP namespace in which to find folders.
1014  *
1015  * Returns: the custom IMAP namespace, or %NULL
1016  *
1017  * Since: 3.2
1018  **/
1019 const gchar *
1020 camel_imapx_settings_get_namespace (CamelIMAPXSettings *settings)
1021 {
1022         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), NULL);
1023
1024         return settings->priv->namespace;
1025 }
1026
1027 /**
1028  * camel_imapx_settings_dup_namespace:
1029  * @settings: a #CamelIMAPXSettings
1030  *
1031  * Thread-safe variation of camel_imapx_settings_get_namespace().
1032  * Use this function when accessing @settings from a worker thread.
1033  *
1034  * The returned string should be freed with g_free() when no longer needed.
1035  *
1036  * Returns: a newly-allocated copy of #CamelIMAPXSettings:namespace
1037  *
1038  * Since: 3.4
1039  **/
1040 gchar *
1041 camel_imapx_settings_dup_namespace (CamelIMAPXSettings *settings)
1042 {
1043         const gchar *protected;
1044         gchar *duplicate;
1045
1046         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), NULL);
1047
1048         g_mutex_lock (settings->priv->property_lock);
1049
1050         protected = camel_imapx_settings_get_namespace (settings);
1051         duplicate = g_strdup (protected);
1052
1053         g_mutex_unlock (settings->priv->property_lock);
1054
1055         return duplicate;
1056 }
1057
1058 /**
1059  * camel_imapx_settings_set_namespace:
1060  * @settings: a #CamelIMAPXSettings
1061  * @namespace: an IMAP namespace, or %NULL
1062  *
1063  * Sets the custom IMAP namespace in which to find folders.  If @namespace
1064  * is %NULL, the default namespace is used.
1065  *
1066  * Since: 3.2
1067  **/
1068 void
1069 camel_imapx_settings_set_namespace (CamelIMAPXSettings *settings,
1070                                     const gchar *namespace)
1071 {
1072         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
1073
1074         /* The default namespace is an empty string. */
1075         if (namespace == NULL)
1076                 namespace = "";
1077
1078         g_mutex_lock (settings->priv->property_lock);
1079
1080         g_free (settings->priv->namespace);
1081         settings->priv->namespace = g_strdup (namespace);
1082
1083         g_mutex_unlock (settings->priv->property_lock);
1084
1085         g_object_notify (G_OBJECT (settings), "namespace");
1086 }
1087
1088 /**
1089  * camel_imapx_settings_get_shell_command:
1090  * @settings: a #CamelIMAPXSettings
1091  *
1092  * Returns an optional shell command used to establish an input/output
1093  * stream with an IMAP server.  Normally the input/output stream is
1094  * established through a network socket.
1095  *
1096  * This option is useful only to a select few advanced users who likely
1097  * administer their own IMAP server.  Most users will not understand what
1098  * this option menas or how to use it.  Probably not worth exposing in a
1099  * graphical interface.
1100  *
1101  * Returns: shell command for connecting to the server, or %NULL
1102  *
1103  * Since: 3.2
1104  **/
1105 const gchar *
1106 camel_imapx_settings_get_shell_command (CamelIMAPXSettings *settings)
1107 {
1108         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), NULL);
1109
1110         return settings->priv->shell_command;
1111 }
1112
1113 /**
1114  * camel_imapx_settings_dup_shell_command:
1115  * @settings: a #CamelIMAPXSettings
1116  *
1117  * Thread-safe variation of camel_imapx_settings_get_shell_command().
1118  * Use this function when accessing @settings from a worker thread.
1119  *
1120  * The returned string should be freed with g_free() when no longer needed.
1121  *
1122  * Returns: a newly-allocated copy of #CamelIMAPXSettings:shell-command
1123  *
1124  * Since: 3.4
1125  **/
1126 gchar *
1127 camel_imapx_settings_dup_shell_command (CamelIMAPXSettings *settings)
1128 {
1129         const gchar *protected;
1130         gchar *duplicate;
1131
1132         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), NULL);
1133
1134         g_mutex_lock (settings->priv->property_lock);
1135
1136         protected = camel_imapx_settings_get_shell_command (settings);
1137         duplicate = g_strdup (protected);
1138
1139         g_mutex_unlock (settings->priv->property_lock);
1140
1141         return duplicate;
1142 }
1143
1144 /**
1145  * camel_imapx_settings_set_shell_command:
1146  * @settings: a #CamelIMAPXSettings
1147  * @shell_command: shell command for connecting to the server, or %NULL
1148  *
1149  * Sets an optional shell command used to establish an input/output stream
1150  * with an IMAP server.  Normally the input/output stream is established
1151  * through a network socket.
1152  *
1153  * This option is useful only to a select few advanced users who likely
1154  * administer their own IMAP server.  Most users will not understand what
1155  * this option means or how to use it.  Probably not worth exposing in a
1156  * graphical interface.
1157  *
1158  * Since: 3.2
1159  **/
1160 void
1161 camel_imapx_settings_set_shell_command (CamelIMAPXSettings *settings,
1162                                         const gchar *shell_command)
1163 {
1164         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
1165
1166         /* An empty string is equivalent to NULL. */
1167         if (shell_command != NULL && *shell_command == '\0')
1168                 shell_command = NULL;
1169
1170         g_mutex_lock (settings->priv->property_lock);
1171
1172         g_free (settings->priv->shell_command);
1173         settings->priv->shell_command = g_strdup (shell_command);
1174
1175         g_mutex_unlock (settings->priv->property_lock);
1176
1177         g_object_notify (G_OBJECT (settings), "shell-command");
1178 }
1179
1180 /**
1181  * camel_imapx_settings_get_use_idle:
1182  * @settings: a #CamelIMAPXSettings
1183  *
1184  * Returns whether to use the IMAP IDLE extension if the server supports
1185  * it.  See RFC 2177 for more details.
1186  *
1187  * Returns: whether to use the IDLE extension
1188  *
1189  * Since: 3.2
1190  **/
1191 gboolean
1192 camel_imapx_settings_get_use_idle (CamelIMAPXSettings *settings)
1193 {
1194         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
1195
1196         return settings->priv->use_idle;
1197 }
1198
1199 /**
1200  * camel_imapx_settings_set_use_idle:
1201  * @settings: a #CamelIMAPXSettings
1202  * @use_idle: whether to use the IDLE extension
1203  *
1204  * Sets whether to use the IMAP IDLE extension if the server supports it.
1205  * See RFC 2177 for more details.
1206  *
1207  * Since: 3.2
1208  **/
1209 void
1210 camel_imapx_settings_set_use_idle (CamelIMAPXSettings *settings,
1211                                    gboolean use_idle)
1212 {
1213         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
1214
1215         settings->priv->use_idle = use_idle;
1216
1217         g_object_notify (G_OBJECT (settings), "use-idle");
1218 }
1219
1220 /**
1221  * camel_imapx_settings_get_use_namespace:
1222  * @settings: a #CamelIMAPXSettings
1223  *
1224  * Returns whether to use a custom IMAP namespace to find folders.  The
1225  * namespace itself is given by the #CamelIMAPStore:namespace property.
1226  *
1227  * Returns: whether to use a custom IMAP namespace
1228  *
1229  * Since: 3.2
1230  **/
1231 gboolean
1232 camel_imapx_settings_get_use_namespace (CamelIMAPXSettings *settings)
1233 {
1234         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
1235
1236         return settings->priv->use_namespace;
1237 }
1238
1239 /**
1240  * camel_imapx_settings_set_use_namespace:
1241  * @settings: a #CamelIMAPXSettings
1242  * @use_namespace: whether to use a custom IMAP namespace
1243  *
1244  * Sets whether to use a custom IMAP namespace to find folders.  The
1245  * namespace itself is given by the #CamelIMAPXSettings:namespace property.
1246  *
1247  * Since: 3.2
1248  **/
1249 void
1250 camel_imapx_settings_set_use_namespace (CamelIMAPXSettings *settings,
1251                                         gboolean use_namespace)
1252 {
1253         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
1254
1255         settings->priv->use_namespace = use_namespace;
1256
1257         g_object_notify (G_OBJECT (settings), "use-namespace");
1258 }
1259
1260 /**
1261  * camel_imapx_settings_get_use_qresync:
1262  * @settings: a #CamelIMAPXSettings
1263  *
1264  * Returns whether to use the Quick Mailbox Resynchronization (QRESYNC)
1265  * IMAP extension if the server supports it.  See RFC 5162 for more
1266  * details.
1267  *
1268  * Returns: whether to use the QRESYNC extension
1269  *
1270  * Since: 3.2
1271  **/
1272 gboolean
1273 camel_imapx_settings_get_use_qresync (CamelIMAPXSettings *settings)
1274 {
1275         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
1276
1277         return settings->priv->use_qresync;
1278 }
1279
1280 /**
1281  * camel_imapx_settings_set_use_qresync:
1282  * @settings: a #CamelIMAPXSettings
1283  * @use_qresync: whether to use the QRESYNC extension
1284  *
1285  * Sets whether to use the Quick Mailbox Resynchronization (QRESYNC)
1286  * IMAP extension if the server supports it.  See RFC 5162 for more
1287  * details.
1288  *
1289  * Since: 3.2
1290  **/
1291 void
1292 camel_imapx_settings_set_use_qresync (CamelIMAPXSettings *settings,
1293                                       gboolean use_qresync)
1294 {
1295         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
1296
1297         settings->priv->use_qresync = use_qresync;
1298
1299         g_object_notify (G_OBJECT (settings), "use-qresync");
1300 }
1301
1302 /**
1303  * camel_imapx_settings_get_use_shell_command:
1304  * @settings: a #CamelIMAPXSettings
1305  *
1306  * Returns whether to use a custom shell command to establish an input/output
1307  * stream with an IMAP server, instead of the more common method of opening a
1308  * network socket.  The shell command itself is given by the
1309  * #CamelIMAPXSettings:shell-command property.
1310  *
1311  * This option is useful only to a select few advanced users who likely
1312  * administer their own IMAP server.  Most users will not understand what
1313  * this option means or how to use it.  Probably not worth exposing in a
1314  * graphical interface.
1315  *
1316  * Returns: whether to use a custom shell command to connect to the server
1317  *
1318  * Since: 3.2
1319  **/
1320 gboolean
1321 camel_imapx_settings_get_use_shell_command (CamelIMAPXSettings *settings)
1322 {
1323         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
1324
1325         return settings->priv->use_shell_command;
1326 }
1327
1328 /**
1329  * camel_imapx_settings_set_use_shell_command:
1330  * @settings: a #CamelIMAPXSettings
1331  * @use_shell_command: whether to use a custom shell command to connect
1332  *                     to the server
1333  *
1334  * Sets whether to use a custom shell command to establish an input/output
1335  * stream with an IMAP server, instead of the more common method of opening
1336  * a network socket.  The shell command itself is given by the
1337  * #CamelIMAPXSettings:shell-command property.
1338  *
1339  * This option is useful only to a select few advanced users who likely
1340  * administer their own IMAP server.  Most users will not understand what
1341  * this option means or how to use it.  Probably not worth exposing in a
1342  * graphical interface.
1343  *
1344  * Since: 3.2
1345  **/
1346 void
1347 camel_imapx_settings_set_use_shell_command (CamelIMAPXSettings *settings,
1348                                             gboolean use_shell_command)
1349 {
1350         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
1351
1352         settings->priv->use_shell_command = use_shell_command;
1353
1354         g_object_notify (G_OBJECT (settings), "use-shell-command");
1355 }
1356
1357 /**
1358  * camel_imapx_settings_get_use_subscriptions:
1359  * @settings: a #CamelIMAPXSettings
1360  *
1361  * Returns whether to list and operate only on subscribed folders, or to
1362  * list and operate on all available folders regardless of subscriptions.
1363  *
1364  * Returns: whether to honor folder subscriptions
1365  *
1366  * Since: 3.2
1367  **/
1368 gboolean
1369 camel_imapx_settings_get_use_subscriptions (CamelIMAPXSettings *settings)
1370 {
1371         g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
1372
1373         return settings->priv->use_subscriptions;
1374 }
1375
1376 /**
1377  * camel_imapx_settings_set_use_subscriptions:
1378  * @settings: a #CamelIMAPXSettings
1379  * @use_subscriptions: whether to honor folder subscriptions
1380  *
1381  * Sets whether to list and operate only on subscribed folders, or to
1382  * list and operate on all available folders regardless of subscriptions.
1383  *
1384  * Since: 3.2
1385  **/
1386 void
1387 camel_imapx_settings_set_use_subscriptions (CamelIMAPXSettings *settings,
1388                                             gboolean use_subscriptions)
1389 {
1390         g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
1391
1392         settings->priv->use_subscriptions = use_subscriptions;
1393
1394         g_object_notify (G_OBJECT (settings), "use-subscriptions");
1395 }
1396