2006-06-12 [colin] 2.3.0cvs5
authorColin Leroy <colin@colino.net>
Mon, 12 Jun 2006 17:08:19 +0000 (17:08 +0000)
committerColin Leroy <colin@colino.net>
Mon, 12 Jun 2006 17:08:19 +0000 (17:08 +0000)
* src/compose.c
* src/compose.h
* src/folder.c
* src/folder.h
* src/imap.c
* src/inc.c
* src/main.c
* src/messageview.c
* src/mh.c
* src/prefs_folder_item.c
* src/procheader.c
* src/procmime.c
* src/procmsg.c
* src/procmsg.h
* src/send_message.c
* src/summaryview.c
* src/toolbar.c
Apply bug #964's patch (Queue and drafts aren't normal)
The Drafts and Queue folder now contain RFC-822 files,
allowing to move and copy mails from and to these
folders. Moving from Drafts to Queue will prepare the
mail for sending (PGP signature, encryption, etc).
This patch also rework sending errors handling to try
to be more helpful.
Also, allow redefining folder types via the GUI
(Folder type in its Properties)

20 files changed:
ChangeLog
PATCHSETS
configure.ac
src/compose.c
src/compose.h
src/folder.c
src/folder.h
src/imap.c
src/inc.c
src/main.c
src/messageview.c
src/mh.c
src/prefs_folder_item.c
src/procheader.c
src/procmime.c
src/procmsg.c
src/procmsg.h
src/send_message.c
src/summaryview.c
src/toolbar.c

index 46c2ade..025a4d2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2006-06-12 [colin]     2.3.0cvs5
+
+       * src/compose.c
+       * src/compose.h
+       * src/folder.c
+       * src/folder.h
+       * src/imap.c
+       * src/inc.c
+       * src/main.c
+       * src/messageview.c
+       * src/mh.c
+       * src/prefs_folder_item.c
+       * src/procheader.c
+       * src/procmime.c
+       * src/procmsg.c
+       * src/procmsg.h
+       * src/send_message.c
+       * src/summaryview.c
+       * src/toolbar.c
+               Apply bug #964's patch (Queue and drafts aren't normal)
+               The Drafts and Queue folder now contain RFC-822 files,
+               allowing to move and copy mails from and to these 
+               folders. Moving from Drafts to Queue will prepare the
+               mail for sending (PGP signature, encryption, etc).
+               This patch also rework sending errors handling to try
+               to be more helpful.
+               Also, allow redefining folder types via the GUI 
+               (Folder type in its Properties)
+
 2006-06-12 [colin]     2.3.0cvs4
 
        * src/summaryview.c
index 73f85c9..a8f7f57 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.8.2.6 -r 1.8.2.7 src/quote_fmt.c;  cvs diff -u -r 1.8.2.2 -r 1.8.2.3 src/quote_fmt_lex.l;  cvs diff -u -r 1.22.2.20 -r 1.22.2.21 src/quote_fmt_parse.y;  ) > 2.3.0cvs2.patchset
 ( cvs diff -u -r 1.8.2.3 -r 1.8.2.4 .cvsignore;  ) > 2.3.0cvs3.patchset
 ( cvs diff -u -r 1.395.2.218 -r 1.395.2.219 src/summaryview.c;  cvs diff -u -r 1.204.2.87 -r 1.204.2.88 src/prefs_common.c;  cvs diff -u -r 1.103.2.50 -r 1.103.2.51 src/prefs_common.h;  cvs diff -u -r 1.1.2.5 -r 1.1.2.6 src/gedit-print.c;  cvs diff -u -r 1.4.2.15 -r 1.4.2.16 src/prefs_fonts.c;  cvs diff -u -r 1.1.2.20 -r 1.1.2.21 manual/advanced.xml;  cvs diff -u -r 1.1.2.11 -r 1.1.2.12 manual/fr/advanced.xml;  ) > 2.3.0cvs4.patchset
+( cvs diff -u -r 1.382.2.276 -r 1.382.2.277 src/compose.c;  cvs diff -u -r 1.50.2.25 -r 1.50.2.26 src/compose.h;  cvs diff -u -r 1.213.2.97 -r 1.213.2.98 src/folder.c;  cvs diff -u -r 1.87.2.28 -r 1.87.2.29 src/folder.h;  cvs diff -u -r 1.179.2.119 -r 1.179.2.120 src/imap.c;  cvs diff -u -r 1.149.2.51 -r 1.149.2.52 src/inc.c;  cvs diff -u -r 1.115.2.89 -r 1.115.2.90 src/main.c;  cvs diff -u -r 1.94.2.85 -r 1.94.2.86 src/messageview.c;  cvs diff -u -r 1.79.2.34 -r 1.79.2.35 src/mh.c;  cvs diff -u -r 1.52.2.20 -r 1.52.2.21 src/prefs_folder_item.c;  cvs diff -u -r 1.47.2.30 -r 1.47.2.31 src/procheader.c;  cvs diff -u -r 1.49.2.76 -r 1.49.2.77 src/procmime.c;  cvs diff -u -r 1.150.2.67 -r 1.150.2.68 src/procmsg.c;  cvs diff -u -r 1.60.2.28 -r 1.60.2.29 src/procmsg.h;  cvs diff -u -r 1.17.2.30 -r 1.17.2.31 src/send_message.c;  cvs diff -u -r 1.395.2.219 -r 1.395.2.220 src/summaryview.c;  cvs diff -u -r 1.43.2.46 -r 1.43.2.47 src/toolbar.c;  ) > 2.3.0cvs5.patchset
index f63955e..948cfbf 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=3
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=4
+EXTRA_VERSION=5
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 340ff6f..60945b7 100644 (file)
@@ -271,15 +271,12 @@ static gint compose_write_body_to_file            (Compose        *compose,
 static gint compose_remove_reedit_target       (Compose        *compose,
                                                 gboolean        force);
 void compose_remove_draft                      (Compose        *compose);
-static gint compose_queue                      (Compose        *compose,
-                                                gint           *msgnum,
-                                                FolderItem     **item,
-                                                gchar          **msgpath);
 static gint compose_queue_sub                  (Compose        *compose,
                                                 gint           *msgnum,
                                                 FolderItem     **item,
                                                 gchar          **msgpath,
-                                                gboolean       check_subject);
+                                                gboolean       check_subject,
+                                                gboolean       remove_reedit_target);
 static void compose_add_attachments            (Compose        *compose,
                                                 MimeInfo       *parent);
 static gchar *compose_get_header               (Compose        *compose);
