src/procmsg.c po/fr.po po/it.po po/pt_BR.po completed typo fixing
[claws.git] / src / procmsg.c
index 8ca00746377e4ae9cea6c7b1a24731fe8f190ea3..2f57feb7826ed6e345b57bf7aee43c026616356c 100644 (file)
@@ -400,6 +400,57 @@ void procmsg_write_flags(MsgInfo *msginfo, FILE *fp)
        WRITE_CACHE_DATA_INT(flags, fp);
 }
 
+void procmsg_flush_mark_queue(FolderItem *item, FILE *fp)
+{
+       MsgInfo *flaginfo;
+
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(fp != NULL);
+
+       while (item->mark_queue != NULL) {
+               flaginfo = (MsgInfo *)item->mark_queue->data;
+               procmsg_write_flags(flaginfo, fp);
+               procmsg_msginfo_free(flaginfo);
+               item->mark_queue = g_slist_remove(item->mark_queue, flaginfo);
+       }
+}
+
+void procmsg_add_flags(FolderItem *item, gint num, MsgFlags flags)
+{
+       FILE *fp;
+       gchar *path;
+       MsgInfo msginfo;
+
+       g_return_if_fail(item != NULL);
+
+       if (item->opened) {
+               MsgInfo *queue_msginfo;
+
+               queue_msginfo = g_new0(MsgInfo, 1);
+               queue_msginfo->msgnum = num;
+               queue_msginfo->flags = flags;
+               item->mark_queue = g_slist_append
+                       (item->mark_queue, queue_msginfo);
+               return;
+       }
+
+       path = folder_item_get_path(item);
+       g_return_if_fail(path != NULL);
+
+       if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL) {
+               g_warning(_("can't open mark file\n"));
+               g_free(path);
+               return;
+       }
+       g_free(path);
+
+       msginfo.msgnum = num;
+       msginfo.flags = flags;
+
+       procmsg_write_flags(&msginfo, fp);
+       fclose(fp);
+}
+
 struct MarkSum {
        gint *new;
        gint *unread;
@@ -828,14 +879,15 @@ void procmsg_empty_trash(void)
        }
 }
 
-gint procmsg_send_queue(gboolean save_msgs)
+gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs)
 {
-       FolderItem *queue;
        gint i;
        gint ret = 0;
 
-       queue = folder_get_default_queue();
+       if (!queue)
+               queue = folder_get_default_queue();
        g_return_val_if_fail(queue != NULL, -1);
+
        folder_item_scan(queue);
        if (queue->last_num < 0) return -1;
        else if (queue->last_num == 0) return 0;
@@ -849,10 +901,16 @@ gint procmsg_send_queue(gboolean save_msgs)
                                g_warning(_("Sending queued message %d failed.\n"), i);
                                ret = -1;
                        } else {
+                       /* CLAWS: 
+                        * We save in procmsg_send_message_queue because
+                        * we need the destination folder from the queue
+                        * header
+                                               
                                if (save_msgs)
                                        procmsg_save_to_outbox
                                                (queue->folder->outbox,
                                                 file, TRUE);
+*/
                                folder_item_remove_msg(queue, i);
                        }
                        g_free(file);
@@ -867,7 +925,7 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
 {
        gint num;
        FILE *fp;
-       gchar *path;
+       MsgFlags flag = {0, 0};
 
        debug_print(_("saving sent message...\n"));
 
@@ -907,19 +965,11 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
                return -1;
        }
 
-       path = folder_item_get_path(outbox);
-       if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
-               g_warning(_("can't open mark file\n"));
-       else {
-               MsgInfo newmsginfo;
-
-               newmsginfo.msgnum = num;
-               newmsginfo.flags.perm_flags = 0;
-               newmsginfo.flags.tmp_flags = 0;
-               procmsg_write_flags(&newmsginfo, fp);
-               fclose(fp);
+       if(is_queued) {
+               unlink(file);
        }
-       g_free(path);
+
+       procmsg_add_flags(outbox, num, flag);
 
        return 0;
 }
@@ -1118,7 +1168,6 @@ gint procmsg_send_message_queue(const gchar *file)
        gchar buf[BUFFSIZE];
        gint hnum;
        PrefsAccount *mailac = NULL, *newsac = NULL;
-       gchar *tmp = NULL;
        int local = 0;
 
        g_return_val_if_fail(file != NULL, -1);
@@ -1158,30 +1207,6 @@ gint procmsg_send_message_queue(const gchar *file)
        }
        filepos = ftell(fp);
 
