* src/folder.[ch]
authorChristoph Hohmann <reboot@gmx.ch>
Wed, 10 Jul 2002 13:11:25 +0000 (13:11 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Wed, 10 Jul 2002 13:11:25 +0000 (13:11 +0000)
* src/msgcache.[ch]
        Added message-id table to the cache in memory
        and functions to msgcache.c and folder.c to
        fetch MsgInfos by message id
* src/compose.c
* src/procmsg.c
        store folder and message-id of message replying
        to in queue header and set reply flag after sending
        (Closes bug #469498)

ChangeLog.claws
configure.in
src/compose.c
src/folder.c
src/folder.h
src/msgcache.c
src/msgcache.h
src/procmsg.c

index 04a5c7b..dadd255 100644 (file)
@@ -1,4 +1,17 @@
-2002-07-10     [paul]  0.7.8claws57
+2002-07-10 [christoph] 0.7.8claws58
+
+       * src/folder.[ch]
+       * src/msgcache.[ch]
+               Added message-id table to the cache in memory
+               and functions to msgcache.c and folder.c to
+               fetch MsgInfos by message id
+       * src/compose.c
+       * src/procmsg.c
+               store folder and message-id of message replying
+               to in queue header and set reply flag after sending
+               (Closes bug #469498)
+
+2002-07-10 [paul]      0.7.8claws57
 
        * AUTHORS
          man/sylpheed.1.gz
index 81a2183..07811ec 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=8
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws57
+EXTRA_VERSION=claws58
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 2acc299..031720c 100644 (file)
@@ -923,14 +923,8 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        } else
                reply_account = account;
 
-       MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
-       MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
-       if (MSG_IS_IMAP(msginfo->flags))
-               imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
-       CHANGE_FLAGS(msginfo);
-
        compose = compose_create(account, COMPOSE_REPLY);
-       compose->replyinfo = procmsg_msginfo_copy(msginfo);
+       compose->replyinfo = procmsg_msginfo_new_ref(msginfo);
 
 #if 0 /* NEW COMPOSE GUI */
        if (followup_and_reply_to) {
@@ -3432,11 +3426,19 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
        /* Save copy folder */
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
-               gchar *str;
+               gchar *savefolderid;
+               
+               savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
+               fprintf(fp, "SCF:%s\n", savefolderid);
+               g_free(savefolderid);
+       }
+       /* Message-ID of message replying to */
+       if((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
+               gchar *folderid;
                
-               str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
-               fprintf(fp, "SCF:%s\n", str);
-               g_free(str);
+               folderid = folder_item_get_identifier(compose->replyinfo->folder);
+               fprintf(fp, "RMID:%s%%%s\n", folderid, compose->replyinfo->msgid);
+               g_free(folderid);
        }
        fprintf(fp, "\n");
 
index 53caa2e..aaa7811 100644 (file)
@@ -1187,8 +1187,29 @@ MsgInfo *folder_item_fetch_msginfo(FolderItem *item, gint num)
                return msginfo;
        
        g_return_val_if_fail(folder->fetch_msginfo, NULL);
-       msginfo = folder->fetch_msginfo(folder, item, num);
-       return msginfo;
+       if((msginfo = folder->fetch_msginfo(folder, item, num)) != NULL) {
+               msgcache_add_msg(item->cache, msginfo);
+               return msginfo;
+       }
+       
+       return NULL;
+}
+
+MsgInfo *folder_item_fetch_msginfo_by_id(FolderItem *item, const gchar *msgid)
+{
+       Folder *folder;
+       MsgInfo *msginfo;
+       
+       g_return_val_if_fail(item != NULL, NULL);
+       
+       folder = item->folder;
+       if(!item->cache)
+               folder_item_read_cache(item);
+       
+       if((msginfo = msgcache_get_msg_by_id(item->cache, msgid)) != NULL)
+               return msginfo;
+
+       return NULL;
 }
 
 GSList *folder_item_get_msg_list(FolderItem *item)
index 72d2203..c0d29d8 100644 (file)
@@ -326,6 +326,8 @@ gint   folder_item_scan                     (FolderItem     *item);
 void   folder_item_scan_foreach                (GHashTable     *table);
 MsgInfo *folder_item_fetch_msginfo     (FolderItem     *item,
                                         gint            num);
+MsgInfo *folder_item_fetch_msginfo_by_id(FolderItem    *item,
+                                        const gchar    *msgid);
 GSList *folder_item_get_msg_list       (FolderItem     *item);
 gchar *folder_item_fetch_msg           (FolderItem     *item,
                                         gint            num);
index 616905c..5c059b3 100644 (file)
@@ -30,6 +30,7 @@
 
 struct _MsgCache {
        GHashTable      *msgnum_table;
+       GHashTable      *msgid_table;
        guint            memusage;
        time_t           last_access;
 };
@@ -39,7 +40,8 @@ MsgCache *msgcache_new()
        MsgCache *cache;
        
        cache = g_new0(MsgCache, 1),
-       cache->msgnum_table = g_hash_table_new(NULL, NULL);
+       cache->msgnum_table = g_hash_table_new(g_int_hash, g_int_equal);
+       cache->msgid_table = g_hash_table_new(g_str_hash, g_str_equal);
        cache->last_access = time(NULL);
 
        return cache;
@@ -56,6 +58,7 @@ void msgcache_destroy(MsgCache *cache)
        g_return_if_fail(cache != NULL);
 
        g_hash_table_foreach_remove(cache->msgnum_table, msgcache_msginfo_free_func, NULL);
+       g_hash_table_destroy(cache->msgid_table);
        g_hash_table_destroy(cache->msgnum_table);
        g_free(cache);
 }
@@ -68,7 +71,9 @@ void msgcache_add_msg(MsgCache *cache, MsgInfo *msginfo)
        g_return_if_fail(msginfo != NULL);
 
        newmsginfo = procmsg_msginfo_new_ref(msginfo);
-       g_hash_table_insert(cache->msgnum_table, GINT_TO_POINTER(msginfo->msgnum), newmsginfo);
+       g_hash_table_insert(cache->msgnum_table, &newmsginfo->msgnum, newmsginfo);
+       if(newmsginfo->msgid != NULL)
+               g_hash_table_insert(cache->msgid_table, newmsginfo->msgid, newmsginfo);
        cache->memusage += procmsg_msginfo_memusage(msginfo);
        cache->last_access = time(NULL);
 
@@ -82,13 +87,15 @@ void msgcache_remove_msg(MsgCache *cache, guint msgnum)
        g_return_if_fail(cache != NULL);
        g_return_if_fail(msgnum > 0);
 
-       msginfo = (MsgInfo *) g_hash_table_lookup(cache->msgnum_table, GINT_TO_POINTER(msgnum));
+       msginfo = (MsgInfo *) g_hash_table_lookup(cache->msgnum_table, &msgnum);
        if(!msginfo)
                return;
 
        cache->memusage -= procmsg_msginfo_memusage(msginfo);
+       if(msginfo->msgid)
+               g_hash_table_remove(cache->msgid_table, msginfo->msgid);
+       g_hash_table_remove(cache->msgnum_table, &msginfo->msgnum);
        procmsg_msginfo_free(msginfo);
-       g_hash_table_remove(cache->msgnum_table, GINT_TO_POINTER(msgnum));
        cache->last_access = time(NULL);
 
        debug_print(_("Cache size: %d messages, %d byte\n"), g_hash_table_size(cache->msgnum_table), cache->memusage);
@@ -101,15 +108,18 @@ void msgcache_update_msg(MsgCache *cache, MsgInfo *msginfo)
        g_return_if_fail(cache != NULL);
        g_return_if_fail(msginfo != NULL);
 
-       oldmsginfo = g_hash_table_lookup(cache->msgnum_table, GINT_TO_POINTER(msginfo->msgnum));
+       oldmsginfo = g_hash_table_lookup(cache->msgnum_table, &msginfo->msgnum);
        if(msginfo) {
-               g_hash_table_remove(cache->msgnum_table, GINT_TO_POINTER(oldmsginfo->msgnum));
+               g_hash_table_remove(cache->msgid_table, oldmsginfo->msgid);
+               g_hash_table_remove(cache->msgnum_table, &oldmsginfo->msgnum);
                procmsg_msginfo_free(oldmsginfo);
        }
        cache->memusage -= procmsg_msginfo_memusage(oldmsginfo);
 
        newmsginfo = procmsg_msginfo_new_ref(msginfo);
-       g_hash_table_insert(cache->msgnum_table, GINT_TO_POINTER(msginfo->msgnum), newmsginfo);
+       g_hash_table_insert(cache->msgnum_table, &newmsginfo->msgnum, newmsginfo);
+       if(newmsginfo->msgid)
+               g_hash_table_insert(cache->msgid_table, newmsginfo->msgid, newmsginfo);
        cache->memusage += procmsg_msginfo_memusage(newmsginfo);
        cache->last_access = time(NULL);
        
@@ -241,7 +251,9 @@ MsgCache *msgcache_read_cache(FolderItem *item, const gchar *cache_file)
 */
                msginfo->folder = item;
 
-               g_hash_table_insert(cache->msgnum_table, GINT_TO_POINTER(msginfo->msgnum), msginfo);
+               g_hash_table_insert(cache->msgnum_table, &msginfo->msgnum, msginfo);
+               if(msginfo->msgid)
+                       g_hash_table_insert(cache->msgid_table, msginfo->msgid, msginfo);
                cache->memusage += procmsg_msginfo_memusage(msginfo);
        }
        fclose(fp);