@@ -506,8 +503,6 @@ static void compose_check_forwards_go          (Compose *compose);
 static gint compose_defer_auto_save_draft      (Compose        *compose);
 static PrefsAccount *compose_guess_forward_account_from_msginfo        (MsgInfo *msginfo);
 
-static gboolean compose_close  (Compose *compose);
-
 static GtkItemFactoryEntry compose_popup_entries[] =
 {
        {N_("/_Add..."),        NULL, compose_attach_cb, 0, NULL},
@@ -1626,7 +1621,7 @@ static void compose_colorize_signature(Compose *compose)
                }
 }
 
-void compose_reedit(MsgInfo *msginfo)
+Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
 {
        Compose *compose = NULL;
        PrefsAccount *account = NULL;
@@ -1640,11 +1635,11 @@ void compose_reedit(MsgInfo *msginfo)
        gboolean use_encryption = FALSE;
        gchar *privacy_system = NULL;
 
-       g_return_if_fail(msginfo != NULL);
-       g_return_if_fail(msginfo->folder != NULL);
+       g_return_val_if_fail(msginfo != NULL, NULL);
+       g_return_val_if_fail(msginfo->folder != NULL, NULL);
 
        if (compose_put_existing_to_front(msginfo)) {
-               return;
+               return NULL;
        }
 
         if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
@@ -1706,9 +1701,9 @@ void compose_reedit(MsgInfo *msginfo)
         if (!account) {
                account = cur_account;
         }
-       g_return_if_fail(account != NULL);
+       g_return_val_if_fail(account != NULL, NULL);
 
-       compose = compose_create(account, COMPOSE_REEDIT, FALSE);
+       compose = compose_create(account, COMPOSE_REEDIT, batch);
        
        compose->updating = TRUE;
        
@@ -1750,7 +1745,7 @@ void compose_reedit(MsgInfo *msginfo)
        if (compose_parse_header(compose, msginfo) < 0) {
                compose->updating = FALSE;
                compose_destroy(compose);
-               return;
+               return NULL;
        }
        compose_reedit_set_entry(compose, msginfo);
 
@@ -1810,7 +1805,9 @@ void compose_reedit(MsgInfo *msginfo)
 
        if (compose->deferred_destroy) {
                compose_destroy(compose);
+               return NULL;
        }
+       return compose;
 }
 
 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
@@ -3949,6 +3946,9 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                }
                if (!found_other) {
                        AlertValue aval;
+                       if (compose->batch) {
+                               gtk_widget_show_all(compose->window);
+                       }
                        aval = alertpanel(_("Send"),
                                          _("The only recipient is the default CC address. Send anyway?"),
                                          GTK_STOCK_CANCEL, _("+_Send"), NULL);
@@ -3977,6 +3977,9 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                }
                if (!found_other) {
                        AlertValue aval;
+                       if (compose->batch) {
+                               gtk_widget_show_all(compose->window);
+                       }
                        aval = alertpanel(_("Send"),
                                          _("The only recipient is the default BCC address. Send anyway?"),
                                          GTK_STOCK_CANCEL, _("+_Send"), NULL);
@@ -3992,6 +3995,9 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
        const gchar *str;
 
        if (compose_check_for_valid_recipient(compose) == FALSE) {
+               if (compose->batch) {
+                       gtk_widget_show_all(compose->window);
+               }
                alertpanel_error(_("Recipient is not specified."));
                return FALSE;
        }
@@ -4019,11 +4025,11 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
 gint compose_send(Compose *compose)
 {
        gint msgnum;
-       FolderItem *folder;
+       FolderItem *folder = NULL;
        gint val = -1;
        gchar *msgpath = NULL;
        gboolean discard_window = FALSE;
-
+       gchar *errstr = NULL;
        if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
                        || compose->batch == TRUE)
                discard_window = TRUE;
@@ -4038,7 +4044,7 @@ gint compose_send(Compose *compose)
                goto bail;
        }
 
-       val = compose_queue(compose, &msgnum, &folder, &msgpath);
+       val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
 
        if (val) {
                if (compose->batch) {
@@ -4078,10 +4084,10 @@ gint compose_send(Compose *compose)
        
        if (msgpath == NULL) {
                msgpath = folder_item_fetch_msg(folder, msgnum);
-               val = procmsg_send_message_queue(msgpath);
+               val = procmsg_send_message_queue(msgpath, &errstr);
                g_free(msgpath);
        } else {
-               val = procmsg_send_message_queue(msgpath);
+               val = procmsg_send_message_queue(msgpath, &errstr);
                g_unlink(msgpath);
                g_free(msgpath);
        }
@@ -4100,9 +4106,17 @@ gint compose_send(Compose *compose)
                if (!discard_window)
                        compose_close(compose);
        } else {
-               alertpanel_error(_("The message was queued but could not be "
+               if (errstr) {
+                       gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
+                                  "the main window to retry."), errstr);
+                       g_free(errstr);
+                       alertpanel_error_log(tmp);
+                       g_free(tmp);
+               } else {
+                       alertpanel_error_log(_("The message was queued but could not be "
                                   "sent.\nUse \"Send queued messages\" from "
                                   "the main window to retry."));
+               }
                if (!discard_window) {
                        goto bail;              
                }
@@ -4608,11 +4622,14 @@ void compose_remove_draft(Compose *compose)
 
 }
 
-static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath)
+gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
+                  gboolean remove_reedit_target)
 {
-       return compose_queue_sub (compose, msgnum, item, msgpath, FALSE);
+       return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
 }
