10
10
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
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.
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
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
22
* along with this program; if not, see <http://www.gnu.org/licenses/>.
27
25
#ifdef HAVE_CONFIG_H
148
session_finish_job_cb (CamelSession *session,
149
GSimpleAsyncResult *simple)
165
session_finish_job_cb (GObject *source_object,
166
GAsyncResult *result,
152
GError *error = NULL;
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;
172
cancellable = g_task_get_cancellable (G_TASK (result));
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);
179
CAMEL_SESSION (source_object),
159
180
signals[JOB_FINISHED], 0,
160
job_data->cancellable, error);
181
cancellable, local_error);
162
g_clear_error (&error);
183
g_clear_error (&local_error);
166
session_do_job_cb (GSimpleAsyncResult *simple,
167
CamelSession *session,
187
session_do_job_cb (GTask *task,
188
gpointer source_object,
168
190
GCancellable *cancellable)
170
192
JobData *job_data;
171
GError *error = NULL;
193
GError *local_error = NULL;
173
job_data = g_simple_async_result_get_op_res_gpointer (simple);
195
job_data = (JobData *) task_data;
175
197
job_data->callback (
176
session, cancellable,
177
job_data->user_data, &error);
198
CAMEL_SESSION (source_object),
180
g_simple_async_result_take_error (simple, error);
203
if (local_error != NULL) {
204
g_task_return_error (task, local_error);
206
g_task_return_boolean (task, TRUE);
184
211
session_start_job_cb (gpointer user_data)
186
213
JobData *job_data = user_data;
187
GSimpleAsyncResult *simple;
190
217
job_data->session,
191
218
signals[JOB_STARTED], 0,
192
219
job_data->cancellable);
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);
199
g_simple_async_result_set_check_cancellable (
200
simple, job_data->cancellable);
202
g_simple_async_result_set_op_res_gpointer (
203
simple, job_data, (GDestroyNotify) job_data_free);
205
g_simple_async_result_run_in_thread (
206
simple, (GSimpleAsyncThreadFunc)
207
session_do_job_cb, JOB_PRIORITY,
208
job_data->cancellable);
210
g_object_unref (simple);
223
job_data->cancellable,
224
session_finish_job_cb, NULL);
226
g_task_set_task_data (
227
task, job_data, (GDestroyNotify) job_data_free);
229
g_task_run_in_thread (task, session_do_job_cb);
231
g_object_unref (task);
237
session_emit_user_alert_cb (gpointer user_data)
239
SignalClosure *signal_closure = user_data;
240
CamelSession *session;
242
session = g_weak_ref_get (&signal_closure->session);
244
if (session != NULL) {
247
signals[USER_ALERT], 0,
248
signal_closure->service,
249
signal_closure->alert_type,
250
signal_closure->alert_message);
251
g_object_unref (session);
254
return G_SOURCE_REMOVE;
216
258
session_set_user_data_dir (CamelSession *session,
217
259
const gchar *user_data_dir)
565
573
return (result == CAMEL_AUTHENTICATION_ACCEPTED);
569
session_authenticate_thread (GSimpleAsyncResult *simple,
571
GCancellable *cancellable)
573
AsyncContext *async_context;
574
GError *error = NULL;
576
async_context = g_simple_async_result_get_op_res_gpointer (simple);
578
camel_session_authenticate_sync (
579
CAMEL_SESSION (object),
580
async_context->service,
581
async_context->auth_mechanism,
582
cancellable, &error);
585
g_simple_async_result_take_error (simple, error);
589
session_authenticate (CamelSession *session,
590
CamelService *service,
591
const gchar *mechanism,
593
GCancellable *cancellable,
594
GAsyncReadyCallback callback,
597
GSimpleAsyncResult *simple;
598
AsyncContext *async_context;
600
async_context = g_slice_new0 (AsyncContext);
601
async_context->service = g_object_ref (service);
602
async_context->auth_mechanism = g_strdup (mechanism);
604
simple = g_simple_async_result_new (
605
G_OBJECT (session), callback, user_data, session_authenticate);
607
g_simple_async_result_set_check_cancellable (simple, cancellable);
609
g_simple_async_result_set_op_res_gpointer (
610
simple, async_context, (GDestroyNotify) async_context_free);
612
g_simple_async_result_run_in_thread (
613
simple, session_authenticate_thread, io_priority, cancellable);
615
g_object_unref (simple);
619
session_authenticate_finish (CamelSession *session,
620
GAsyncResult *result,
623
GSimpleAsyncResult *simple;
625
g_return_val_if_fail (
626
g_simple_async_result_is_valid (
627
result, G_OBJECT (session), session_authenticate), FALSE);
629
simple = G_SIMPLE_ASYNC_RESULT (result);
631
/* Assume success unless a GError is set. */
632
return !g_simple_async_result_propagate_error (simple, error);
636
577
session_forward_to_sync (CamelSession *session,
637
578
CamelFolder *folder,
651
session_forward_to_thread (GSimpleAsyncResult *simple,
653
GCancellable *cancellable)
655
AsyncContext *async_context;
656
GError *error = NULL;
658
async_context = g_simple_async_result_get_op_res_gpointer (simple);
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);
668
g_simple_async_result_take_error (simple, error);
672
session_forward_to (CamelSession *session,
674
CamelMimeMessage *message,
675
const gchar *address,
677
GCancellable *cancellable,
678
GAsyncReadyCallback callback,
681
GSimpleAsyncResult *simple;
682
AsyncContext *async_context;
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);
689
simple = g_simple_async_result_new (
690
G_OBJECT (session), callback, user_data, session_forward_to);
692
g_simple_async_result_set_check_cancellable (simple, cancellable);
694
g_simple_async_result_set_op_res_gpointer (
695
simple, async_context, (GDestroyNotify) async_context_free);
697
g_simple_async_result_run_in_thread (
698
simple, session_forward_to_thread, io_priority, cancellable);
700
g_object_unref (simple);
704
session_forward_to_finish (CamelSession *session,
705
GAsyncResult *result,
708
GSimpleAsyncResult *simple;
710
g_return_val_if_fail (
711
g_simple_async_result_is_valid (
712
result, G_OBJECT (session), session_forward_to), FALSE);
714
simple = G_SIMPLE_ASYNC_RESULT (result);
716
/* Assume success unless a GError is set. */
717
return !g_simple_async_result_propagate_error (simple, error);
721
592
camel_session_class_init (CamelSessionClass *class)
723
594
GObjectClass *object_class;
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
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.
1303
* Returns: Index of pressed button from @button_captions, -1 if NULL.
1306
camel_session_alert_user (CamelSession *session,
1307
CamelSessionAlertType type,
1308
const gchar *prompt,
1309
GList *button_captions,
1310
GCancellable *cancellable)
1312
CamelSessionClass *class;
1314
g_return_val_if_fail (CAMEL_IS_SESSION (session), -1);
1315
g_return_val_if_fail (prompt != NULL, -1);
1317
class = CAMEL_SESSION_GET_CLASS (session);
1318
g_return_val_if_fail (class->alert_user != NULL, -1);
1320
return class->alert_user (
1321
session, type, prompt, button_captions, cancellable);
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
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.
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
1140
* Prompts the user whether to accept @certificate for @service. The
1141
* set of flags given in @errors indicate why the @certificate failed
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
1148
* Returns: the user's trust level for @certificate
1345
1153
camel_session_trust_prompt (CamelSession *session,
1347
const gchar *certificate,
1348
guint32 certificate_errors,
1350
GCancellable *cancellable)
1154
CamelService *service,
1155
GTlsCertificate *certificate,
1156
GTlsCertificateFlags errors)
1352
1158
CamelSessionClass *class;
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);
1357
1167
class = CAMEL_SESSION_GET_CLASS (session);
1358
g_return_val_if_fail (class->trust_prompt != NULL, CAMEL_CERT_TRUST_UNKNOWN);
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);
1171
return class->trust_prompt (session, service, certificate, errors);
1175
* camel_session_user_alert:
1176
* @session: a #CamelSession
1177
* @service: a #CamelService
1178
* @type: a #CamelSessionAlertType
1179
* @message: the message for the user
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.
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
1191
camel_session_user_alert (CamelSession *session,
1192
CamelService *service,
1193
CamelSessionAlertType type,
1194
const gchar *message)
1196
SignalClosure *signal_closure;
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);
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);
1208
camel_session_idle_add (
1209
session, G_PRIORITY_LOW,
1210
session_emit_user_alert_cb,
1212
(GDestroyNotify) signal_closure_free);
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
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.
1393
* Returns: a newly-allocated password prompt string
1398
camel_session_build_password_prompt (const gchar *type,
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);
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);
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);
1423
g_free (user_markup);
1424
g_free (host_markup);
1430
1236
* camel_session_get_online:
1431
1237
* @session: a #CamelSession
1655
* camel_session_get_check_junk:
1656
* @session: a #CamelSession
1658
* Do we have to check incoming messages to be junk?
1660
* Returns: whether or not we are checking incoming messages for junk
1663
camel_session_get_check_junk (CamelSession *session)
1665
g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
1667
return session->priv->check_junk;
1671
* camel_session_set_check_junk:
1672
* @session: a #CamelSession
1673
* @check_junk: whether to check incoming messages for junk
1675
* Set check_junk flag, if set, incoming mail will be checked for being junk.
1678
camel_session_set_check_junk (CamelSession *session,
1679
gboolean check_junk)
1681
g_return_if_fail (CAMEL_IS_SESSION (session));
1683
session->priv->check_junk = check_junk;
1685
g_object_notify (G_OBJECT (session), "check-junk");
1689
* camel_session_get_network_available:
1690
* @session: a #CamelSession
1695
camel_session_get_network_available (CamelSession *session)
1697
g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
1699
return session->priv->network_available;
1703
* camel_session_set_network_available:
1704
* @session: a #CamelSession
1705
* @network_available: whether a network is available
1710
camel_session_set_network_available (CamelSession *session,
1711
gboolean network_available)
1713
g_return_if_fail (CAMEL_IS_SESSION (session));
1715
session->priv->network_available = network_available;
1717
g_object_notify (G_OBJECT (session), "network-available");
1721
1461
* camel_session_set_junk_headers:
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
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.
1774
camel_session_get_socks_proxy (CamelSession *session,
1775
const gchar *for_host,
1779
CamelSessionClass *class;
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);
1786
class = CAMEL_SESSION_GET_CLASS (session);
1787
g_return_if_fail (class->get_socks_proxy != NULL);
1789
class->get_socks_proxy (session, for_host, host_ret, port_ret);
1793
1501
* camel_session_authenticate_sync:
1794
1502
* @session: a #CamelSession
1795
1503
* @service: a #CamelService
1833
1541
return success;
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
1845
* Forwards @message in @folder to the email address(es) given by @address.
1847
* If an error occurs, the function sets @error and returns %FALSE.
1849
* Returns: %TRUE on success, %FALSE on failure
1854
camel_session_forward_to_sync (CamelSession *session,
1855
CamelFolder *folder,
1856
CamelMimeMessage *message,
1857
const gchar *address,
1858
GCancellable *cancellable,
1544
/* Helper for camel_session_authenticate() */
1546
session_authenticate_thread (GTask *task,
1547
gpointer source_object,
1549
GCancellable *cancellable)
1861
CamelSessionClass *class;
1862
1551
gboolean success;
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);
1869
class = CAMEL_SESSION_GET_CLASS (session);
1870
g_return_val_if_fail (class->forward_to_sync != NULL, FALSE);
1872
success = class->forward_to_sync (
1873
session, folder, message, address, cancellable, error);
1874
CAMEL_CHECK_GERROR (session, forward_to_sync, success, error);
1552
AsyncContext *async_context;
1553
GError *local_error = NULL;
1555
async_context = (AsyncContext *) task_data;
1557
success = camel_session_authenticate_sync (
1558
CAMEL_SESSION (source_object),
1559
async_context->service,
1560
async_context->auth_mechanism,
1561
cancellable, &local_error);
1563
if (local_error != NULL) {
1564
g_task_return_error (task, local_error);
1566
g_task_return_boolean (task, success);
1907
1598
GAsyncReadyCallback callback,
1908
1599
gpointer user_data)
1910
CamelSessionClass *class;
1602
AsyncContext *async_context;
1912
1604
g_return_if_fail (CAMEL_IS_SESSION (session));
1913
1605
g_return_if_fail (CAMEL_IS_SERVICE (service));
1915
class = CAMEL_SESSION_GET_CLASS (session);
1916
g_return_if_fail (class->authenticate != NULL);
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);
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);
1615
g_task_set_task_data (
1616
task, async_context,
1617
(GDestroyNotify) async_context_free);
1619
g_task_run_in_thread (task, session_authenticate_thread);
1621
g_object_unref (task);
1940
1641
GAsyncResult *result,
1941
1642
GError **error)
1644
g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
1645
g_return_val_if_fail (g_task_is_valid (result, session), FALSE);
1647
g_return_val_if_fail (
1648
g_async_result_is_tagged (
1649
result, camel_session_authenticate), FALSE);
1651
return g_task_propagate_boolean (G_TASK (result), error);
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
1663
* Forwards @message in @folder to the email address(es) given by @address.
1665
* If an error occurs, the function sets @error and returns %FALSE.
1667
* Returns: %TRUE on success, %FALSE on failure
1672
camel_session_forward_to_sync (CamelSession *session,
1673
CamelFolder *folder,
1674
CamelMimeMessage *message,
1675
const gchar *address,
1676
GCancellable *cancellable,
1943
1679
CamelSessionClass *class;
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);
1948
1687
class = CAMEL_SESSION_GET_CLASS (session);
1949
g_return_val_if_fail (class->authenticate_finish != NULL, FALSE);
1951
return class->authenticate_finish (session, result, error);
1688
g_return_val_if_fail (class->forward_to_sync != NULL, FALSE);
1690
success = class->forward_to_sync (
1691
session, folder, message, address, cancellable, error);
1692
CAMEL_CHECK_GERROR (session, forward_to_sync, success, error);
1697
/* Helper for camel_session_forward_to() */
1699
session_forward_to_thread (GTask *task,
1700
gpointer source_object,
1702
GCancellable *cancellable)
1705
AsyncContext *async_context;
1706
GError *local_error = NULL;
1708
async_context = (AsyncContext *) task_data;
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);
1717
if (local_error != NULL) {
1718
g_task_return_error (task, local_error);
1720
g_task_return_boolean (task, success);
1981
1751
GAsyncReadyCallback callback,
1982
1752
gpointer user_data)
1984
CamelSessionClass *class;
1755
AsyncContext *async_context;
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);
1991
class = CAMEL_SESSION_GET_CLASS (session);
1992
g_return_if_fail (class->forward_to != NULL);
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);
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);
1771
g_task_set_task_data (
1772
task, async_context,
1773
(GDestroyNotify) async_context_free);
1775
g_task_run_in_thread (task, session_forward_to_thread);
1777
g_object_unref (task);