@@ -281,7 +293,7 @@ void msgcache_read_mark(MsgCache *cache, const gchar *mark_file)
                while (fread(&num, sizeof(num), 1, fp) == 1) {
                        if (fread(&perm_flags, sizeof(perm_flags), 1, fp) != 1) break;
 
-                       msginfo = g_hash_table_lookup(cache->msgnum_table, GUINT_TO_POINTER(num));
+                       msginfo = g_hash_table_lookup(cache->msgnum_table, &num);
                        if(msginfo) {
                                msginfo->flags.perm_flags = perm_flags;
                        }
@@ -407,7 +419,7 @@ MsgInfo *msgcache_get_msg(MsgCache *cache, guint num)
 
        g_return_val_if_fail(cache != NULL, NULL);
 
-       msginfo = g_hash_table_lookup(cache->msgnum_table, GINT_TO_POINTER(num));
+       msginfo = g_hash_table_lookup(cache->msgnum_table, &num);
        if(!msginfo)
                return NULL;
        cache->last_access = time(NULL);
@@ -415,6 +427,20 @@ MsgInfo *msgcache_get_msg(MsgCache *cache, guint num)
        return procmsg_msginfo_new_ref(msginfo);
 }
 
+MsgInfo *msgcache_get_msg_by_id(MsgCache *cache, const gchar *msgid)
+{
+       MsgInfo *msginfo;
+       
+       g_return_val_if_fail(cache != NULL, NULL);
+
+       msginfo = g_hash_table_lookup(cache->msgid_table, msgid);
+       if(!msginfo)
+               return NULL;
+       cache->last_access = time(NULL);
+       
+       return procmsg_msginfo_new_ref(msginfo);        
+}
+
 static void msgcache_get_msg_list_func(gpointer key, gpointer value, gpointer user_data)
 {
        GSList **listptr = user_data;
index a6b69ea..2d2a4a6 100644 (file)
@@ -40,6 +40,7 @@ void      msgcache_add_msg                    (MsgCache *cache, MsgInfo *msginfo);
 void       msgcache_remove_msg                 (MsgCache *cache, guint num);
 void       msgcache_update_msg                 (MsgCache *cache, MsgInfo *msginfo);
 MsgInfo           *msgcache_get_msg                    (MsgCache *cache, guint num);
+MsgInfo            *msgcache_get_msg_by_id             (MsgCache *cache, const gchar *msgid);
 GSList    *msgcache_get_msg_list               (MsgCache *cache);
 time_t     msgcache_get_last_access_time       (MsgCache *cache);
 gint       msgcache_get_memory_usage           (MsgCache *cache);
index 16a0f23..2813f9c 100644 (file)
@@ -1158,7 +1158,8 @@ enum
        Q_NEWSGROUPS       = 3,
        Q_MAIL_ACCOUNT_ID  = 4,
        Q_NEWS_ACCOUNT_ID  = 5,
-       Q_SAVE_COPY_FOLDER = 6
+       Q_SAVE_COPY_FOLDER = 6,
+       Q_REPLY_MESSAGE_ID = 7,
 };
 
 gint procmsg_send_message_queue(const gchar *file)
