Allow custom window title for the folder selection dialog.
[claws.git] / src / compose.c
index 71b96d19cbe31458586335fe8bb04b6c1c34b544..7cd07298759170f68e329eae8b82b26ea3a634f0 100644 (file)
 #include "timing.h"
 #include "autofaces.h"
 #include "spell_entry.h"
+#include "headers.h"
 
 enum
 {
@@ -313,7 +314,7 @@ static gint compose_queue_sub                       (Compose        *compose,
                                                 gint           *msgnum,
                                                 FolderItem     **item,
                                                 gchar          **msgpath,
-                                                gboolean       check_subject,
+                                                gboolean       perform_checks,
                                                 gboolean       remove_reedit_target);
 static int compose_add_attachments             (Compose        *compose,
                                                 MimeInfo       *parent);
@@ -2224,7 +2225,6 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        GtkTextMark *mark;
        GtkTextIter iter;
        FILE *fp;
-       gchar buf[BUFFSIZE];
        gboolean use_signing = FALSE;
        gboolean use_encryption = FALSE;
        gchar *privacy_system = NULL;
@@ -2244,124 +2244,141 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
         if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
            folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
            folder_has_parent_of_type(msginfo->folder, F_OUTBOX)) {
-               gchar queueheader_buf[BUFFSIZE];
+               gchar *queueheader_buf = NULL;
                gint id, param;
 
                /* Select Account from queue headers */
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Claws-Account-Id:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                                       "X-Claws-Account-Id:")) {
                        id = atoi(&queueheader_buf[strlen("X-Claws-Account-Id:")]);
                        account = account_find_from_id(id);
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                                       "X-Sylpheed-Account-Id:")) {
                        id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
                        account = account_find_from_id(id);
+                       g_free(queueheader_buf);
                }
-               if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "NAID:")) {
+               if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                                       "NAID:")) {
                        id = atoi(&queueheader_buf[strlen("NAID:")]);
                        account = account_find_from_id(id);
+                       g_free(queueheader_buf);
                }
-               if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                                   sizeof(queueheader_buf), "MAID:")) {
+               if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                                       "MAID:")) {
                        id = atoi(&queueheader_buf[strlen("MAID:")]);
                        account = account_find_from_id(id);
+                       g_free(queueheader_buf);
                }
-               if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                                               sizeof(queueheader_buf), "S:")) {
+               if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                                       "S:")) {
                        account = account_find_from_address(queueheader_buf, FALSE);
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Claws-Sign:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                               "X-Claws-Sign:")) {
                        param = atoi(&queueheader_buf[strlen("X-Claws-Sign:")]);
                        use_signing = param;
-                       
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                               "X-Sylpheed-Sign:")) {
                        param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
                        use_signing = param;
-                       
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Claws-Encrypt:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                               "X-Claws-Encrypt:")) {
                        param = atoi(&queueheader_buf[strlen("X-Claws-Encrypt:")]);
                        use_encryption = param;
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                               "X-Sylpheed-Encrypt:")) {
                        param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
                        use_encryption = param;
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Claws-Auto-Wrapping:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                               "X-Claws-Auto-Wrapping:")) {
                        param = atoi(&queueheader_buf[strlen("X-Claws-Auto-Wrapping:")]);
                        autowrap = param;
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Claws-Auto-Indent:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                               "X-Claws-Auto-Indent:")) {
                        param = atoi(&queueheader_buf[strlen("X-Claws-Auto-Indent:")]);
                        autoindent = param;
+                       g_free(queueheader_buf);
+               }
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                       "X-Claws-Privacy-System:")) {
+                       privacy_system = g_strdup(&queueheader_buf[strlen("X-Claws-Privacy-System:")]);
+                       g_free(queueheader_buf);
                }