-static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath, gboolean check_subject)
+static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, 
+                             gchar **msgpath, gboolean check_subject,
+                             gboolean remove_reedit_target)
 {
        FolderItem *queue;
        gchar *tmp;
@@ -4629,6 +4646,9 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        
        if (compose_check_entries(compose, check_subject) == FALSE) {
                 lock = FALSE;
+               if (compose->batch) {
+                       gtk_widget_show_all(compose->window);
+               }
                 return -1;
        }
 
@@ -4666,6 +4686,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        if ((fp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
                g_free(tmp);
+               lock = FALSE;
                return -2;
        }
 
@@ -4777,7 +4798,9 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
                g_free(folderid);
        }
-       fprintf(fp, "\n");
+
+       /* end of headers */
+       fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
 
        if (compose->redirect_filename != NULL) {
                if (compose_redirect_write_to_file(compose, fp) < 0) {
@@ -4802,14 +4825,20 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                FILE_OP_ERROR(tmp, "fclose");
                g_unlink(tmp);
                g_free(tmp);
+               lock = FALSE;
                return -2;
        }
 
-       queue = account_get_special_folder(compose->account, F_QUEUE);
+       if (item && *item) {
+               queue = *item;
+       } else {
+               queue = account_get_special_folder(compose->account, F_QUEUE);
+       }
        if (!queue) {
                g_warning("can't find queue folder\n");
                g_unlink(tmp);
                g_free(tmp);
+               lock = FALSE;
                return -1;
        }
        folder_item_scan(queue);
@@ -4817,6 +4846,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                g_warning("can't queue the message\n");
                g_unlink(tmp);
                g_free(tmp);
+               lock = FALSE;
                return -1;
        }
        
@@ -4826,7 +4856,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        } else
                *msgpath = tmp;
 
-       if (compose->mode == COMPOSE_REEDIT) {
+       if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
                compose_remove_reedit_target(compose, FALSE);
        }
 
@@ -7481,10 +7511,12 @@ static void compose_send_later_cb(gpointer data, guint action,
        Compose *compose = (Compose *)data;
        gint val;
 
-       val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE);
+       val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
        if (!val) 
                compose_close(compose);