@@ -1170,6 +1171,7 @@ gint procmsg_send_message_queue(const gchar *file)
                                       {"MAID:", NULL, FALSE},
                                       {"NAID:", NULL, FALSE},
                                       {"SCF:",  NULL, FALSE},
+                                      {"RMID:", NULL, FALSE},
                                       {NULL,    NULL, FALSE}};
        FILE *fp;
        gint filepos;
@@ -1179,6 +1181,7 @@ gint procmsg_send_message_queue(const gchar *file)
        GSList *to_list = NULL;
        GSList *newsgroup_list = NULL;
        gchar *savecopyfolder = NULL;
+       gchar *replymessageid = NULL;
        gchar buf[BUFFSIZE];
        gint hnum;
        PrefsAccount *mailac = NULL, *newsac = NULL;
@@ -1217,6 +1220,9 @@ gint procmsg_send_message_queue(const gchar *file)
                case Q_SAVE_COPY_FOLDER:
                        if (!savecopyfolder) savecopyfolder = g_strdup(p);
                        break;
+               case Q_REPLY_MESSAGE_ID:
+                       if (!replymessageid) replymessageid = g_strdup(p);
+                       break;
                }
        }
        filepos = ftell(fp);
@@ -1336,6 +1342,29 @@ gint procmsg_send_message_queue(const gchar *file)
                procmsg_save_to_outbox(outbox, file, TRUE);
        }
 
+       if(replymessageid != NULL) {
+               gchar **tokens;
+               FolderItem *item;
+               
+               tokens = g_strsplit(replymessageid, "%", 0);
+               item = folder_find_item_from_identifier(tokens[0]);
+               if(item != NULL) {
+                       MsgInfo *msginfo;
+                       
+                       msginfo = folder_item_fetch_msginfo_by_id(item, tokens[1]);
+                       if(msginfo != NULL) {
+                               procmsg_msginfo_unset_flags(msginfo, MSG_FORWARDED, 0);
+                               procmsg_msginfo_set_flags(msginfo, MSG_REPLIED, 0);
+
+                               procmsg_msginfo_free(msginfo);
+                       }
+               }
+               g_strfreev(tokens);
+       }
+
+       g_free(savecopyfolder);
+       g_free(replymessageid);
+       
        return (newsval != 0 ? newsval : mailval);
 }