2 * e-source-mail-identity.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-identity
21 * @include: libedataserver/libedataserver.h
22 * @short_description: #ESource extension for an email identity
24 * The #ESourceMailIdentity extension describes an "identity" for a mail
25 * account, which is the information that other people see when they read
28 * Access the extension as follows:
31 * #include <libedataserver/libedataserver.h>
33 * ESourceMailIdentity *extension;
35 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_IDENTITY);
39 #include "e-source-mail-identity.h"
41 #include <libedataserver/e-data-server-util.h>
43 #define E_SOURCE_MAIL_IDENTITY_GET_PRIVATE(obj) \
44 (G_TYPE_INSTANCE_GET_PRIVATE \
45 ((obj), E_TYPE_SOURCE_MAIL_IDENTITY, ESourceMailIdentityPrivate))
47 struct _ESourceMailIdentityPrivate {
67 e_source_mail_identity,
68 E_TYPE_SOURCE_EXTENSION)
71 source_mail_identity_set_property (GObject *object,
76 switch (property_id) {
78 e_source_mail_identity_set_address (
79 E_SOURCE_MAIL_IDENTITY (object),
80 g_value_get_string (value));
84 e_source_mail_identity_set_name (
85 E_SOURCE_MAIL_IDENTITY (object),
86 g_value_get_string (value));
89 case PROP_ORGANIZATION:
90 e_source_mail_identity_set_organization (
91 E_SOURCE_MAIL_IDENTITY (object),
92 g_value_get_string (value));
96 e_source_mail_identity_set_reply_to (
97 E_SOURCE_MAIL_IDENTITY (object),
98 g_value_get_string (value));
101 case PROP_SIGNATURE_UID:
102 e_source_mail_identity_set_signature_uid (
103 E_SOURCE_MAIL_IDENTITY (object),
104 g_value_get_string (value));
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
112 source_mail_identity_get_property (GObject *object,
117 switch (property_id) {
119 g_value_take_string (
121 e_source_mail_identity_dup_address (
122 E_SOURCE_MAIL_IDENTITY (object)));
126 g_value_take_string (
128 e_source_mail_identity_dup_name (
129 E_SOURCE_MAIL_IDENTITY (object)));
132 case PROP_ORGANIZATION:
133 g_value_take_string (
135 e_source_mail_identity_dup_organization (
136 E_SOURCE_MAIL_IDENTITY (object)));
140 g_value_take_string (
142 e_source_mail_identity_dup_reply_to (
143 E_SOURCE_MAIL_IDENTITY (object)));
146 case PROP_SIGNATURE_UID:
147 g_value_take_string (
149 e_source_mail_identity_dup_signature_uid (
150 E_SOURCE_MAIL_IDENTITY (object)));
154 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
158 source_mail_identity_finalize (GObject *object)
160 ESourceMailIdentityPrivate *priv;
162 priv = E_SOURCE_MAIL_IDENTITY_GET_PRIVATE (object);
164 g_mutex_clear (&priv->property_lock);
166 g_free (priv->address);
168 g_free (priv->organization);
169 g_free (priv->reply_to);
170 g_free (priv->signature_uid);
172 /* Chain up to parent's finalize() method. */
173 G_OBJECT_CLASS (e_source_mail_identity_parent_class)->finalize (object);
177 e_source_mail_identity_class_init (ESourceMailIdentityClass *class)
179 GObjectClass *object_class;
180 ESourceExtensionClass *extension_class;
182 g_type_class_add_private (class, sizeof (ESourceMailIdentityPrivate));
184 object_class = G_OBJECT_CLASS (class);
185 object_class->set_property = source_mail_identity_set_property;
186 object_class->get_property = source_mail_identity_get_property;
187 object_class->finalize = source_mail_identity_finalize;
189 extension_class = E_SOURCE_EXTENSION_CLASS (class);
190 extension_class->name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
192 g_object_class_install_property (
195 g_param_spec_string (
198 "Sender's email address",
202 G_PARAM_STATIC_STRINGS |
203 E_SOURCE_PARAM_SETTING));
205 g_object_class_install_property (
208 g_param_spec_string (
215 G_PARAM_STATIC_STRINGS |
216 E_SOURCE_PARAM_SETTING));
218 g_object_class_install_property (
221 g_param_spec_string (
224 "Sender's organization",
228 G_PARAM_STATIC_STRINGS |
229 E_SOURCE_PARAM_SETTING));
231 g_object_class_install_property (
234 g_param_spec_string (
237 "Sender's reply-to address",
241 G_PARAM_STATIC_STRINGS |
242 E_SOURCE_PARAM_SETTING));
244 g_object_class_install_property (
247 g_param_spec_string (
250 "ESource UID of the sender's signature",
254 G_PARAM_STATIC_STRINGS |
255 E_SOURCE_PARAM_SETTING));
259 e_source_mail_identity_init (ESourceMailIdentity *extension)
261 extension->priv = E_SOURCE_MAIL_IDENTITY_GET_PRIVATE (extension);
262 g_mutex_init (&extension->priv->property_lock);
266 * e_source_mail_identity_get_address:
267 * @extension: an #ESourceMailIdentity
269 * Returns the email address for this identity from which to send messages.
270 * This may be an empty string but will never be %NULL.
272 * Returns: the sender's email address
277 e_source_mail_identity_get_address (ESourceMailIdentity *extension)
279 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
281 return extension->priv->address;
285 * e_source_mail_identity_dup_address:
286 * @extension: an #ESourceMailIdentity
288 * Thread-safe variation of e_source_mail_identity_get_address().
289 * Use this function when accessing @extension from multiple threads.
291 * The returned string should be freed with g_free() when no longer needed.
293 * Returns: a newly-allocated copy of #ESourceMailIdentity:address
298 e_source_mail_identity_dup_address (ESourceMailIdentity *extension)
300 const gchar *protected;
303 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
305 g_mutex_lock (&extension->priv->property_lock);
307 protected = e_source_mail_identity_get_address (extension);
308 duplicate = g_strdup (protected);
310 g_mutex_unlock (&extension->priv->property_lock);
316 * e_source_mail_identity_set_address:
317 * @extension: an #ESourceMailIdentity
318 * @address: (allow-none): the sender's email address, or %NULL
320 * Sets the email address for this identity from which to send messages.
322 * The internal copy of @address is automatically stripped of leading and
323 * trailing whitespace. If the resulting string is empty, %NULL is set
329 e_source_mail_identity_set_address (ESourceMailIdentity *extension,
330 const gchar *address)
332 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
334 g_mutex_lock (&extension->priv->property_lock);
336 if (g_strcmp0 (extension->priv->address, address) == 0) {
337 g_mutex_unlock (&extension->priv->property_lock);
341 g_free (extension->priv->address);
342 extension->priv->address = e_util_strdup_strip (address);
344 g_mutex_unlock (&extension->priv->property_lock);
346 g_object_notify (G_OBJECT (extension), "address");
350 * e_source_mail_identity_get_name:
351 * @extension: an #ESourceMailIdentity
353 * Returns the sender's name for this identity.
355 * Returns: the sender's name
360 e_source_mail_identity_get_name (ESourceMailIdentity *extension)
362 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
364 return extension->priv->name;
368 * e_source_mail_identity_dup_name:
369 * @extension: an #ESourceMailIdentity
371 * Thread-safe variation of e_source_mail_identity_get_name().
372 * Use this function when accessing @extension from multiple threads.
374 * The returned string should be freed with g_free() when no longer needed.
376 * Returns: a newly-allocated copy of #ESourceMailIdentity:name
381 e_source_mail_identity_dup_name (ESourceMailIdentity *extension)
383 const gchar *protected;
386 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
388 g_mutex_lock (&extension->priv->property_lock);
390 protected = e_source_mail_identity_get_name (extension);
391 duplicate = g_strdup (protected);
393 g_mutex_unlock (&extension->priv->property_lock);
399 * e_source_mail_identity_set_name:
400 * @extension: an #ESourceMailIdentity
401 * @name: (allow-none): the sender's name, or %NULL
403 * Sets the sender's name for this identity.
405 * The internal copy of @name is automatically stripped of leading and
406 * trailing whitespace. If @name is %NULL or the resulting string is
407 * empty, the result of g_get_real_name() is set instead.
412 e_source_mail_identity_set_name (ESourceMailIdentity *extension,
415 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
417 g_mutex_lock (&extension->priv->property_lock);
419 if (extension->priv->name != NULL &&
420 g_strcmp0 (extension->priv->name, name) == 0) {
421 g_mutex_unlock (&extension->priv->property_lock);
425 g_free (extension->priv->name);
426 extension->priv->name = e_util_strdup_strip (name);
428 if (extension->priv->name == NULL)
429 extension->priv->name = g_strdup (g_get_real_name ());
431 g_mutex_unlock (&extension->priv->property_lock);
433 g_object_notify (G_OBJECT (extension), "name");
437 * e_source_mail_identity_get_organization:
438 * @extension: an #ESourceMailIdentity
440 * Returns the sender's organization for this identity.
442 * Returns: the sender's organization
447 e_source_mail_identity_get_organization (ESourceMailIdentity *extension)
449 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
451 return extension->priv->organization;
455 * e_source_mail_identity_dup_organization:
456 * @extension: an #ESourceMailIdentity
458 * Thread-safe variation of e_source_mail_identity_dup_organization().
459 * Use this function when accessing @extension from multiple threads.
461 * The returned string should be freed with g_free() when no longer needed.
463 * Returns: a newly-allocated copy of #ESourceMailIdentity:organization
468 e_source_mail_identity_dup_organization (ESourceMailIdentity *extension)
470 const gchar *protected;
473 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
475 g_mutex_lock (&extension->priv->property_lock);
477 protected = e_source_mail_identity_get_organization (extension);
478 duplicate = g_strdup (protected);
480 g_mutex_unlock (&extension->priv->property_lock);
486 * e_source_mail_identity_set_organization:
487 * @extension: an #ESourceMailIdentity
488 * @organization: (allow-none): the sender's organization, or %NULL
490 * Sets the sender's organization for this identity.
492 * The internal copy of @organization is automatically stripped of leading
493 * and trailing whitespace. If the resulting string is empty, %NULL is set
499 e_source_mail_identity_set_organization (ESourceMailIdentity *extension,
500 const gchar *organization)
502 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
504 g_mutex_lock (&extension->priv->property_lock);
506 if (g_strcmp0 (extension->priv->organization, organization) == 0) {
507 g_mutex_unlock (&extension->priv->property_lock);
511 g_free (extension->priv->organization);
512 extension->priv->organization = e_util_strdup_strip (organization);
514 g_mutex_unlock (&extension->priv->property_lock);
516 g_object_notify (G_OBJECT (extension), "organization");
520 * e_source_mail_identity_get_reply_to:
521 * @extension: an #ESourceMailIdentity
523 * Returns the email address for this identity to which recipients should
526 * Returns: the sender's reply-to address
531 e_source_mail_identity_get_reply_to (ESourceMailIdentity *extension)
533 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
535 return extension->priv->reply_to;
539 * e_source_mail_identity_dup_reply_to:
540 * @extension: an #ESourceMailIdentity
542 * Thread-safe variation of e_source_mail_identity_get_reply_to().
543 * Use this function when accessing @extension from multiple threads.
545 * The returned string should be freed with g_free() when no longer needed.
547 * Returns: a newly-allocated copy of #ESourceMailIdentity:reply-to
552 e_source_mail_identity_dup_reply_to (ESourceMailIdentity *extension)
554 const gchar *protected;
557 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
559 g_mutex_lock (&extension->priv->property_lock);
561 protected = e_source_mail_identity_get_reply_to (extension);
562 duplicate = g_strdup (protected);
564 g_mutex_unlock (&extension->priv->property_lock);
570 * e_source_mail_identity_set_reply_to:
571 * @extension: an #ESourceMailIdentity
572 * @reply_to: (allow-none): the sender's reply-to address, or %NULL
574 * Sets the email address for this identity to which recipients should
577 * The internal copy of @reply_to is automatically stripped of leading
578 * and trailing whitespace. If the resulting string is empty, %NULL is
584 e_source_mail_identity_set_reply_to (ESourceMailIdentity *extension,
585 const gchar *reply_to)
587 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
589 g_mutex_lock (&extension->priv->property_lock);
591 if (g_strcmp0 (extension->priv->reply_to, reply_to) == 0) {
592 g_mutex_unlock (&extension->priv->property_lock);
596 g_free (extension->priv->reply_to);
597 extension->priv->reply_to = e_util_strdup_strip (reply_to);
599 g_mutex_unlock (&extension->priv->property_lock);
601 g_object_notify (G_OBJECT (extension), "reply-to");
605 * e_source_mail_identity_get_signature_uid:
606 * @extension: an #ESourceMailIdentity
608 * Returns the #ESource:uid of an #ESource describing a mail signature.
610 * If the user does not want to use a signature for this identity, the
611 * convention is to set the #ESourceMailIdentity:signature-uid property
614 * Returns: the sender's signature ID, or "none"
619 e_source_mail_identity_get_signature_uid (ESourceMailIdentity *extension)
621 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
623 return extension->priv->signature_uid;
627 * e_source_mail_identity_dup_signature_uid:
628 * @extension: an #ESourceMailIdentity
630 * Thread-safe variation of e_source_mail_identity_get_signature_uid().
631 * Use this function when accessing @extension from multiple threads.
633 * The returned string should be freed with g_free() when no longer needed.
635 * Returns: a newly-allocated copy of #ESourceMailIdentity:signature-uid
640 e_source_mail_identity_dup_signature_uid (ESourceMailIdentity *extension)
642 const gchar *protected;
645 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
647 g_mutex_lock (&extension->priv->property_lock);
649 protected = e_source_mail_identity_get_signature_uid (extension);
650 duplicate = g_strdup (protected);
652 g_mutex_unlock (&extension->priv->property_lock);
658 * e_source_mail_identity_set_signature_uid:
659 * @extension: an #ESourceMailIdentity
660 * @signature_uid: (allow-none): the sender's signature ID, or %NULL
662 * Sets the #ESource:uid of an #ESource describing a mail signature.
664 * If the user does not want to use a signature for this identity, the
665 * convention is to set the #ESourceMailIdentity:signature-uid property
666 * to "none". In keeping with that convention, the property will be set
667 * to "none" if @signature is %NULL or an empty string.
672 e_source_mail_identity_set_signature_uid (ESourceMailIdentity *extension,
673 const gchar *signature_uid)
675 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
677 /* Convert empty strings to "none". */
678 if (signature_uid == NULL || *signature_uid == '\0')
679 signature_uid = "none";
681 g_mutex_lock (&extension->priv->property_lock);
683 if (g_strcmp0 (extension->priv->signature_uid, signature_uid) == 0) {
684 g_mutex_unlock (&extension->priv->property_lock);
688 g_free (extension->priv->signature_uid);
689 extension->priv->signature_uid = g_strdup (signature_uid);
691 g_mutex_unlock (&extension->priv->property_lock);
693 g_object_notify (G_OBJECT (extension), "signature-uid");