Re: Patch: improvements to TnyCamelMsgHeader TnyCamelHeader proxy feature
- From: Jose Dapena Paz <jdapena igalia com>
- To: Philip Van Hoof <spam pvanhoof be>
- Cc: tinymail-devel-list <tinymail-devel-list gnome org>
- Subject: Re: Patch: improvements to TnyCamelMsgHeader TnyCamelHeader proxy feature
- Date: Wed, 12 Dec 2007 13:31:41 +0100
El mié, 12-12-2007 a las 11:42 +0100, Philip Van Hoof escribió:
> On Wed, 2007-12-12 at 10:30 +0100, Jose Dapena Paz wrote:
> > if (uid && uid[0] != '/' && strlen (uid) > 0)
> > {
> > - info = camel_message_info_new_uid (NULL, uid);
> > + info = camel_folder_get_message_info (priv->folder,
> > uid);
>
> What if the UID does not exist in the folder? Then info will be NULL.
> This is very different from the current situation.
Attached a new patch. Some small changes:
* One is checking if message info is null, and then setting an error
and returning NULL.
* Other is making sure the TnyCamelMsgHeader proxy does a g_object_ref
on the TnyCamelHeader for the find_msg method.
--
Jose Dapena Paz <jdapena igalia com>
Igalia
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c (revision 3100)
+++ libtinymail-camel/tny-camel-folder.c (working copy)
@@ -176,7 +176,6 @@
{
TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (priv->account);
- TnyIterator *iter;
GList *list, *list_iter;
g_static_rec_mutex_lock (priv->obs_lock);
@@ -2459,18 +2458,30 @@
if (uid && uid[0] != '/' && strlen (uid) > 0)
{
- info = camel_message_info_new_uid (NULL, uid);
- hdr = _tny_camel_header_new ();
+ TnyHeader *nhdr;
+ info = camel_folder_get_message_info (priv->folder, uid);
+ if (info == NULL) {
+ g_warning ("%s: uid %s not found in folder %s", __FUNCTION__,
+ uid, self ? tny_folder_get_name (self):"none");
+ g_set_error (err, TNY_FOLDER_ERROR, TNY_FOLDER_ERROR_GET_MSG,
+ "Message uid not found in folder");
+ retval = NULL;
+ } else {
+ hdr = _tny_camel_header_new ();
+ _tny_camel_header_set_folder ((TnyCamelHeader *) hdr, (TnyCamelFolder *) self, priv);
+ _tny_camel_header_set_camel_message_info ((TnyCamelHeader *) hdr, info, FALSE);
+
+ retval = tny_msg_receive_strategy_perform_get_msg (priv->receive_strat, self, hdr, err);
+ if (retval) {
+ nhdr = tny_msg_get_header (retval);
+ /* This trick is for forcing owning a TnyCamelHeader reference */
+ _tny_camel_msg_header_set_decorated (nhdr, hdr, TRUE);
+ g_object_unref (nhdr);
+ }
+ g_object_unref (hdr);
+ reset_local_size (priv);
+ }
- /* This adds a reason to live to self */
- _tny_camel_header_set_folder (TNY_CAMEL_HEADER (hdr),
- TNY_CAMEL_FOLDER (self), priv);
- /* hdr will take care of the freeup */
- _tny_camel_header_set_as_memory (TNY_CAMEL_HEADER (hdr), info);
- retval = tny_msg_receive_strategy_perform_get_msg (priv->receive_strat, self, hdr, err);
- g_object_unref (hdr);
- reset_local_size (priv);
-
} else {
g_warning ("%s: malformed url string: %s", __FUNCTION__, url_string);
g_set_error (err, TNY_FOLDER_ERROR,
@@ -4410,7 +4421,6 @@
TnyFolder *folder; CamelFolderInfo *info;
TnyFolderStoreChange *change;
CamelException subex = CAMEL_EXCEPTION_INITIALISER;
- TnyCamelFolderPriv *rpriv = NULL;
gboolean was_new = FALSE;
if (!_tny_session_check_operation (TNY_FOLDER_PRIV_GET_SESSION(priv),
@@ -5285,6 +5295,8 @@
if (apriv->service)
{
char *urls = camel_service_get_url (apriv->service);
+ if (!priv->folder)
+ load_folder_no_lock (priv);
const char *foln = camel_folder_get_full_name (priv->folder);
retval = g_strdup_printf ("%s/%s", urls, foln);
g_free (urls);
Index: libtinymail-camel/tny-camel-full-msg-receive-strategy.c
===================================================================
--- libtinymail-camel/tny-camel-full-msg-receive-strategy.c (revision 3100)
+++ libtinymail-camel/tny-camel-full-msg-receive-strategy.c (working copy)
@@ -92,7 +92,7 @@
nheader = _tny_camel_msg_header_new (CAMEL_MIME_MESSAGE (camel_message),
folder, tny_header_get_date_received (header));
- _tny_camel_msg_header_set_decorated (TNY_CAMEL_MSG_HEADER (nheader), header);
+ _tny_camel_msg_header_set_decorated (TNY_CAMEL_MSG_HEADER (nheader), header, FALSE);
message = tny_camel_msg_new ();
_tny_camel_msg_set_received (TNY_CAMEL_MSG (message),
Index: libtinymail-camel/tny-camel-partial-msg-receive-strategy.c
===================================================================
--- libtinymail-camel/tny-camel-partial-msg-receive-strategy.c (revision 3100)
+++ libtinymail-camel/tny-camel-partial-msg-receive-strategy.c (working copy)
@@ -93,7 +93,7 @@
nheader = _tny_camel_msg_header_new (CAMEL_MIME_MESSAGE (camel_message), folder,
tny_header_get_date_received (header));
- _tny_camel_msg_header_set_decorated (TNY_CAMEL_MSG_HEADER (nheader), header);
+ _tny_camel_msg_header_set_decorated (TNY_CAMEL_MSG_HEADER (nheader), header, FALSE);
message = tny_camel_msg_new ();
_tny_camel_msg_set_received (TNY_CAMEL_MSG (message),
tny_header_get_date_received (header));
Index: libtinymail-camel/tny-camel-msg-header.c
===================================================================
--- libtinymail-camel/tny-camel-msg-header.c (revision 3100)
+++ libtinymail-camel/tny-camel-msg-header.c (working copy)
@@ -464,6 +464,7 @@
{
TnyCamelMsgHeader *me = (TnyCamelMsgHeader *) user_data;
me->decorated = NULL;
+ me->decorated_has_ref = FALSE;
}
static void
@@ -488,7 +489,10 @@
g_free (me->old_uid);
if (me->decorated) {
- g_object_weak_unref (G_OBJECT (me->decorated), notify_decorated_del, me);
+ if (me->decorated_has_ref)
+ g_object_unref (me->decorated);
+ else
+ g_object_weak_unref (G_OBJECT (me->decorated), notify_decorated_del, me);
me->decorated = NULL;
}
@@ -527,6 +531,7 @@
self->has_received = FALSE;
self->partial = FALSE;
self->decorated = NULL;
+ self->decorated_has_ref = FALSE;
self->to = NULL;
self->from = NULL;
self->cc = NULL;
@@ -540,14 +545,22 @@
void
_tny_camel_msg_header_set_decorated (TnyCamelMsgHeader *header,
- TnyHeader *decorated)
+ TnyHeader *decorated,
+ gboolean add_reference)
{
g_assert (TNY_IS_HEADER (decorated));
if (header->decorated) {
- g_object_weak_unref (G_OBJECT (decorated), notify_decorated_del, header);
+ if (header->decorated_has_ref)
+ g_object_unref (header->decorated);
+ else
+ g_object_weak_unref (G_OBJECT (header->decorated), notify_decorated_del, header);
}
+ header->decorated_has_ref = add_reference;
- g_object_weak_ref (G_OBJECT (decorated), notify_decorated_del, header);
+ if (add_reference)
+ g_object_ref (decorated);
+ else
+ g_object_weak_ref (G_OBJECT (decorated), notify_decorated_del, header);
header->decorated = decorated;
Index: libtinymail-camel/tny-camel-msg-header-priv.h
===================================================================
--- libtinymail-camel/tny-camel-msg-header-priv.h (revision 3100)
+++ libtinymail-camel/tny-camel-msg-header-priv.h (working copy)
@@ -54,6 +54,7 @@
time_t received;
gboolean partial;
TnyHeader *decorated;
+ gboolean decorated_has_ref;
};
struct _TnyCamelMsgHeaderClass
@@ -64,7 +65,7 @@
GType tny_camel_msg_header_get_type (void);
TnyHeader* _tny_camel_msg_header_new (CamelMimeMessage *msg, TnyFolder *folder, time_t received);
-void _tny_camel_msg_header_set_decorated (TnyCamelMsgHeader *header, TnyHeader *decorated);
+void _tny_camel_msg_header_set_decorated (TnyCamelMsgHeader *header, TnyHeader *decorated, gboolean add_reference);
G_END_DECLS
Index: ChangeLog
===================================================================
--- ChangeLog (revision 3100)
+++ ChangeLog (working copy)
@@ -1,3 +1,19 @@
+2007-12-12 Jose Dapena Paz <jdapena igalia com>
+
+ * libtinymail-camel/tny-camel-folder.c: load camel folder before
+ getting the url string of it.
+ * libtinymail-camel/tny-camel-msg-header.c: now the decorated header
+ can be added with g_object_ref or a weak reference.
+ * libtinymail-camel/tny-camel-folder.c: now the TnyCamelHeader we
+ use to retrieve the message in find_msg is constructed from summary.
+ This is created in a way it's persistent, and then, we can access
+ properly to the summary flags. We also eturn null and set error if
+ message is not in summary.
+ * libtinymail-camel/tny-camel-full-msg-receive-strategy.c
+ libtinymail-camel/tny-camel-partial-msg-receive-strategy.c:
+ use the new TnyCamelMsgHeader decorator api.
+ * Fixed minor build issues.
+
2007-12-11 Philip Van Hoof <pvanhoof gnome org>
* Repeated the bugfix of Sergio to the other locations where the same
Index: libtinymail/tny-merge-folder.c
===================================================================
--- libtinymail/tny-merge-folder.c (revision 3100)
+++ libtinymail/tny-merge-folder.c (working copy)
@@ -51,7 +51,6 @@
notify_folder_observers_about (TnyFolder *self, TnyFolderChange *change)
{
TnyMergeFolderPriv *priv = TNY_MERGE_FOLDER_GET_PRIVATE (self);
- TnyIterator *iter;
GList *list, *list_iter;
g_static_rec_mutex_lock (priv->lock);
@@ -1015,7 +1014,6 @@
static void
tny_merge_folder_transfer_msgs (TnyFolder *self, TnyList *header_list, TnyFolder *folder_dst, gboolean delete_originals, GError **err)
{
- TnyMergeFolderPriv *priv = TNY_MERGE_FOLDER_GET_PRIVATE (self);
TnyIterator *iter;
iter = tny_list_create_iterator (header_list);
@@ -1100,8 +1098,6 @@
transfer_msgs_async_thread (gpointer thr_user_data)
{
TransferMsgsInfo *info = thr_user_data;
- TnyFolder *self = info->self;
- TnyMergeFolderPriv *priv = TNY_MERGE_FOLDER_GET_PRIVATE (self);
tny_merge_folder_transfer_msgs (info->self, info->header_list, info->folder_dst, info->delete_originals, &info->err);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]