sync with sylpheed 0.7.0cvs38
[claws.git] / src / procmsg.c
index c141f09264fcefa10b9d96463e6a7cf31d2ecdf2..9942c36cf46b6c4cbd51672e9d412719ccacf7ee 100644 (file)
@@ -445,7 +445,7 @@ static GHashTable *procmsg_read_mark_file(const gchar *folder)
        mark_table = g_hash_table_new(NULL, g_direct_equal);
 
        while (fread(&num, sizeof(num), 1, fp) == 1) {
-               if (fread(&perm_flags, sizeof(flags), 1, fp) != 1) break;
+               if (fread(&perm_flags, sizeof(perm_flags), 1, fp) != 1) break;
 
                flags = g_new0(MsgFlags, 1);
                flags->perm_flags = perm_flags;
@@ -707,7 +707,7 @@ FILE *procmsg_open_message(MsgInfo *msginfo)
 
        g_return_val_if_fail(msginfo != NULL, NULL);
 
-       file = procmsg_get_message_file_path(msginfo);
+       file = procmsg_get_message_file(msginfo);
        g_return_val_if_fail(file != NULL, NULL);
 
        if ((fp = fopen(file, "r")) == NULL) {
@@ -750,7 +750,8 @@ void procmsg_empty_trash(void)
 
        for (cur = folder_get_list(); cur != NULL; cur = cur->next) {
                trash = FOLDER(cur->data)->trash;
-               if (trash) folder_item_remove_all_msg(trash);
+               if (trash && trash->total > 0)
+                       folder_item_remove_all_msg(trash);
        }
 }
 
@@ -945,12 +946,13 @@ static gint procmsg_cmp_flag_msgnum(gconstpointer a, gconstpointer b)
 
 enum
 {
-       Q_SENDER          = 0,
-       Q_SMTPSERVER      = 1,
-       Q_RECIPIENTS      = 2,
-       Q_NEWSGROUPS      = 3,
-       Q_MAIL_ACCOUNT_ID = 4,
-       Q_NEWS_ACCOUNT_ID = 5
+       Q_SENDER           = 0,
+       Q_SMTPSERVER       = 1,
+       Q_RECIPIENTS       = 2,
+       Q_NEWSGROUPS       = 3,
+       Q_MAIL_ACCOUNT_ID  = 4,
+       Q_NEWS_ACCOUNT_ID  = 5,
+       Q_SAVE_COPY_FOLDER = 6
 };
 
 gint procmsg_send_message_queue(const gchar *file)
@@ -961,6 +963,7 @@ gint procmsg_send_message_queue(const gchar *file)
                                       {"NG:",   NULL, FALSE},
                                       {"MAID:", NULL, FALSE},
                                       {"NAID:", NULL, FALSE},
+                                      {"SCF:",  NULL, FALSE},
                                       {NULL,    NULL, FALSE}};
        FILE *fp;
        gint filepos;
@@ -969,6 +972,7 @@ gint procmsg_send_message_queue(const gchar *file)
        gchar *smtpserver = NULL;
        GSList *to_list = NULL;
        GSList *newsgroup_list = NULL;
+       gchar *savecopyfolder = NULL;
        gchar buf[BUFFSIZE];
        gint hnum;
        PrefsAccount *mailac = NULL, *newsac = NULL;
@@ -1004,6 +1008,9 @@ gint procmsg_send_message_queue(const gchar *file)
                case Q_NEWS_ACCOUNT_ID:
                        newsac = account_find_from_id(atoi(p));
                        break;
+               case Q_SAVE_COPY_FOLDER:
+                       if (!savecopyfolder) savecopyfolder = g_strdup(p);
+                       break;
                default:
                }
        }
@@ -1065,41 +1072,44 @@ gint procmsg_send_message_queue(const gchar *file)
                                mailval = send_message_smtp(&tmp_ac, to_list, fp);
                        }
                }
+               if (mailval < 0) {
+                       alertpanel_error(_("Error occurred while sending the message to %s ."),
+                                 mailac ? mailac->smtp_server : smtpserver);
+               }
        }
 
-       if(newsgroup_list) {
+       if(newsgroup_list && (newsval == 0)) {
                Folder *folder;
 
                debug_print(_("Sending message by news\n"));
 
                folder = FOLDER(newsac->folder);
 
-               if(newsval == 0) {
-                       newsval = news_post(folder, tmp);
-                       if (newsval < 0) {
-                               alertpanel_error(_("Error occurred while posting the message to %s ."),
-                                         newsac->nntp_server);
-                       }
-               }
-
+               newsval = news_post(folder, tmp);
+               if (newsval < 0) {
+                       alertpanel_error(_("Error occurred while posting the message to %s ."),
+                                 newsac->nntp_server);
+               }
        }
 
        /* save message to outbox */
-       if (mailval == 0 && newsval == 0 && prefs_common.savemsg) {
-               FolderItem *outbox;
+       if (mailval == 0 && newsval == 0 && savecopyfolder) {
+               FolderItem *folder;
                gchar *path;
                gint num;
                FILE *fp;
 
                debug_print(_("saving sent message...\n"));
 
-               outbox = folder_get_default_outbox();
-               path = folder_item_get_path(outbox);
+               folder = folder_find_item_from_identifier(savecopyfolder);
+               if(!folder)
+                       folder = folder_get_default_outbox();
+               path = folder_item_get_path(folder);
                if (!is_dir_exist(path))
                        make_dir_hier(path);
 
-               folder_item_scan(outbox);
-               if ((num = folder_item_add_msg(outbox, tmp, FALSE)) < 0) {
+               folder_item_scan(folder);
+               if ((num = folder_item_add_msg(folder, tmp, FALSE)) < 0) {
                        g_warning(_("can't save message\n"));
                }