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.
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.
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/>
20 * SECTION: e-source-smime
21 * @include: libedataserver/libedataserver.h
22 * @short_description: #ESource extension for S/MIME settings
24 * The #ESourceSMIME extension tracks Secure/Multipurpose Internet Mail
25 * Extensions (S/MIME) settings to be applied to outgoing mail messages.
27 * Access the extension as follows:
30 * #include <libedataserver/libedataserver.h>
32 * ESourceSMIME *extension;
34 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_SMIME);
38 #include "e-source-smime.h"
40 #include <libedataserver/e-data-server-util.h>
42 #define E_SOURCE_SMIME_GET_PRIVATE(obj) \
43 (G_TYPE_INSTANCE_GET_PRIVATE \
44 ((obj), E_TYPE_SOURCE_SMIME, ESourceSMIMEPrivate))
46 struct _ESourceSMIMEPrivate {
48 gchar *encryption_certificate;
49 gchar *signing_algorithm;
50 gchar *signing_certificate;
52 gboolean encrypt_by_default;
53 gboolean encrypt_to_self;
54 gboolean sign_by_default;
59 PROP_ENCRYPTION_CERTIFICATE,
60 PROP_ENCRYPT_BY_DEFAULT,
62 PROP_SIGNING_ALGORITHM,
63 PROP_SIGNING_CERTIFICATE,
70 E_TYPE_SOURCE_EXTENSION)
73 source_smime_set_property (GObject *object,
78 switch (property_id) {
79 case PROP_ENCRYPTION_CERTIFICATE:
80 e_source_smime_set_encryption_certificate (
81 E_SOURCE_SMIME (object),
82 g_value_get_string (value));
85 case PROP_ENCRYPT_BY_DEFAULT:
86 e_source_smime_set_encrypt_by_default (
87 E_SOURCE_SMIME (object),
88 g_value_get_boolean (value));
91 case PROP_ENCRYPT_TO_SELF:
92 e_source_smime_set_encrypt_to_self (
93 E_SOURCE_SMIME (object),
94 g_value_get_boolean (value));
97 case PROP_SIGNING_ALGORITHM:
98 e_source_smime_set_signing_algorithm (
99 E_SOURCE_SMIME (object),
100 g_value_get_string (value));
103 case PROP_SIGNING_CERTIFICATE:
104 e_source_smime_set_signing_certificate (
105 E_SOURCE_SMIME (object),
106 g_value_get_string (value));
109 case PROP_SIGN_BY_DEFAULT:
110 e_source_smime_set_sign_by_default (
111 E_SOURCE_SMIME (object),
112 g_value_get_boolean (value));
116 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
120 source_smime_get_property (GObject *object,
125 switch (property_id) {
126 case PROP_ENCRYPTION_CERTIFICATE:
127 g_value_take_string (
129 e_source_smime_dup_encryption_certificate (
130 E_SOURCE_SMIME (object)));
133 case PROP_ENCRYPT_BY_DEFAULT:
134 g_value_set_boolean (
136 e_source_smime_get_encrypt_by_default (
137 E_SOURCE_SMIME (object)));
140 case PROP_ENCRYPT_TO_SELF:
141 g_value_set_boolean (
143 e_source_smime_get_encrypt_to_self (
144 E_SOURCE_SMIME (object)));
147 case PROP_SIGNING_ALGORITHM:
148 g_value_take_string (
150 e_source_smime_dup_signing_algorithm (
151 E_SOURCE_SMIME (object)));
154 case PROP_SIGNING_CERTIFICATE:
155 g_value_take_string (
157 e_source_smime_dup_signing_certificate (
158 E_SOURCE_SMIME (object)));
161 case PROP_SIGN_BY_DEFAULT:
162 g_value_set_boolean (
164 e_source_smime_get_sign_by_default (
165 E_SOURCE_SMIME (object)));
169 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
173 source_smime_finalize (GObject *object)
175 ESourceSMIMEPrivate *priv;
177 priv = E_SOURCE_SMIME_GET_PRIVATE (object);
179 g_mutex_clear (&priv->property_lock);
181 g_free (priv->encryption_certificate);
182 g_free (priv->signing_algorithm);
183 g_free (priv->signing_certificate);
185 /* Chain up to parent's finalize() method. */
186 G_OBJECT_CLASS (e_source_smime_parent_class)->finalize (object);
190 e_source_smime_class_init (ESourceSMIMEClass *class)
192 GObjectClass *object_class;
193 ESourceExtensionClass *extension_class;
195 g_type_class_add_private (class, sizeof (ESourceSMIMEPrivate));
197 object_class = G_OBJECT_CLASS (class);
198 object_class->set_property = source_smime_set_property;
199 object_class->get_property = source_smime_get_property;
200 object_class->finalize = source_smime_finalize;
202 extension_class = E_SOURCE_EXTENSION_CLASS (class);
203 extension_class->name = E_SOURCE_EXTENSION_SMIME;
205 g_object_class_install_property (
207 PROP_ENCRYPTION_CERTIFICATE,
208 g_param_spec_string (
209 "encryption-certificate",
210 "Encryption Certificate",
211 "S/MIME certificate for encrypting messages",
215 G_PARAM_STATIC_STRINGS |
216 E_SOURCE_PARAM_SETTING));
218 g_object_class_install_property (
220 PROP_ENCRYPT_BY_DEFAULT,
221 g_param_spec_boolean (
222 "encrypt-by-default",
223 "Encrypt By Default",
224 "Encrypt outgoing messages by default",
228 G_PARAM_STATIC_STRINGS |
229 E_SOURCE_PARAM_SETTING));
231 g_object_class_install_property (
233 PROP_ENCRYPT_TO_SELF,
234 g_param_spec_boolean (
237 "Always encrypt to myself",
241 G_PARAM_STATIC_STRINGS |
242 E_SOURCE_PARAM_SETTING));
244 g_object_class_install_property (
246 PROP_SIGNING_ALGORITHM,
247 g_param_spec_string (
250 "Hash algorithm used to sign messages",
254 G_PARAM_STATIC_STRINGS |
255 E_SOURCE_PARAM_SETTING));
257 g_object_class_install_property (
259 PROP_SIGNING_CERTIFICATE,
260 g_param_spec_string (
261 "signing-certificate",
262 "Signing Certificate",
263 "S/MIME certificate for signing messages",
267 G_PARAM_STATIC_STRINGS |
268 E_SOURCE_PARAM_SETTING));
270 g_object_class_install_property (
272 PROP_SIGN_BY_DEFAULT,
273 g_param_spec_boolean (
276 "Sign outgoing messages by default",
280 G_PARAM_STATIC_STRINGS |
281 E_SOURCE_PARAM_SETTING));
285 e_source_smime_init (ESourceSMIME *extension)
287 extension->priv = E_SOURCE_SMIME_GET_PRIVATE (extension);
288 g_mutex_init (&extension->priv->property_lock);
292 * e_source_smime_get_encryption_certificate:
293 * @extension: an #ESourceSMIME
295 * Returns the S/MIME certificate name used to encrypt messages.
297 * Returns: the certificate name used to encrypt messages
302 e_source_smime_get_encryption_certificate (ESourceSMIME *extension)
304 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), NULL);
306 return extension->priv->encryption_certificate;
310 * e_source_smime_dup_encryption_certificate:
311 * @extension: an #ESourceSMIME
313 * Thread-safe variation of e_source_smime_get_encryption_certificate().
314 * Use this function when accessing @extension from multiple threads.
316 * The returned string should be freed with g_free() when no longer needed.
318 * Returns: a newly-allocated copy of #ESourceSMIME:encryption-certificate
323 e_source_smime_dup_encryption_certificate (ESourceSMIME *extension)
325 const gchar *protected;
328 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), NULL);
330 g_mutex_lock (&extension->priv->property_lock);
332 protected = e_source_smime_get_encryption_certificate (extension);
333 duplicate = g_strdup (protected);
335 g_mutex_unlock (&extension->priv->property_lock);
341 * e_source_smime_set_encryption_certificate:
342 * @extension: an #ESourceSMIME
343 * @encryption_certificate: (allow-none): the certificate name used to encrypt
346 * Sets the certificate name used to encrypt messages.
348 * The internal copy of @encryption_certificate is automatically stripped
349 * of leading and trailing whitespace. If the resulting string is empty,
350 * %NULL is set instead.
355 e_source_smime_set_encryption_certificate (ESourceSMIME *extension,
356 const gchar *encryption_certificate)
358 g_return_if_fail (E_IS_SOURCE_SMIME (extension));
360 g_mutex_lock (&extension->priv->property_lock);
363 extension->priv->encryption_certificate,
364 encryption_certificate) == 0) {
365 g_mutex_unlock (&extension->priv->property_lock);
369 g_free (extension->priv->encryption_certificate);
370 extension->priv->encryption_certificate =
371 e_util_strdup_strip (encryption_certificate);
373 g_mutex_unlock (&extension->priv->property_lock);
375 g_object_notify (G_OBJECT (extension), "encryption-certificate");
379 * e_source_smime_get_encrypt_by_default:
380 * @extension: an #ESourceSMIME
382 * Returns whether to encrypt outgoing messages by default using S/MIME
383 * software such as Mozilla Network Security Services (NSS).
385 * Returns: whether to encrypt outgoing messages by default
390 e_source_smime_get_encrypt_by_default (ESourceSMIME *extension)
392 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), FALSE);
394 return extension->priv->encrypt_by_default;
398 * e_source_smime_set_encrypt_by_default:
399 * @extension: an #ESourceSMIME
400 * @encrypt_by_default: whether to encrypt outgoing messages by default
402 * Sets whether to encrypt outgoing messages by default using S/MIME
403 * software such as Mozilla Network Security Services (NSS).
408 e_source_smime_set_encrypt_by_default (ESourceSMIME *extension,
409 gboolean encrypt_by_default)
411 g_return_if_fail (E_IS_SOURCE_SMIME (extension));
413 if (extension->priv->encrypt_by_default == encrypt_by_default)
416 extension->priv->encrypt_by_default = encrypt_by_default;
418 g_object_notify (G_OBJECT (extension), "encrypt-by-default");
422 * e_source_smime_get_encrypt_to_self:
423 * @extension: an #ESourceSMIME
425 * Returns whether to "encrypt-to-self" when sending encrypted messages.
427 * Returns: whether to "encrypt-to-self"
432 e_source_smime_get_encrypt_to_self (ESourceSMIME *extension)
434 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), FALSE);
436 return extension->priv->encrypt_to_self;
440 * e_source_smime_set_encrypt_to_self:
441 * @extension: an #ESourceSMIME
442 * @encrypt_to_self: whether to "encrypt-to-self"
444 * Sets whether to "encrypt-to-self" when sending encrypted messages.
449 e_source_smime_set_encrypt_to_self (ESourceSMIME *extension,
450 gboolean encrypt_to_self)
452 g_return_if_fail (E_IS_SOURCE_SMIME (extension));
454 if (extension->priv->encrypt_to_self == encrypt_to_self)
457 extension->priv->encrypt_to_self = encrypt_to_self;
459 g_object_notify (G_OBJECT (extension), "encrypt-to-self");
463 * e_source_smime_get_signing_algorithm:
464 * @extension: an #ESourceSMIME
466 * Returns the name of the hash algorithm used to digitally sign outgoing
469 * Returns: the signing algorithm for outgoing messages
474 e_source_smime_get_signing_algorithm (ESourceSMIME *extension)
476 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), NULL);
478 return extension->priv->signing_algorithm;
482 * e_source_smime_dup_signing_algorithm:
483 * @extension: an #ESourceSMIME
485 * Thread-safe variation of e_source_smime_get_signing_algorithm().
486 * Use this function when accessing @extension from multiple threads.
488 * The returned string should be freed with g_free() when no longer needed.
490 * Returns: a newly-allocated copy of #ESourceSMIME:signing-algorithm
495 e_source_smime_dup_signing_algorithm (ESourceSMIME *extension)
497 const gchar *protected;
500 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), NULL);
502 g_mutex_lock (&extension->priv->property_lock);
504 protected = e_source_smime_get_signing_algorithm (extension);
505 duplicate = g_strdup (protected);
507 g_mutex_unlock (&extension->priv->property_lock);
513 * e_source_smime_set_signing_algorithm:
514 * @extension: an #ESourceSMIME
515 * @signing_algorithm: (allow-none): the signing algorithm for outgoing
518 * Sets the name of the hash algorithm used to digitally sign outgoing
521 * The internal copy of @signing_algorithm is automatically stripped of
522 * leading and trailing whitespace. If the resulting string is empty,
523 * %NULL is set instead.
528 e_source_smime_set_signing_algorithm (ESourceSMIME *extension,
529 const gchar *signing_algorithm)
531 g_return_if_fail (E_IS_SOURCE_SMIME (extension));
533 g_mutex_lock (&extension->priv->property_lock);
535 if (g_strcmp0 (extension->priv->signing_algorithm, signing_algorithm) == 0) {
536 g_mutex_unlock (&extension->priv->property_lock);
540 g_free (extension->priv->signing_algorithm);
541 extension->priv->signing_algorithm =
542 e_util_strdup_strip (signing_algorithm);
544 g_mutex_unlock (&extension->priv->property_lock);
546 g_object_notify (G_OBJECT (extension), "signing-algorithm");
550 * e_source_smime_get_signing_certificate:
551 * @extension: an #ESourceSMIME
553 * Returns the S/MIME certificate name used to sign messages.
555 * Returns: the certificate name used to sign messages
560 e_source_smime_get_signing_certificate (ESourceSMIME *extension)
562 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), NULL);
564 return extension->priv->signing_certificate;
568 * e_source_smime_dup_signing_certificate:
569 * @extension: an #ESourceSMIME
571 * Thread-safe variation of e_source_smime_get_signing_certificate().
572 * Use this function when accessing @extension from multiple threads.
574 * The returned string should be freed with g_free() when no longer needed.
576 * Returns: a newly-allocated copy of #ESourceSMIME:signing-certificate
581 e_source_smime_dup_signing_certificate (ESourceSMIME *extension)
583 const gchar *protected;
586 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), NULL);
588 g_mutex_lock (&extension->priv->property_lock);
590 protected = e_source_smime_get_signing_certificate (extension);
591 duplicate = g_strdup (protected);
593 g_mutex_unlock (&extension->priv->property_lock);
599 * e_source_smime_set_signing_certificate:
600 * @extension: an #ESourceSMIME
601 * @signing_certificate: (allow-none): the certificate name used to sign
604 * Sets the S/MIME certificate name used to sign messages.
606 * The internal copy of @signing_certificate is automatically stripped
607 * of leading and trailing whitespace. If the resulting string is empty,
608 * %NULL is set instead.
613 e_source_smime_set_signing_certificate (ESourceSMIME *extension,
614 const gchar *signing_certificate)
616 g_return_if_fail (E_IS_SOURCE_SMIME (extension));
618 g_mutex_lock (&extension->priv->property_lock);
620 if (g_strcmp0 (extension->priv->signing_certificate, signing_certificate) == 0) {
621 g_mutex_unlock (&extension->priv->property_lock);
625 g_free (extension->priv->signing_certificate);
626 extension->priv->signing_certificate =
627 e_util_strdup_strip (signing_certificate);
629 g_mutex_unlock (&extension->priv->property_lock);
631 g_object_notify (G_OBJECT (extension), "signing-certificate");
635 * e_source_smime_get_sign_by_default:
636 * @extension: an #ESourceSMIME
638 * Returns whether to digitally sign outgoing messages by default using
639 * S/MIME software such as Mozilla Network Security Services (NSS).
641 * Returns: whether to sign outgoing messages by default
646 e_source_smime_get_sign_by_default (ESourceSMIME *extension)
648 g_return_val_if_fail (E_IS_SOURCE_SMIME (extension), FALSE);
650 return extension->priv->sign_by_default;
654 * e_source_smime_set_sign_by_default:
655 * @extension: an #ESourceSMIME
656 * @sign_by_default: whether to sign outgoing messages by default
658 * Sets whether to digitally sign outgoing messages by default using
659 * S/MIME software such as Mozilla Network Security Services (NSS).
664 e_source_smime_set_sign_by_default (ESourceSMIME *extension,
665 gboolean sign_by_default)
667 g_return_if_fail (E_IS_SOURCE_SMIME (extension));
669 if (extension->priv->sign_by_default == sign_by_default)
672 extension->priv->sign_by_default = sign_by_default;
674 g_object_notify (G_OBJECT (extension), "sign-by-default");