0.8.8claws120
[claws.git] / src / procmsg.c
index ba12921421f05d4f3268c387ca765f80421798a5..a471bc2f404db9a9e92228a2f8d35128d64f23e2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
  *
  * 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
@@ -52,7 +52,6 @@ struct _FlagInfo
 
 static GHashTable *procmsg_read_mark_file      (const gchar    *folder);
 void   procmsg_msginfo_write_flags             (MsgInfo        *msginfo);
-static void procmsg_update_unread_children (MsgInfo *info, gboolean newly_marked);
 
 GHashTable *procmsg_msg_hash_table_create(GSList *mlist)
 {
@@ -810,8 +809,7 @@ FILE *procmsg_open_message_decrypted(MsgInfo *msginfo, MimeInfo **mimeinfo)
        }
 
        if (MSG_IS_ENCRYPTED(msginfo->flags) &&
-           !msginfo->plaintext_file &&
-           !msginfo->decryption_failed) {
+           (!msginfo->plaintext_file || msginfo->decryption_failed)) {
                rfc2015_decrypt_message(msginfo, mimeinfo_, fp);
                if (msginfo->plaintext_file &&
                    !msginfo->decryption_failed) {
@@ -1132,6 +1130,8 @@ void procmsg_msginfo_free(MsgInfo *msginfo)
        if (msginfo->refcnt > 0)
                return;
 
+       debug_print("freeing msginfo %d is %s\n", msginfo->msgnum, msginfo->folder ? msginfo->folder->path : "(nil)");
+
        if (msginfo->to_folder) {
                msginfo->to_folder->op_count--;
                folder_item_update(msginfo->to_folder, F_ITEM_UPDATE_MSGCNT);
@@ -1218,6 +1218,7 @@ enum
        Q_NEWS_ACCOUNT_ID  = 5,
        Q_SAVE_COPY_FOLDER = 6,
        Q_REPLY_MESSAGE_ID = 7,
+       Q_FWD_MESSAGE_ID   = 8
 };
 
 gint procmsg_send_message_queue(const gchar *file)
@@ -1230,6 +1231,7 @@ gint procmsg_send_message_queue(const gchar *file)
                                       {"NAID:", NULL, FALSE},
                                       {"SCF:",  NULL, FALSE},
                                       {"RMID:", NULL, FALSE},
+                                      {"FMID:", NULL, FALSE},
                                       {NULL,    NULL, FALSE}};
        FILE *fp;
        gint filepos;
@@ -1240,6 +1242,7 @@ gint procmsg_send_message_queue(const gchar *file)
        GSList *newsgroup_list = NULL;
        gchar *savecopyfolder = NULL;
        gchar *replymessageid = NULL;
+       gchar *fwdmessageid = NULL;
        gchar buf[BUFFSIZE];
        gint hnum;
        PrefsAccount *mailac = NULL, *newsac = NULL;
@@ -1281,6 +1284,9 @@ gint procmsg_send_message_queue(const gchar *file)
                case Q_REPLY_MESSAGE_ID:
                        if (!replymessageid) replymessageid = g_strdup(p);
                        break;
+               case Q_FWD_MESSAGE_ID:
+                       if (!fwdmessageid) fwdmessageid = g_strdup(p);
+                       break;
                }
        }
        filepos = ftell(fp);
