~ubuntu-branches/ubuntu/utopic/evolution-data-server/utopic-proposed

« back to all changes in this revision

Viewing changes to camel/camel-session.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-06-13 12:02:14 UTC
  • mfrom: (1.1.116) (1.2.35 sid)
  • Revision ID: package-import@ubuntu.com-20140613120214-1zx93d8jxwt093aw
Tags: 3.12.2-1ubuntu1
* Merge with Debian, remaining changes:
  - debian/control: build depend on hardening-wrapper
  - Add build-depends and pass configure flag to enable Ubuntu Online
    Accounts support.
  - Filter out -Bsymbolic-functions from LDFLAGS (for future people
    wondering about this change, see e.g. BGO #594473 and duplicates).
  - Enable Ubuntu Online Accounts and split it and GOA into a separate
    package

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 *
10
10
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
11
11
 *
12
 
 * This program is free software; you can redistribute it and/or
13
 
 * modify it under the terms of version 2 of the GNU Lesser General Public
14
 
 * License as published by the Free Software Foundation.
 
12
 * This library is free software you can redistribute it and/or modify it
 
13
 * under the terms of the GNU Lesser General Public License as published by
 
14
 * the Free Software Foundation.
15
15
 *
16
 
 * This program is distributed in the hope that it will be useful,
17
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 * GNU Lesser General Public License for more details.
 
16
 * This library is distributed in the hope that it will be useful, but
 
17
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
18
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
19
 *for more details.
20
20
 *
21
21
 * You should have received a copy of the GNU Lesser General Public License
22
 
 * along with this program; if not, write to the Free Software
23
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
24
 
 * USA
 
22
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25
23
 */
26
24
 
27
25
#ifdef HAVE_CONFIG_H
38
36
#include <glib/gstdio.h>
39
37
 
40
38
#include "camel-debug.h"
 
39
#include "camel-enumtypes.h"
41
40
#include "camel-file-utils.h"
42
41
#include "camel-folder.h"
43
42
#include "camel-mime-message.h"
58
57
#define d(x)
59
58
 
60
59
typedef struct _AsyncContext AsyncContext;
 
60
typedef struct _SignalClosure SignalClosure;
61
61
typedef struct _JobData JobData;
62
62
 
63
63
struct _CamelSessionPrivate {
72
72
 
73
73
        GMainContext *main_context;
74
74
 
75
 
        guint check_junk : 1;
76
 
        guint network_available : 1;
77
75
        guint online : 1;
78
76
};
79
77
 
85
83
        gchar *auth_mechanism;
86
84
};
87
85
 
 
86
struct _SignalClosure {
 
87
        GWeakRef session;
 
88
        CamelService *service;
 
89
        CamelSessionAlertType alert_type;
 
90
        gchar *alert_message;
 
91
};
 
92
 
88
93
struct _JobData {
89
94
        CamelSession *session;
90
95
        GCancellable *cancellable;
95
100
 
96
101
enum {
97
102
        PROP_0,
98
 
        PROP_CHECK_JUNK,
99
103
        PROP_JUNK_FILTER,
100
104
        PROP_MAIN_CONTEXT,
101
 
        PROP_NETWORK_AVAILABLE,
102
105
        PROP_ONLINE,
103
106
        PROP_USER_DATA_DIR,
104
107
        PROP_USER_CACHE_DIR
107
110
enum {
108
111
        JOB_STARTED,
109
112
        JOB_FINISHED,
 
113
        USER_ALERT,
110
114
        LAST_SIGNAL
111
115
};
112
116
 
113
117
static guint signals[LAST_SIGNAL];
114
118
 
115
 
G_DEFINE_TYPE (CamelSession, camel_session, CAMEL_TYPE_OBJECT)
 
119
G_DEFINE_TYPE (CamelSession, camel_session, G_TYPE_OBJECT)
116
120
 
117
121
static void
118
122
async_context_free (AsyncContext *async_context)
133
137
}
134
138
 
135
139
static void
 
140
signal_closure_free (SignalClosure *signal_closure)
 
141
{
 
142
        g_weak_ref_set (&signal_closure->session, NULL);
 
143
 
 
144
        if (signal_closure->service != NULL)
 
145
                g_object_unref (signal_closure->service);
 
146
 
 
147
        g_free (signal_closure->alert_message);
 
148
 
 
149
        g_slice_free (SignalClosure, signal_closure);
 
150
}
 
151
 
 
152
static void
136
153
job_data_free (JobData *job_data)
137
154
{
138
155
        g_object_unref (job_data->session);
145
162
}
146
163
 
147
164
static void
148
 
session_finish_job_cb (CamelSession *session,
149
 
                       GSimpleAsyncResult *simple)
 
165
session_finish_job_cb (GObject *source_object,
 
166
                       GAsyncResult *result,
 
167
                       gpointer unused)
150
168
{
151
 
        JobData *job_data;
152
 
        GError *error = NULL;
153
 
 
154
 
        g_simple_async_result_propagate_error (simple, &error);
155
 
        job_data = g_simple_async_result_get_op_res_gpointer (simple);
 
169
        GCancellable *cancellable;
 
170
        GError *local_error = NULL;
 
171
 
 
172
        cancellable = g_task_get_cancellable (G_TASK (result));
 
173
 
 
174
        /* XXX Ignore the return value, this is just
 
175
         *     to extract the GError if there is one. */
 
176
        g_task_propagate_boolean (G_TASK (result), &local_error);
156
177
 
157
178
        g_signal_emit (
158
 
                job_data->session,
 
179
                CAMEL_SESSION (source_object),
159
180
                signals[JOB_FINISHED], 0,
160
 
                job_data->cancellable, error);
 
181
                cancellable, local_error);
161
182
 
162
 
