1 /*
2  * e-source-mail-composition.c
3  *
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.
7  *
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 Lesser General Public License
11  * for more details.
12  *
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/>.
15  *
16  */
17 
18 /**
19  * SECTION: e-source-mail-composition
20  * @include: libedataserver/libedataserver.h
21  * @short_description: #ESource extension for mail composition settings
22  *
23  * The #ESourceMailComposition extension tracks settings to be applied
24  * when composing a new mail message.
25  *
26  * Access the extension as follows:
27  *
28  * |[
29  *   #include <libedataserver/libedataserver.h>
30  *
31  *   ESourceMailComposition *extension;
32  *
33  *   extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_COMPOSITION);
34  * ]|
35  **/
36 
37 #include "evolution-data-server-config.h"
38 
39 #include <libedataserver/e-data-server-util.h>
40 
41 #include "e-source-enumtypes.h"
42 #include "e-source-mail-composition.h"
43 
44 struct _ESourceMailCompositionPrivate {
45 	gchar **bcc;
46 	gchar **cc;
47 	gchar *drafts_folder;
48 	gchar *templates_folder;
49 	gchar *language;
50 	gboolean sign_imip;
51 	ESourceMailCompositionReplyStyle reply_style;
52 	EThreeState start_bottom;
53 	EThreeState top_signature;
54 };
55 
56 enum {
57 	PROP_0,
58 	PROP_BCC,
59 	PROP_CC,
60 	PROP_DRAFTS_FOLDER,
61 	PROP_REPLY_STYLE,
62 	PROP_SIGN_IMIP,
63 	PROP_TEMPLATES_FOLDER,
64 	PROP_START_BOTTOM,
65 	PROP_TOP_SIGNATURE,
66 	PROP_LANGUAGE
67 };
68 
G_DEFINE_TYPE_WITH_PRIVATE(ESourceMailComposition,e_source_mail_composition,E_TYPE_SOURCE_EXTENSION)69 G_DEFINE_TYPE_WITH_PRIVATE (
70 	ESourceMailComposition,
71 	e_source_mail_composition,
72 	E_TYPE_SOURCE_EXTENSION)
73 
74 static void
75 source_mail_composition_set_property (GObject *object,
76                                       guint property_id,
77                                       const GValue *value,
78                                       GParamSpec *pspec)
79 {
80 	switch (property_id) {
81 		case PROP_BCC:
82 			e_source_mail_composition_set_bcc (
83 				E_SOURCE_MAIL_COMPOSITION (object),
84 				g_value_get_boxed (value));
85 			return;
86 
87 		case PROP_CC:
88 			e_source_mail_composition_set_cc (
89 				E_SOURCE_MAIL_COMPOSITION (object),
90 				g_value_get_boxed (value));
91 			return;
92 
93 		case PROP_DRAFTS_FOLDER:
94 			e_source_mail_composition_set_drafts_folder (
95 				E_SOURCE_MAIL_COMPOSITION (object),
96 				g_value_get_string (value));
97 			return;
98 
99 		case PROP_LANGUAGE:
100 			e_source_mail_composition_set_language (
101 				E_SOURCE_MAIL_COMPOSITION (object),
102 				g_value_get_string (value));
103 			return;
104 
105 		case PROP_REPLY_STYLE:
106 			e_source_mail_composition_set_reply_style (
107 				E_SOURCE_MAIL_COMPOSITION (object),
108 				g_value_get_enum (value));
109 			return;
110 
111 		case PROP_SIGN_IMIP:
112 			e_source_mail_composition_set_sign_imip (
113 				E_SOURCE_MAIL_COMPOSITION (object),
114 				g_value_get_boolean (value));
115 			return;
116 
117 		case PROP_START_BOTTOM:
118 			e_source_mail_composition_set_start_bottom (
119 				E_SOURCE_MAIL_COMPOSITION (object),
120 				g_value_get_enum (value));
121 			return;
122 
123 		case PROP_TEMPLATES_FOLDER:
124 			e_source_mail_composition_set_templates_folder (
125 				E_SOURCE_MAIL_COMPOSITION (object),
126 				g_value_get_string (value));
127 			return;
128 
129 		case PROP_TOP_SIGNATURE:
130 			e_source_mail_composition_set_top_signature (
131 				E_SOURCE_MAIL_COMPOSITION (object),
132 				g_value_get_enum (value));
133 			return;
134 	}
135 
136 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
137 }
138 
139 static void
source_mail_composition_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)140 source_mail_composition_get_property (GObject *object,
141                                       guint property_id,
142                                       GValue *value,
143                                       GParamSpec *pspec)
144 {
145 	switch (property_id) {
146 		case PROP_BCC:
147 			g_value_take_boxed (
148 				value,
149 				e_source_mail_composition_dup_bcc (
150 				E_SOURCE_MAIL_COMPOSITION (object)));
151 			return;
152 
153 		case PROP_CC:
154 			g_value_take_boxed (
155 				value,
156 				e_source_mail_composition_dup_cc (
157 				E_SOURCE_MAIL_COMPOSITION (object)));
158 			return;
159 
160 		case PROP_DRAFTS_FOLDER:
161 			g_value_take_string (
162 				value,
163 				e_source_mail_composition_dup_drafts_folder (
164 				E_SOURCE_MAIL_COMPOSITION (object)));
165 			return;
166 
167 		case PROP_LANGUAGE:
168 			g_value_take_string (
169 				value,
170 				e_source_mail_composition_dup_language (
171 				E_SOURCE_MAIL_COMPOSITION (object)));
172 			return;
173 
174 		case PROP_REPLY_STYLE:
175 			g_value_set_enum (
176 				value,
177 				e_source_mail_composition_get_reply_style (
178 				E_SOURCE_MAIL_COMPOSITION (object)));
179 			return;
180 
181 		case PROP_SIGN_IMIP:
182 			g_value_set_boolean (
183 				value,
184 				e_source_mail_composition_get_sign_imip (
185 				E_SOURCE_MAIL_COMPOSITION (object)));
186 			return;
187 
188 		case PROP_START_BOTTOM:
189 			g_value_set_enum (
190 				value,
191 				e_source_mail_composition_get_start_bottom (
192 				E_SOURCE_MAIL_COMPOSITION (object)));
193 			return;
194 
195 		case PROP_TEMPLATES_FOLDER:
196 			g_value_take_string (
197 				value,
198 				e_source_mail_composition_dup_templates_folder (
199 				E_SOURCE_MAIL_COMPOSITION (object)));
200 			return;
201 
202 		case PROP_TOP_SIGNATURE:
203 			g_value_set_enum (
204 				value,
205 				e_source_mail_composition_get_top_signature (
206 				E_SOURCE_MAIL_COMPOSITION (object)));
207 			return;
208 	}
209 
210 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
211 }
212 
213 static void
source_mail_composition_finalize(GObject * object)214 source_mail_composition_finalize (GObject *object)
215 {
216 	ESourceMailCompositionPrivate *priv;
217 
218 	priv = E_SOURCE_MAIL_COMPOSITION (object)->priv;
219 
220 	g_strfreev (priv->bcc);
221 	g_strfreev (priv->cc);
222 	g_free (priv->drafts_folder);
223 	g_free (priv->templates_folder);
224 	g_free (priv->language);
225 
226 	/* Chain up to parent's finalize() method. */
227 	G_OBJECT_CLASS (e_source_mail_composition_parent_class)->
228 		finalize (object);
229 }
230 
231 static void
e_source_mail_composition_class_init(ESourceMailCompositionClass * class)232 e_source_mail_composition_class_init (ESourceMailCompositionClass *class)
233 {
234 	GObjectClass *object_class;
235 	ESourceExtensionClass *extension_class;
236 
237 	object_class = G_OBJECT_CLASS (class);
238 	object_class->set_property = source_mail_composition_set_property;
239 	object_class->get_property = source_mail_composition_get_property;
240 	object_class->finalize = source_mail_composition_finalize;
241 
242 	extension_class = E_SOURCE_EXTENSION_CLASS (class);
243 	extension_class->name = E_SOURCE_EXTENSION_MAIL_COMPOSITION;
244 
245 	g_object_class_install_property (
246 		object_class,
247 		PROP_BCC,
248 		g_param_spec_boxed (
249 			"bcc",
250 			"Bcc",
251 			"Recipients to blind carbon-copy",
252 			G_TYPE_STRV,
253 			G_PARAM_READWRITE |
254 			G_PARAM_CONSTRUCT |
255 			G_PARAM_EXPLICIT_NOTIFY |
256 			G_PARAM_STATIC_STRINGS |
257 			E_SOURCE_PARAM_SETTING));
258 
259 	g_object_class_install_property (
260 		object_class,
261 		PROP_CC,
262 		g_param_spec_boxed (
263 			"cc",
264 			"Cc",
265 			"Recipients to carbon-copy",
266 			G_TYPE_STRV,
267 			G_PARAM_READWRITE |
268 			G_PARAM_CONSTRUCT |
269 			G_PARAM_EXPLICIT_NOTIFY |
270 			G_PARAM_STATIC_STRINGS |
271 			E_SOURCE_PARAM_SETTING));
272 
273 	g_object_class_install_property (
274 		object_class,
275 		PROP_DRAFTS_FOLDER,
276 		g_param_spec_string (
277 			"drafts-folder",
278 			"Drafts Folder",
279 			"Preferred folder for draft messages",
280 			NULL,
281 			G_PARAM_READWRITE |
282 			G_PARAM_CONSTRUCT |
283 			G_PARAM_EXPLICIT_NOTIFY |
284 			G_PARAM_STATIC_STRINGS |
285 			E_SOURCE_PARAM_SETTING));
286 
287 	g_object_class_install_property (
288 		object_class,
289 		PROP_REPLY_STYLE,
290 		g_param_spec_enum (
291 			"reply-style",
292 			"Reply Style",
293 			"What reply style to prefer",
294 			E_TYPE_SOURCE_MAIL_COMPOSITION_REPLY_STYLE,
295 			E_SOURCE_MAIL_COMPOSITION_REPLY_STYLE_DEFAULT,
296 			G_PARAM_READWRITE |
297 			G_PARAM_CONSTRUCT |
298 			G_PARAM_EXPLICIT_NOTIFY |
299 			G_PARAM_STATIC_STRINGS |
300 			E_SOURCE_PARAM_SETTING));
301 
302 	g_object_class_install_property (
303 		object_class,
304 		PROP_SIGN_IMIP,
305 		g_param_spec_boolean (
306 			"sign-imip",
307 			"Sign iMIP",
308 			"Include iMIP messages when signing",
309 			TRUE,
310 			G_PARAM_READWRITE |
311 			G_PARAM_CONSTRUCT |
312 			G_PARAM_EXPLICIT_NOTIFY |
313 			G_PARAM_STATIC_STRINGS |
314 			E_SOURCE_PARAM_SETTING));
315 
316 	g_object_class_install_property (
317 		object_class,
318 		PROP_START_BOTTOM,
319 		g_param_spec_enum (
320 			"start-bottom",
321 			"Start Bottom",
322 			"Whether start at bottom on reply or forward",
323 			E_TYPE_THREE_STATE,
324 			E_THREE_STATE_INCONSISTENT,
325 			G_PARAM_READWRITE |
326 			G_PARAM_CONSTRUCT |
327 			G_PARAM_EXPLICIT_NOTIFY |
328 			G_PARAM_STATIC_STRINGS |
329 			E_SOURCE_PARAM_SETTING));
330 
331 	g_object_class_install_property (
332 		object_class,
333 		PROP_TEMPLATES_FOLDER,
334 		g_param_spec_string (
335 			"templates-folder",
336 			"Templates Folder",
337 			"Preferred folder for message templates",
338 			NULL,
339 			G_PARAM_READWRITE |
340 			G_PARAM_CONSTRUCT |
341 			G_PARAM_EXPLICIT_NOTIFY |
342 			G_PARAM_STATIC_STRINGS |
343 			E_SOURCE_PARAM_SETTING));
344 
345 	g_object_class_install_property (
346 		object_class,
347 		PROP_TOP_SIGNATURE,
348 		g_param_spec_enum (
349 			"top-signature",
350 			"Top Signature",
351 			"Whether place signature at the top on reply or forward",
352 			E_TYPE_THREE_STATE,
353 			E_THREE_STATE_INCONSISTENT,
354 			G_PARAM_READWRITE |
355 			G_PARAM_CONSTRUCT |
356 			G_PARAM_EXPLICIT_NOTIFY |
357 			G_PARAM_STATIC_STRINGS |
358 			E_SOURCE_PARAM_SETTING));
359 
360 	g_object_class_install_property (
361 		object_class,
362 		PROP_LANGUAGE,
363 		g_param_spec_string (
364 			"language",
365 			"Language",
366 			"Preferred language",
367 			NULL,
368 			G_PARAM_READWRITE |
369 			G_PARAM_CONSTRUCT |
370 			G_PARAM_EXPLICIT_NOTIFY |
371 			G_PARAM_STATIC_STRINGS |
372 			E_SOURCE_PARAM_SETTING));
373 }
374 
375 static void
e_source_mail_composition_init(ESourceMailComposition * extension)376 e_source_mail_composition_init (ESourceMailComposition *extension)
377 {
378 	extension->priv = e_source_mail_composition_get_instance_private (extension);
379 }
380 
381 /**
382  * e_source_mail_composition_get_bcc:
383  * @extension: an #ESourceMailComposition
384  *
385  * Returns a %NULL-terminated string array of recipients which should
386  * automatically be added to the blind carbon-copy (Bcc) list when
387  * composing a new mail message.  The recipient strings should be of
388  * the form "Full Name &lt;email-address&gt;".  The returned array is
389  * owned by @extension and should not be modified or freed.
390  *
391  * Returns: (transfer none): a %NULL-terminated string array of Bcc recipients
392  *
393  * Since: 3.6
394  **/
395 const gchar * const *
e_source_mail_composition_get_bcc(ESourceMailComposition * extension)396 e_source_mail_composition_get_bcc (ESourceMailComposition *extension)
397 {
398 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
399 
400 	return (const gchar * const *) extension->priv->bcc;
401 }
402 
403 /**
404  * e_source_mail_composition_dup_bcc:
405  * @extension: an #ESourceMailComposition
406  *
407  * Thread-safe variation of e_source_mail_composition_get_bcc().
408  * Use this function when accessing @extension from multiple threads.
409  *
410  * The returned string array should be freed with g_strfreev() when no
411  * longer needed.
412  *
413  * Returns: (transfer full): a newly-allocated copy of
414  * #ESourceMailComposition:bcc
415  *
416  * Since: 3.6
417  **/
418 gchar **
e_source_mail_composition_dup_bcc(ESourceMailComposition * extension)419 e_source_mail_composition_dup_bcc (ESourceMailComposition *extension)
420 {
421 	const gchar * const *protected;
422 	gchar **duplicate;
423 
424 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
425 
426 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
427 
428 	protected = e_source_mail_composition_get_bcc (extension);
429 	duplicate = g_strdupv ((gchar **) protected);
430 
431 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
432 
433 	return duplicate;
434 }
435 
436 /**
437  * e_source_mail_composition_set_bcc:
438  * @extension: an #ESource
439  * @bcc: (array zero-terminated=1): a %NULL-terminated string array of Bcc
440  *    recipients
441  *
442  * Sets the recipients which should automatically be added to the blind
443  * carbon-copy (Bcc) list when composing a new mail message.  The recipient
444  * strings should be of the form "Full Name &lt;email-address&gt;".
445  *
446  * Since: 3.6
447  **/
448 void
e_source_mail_composition_set_bcc(ESourceMailComposition * extension,const gchar * const * bcc)449 e_source_mail_composition_set_bcc (ESourceMailComposition *extension,
450                                    const gchar * const *bcc)
451 {
452 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
453 
454 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
455 
456 	if (e_util_strv_equal (bcc, extension->priv->bcc)) {
457 		e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
458 		return;
459 	}
460 
461 	g_strfreev (extension->priv->bcc);
462 	extension->priv->bcc = g_strdupv ((gchar **) bcc);
463 
464 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
465 
466 	g_object_notify (G_OBJECT (extension), "bcc");
467 }
468 
469 /**
470  * e_source_mail_composition_get_cc:
471  * @extension: an #ESourceMailComposition
472  *
473  * Returns a %NULL-terminated string array of recipients which should
474  * automatically be added to the carbon-copy (Cc) list when composing a
475  * new mail message.  The recipient strings should be of the form "Full
476  * Name <email-address>".  The returned array is owned by @extension and
477  * should not be modified or freed.
478  *
479  * Returns: (transfer none): a %NULL-terminated string array of Cc recipients
480  *
481  * Since: 3.6
482  **/
483 const gchar * const *
e_source_mail_composition_get_cc(ESourceMailComposition * extension)484 e_source_mail_composition_get_cc (ESourceMailComposition *extension)
485 {
486 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
487 
488 	return (const gchar * const *) extension->priv->cc;
489 }
490 
491 /**
492  * e_source_mail_composition_dup_cc:
493  * @extension: an #ESourceMailComposition
494  *
495  * Thread-safe variation of e_source_mail_composition_get_cc().
496  * Use this function when accessing @extension from multiple threads.
497  *
498  * The returned string array should be freed with g_strfreev() when no
499  * longer needed.
500  *
501  * Returns: (transfer full): a newly-allocated copy of
502  * #ESourceMailComposition:cc
503  *
504  * Since: 3.6
505  **/
506 gchar **
e_source_mail_composition_dup_cc(ESourceMailComposition * extension)507 e_source_mail_composition_dup_cc (ESourceMailComposition *extension)
508 {
509 	const gchar * const *protected;
510 	gchar **duplicate;
511 
512 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
513 
514 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
515 
516 	protected = e_source_mail_composition_get_cc (extension);
517 	duplicate = g_strdupv ((gchar **) protected);
518 
519 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
520 
521 	return duplicate;
522 }
523 
524 /**
525  * e_source_mail_composition_set_cc:
526  * @extension: an #ESourceMailComposition
527  * @cc: (array zero-terminated=1): a %NULL-terminated string array of Cc
528  *    recipients
529  *
530  * Sets the recipients which should automatically be added to the carbon
531  * copy (Cc) list when composing a new mail message.  The recipient strings
532  * should be of the form "Full Name &lt;email-address&gt;".
533  *
534  * Since: 3.6
535  **/
536 void
e_source_mail_composition_set_cc(ESourceMailComposition * extension,const gchar * const * cc)537 e_source_mail_composition_set_cc (ESourceMailComposition *extension,
538                                   const gchar * const *cc)
539 {
540 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
541 
542 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
543 
544 	if (e_util_strv_equal (cc, extension->priv->cc)) {
545 		e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
546 		return;
547 	}
548 
549 	g_strfreev (extension->priv->cc);
550 	extension->priv->cc = g_strdupv ((gchar **) cc);
551 
552 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
553 
554 	g_object_notify (G_OBJECT (extension), "cc");
555 }
556 
557 /**
558  * e_source_mail_composition_get_drafts_folder:
559  * @extension: an #ESourceMailComposition
560  *
561  * Returns a string identifying the preferred folder for draft messages.
562  * The format of the identifier string is defined by the client application.
563  *
564  * Returns: (nullable): an identifier for the preferred drafts folder
565  *
566  * Since: 3.6
567  **/
568 const gchar *
e_source_mail_composition_get_drafts_folder(ESourceMailComposition * extension)569 e_source_mail_composition_get_drafts_folder (ESourceMailComposition *extension)
570 {
571 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
572 
573 	return extension->priv->drafts_folder;
574 }
575 
576 /**
577  * e_source_mail_composition_dup_drafts_folder:
578  * @extension: an #ESourceMailComposition
579  *
580  * Thread-safe variation of e_source_mail_composition_get_drafts_folder().
581  * Use this function when accessing @extension from multiple threads.
582  *
583  * The returned string should be freed with g_free() when no longer needed.
584  *
585  * Returns: (nullable): a newly-allocated copy of #ESourceMailComposition:drafts-folder
586  *
587  * Since: 3.6
588  **/
589 gchar *
e_source_mail_composition_dup_drafts_folder(ESourceMailComposition * extension)590 e_source_mail_composition_dup_drafts_folder (ESourceMailComposition *extension)
591 {
592 	const gchar *protected;
593 	gchar *duplicate;
594 
595 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
596 
597 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
598 
599 	protected = e_source_mail_composition_get_drafts_folder (extension);
600 	duplicate = g_strdup (protected);
601 
602 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
603 
604 	return duplicate;
605 }
606 
607 /**
608  * e_source_mail_composition_set_drafts_folder:
609  * @extension: an #ESourceMailComposition
610  * @drafts_folder: (nullable): an identifier for the preferred drafts
611  *                 folder, or %NULL
612  *
613  * Sets the preferred folder for draft messages by an identifier string.
614  * The format of the identifier string is defined by the client application.
615  *
616  * The internal copy of @drafts_folder is automatically stripped of
617  * leading and trailing whitespace.  If the resulting string is empty,
618  * %NULL is set instead.
619  *
620  * Since: 3.6
621  **/
622 void
e_source_mail_composition_set_drafts_folder(ESourceMailComposition * extension,const gchar * drafts_folder)623 e_source_mail_composition_set_drafts_folder (ESourceMailComposition *extension,
624                                              const gchar *drafts_folder)
625 {
626 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
627 
628 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
629 
630 	if (e_util_strcmp0 (extension->priv->drafts_folder, drafts_folder) == 0) {
631 		e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
632 		return;
633 	}
634 
635 	g_free (extension->priv->drafts_folder);
636 	extension->priv->drafts_folder = e_util_strdup_strip (drafts_folder);
637 
638 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
639 
640 	g_object_notify (G_OBJECT (extension), "drafts-folder");
641 }
642 
643 /**
644  * e_source_mail_composition_get_sign_imip:
645  * @extension: an #ESourceMailComposition
646  *
647  * Returns whether outgoing iMIP messages such as meeting requests should
648  * also be signed.  This is primarily intended as a workaround for certain
649  * versions of Microsoft Outlook which can't handle signed iMIP messages.
650  *
651  * Returns: whether outgoing iMIP messages should be signed
652  *
653  * Since: 3.6
654  **/
655 gboolean
e_source_mail_composition_get_sign_imip(ESourceMailComposition * extension)656 e_source_mail_composition_get_sign_imip (ESourceMailComposition *extension)
657 {
658 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), FALSE);
659 
660 	return extension->priv->sign_imip;
661 }
662 
663 /**
664  * e_source_mail_composition_set_sign_imip:
665  * @extension: an #ESourceMailComposition
666  * @sign_imip: whether outgoing iMIP messages should be signed
667  *
668  * Sets whether outgoing iMIP messages such as meeting requests should
669  * also be signed.  This is primarily intended as a workaround for certain
670  * versions of Microsoft Outlook which can't handle signed iMIP messages.
671  *
672  * Since: 3.6
673  **/
674 void
e_source_mail_composition_set_sign_imip(ESourceMailComposition * extension,gboolean sign_imip)675 e_source_mail_composition_set_sign_imip (ESourceMailComposition *extension,
676                                          gboolean sign_imip)
677 {
678 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
679 
680 	if (extension->priv->sign_imip == sign_imip)
681 		return;
682 
683 	extension->priv->sign_imip = sign_imip;
684 
685 	g_object_notify (G_OBJECT (extension), "sign-imip");
686 }
687 
688 /**
689  * e_source_mail_composition_get_templates_folder:
690  * @extension: an #ESourceMailComposition
691  *
692  * Returns a string identifying the preferred folder for message templates.
693  * The format of the identifier string is defined by the client application.
694  *
695  * Returns: (nullable): an identifier for the preferred templates folder
696  *
697  * Since: 3.6
698  **/
699 const gchar *
e_source_mail_composition_get_templates_folder(ESourceMailComposition * extension)700 e_source_mail_composition_get_templates_folder (ESourceMailComposition *extension)
701 {
702 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
703 
704 	return extension->priv->templates_folder;
705 }
706 
707 /**
708  * e_source_mail_composition_dup_templates_folder:
709  * @extension: an #ESourceMailComposition
710  *
711  * Thread-safe variation of e_source_mail_composition_get_templates_folder().
712  * Use this function when accessing @extension from multiple threads.
713  *
714  * The returned string should be freed with g_free() when no longer needed.
715  *
716  * Returns: (nullable): a newly-allocated copy of #ESourceMailComposition:templates-folder
717  *
718  * Since: 3.6
719  **/
720 gchar *
e_source_mail_composition_dup_templates_folder(ESourceMailComposition * extension)721 e_source_mail_composition_dup_templates_folder (ESourceMailComposition *extension)
722 {
723 	const gchar *protected;
724 	gchar *duplicate;
725 
726 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
727 
728 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
729 
730 	protected = e_source_mail_composition_get_templates_folder (extension);
731 	duplicate = g_strdup (protected);
732 
733 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
734 
735 	return duplicate;
736 }
737 
738 /**
739  * e_source_mail_composition_set_templates_folder:
740  * @extension: an #ESourceMailComposition
741  * @templates_folder: (nullable): an identifier for the preferred templates
742  *                    folder, or %NULL
743  *
744  * Sets the preferred folder for message templates by an identifier string.
745  * The format of the identifier string is defined by the client application.
746  *
747  * The internal copy of @templates_folder is automatically stripped of
748  * leading and trailing whitespace.  If the resulting string is empty,
749  * %NULL is set instead.
750  *
751  * Since: 3.6
752  **/
753 void
e_source_mail_composition_set_templates_folder(ESourceMailComposition * extension,const gchar * templates_folder)754 e_source_mail_composition_set_templates_folder (ESourceMailComposition *extension,
755                                                 const gchar *templates_folder)
756 {
757 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
758 
759 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
760 
761 	if (e_util_strcmp0 (extension->priv->templates_folder, templates_folder) == 0) {
762 		e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
763 		return;
764 	}
765 
766 	g_free (extension->priv->templates_folder);
767 	extension->priv->templates_folder = e_util_strdup_strip (templates_folder);
768 
769 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
770 
771 	g_object_notify (G_OBJECT (extension), "templates-folder");
772 }
773 
774 /**
775  * e_source_mail_composition_get_reply_style:
776  * @extension: an #ESourceMailComposition
777  *
778  * Returns preferred reply style to be used when replying
779  * using the associated account. If no preference is set,
780  * the %E_SOURCE_MAIL_COMPOSITION_REPLY_STYLE_DEFAULT is returned.
781  *
782  * Returns: reply style preference
783  *
784  * Since: 3.20
785  **/
786 ESourceMailCompositionReplyStyle
e_source_mail_composition_get_reply_style(ESourceMailComposition * extension)787 e_source_mail_composition_get_reply_style (ESourceMailComposition *extension)
788 {
789 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension),
790 		E_SOURCE_MAIL_COMPOSITION_REPLY_STYLE_DEFAULT);
791 
792 	return extension->priv->reply_style;
793 }
794 
795 /**
796  * e_source_mail_composition_set_reply_style:
797  * @extension: an #ESourceMailComposition
798  * @reply_style: an #ESourceMailCompositionReplyStyle
799  *
800  * Sets preferred reply style to be used when replying
801  * using the associated account. To unset the preference,
802  * use the %E_SOURCE_MAIL_COMPOSITION_REPLY_STYLE_DEFAULT.
803  *
804  * Since: 3.20
805  **/
806 void
e_source_mail_composition_set_reply_style(ESourceMailComposition * extension,ESourceMailCompositionReplyStyle reply_style)807 e_source_mail_composition_set_reply_style (ESourceMailComposition *extension,
808 					   ESourceMailCompositionReplyStyle reply_style)
809 {
810 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
811 
812 	if (extension->priv->reply_style == reply_style)
813 		return;
814 
815 	extension->priv->reply_style = reply_style;
816 
817 	g_object_notify (G_OBJECT (extension), "reply-style");
818 }
819 
820 /**
821  * e_source_mail_composition_get_start_bottom:
822  * @extension: an #ESourceMailComposition
823  *
824  * Returns whether start at bottom when replying or forwarding
825  * using the associated account. If no preference is set,
826  * the %E_THREE_STATE_INCONSISTENT is returned.
827  *
828  * Returns: start bottom on reply or forward preference
829  *
830  * Since: 3.26
831  **/
832 EThreeState
e_source_mail_composition_get_start_bottom(ESourceMailComposition * extension)833 e_source_mail_composition_get_start_bottom (ESourceMailComposition *extension)
834 {
835 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), E_THREE_STATE_INCONSISTENT);
836 
837 	return extension->priv->start_bottom;
838 }
839 
840 /**
841  * e_source_mail_composition_set_start_bottom:
842  * @extension: an #ESourceMailComposition
843  * @start_bottom: an #EThreeState
844  *
845  * Sets whether start bottom when replying or forwarding using the associated account.
846  * To unset the preference, use the %E_THREE_STATE_INCONSISTENT.
847  *
848  * Since: 3.26
849  **/
850 void
e_source_mail_composition_set_start_bottom(ESourceMailComposition * extension,EThreeState start_bottom)851 e_source_mail_composition_set_start_bottom (ESourceMailComposition *extension,
852 					    EThreeState start_bottom)
853 {
854 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
855 
856 	if (extension->priv->start_bottom == start_bottom)
857 		return;
858 
859 	extension->priv->start_bottom = start_bottom;
860 
861 	g_object_notify (G_OBJECT (extension), "start-bottom");
862 }
863 
864 /**
865  * e_source_mail_composition_get_top_signature:
866  * @extension: an #ESourceMailComposition
867  *
868  * Returns whether place signature at top when replying or forwarding
869  * using the associated account. If no preference is set,
870  * the %E_THREE_STATE_INCONSISTENT is returned.
871  *
872  * Returns: top signature on reply or forward preference
873  *
874  * Since: 3.26
875  **/
876 EThreeState
e_source_mail_composition_get_top_signature(ESourceMailComposition * extension)877 e_source_mail_composition_get_top_signature (ESourceMailComposition *extension)
878 {
879 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), E_THREE_STATE_INCONSISTENT);
880 
881 	return extension->priv->top_signature;
882 }
883 
884 /**
885  * e_source_mail_composition_set_top_signature:
886  * @extension: an #ESourceMailComposition
887  * @top_signature: an #EThreeState
888  *
889  * Sets whether place signature at top when replying or forwarding using the associated account.
890  * To unset the preference, use the %E_THREE_STATE_INCONSISTENT.
891  *
892  * Since: 3.26
893  **/
894 void
e_source_mail_composition_set_top_signature(ESourceMailComposition * extension,EThreeState top_signature)895 e_source_mail_composition_set_top_signature (ESourceMailComposition *extension,
896 					     EThreeState top_signature)
897 {
898 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
899 
900 	if (extension->priv->top_signature == top_signature)
901 		return;
902 
903 	extension->priv->top_signature = top_signature;
904 
905 	g_object_notify (G_OBJECT (extension), "top-signature");
906 }
907 
908 /**
909  * e_source_mail_composition_get_language:
910  * @extension: an #ESourceMailComposition
911  *
912  * Returns a string identifying the preferred language, like "en_US".
913  *
914  * Returns: (nullable): an identifier for the preferred language, or %NULL for none
915  *
916  * Since: 3.32
917  **/
918 const gchar *
e_source_mail_composition_get_language(ESourceMailComposition * extension)919 e_source_mail_composition_get_language (ESourceMailComposition *extension)
920 {
921 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
922 
923 	return extension->priv->language;
924 }
925 
926 /**
927  * e_source_mail_composition_dup_language:
928  * @extension: an #ESourceMailComposition
929  *
930  * Thread-safe variation of e_source_mail_composition_get_language().
931  * Use this function when accessing @extension from multiple threads.
932  *
933  * The returned string should be freed with g_free() when no longer needed.
934  *
935  * Returns: (nullable): a newly-allocated copy of #ESourceMailComposition:language
936  *
937  * Since: 3.32
938  **/
939 gchar *
e_source_mail_composition_dup_language(ESourceMailComposition * extension)940 e_source_mail_composition_dup_language (ESourceMailComposition *extension)
941 {
942 	const gchar *protected;
943 	gchar *duplicate;
944 
945 	g_return_val_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension), NULL);
946 
947 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
948 
949 	protected = e_source_mail_composition_get_language (extension);
950 	duplicate = g_strdup (protected);
951 
952 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
953 
954 	return duplicate;
955 }
956 
957 /**
958  * e_source_mail_composition_set_language:
959  * @extension: an #ESourceMailComposition
960  * @language: (nullable): an identifier for the preferred language, or %NULL
961  *
962  * Sets the preferred language by an identifier string, like "en_US".
963  * Use %NULL to unset any previous value.
964  *
965  * The internal copy of @language is automatically stripped of
966  * leading and trailing whitespace.  If the resulting string is empty,
967  * %NULL is set instead.
968  *
969  * Since: 3.32
970  **/
971 void
e_source_mail_composition_set_language(ESourceMailComposition * extension,const gchar * language)972 e_source_mail_composition_set_language (ESourceMailComposition *extension,
973 					const gchar *language)
974 {
975 	g_return_if_fail (E_IS_SOURCE_MAIL_COMPOSITION (extension));
976 
977 	e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
978 
979 	if (e_util_strcmp0 (extension->priv->language, language) == 0) {
980 		e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
981 		return;
982 	}
983 
984 	g_free (extension->priv->language);
985 	extension->priv->language = e_util_strdup_strip (language);
986 
987 	e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
988 
989 	g_object_notify (G_OBJECT (extension), "language");
990 }
991