fix Resent-Date value
[claws.git] / src / compose.c
index bdb14b40a7b056da15040808683726d58bf5478c..224e5c15525d5ce2d439c7808f5eeeb0bdd09dc5 100644 (file)
 #include "timing.h"
 #include "autofaces.h"
 #include "spell_entry.h"
+#include "headers.h"
 
 enum
 {
@@ -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, 
+                                       "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, 
-                                            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-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,7 +5152,7 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                }
        }
 
-       if (!compose->batch && prefs_common.warn_sending_many_recipients == TRUE
+       if (!compose->batch && prefs_common.warn_sending_many_recipients_num > 0
                        && check_everything == TRUE) {
                GSList *list;
                gint cnt = 0;
@@ -5173,7 +5193,7 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                        g_free(message);
                        if (aval & G_ALERTDISABLE) {
                                aval &= ~G_ALERTDISABLE;
-                               prefs_common.warn_empty_subj = FALSE;
+                               prefs_common.warn_sending_many_recipients_num = 0;
                        }
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
@@ -5425,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;
@@ -5437,10 +5458,10 @@ 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));
-       err |= (fprintf(fp, "Resent-Date: %s\n", buf) < 0);
+               get_rfc822_date(date, sizeof(date));
+       err |= (fprintf(fp, "Resent-Date: %s\n", date) < 0);
 
        /* Resent-From */
        if (compose->account->name && *compose->account->name) {
@@ -5488,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;
@@ -5509,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],
@@ -5523,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:",
@@ -5534,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",
@@ -5549,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;
        }
@@ -5559,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);
 
@@ -5576,7 +5611,7 @@ error:
 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
 {
        GtkTextBuffer *buffer;
-       GtkTextIter start, end;
+       GtkTextIter start, end, tmp;
        gchar *chars, *tmp_enc_file, *content;
        gchar *buf, *msg;
        const gchar *out_codeset;
@@ -5608,10 +5643,20 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        mimemsg->data.mem = compose_get_header(compose);
 
        /* Create text part MimeInfo */
-       /* get all composed text */
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
-       gtk_text_buffer_get_start_iter(buffer, &start);
        gtk_text_buffer_get_end_iter(buffer, &end);
+       tmp = end;
+
+       /* We make sure that there is a newline at the end. */
+       if (action == COMPOSE_WRITE_FOR_SEND && gtk_text_iter_backward_char(&tmp)) {
+               chars = gtk_text_buffer_get_text(buffer, &tmp, &end, FALSE);
+               if (*chars != '\n') {
+                       gtk_text_buffer_insert(buffer, &end, "\n", 1);
+               }
+       }
+
+       /* get all composed text */
+       gtk_text_buffer_get_start_iter(buffer, &start);
        chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
 
        out_codeset = conv_get_charset_str(compose->out_encoding);
@@ -6259,9 +6304,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);
@@ -6290,11 +6333,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")) {
@@ -6332,8 +6375,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);
@@ -6388,6 +6429,40 @@ 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. otherwise, returns header_name. */
+       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 header_name;
+}
+
 static void compose_add_headerfield_from_headerlist(Compose *compose, 
                                                    GString *header, 
                                                    const gchar *fieldname,
@@ -6497,6 +6572,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;
@@ -6514,10 +6590,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 */
        
@@ -6746,16 +6822,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);              
        }
@@ -7373,7 +7455,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);
@@ -8719,7 +8802,7 @@ static void compose_template_apply_fields_error(const gchar *header)
        tr = g_strdup(C_("'%s' stands for a header name",
                                  "Template '%s' format error."));
        text = g_strdup_printf(tr, prefs_common_translated_header_name(header));
-       alertpanel_error(text);
+       alertpanel_error("%s", text);
 
        g_free(text);
        g_free(tr);
@@ -8961,20 +9044,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);
 }
@@ -11813,23 +11902,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)
@@ -12059,15 +12150,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) {