Re: A question about TnyCamelHeader
- From: Sergio Villar Senin <svillar igalia com>
- To: tinymail-devel-list gnome org
- Subject: Re: A question about TnyCamelHeader
- Date: Thu, 25 Jan 2007 16:53:30 +0100
Philip Van Hoof wrote:
> I would agree with a change (a patch) that adds checks for NULL
> everywhere and removes the "Invalid" string.
You like it? You get it! :)
Br
Index: libtinymail-camel/tny-camel-header.c
===================================================================
--- libtinymail-camel/tny-camel-header.c (revisión: 1470)
+++ libtinymail-camel/tny-camel-header.c (copia de trabajo)
@@ -41,8 +41,6 @@
static GObjectClass *parent_class = NULL;
-static const gchar *invalid = "Invalid";
-
static void
destroy_write (TnyCamelHeader *self)
{
@@ -50,7 +48,7 @@
if (((WriteInfo*)self->info)->msg)
camel_object_unref (CAMEL_OBJECT (((WriteInfo*)self->info)->msg));
- if (((WriteInfo*)self->info)->mime_from && ((WriteInfo*)self->info)->mime_from != invalid)
+ if (((WriteInfo*)self->info)->mime_from && ((WriteInfo*)self->info)->mime_from != NULL)
g_free (((WriteInfo*)self->info)->mime_from);
g_slice_free (WriteInfo, self->info);
@@ -154,14 +152,14 @@
tny_camel_header_get_replyto (TnyHeader *self)
{
TnyCamelHeader *me = TNY_CAMEL_HEADER (self);
- const gchar *retval;
+ const gchar *retval = NULL;
#ifdef HEALTHY_CHECK
if (!me->healthy || G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#else
if (G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#endif
if (G_UNLIKELY (me->write == 1))
@@ -170,10 +168,7 @@
camel_mime_message_get_reply_to (((WriteInfo*)me->info)->msg);
if (addr)
retval = camel_address_format (CAMEL_ADDRESS (addr));
- else
- retval = invalid;
- } else
- retval = invalid;
+ }
return retval;
}
@@ -293,44 +288,42 @@
tny_camel_header_get_cc (TnyHeader *self)
{
TnyCamelHeader *me = TNY_CAMEL_HEADER (self);
- const gchar *retval;
+ const gchar *retval = NULL;
#ifdef HEALTHY_CHECK
if (!me->healthy)
- return invalid;
+ return NULL;
#endif
if (G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
if (G_UNLIKELY (me->write == 1))
retval = camel_medium_get_header (CAMEL_MEDIUM (((WriteInfo*)me->info)->msg), "cc");
else
retval = camel_message_info_cc ((CamelMessageInfo*)me->info);
- return retval?retval:invalid;
+ return retval;
}
static const gchar*
tny_camel_header_get_bcc (TnyHeader *self)
{
TnyCamelHeader *me = TNY_CAMEL_HEADER (self);
- const gchar *retval;
+ const gchar *retval = NULL;
#ifdef HEALTHY_CHECK
if (!me->healthy)
- return invalid;
+ return NULL;
#endif
if (G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
if (G_UNLIKELY (me->write == 1))
retval = camel_medium_get_header (CAMEL_MEDIUM (((WriteInfo*)me->info)->msg), "bcc");
- else
- retval = invalid;
- return retval?retval:invalid;
+ return retval;
}
static TnyHeaderFlags
@@ -469,14 +462,14 @@
tny_camel_header_get_from (TnyHeader *self)
{
TnyCamelHeader *me = TNY_CAMEL_HEADER (self);
- const gchar *retval;
+ const gchar *retval = NULL;
#ifdef HEALTHY_CHECK
if (!me->healthy || G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#else
if (G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#endif
if (G_UNLIKELY (me->write == 1))
@@ -487,28 +480,28 @@
camel_mime_message_get_from (((WriteInfo*)me->info)->msg);
if (addr)
((WriteInfo*)me->info)->mime_from = camel_address_format (CAMEL_ADDRESS (addr));
- else ((WriteInfo*)me->info)->mime_from = (gchar*) invalid;
+ else ((WriteInfo*)me->info)->mime_from = NULL;
}
retval = (const gchar*)((WriteInfo*)me->info)->mime_from;
} else
retval = camel_message_info_from ((CamelMimeMessage*)me->info);
- return retval?retval:invalid;
+ return retval;
}
static const gchar*
tny_camel_header_get_subject (TnyHeader *self)
{
TnyCamelHeader *me = TNY_CAMEL_HEADER (self);
- const gchar *retval;
+ const gchar *retval = NULL;
#ifdef HEALTHY_CHECK
if (!me->healthy || G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#else
if (G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#endif
if (G_UNLIKELY (me->write == 1))
@@ -516,7 +509,7 @@
else
retval = camel_message_info_subject ((CamelMessageInfo*)me->info);
- return retval?retval:invalid;
+ return retval;
}
@@ -524,44 +517,44 @@
tny_camel_header_get_to (TnyHeader *self)
{
TnyCamelHeader *me = TNY_CAMEL_HEADER (self);
- gchar *retval;
+ const gchar *retval = NULL;
#ifdef HEALTHY_CHECK
if (!me->healthy || G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#else
if (G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#endif
if (G_UNLIKELY (me->write == 1))
- retval = (gchar*) camel_medium_get_header (CAMEL_MEDIUM (((WriteInfo*)me->info)->msg), "to");
+ retval = camel_medium_get_header (CAMEL_MEDIUM (((WriteInfo*)me->info)->msg), "to");
else
- retval = (gchar*) camel_message_info_to ((CamelMessageInfo*)me->info);
+ retval = camel_message_info_to ((CamelMessageInfo*)me->info);
- return retval?(const gchar*)retval:invalid;
+ return retval;
}
static const gchar*
tny_camel_header_get_message_id (TnyHeader *self)
{
TnyCamelHeader *me = TNY_CAMEL_HEADER (self);
- gchar *retval;
+ const gchar *retval = NULL;
#ifdef HEALTHY_CHECK
if (!me->healthy || G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#else
if (G_UNLIKELY (!me->info))
- return invalid;
+ return NULL;
#endif
if (G_UNLIKELY (me->write == 1))
- retval = (gchar*) camel_mime_message_get_message_id (((WriteInfo*)me->info)->msg);
+ retval = camel_mime_message_get_message_id (((WriteInfo*)me->info)->msg);
else
- retval = (gchar*) camel_message_info_message_id ((CamelMessageInfo*)me->info);
+ retval = camel_message_info_message_id ((CamelMessageInfo*)me->info);
- return retval?(const gchar*)retval:invalid;
+ return retval;
}
@@ -598,19 +591,19 @@
tny_camel_header_get_uid (TnyHeader *self)
{
TnyCamelHeader *me = TNY_CAMEL_HEADER (self);
- const gchar *retval;
+ const gchar *retval = NULL;
#ifdef HEALTHY_CHECK
if (!me->healthy || G_UNLIKELY (!me->info) || G_UNLIKELY (me->write == 1))
- return invalid;
+ return NULL;
#else
if (G_UNLIKELY (!me->info) || G_UNLIKELY (me->write == 1))
- return invalid;
+ return NULL;
#endif
retval = camel_message_info_uid ((CamelMessageInfo*)me->info);
- return retval?retval:invalid;
+ return retval;
}
static void
Index: libtinymailui-gtk/tny-gtk-header-view.c
===================================================================
--- libtinymailui-gtk/tny-gtk-header-view.c (revisión: 1470)
+++ libtinymailui-gtk/tny-gtk-header-view.c (copia de trabajo)
@@ -78,13 +78,21 @@
if (header && G_IS_OBJECT (header))
{
gchar *str;
+ const gchar *to, *from, *subject;
g_object_ref (G_OBJECT (header));
priv->header = header;
- gtk_label_set_text (GTK_LABEL (priv->to_label), tny_header_get_to (header));
- gtk_label_set_text (GTK_LABEL (priv->from_label), tny_header_get_from (header));
- gtk_label_set_text (GTK_LABEL (priv->subject_label), tny_header_get_subject (header));
+ to = tny_header_get_to (header);
+ from = tny_header_get_from (header);
+ subject = tny_header_get_subject (header);
+ if (to)
+ gtk_label_set_text (GTK_LABEL (priv->to_label), to);
+ if (from)
+ gtk_label_set_text (GTK_LABEL (priv->from_label), from);
+ if (subject)
+ gtk_label_set_text (GTK_LABEL (priv->subject_label), subject);
+
str = _get_readable_date (tny_header_get_date_sent (header));
gtk_label_set_text (GTK_LABEL (priv->date_label), (const gchar*)str);
g_free (str);
Index: libtinymailui-gtk/tny-gtk-msg-window.c
===================================================================
--- libtinymailui-gtk/tny-gtk-msg-window.c (revisión: 1470)
+++ libtinymailui-gtk/tny-gtk-msg-window.c (copia de trabajo)
@@ -96,10 +96,12 @@
if (msg)
{
g_assert (TNY_IS_MSG (msg));
+ const gchar *subject;
header = TNY_HEADER (tny_msg_get_header (msg));
- gtk_window_set_title (GTK_WINDOW (self),
- tny_header_get_subject (header));
+ subject = tny_header_get_subject (header);
+ if (subject)
+ gtk_window_set_title (GTK_WINDOW (self), subject);
g_object_unref (G_OBJECT (header));
}
tny_msg_view_set_msg (priv->msg_view, msg);
Index: libtinymailui-gtk/tny-gtk-header-list-model.c
===================================================================
--- libtinymailui-gtk/tny-gtk-header-list-model.c (revisión: 1470)
+++ libtinymailui-gtk/tny-gtk-header-list-model.c (copia de trabajo)
@@ -325,6 +325,7 @@
{
TnyHeader *header = NULL;
TnyGtkHeaderListModel *list_model = TNY_GTK_HEADER_LIST_MODEL (self);
+ const gchar *str;
g_return_if_fail (iter->stamp == TNY_GTK_HEADER_LIST_MODEL (self)->stamp);
g_return_if_fail (iter->user_data != NULL);
@@ -342,7 +343,9 @@
{
case TNY_GTK_HEADER_LIST_MODEL_CC_COLUMN:
g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, tny_header_get_cc (header));
+ str = tny_header_get_cc (header);
+ if (str)
+ g_value_set_string (value, str);
break;
case TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_COLUMN:
g_value_init (value, G_TYPE_STRING);
@@ -375,15 +378,21 @@
break;
case TNY_GTK_HEADER_LIST_MODEL_TO_COLUMN:
g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, tny_header_get_to (header));
+ str = tny_header_get_to (header);
+ if (str)
+ g_value_set_string (value, str);
break;
case TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN:
g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, tny_header_get_subject (header));
+ str = tny_header_get_subject (header);
+ if (str)
+ g_value_set_string (value, str);
break;
case TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN:
g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, tny_header_get_from (header));
+ str = tny_header_get_from (header);
+ if (str)
+ g_value_set_string (value, str);
break;
case TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN:
g_value_init (value, G_TYPE_INT);
Index: libtinymail/tny-folder-monitor.c
===================================================================
--- libtinymail/tny-folder-monitor.c (revisión: 1470)
+++ libtinymail/tny-folder-monitor.c (copia de trabajo)
@@ -161,8 +161,10 @@
iter = tny_list_create_iterator (list);
while (!tny_iterator_is_done (iter))
{
+ const gchar *id;
TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
- if (!strcmp (tny_header_get_uid (header), uid))
+ id = tny_header_get_uid (header);
+ if (id && (!strcmp (id, uid)))
{ found = TRUE; break; }
g_object_unref (G_OBJECT (header));
tny_iterator_next (iter);
@@ -221,8 +223,11 @@
iter = tny_list_create_iterator (list);
while (!tny_iterator_is_done (iter))
{
+ const gchar *uid;
TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
- foreach_list_remove_header (priv, tny_header_get_uid (header));
+ uid = tny_header_get_uid (header);
+ if (uid)
+ foreach_list_remove_header (priv, uid);
g_object_unref (G_OBJECT (header));
tny_iterator_next (iter);
}
Index: libtinymail/tny-header.c
===================================================================
--- libtinymail/tny-header.c (revisión: 1470)
+++ libtinymail/tny-header.c (copia de trabajo)
@@ -48,7 +48,7 @@
*
* Get the reply-to header
*
- * Return value: reply-to header
+ * Return value: reply-to header, or NULL if not found
**/
const gchar*
tny_header_get_replyto (TnyHeader *self)
@@ -173,7 +173,7 @@
*
* Get the CC header. The returned value should not be freed.
*
- * Return value: cc header as a read-only string
+ * Return value: cc header as a read-only string, or NULL if not found
*
**/
const gchar*
@@ -193,7 +193,7 @@
*
* Get the BCC header. The returned value should not be freed.
*
- * Return value: bcc header as a read-only string
+ * Return value: bcc header as a read-only string, or NULL if not found
*
**/
const gchar*
@@ -253,7 +253,7 @@
* Get an unique id of the message of which self is a message header. The
* returned value should not be freed.
*
- * Return value: Unique follow-up uid as a read-only string
+ * Return value: Unique follow-up uid as a read-only string, or NULL if not found
*
**/
const gchar*
@@ -274,7 +274,7 @@
* Get an unique id of the message of which self is a message header. The
* returned value should not be freed.
*
- * Return value: message-id header as a read-only string
+ * Return value: message-id header as a read-only string, or NULL if not found
*
**/
const gchar*
@@ -316,7 +316,7 @@
*
* Get the from header. The returned value should not be freed.
*
- * Return value: from header as a read-only string.
+ * Return value: from header as a read-only string, or NULL if not found
*
**/
const gchar*
@@ -336,7 +336,7 @@
*
* Get the subject header. The returned value should not be freed.
*
- * Return value: subject header as a read-only string.
+ * Return value: subject header as a read-only string, or NULL if not found
*
**/
const gchar*
@@ -357,7 +357,7 @@
*
* Get the to header. The returned value should not be freed.
*
- * Return value: to header as a read-only string
+ * Return value: to header as a read-only string, or NULL if not found
*
**/
const gchar*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]