-       else if (val == -2) {
+       else if (val == -1) {
+               alertpanel_error(_("Could not queue message."));
+       } else if (val == -2) {
                alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
        } else if (val == -3) {
                alertpanel_error(_("Could not queue message for sending:\n\n"
@@ -7560,7 +7592,9 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
                fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
                fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
        }
-       fprintf(fp, "\n");
+
+       /* end of headers */
+       fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
 
        if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
                fclose(fp);
@@ -8760,7 +8794,7 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
        return account;
 }
 
-static gboolean compose_close(Compose *compose)
+gboolean compose_close(Compose *compose)
 {
        gint x, y;
 
index 01fa036..5f30d7d 100644 (file)
@@ -265,7 +265,8 @@ Compose *compose_forward_multiple   (PrefsAccount   *account,
 Compose *compose_redirect              (PrefsAccount   *account,
                                         MsgInfo        *msginfo,
                                         gboolean        batch);
-void compose_reedit                    (MsgInfo        *msginfo);
+Compose *compose_reedit                        (MsgInfo        *msginfo,
+                                        gboolean        batch);
 
 GList *compose_get_compose_list                (void);
 
@@ -302,5 +303,10 @@ gboolean compose_search_string                     (Compose        *compose,
 gboolean compose_search_string_backward        (Compose        *compose,
                                                 const gchar    *str,
                                                 gboolean        case_sens);
-
+gint compose_queue                     (Compose *compose, 
+                                        gint *msgnum, 
+                                        FolderItem **item, 
+                                        gchar **msgpath,
+                                        gboolean remove_reedit_target);
+gboolean compose_close                 (Compose *compose);
 #endif /* __COMPOSE_H__ */
index f9c1616..d42dfa0 100644 (file)
@@ -56,6 +56,7 @@
 #include "statusbar.h"
 #include "gtkutils.h"
 #include "timing.h"
+#include "compose.h"
 
 /* Dependecies to be removed ?! */
 #include "prefs_common.h"
@@ -90,7 +91,6 @@ static void folder_get_persist_prefs_recursive
                                        (GNode *node, GHashTable *pptable);
 static gboolean persist_prefs_free     (gpointer key, gpointer val, gpointer data);
 void folder_item_read_cache            (FolderItem *item);
-gboolean folder_item_free_cache                (FolderItem *item, gboolean force);
 gint folder_item_scan_full             (FolderItem *item, gboolean filtering);
 static void folder_item_update_with_msg (FolderItem *item, FolderItemUpdateFlags update_flags,
                                          MsgInfo *msg);
@@ -199,6 +199,58 @@ void folder_init(Folder *folder, const gchar *name)
        folder->trash = NULL;
 }
 
+static void reset_parent_type(FolderItem *item, gpointer data) {
+       item->parent_stype = -1;
+}
+
+void folder_item_change_type(FolderItem *item, SpecialFolderItemType newtype)
+{
+       FolderItem *parent;
+       Folder *folder = NULL;
+       FolderUpdateData hookdata;
+
+       if ((parent = folder_item_parent(item)) != NULL 
+       && folder_item_parent(parent) != NULL) {
+               g_warning("can't change subfolder's type");
+               return;
+       }
+       folder = item->folder;
+       /* unset previous root of newtype */
+       switch(newtype) {
+       case F_INBOX:
+               folder_item_change_type(folder->inbox, F_NORMAL);
+               folder->inbox = item;
+               break;
+       case F_OUTBOX:
+               folder_item_change_type(folder->outbox, F_NORMAL);
+               folder->outbox = item;
+               break;
+       case F_QUEUE:
+               folder_item_change_type(folder->queue, F_NORMAL);
+               folder->queue = item;
+               break;
+       case F_DRAFT:
+               folder_item_change_type(folder->draft, F_NORMAL);
+               folder->draft = item;
+               break;
+       case F_TRASH:
+               folder_item_change_type(folder->trash, F_NORMAL);
+               folder->trash = item;
+               break;
+       case F_NORMAL:
+       default:
+               break;
+       }
+       /* set new type for current folder and sons */
+       item->stype = newtype;
+       folder_func_to_all_folders(reset_parent_type, NULL);
+       
+       hookdata.folder = folder;
+       hookdata.update_flags = FOLDER_TREE_CHANGED;
+       hookdata.item = NULL;
+       hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
+}
+
 void folder_destroy(Folder *folder)
 {
        g_return_if_fail(folder != NULL);
@@ -2826,6 +2878,7 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour
        GRelation *relation;
        GSList *not_moved = NULL;
        gint total = 0, curmsg = 0;
+       MsgInfo *msginfo = NULL;
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(msglist != NULL, -1);
@@ -2836,6 +2889,40 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour
        if (dest->no_select)
                return -1;
 
+       msginfo = (MsgInfo *)msglist->data;
+       
+       if (!msginfo)
+               return -1;
+       
+       if (!MSG_IS_QUEUED(msginfo->flags) && 
+           MSG_IS_DRAFT(msginfo->flags) && 
+           folder_has_parent_of_type(dest, F_QUEUE)) {
+               GSList *cur = msglist;
+               gboolean queue_err = FALSE;
+               for (; cur; cur = cur->next) {
+                       Compose *compose = NULL;
+                       FolderItem *queue = dest;
+                       int val = 0;
+                       
+                       msginfo = (MsgInfo *)cur->data;
+                       compose = compose_reedit(msginfo, TRUE);
+                       if (compose == NULL) {
+                               queue_err = TRUE;
+                               continue;
+                       }
+                       val = compose_queue(compose, NULL, &queue, NULL,
+                                       FALSE);
+                       if (val < 0) {
+                               queue_err = TRUE;
+                       } else if (remove_source) {
+                               folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
+                       }
+                       if (val == 0)
+                               compose_close(compose);
+               }
+               return queue_err ? -1:0;
+       }
+
        relation = g_relation_new(2);
        g_relation_index(relation, 0, g_direct_hash, g_direct_equal);
        g_relation_index(relation, 1, g_direct_hash, g_direct_equal);
index 7ec005f..050ea7a 100644 (file)
@@ -822,5 +822,8 @@ void folder_item_process_open               (FolderItem *item,
                                         gpointer data);
 gboolean folder_subscribe              (const gchar *uri);
 gboolean folder_have_mailbox           (void);
+gboolean folder_item_free_cache                (FolderItem *item, gboolean force);
+void folder_item_change_type           (FolderItem *item,
+                                        SpecialFolderItemType newtype);
 
 #endif /* __FOLDER_H__ */
index b372b70..7ded573 100644 (file)
@@ -483,8 +483,6 @@ static Folder *imap_folder_new(const gchar *name, const gchar *path)
 
 static void imap_folder_destroy(Folder *folder)
 {
-       gchar *dir;
-
        while (imap_folder_get_refcnt(folder) > 0)
                gtk_main_iteration();
        
@@ -1061,7 +1059,6 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                IMAPFlags iflags = 0;
                guint32 new_uid = 0;
                gchar *real_file = NULL;
-               gboolean file_is_tmp = FALSE;
                fileinfo = (MsgFileInfo *)cur->data;
 
                statusbar_progress_all(curnum, total, 1);
@@ -1076,28 +1073,6 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                                iflags |= IMAP_FLAG_SEEN;
                }
                
-               if (fileinfo->flags) {
-                       if ((MSG_IS_QUEUED(*fileinfo->flags) 
-                            || MSG_IS_DRAFT(*fileinfo->flags))
-                       && !folder_has_parent_of_type(dest, F_QUEUE)
-                       && !folder_has_parent_of_type(dest, F_DRAFT)) {
-                               real_file = get_tmp_file();
-                               file_is_tmp = TRUE;
-                               if (procmsg_remove_special_headers(
-                                               fileinfo->file, 
-                                               real_file) !=0) {
-                                       g_free(real_file);
-                                       g_free(destdir);
-                                       unlock_session();
-                                       return -1;
-                               }
-                       }  else if (!(MSG_IS_QUEUED(*fileinfo->flags) 
-                                     || MSG_IS_DRAFT(*fileinfo->flags))
-                                   && (folder_has_parent_of_type(dest, F_QUEUE)
-                                   || folder_has_parent_of_type(dest, F_DRAFT))) {
-                               return -1;
-                       } 
-               }
                if (real_file == NULL)
                        real_file = g_strdup(fileinfo->file);
                
@@ -1112,8 +1087,6 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
 
                if (ok != IMAP_SUCCESS) {
                        g_warning("can't append message %s\n", real_file);
-                       if (file_is_tmp)
-                               g_unlink(real_file);
                        g_free(real_file);
                        g_free(destdir);
                        unlock_session();
@@ -1149,8 +1122,6 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                }
                if (last_uid < new_uid)
                        last_uid = new_uid;
-               if (file_is_tmp)
-                       g_unlink(real_file);
 
                g_free(real_file);
        }
@@ -1196,6 +1167,27 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
                return -1;
        }
 
+       if (src->folder != dest->folder) {
+               GSList *infolist = NULL, *cur;
+               int res = -1;
+               for (cur = msglist; cur; cur = cur->next) {
+                       msginfo = (MsgInfo *)cur->data;
+                       MsgFileInfo *fileinfo = g_new0(MsgFileInfo, 1);
+                       fileinfo->file = procmsg_get_message_file(msginfo);
+                       fileinfo->flags = &(msginfo->flags);
+                       infolist = g_slist_prepend(infolist, fileinfo);
+               }
+               infolist = g_slist_reverse(infolist);
+               res = folder_item_add_msgs(dest, infolist, FALSE);
+               for (cur = infolist; cur; cur = cur->next) {
+                       MsgFileInfo *info = (MsgFileInfo *)cur->data;
+                       g_free(info->file);
+                       g_free(info);
+               }
+               g_slist_free(infolist);
+               return res;
+       } 
+
        ok = imap_select(session, IMAP_FOLDER(folder), msginfo->folder->path,
                         NULL, NULL, NULL, NULL, FALSE);
        if (ok != IMAP_SUCCESS) {
@@ -1278,7 +1270,6 @@ static gint imap_copy_msgs(Folder *folder, FolderItem *dest,
                    MsgInfoList *msglist, GRelation *relation)
 {
        MsgInfo *msginfo;
-       GSList *file_list;
        gint ret;
 
        g_return_val_if_fail(folder != NULL, -1);
@@ -1288,30 +1279,7 @@ static gint imap_copy_msgs(Folder *folder, FolderItem *dest,
        msginfo = (MsgInfo *)msglist->data;
        g_return_val_if_fail(msginfo->folder != NULL, -1);
 
-       /* if from/to are the same "type" (with or without extra headers),
-        * copy them via imap */
-       if (folder == msginfo->folder->folder &&
-           !folder_has_parent_of_type(msginfo->folder, F_DRAFT) &&
-           !folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
-           !folder_has_parent_of_type(dest, F_DRAFT) &&
-           !folder_has_parent_of_type(dest, F_QUEUE)) {
-               ret = imap_do_copy_msgs(folder, dest, msglist, relation);
-               return ret;
-       } else if (folder == msginfo->folder->folder &&
-           (folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
-            folder_has_parent_of_type(msginfo->folder, F_QUEUE)) && 
-           (folder_has_parent_of_type(dest, F_DRAFT) ||
-            folder_has_parent_of_type(dest, F_QUEUE))) {
-               ret = imap_do_copy_msgs(folder, dest, msglist, relation);
-               return ret;
-       }
-       /* else reupload them */
-       file_list = procmsg_get_message_file_list(msglist);
-       g_return_val_if_fail(file_list != NULL, -1);
-
-       ret = imap_add_msgs(folder, dest, file_list, relation);
-       procmsg_message_file_list_free(file_list);
-
+       ret = imap_do_copy_msgs(folder, dest, msglist, relation);
        return ret;
 }
 
index 4ea415d..6350423 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -688,7 +688,7 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                            inc_state == INC_IO_ERROR)
                                break;
                }
-               folder_item_free_cache(processing);
+               folder_item_free_cache(processing, TRUE);
 
                inc_session_destroy(session);
                inc_dialog->queue_list =
index 41cbc49..bf89c0e 100644 (file)
@@ -608,7 +608,7 @@ static void save_all_caches(FolderItem *item, gpointer data)
        if (item->opened)
                folder_item_close(item);
 
-       folder_item_free_cache(item);
+       folder_item_free_cache(item, TRUE);
 }
 
 static void exit_sylpheed(MainWindow *mainwin)
@@ -1218,22 +1218,30 @@ static void open_compose_new(const gchar *address, GPtrArray *attach_files)
 static void send_queue(void)
 {
        GList *list;
-
+       gchar *errstr = NULL;
        for (list = folder_get_list(); list != NULL; list = list->next) {
                Folder *folder = list->data;
 
                if (folder->queue) {
                        gint res = procmsg_send_queue
-                               (folder->queue, prefs_common.savemsg);
+                               (folder->queue, prefs_common.savemsg,
+                               &errstr);
 
-                       if (res < 0) {
-                               alertpanel_error(_("Some errors occurred while sending queued messages."));
-                       }
                        if (res) {
                                folder_item_scan(folder->queue);
                        }
                }
        }
+       if (errstr) {
+               gchar *tmp = g_strdup_printf(_("Some errors occurred "
+                               "while sending queued messages:\n%s"), errstr);
+               g_free(errstr);
+               alertpanel_error_log(tmp);
+               g_free(tmp);
+       } else {
+               alertpanel_error_log("Some errors occurred "
+                               "while sending queued messages.");
+       }
 }
 
 static void quit_signal_handler(int sig)
index 350d091..96fbb30 100644 (file)
@@ -529,7 +529,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        gchar *path;
         gchar *addr;
         gchar *addrp;
-
+       gchar *foo = NULL;
        if ((!msginfo->returnreceiptto) && 
            (!msginfo->dispositionnotificationto)) 
                return -1;
@@ -709,8 +709,9 @@ static gint disposition_notification_send(MsgInfo *msginfo)
 
        /* send it */
        path = folder_item_fetch_msg(queue, num);
-       ok = procmsg_send_message_queue(path);
+       ok = procmsg_send_message_queue(path, &foo);
        g_free(path);
+       g_free(foo);
        folder_item_remove_msg(queue, num);
 
        return ok;
@@ -1558,7 +1559,7 @@ static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
            !folder_has_parent_of_type(msginfo->folder, F_QUEUE)) 
                return;
 
-       compose_reedit(msginfo);
+       compose_reedit(msginfo, FALSE);
 }
 
 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