-                if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Claws-Privacy-System:")) {
-                        privacy_system = g_strdup(&queueheader_buf[strlen("X-Claws-Privacy-System:")]);
-                }
-                if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
-                        privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
-                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "X-Priority: ")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                       "X-Sylpheed-Privacy-System:")) {
+                       privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
+                       g_free(queueheader_buf);
+               }
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                               "X-Priority: ")) {
                        param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
                        priority = param;
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "RMID:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
+                                                                                       "RMID:")) {
                        gchar **tokens = g_strsplit(&queueheader_buf[strlen("RMID:")], "\t", 0);
-                       if (tokens[0] && tokens[1] && tokens[2]) {
+                       if (tokens && tokens[0] && tokens[1] && tokens[2]) {
                                FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
                                if (orig_item != NULL) {
                                        replyinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
                                }
+                               g_strfreev(tokens);
                        }
-                       g_strfreev(tokens);
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "FMID:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, 
+                                                                               "FMID:")) {
                        gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0);
-                       if (tokens[0] && tokens[1] && tokens[2]) {
+                       if (tokens && tokens[0] && tokens[1] && tokens[2]) {
                                FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
                                if (orig_item != NULL) {
                                        fwdinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
                                }
+                               g_strfreev(tokens);
                        }
-                       g_strfreev(tokens);
+                       g_free(queueheader_buf);
                }
                /* Get manual headers */
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "X-Claws-Manual-Headers:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
+                                                                                       "X-Claws-Manual-Headers:")) {
                        gchar *listmh = g_strdup(&queueheader_buf[strlen("X-Claws-Manual-Headers:")]);
-                       if (*listmh != '\0') {
+                       if (listmh && *listmh != '\0') {
                                debug_print("Got manual headers: %s\n", listmh);
                                manual_headers = procheader_entries_from_str(listmh);
+                               g_free(listmh);
                        }
-                       g_free(listmh);
+                       g_free(queueheader_buf);
                }
        } else {
                account = msginfo->folder->folder->account;
        }
 
        if (!account && prefs_common.reedit_account_autosel) {
-                       gchar from[BUFFSIZE];
-               if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
-                       extract_address(from);
-                       account = account_find_from_address(from, FALSE);
-                }
-       }
-        if (!account) {
-               account = cur_account;
-        }
+               gchar *from = NULL;
+               if (!procheader_get_header_from_msginfo(msginfo, &from, "FROM:")) {
+                       extract_address(from);
+                       account = account_find_from_address(from, FALSE);
+                       g_free(from);
+               }
+       }
+       if (!account) {
+               account = cur_account;
+       }
        cm_return_val_if_fail(account != NULL, NULL);
 
        compose = compose_create(account, msginfo->folder, COMPOSE_REEDIT, batch);
@@ -2388,21 +2405,23 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
 
        compose_extract_original_charset(compose);
 
-        if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
+       if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
            folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
            folder_has_parent_of_type(msginfo->folder, F_OUTBOX)) {
-               gchar queueheader_buf[BUFFSIZE];
+               gchar *queueheader_buf = NULL;
 
                /* Set message save folder */
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "SCF:")) {
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
                        compose_set_save_to(compose, &queueheader_buf[4]);
+                       g_free(queueheader_buf);
                }
-               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
+               if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "RRCPT:")) {
                        gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
                        if (active) {
                                cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", TRUE);
                        }
+                       g_free(queueheader_buf);
                }
        }
        
@@ -2437,6 +2456,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        }
 
        if (fp != NULL) {
+               gchar buf[BUFFSIZE];
                gboolean prev_autowrap;
                GtkTextBuffer *buffer;
                BLOCK_WRAP();
@@ -3736,7 +3756,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
                g_free(file_from_uri);
                if (result)
                        return TRUE;
-               alertpanel_error("File %s doesn't exist\n", filename);
+               alertpanel_error("File %s doesn't exist or permission denied\n", filename);
                return FALSE;
        }
        if ((size = get_file_size(file)) < 0) {
@@ -5132,6 +5152,54 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                }
        }
 
