2012-02-02 [pawel] 3.8.0cvs21
[claws.git] / src / folder.c
index 7a7d346ba6e2d232992cbd00eacef5b2ec268fb6..f6f961fe032660844952009aa23398f7f2919649 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2009 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -398,7 +398,7 @@ void folder_item_remove(FolderItem *item)
 {
        GNode *node, *start_node;
        FolderUpdateData hookdata;
-       gchar *tags_file = NULL;
+       gchar *tags_file = NULL, *tags_dir = NULL;
 
        cm_return_if_fail(item != NULL);
        cm_return_if_fail(item->folder != NULL);
@@ -428,7 +428,12 @@ void folder_item_remove(FolderItem *item)
        tags_file = folder_item_get_tags_file(item);
        if (tags_file)
                claws_unlink(tags_file);
+       tags_dir = g_path_get_dirname(tags_file);
+       if (tags_dir)
+               rmdir(tags_dir);
+
        g_free(tags_file);
+       g_free(tags_dir);
 
        hookdata.folder = item->folder;
        hookdata.update_flags = FOLDER_TREE_CHANGED | FOLDER_REMOVE_FOLDERITEM;
@@ -572,6 +577,8 @@ void folder_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag)
                        item->hide_read_msgs =  *attr->value == '1' ? TRUE : FALSE;
                else if (!strcmp(attr->name, "hidedelmsgs"))
                        item->hide_del_msgs =  *attr->value == '1' ? TRUE : FALSE;
+               else if (!strcmp(attr->name, "hidereadthreads"))
+                       item->hide_read_threads =  *attr->value == '1' ? TRUE : FALSE;
                else if (!strcmp(attr->name, "reqretrcpt"))
                        item->ret_rcpt =  *attr->value == '1' ? TRUE : FALSE;
                else if (!strcmp(attr->name, "sort_key")) {
@@ -656,6 +663,7 @@ XMLTag *folder_item_get_xml(Folder *folder, FolderItem *item)
        xml_tag_add_attr(tag, xml_attr_new("threaded", item->threaded ? "1" : "0"));
        xml_tag_add_attr(tag, xml_attr_new("hidereadmsgs", item->hide_read_msgs ? "1" : "0"));
        xml_tag_add_attr(tag, xml_attr_new("hidedelmsgs", item->hide_del_msgs ? "1" : "0"));
+       xml_tag_add_attr(tag, xml_attr_new("hidereadthreads", item->hide_read_threads ? "1" : "0"));
        if (item->ret_rcpt)
                xml_tag_add_attr(tag, xml_attr_new("reqretrcpt", "1"));
 
@@ -1380,6 +1388,37 @@ gchar *folder_item_get_identifier(FolderItem *item)
        return id;
 }
 
+Folder *folder_find_from_identifier(const gchar *identifier)
+{
+       gchar *str;
+       gchar *p;
+       gchar *name;
+       FolderClass *class;
+
+       cm_return_val_if_fail(identifier != NULL, NULL);
+
+       if (*identifier != '#')
+               return NULL;
+
+       Xstrdup_a(str, identifier, return NULL);
+
+       p = strchr(str, '/');
+       if (!p)
+               return NULL;
+       *p = '\0';
+       p++;
+       class = folder_get_class_from_string(&str[1]);
+       if (class == NULL)
+               return NULL;
+
+       name = p;
+       p = strchr(p, '/');
+       if (p)
+               return NULL;
+
+       return folder_find_from_name(name, class);
+}
+
 FolderItem *folder_find_item_from_identifier(const gchar *identifier)
 {
        Folder *folder;
@@ -2800,6 +2839,7 @@ static void msginfo_set_mime_flags(GNode *node, gpointer data)
             strcmp(mimeinfo->subtype, "pkcs7-signature")))) {
                procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
        } else if (mimeinfo->disposition == DISPOSITIONTYPE_UNKNOWN && 
+                mimeinfo->id == NULL &&
                 mimeinfo->type != MIMETYPE_TEXT &&
                 mimeinfo->type != MIMETYPE_MULTIPART) {
                if (!mimeinfo->subtype 
@@ -2808,6 +2848,7 @@ static void msginfo_set_mime_flags(GNode *node, gpointer data)
                    strcmp(mimeinfo->subtype, "pkcs7-signature")))
                        procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
        } else if (mimeinfo->disposition == DISPOSITIONTYPE_INLINE &&
+                mimeinfo->id == NULL &&
                (strcmp(mimeinfo->subtype, "pgp-signature") &&
                 strcmp(mimeinfo->subtype, "x-pkcs7-signature") &&
                 strcmp(mimeinfo->subtype, "pkcs7-signature")) && 
@@ -3025,6 +3066,8 @@ static void copy_msginfo_flags(MsgInfo *source, MsgInfo *dest)
 
 static void add_msginfo_to_cache(FolderItem *item, MsgInfo *newmsginfo, MsgInfo *flagsource)
 {
+       MsgInfoUpdate msginfo_update;
+
        /* update folder stats */
        if (MSG_IS_NEW(newmsginfo->flags))
                item->new_msgs++;
@@ -3051,6 +3094,10 @@ static void add_msginfo_to_cache(FolderItem *item, MsgInfo *newmsginfo, MsgInfo
        if (!item->cache)
                folder_item_read_cache(item);
 
+       msginfo_update.msginfo = newmsginfo;
+       msginfo_update.flags = MSGINFO_UPDATE_ADDED;
+       hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
+
        msgcache_add_msg(item->cache, newmsginfo);
        copy_msginfo_flags(flagsource, newmsginfo);
        folder_item_update_with_msg(item,  F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT | F_ITEM_UPDATE_ADDMSG, newmsginfo);
@@ -3245,6 +3292,7 @@ static FolderItem *folder_item_move_recursive(FolderItem *src, FolderItem *dest,
        new_item->ret_rcpt  = src->ret_rcpt;
        new_item->hide_read_msgs = src->hide_read_msgs;
        new_item->hide_del_msgs = src->hide_del_msgs;
+       new_item->hide_read_threads = src->hide_read_threads;
        new_item->sort_key  = src->sort_key;
        new_item->sort_type = src->sort_type;
 
@@ -4317,6 +4365,7 @@ static void folder_item_restore_persist_prefs(FolderItem *item, GHashTable *ppta
        item->ret_rcpt  = pp->ret_rcpt;
        item->hide_read_msgs = pp->hide_read_msgs;
        item->hide_del_msgs = pp->hide_del_msgs;
+       item->hide_read_threads = pp->hide_read_threads;
        item->sort_key  = pp->sort_key;
        item->sort_type = pp->sort_type;
 }
@@ -4343,6 +4392,7 @@ static void folder_get_persist_prefs_recursive(GNode *node, GHashTable *pptable)
                pp->ret_rcpt  = item->ret_rcpt; 
                pp->hide_read_msgs = item->hide_read_msgs;
                pp->hide_del_msgs = item->hide_del_msgs;
+               pp->hide_read_threads = item->hide_read_threads;
                pp->sort_key  = item->sort_key;
                pp->sort_type = item->sort_type;
                g_hash_table_insert(pptable, id, pp);