index caa4675..000c6c4 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -461,7 +461,6 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
        gint filemode = 0;
        FolderItemPrefs *prefs;
        MsgInfo *msginfo = NULL;
-       gboolean remove_special_headers = FALSE;
        MsgInfoList *cur = NULL;
        gint curnum = 0, total = 0;
        gchar *srcpath = NULL;
@@ -487,19 +486,6 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
                if (dest->last_num < 0) return -1;
        }
 
-       if ((MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
-       && !folder_has_parent_of_type(dest, F_QUEUE)
-       && !folder_has_parent_of_type(dest, F_DRAFT)) {
-               /* as every msginfo comes from the same folder, it is supposed they
-                * will either match the preceding condition either all or none.
-                */
-               remove_special_headers = TRUE;
-       } else if (!(MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
-       && (folder_has_parent_of_type(dest, F_QUEUE)
-        || folder_has_parent_of_type(dest, F_DRAFT))) {
-               return -1;
-       } 
-
        prefs = dest->prefs;
 
        srcpath = folder_item_get_path(msginfo->folder);
@@ -512,7 +498,6 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
                        statusbar_print_all(_("Copying messages..."));
        }
        for (cur = msglist; cur; cur = cur->next) {
-               gboolean moved = FALSE;
                msginfo = (MsgInfo *)cur->data;
                if (!msginfo) {
                        goto err_reset_status;
@@ -545,13 +530,7 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
                            msginfo->msgnum, dest->path);
 
 
-               if (remove_special_headers) {
-                       if (procmsg_remove_special_headers(srcfile, destfile) !=0) {
-                               g_free(srcfile);
-                               g_free(destfile);
-                               goto err_reset_status;
-                       }
-               } else if (MSG_IS_MOVE(msginfo->flags)) {
+               if (MSG_IS_MOVE(msginfo->flags)) {
                        if (move_file(srcfile, destfile, TRUE) < 0) {
                                FILE_OP_ERROR(srcfile, "move");
                                if (copy_file(srcfile, destfile, TRUE) < 0) {
index 088d303..f96b725 100644 (file)
@@ -32,6 +32,7 @@
 #include "folder.h"
 #include "prefs_folder_item.h"
 #include "folderview.h"
+#include "folder.h"
 #include "summaryview.h"
 #include "menu.h"
 #include "account.h"
@@ -65,6 +66,7 @@ struct _FolderItemGeneralPage
        FolderItem *item;
 
        GtkWidget *table;
+       GtkWidget *folder_type;
        GtkWidget *checkbtn_simplify_subject;
        GtkWidget *entry_simplify_subject;
        GtkWidget *checkbtn_folder_chmod;
@@ -137,13 +139,21 @@ void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
                                                   gpointer data)
 {
        FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
-       FolderItem *item = (FolderItem *) data;
+       FolderItem *item = (FolderItem *) data, *parent;
        guint rowcount;
 
+
        GtkWidget *table;
        GtkWidget *hbox;
        GtkWidget *label;
        
+       GtkWidget *folder_type_menu;
+       GtkWidget *folder_type;
+       GtkWidget *dummy_chkbtn;
+       GtkWidget *menuitem;
+       SpecialFolderItemType type;
+       gboolean type_apply_to_sub = TRUE;
+       
        GtkWidget *checkbtn_simplify_subject;
        GtkWidget *entry_simplify_subject;
        GtkWidget *checkbtn_folder_chmod;
@@ -177,6 +187,56 @@ void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
                         rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
        rowcount++;
 
+       /* folder_type */
+       folder_type = gtk_option_menu_new ();
+       gtk_widget_show (folder_type);
+
+       parent = item;
+       type = F_NORMAL;
+       while (parent && (type = parent->stype) == F_NORMAL) {
+               parent = folder_item_parent(parent);
+       }
+
+       if (type == F_INBOX && (parent = folder_item_parent(item)) != NULL
+       &&  folder_item_parent(parent) != NULL) {
+               type = F_NORMAL;
+               type_apply_to_sub = FALSE;
+       }
+
+       folder_type_menu = gtk_menu_new ();
+
+       MENUITEM_ADD (folder_type_menu, menuitem, _("Normal"),  F_NORMAL);
+       MENUITEM_ADD (folder_type_menu, menuitem, _("Inbox"),  F_INBOX);
+       MENUITEM_ADD (folder_type_menu, menuitem, _("Outbox"),  F_OUTBOX);
+       MENUITEM_ADD (folder_type_menu, menuitem, _("Drafts"),  F_DRAFT);
+       MENUITEM_ADD (folder_type_menu, menuitem, _("Queue"),  F_QUEUE);
+       MENUITEM_ADD (folder_type_menu, menuitem, _("Trash"),  F_TRASH);
+       gtk_option_menu_set_menu (GTK_OPTION_MENU (folder_type), folder_type_menu);
+
+       gtk_option_menu_set_history(GTK_OPTION_MENU(folder_type), type);
+
+       dummy_chkbtn = gtk_check_button_new();
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy_chkbtn), type_apply_to_sub);
+       gtk_widget_set_sensitive(dummy_chkbtn, FALSE);
+
+       if (((parent = folder_item_parent(item)) != NULL
+       &&  folder_item_parent(parent) == NULL)
+       &&  item->stype == F_NORMAL) {
+               gtk_widget_set_sensitive(folder_type, TRUE);
+       } else {
+               gtk_widget_set_sensitive(folder_type, FALSE);
+       }
+       label = gtk_label_new(_("Folder type:"));
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+       gtk_table_attach(GTK_TABLE(table), label, 0, 1, 
+                        rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), folder_type, 1, 2, 
+                        rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), dummy_chkbtn, 2, 3, 
+                        rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
+
+       rowcount++;
+
        /* Simplify Subject */
        checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp: "));
        gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
@@ -306,6 +366,7 @@ void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
        gtk_widget_show_all(table);
 
        page->table = table;
+       page->folder_type = folder_type;
        page->checkbtn_simplify_subject = checkbtn_simplify_subject;
        page->entry_simplify_subject = entry_simplify_subject;
        page->checkbtn_folder_chmod = checkbtn_folder_chmod;
@@ -340,6 +401,9 @@ static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage
        FolderItemPrefs *prefs = folder->prefs;
        gchar *buf;
        gboolean all = FALSE;
+       SpecialFolderItemType type = F_NORMAL;
+       GtkWidget *menu;
+       GtkWidget *menuitem;
 
        if (folder->path == NULL)
                return;
@@ -349,6 +413,14 @@ static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage
        if (page->item == folder) 
                all = TRUE;
 
+       menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->folder_type));
+       menuitem = gtk_menu_get_active(GTK_MENU(menu));
+       type = GPOINTER_TO_INT
+               (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
+       if (all && folder->stype != type) {
+               folder_item_change_type(folder, type);
+       }
+
        if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
                prefs->enable_simplify_subject =
                        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
index 7382e41..b2c9517 100644 (file)
@@ -435,6 +435,8 @@ static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
        gchar *hp;
        HeaderEntry *hentry;
        gint hnum;
+       void *orig_data = data;
+
        get_one_field_func get_one_field =
                isstring ? (get_one_field_func)string_get_one_field
                         : (get_one_field_func)procheader_get_one_field;
@@ -442,8 +444,22 @@ static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
        hentry = procheader_get_headernames(full);
 
        if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
-               while (get_one_field(buf, sizeof(buf), data, NULL) != -1)
-                       ; /* loop */
+               while (get_one_field(buf, sizeof(buf), data, NULL) != -1) {
+                       if (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
+                               strlen("X-Sylpheed-End-Special-Headers:")))
+                               break;
+                       /* from other mailers */
+                       if (!strncmp(buf, "Date: ", 6)
+                       ||  !strncmp(buf, "To: ", 4)
+                       ||  !strncmp(buf, "From: ", 6)
+                       ||  !strncmp(buf, "Subject: ", 9)) {
+                               if (isstring)
+                                       data = orig_data;
+                               else 
+                                       rewind((FILE *)data);
+                               break;
+                       }
+               }
        }
 
        msginfo = procmsg_msginfo_new();