        g_clear_error (&error);
 
183
        g_clear_error (&local_error);
163
184
}
164
185
 
165
186
static void
166
 
session_do_job_cb (GSimpleAsyncResult *simple,
167
 
                   CamelSession *session,
 
187
session_do_job_cb (GTask *task,
 
188
                   gpointer source_object,
 
189
                   gpointer task_data,
168
190
                   GCancellable *cancellable)
169
191
{
170
192
        JobData *job_data;
171
 
        GError *error = NULL;
 
193
        GError *local_error = NULL;
172
194
 
173
 
        job_data = g_simple_async_result_get_op_res_gpointer (simple);
 
195
        job_data = (JobData *) task_data;
174
196
 
175
197
        job_data->callback (
176
 
                session, cancellable,
177
 
                job_data->user_data, &error);
 
198
                CAMEL_SESSION (source_object),
 
199
                cancellable,
 
200
                job_data->user_data,
 
201
                &local_error);
178
202
 
179
 
        if (error != NULL)
180
 
                g_simple_async_result_take_error (simple, error);
 
203
        if (local_error != NULL) {
 
204
                g_task_return_error (task, local_error);
 
205
        } else {
 
206
                g_task_return_boolean (task, TRUE);
 
207
        }
181
208
}
182
209
 
183
210
static gboolean
184
211
session_start_job_cb (gpointer user_data)
185
212
{
186
213
        JobData *job_data = user_data;
187
 
        GSimpleAsyncResult *simple;
 
214
        GTask *task;
188
215
 
189
216
        g_signal_emit (
190
217
                job_data->session,
191
218
                signals[JOB_STARTED], 0,
192
219
                job_data->cancellable);
193
220
 
194
 
        simple = g_simple_async_result_new (
195
 
                G_OBJECT (job_data->session),
196
 
                (GAsyncReadyCallback) session_finish_job_cb,
197
 
                NULL, camel_session_submit_job);
198
 
 
199
 
        g_simple_async_result_set_check_cancellable (
200
 
                simple, job_data->cancellable);
201
 
 
202
 
        g_simple_async_result_set_op_res_gpointer (
203
 
                simple, job_data, (GDestroyNotify) job_data_free);
204
 
 
205
 
        g_simple_async_result_run_in_thread (
206
 
                simple, (GSimpleAsyncThreadFunc)
207
 
                session_do_job_cb, JOB_PRIORITY,
208
 
                job_data->cancellable);
209
 
 
210
 
        g_object_unref (simple);
 
221
        task = g_task_new (
 
222
                job_data->session,
 
223
                job_data->cancellable,
 
224
                session_finish_job_cb, NULL);
 
225
 
 
226
        g_task_set_task_data (
 
227
                task, job_data, (GDestroyNotify) job_data_free);
 
228
 
 
229
        g_task_run_in_thread (task, session_do_job_cb);
 
230
 
 
231
        g_object_unref (task);
211
232
 
212
233
        return FALSE;
213
234
}
214
235
 
 
236
static gboolean
 
237
session_emit_user_alert_cb (gpointer user_data)
 
238
{
 
239
        SignalClosure *signal_closure = user_data;
 
240
        CamelSession *session;
 
241
 
 
242
        session = g_weak_ref_get (&signal_closure->session);
 
243
 
 
244
        if (session != NULL) {
 
245
                g_signal_emit (
 
246
                        session,
 
247
                        signals[USER_ALERT], 0,
 
248
                        signal_closure->service,
 
249
                        signal_closure->alert_type,
 
250
                        signal_closure->alert_message);
 
251
                g_object_unref (session);
 
252
        }
 
253
 
 
254
        return G_SOURCE_REMOVE;
 
255
}
 
256
 
215
257
static void
216
258
session_set_user_data_dir (CamelSession *session,
217
259
                           const gchar *user_data_dir)
239
281
                      GParamSpec *pspec)