+       if (!compose->batch && prefs_common.warn_sending_many_recipients_num > 0
+                       && check_everything == TRUE) {
+               GSList *list;
+               gint cnt = 0;
+
+               /* count To and Cc recipients */
+               for (list = compose->header_list; list; list = list->next) {
+                       gchar *header;
+                       gchar *entry;
+
+                       header = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
+                       entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
+                       g_strstrip(header);
+                       g_strstrip(entry);
+                       if ((entry[0] != '\0')
+                       &&      (strcmp(header, prefs_common_translated_header_name("To:"))
+                       ||  strcmp(header, prefs_common_translated_header_name("Cc:")))) {
+                               cnt++;
+                       }
+                       g_free(header);
+                       g_free(entry);
+               }
+               if (cnt > prefs_common.warn_sending_many_recipients_num) {
+                       AlertValue aval;
+                       gchar *button_label;
+                       gchar *message;
+
+                       if (compose->sending)
+                               button_label = g_strconcat("+", _("_Send"), NULL);
+                       else
+                               button_label = g_strconcat("+", _("_Queue"), NULL);
+                       message = g_strdup_printf(_("Sending to %d recipients. %s"), cnt,
+                                       compose->sending?_("Send it anyway?"):
+                                       _("Queue it anyway?"));
+
+                       aval = alertpanel_full(compose->sending?_("Send"):_("Send later"), message,
+                                              GTK_STOCK_CANCEL, button_label, NULL, TRUE, NULL,
+                                              ALERT_QUESTION, G_ALERTDEFAULT);
+                       g_free(message);
+                       if (aval & G_ALERTDISABLE) {
+                               aval &= ~G_ALERTDISABLE;
+                               prefs_common.warn_sending_many_recipients_num = 0;
+                       }
+                       if (aval != G_ALERTALTERNATE)
+                               return FALSE;
+               }
+       }
+
        if (check_everything && hooks_invoke(COMPOSE_CHECK_BEFORE_SEND_HOOKLIST, compose))
                return FALSE;
 
@@ -5377,6 +5445,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
 
 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
 {
+       gchar date[RFC822_DATE_BUFFSIZE];
        gchar buf[BUFFSIZE];
        gchar *str;
        const gchar *entstr;
@@ -5389,9 +5458,9 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
 
        /* Resent-Date */
        if (prefs_common.hide_timezone)
-               get_rfc822_date_hide_tz(buf, sizeof(buf));
+               get_rfc822_date_hide_tz(date, sizeof(date));
        else
-               get_rfc822_date(buf, sizeof(buf));
+               get_rfc822_date(date, sizeof(date));
        err |= (fprintf(fp, "Resent-Date: %s\n", buf) < 0);
 
        /* Resent-From */
@@ -5440,7 +5509,8 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
 {
        FILE *fp;
        size_t len;
-       gchar buf[BUFFSIZE];
+       gchar *buf = NULL;
+       gchar rewrite_buf[BUFFSIZE];
        int i = 0;
        gboolean skip = FALSE;
        gboolean err = FALSE;
@@ -5461,12 +5531,14 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                "X-Claws-Auto-Wrapping:", "X-Claws-Auto-Indent:",
                NULL
                };
+       gint ret = 0;
+
        if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
                FILE_OP_ERROR(compose->redirect_filename, "fopen");
                return -1;
        }
 
