1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* Evolution calendar - generic backend class
4 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
6 * Authors: Rodrigo Moya <rodrigo@ximian.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU Lesser General Public
10 * License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <glib/gi18n-lib.h>
28 #include "e-cal-backend-util.h"
29 #include <libedataserver/e-source-mail-account.h>
30 #include <libedataserver/e-source-mail-identity.h>
33 * e_cal_backend_mail_account_get_default:
34 * @registry: an #ESourceRegistry
35 * @address: placeholder for default address
36 * @name: placeholder for name
38 * Retrieve the default mail account as stored in Evolution configuration.
40 * Returns: TRUE if there is a default account, FALSE otherwise.
43 e_cal_backend_mail_account_get_default (ESourceRegistry *registry,
48 ESourceMailIdentity *extension;
49 const gchar *extension_name;
51 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
53 source = e_source_registry_ref_default_mail_identity (registry);
58 extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
59 extension = e_source_get_extension (source, extension_name);
62 *address = e_source_mail_identity_dup_address (extension);
65 *name = e_source_mail_identity_dup_name (extension);
67 g_object_unref (source);
73 * e_cal_backend_mail_account_is_valid:
74 * @registry: an #ESourceRegistry
75 * @user: user name for the account to check
76 * @name: placeholder for the account name
78 * Checks that a mail account is valid, and returns its name.
80 * Returns: TRUE if the account is valid, FALSE if not.
83 e_cal_backend_mail_account_is_valid (ESourceRegistry *registry,
88 const gchar *extension_name;
89 gboolean valid = FALSE;
91 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
92 g_return_val_if_fail (user != NULL, FALSE);
94 extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
96 list = e_source_registry_list_sources (registry, extension_name);
98 for (iter = list; iter != NULL; iter = g_list_next (iter)) {
99 ESource *source = E_SOURCE (iter->data);
100 ESourceMailAccount *mail_account;
101 ESourceMailIdentity *mail_identity;
103 gboolean match = FALSE;
106 if (!e_source_get_enabled (source))
109 extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
110 mail_account = e_source_get_extension (source, extension_name);
111 uid = e_source_mail_account_get_identity_uid (mail_account);
116 source = e_source_registry_ref_source (registry, uid);
121 extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
123 if (!e_source_has_extension (source, extension_name)) {
124 g_object_unref (source);
128 mail_identity = e_source_get_extension (source, extension_name);
129 address = e_source_mail_identity_dup_address (mail_identity);
131 if (address != NULL) {
132 match = (g_ascii_strcasecmp (address, user) == 0);
136 if (match && name != NULL)
137 *name = e_source_dup_display_name (source);
139 g_object_unref (source);
147 g_list_free_full (list, (GDestroyNotify) g_object_unref);
153 * is_attendee_declined:
154 * @icalcomp: Component where to check the attendee list.
155 * @email: Attendee's email to look for.
157 * Returns: Whether the required attendee declined or not.
158 * It's not necessary to have this attendee in the list.
161 is_attendee_declined (icalcomponent *icalcomp,
165 icalparameter *param;
167 g_return_val_if_fail (icalcomp != NULL, FALSE);
168 g_return_val_if_fail (email != NULL, FALSE);
170 for (prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTENDEE_PROPERTY);
172 prop = icalcomponent_get_next_property (icalcomp, ICAL_ATTENDEE_PROPERTY)) {
176 attendee = icalproperty_get_value_as_string_r (prop);
180 if (!g_ascii_strncasecmp (attendee, "mailto:", 7))
181 text = g_strdup (attendee + 7);
182 text = g_strstrip (text);
184 if (!g_ascii_strcasecmp (email, text)) {
196 param = icalproperty_get_first_parameter (prop, ICAL_PARTSTAT_PARAMETER);
198 return param && icalparameter_get_partstat (param) == ICAL_PARTSTAT_DECLINED;
202 * e_cal_backend_user_declined:
203 * @registry: an #ESourceRegistry
204 * @icalcomp: component where to check
206 * Returns: Whether icalcomp contains attendee with a mail same as any of
207 * configured enabled mail account and whether this user declined.
212 e_cal_backend_user_declined (ESourceRegistry *registry,
213 icalcomponent *icalcomp)
216 const gchar *extension_name;
217 gboolean declined = FALSE;
219 g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
220 g_return_val_if_fail (icalcomp != NULL, FALSE);
222 extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
224 list = e_source_registry_list_sources (registry, extension_name);
226 for (iter = list; iter != NULL; iter = g_list_next (iter)) {
227 ESource *source = E_SOURCE (iter->data);
228 ESourceMailIdentity *extension;
229 const gchar *address;
231 if (!e_source_get_enabled (source))
234 extension = e_source_get_extension (source, extension_name);
235 address = e_source_mail_identity_get_address (extension);
240 if (is_attendee_declined (icalcomp, address)) {
246 g_list_free_full (list, (GDestroyNotify) g_object_unref);