240
282
{
241
283
        switch (property_id) {
242
 
                case PROP_CHECK_JUNK:
243
 
                        camel_session_set_check_junk (
244
 
                                CAMEL_SESSION (object),
245
 
                                g_value_get_boolean (value));
246
 
                        return;
247
 
 
248
284
                case PROP_JUNK_FILTER:
249
285
                        camel_session_set_junk_filter (
250
286
                                CAMEL_SESSION (object),
251
287
                                g_value_get_object (value));
252
288
                        return;
253
289
 
254
 
                case PROP_NETWORK_AVAILABLE:
255
 
                        camel_session_set_network_available (
256
 
                                CAMEL_SESSION (object),
257
 
                                g_value_get_boolean (value));
258
 
                        return;
259
 
 
260
290
                case PROP_ONLINE:
261
291
                        camel_session_set_online (
262
292
                                CAMEL_SESSION (object),
286
316
                      GParamSpec *pspec)
287
317
{
288
318
        switch (property_id) {
289
 
                case PROP_CHECK_JUNK:
290
 
                        g_value_set_boolean (
291
 
                                value, camel_session_get_check_junk (
292
 
                                CAMEL_SESSION (object)));
293
 
                        return;
294
 
 
295
319
                case PROP_JUNK_FILTER:
296
320
                        g_value_set_object (
297
321
                                value, camel_session_get_junk_filter (
304
328
                                CAMEL_SESSION (object)));
305
329
                        return;
306
330
 
307
 
                case PROP_NETWORK_AVAILABLE:
308
 
                        g_value_set_boolean (
309
 
                                value, camel_session_get_network_available (
310
 
                                CAMEL_SESSION (object)));
311
 
                        return;
312
 
 
313
331
                case PROP_ONLINE:
314
332
                        g_value_set_boolean (
315
333
                                value, camel_session_get_online (
450
468
        g_mutex_unlock (&session->priv->services_lock);
451
469
}
452
470
 
453
 
static void
454
 
session_get_socks_proxy (CamelSession *session,
455
 
                         const gchar *for_host,
456
 
                         gchar **host_ret,
457
 
                         gint *port_ret)
458
 
{
459
 
        *host_ret = NULL;
460
 
        *port_ret = 0;
461
 
}
462
 
 
463
471
static gboolean
464
472
session_authenticate_sync (CamelSession *session,
465
473
                           CamelService *service,
565
573
        return (result == CAMEL_AUTHENTICATION_ACCEPTED);
566
574
}
567
575
 
568
 
static void
569
 
session_authenticate_thread (GSimpleAsyncResult *simple,
570
 
                             GObject *object,
571
 
                             GCancellable *cancellable)
572
 
{
573
 
        AsyncContext *async_context;
574
 
        GError *error = NULL;
575
 
 
576
 
        async_context = g_simple_async_result_get_op_res_gpointer (simple);
577
 
 
578
 
        camel_session_authenticate_sync (
579
 
                CAMEL_SESSION (object),
580
 
                async_context->service,
581
 
                async_context->auth_mechanism,
582
 
                cancellable, &error);
583
 
 
584
 
        if (error != NULL)
585
 
                g_simple_async_result_take_error (simple, error);
586
 
}
587
 
 
588
 
static void
589
 
session_authenticate (CamelSession *session,
590
 
                      CamelService *service,
591
 
                      const gchar *mechanism,
592
 
                      gint io_priority,
593
 
                      GCancellable *cancellable,
594
 
                      GAsyncReadyCallback callback,
595
 
                      gpointer user_data)
596
 
{
597
 
        GSimpleAsyncResult *simple;
598
 
        AsyncContext *async_context;
599
 
 
600
 
        async_context = g_slice_new0 (AsyncContext);
601
 
        async_context->service = g_object_ref (service);
602
 
        async_context->auth_mechanism = g_strdup (mechanism);
603
 
 
604
 
        simple = g_simple_async_result_new (
605
 
                G_OBJECT (session), callback, user_data, session_authenticate);
606
 
 
607
 
        g_simple_async_result_set_check_cancellable (simple, cancellable);
608
 
 
609
 
        g_simple_async_result_set_op_res_gpointer (
610
 
                simple, async_context, (GDestroyNotify) async_context_free);
611
 
 
612
 
        g_simple_async_result_run_in_thread (
613
 
                simple, session_authenticate_thread, io_priority, cancellable);
614
 
 
615
 
        g_object_unref (simple);
616
 
}
617
 
 
618
 
static gboolean
619
 
session_authenticate_finish (CamelSession *session,
620
 
                             GAsyncResult *result,
621
 
                             GError **error)
622
 
{
623
 
        GSimpleAsyncResult *simple;
624
 
 
625
 
        g_return_val_if_fail (
626
 
                g_simple_async_result_is_valid (
627
 
                result, G_OBJECT (session), session_authenticate), FALSE);
628
 
 
629
 
        simple = G_SIMPLE_ASYNC_RESULT (result);
630
 
 
631
 
        /* Assume success unless a GError is set. */
632
 
        return !g_simple_async_result_propagate_error (simple, error);
633
 
}
634
 
 
635
576
static gboolean
636
577
session_forward_to_sync (CamelSession *session,
637
578
                         CamelFolder *folder,
648
589
}
649
590
 
650
591
static void
651
 
session_forward_to_thread (GSimpleAsyncResult *simple,
652
 
                           GObject *object,
653
 
                           GCancellable *cancellable)
654
 
{
655
 
        AsyncContext *async_context;
656
 
        GError *error = NULL;
657
 
 
658
 
        async_context = g_simple_async_result_get_op_res_gpointer (simple);
659
 
 
660
 
        camel_session_forward_to_sync (
661
 
                CAMEL_SESSION (object),
662
 
                async_context->folder,
663
 
                async_context->message,
664
 
                async_context->address,
665
 
                cancellable, &error);
666
 
 
667
 
        if (error != NULL)
668
 
                g_simple_async_result_take_error (simple, error);
669
 
}
670
 
 
671
 
static void
672
 
session_forward_to (CamelSession *session,
673
 
                    CamelFolder *folder,
674
 
                    CamelMimeMessage *message,
675
 
                    const gchar *address,
676
 
                    gint io_priority,
677
 
                    GCancellable *cancellable,
678
 
                    GAsyncReadyCallback callback,
679
 
                    gpointer user_data)
680
 
{
681
 
        GSimpleAsyncResult *simple;
682
 
        AsyncContext *async_context;
683
 
 
684
 
        async_context = g_slice_new0 (AsyncContext);
685
 
        async_context->folder = g_object_ref (folder);
686
 
        async_context->message = g_object_ref (message);
687
 
        async_context->address = g_strdup (address);
688
 
 
689
 
        simple = g_simple_async_result_new (
690
 
                G_OBJECT (session), callback, user_data, session_forward_to);
691
 
 
692
 
        g_simple_async_result_set_check_cancellable (simple, cancellable);
693
 
 
694
 
        g_simple_async_result_set_op_res_gpointer (
695
 
                simple, async_context, (GDestroyNotify) async_context_free);
696
 
 
697
 
        g_simple_async_result_run_in_thread (
698
 
                simple, session_forward_to_thread, io_priority, cancellable);
699
 
 
700
 
        g_object_unref (simple);
701
 
}
702
 
 
703
 
static gboolean
704
 
session_forward_to_finish (CamelSession *session,
705
 
                           GAsyncResult *result,
706
 
                           GError **error)
707
 
{
708
 
        GSimpleAsyncResult *simple;
709
 
 
710
 
        g_return_val_if_fail (
711
 
                g_simple_async_result_is_valid (
712
 
                result, G_OBJECT (session), session_forward_to), FALSE);
713
 
 
714
 
        simple = G_SIMPLE_ASYNC_RESULT (result);
715
 
 
716
 
        /* Assume success unless a GError is set. */
717
 
        return !g_simple_async_result_propagate_error (simple, error);
718
 
}
719
 
 
720
 
static void
721
592
camel_session_class_init (CamelSessionClass *class)
722
593
{
723
594
        GObjectClass *object_class;
732
603
 
733
604
        class->add_service = session_add_service;
734
605
        class->remove_service = session_remove_service;
735
 
        class->get_socks_proxy = session_get_socks_proxy;
736
606
 
737
607
        class->authenticate_sync = session_authenticate_sync;
738
608
        class->forward_to_sync = session_forward_to_sync;
739
609
 
740
 
        class->authenticate = session_authenticate;
741
 
        class->authenticate_finish = session_authenticate_finish;
742
 
        class->forward_to = session_forward_to;
743
 
        class->forward_to_finish = session_forward_to_finish;
744
 
 
745
 
        g_object_class_install_property (
746
 
                object_class,
747
 
                PROP_CHECK_JUNK,
748
 
                g_param_spec_boolean (
749
 
                        "check-junk",
750
 
                        "Check Junk",
751
 
                        "Check incoming messages for junk",
752
 
                        FALSE,
753
 
                        G_PARAM_READWRITE |
754
 
                        G_PARAM_CONSTRUCT |
755
 
                        G_PARAM_STATIC_STRINGS));
756
 
 
757
610
        g_object_class_install_property (
758
611
                object_class,
759
612
                PROP_JUNK_FILTER,
779
632
 
780
633
        g_object_class_install_property (
781
634
                object_class,
782
 
                PROP_NETWORK_AVAILABLE,
783
 
                g_param_spec_boolean (
784
 
                        "network-available",
785
 
                        "Network Available",
786
 
                        "Whether the network is available",
787
 
                        TRUE,
788
 
                        G_PARAM_READWRITE |
789
 
                        G_PARAM_CONSTRUCT |
790
 
                        G_PARAM_STATIC_STRINGS));
791
 
 
792
 
        g_object_class_install_property (
793
 
                object_class,
794
635
                PROP_ONLINE,
795
636
                g_param_spec_boolean (
796
637
                        "online",
843
684
                G_TYPE_NONE, 2,
844
685
                G_TYPE_CANCELLABLE,
845
686
                G_TYPE_POINTER);
 
687
 
 
688
        /**
 
689
         * CamelSession::user-alert:
 
690
         * @session: the #CamelSession that received the signal
 
691
         * @service: the #CamelService issuing the alert
 
692
         * @type: the #CamelSessionAlertType
 
693
         * @message: the alert message
 
694
         *
 
695
         * This purpose of this signal is to propagate a server-issued alert
 
696
         * message from @service to a user interface.  The @type hints at the
 
697
         * severity of the alert message.
 
698
         **/
 
699
        signals[USER_ALERT] = g_signal_new (
 
700
                "user-alert",
 
701
                G_OBJECT_CLASS_TYPE (class),
 
702
                G_SIGNAL_RUN_LAST,
 
703
                G_STRUCT_OFFSET (CamelSessionClass, user_alert),
 
704
                NULL, NULL, NULL,
 
705
                G_TYPE_NONE, 3,
 
706
                CAMEL_TYPE_SERVICE,
 
707
                CAMEL_TYPE_SESSION_ALERT_TYPE,
 
708
                G_TYPE_STRING);
846
709
}
847
710
 
848
711
static void
866
729
}
867
730
 
868
731
/**
869
 
 * camel_session_get_main_context:
870
 
 * @session: a #CamelSession
871
 
 *
872
 
 * Returns the #GMainContext on which event sources for @session are to
873
 
 * be attached.
874
 
 *
875
 
 * Returns: a #GMainContext
876
 
 *
877
 
 * Since: 3.6
878
 
 *
879
 
 * Deprecated: 3.8: Use camel_session_ref_main_context() instead.
880
 
 **/
881
 
GMainContext *
882
 
camel_session_get_main_context (CamelSession *session)
883
 
{
884
 
        g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
885
 
 
886
 
        return session->priv->main_context;
887
 
}
888
 
 
889
 
/**
890
732
 * camel_session_ref_main_context:
891
733
 * @session: a #CamelSession
892
734
 *
1289
1131
}
1290
1132
 
1291
1133
/**
1292
 
 * camel_session_alert_user:
1293
 
 * @session: a #CamelSession
1294
 
 * @type: the type of alert (info, warning, or error)
1295
 
 * @prompt: the message for the user
1296
 
 * @button_captions: List of button captions to use. If NULL, only "Dismiss" button is shown.
1297
 
 * @cancellable: (allow-non): optional #GCancellable object, or %NULL
1298
 
 *
1299
 
 * Presents the given @prompt to the user, in the style indicated by
1300
 
 * @type. If @cancel is %TRUE, the user will be able to accept or
1301
 
 * cancel. Otherwise, the message is purely informational.
1302
 
 *
1303
 
 * Returns: Index of pressed button from @button_captions, -1 if NULL.
1304
 
 */
1305
 
gint
1306
 
camel_session_alert_user (CamelSession *session,
1307
 
                          CamelSessionAlertType type,
1308
 
                          const gchar *prompt,
1309
 
                          GList *button_captions,
1310
 
                          GCancellable *cancellable)
1311
 
{
1312
 
        CamelSessionClass *class;
1313
 
 
1314
 
        g_return_val_if_fail (CAMEL_IS_SESSION (session), -1);
1315
 
        g_return_val_if_fail (prompt != NULL, -1);
1316
 
 
1317
 
        class = CAMEL_SESSION_GET_CLASS (session);
1318
 
        g_return_val_if_fail (class->alert_user != NULL, -1);
1319
 
 
1320
 
        return class->alert_user (
1321
 
                session, type, prompt, button_captions, cancellable);
1322
 
}
1323
 
 
1324
 
/**
1325
1134
 * camel_session_trust_prompt:
1326
1135
 * @session: a #CamelSession
1327
 
 * @host: host name, to which the @certificate belongs
1328
 
 * @certificate: base64-encoded DER certificate on which to ask
1329
 
 * @certificate_errors: errors found with the certificate; a bit-OR of a #GTlsCertificateFlags
1330
 
 * @issuers: (allow-none): chain of issuers, or %NULL
1331
 
 * @cancellable: (allow-non): optional #GCancellable object, or %NULL
1332
 
 *
1333
 
 * Prompts user about trust of a certificate. The @certificate is not
1334
 
 * considered trusted, due to reasons set in @certificate_errors.
1335
 
 * There can be passed a list of @issuers, which has as items also base64-encoded
1336
 
 * DER certificates. The first item in the list is an issuer of the @certificate,
1337
 
 * the second item is an issuer of the first item, and so on.
1338
 
 *
1339
 
 * Returns: What trust level should be used for this certificate. It returns
1340
 
 *   #CAMEL_CERT_TRUST_UNKNOWN on error or if user cancelled the dialog prompt.
 
1136
 * @service: a #CamelService
 
1137
 * @certificate: the peer's #GTlsCertificate
 
1138
 * @errors: the problems with @certificate
 
1139
 *
 
1140
 * Prompts the user whether to accept @certificate for @service.  The
 
1141
 * set of flags given in @errors indicate why the @certificate failed
 
1142
 * validation.
 
1143
 *
 
1144
 * If an error occurs during prompting or if the user declines to respond,
 
1145
 * the function returns #CAMEL_CERT_TRUST_UNKNOWN and the certificate will
 
1146
 * be rejected.
 
1147
 *
 
1148
 * Returns: the user's trust level for @certificate
1341
1149
 *
1342
1150
 * Since: 3.8
1343
1151
 **/
1344
1152
CamelCertTrust
1345
1153
camel_session_trust_prompt (CamelSession *session,
1346
 
                            const gchar *host,
1347
 
                            const gchar *certificate,
1348
 
                            guint32 certificate_errors,
1349
 
                            GList *issuers,
1350
 
                            GCancellable *cancellable)
 
1154
                            CamelService *service,
 
1155
                            GTlsCertificate *certificate,
 
1156
                            GTlsCertificateFlags errors)
1351
1157
{
1352
1158
        CamelSessionClass *class;
1353
1159
 
1354
 
        g_return_val_if_fail (CAMEL_IS_SESSION (session), CAMEL_CERT_TRUST_UNKNOWN);
1355
 
        g_return_val_if_fail (certificate != NULL, CAMEL_CERT_TRUST_UNKNOWN);
 
1160
        g_return_val_if_fail (
 
1161
                CAMEL_IS_SESSION (session), CAMEL_CERT_TRUST_UNKNOWN);
 
1162
        g_return_val_if_fail (
 
1163
                CAMEL_IS_SERVICE (service), CAMEL_CERT_TRUST_UNKNOWN);
 
1164
        g_return_val_if_fail (
 
1165
                G_IS_TLS_CERTIFICATE (certificate), CAMEL_CERT_TRUST_UNKNOWN);
1356
1166
 
1357
1167
        class = CAMEL_SESSION_GET_CLASS (session);
1358
 
        g_return_val_if_fail (class->trust_prompt != NULL, CAMEL_CERT_TRUST_UNKNOWN);
1359
 
 
1360
 
        return class->trust_prompt (session, host, certificate, certificate_errors, issuers, cancellable);
 
1168
        g_return_val_if_fail (
 
1169
                class->trust_prompt != NULL, CAMEL_CERT_TRUST_UNKNOWN);
 
1170
 
 
1171
        return class->trust_prompt (session, service, certificate, errors);
 
1172
}
 
1173
 
 
1174
/**
 
1175
 * camel_session_user_alert:
 
1176
 * @session: a #CamelSession
 
1177
 * @service: a #CamelService
 
1178
 * @type: a #CamelSessionAlertType
 
1179
 * @message: the message for the user
 
1180
 *
 
1181
 * Emits a #CamelSession:user_alert signal from an idle source on the main
 
1182
 * loop.  The idle source's priority is #G_PRIORITY_LOW.
 
1183
 *
 
1184
 * The purpose of the signal is to propagate a server-issued alert message
 
1185
 * from @service to a user interface.  The @type hints at the nature of the
 
1186
 * alert message.
 
1187
 *
 
1188
 * Since: 3.12
 
1189
 */
 
1190
void
 
1191
camel_session_user_alert (CamelSession *session,
 
1192
                          CamelService *service,
 
1193
                          CamelSessionAlertType type,
 
1194
                          const gchar *message)
 
1195
{
 
1196
        SignalClosure *signal_closure;
 
1197
 
 
1198
        g_return_if_fail (CAMEL_IS_SESSION (session));
 
1199
        g_return_if_fail (CAMEL_IS_SERVICE (service));
 
1200
        g_return_if_fail (message != NULL);
 
1201
 
 
1202
        signal_closure = g_slice_new0 (SignalClosure);
 
1203
        g_weak_ref_set (&signal_closure->session, session);
 
1204
        signal_closure->service = g_object_ref (service);
 
1205
        signal_closure->alert_type = type;
 
1206
        signal_closure->alert_message = g_strdup (message);
 
1207
 
 
1208
        camel_session_idle_add (
 
1209
                session, G_PRIORITY_LOW,
 
1210
                session_emit_user_alert_cb,
 
1211
                signal_closure,
 
1212
                (GDestroyNotify) signal_closure_free);
1361
1213
}
1362
1214
 
1363
1215
/**
1381
1233
}
1382
1234
 
1383
1235
/**
1384
 
 * camel_session_build_password_prompt:
1385
 
 * @type: account type (e.g. "IMAP")
1386
 
 * @user: user name for the account
1387
 
 * @host: host name for the account
1388
 
 *
1389
 
 * Constructs a localized password prompt from @type, @user and @host,
1390
 
 * suitable for passing to camel_session_get_password().  The resulting
1391
 
 * string contains markup tags.  Use g_free() to free it.
1392
 
 *
1393
 
 * Returns: a newly-allocated password prompt string
1394
 
 *
1395
 
 * Since: 2.22
1396
 
 **/
1397
 
gchar *
1398
 
camel_session_build_password_prompt (const gchar *type,
1399
 
                                     const gchar *user,
1400
 
                                     const gchar *host)
1401
 
{
1402
 
        gchar *user_markup;
1403
 
        gchar *host_markup;
1404
 
        gchar *prompt;
1405
 
 
1406
 
        g_return_val_if_fail (type != NULL, NULL);
1407
 
        g_return_val_if_fail (user != NULL, NULL);
1408
 
        g_return_val_if_fail (host != NULL, NULL);
1409
 
 
1410
 
        /* Add bold tags to the "user" and "host" strings.  We use
1411
 
         * separate strings here to avoid putting markup tags in the
1412
 
         * translatable string below. */
1413
 
        user_markup = g_markup_printf_escaped ("<b>%s</b>", user);
1414
 
        host_markup = g_markup_printf_escaped ("<b>%s</b>", host);
1415
 
 
1416
 
        prompt = g_strdup_printf (
1417
 
                /* Translators: The first argument is the account type
1418
 
                 * (e.g. "IMAP"), the second is the user name, and the
1419
 
                 * third is the host name. */
1420
 
                _("Please enter the %s password for %s on host %s."),
1421
 
                type, user_markup, host_markup);
1422
 
 
1423
 
        g_free (user_markup);
1424
 
        g_free (host_markup);
1425
 
 
1426
 
        return prompt;
1427
 
}
1428
 
 
1429
 
/**
1430
1236
 * camel_session_get_online:
1431
1237
 * @session: a #CamelSession
1432
1238
 *
1652
1458
}
1653
1459
 
1654
1460
/**
1655
 
 * camel_session_get_check_junk:
1656
 
 * @session: a #CamelSession
1657
 
 *
1658
 
 * Do we have to check incoming messages to be junk?
1659
 
 *
1660
 
 * Returns: whether or not we are checking incoming messages for junk
1661
 
 **/
1662
 
gboolean
1663
 
camel_session_get_check_junk (CamelSession *session)
1664
 
{
1665
 
        g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
1666
 
 
1667
 
        return session->priv->check_junk;
1668
 
}
1669
 
 
1670
 
/**
1671
 
 * camel_session_set_check_junk:
1672
 
 * @session: a #CamelSession
1673
 
 * @check_junk: whether to check incoming messages for junk
1674
 
 *
1675
 
 * Set check_junk flag, if set, incoming mail will be checked for being junk.
1676
 
 **/
1677
 
void
1678
 
camel_session_set_check_junk (CamelSession *session,
1679
 
                              gboolean check_junk)
1680
 
{
1681
 
        g_return_if_fail (CAMEL_IS_SESSION (session));
1682
 
 
1683
 
        session->priv->check_junk = check_junk;
1684
 
 
1685
 
        g_object_notify (G_OBJECT (session), "check-junk");
1686
 
}
1687
 
 
1688
 
/**
1689
 
 * camel_session_get_network_available:
1690
 
 * @session: a #CamelSession
1691
 
 *
1692
 
 * Since: 2.32
1693
 
 **/
1694
 
gboolean
1695
 
camel_session_get_network_available (CamelSession *session)
1696
 
{
1697
 
        g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
1698
 
 
1699
 
        return session->priv->network_available;
1700
 
}
1701
 
 
1702
 
/**
1703
 
 * camel_session_set_network_available:
1704
 
 * @session: a #CamelSession
1705
 
 * @network_available: whether a network is available
1706
 
 *
1707
 
 * Since: 2.32
1708
 
 **/
1709
 
void
1710
 
camel_session_set_network_available (CamelSession *session,
1711
 
                                     gboolean network_available)
1712
 
{
1713
 
        g_return_if_fail (CAMEL_IS_SESSION (session));
1714
 
 
1715
 
        session->priv->network_available = network_available;
1716
 
 
1717
 
        g_object_notify (G_OBJECT (session), "network-available");
1718
 
}
1719
 
 
1720
 
/**
1721
1461
 * camel_session_set_junk_headers:
1722
1462
 *
1723
1463
 * Since: 2.22
1758
1498
}
1759
1499
 
1760
1500
/**
1761
 
 * camel_session_get_socks_proxy:
1762
 
 * @session: A #CamelSession
1763
 
 * @for_host: Host name to which the connection will be requested
1764
 
 * @host_ret: Location to return the SOCKS proxy hostname
1765
 
 * @port_ret: Location to return the SOCKS proxy port
1766
 
 *
1767
 
 * Queries the SOCKS proxy that is configured for a @session.  This will
1768
 
 * put %NULL in @hosts_ret if there is no proxy configured or when
1769
 
 * the @for_host is listed in proxy ignore list.
1770
 
 *
1771
 
 * Since: 2.32
1772
 
 */
1773
 
void
1774
 
camel_session_get_socks_proxy (CamelSession *session,
1775
 
                               const gchar *for_host,
1776
 
                               gchar **host_ret,
1777
 
                               gint *port_ret)
1778
 
{
1779
 
        CamelSessionClass *class;
1780
 
 
1781
 
        g_return_if_fail (CAMEL_IS_SESSION (session));
1782
 
        g_return_if_fail (for_host != NULL);
1783
 
        g_return_if_fail (host_ret != NULL);
1784
 
        g_return_if_fail (port_ret != NULL);
1785
 
 
1786
 
        class = CAMEL_SESSION_GET_CLASS (session);
1787
 
        g_return_if_fail (class->get_socks_proxy != NULL);
1788
 
 
1789
 
        class->get_socks_proxy (session, for_host, host_ret, port_ret);
1790
 
}
1791
 
 
1792
 
/**
1793
1501
 * camel_session_authenticate_sync:
1794
1502
 * @session: a #CamelSession
1795
1503
 * @service: a #CamelService
1833
1541
        return success;
1834
1542
}
1835
1543
 
1836
 
/**
1837
 
 * camel_session_forward_to_sync:
1838
 
 * @session: a #CamelSession
1839
 
 * @folder: the #CamelFolder where @message is located
1840
 
 * @message: the #CamelMimeMessage to forward
1841
 
 * @address: the recipient's email address
1842
 
 * @cancellable: optional #GCancellable object, or %NULL
1843
 
 * @error: return location for a #GError, or %NULL
1844
 
 *
1845
 
 * Forwards @message in @folder to the email address(es) given by @address.
1846
 
 *
1847
 
 * If an error occurs, the function sets @error and returns %FALSE.
1848
 
 *
1849
 
 * Returns: %TRUE on success, %FALSE on failure
1850
 
 *
1851
 
 * Since: 3.6
1852
 
 **/
1853
 
gboolean
1854
 
camel_session_forward_to_sync (CamelSession *session,
1855
 
                               CamelFolder *folder,
1856
 
                               CamelMimeMessage *message,
1857
 
                               const gchar *address,
1858
 
                               GCancellable *cancellable,
1859
 
                               GError **error)
 
1544
/* Helper for camel_session_authenticate() */
 
1545
static void
 
1546
session_authenticate_thread (GTask *task,
 
1547
                             gpointer source_object,
 
1548
                             gpointer task_data,
 
1549
                             GCancellable *cancellable)
1860
1550
{
1861
 
        CamelSessionClass *class;
1862
1551
        gboolean success;
1863
 
 
1864
 
        g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
1865
 
        g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
1866
 
        g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
1867
 
        g_return_val_if_fail (address != NULL, FALSE);
1868
 
 
1869
 
        class = CAMEL_SESSION_GET_CLASS (session);
1870
 
        g_return_val_if_fail (class->forward_to_sync != NULL, FALSE);
1871
 
 
1872
 
        success = class->forward_to_sync (
1873
 
                session, folder, message, address, cancellable, error);
1874
 
        CAMEL_CHECK_GERROR (session, forward_to_sync, success, error);
1875
 
 
1876
 
        return success;
 
1552
        AsyncContext *async_context;
 
1553
        GError *local_error = NULL;
 
1554
 
 
1555
        async_context = (AsyncContext *) task_data;
 
1556
 
 
1557
        success = camel_session_authenticate_sync (
 
1558
                CAMEL_SESSION (source_object),
 
1559
                async_context->service,
 
1560
                async_context->auth_mechanism,
 
1561
                cancellable, &local_error);
 
1562
 
 
1563
        if (local_error != NULL) {
 
1564
                g_task_return_error (task, local_error);
 
1565
        } else {
 
1566
                g_task_return_boolean (task, success);
 
1567
        }
1877
1568
}
1878
1569
 
1879
1570
/**
1907
1598
                            GAsyncReadyCallback callback,
1908
1599
                            gpointer user_data)
1909
1600
{
1910
 
        CamelSessionClass *class;
 
1601
        GTask *task;
 
1602
        AsyncContext *async_context;
1911
1603
 
1912
1604
        g_return_if_fail (CAMEL_IS_SESSION (session));
1913
1605
        g_return_if_fail (CAMEL_IS_SERVICE (service));
1914
1606
 
1915
 
        class = CAMEL_SESSION_GET_CLASS (session);
1916
 
        g_return_if_fail (class->authenticate != NULL);
1917
 
 
1918
 
        class->authenticate (
1919
 
                session, service, mechanism, io_priority,
1920
 
                cancellable, callback, user_data);
 
1607
        async_context = g_slice_new0 (AsyncContext);
 
1608
        async_context->service = g_object_ref (service);
 
1609
        async_context->auth_mechanism = g_strdup (mechanism);
 
1610
 
 
1611
        task = g_task_new (session, cancellable, callback, user_data);
 
1612
        g_task_set_source_tag (task, camel_session_authenticate);
 
1613
        g_task_set_priority (task, io_priority);
 
1614
 
 
1615
        g_task_set_task_data (
 
1616
                task, async_context,
 
1617
                (GDestroyNotify) async_context_free);
 
1618
 
 
1619
        g_task_run_in_thread (task, session_authenticate_thread);
 
1620
 
 
1621
        g_object_unref (task);
1921
1622
}
1922
1623
 
1923
1624
/**
1940
1641
                                   GAsyncResult *result,
1941
1642
                                   GError **error)
1942
1643
{
 
1644
        g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
 
1645
        g_return_val_if_fail (g_task_is_valid (result, session), FALSE);
 
1646
 
 
1647
        g_return_val_if_fail (
 
1648
                g_async_result_is_tagged (
 
1649
                result, camel_session_authenticate), FALSE);
 
1650
 
 
1651
        return g_task_propagate_boolean (G_TASK (result), error);
 
1652
}
 
1653
 
 
1654
/**
 
1655
 * camel_session_forward_to_sync:
 
1656
 * @session: a #CamelSession
 
1657
 * @folder: the #CamelFolder where @message is located
 
1658
 * @message: the #CamelMimeMessage to forward
 
1659
 * @address: the recipient's email address
 
1660
 * @cancellable: optional #GCancellable object, or %NULL
 
1661
 * @error: return location for a #GError, or %NULL
 
1662
 *
 
1663
 * Forwards @message in @folder to the email address(es) given by @address.
 
1664
 *
 
1665
 * If an error occurs, the function sets @error and returns %FALSE.
 
1666
 *
 
1667
 * Returns: %TRUE on success, %FALSE on failure
 
1668
 *
 
1669
 * Since: 3.6
 
1670
 **/
 
1671
gboolean
 
1672
camel_session_forward_to_sync (CamelSession *session,
 
1673
                               CamelFolder *folder,
 
1674
                               CamelMimeMessage *message,
 
1675
                               const gchar *address,
 
1676
                               GCancellable *cancellable,
 
1677
                               GError **error)
 
1678
{
1943
1679
        CamelSessionClass *class;
 
1680
        gboolean success;
1944
1681
 
1945
1682
        g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
1946
 
        g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
 
1683
        g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
 
1684
        g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
 
1685
        g_return_val_if_fail (address != NULL, FALSE);
1947
1686
 
1948
1687
        class = CAMEL_SESSION_GET_CLASS (session);
1949
 
        g_return_val_if_fail (class->authenticate_finish != NULL, FALSE);
1950
 
 
1951
 
        return class->authenticate_finish (session, result, error);
 
1688
        g_return_val_if_fail (class->forward_to_sync != NULL, FALSE);
 
1689
 
 
1690
        success = class->forward_to_sync (
 
1691
                session, folder, message, address, cancellable, error);
 
1692
        CAMEL_CHECK_GERROR (session, forward_to_sync, success, error);
 
1693
 
 
1694
        return success;
 
1695
}
 
1696
 
 
1697
/* Helper for camel_session_forward_to() */
 
1698
static void
 
1699
session_forward_to_thread (GTask *task,
 
1700
                           gpointer source_object,
 
1701
                           gpointer task_data,
 
1702
                           GCancellable *cancellable)
 
1703
{
 
1704
        gboolean success;
 
1705
        AsyncContext *async_context;
 
1706
        GError *local_error = NULL;
 
1707
 
 
1708
        async_context = (AsyncContext *) task_data;
 
1709
 
 
1710
        success = camel_session_forward_to_sync (
 
1711
                CAMEL_SESSION (source_object),
 
1712
                async_context->folder,
 
1713
                async_context->message,
 
1714
                async_context->address,
 
1715
                cancellable, &local_error);
 
1716
 
 
1717
        if (local_error != NULL) {
 
1718
                g_task_return_error (task, local_error);
 
1719
        } else {
 
1720
                g_task_return_boolean (task, success);
 
1721
        }
1952
1722
}
1953
1723
 
1954
1724
/**
1981
1751
                          GAsyncReadyCallback callback,
1982
1752
                          gpointer user_data)
1983
1753
{
1984
 
        CamelSessionClass *class;
 
1754
        GTask *task;
 
1755
        AsyncContext *async_context;
1985
1756
 
1986
1757
        g_return_if_fail (CAMEL_IS_SESSION (session));
1987
1758
        g_return_if_fail (CAMEL_IS_FOLDER (folder));
1988
1759
        g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
1989
1760
        g_return_if_fail (address != NULL);
1990
1761
 
1991
 
        class = CAMEL_SESSION_GET_CLASS (session);
1992
 
        g_return_if_fail (class->forward_to != NULL);
1993
 
 
1994
 
        class->forward_to (
1995
 
                session, folder, message, address,
1996
 
                io_priority, cancellable, callback, user_data);
 
1762
        async_context = g_slice_new0 (AsyncContext);
 
1763
        async_context->folder = g_object_ref (folder);
 
1764
        async_context->message = g_object_ref (message);
 
1765
        async_context->address = g_strdup (address);
 
1766
 
 
1767
        task = g_task_new (session, cancellable, callback, user_data);
 
1768
        g_task_set_source_tag (task, camel_session_forward_to);
 
1769
        g_task_set_priority (task, io_priority);
 
1770
 
 
1771
        g_task_set_task_data (
 
1772
                task, async_context,
 
1773
                (GDestroyNotify) async_context_free);
 
1774
 
 
1775
        g_task_run_in_thread (task, session_forward_to_thread);
 
1776
 
 
1777
        g_object_unref (task);
1997
1778
}
1998
1779
 
1999
1780
/**
2015
1796
                                 GAsyncResult *result,
2016
1797
                                 GError **error)
2017
1798
{
2018
 
        CamelSessionClass *class;
2019
 
 
2020
1799
        g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
2021
 
        g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
2022
 
 
2023
 
        class = CAMEL_SESSION_GET_CLASS (session);
2024
 
        g_return_val_if_fail (class->forward_to_finish != NULL, FALSE);
2025
 
 
2026
 
        return class->forward_to_finish (session, result, error);
 
1800
        g_return_val_if_fail (g_task_is_valid (result, session), FALSE);
 
1801
 
 
1802
        g_return_val_if_fail (
 
1803
                g_async_result_is_tagged (
 
1804
                result, camel_session_forward_to), FALSE);
 
1805
 
 
1806
        return g_task_propagate_boolean (G_TASK (result), error);
2027
1807
}
2028
1808