-       if(newsgroup_list || prefs_common.savemsg) {
-               FILE *tmpfp;
-
-               /* write to temporary file */
-               tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
-                           G_DIR_SEPARATOR, (gint)file);
-               if ((tmpfp = fopen(tmp, "wb")) == NULL) {
-                       FILE_OP_ERROR(tmp, "fopen");
-                       newsval = -1;
-               }
-               if (change_file_mode_rw(tmpfp, tmp) < 0) {
-                       FILE_OP_ERROR(tmp, "chmod");
-                       g_warning(_("can't change file mode\n"));
-               }
-
-               while ((newsval == 0) && fgets(buf, sizeof(buf), fp) != NULL) {
-                       if (fputs(buf, tmpfp) == EOF) {
-                               FILE_OP_ERROR(tmp, "fputs");
-                               newsval = -1;
-                       }
-               }
-               fclose(tmpfp);
-       }
-
        fseek(fp, filepos, SEEK_SET);
        if (to_list) {
                debug_print(_("Sending message by mail\n"));
@@ -1235,53 +1260,45 @@ gint procmsg_send_message_queue(const gchar *file)
 
        if(newsgroup_list && (newsval == 0)) {
                Folder *folder;
+               gchar *tmp = NULL;
+               FILE *tmpfp;
 
-               debug_print(_("Sending message by news\n"));
-
-               folder = FOLDER(newsac->folder);
-
-               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 && savecopyfolder) {
-               FolderItem *folder;
-               gchar *path;
-               gint num;
-               FILE *fp;
-
-               debug_print(_("saving sent message...\n"));
-
-               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);
+               /* write to temporary file */
+               tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
+                           G_DIR_SEPARATOR, (gint)file);
+               if ((tmpfp = fopen(tmp, "wb")) == NULL) {
+                       FILE_OP_ERROR(tmp, "fopen");
+                       newsval = -1;
+                       alertpanel_error(_("Could not create temporary file for news sending."));
+               } else {
+                       if (change_file_mode_rw(tmpfp, tmp) < 0) {
+                               FILE_OP_ERROR(tmp, "chmod");
+                               g_warning(_("can't change file mode\n"));
+                       }
+
+                       while ((newsval == 0) && fgets(buf, sizeof(buf), fp) != NULL) {
+                               if (fputs(buf, tmpfp) == EOF) {
+                                       FILE_OP_ERROR(tmp, "fputs");
+                                       newsval = -1;
+                                       alertpanel_error(_("Error when writing temporary file for news sending."));
+                               }
+                       }
+                       fclose(tmpfp);
 
-               folder_item_scan(folder);
-               if ((num = folder_item_add_msg(folder, tmp, FALSE)) < 0) {
-                       g_warning(_("can't save message\n"));
-               }
+                       if(newsval == 0) {
+                               debug_print(_("Sending message by news\n"));
 
-               if(num) {
-                       if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
-                               g_warning(_("can't open mark file\n"));
-                       else {
-                               MsgInfo newmsginfo;
+                               folder = FOLDER(newsac->folder);
 
-                               newmsginfo.msgnum = num;
-                               newmsginfo.flags.perm_flags = 0;
-                               newmsginfo.flags.tmp_flags = 0;
-                               procmsg_write_flags(&newmsginfo, fp);
-                               fclose(fp);
+                               newsval = news_post(folder, tmp);
+                               if (newsval < 0) {
+                                       alertpanel_error(_("Error occurred while posting the message to %s ."),
+                                                newsac->nntp_server);
+                               }
                        }
+                       unlink(tmp);
                }
-               g_free(path);
+               g_free(tmp);
        }
 
        slist_free_strings(to_list);
@@ -1291,9 +1308,18 @@ gint procmsg_send_message_queue(const gchar *file)
        g_free(from);
        g_free(smtpserver);
        fclose(fp);
-       if(tmp) {
-               unlink(tmp);
-               g_free(tmp);
+
+       /* save message to outbox */
+       if (mailval == 0 && newsval == 0 && savecopyfolder) {
+               FolderItem *outbox;
+
+               debug_print(_("saving sent message...\n"));
+
+               outbox = folder_find_item_from_identifier(savecopyfolder);
+               if(!outbox)
+                       outbox = folder_get_default_outbox();
+
+               procmsg_save_to_outbox(outbox, file, TRUE);
        }
 
        return (newsval != 0 ? newsval : mailval);