2 * e-source-mail-identity.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-identity
20 * @include: libedataserver/libedataserver.h
21 * @short_description: #ESource extension for an email identity
23 * The #ESourceMailIdentity extension describes an "identity" for a mail
24 * account, which is the information that other people see when they read
27 * Access the extension as follows:
30 * #include <libedataserver/libedataserver.h>
32 * ESourceMailIdentity *extension;
34 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_IDENTITY);
38 #include "e-source-mail-identity.h"
40 #include <libedataserver/e-data-server-util.h>
42 #define E_SOURCE_MAIL_IDENTITY_GET_PRIVATE(obj) \
43 (G_TYPE_INSTANCE_GET_PRIVATE \
44 ((obj), E_TYPE_SOURCE_MAIL_IDENTITY, ESourceMailIdentityPrivate))
46 struct _ESourceMailIdentityPrivate {
66 e_source_mail_identity,
67 E_TYPE_SOURCE_EXTENSION)
70 source_mail_identity_set_property (GObject *object,
75 switch (property_id) {
77 e_source_mail_identity_set_address (
78 E_SOURCE_MAIL_IDENTITY (object),
79 g_value_get_string (value));
83 e_source_mail_identity_set_name (
84 E_SOURCE_MAIL_IDENTITY (object),
85 g_value_get_string (value));
88 case PROP_ORGANIZATION:
89 e_source_mail_identity_set_organization (
90 E_SOURCE_MAIL_IDENTITY (object),
91 g_value_get_string (value));
95 e_source_mail_identity_set_reply_to (
96 E_SOURCE_MAIL_IDENTITY (object),
97 g_value_get_string (value));
100 case PROP_SIGNATURE_UID:
101 e_source_mail_identity_set_signature_uid (
102 E_SOURCE_MAIL_IDENTITY (object),
103 g_value_get_string (value));
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
111 source_mail_identity_get_property (GObject *object,
116 switch (property_id) {
118 g_value_take_string (
120 e_source_mail_identity_dup_address (
121 E_SOURCE_MAIL_IDENTITY (object)));
125 g_value_take_string (
127 e_source_mail_identity_dup_name (
128 E_SOURCE_MAIL_IDENTITY (object)));
131 case PROP_ORGANIZATION:
132 g_value_take_string (
134 e_source_mail_identity_dup_organization (
135 E_SOURCE_MAIL_IDENTITY (object)));
139 g_value_take_string (
141 e_source_mail_identity_dup_reply_to (
142 E_SOURCE_MAIL_IDENTITY (object)));
145 case PROP_SIGNATURE_UID:
146 g_value_take_string (
148 e_source_mail_identity_dup_signature_uid (
149 E_SOURCE_MAIL_IDENTITY (object)));
153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
157 source_mail_identity_finalize (GObject *object)
159 ESourceMailIdentityPrivate *priv;
161 priv = E_SOURCE_MAIL_IDENTITY_GET_PRIVATE (object);
163 g_mutex_clear (&priv->property_lock);
165 g_free (priv->address);
167 g_free (priv->organization);
168 g_free (priv->reply_to);
169 g_free (priv->signature_uid);
171 /* Chain up to parent's finalize() method. */
172 G_OBJECT_CLASS (e_source_mail_identity_parent_class)->finalize (object);
176 e_source_mail_identity_class_init (ESourceMailIdentityClass *class)
178 GObjectClass *object_class;
179 ESourceExtensionClass *extension_class;
181 g_type_class_add_private (class, sizeof (ESourceMailIdentityPrivate));
183 object_class = G_OBJECT_CLASS (class);
184 object_class->set_property = source_mail_identity_set_property;
185 object_class->get_property = source_mail_identity_get_property;
186 object_class->finalize = source_mail_identity_finalize;
188 extension_class = E_SOURCE_EXTENSION_CLASS (class);
189 extension_class->name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
191 g_object_class_install_property (
194 g_param_spec_string (
197 "Sender's email address",
201 G_PARAM_STATIC_STRINGS |
202 E_SOURCE_PARAM_SETTING));
204 g_object_class_install_property (
207 g_param_spec_string (
214 G_PARAM_STATIC_STRINGS |
215 E_SOURCE_PARAM_SETTING));
217 g_object_class_install_property (
220 g_param_spec_string (
223 "Sender's organization",
227 G_PARAM_STATIC_STRINGS |
228 E_SOURCE_PARAM_SETTING));
230 g_object_class_install_property (
233 g_param_spec_string (
236 "Sender's reply-to address",
240 G_PARAM_STATIC_STRINGS |
241 E_SOURCE_PARAM_SETTING));
243 g_object_class_install_property (
246 g_param_spec_string (
249 "ESource UID of the sender's signature",
253 G_PARAM_STATIC_STRINGS |
254 E_SOURCE_PARAM_SETTING));
258 e_source_mail_identity_init (ESourceMailIdentity *extension)
260 extension->priv = E_SOURCE_MAIL_IDENTITY_GET_PRIVATE (extension);
261 g_mutex_init (&extension->priv->property_lock);
265 * e_source_mail_identity_get_address:
266 * @extension: an #ESourceMailIdentity
268 * Returns the email address for this identity from which to send messages.
269 * This may be an empty string but will never be %NULL.
271 * Returns: the sender's email address
276 e_source_mail_identity_get_address (ESourceMailIdentity *extension)
278 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
280 return extension->priv->address;
284 * e_source_mail_identity_dup_address:
285 * @extension: an #ESourceMailIdentity
287 * Thread-safe variation of e_source_mail_identity_get_address().
288 * Use this function when accessing @extension from multiple threads.
290 * The returned string should be freed with g_free() when no longer needed.
292 * Returns: a newly-allocated copy of #ESourceMailIdentity:address
297 e_source_mail_identity_dup_address (ESourceMailIdentity *extension)
299 const gchar *protected;
302 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
304 g_mutex_lock (&extension->priv->property_lock);
306 protected = e_source_mail_identity_get_address (extension);
307 duplicate = g_strdup (protected);
309 g_mutex_unlock (&extension->priv->property_lock);
315 * e_source_mail_identity_set_address:
316 * @extension: an #ESourceMailIdentity
317 * @address: (allow-none): the sender's email address, or %NULL
319 * Sets the email address for this identity from which to send messages.
321 * The internal copy of @address is automatically stripped of leading and
322 * trailing whitespace. If the resulting string is empty, %NULL is set
328 e_source_mail_identity_set_address (ESourceMailIdentity *extension,
329 const gchar *address)
331 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
333 g_mutex_lock (&extension->priv->property_lock);
335 if (g_strcmp0 (extension->priv->address, address) == 0) {
336 g_mutex_unlock (&extension->priv->property_lock);
340 g_free (extension->priv->address);
341 extension->priv->address = e_util_strdup_strip (address);
343 g_mutex_unlock (&extension->priv->property_lock);
345 g_object_notify (G_OBJECT (extension), "address");
349 * e_source_mail_identity_get_name:
350 * @extension: an #ESourceMailIdentity
352 * Returns the sender's name for this identity.
354 * Returns: the sender's name
359 e_source_mail_identity_get_name (ESourceMailIdentity *extension)
361 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
363 return extension->priv->name;
367 * e_source_mail_identity_dup_name:
368 * @extension: an #ESourceMailIdentity
370 * Thread-safe variation of e_source_mail_identity_get_name().
371 * Use this function when accessing @extension from multiple threads.
373 * The returned string should be freed with g_free() when no longer needed.
375 * Returns: a newly-allocated copy of #ESourceMailIdentity:name
380 e_source_mail_identity_dup_name (ESourceMailIdentity *extension)
382 const gchar *protected;
385 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
387 g_mutex_lock (&extension->priv->property_lock);
389 protected = e_source_mail_identity_get_name (extension);
390 duplicate = g_strdup (protected);
392 g_mutex_unlock (&extension->priv->property_lock);
398 * e_source_mail_identity_set_name:
399 * @extension: an #ESourceMailIdentity
400 * @name: (allow-none): the sender's name, or %NULL
402 * Sets the sender's name for this identity.
404 * The internal copy of @name is automatically stripped of leading and
405 * trailing whitespace. If @name is %NULL or the resulting string is
406 * empty, the result of g_get_real_name() is set instead.
411 e_source_mail_identity_set_name (ESourceMailIdentity *extension,
414 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
416 g_mutex_lock (&extension->priv->property_lock);
418 if (extension->priv->name != NULL &&
419 g_strcmp0 (extension->priv->name, name) == 0) {
420 g_mutex_unlock (&extension->priv->property_lock);
424 g_free (extension->priv->name);
425 extension->priv->name = e_util_strdup_strip (name);
427 if (extension->priv->name == NULL)
428 extension->priv->name = g_strdup (g_get_real_name ());
430 g_mutex_unlock (&extension->priv->property_lock);
432 g_object_notify (G_OBJECT (extension), "name");
436 * e_source_mail_identity_get_organization:
437 * @extension: an #ESourceMailIdentity
439 * Returns the sender's organization for this identity.
441 * Returns: the sender's organization
446 e_source_mail_identity_get_organization (ESourceMailIdentity *extension)
448 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
450 return extension->priv->organization;
454 * e_source_mail_identity_dup_organization:
455 * @extension: an #ESourceMailIdentity
457 * Thread-safe variation of e_source_mail_identity_dup_organization().
458 * Use this function when accessing @extension from multiple threads.
460 * The returned string should be freed with g_free() when no longer needed.
462 * Returns: a newly-allocated copy of #ESourceMailIdentity:organization
467 e_source_mail_identity_dup_organization (ESourceMailIdentity *extension)
469 const gchar *protected;
472 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
474 g_mutex_lock (&extension->priv->property_lock);
476 protected = e_source_mail_identity_get_organization (extension);
477 duplicate = g_strdup (protected);
479 g_mutex_unlock (&extension->priv->property_lock);
485 * e_source_mail_identity_set_organization:
486 * @extension: an #ESourceMailIdentity
487 * @organization: (allow-none): the sender's organization, or %NULL
489 * Sets the sender's organization for this identity.
491 * The internal copy of @organization is automatically stripped of leading
492 * and trailing whitespace. If the resulting string is empty, %NULL is set
498 e_source_mail_identity_set_organization (ESourceMailIdentity *extension,
499 const gchar *organization)
501 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
503 g_mutex_lock (&extension->priv->property_lock);
505 if (g_strcmp0 (extension->priv->organization, organization) == 0) {
506 g_mutex_unlock (&extension->priv->property_lock);
510 g_free (extension->priv->organization);
511 extension->priv->organization = e_util_strdup_strip (organization);
513 g_mutex_unlock (&extension->priv->property_lock);
515 g_object_notify (G_OBJECT (extension), "organization");
519 * e_source_mail_identity_get_reply_to:
520 * @extension: an #ESourceMailIdentity
522 * Returns the email address for this identity to which recipients should
525 * Returns: the sender's reply-to address
530 e_source_mail_identity_get_reply_to (ESourceMailIdentity *extension)
532 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
534 return extension->priv->reply_to;
538 * e_source_mail_identity_dup_reply_to:
539 * @extension: an #ESourceMailIdentity
541 * Thread-safe variation of e_source_mail_identity_get_reply_to().
542 * Use this function when accessing @extension from multiple threads.
544 * The returned string should be freed with g_free() when no longer needed.
546 * Returns: a newly-allocated copy of #ESourceMailIdentity:reply-to
551 e_source_mail_identity_dup_reply_to (ESourceMailIdentity *extension)
553 const gchar *protected;
556 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
558 g_mutex_lock (&extension->priv->property_lock);
560 protected = e_source_mail_identity_get_reply_to (extension);
561 duplicate = g_strdup (protected);
563 g_mutex_unlock (&extension->priv->property_lock);
569 * e_source_mail_identity_set_reply_to:
570 * @extension: an #ESourceMailIdentity
571 * @reply_to: (allow-none): the sender's reply-to address, or %NULL
573 * Sets the email address for this identity to which recipients should
576 * The internal copy of @reply_to is automatically stripped of leading
577 * and trailing whitespace. If the resulting string is empty, %NULL is
583 e_source_mail_identity_set_reply_to (ESourceMailIdentity *extension,
584 const gchar *reply_to)
586 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
588 g_mutex_lock (&extension->priv->property_lock);
590 if (g_strcmp0 (extension->priv->reply_to, reply_to) == 0) {
591 g_mutex_unlock (&extension->priv->property_lock);
595 g_free (extension->priv->reply_to);
596 extension->priv->reply_to = e_util_strdup_strip (reply_to);
598 g_mutex_unlock (&extension->priv->property_lock);
600 g_object_notify (G_OBJECT (extension), "reply-to");
604 * e_source_mail_identity_get_signature_uid:
605 * @extension: an #ESourceMailIdentity
607 * Returns the #ESource:uid of an #ESource describing a mail signature.
609 * If the user does not want to use a signature for this identity, the
610 * convention is to set the #ESourceMailIdentity:signature-uid property
613 * Returns: the sender's signature ID, or "none"
618 e_source_mail_identity_get_signature_uid (ESourceMailIdentity *extension)
620 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
622 return extension->priv->signature_uid;
626 * e_source_mail_identity_dup_signature_uid:
627 * @extension: an #ESourceMailIdentity
629 * Thread-safe variation of e_source_mail_identity_get_signature_uid().
630 * Use this function when accessing @extension from multiple threads.
632 * The returned string should be freed with g_free() when no longer needed.
634 * Returns: a newly-allocated copy of #ESourceMailIdentity:signature-uid
639 e_source_mail_identity_dup_signature_uid (ESourceMailIdentity *extension)
641 const gchar *protected;
644 g_return_val_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension), NULL);
646 g_mutex_lock (&extension->priv->property_lock);
648 protected = e_source_mail_identity_get_signature_uid (extension);
649 duplicate = g_strdup (protected);
651 g_mutex_unlock (&extension->priv->property_lock);
657 * e_source_mail_identity_set_signature_uid:
658 * @extension: an #ESourceMailIdentity
659 * @signature_uid: (allow-none): the sender's signature ID, or %NULL
661 * Sets the #ESource:uid of an #ESource describing a mail signature.
663 * If the user does not want to use a signature for this identity, the
664 * convention is to set the #ESourceMailIdentity:signature-uid property
665 * to "none". In keeping with that convention, the property will be set
666 * to "none" if @signature is %NULL or an empty string.
671 e_source_mail_identity_set_signature_uid (ESourceMailIdentity *extension,
672 const gchar *signature_uid)
674 g_return_if_fail (E_IS_SOURCE_MAIL_IDENTITY (extension));
676 /* Convert empty strings to "none". */
677 if (signature_uid == NULL || *signature_uid == '\0')
678 signature_uid = "none";
680 g_mutex_lock (&extension->priv->property_lock);
682 if (g_strcmp0 (extension->priv->signature_uid, signature_uid) == 0) {
683 g_mutex_unlock (&extension->priv->property_lock);
687 g_free (extension->priv->signature_uid);
688 extension->priv->signature_uid = g_strdup (signature_uid);
690 g_mutex_unlock (&extension->priv->property_lock);
692 g_object_notify (G_OBJECT (extension), "signature-uid");