2 * e-source-mail-composition.c
4 * This library is free software you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * SECTION: e-source-mail-composition
20 * @include: libedataserver/libedataserver.h
21 * @short_description: #ESource extension for mail composition settings
23 * The #ESourceMailComposition extension tracks settings to be applied
24 * when composing a new mail message.
26 * Access the extension as follows:
29 * #include <libedataserver/libedataserver.h>
31 * ESourceMailComposition *extension;
33 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_COMPOSITION);
37 #include "e-source-mail-composition.h"
39 #include <libedataserver/e-data-server-util.h>
41 #define E_SOURCE_MAIL_COMPOSITION_GET_PRIVATE(obj) \
42 (G_TYPE_INSTANCE_GET_PRIVATE \
43 ((obj), E_TYPE_SOURCE_MAIL_COMPOSITION, ESourceMailCompositionPrivate))
45 struct _ESourceMailCompositionPrivate {
50 gchar *templates_folder;
64 ESourceMailComposition,
65 e_source_mail_composition,
66 E_TYPE_SOURCE_EXTENSION)
69 source_mail_composition_set_property (GObject *object,
74 switch (property_id) {
76 e_source_mail_composition_set_bcc (
77 E_SOURCE_MAIL_COMPOSITION (object),
78 g_value_get_boxed (value));
82 e_source_mail_composition_set_cc (
83 E_SOURCE_MAIL_COMPOSITION (object),
84 g_value_get_boxed (value));
87 case PROP_DRAFTS_FOLDER:
88 e_source_mail_composition_set_drafts_folder (
89 E_SOURCE_MAIL_COMPOSITION (object),
90 g_value_get_string (value));
94 e_source_mail_composition_set_sign_imip (
95 E_SOURCE_MAIL_COMPOSITION (object),
96 g_value_get_boolean (value));
99 case PROP_TEMPLATES_FOLDER:
100 e_source_mail_composition_set_templates_folder (
101 E_SOURCE_MAIL_COMPOSITION (object),
102 g_value_get_string (value));
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
110 source_mail_composition_get_property (GObject *object,
115 switch (property_id) {
119 e_source_mail_composition_dup_bcc (
120 E_SOURCE_MAIL_COMPOSITION (object)));
126 e_source_mail_composition_dup_cc (
127 E_SOURCE_MAIL_COMPOSITION (object)));
130 case PROP_DRAFTS_FOLDER:
131 g_value_take_string (
133 e_source_mail_composition_dup_drafts_folder (
134 E_SOURCE_MAIL_COMPOSITION (object)));
138 g_value_set_boolean (
140 e_source_mail_composition_get_sign_imip (
141 E_SOURCE_MAIL_COMPOSITION (object)));
144 case PROP_TEMPLATES_FOLDER:
145 g_value_take_string (
147 e_source_mail_composition_dup_templates_folder (
148 E_SOURCE_MAIL_COMPOSITION (object)));
152 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
156 source_mail_composition_finalize (GObject *object)
158 ESourceMailCompositionPrivate *priv;
160 priv = E_SOURCE_MAIL_COMPOSITION_GET_PRIVATE (object);
162 g_mutex_clear (&priv->property_lock);
164 g_strfreev (priv->bcc);
165 g_strfreev (priv->cc);
166 g_free (priv->drafts_folder);
167 g_free (priv->templates_folder);
169 /* Chain up to parent's finalize() method. */
170 G_OBJECT_CLASS (e_source_mail_composition_parent_class)->
175 e_source_mail_composition_class_init (ESourceMailCompositionClass *class)
177 GObjectClass *object_class;
178 ESourceExtensionClass *extension_class;
180 g_type_class_add_private (
181 class, sizeof (ESourceMailCompositionPrivate));
183 object_class = G_OBJECT_CLASS (class);
184 object_class->set_property = source_mail_composition_set_property;
185 object_class->get_property = source_mail_composition_get_property;
186 object_class->finalize = source_mail_composition_finalize;
188 extension_class = E_SOURCE_EXTENSION_CLASS (class);
189 extension_class->name = E_SOURCE_EXTENSION_MAIL_COMPOSITION;
191 g_object_class_install_property (
197 "Recipients to blind carbon-copy",
201 G_PARAM_STATIC_STRINGS |
202 E_SOURCE_PARAM_SETTING));
204 g_object_class_install_property (
210 "Recipients to carbon-copy",
214 G_PARAM_STATIC_STRINGS |
215 E_SOURCE_PARAM_SETTING));
217 g_object_class_install_property (
220 g_param_spec_string (
223 "Preferred folder for draft messages",
227 G_PARAM_STATIC_STRINGS |
228 E_SOURCE_PARAM_SETTING));
230 g_object_class_install_property (
233 g_param_spec_boolean (
236 "Include iMIP messages when signing",
240 G_PARAM_STATIC_STRINGS |
241 E_SOURCE_PARAM_SETTING));
243 g_object_class_install_property (
245 PROP_TEMPLATES_FOLDER,
246 g_param_spec_string (
249 "Preferred folder for message templates",
253 G_PARAM_STATIC_STRINGS |
254 E_SOURCE_PARAM_SETTING));
258 e_source_mail_composition_init (ESourceMailComposition *extension)
260 extension->priv = E_SOURCE_MAIL_COMPOSITION_GET_PRIVATE (extension);
261 g_mutex_init (&extension->priv->property_lock);
265 * e_source_mail_composition_get_bcc:
266 * @extension: an #ESourceMailComposition
268 * Returns a %NULL-terminated string array of recipients which should
269 * automatically be added to the blind carbon-copy (Bcc) list when
270 * composing a new mail message. The recipient strings should be of
271 * the form "Full Name <email-address>". The returned array is
272 * owned by @extension and should not be modified or freed.
274 * Returns: (transfer none): a %NULL-terminated string array of Bcc recipients
278 const gchar * const *
279 e_source_mail_composition_get_bcc (ESourceMailComposition *extension)
281 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
283 return (const gchar * const *) extension->priv->bcc;
287 * e_source_mail_composition_dup_bcc:
288 * @extension: an #ESourceMailComposition
290 * Thread-safe variation of e_source_mail_composition_get_bcc().
291 * Use this function when accessing @extension from multiple threads.
293 * The returned string array should be freed with g_strfreev() when no
296 * Returns: (transfer full): a newly-allocated copy of
297 * #ESourceMailComposition:bcc
302 e_source_mail_composition_dup_bcc (ESourceMailComposition *extension)
304 const gchar * const *protected;
307 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
309 g_mutex_lock (&extension->priv->property_lock);
311 protected = e_source_mail_composition_get_bcc (extension);
312 duplicate = g_strdupv ((gchar **) protected);
314 g_mutex_unlock (&extension->priv->property_lock);
320 * e_source_mail_composition_set_bcc:
321 * @extension: an #ESource
322 * @bcc: (allow-none): a %NULL-terminated string array of Bcc recipients
324 * Sets the recipients which should automatically be added to the blind
325 * carbon-copy (Bcc) list when composing a new mail message. The recipient
326 * strings should be of the form "Full Name <email-address>".
331 e_source_mail_composition_set_bcc (ESourceMailComposition *extension,
332 const gchar * const *bcc)
334 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
336 g_mutex_lock (&extension->priv->property_lock);
338 if (e_util_strv_equal (bcc, extension->priv->bcc)) {
339 g_mutex_unlock (&extension->priv->property_lock);
343 g_strfreev (extension->priv->bcc);
344 extension->priv->bcc = g_strdupv ((gchar **) bcc);
346 g_mutex_unlock (&extension->priv->property_lock);
348 g_object_notify (G_OBJECT (extension), "bcc");
352 * e_source_mail_composition_get_cc:
353 * @extension: an #ESourceMailComposition
355 * Returns a %NULL-terminated string array of recipients which should
356 * automatically be added to the carbon-copy (Cc) list when composing a
357 * new mail message. The recipient strings should be of the form "Full
358 * Name <email-address>". The returned array is owned by @extension and
359 * should not be modified or freed.
361 * Returns: (transfer none): a %NULL-terminated string array of Cc recipients
365 const gchar * const *
366 e_source_mail_composition_get_cc (ESourceMailComposition *extension)
368 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
370 return (const gchar * const *) extension->priv->cc;
374 * e_source_mail_composition_dup_cc:
375 * @extension: an #ESourceMailComposition
377 * Thread-safe variation of e_source_mail_composition_get_cc().
378 * Use this function when accessing @extension from multiple threads.
380 * The returned string array should be freed with g_strfreev() when no
383 * Returns: (transfer full): a newly-allocated copy of
384 * #ESourceMailComposition:cc
389 e_source_mail_composition_dup_cc (ESourceMailComposition *extension)
391 const gchar * const *protected;
394 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
396 g_mutex_lock (&extension->priv->property_lock);
398 protected = e_source_mail_composition_get_cc (extension);
399 duplicate = g_strdupv ((gchar **) protected);
401 g_mutex_unlock (&extension->priv->property_lock);
407 * e_source_mail_composition_set_cc:
408 * @extension: an #ESourceMailComposition
409 * @cc: (allow-none): a %NULL-terminated string array of Cc recipients
411 * Sets the recipients which should automatically be added to the carbon
412 * copy (Cc) list when composing a new mail message. The recipient strings
413 * should be of the form "Full Name <email-address>".
418 e_source_mail_composition_set_cc (ESourceMailComposition *extension,
419 const gchar * const *cc)
421 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
423 g_mutex_lock (&extension->priv->property_lock);
425 if (e_util_strv_equal (cc, extension->priv->cc)) {
426 g_mutex_unlock (&extension->priv->property_lock);
430 g_strfreev (extension->priv->cc);
431 extension->priv->cc = g_strdupv ((gchar **) cc);
433 g_mutex_unlock (&extension->priv->property_lock);
435 g_object_notify (G_OBJECT (extension), "cc");
439 * e_source_mail_composition_get_drafts_folder:
440 * @extension: an #ESourceMailComposition
442 * Returns a string identifying the preferred folder for draft messages.
443 * The format of the identifier string is defined by the client application.
445 * Returns: an identifier for the preferred drafts folder
450 e_source_mail_composition_get_drafts_folder (ESourceMailComposition *extension)
452 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
454 return extension->priv->drafts_folder;
458 * e_source_mail_composition_dup_drafts_folder:
459 * @extension: an #ESourceMailComposition
461 * Thread-safe variation of e_source_mail_composition_get_drafts_folder().
462 * Use this function when accessing @extension from multiple threads.
464 * The returned string should be freed with g_free() when no longer needed.
466 * Returns: a newly-allocated copy of #ESourceMailComposition:drafts-folder
471 e_source_mail_composition_dup_drafts_folder (ESourceMailComposition *extension)
473 const gchar *protected;
476 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
478 g_mutex_lock (&extension->priv->property_lock);
480 protected = e_source_mail_composition_get_drafts_folder (extension);
481 duplicate = g_strdup (protected);
483 g_mutex_unlock (&extension->priv->property_lock);
489 * e_source_mail_composition_set_drafts_folder:
490 * @extension: an #ESourceMailComposition
491 * @drafts_folder: (allow-none): an identifier for the preferred drafts
494 * Sets the preferred folder for draft messages by an identifier string.
495 * The format of the identifier string is defined by the client application.
497 * The internal copy of @drafts_folder is automatically stripped of
498 * leading and trailing whitespace. If the resulting string is empty,
499 * %NULL is set instead.
504 e_source_mail_composition_set_drafts_folder (ESourceMailComposition *extension,
505 const gchar *drafts_folder)
507 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
509 g_mutex_lock (&extension->priv->property_lock);
511 if (g_strcmp0 (extension->priv->drafts_folder, drafts_folder) == 0) {
512 g_mutex_unlock (&extension->priv->property_lock);
516 g_free (extension->priv->drafts_folder);
517 extension->priv->drafts_folder = e_util_strdup_strip (drafts_folder);
519 g_mutex_unlock (&extension->priv->property_lock);
521 g_object_notify (G_OBJECT (extension), "drafts-folder");
525 * e_source_mail_composition_get_sign_imip:
526 * @extension: an #ESourceMailComposition
528 * Returns whether outgoing iMIP messages such as meeting requests should
529 * also be signed. This is primarily intended as a workaround for certain
530 * versions of Microsoft Outlook which can't handle signed iMIP messages.
532 * Returns: whether outgoing iMIP messages should be signed
537 e_source_mail_composition_get_sign_imip (ESourceMailComposition *extension)
539 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), FALSE);
541 return extension->priv->sign_imip;
545 * e_source_mail_composition_set_sign_imip:
546 * @extension: an #ESourceMailComposition
547 * @sign_imip: whether outgoing iMIP messages should be signed
549 * Sets whether outgoing iMIP messages such as meeting requests should
550 * also be signed. This is primarily intended as a workaround for certain
551 * versions of Microsoft Outlook which can't handle signed iMIP messages.
556 e_source_mail_composition_set_sign_imip (ESourceMailComposition *extension,
559 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
561 if (extension->priv->sign_imip == sign_imip)
564 extension->priv->sign_imip = sign_imip;
566 g_object_notify (G_OBJECT (extension), "sign-imip");
570 * e_source_mail_composition_get_templates_folder:
571 * @extension: an #ESourceMailComposition
573 * Returns a string identifying the preferred folder for message templates.
574 * The format of the identifier string is defined by the client application.
576 * Returns: an identifier for the preferred templates folder
581 e_source_mail_composition_get_templates_folder (ESourceMailComposition *extension)
583 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
585 return extension->priv->templates_folder;
589 * e_source_mail_composition_dup_templates_folder:
590 * @extension: an #ESourceMailComposition
592 * Thread-safe variation of e_source_mail_composition_get_templates_folder().
593 * Use this function when accessing @extension from multiple threads.
595 * The returned string should be freed with g_free() when no longer needed.
597 * Returns: a newly-allocated copy of #ESourceMailComposition:templates-folder
602 e_source_mail_composition_dup_templates_folder (ESourceMailComposition *extension)
604 const gchar *protected;
607 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
609 g_mutex_lock (&extension->priv->property_lock);
611 protected = e_source_mail_composition_get_templates_folder (extension);
612 duplicate = g_strdup (protected);
614 g_mutex_unlock (&extension->priv->property_lock);
620 * e_source_mail_composition_set_templates_folder:
621 * @extension: an #ESourceMailComposition
622 * @templates_folder: (allow-none): an identifier for the preferred templates
625 * Sets the preferred folder for message templates by an identifier string.
626 * The format of the identifier string is defined by the client application.
628 * The internal copy of @templates_folder is automatically stripped of
629 * leading and trailing whitespace. If the resulting string is empty,
630 * %NULL is set instead.
635 e_source_mail_composition_set_templates_folder (ESourceMailComposition *extension,
636 const gchar *templates_folder)
638 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
640 g_mutex_lock (&extension->priv->property_lock);
642 if (g_strcmp0 (extension->priv->templates_folder, templates_folder) == 0) {
643 g_mutex_unlock (&extension->priv->property_lock);
647 g_free (extension->priv->templates_folder);
648 extension->priv->templates_folder = e_util_strdup_strip (templates_folder);
650 g_mutex_unlock (&extension->priv->property_lock);
652 g_object_notify (G_OBJECT (extension), "templates-folder");