detect loops across several messages
authorThorsten Maerz <torte@netztorte.de>
Thu, 2 Jan 2003 04:16:13 +0000 (04:16 +0000)
committerThorsten Maerz <torte@netztorte.de>
Thu, 2 Jan 2003 04:16:13 +0000 (04:16 +0000)
ChangeLog.claws
configure.in
src/procmsg.c

index 492316c..88378f7 100644 (file)
@@ -1,3 +1,9 @@
+2003-01-02 [thorsten]  0.8.8claws37
+
+       * src/procmsg.c
+               detect loops across several messages
+               as suggested by Christoph Hohmann
+
 2003-01-01 [match]     0.8.8claws36
 
        * src/addrindex.c
index 766a8d7..a14a4a0 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=8
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws36
+EXTRA_VERSION=claws37
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 6c7369b..2c46273 100644 (file)
@@ -1599,26 +1599,42 @@ void procmsg_msginfo_write_flags(MsgInfo *msginfo)
        g_free(destdir);
 }
 
-gboolean procmsg_msg_has_flagged_parent(MsgInfo *info, MsgPermFlags perm_flags)
+/*!
+ *\brief       check for flags (e.g. mark) in prior msgs of current thread
+ *
+ *\param       info Current message
+ *\param       perm_flags Flags to be checked
+ *\param       parentmsgs Hash of prior msgs to avoid loops
+ *
+ *\return      gboolean TRUE if perm_flags are found
+ */
+gboolean procmsg_msg_has_flagged_parent_real(MsgInfo *info,
+               MsgPermFlags perm_flags, GHashTable *parentmsgs)
 {
        MsgInfo *tmp;
 
        g_return_val_if_fail(info != NULL, FALSE);
 
        if (info != NULL && info->folder != NULL && info->inreplyto != NULL) {
-               tmp = folder_item_get_msginfo_by_msgid(info->folder, info->inreplyto);
+               tmp = folder_item_get_msginfo_by_msgid(info->folder,
+                               info->inreplyto);
                if (tmp && (tmp->flags.perm_flags & perm_flags)) {
                        procmsg_msginfo_free(tmp);
                        return TRUE;
                } else if (tmp != NULL) {
                        gboolean result;
-                       if (tmp->msgnum == info->msgnum) {
-                               debug_print("LOOP: message %s%c%d references itself\n",
-                                       folder_item_get_path(info->folder), 
+
+                       if (g_hash_table_lookup(parentmsgs, info)) {
+                               debug_print("loop detected: %s%c%d\n",
+                                       folder_item_get_path(info->folder),
                                        G_DIR_SEPARATOR, info->msgnum);
                                result = FALSE;
-                       } else
-                               result = procmsg_msg_has_flagged_parent(tmp, perm_flags);
+                       } else {
+                               g_hash_table_insert(parentmsgs, info, "1");
+                               procmsg_msg_has_flagged_parent_real(tmp,
+                                               perm_flags, parentmsgs);
+                               result = TRUE;
+                       }
                        procmsg_msginfo_free(tmp);
                        return result;
                } else {
@@ -1628,10 +1644,40 @@ gboolean procmsg_msg_has_flagged_parent(MsgInfo *info, MsgPermFlags perm_flags)
                return FALSE;
 }
 
+/*!
+ *\brief       Callback for cleaning up hash of parentmsgs
+ */
+gboolean parentmsgs_hash_remove(gpointer key,
+                            gpointer value,
+                            gpointer user_data)
+{
+       return TRUE;
+}
+
+/*!
+ *\brief       Set up list of parentmsgs
+ *             See procmsg_msg_has_flagged_parent_real()
+ */
+gboolean procmsg_msg_has_flagged_parent(MsgInfo *info, MsgPermFlags perm_flags)
+{
+       gboolean result;
+       GHashTable *parentmsgs = g_hash_table_new(NULL, NULL); 
+
+       result = procmsg_msg_has_flagged_parent_real(info, perm_flags, parentmsgs);
+       g_hash_table_foreach_remove(parentmsgs, parentmsgs_hash_remove, NULL);
+       g_hash_table_destroy(parentmsgs);
+       return result;
+}
+
+/*!
+ *\brief       Check if msgs prior in thread are marked
+ *             See procmsg_msg_has_flagged_parent_real()
+ */
 gboolean procmsg_msg_has_marked_parent(MsgInfo *info)
 {
        return procmsg_msg_has_flagged_parent(info, MSG_MARKED);
-}      
+}
+
 
 GSList *procmsg_find_children (MsgInfo *info)
 {