2 * e-source-mail-submission.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-submission
21 * @include: libedataserver/libedataserver.h
22 * @short_description: #ESource extension for submitting emails
24 * The #ESourceMailSubmission extension tracks settings to be applied
25 * when submitting a mail message for delivery.
27 * Access the extension as follows:
30 * #include <libedataserver/e-source-mail-submission.h>
32 * ESourceMailSubmission *extension;
34 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_SUBMISSION);
38 #include "e-source-mail-submission.h"
40 #include <libedataserver/e-data-server-util.h>
42 #define E_SOURCE_MAIL_SUBMISSION_GET_PRIVATE(obj) \
43 (G_TYPE_INSTANCE_GET_PRIVATE \
44 ((obj), E_TYPE_SOURCE_MAIL_SUBMISSION, ESourceMailSubmissionPrivate))
46 struct _ESourceMailSubmissionPrivate {
47 GMutex *property_lock;
59 ESourceMailSubmission,
60 e_source_mail_submission,
61 E_TYPE_SOURCE_EXTENSION)
64 source_mail_submission_set_property (GObject *object,
69 switch (property_id) {
70 case PROP_SENT_FOLDER:
71 e_source_mail_submission_set_sent_folder (
72 E_SOURCE_MAIL_SUBMISSION (object),
73 g_value_get_string (value));
76 case PROP_TRANSPORT_UID:
77 e_source_mail_submission_set_transport_uid (
78 E_SOURCE_MAIL_SUBMISSION (object),
79 g_value_get_string (value));
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
87 source_mail_submission_get_property (GObject *object,
92 switch (property_id) {
93 case PROP_SENT_FOLDER:
96 e_source_mail_submission_dup_sent_folder (
97 E_SOURCE_MAIL_SUBMISSION (object)));
100 case PROP_TRANSPORT_UID:
101 g_value_take_string (
103 e_source_mail_submission_dup_transport_uid (
104 E_SOURCE_MAIL_SUBMISSION (object)));
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
112 source_mail_submission_finalize (GObject *object)
114 ESourceMailSubmissionPrivate *priv;
116 priv = E_SOURCE_MAIL_SUBMISSION_GET_PRIVATE (object);
118 g_mutex_free (priv->property_lock);
120 g_free (priv->sent_folder);
121 g_free (priv->transport_uid);
123 /* Chain up to parent's finalize() method. */
124 G_OBJECT_CLASS (e_source_mail_submission_parent_class)->
129 e_source_mail_submission_class_init (ESourceMailSubmissionClass *class)
131 GObjectClass *object_class;
132 ESourceExtensionClass *extension_class;
134 g_type_class_add_private (
135 class, sizeof (ESourceMailSubmissionPrivate));
137 object_class = G_OBJECT_CLASS (class);
138 object_class->set_property = source_mail_submission_set_property;
139 object_class->get_property = source_mail_submission_get_property;
140 object_class->finalize = source_mail_submission_finalize;
142 extension_class = E_SOURCE_EXTENSION_CLASS (class);
143 extension_class->name = E_SOURCE_EXTENSION_MAIL_SUBMISSION;
145 g_object_class_install_property (
148 g_param_spec_string (
151 "Preferred folder for sent messages",
155 G_PARAM_STATIC_STRINGS |
156 E_SOURCE_PARAM_SETTING));
158 g_object_class_install_property (
161 g_param_spec_string (
164 "ESource UID of a Mail Transport",
168 G_PARAM_STATIC_STRINGS |
169 E_SOURCE_PARAM_SETTING));
173 e_source_mail_submission_init (ESourceMailSubmission *extension)
175 extension->priv = E_SOURCE_MAIL_SUBMISSION_GET_PRIVATE (extension);
176 extension->priv->property_lock = g_mutex_new ();
180 * e_source_mail_submission_get_sent_folder:
181 * @extension: an #ESourceMailSubmission
183 * Returns a string identifying the preferred folder for sent messages.
184 * The format of the identifier string is defined by the client application.
186 * Returns: an identifier for the preferred sent folder
191 e_source_mail_submission_get_sent_folder (ESourceMailSubmission *extension)
193 g_return_val_if_fail (E_IS_SOURCE_MAIL_SUBMISSION (extension), NULL);
195 return extension->priv->sent_folder;
199 * e_source_mail_submission_dup_sent_folder:
200 * @extension: an #ESourceMailSubmission
202 * Thread-safe variation of e_source_mail_submission_get_sent_folder().
203 * Use this function when accessing @extension from multiple threads.
205 * The returned string should be freed with g_free() when no longer needed.
207 * Returns: a newly-allocated copy of #ESourceMailSubmission:sent-folder
212 e_source_mail_submission_dup_sent_folder (ESourceMailSubmission *extension)
214 const gchar *protected;
217 g_return_val_if_fail (E_IS_SOURCE_MAIL_SUBMISSION (extension), NULL);
219 g_mutex_lock (extension->priv->property_lock);
221 protected = e_source_mail_submission_get_sent_folder (extension);
222 duplicate = g_strdup (protected);
224 g_mutex_unlock (extension->priv->property_lock);
230 * e_source_mail_submission_set_sent_folder:
231 * @extension: an #ESourceMailSubmission
232 * @sent_folder: (allow-none): an identifier for the preferred sent folder,
235 * Sets the preferred folder for sent messages by an identifier string.
236 * The format of the identifier string is defined by the client application.
238 * The internal copy of @sent_folder is automatically stripped of leading
239 * and trailing whitespace. If the resulting string is empty, %NULL is set
245 e_source_mail_submission_set_sent_folder (ESourceMailSubmission *extension,
246 const gchar *sent_folder)
248 g_return_if_fail (E_IS_SOURCE_MAIL_SUBMISSION (extension));
250 g_mutex_lock (extension->priv->property_lock);
252 if (g_strcmp0 (extension->priv->sent_folder, sent_folder) == 0) {
253 g_mutex_unlock (extension->priv->property_lock);
257 g_free (extension->priv->sent_folder);
258 extension->priv->sent_folder = e_util_strdup_strip (sent_folder);
260 g_mutex_unlock (extension->priv->property_lock);
262 g_object_notify (G_OBJECT (extension), "sent-folder");
266 * e_source_mail_submission_get_transport_uid:
267 * @extension: an #ESourceMailSubmission
269 * Returns the #ESource:uid of the #ESource that describes the mail
270 * transport to be used for outgoing messages.
272 * Returns: the mail transport #ESource:uid
277 e_source_mail_submission_get_transport_uid (ESourceMailSubmission *extension)
279 g_return_val_if_fail (E_IS_SOURCE_MAIL_SUBMISSION (extension), NULL);
281 return extension->priv->transport_uid;
285 * e_source_mail_submission_dup_transport_uid:
286 * @extension: an #ESourceMailSubmission
288 * Thread-safe variation of e_source_mail_submission_get_transport_uid().
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 #ESourceMailSubmission:transport-uid
298 e_source_mail_submission_dup_transport_uid (ESourceMailSubmission *extension)
300 const gchar *protected;
303 g_return_val_if_fail (E_IS_SOURCE_MAIL_SUBMISSION (extension), NULL);
305 g_mutex_lock (extension->priv->property_lock);
307 protected = e_source_mail_submission_get_transport_uid (extension);
308 duplicate = g_strdup (protected);
310 g_mutex_unlock (extension->priv->property_lock);
316 * e_source_mail_submission_set_transport_uid:
317 * @extension: an #ESourceMailSubmission
318 * @transport_uid: (allow-none): the mail transport #ESource:uid, or %NULL
320 * Sets the #ESource:uid of the #ESource that describes the mail
321 * transport to be used for outgoing messages.
326 e_source_mail_submission_set_transport_uid (ESourceMailSubmission *extension,
327 const gchar *transport_uid)
329 g_return_if_fail (E_IS_SOURCE_MAIL_SUBMISSION (extension));
331 g_mutex_lock (extension->priv->property_lock);
333 if (g_strcmp0 (extension->priv->transport_uid, transport_uid) == 0) {
334 g_mutex_unlock (extension->priv->property_lock);
338 g_free (extension->priv->transport_uid);
339 extension->priv->transport_uid = g_strdup (transport_uid);
341 g_mutex_unlock (extension->priv->property_lock);
343 g_object_notify (G_OBJECT (extension), "transport-uid");