index b1d58b8..f6fddff 100644 (file)
@@ -1841,8 +1841,22 @@ MimeInfo *procmime_scan_queue_file(const gchar *filename)
        if ((fp = g_fopen(filename, "rb")) == NULL)
                return NULL;
        /* Skip queue header */
-       while (fgets(buf, sizeof(buf), fp) != NULL)
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               /* new way */
+               if (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
+                       strlen("X-Sylpheed-End-Special-Headers:")))
+                       break;
+               /* old way */
                if (buf[0] == '\r' || buf[0] == '\n') break;
+               /* from other mailers */
+               if (!strncmp(buf, "Date: ", 6)
+               ||  !strncmp(buf, "To: ", 4)
+               ||  !strncmp(buf, "From: ", 6)
+               ||  !strncmp(buf, "Subject: ", 9)) {
+                       rewind(fp);
+                       break;
+               }
+       }
        offset = ftell(fp);
        fclose(fp);
 
index 39b5e64..2116e9a 100644 (file)
@@ -47,7 +47,7 @@
 #include "log.h"
 #include "timing.h"
 
-static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session);
+static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session, gchar **errstr);
 
 enum
 {
@@ -63,6 +63,7 @@ enum
        Q_PRIVACY_SYSTEM   = 9,
        Q_ENCRYPT          = 10,
        Q_ENCRYPT_DATA     = 11,
+       Q_SYLPHEED_HDRS    = 12,
 };
 
 GHashTable *procmsg_msg_hash_table_create(GSList *mlist)
