2 * e-source-mail-composition.c
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-mail-composition
21 * @include: libedataserver/e-source-mail-composition.h
22 * @short_description: #ESource extension for mail composition settings
24 * The #ESourceMailComposition extension tracks settings to be applied
25 * when composing a new mail message.
27 * Access the extension as follows:
30 * #include <libedataserver/e-source-mail-composition.h>
32 * ESourceMailComposition *extension;
34 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_COMPOSITION);
38 #include "e-source-mail-composition.h"
40 #include <libedataserver/e-data-server-util.h>
42 #define E_SOURCE_MAIL_COMPOSITION_GET_PRIVATE(obj) \
43 (G_TYPE_INSTANCE_GET_PRIVATE \
44 ((obj), E_TYPE_SOURCE_MAIL_COMPOSITION, ESourceMailCompositionPrivate))
46 struct _ESourceMailCompositionPrivate {
47 GMutex *property_lock;
51 gchar *templates_folder;
65 ESourceMailComposition,
66 e_source_mail_composition,
67 E_TYPE_SOURCE_EXTENSION)
70 source_mail_composition_set_property (GObject *object,
75 switch (property_id) {
77 e_source_mail_composition_set_bcc (
78 E_SOURCE_MAIL_COMPOSITION (object),
79 g_value_get_boxed (value));
83 e_source_mail_composition_set_cc (
84 E_SOURCE_MAIL_COMPOSITION (object),
85 g_value_get_boxed (value));
88 case PROP_DRAFTS_FOLDER:
89 e_source_mail_composition_set_drafts_folder (
90 E_SOURCE_MAIL_COMPOSITION (object),
91 g_value_get_string (value));
95 e_source_mail_composition_set_sign_imip (
96 E_SOURCE_MAIL_COMPOSITION (object),
97 g_value_get_boolean (value));
100 case PROP_TEMPLATES_FOLDER:
101 e_source_mail_composition_set_templates_folder (
102 E_SOURCE_MAIL_COMPOSITION (object),
103 g_value_get_string (value));
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
111 source_mail_composition_get_property (GObject *object,
116 switch (property_id) {
120 e_source_mail_composition_dup_bcc (
121 E_SOURCE_MAIL_COMPOSITION (object)));
127 e_source_mail_composition_dup_cc (
128 E_SOURCE_MAIL_COMPOSITION (object)));
131 case PROP_DRAFTS_FOLDER:
132 g_value_take_string (
134 e_source_mail_composition_dup_drafts_folder (
135 E_SOURCE_MAIL_COMPOSITION (object)));
139 g_value_set_boolean (
141 e_source_mail_composition_get_sign_imip (
142 E_SOURCE_MAIL_COMPOSITION (object)));
145 case PROP_TEMPLATES_FOLDER:
146 g_value_take_string (
148 e_source_mail_composition_dup_templates_folder (
149 E_SOURCE_MAIL_COMPOSITION (object)));
153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
157 source_mail_composition_finalize (GObject *object)
159 ESourceMailCompositionPrivate *priv;
161 priv = E_SOURCE_MAIL_COMPOSITION_GET_PRIVATE (object);
163 g_mutex_free (priv->property_lock);
165 g_strfreev (priv->bcc);
166 g_strfreev (priv->cc);
167 g_free (priv->drafts_folder);
168 g_free (priv->templates_folder);
170 /* Chain up to parent's finalize() method. */
171 G_OBJECT_CLASS (e_source_mail_composition_parent_class)->
176 e_source_mail_composition_class_init (ESourceMailCompositionClass *class)
178 GObjectClass *object_class;
179 ESourceExtensionClass *extension_class;
181 g_type_class_add_private (
182 class, sizeof (ESourceMailCompositionPrivate));
184 object_class = G_OBJECT_CLASS (class);
185 object_class->set_property = source_mail_composition_set_property;
186 object_class->get_property = source_mail_composition_get_property;
187 object_class->finalize = source_mail_composition_finalize;
189 extension_class = E_SOURCE_EXTENSION_CLASS (class);
190 extension_class->name = E_SOURCE_EXTENSION_MAIL_COMPOSITION;
192 g_object_class_install_property (
198 "Recipients to blind carbon-copy",
202 G_PARAM_STATIC_STRINGS |
203 E_SOURCE_PARAM_SETTING));
205 g_object_class_install_property (
211 "Recipients to carbon-copy",
215 G_PARAM_STATIC_STRINGS |
216 E_SOURCE_PARAM_SETTING));
218 g_object_class_install_property (
221 g_param_spec_string (
224 "Preferred folder for draft messages",
228 G_PARAM_STATIC_STRINGS |
229 E_SOURCE_PARAM_SETTING));
231 g_object_class_install_property (
234 g_param_spec_boolean (
237 "Include iMIP messages when signing",
241 G_PARAM_STATIC_STRINGS |
242 E_SOURCE_PARAM_SETTING));
244 g_object_class_install_property (
246 PROP_TEMPLATES_FOLDER,
247 g_param_spec_string (
250 "Preferred folder for message templates",
254 G_PARAM_STATIC_STRINGS |
255 E_SOURCE_PARAM_SETTING));
259 e_source_mail_composition_init (ESourceMailComposition *extension)
261 extension->priv = E_SOURCE_MAIL_COMPOSITION_GET_PRIVATE (extension);
262 extension->priv->property_lock = g_mutex_new ();
266 * e_source_mail_composition_get_bcc:
267 * @extension: an #ESourceMailComposition
269 * Returns a %NULL-terminated string array of recipients which should
270 * automatically be added to the blind carbon-copy (Bcc) list when
271 * composing a new mail message. The recipient strings should be of
272 * the form "Full Name <email-address>". The returned array is owned
273 * by @extension and should not be modified or freed.
275 * Returns: a %NULL-terminated string array of Bcc recipients
279 const gchar * const *
280 e_source_mail_composition_get_bcc (ESourceMailComposition *extension)
282 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
284 return (const gchar * const *) extension->priv->bcc;
288 * e_source_mail_composition_dup_bcc:
289 * @extension: an #ESourceMailComposition
291 * Thread-safe variation of e_source_mail_composition_get_bcc().
292 * Use this function when accessing @extension from multiple threads.
294 * The returned string array should be freed with g_strfreev() when no
297 * Returns: a newly-allocated copy of #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 g_strfreev (extension->priv->bcc);
339 extension->priv->bcc = g_strdupv ((gchar **) bcc);
341 g_mutex_unlock (extension->priv->property_lock);
343 g_object_notify (G_OBJECT (extension), "bcc");
347 * e_source_mail_composition_get_cc:
348 * @extension: an #ESourceMailComposition
350 * Returns a %NULL-terminated string array of recipients which should
351 * automatically be added to the carbon-copy (Cc) list when composing a
352 * new mail message. The recipient strings should be of the form "Full
353 * Name <email-address>". The returned array is owned by @extension and
354 * should not be modified or freed.
356 * Returns: a %NULL-terminated string array of Cc recipients
360 const gchar * const *
361 e_source_mail_composition_get_cc (ESourceMailComposition *extension)
363 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
365 return (const gchar * const *) extension->priv->cc;
369 * e_source_mail_composition_dup_cc:
370 * @extension: an #ESourceMailComposition
372 * Thread-safe variation of e_source_mail_composition_get_cc().
373 * Use this function when accessing @extension from multiple threads.
375 * The returned string array should be freed with g_strfreev() when no
378 * Returns: a newly-allocated copy of #ESourceMailComposition:cc
383 e_source_mail_composition_dup_cc (ESourceMailComposition *extension)
385 const gchar * const *protected;
388 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
390 g_mutex_lock (extension->priv->property_lock);
392 protected = e_source_mail_composition_get_cc (extension);
393 duplicate = g_strdupv ((gchar **) protected);
395 g_mutex_unlock (extension->priv->property_lock);
401 * e_source_mail_composition_set_cc:
402 * @extension: an #ESourceMailComposition
403 * @cc: (allow-none): a %NULL-terminated string array of Cc recipients
405 * Sets the recipients which should automatically be added to the carbon
406 * copy (Cc) list when composing a new mail message. The recipient strings
407 * should be of the form "Full Name <email-address>".
412 e_source_mail_composition_set_cc (ESourceMailComposition *extension,
413 const gchar * const *cc)
415 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
417 g_mutex_lock (extension->priv->property_lock);
419 g_strfreev (extension->priv->cc);
420 extension->priv->cc = g_strdupv ((gchar **) cc);
422 g_mutex_unlock (extension->priv->property_lock);
424 g_object_notify (G_OBJECT (extension), "cc");
428 * e_source_mail_composition_get_drafts_folder:
429 * @extension: an #ESourceMailComposition
431 * Returns a string identifying the preferred folder for draft messages.
432 * The format of the identifier string is defined by the client application.
434 * Returns: an identifier for the preferred drafts folder
439 e_source_mail_composition_get_drafts_folder (ESourceMailComposition *extension)
441 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
443 return extension->priv->drafts_folder;
447 * e_source_mail_composition_dup_drafts_folder:
448 * @extension: an #ESourceMailComposition
450 * Thread-safe variation of e_source_mail_composition_get_drafts_folder().
451 * Use this function when accessing @extension from multiple threads.
453 * The returned string should be freed with g_free() when no longer needed.
455 * Returns: a newly-allocated copy of #ESourceMailComposition:drafts-folder
460 e_source_mail_composition_dup_drafts_folder (ESourceMailComposition *extension)
462 const gchar *protected;
465 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
467 g_mutex_lock (extension->priv->property_lock);
469 protected = e_source_mail_composition_get_drafts_folder (extension);
470 duplicate = g_strdup (protected);
472 g_mutex_unlock (extension->priv->property_lock);
478 * e_source_mail_composition_set_drafts_folder:
479 * @extension: an #ESourceMailComposition
480 * @drafts_folder: (allow-none): an identifier for the preferred drafts
483 * Sets the preferred folder for draft messages by an identifier string.
484 * The format of the identifier string is defined by the client application.
486 * The internal copy of @drafts_folder is automatically stripped of
487 * leading and trailing whitespace. If the resulting string is empty,
488 * %NULL is set instead.
493 e_source_mail_composition_set_drafts_folder (ESourceMailComposition *extension,
494 const gchar *drafts_folder)
496 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
498 g_mutex_lock (extension->priv->property_lock);
500 g_free (extension->priv->drafts_folder);
501 extension->priv->drafts_folder = e_util_strdup_strip (drafts_folder);
503 g_mutex_unlock (extension->priv->property_lock);
505 g_object_notify (G_OBJECT (extension), "drafts-folder");
509 * e_source_mail_composition_get_sign_imip:
510 * @extension: an #ESourceMailComposition
512 * Returns whether outgoing iMIP messages such as meeting requests should
513 * also be signed. This is primarily intended as a workaround for certain
514 * versions of Microsoft Outlook which can't handle signed iMIP messages.
516 * Returns: whether outgoing iMIP messages should be signed
521 e_source_mail_composition_get_sign_imip (ESourceMailComposition *extension)
523 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), FALSE);
525 return extension->priv->sign_imip;
529 * e_source_mail_composition_set_sign_imip:
530 * @extension: an #ESourceMailComposition
531 * @sign_imip: whether outgoing iMIP messages should be signed
533 * Sets whether outgoing iMIP messages such as meeting requests should
534 * also be signed. This is primarily intended as a workaround for certain
535 * versions of Microsoft Outlook which can't handle signed iMIP messages.
540 e_source_mail_composition_set_sign_imip (ESourceMailComposition *extension,
543 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
545 extension->priv->sign_imip = sign_imip;
547 g_object_notify (G_OBJECT (extension), "sign-imip");
551 * e_source_mail_composition_get_templates_folder:
552 * @extension: an #ESourceMailComposition
554 * Returns a string identifying the preferred folder for message templates.
555 * The format of the identifier string is defined by the client application.
557 * Returns: an identifier for the preferred templates folder
562 e_source_mail_composition_get_templates_folder (ESourceMailComposition *extension)
564 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
566 return extension->priv->templates_folder;
570 * e_source_mail_composition_dup_templates_folder:
571 * @extension: an #ESourceMailComposition
573 * Thread-safe variation of e_source_mail_composition_get_templates_folder().
574 * Use this function when accessing @extension from multiple threads.
576 * The returned string should be freed with g_free() when no longer needed.
578 * Returns: a newly-allocated copy of #ESourceMailComposition:templates-folder
583 e_source_mail_composition_dup_templates_folder (ESourceMailComposition *extension)
585 const gchar *protected;
588 g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
590 g_mutex_lock (extension->priv->property_lock);
592 protected = e_source_mail_composition_get_templates_folder (extension);
593 duplicate = g_strdup (protected);
595 g_mutex_unlock (extension->priv->property_lock);
601 * e_source_mail_composition_set_templates_folder:
602 * @extension: an #ESourceMailComposition
603 * @templates_folder: (allow-none): an identifier for the preferred templates
606 * Sets the preferred folder for message templates by an identifier string.
607 * The format of the identifier string is defined by the client application.
609 * The internal copy of @templates_folder is automatically stripped of
610 * leading and trailing whitespace. If the resulting string is empty,
611 * %NULL is set instead.
616 e_source_mail_composition_set_templates_folder (ESourceMailComposition *extension,
617 const gchar *templates_folder)
619 g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
621 g_mutex_lock (extension->priv->property_lock);
623 g_free (extension->priv->templates_folder);
624 extension->priv->templates_folder = e_util_strdup_strip (templates_folder);
626 g_mutex_unlock (extension->priv->property_lock);
628 g_object_notify (G_OBJECT (extension), "templates-folder");