@@ -1323,11 +1329,11 @@ gint procmsg_send_message_queue(const gchar *file)
                }
                if (mailval < 0) {
                        if (!local)
-                               alertpanel_error(
+                               alertpanel_error_log(
                                        _("Error occurred while sending the message to `%s'."),
                                        mailac ? mailac->smtp_server : smtpserver);
                        else
-                               alertpanel_error(
+                               alertpanel_error_log(
                                        _("Error occurred while sending the message with command `%s'."),
                                        (mailac && mailac->use_mail_command && 
                                         mailac->mail_command && (*mailac->mail_command)) ? 
@@ -1400,11 +1406,14 @@ gint procmsg_send_message_queue(const gchar *file)
                procmsg_save_to_outbox(outbox, file, TRUE);
        }
 
-       if (replymessageid != NULL) {
+       if (replymessageid != NULL || fwdmessageid != NULL) {
                gchar **tokens;
                FolderItem *item;
                
-               tokens = g_strsplit(replymessageid, "\x7f", 0);
+               if (replymessageid != NULL)
+                       tokens = g_strsplit(replymessageid, "\x7f", 0);
+               else
+                       tokens = g_strsplit(fwdmessageid, "\x7f", 0);
                item = folder_find_item_from_identifier(tokens[0]);
                if (item != NULL) {
                        MsgInfo *msginfo;
@@ -1420,9 +1429,14 @@ gint procmsg_send_message_queue(const gchar *file)
                        }
                        
                        if (msginfo != NULL) {
-                               procmsg_msginfo_unset_flags(msginfo, MSG_FORWARDED, 0);
-                               procmsg_msginfo_set_flags(msginfo, MSG_REPLIED, 0);
-
+                               if (replymessageid != NULL) {
+                                       procmsg_msginfo_unset_flags(msginfo, MSG_FORWARDED, 0);
+                                       procmsg_msginfo_set_flags(msginfo, MSG_REPLIED, 0);
+                               } 
+                               else {
+                                       procmsg_msginfo_unset_flags(msginfo, MSG_REPLIED, 0);
+                                       procmsg_msginfo_set_flags(msginfo, MSG_FORWARDED, 0);
+                               }
                                procmsg_msginfo_free(msginfo);
                        }
                }
@@ -1431,6 +1445,7 @@ gint procmsg_send_message_queue(const gchar *file)
 
        g_free(savecopyfolder);
        g_free(replymessageid);
+       g_free(fwdmessageid);
        
        return (newsval != 0 ? newsval : mailval);
 }
@@ -1673,32 +1688,53 @@ gboolean procmsg_msg_has_marked_parent(MsgInfo *info)
 }
 
 
-GSList *procmsg_find_children (MsgInfo *info)
+GSList *procmsg_find_children_func(MsgInfo *info, 
+                                  GSList *children, GSList *all)
 {
-       GSList *children = NULL;
-       GSList *all, *cur;
-       
-       g_return_val_if_fail(info!=NULL, NULL);
+       GSList *cur;
+
+       g_return_val_if_fail(info!=NULL, children);
        if (info->msgid == NULL)
-               return NULL;
-       all = folder_item_get_msg_list(info->folder);
+               return children;
+
        for (cur = all; cur != NULL; cur = g_slist_next(cur)) {
                MsgInfo *tmp = (MsgInfo *)cur->data;
                if (tmp->inreplyto && !strcmp(tmp->inreplyto, info->msgid)) {
-                       GSList *grand_children;
-                       children = g_slist_prepend(children, tmp);
-                       grand_children = procmsg_find_children(tmp);
-                       children = slist_concat_unique(children, grand_children);
-                       g_slist_free(grand_children);
+                       /* Check if message is already in the list */
+                       if ((children == NULL) || 
+                           (g_slist_index(children, tmp) == -1)) {
+                               children = g_slist_prepend(children,
+                                               procmsg_msginfo_new_ref(tmp));
+                               children = procmsg_find_children_func(tmp, 
+                                                       children, 
+                                                       all);
+                       }
                }
-               if (tmp && tmp != info)
-                       procmsg_msginfo_free(tmp);
        }
-       
        return children;
 }
 
-static void procmsg_update_unread_children(MsgInfo *info, gboolean newly_marked)
+GSList *procmsg_find_children (MsgInfo *info)
+{
+       GSList *children;
+       GSList *all, *cur;
+
+       g_return_val_if_fail(info!=NULL, NULL);
+       all = folder_item_get_msg_list(info->folder);
+       children = procmsg_find_children_func(info, NULL, all);
+       if (children != NULL) {
+               for (cur = all; cur != NULL; cur = g_slist_next(cur)) {
+                       /* this will not free the used pointers
+                          created with procmsg_msginfo_new_ref */
+                       procmsg_msginfo_free((MsgInfo *)cur->data);
+               }
+       }
+       g_slist_free(all);
+
+       return children;
+}
+
+void procmsg_update_unread_children(MsgInfo *info, gboolean newly_marked)
 {
        GSList *children = procmsg_find_children(info);
        GSList *cur;
@@ -1713,6 +1749,7 @@ static void procmsg_update_unread_children(MsgInfo *info, gboolean newly_marked)
                }
                procmsg_msginfo_free(tmp);
        }
+       g_slist_free(children);
 }
 
 /**