@@ -540,8 +541,22 @@ FILE *procmsg_open_message(MsgInfo *msginfo)
        if (MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags)) {
                gchar buf[BUFFSIZE];
 
-               while (fgets(buf, sizeof(buf), fp) != NULL)
+               while (fgets(buf, sizeof(buf), fp) != NULL) {
+                       /* new way */
+                       if (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
+                               strlen("X-Sylpheed-End-Special-Headers:")))
+                               break;
+                       /* old way */
                        if (buf[0] == '\r' || buf[0] == '\n') break;
+                       /* from other mailers */
+                       if (!strncmp(buf, "Date: ", 6)
+                       ||  !strncmp(buf, "To: ", 4)
+                       ||  !strncmp(buf, "From: ", 6)
+                       ||  !strncmp(buf, "Subject: ", 9)) {
+                               rewind(fp);
+                               break;
+                       }
+               }
        }
 
        return fp;
@@ -873,7 +888,7 @@ static gboolean procmsg_is_last_for_account(FolderItem *queue, MsgInfo *msginfo,
  *\return      Number of messages sent, negative if an error occurred
  *             positive if no error occurred
  */
-gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs)
+gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs, gchar **errstr)
 {
        gint sent = 0, err = 0;
        GSList *list, *elem;
@@ -883,6 +898,10 @@ gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs)
        
        if (send_queue_lock) {
                log_error(_("Already trying to send\n"));
+               if (errstr) {
+                       if (*errstr) g_free(*errstr);
+                       *errstr = g_strdup_printf(_("Already trying to send."));
+               }
                return -1;
        }
        send_queue_lock = TRUE;
@@ -905,7 +924,8 @@ gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs)
                        file = folder_item_fetch_msg(queue, msginfo->msgnum);
                        if (file) {
                                if (procmsg_send_message_queue_full(file, 
-                                               !procmsg_is_last_for_account(queue, msginfo, elem)) < 0) {
+                                               !procmsg_is_last_for_account(queue, msginfo, elem),
+                                               errstr) < 0) {
                                        g_warning("Sending queued message %d failed.\n", 
                                                  msginfo->msgnum);
                                        err++;
@@ -930,7 +950,7 @@ gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs)
                while (node != NULL) {
                        int res = 0;
                        next = node->next;
-                       res = procmsg_send_queue(FOLDER_ITEM(node->data), save_msgs);
+                       res = procmsg_send_queue(FOLDER_ITEM(node->data), save_msgs, errstr);
                        if (res < 0) 
                                err = -res;
                        else
@@ -991,8 +1011,22 @@ gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
                fclose(fp);
                return -1;
        }
-       while (fgets(buf, sizeof(buf), fp) != NULL)
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               /* new way */
+               if (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
+                       strlen("X-Sylpheed-End-Special-Headers:")))
+                       break;
+               /* old way */
                if (buf[0] == '\r' || buf[0] == '\n') break;
+               /* from other mailers */
+               if (!strncmp(buf, "Date: ", 6)
+               ||  !strncmp(buf, "To: ", 4)
+               ||  !strncmp(buf, "From: ", 6)
+               ||  !strncmp(buf, "Subject: ", 9)) {
+                       rewind(fp);
+                       break;
+               }
+       }
        while (fgets(buf, sizeof(buf), fp) != NULL)
                fputs(buf, outfp);
        fclose(outfp);
@@ -1036,7 +1070,7 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
                        g_warning("can't save message\n");
                        return -1;
                }
-               return -1;
+               return 0;
        }
        msginfo = folder_item_get_msginfo(outbox, num);         /* refcnt++ */
        tmp_msginfo = procmsg_msginfo_get_full_info(msginfo);   /* refcnt++ */ 
@@ -1354,7 +1388,7 @@ gint procmsg_cmp_msgnum_for_sort(gconstpointer a, gconstpointer b)
        return msginfo1->msgnum - msginfo2->msgnum;
 }
 
-static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session)
+static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session, gchar **errstr)
 {
        static HeaderEntry qentry[] = {{"S:",    NULL, FALSE},
                                       {"SSV:",  NULL, FALSE},
@@ -1368,6 +1402,7 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                                       {"X-Sylpheed-Privacy-System:", NULL, FALSE},
                                       {"X-Sylpheed-Encrypt:", NULL, FALSE},
                                       {"X-Sylpheed-Encrypt-Data:", NULL, FALSE},
+                                      {"X-Sylpheed-End-Special-Headers:", NULL, FALSE},
                                       {NULL,    NULL, FALSE}};
        FILE *fp;
        gint filepos;
@@ -1394,6 +1429,10 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
 
        if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
+               if (errstr) {
+                       if (*errstr) g_free(*errstr);
+                       *errstr = g_strdup_printf(_("Couldn't open file %s."), file);
+               }
                return -1;
        }
 
@@ -1446,8 +1485,12 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                        if (encrypt_data == NULL) 
                                encrypt_data = g_strdup(p);
                        break;
+               case Q_SYLPHEED_HDRS:
+                       /* end of special headers reached */
+                       goto send_mail; /* can't "break;break;" */
                }
        }
+send_mail:
        filepos = ftell(fp);
 
        if (encrypt) {
@@ -1480,6 +1523,10 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                        g_free(fwdmessageid);
                        g_free(privacy_system);
                        g_free(encrypt_data);
+                       if (errstr) {
+                               if (*errstr) g_free(*errstr);
+                               *errstr = g_strdup_printf(_("Couldn't encrypt the email."));
+                       }
                        return -1;
                }
                