-       while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
+       while ((ret = procheader_get_one_field_asis(&buf, fp)) != -1) {
                skip = FALSE;
                for (i = 0; not_included[i] != NULL; i++) {
                        if (g_ascii_strncasecmp(buf, not_included[i],
@@ -5475,10 +5547,16 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                                break;
                        }
                }
-               if (skip)
+               if (skip) {
+                       g_free(buf);
+                       buf = NULL;
                        continue;
-               if (fputs(buf, fdest) == -1)
+               }
+               if (fputs(buf, fdest) == -1) {
+                       g_free(buf);
+                       buf = NULL;
                        goto error;
+               }
 
                if (!prefs_common.redirect_keep_from) {
                        if (g_ascii_strncasecmp(buf, "From:",
@@ -5486,13 +5564,15 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                                err |= (fputs(" (by way of ", fdest) == EOF);
                                if (compose->account->name
                                    && *compose->account->name) {
+                                       gchar buffer[BUFFSIZE];
+
                                        compose_convert_header
-                                               (compose, buf, sizeof(buf),
+                                               (compose, buffer, sizeof(buffer),
                                                 compose->account->name,
                                                 strlen("From: "),
                                                 FALSE);
                                        err |= (fprintf(fdest, "%s <%s>",
-                                               buf,
+                                               buffer,
                                                compose->account->address) < 0);
                                } else
                                        err |= (fprintf(fdest, "%s",
@@ -5501,6 +5581,8 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                        }
                }
 
+               g_free(buf);
+               buf = NULL;
                if (fputs("\n", fdest) == -1)
                        goto error;
        }
@@ -5511,14 +5593,15 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
        if (compose_redirect_write_headers(compose, fdest))
                goto error;
 
-       while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
-               if (fwrite(buf, sizeof(gchar), len, fdest) != len)
+       while ((len = fread(rewrite_buf, sizeof(gchar), sizeof(rewrite_buf), fp)) > 0) {
+               if (fwrite(rewrite_buf, sizeof(gchar), len, fdest) != len)
                        goto error;
        }
 
        fclose(fp);
 
        return 0;
+
 error:
        fclose(fp);
 
@@ -5940,7 +6023,7 @@ static gboolean compose_warn_encryption(Compose *compose)
 }
 
 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, 
-                             gchar **msgpath, gboolean check_subject,
+                             gchar **msgpath, gboolean perform_checks,
                              gboolean remove_reedit_target)
 {
        FolderItem *queue;
@@ -5954,7 +6037,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        debug_print("queueing message...\n");
        cm_return_val_if_fail(compose->account != NULL, -1);
 
-       if (compose_check_entries(compose, check_subject) == FALSE) {
+       if (compose_check_entries(compose, perform_checks) == FALSE) {
                if (compose->batch) {
                        gtk_widget_show_all(compose->window);
                }
@@ -6211,9 +6294,7 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
        if (!gtk_tree_model_get_iter_first(model, &iter))
                return 0;
        do {
-               gtk_tree_model_get(model, &iter,
-                                  COL_DATA, &ainfo,
-                                  -1);
+               gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
                
                if (!is_file_exist(ainfo->file)) {
                        gchar *msg = g_strdup_printf(_("Attachment %s doesn't exist anymore. Ignore?"), ainfo->file);
@@ -6242,11 +6323,11 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
                        type = g_strdup("application/octet-stream");
                }
 
-               subtype = strchr(type, '/') + 1;
-               *(subtype - 1) = '\0';
-               mimepart->type = procmime_get_media_type(type);
-               mimepart->subtype = g_strdup(subtype);
-               g_free(type);
+               subtype = strchr(type, '/') + 1;
+               *(subtype - 1) = '\0';
+               mimepart->type = procmime_get_media_type(type);
+               mimepart->subtype = g_strdup(subtype);
+               g_free(type);
 
                if (mimepart->type == MIMETYPE_MESSAGE && 
                    !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
@@ -6284,8 +6365,6 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
                                ainfo->encoding = ENC_BASE64;
                }
 
-               
-               
                procmime_encode_content(mimepart, ainfo->encoding);
 
                g_node_append(parent->node, mimepart->node);
@@ -6340,6 +6419,41 @@ static gchar *compose_quote_list_of_addresses(gchar *str)
        (compose->account->add_customhdr && \
         custom_header_find(compose->account->customhdr_list, header) != NULL)
 
+static const gchar *compose_untranslated_header_name(gchar *header_name)
+{
+       /* return the untranslated header name, if header_name is a known
+          header name, in either its translated or untranslated form, with
+          or without trailing colon. return NULL if no matching header name
+          is found or if header_name is NULL. */
+       gchar *translated_header_name;
+       gchar *translated_header_name_wcolon;
+       const gchar *untranslated_header_name;
+       const gchar *untranslated_header_name_wcolon;
+       gint i;
+
+       cm_return_val_if_fail(header_name != NULL, NULL);
+
+       for (i = 0; HEADERS[i].header_name != NULL; i++) {
+               untranslated_header_name = HEADERS[i].header_name;
+               untranslated_header_name_wcolon = HEADERS[i].header_name_w_colon;
+
+               translated_header_name = gettext(untranslated_header_name);
+               translated_header_name_wcolon = gettext(untranslated_header_name_wcolon);
+
+               if (!strcmp(header_name, untranslated_header_name) ||
+                       !strcmp(header_name, translated_header_name)) {
+                       return untranslated_header_name;
+               } else {
+                       if (!strcmp(header_name, untranslated_header_name_wcolon) ||
+                               !strcmp(header_name, translated_header_name_wcolon)) {
+                               return untranslated_header_name_wcolon;
+                       }
+               }
+       }
+       debug_print("compose_untranslated_header_name: unknown header '%s'\n", header_name);
+       return NULL;
+}
+
 static void compose_add_headerfield_from_headerlist(Compose *compose, 
                                                    GString *header, 
                                                    const gchar *fieldname,
@@ -6449,6 +6563,7 @@ static gchar *compose_get_manual_headers_info(Compose *compose)
 
 static gchar *compose_get_header(Compose *compose)
 {
+       gchar date[RFC822_DATE_BUFFSIZE];
        gchar buf[BUFFSIZE];
        const gchar *entry_str;
        gchar *str;
@@ -6466,10 +6581,10 @@ static gchar *compose_get_header(Compose *compose)
 
        /* Date */
        if (prefs_common.hide_timezone)
-               get_rfc822_date_hide_tz(buf, sizeof(buf));
+               get_rfc822_date_hide_tz(date, sizeof(date));
        else
-               get_rfc822_date(buf, sizeof(buf));
-       g_string_append_printf(header, "Date: %s\n", buf);
+               get_rfc822_date(date, sizeof(date));
+       g_string_append_printf(header, "Date: %s\n", date);
 
        /* From */
        
@@ -6698,16 +6813,22 @@ static gchar *compose_get_header(Compose *compose)
                Xstrdup_a(headervalue, entry_str, return NULL);
                subst_char(headervalue, '\r', ' ');
                subst_char(headervalue, '\n', ' ');
-               string = std_headers;
-               while (*string != NULL) {
-                       headername_trans = prefs_common_translated_header_name(*string);
-                       if (!strcmp(headername_trans, headername_wcolon))
-                               standard_header = TRUE;
-                       string++;
-               }
-               if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
-                       g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
-                               
+               g_strstrip(headervalue);
+               if (*headervalue != '\0') {
+                       string = std_headers;
+                       while (*string != NULL && !standard_header) {
+                               headername_trans = prefs_common_translated_header_name(*string);
+                               /* support mixed translated and untranslated headers */
+                               if (!strcmp(headername_trans, headername_wcolon) || !strcmp(*string, headername_wcolon))
+                                       standard_header = TRUE;
+                               string++;
+                       }
+                       if (!standard_header && !IS_IN_CUSTOM_HEADER(headername)) {
+                               /* store untranslated header name */
+                               g_string_append_printf(header, "%s %s\n",
+                                               compose_untranslated_header_name(headername_wcolon), headervalue);
+                       }
+               }                               
                g_free(headername);
                g_free(headername_wcolon);              
        }
@@ -7325,7 +7446,8 @@ static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
        FolderItem *dest;
        gchar * path;
 
-       dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
+       dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE,
+                       _("Select folder to save message to"));
        if (!dest) return;
 
        path = folder_item_get_identifier(dest);
@@ -8913,20 +9035,26 @@ static void compose_attach_update_label(Compose *compose)
        gint i = 1;
        gchar *text;
        GtkTreeModel *model;
-       
-       if(compose == NULL)
+       goffset total_size;
+       AttachInfo *ainfo;
+
+       if (compose == NULL)
                return;
-               
+
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(compose->attach_clist));
-       if(!gtk_tree_model_get_iter_first(model, &iter)) {
+       if (!gtk_tree_model_get_iter_first(model, &iter)) {
                gtk_label_set_text(GTK_LABEL(compose->attach_label), "");       
                return;
        }
-       
-       while(gtk_tree_model_iter_next(model, &iter))
+
+       gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
+       total_size = ainfo->size;
+       while(gtk_tree_model_iter_next(model, &iter)) {
+               gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
+               total_size += ainfo->size;
                i++;
-       
-       text = g_strdup_printf("(%d)", i);
+       }
+       text = g_strdup_printf(" (%d/%s)", i, to_human_readable(total_size));
        gtk_label_set_text(GTK_LABEL(compose->attach_label), text);
        g_free(text);
 }
@@ -9430,7 +9558,7 @@ static gboolean compose_get_ext_editor_cmd_valid()
 
 static gint compose_exec_ext_editor_real(const gchar *file, GdkNativeWindow socket_wid)
 {
-       gchar buf[1024];
+       gchar *buf;
        gchar *p, *s;
        gchar **cmdline;
        pid_t pid;
@@ -9455,22 +9583,22 @@ static gint compose_exec_ext_editor_real(const gchar *file, GdkNativeWindow sock
                        s = strstr(p, "%w");
                        s[1] = 'u';
                        if (strstr(p, "%s") < s)
-                               g_snprintf(buf, sizeof(buf), p, file, socket_wid);
+                               buf = g_strdup_printf(p, file, socket_wid);
                        else
-                               g_snprintf(buf, sizeof(buf), p, socket_wid, file);
+                               buf = g_strdup_printf(p, socket_wid, file);
                        g_free(p);
                } else {
-                       g_snprintf(buf, sizeof(buf),
-                                  prefs_common_get_ext_editor_cmd(), file);
+                       buf = g_strdup_printf(prefs_common_get_ext_editor_cmd(), file);
                }
        } else {
                if (prefs_common_get_ext_editor_cmd())
                        g_warning("External editor command-line is invalid: '%s'",
                                  prefs_common_get_ext_editor_cmd());
-               g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
+               buf = g_strdup_printf(DEFAULT_EDITOR_CMD, file);
        }
 
-       cmdline = strsplit_with_quote(buf, " ", 1024);
+       cmdline = strsplit_with_quote(buf, " ", 0);
+       g_free(buf);
        execvp(cmdline[0], cmdline);
 
        perror("execvp");
@@ -11765,23 +11893,25 @@ static PrefsAccount *compose_find_account(MsgInfo *msginfo)
        }
 
        if (!account && prefs_common.forward_account_autosel) {
-               gchar cc[BUFFSIZE];
+               gchar *cc = NULL;
                if (!procheader_get_header_from_msginfo
-                       (msginfo, cc,sizeof cc , "Cc:")) { 
+                               (msginfo, &cc, "Cc:")) { 
                        gchar *buf = cc + strlen("Cc:");
-                       extract_address(buf);
-                       account = account_find_from_address(buf, FALSE);
-                }
+                       extract_address(buf);
+                       account = account_find_from_address(buf, FALSE);
+                       g_free(cc);
+               }
        }
        
        if (!account && prefs_common.forward_account_autosel) {
-               gchar deliveredto[BUFFSIZE];
+               gchar *deliveredto = NULL;
                if (!procheader_get_header_from_msginfo
-                       (msginfo, deliveredto,sizeof deliveredto , "Delivered-To:")) { 
+                               (msginfo, &deliveredto, "Delivered-To:")) { 
                        gchar *buf = deliveredto + strlen("Delivered-To:");
-                       extract_address(buf);
-                       account = account_find_from_address(buf, FALSE);
-                }
+                       extract_address(buf);
+                       account = account_find_from_address(buf, FALSE);
+                       g_free(deliveredto);
+               }
        }
 
        if (!account)
@@ -12011,15 +12141,15 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
 {
        MsgInfo *newmsginfo;
        GSList *list;
-       gchar buf[BUFFSIZE];
+       gchar date[RFC822_DATE_BUFFSIZE];
 
        cm_return_val_if_fail( compose != NULL, NULL );
 
        newmsginfo = procmsg_msginfo_new();
 
        /* date is now */
-       get_rfc822_date(buf, sizeof(buf));
-       newmsginfo->date = g_strdup(buf);
+       get_rfc822_date(date, sizeof(date));
+       newmsginfo->date = g_strdup(date);
 
        /* from */
        if (compose->from_name) {