@@ -1508,7 +1555,10 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
        if (to_list) {
                debug_print("Sending message by mail\n");
                if (!from) {
-                       g_warning("Queued message header is broken.\n");
+                       if (errstr) {
+                               if (*errstr) g_free(*errstr);
+                               *errstr = g_strdup_printf(_("Queued message header is broken."));
+                       }
                        mailval = -1;
                } else if (mailac && mailac->use_mail_command &&
                           mailac->mail_command && (* mailac->mail_command)) {
@@ -1524,9 +1574,13 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                                }
                        }
 
-                       if (mailac)
+                       if (mailac) {
                                mailval = send_message_smtp_full(mailac, to_list, fp, keep_session);
-                       else {
+                               if (mailval == -1 && errstr) {
+                                       if (*errstr) g_free(*errstr);
+                                       *errstr = g_strdup_printf(_("An error happened during SMTP session."));
+                               }
+                       } else {
                                PrefsAccount tmp_ac;
 
                                g_warning("Account not found.\n");
@@ -1536,11 +1590,21 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                                tmp_ac.smtp_server = smtpserver;
                                tmp_ac.smtpport = SMTP_PORT;
                                mailval = send_message_smtp(&tmp_ac, to_list, fp);
+                               if (mailval == -1 && errstr) {
+                                       if (*errstr) g_free(*errstr);
+                                       *errstr = g_strdup_printf(_("No specific account has been found to "
+                                                       "send, and an error happened during SMTP session."));
+                               }
                        }
                }
-       } else if (!to_list && !newsgroup_list) 
+       } else if (!to_list && !newsgroup_list) {
+               if (errstr) {
+                       if (*errstr) g_free(*errstr);
+                       *errstr = g_strdup(_("Couldn't determine sending informations. "
+                               "Maybe the email hasn't been generated by Sylpheed-Claws."));
+               }
                mailval = -1;
-
+       }
 
        fseek(fp, filepos, SEEK_SET);
        if (newsgroup_list && (mailval == 0)) {
@@ -1565,7 +1629,10 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                                if (fputs(buf, tmpfp) == EOF) {
                                        FILE_OP_ERROR(tmp, "fputs");
                                        newsval = -1;
-                                       alertpanel_error(_("Error when writing temporary file for news sending."));
+                                       if (errstr) {
+                                               if (*errstr) g_free(*errstr);
+                                               *errstr = g_strdup_printf(_("Error when writing temporary file for news sending."));
+                                       }
                                }
                        }
                        fclose(tmpfp);
@@ -1576,10 +1643,11 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                                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);
-                               }
+                               if (newsval < 0 && errstr)  {
+                                       if (*errstr) g_free(*errstr);
+                                       *errstr = g_strdup_printf(_("Error occurred while posting the message to %s."),
+                                        newsac->nntp_server);
+                               }
                        }
                        g_unlink(tmp);
                }
@@ -1668,9 +1736,9 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
        return (newsval != 0 ? newsval : mailval);
 }
 
-gint procmsg_send_message_queue(const gchar *file)
+gint procmsg_send_message_queue(const gchar *file, gchar **errstr)
 {
-       return procmsg_send_message_queue_full(file, FALSE);
+       return procmsg_send_message_queue_full(file, FALSE, errstr);
 }
 
 static void update_folder_msg_counts(FolderItem *item, MsgInfo *msginfo, MsgPermFlags old_flags)
index c8da4fc..534c82d 100644 (file)
@@ -287,7 +287,8 @@ void        procmsg_empty_trash             (FolderItem     *trash);
 void   procmsg_empty_all_trash         (void);
 
 gint   procmsg_send_queue              (FolderItem     *queue,
-                                        gboolean        save_msgs);
+                                        gboolean        save_msgs,
+                                        gchar          **errstr);
 gboolean procmsg_queue_is_empty        (FolderItem *queue);
 gint   procmsg_save_to_outbox          (FolderItem     *outbox,
                                         const gchar    *file,
@@ -304,7 +305,8 @@ guint        procmsg_msginfo_memusage       (MsgInfo        *msginfo);
 
 gint procmsg_cmp_msgnum_for_sort       (gconstpointer   a,
                                         gconstpointer   b);
-gint procmsg_send_message_queue                (const gchar *file);
+gint procmsg_send_message_queue                (const gchar *file,
+                                        gchar **errstr);
 
 void procmsg_msginfo_set_flags         (MsgInfo *msginfo,
                                         MsgPermFlags perm_flags,
index 8d220b9..29cfc80 100644 (file)
@@ -607,7 +607,7 @@ static void send_put_error(Session *session)
        if (log_msg)
                log_warning("%s\n", log_msg);
        if (err_msg) {
-               alertpanel_error_log("%s", err_msg);
+               log_error("%s", err_msg);
                g_free(err_msg);
        }
 }
index edbddd8..a35ff67 100644 (file)
@@ -2892,7 +2892,7 @@ void summary_reedit(SummaryView *summaryview)
                                              summaryview->selected);
        if (!msginfo) return;
 
-       compose_reedit(msginfo);
+       compose_reedit(msginfo, FALSE);
 }
 
 gboolean summary_step(SummaryView *summaryview, GtkScrollType type)
index e45391e..4330507 100644 (file)
@@ -2085,6 +2085,7 @@ void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
        GList *list;
        gboolean found;
        gboolean got_error = FALSE;
+       gchar *errstr = NULL;
 
        if (prefs_common.work_offline)
                if (alertpanel(_("Offline warning"), 
@@ -2120,13 +2121,23 @@ void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
 
                if (folder->queue) {
                        if (procmsg_send_queue(folder->queue, 
-                                              prefs_common.savemsg) < 0)
+                                              prefs_common.savemsg,
+                                              &errstr) < 0)
                                got_error = TRUE;
                }
        }
-       if (got_error)
-               alertpanel_error(_("Some errors occurred while "
-                                  "sending queued messages."));
+       if (got_error) {
+               if (!errstr)
+                       alertpanel_error_log(_("Some errors occurred while "
+                                          "sending queued messages."));
+               else {
+                       gchar *tmp = g_strdup_printf(_("Some errors occurred "
+                                       "while sending queued messages:\n%s"), errstr);
+                       g_free(errstr);
+                       alertpanel_error_log(tmp);
+                       g_free(tmp);
+               }
+       }
 }
 
 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)