fix memory leak in
[claws.git] / src / compose.c
index f426b005bfd69431abd193e865b2f1aaa926067d..99938cde1ddd910fc2283637f5617689b56f5869 100644 (file)
@@ -138,6 +138,15 @@ typedef enum
        COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
 } ComposeCallGtkSTextAction;
 
+typedef enum
+{
+       PRIORITY_HIGHEST = 1,
+       PRIORITY_HIGH,
+       PRIORITY_NORMAL,
+       PRIORITY_LOW,
+       PRIORITY_LOWEST
+} PriorityLevel;
+
 #define B64_LINE_SIZE          57
 #define B64_BUFFSIZE           77
 
@@ -201,7 +210,8 @@ static PrefsAccount *compose_current_mail_account(void);
 /* static gint compose_send                    (Compose        *compose); */
 static gboolean compose_check_for_valid_recipient
                                                (Compose        *compose);
-static gboolean compose_check_entries          (Compose        *compose);
+static gboolean compose_check_entries          (Compose        *compose,
+                                                gboolean       check_subject);
 static gint compose_write_to_file              (Compose        *compose,
                                                 const gchar    *file,
                                                 gboolean        is_draft);
@@ -211,6 +221,10 @@ static gint compose_remove_reedit_target   (Compose        *compose);
 static gint compose_queue                      (Compose        *compose,
                                                 gint           *msgnum,
                                                 FolderItem     **item);
+static gint compose_queue_sub                  (Compose        *compose,
+                                                gint           *msgnum,
+                                                FolderItem     **item,
+                                                gboolean       check_subject);
 static void compose_write_attach               (Compose        *compose,
                                                 FILE           *fp);
 static gint compose_write_headers              (Compose        *compose,
@@ -263,6 +277,7 @@ static gint calc_cursor_xpos        (GtkSText       *text,
 
 static void compose_create_header_entry        (Compose *compose);
 static void compose_add_header_entry   (Compose *compose, gchar *header, gchar *text);
+static void compose_update_priority_menu_item(Compose * compose);
 
 /* callback functions */
 
@@ -402,6 +417,9 @@ static void compose_toggle_encrypt_cb       (gpointer        data,
 #endif
 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
                                             GtkWidget *widget);
+static void compose_set_priority_cb    (gpointer        data,
+                                        guint           action,
+                                        GtkWidget      *widget);
 
 static void compose_attach_drag_received_cb (GtkWidget         *widget,
                                             GdkDragContext     *drag_context,
@@ -623,6 +641,13 @@ static GtkItemFactoryEntry compose_entries[] =
        {N_("/_Message/Si_gn"),         NULL, compose_toggle_sign_cb   , 0, "<ToggleItem>"},
        {N_("/_Message/_Encrypt"),      NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
 #endif /* USE_GPGME */
+       {N_("/_Message/---"),           NULL,           NULL,   0, "<Separator>"},
+       {N_("/_Message/Priority"),      NULL,           NULL,   0, "<Branch>"},
+       {N_("/_Message/Priority/Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
+       {N_("/_Message/Priority/High"),    NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
+       {N_("/_Message/Priority/Normal"),  NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
+       {N_("/_Message/Priority/Low"),     NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
+       {N_("/_Message/Priority/Lowest"),  NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
        {N_("/_Message/---"),           NULL,           NULL,   0, "<Separator>"},
        {N_("/_Message/_Request Return Receipt"),       NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
        {N_("/_Tools"),                 NULL, NULL, 0, "<Branch>"},
@@ -644,7 +669,7 @@ Compose *compose_new(PrefsAccount *account)
        return compose_generic_new(account, NULL, NULL);
 }
 
-Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
+Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
 {
        Compose *c;
        gchar *filename;
@@ -656,7 +681,7 @@ Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
        if (filename == NULL)
                return NULL;
 
-       c->bounce_filename = filename;
+       c->redirect_filename = filename;
 
        if (msginfo->subject)
                gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
@@ -1395,6 +1420,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                                       {"Followup-To:",    NULL, FALSE},
                                       {"X-Mailing-List:", NULL, FALSE},
                                       {"X-BeenThere:",    NULL, FALSE},
+                                      {"X-Priority:",     NULL, FALSE},
                                       {NULL,              NULL, FALSE}};
 
        enum
@@ -1406,7 +1432,8 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                H_NEWSGROUPS     = 4,
                H_FOLLOWUP_TO    = 5,
                H_X_MAILING_LIST = 6,
-               H_X_BEENTHERE    = 7
+               H_X_BEENTHERE    = 7,
+               H_X_PRIORITY     = 8
        };
 
        FILE *fp;
@@ -1475,6 +1502,22 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                hentry[H_FOLLOWUP_TO].body = NULL;
        }
 
+       if (compose->mode == COMPOSE_REEDIT)
+               if (hentry[H_X_PRIORITY].body != NULL) {
+                       gint priority;
+                       
+                       priority = atoi(hentry[H_X_PRIORITY].body);
+                       g_free(hentry[H_X_PRIORITY].body);
+                       
+                       hentry[H_X_PRIORITY].body = NULL;
+                       
+                       if (priority < PRIORITY_HIGHEST || 
+                           priority > PRIORITY_LOWEST)
+                               priority = PRIORITY_NORMAL;
+                       
+                       compose->priority =  priority;
+               }
        if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
                compose->inreplyto = g_strdup(msginfo->inreplyto);
        else if (compose->mode != COMPOSE_REEDIT &&
@@ -1726,6 +1769,8 @@ static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
        SET_ADDRESS(COMPOSE_BCC, compose->bcc);
        SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
 
+       compose_update_priority_menu_item(compose);
+
        compose_show_first_last_header(compose, TRUE);
 
 #if 0 /* NEW COMPOSE GUI */
@@ -1998,6 +2043,9 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        }                                                                    \
 }
 
+#define INDENT_CHARS   ">|#"
+#define SPACE_CHARS    " \t"
+
 static void compose_wrap_line(Compose *compose)
 {
        GtkSText *text = GTK_STEXT(compose->text);
@@ -2038,7 +2086,8 @@ static void compose_wrap_line(Compose *compose)
                        }
                        line_end = 1;
                } else {
-                       if (ch_len == 1 && strchr(">|:#", *cbuf))
+                       if (ch_len == 1 
+                           && strchr(prefs_common.quote_chars, *cbuf))
                                quoted = 1;
                        else if (ch_len != 1 || !isspace(*cbuf))
                                quoted = 0;
@@ -2060,7 +2109,8 @@ static void compose_wrap_line(Compose *compose)
                        }
                        line_end = 1;
                } else {
-                       if (line_end && ch_len == 1 && strchr(">|:#", *cbuf))
+                       if (line_end && ch_len == 1 &&
+                           strchr(prefs_common.quote_chars, *cbuf))
                                goto compose_end; /* quoted part */
 
                        line_end = 0;
@@ -2177,13 +2227,10 @@ void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
 #endif
 
 typedef enum {
-       WAIT_FOR_SPACETAB,
-       WAIT_FOR_INDENTCHAR,
-       WAIT_FOR_INDENTCHARORSPACETAB
-} IndentStates;
-
-#define INDCHARS   ">|:#"
-#define SPACECHARS " \t"
+       WAIT_FOR_SPACE,
+       WAIT_FOR_INDENT_CHAR,
+       WAIT_FOR_INDENT_CHAR_OR_SPACE
+} IndentState;
 
 /* return indent length, we allow:
    > followed by spaces/tabs
@@ -2195,50 +2242,52 @@ static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
 {
        guint i_len = 0;
        guint i, ch_len, alnum_cnt = 0;
-       IndentStates state = WAIT_FOR_INDENTCHAR;
-       gchar cb[MB_LEN_MAX];
+       IndentState state = WAIT_FOR_INDENT_CHAR;
+       gchar cbuf[MB_LEN_MAX];
        gboolean is_space;
        gboolean is_indent;
 
        for (i = start_pos; i < text_len; i++) {
-               GET_CHAR(i, cb, ch_len);
+               GET_CHAR(i, cbuf, ch_len);
                if (ch_len > 1)
                        break;
 
-               if (cb[0] == '\n')
+               if (cbuf[0] == '\n')
                        break;
 
-               is_indent = strchr(INDCHARS, cb[0]) ? TRUE : FALSE;
-               is_space = strchr(SPACECHARS, cb[0]) ? TRUE : FALSE;
+               is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
+               is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
 
                switch (state) {
-               case WAIT_FOR_SPACETAB:
+               case WAIT_FOR_SPACE:
                        if (is_space == FALSE)
                                goto out;
-                       state = WAIT_FOR_INDENTCHARORSPACETAB;
+                       state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
                        break;
-               case WAIT_FOR_INDENTCHARORSPACETAB:
+               case WAIT_FOR_INDENT_CHAR_OR_SPACE:
                        if (is_indent == FALSE && is_space == FALSE &&
-                           !isupper(cb[0]))
+                           !isupper(cbuf[0]))
                                goto out;
                        if (is_space == TRUE) {
                                alnum_cnt = 0;
-                               state = WAIT_FOR_INDENTCHARORSPACETAB;
+                               state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
                        } else if (is_indent == TRUE) {
                                alnum_cnt = 0;
-                               state = WAIT_FOR_SPACETAB;
+                               state = WAIT_FOR_SPACE;
                        } else {
                                alnum_cnt++;
-                               state = WAIT_FOR_INDENTCHAR;
-                               break;
+                               state = WAIT_FOR_INDENT_CHAR;
                        }
                        break;
-               case WAIT_FOR_INDENTCHAR:
-                       if (is_indent == FALSE && !isupper(cb[0]))
+               case WAIT_FOR_INDENT_CHAR:
+                       if (is_indent == FALSE && !isupper(cbuf[0]))
                                goto out;
                        if (is_indent == TRUE) {
+                               if (alnum_cnt > 0 
+                                   && !strchr(prefs_common.quote_chars, cbuf[0]))
+                                       goto out;
                                alnum_cnt = 0;
-                               state = WAIT_FOR_SPACETAB;
+                               state = WAIT_FOR_SPACE;
                        } else {
                                alnum_cnt++;
                        }
@@ -2249,7 +2298,7 @@ static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
        }
 
 out:
-       if ((i_len > 0) && (state == WAIT_FOR_INDENTCHAR))
+       if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
                i_len -= alnum_cnt;
 
        return i_len;
@@ -2286,7 +2335,7 @@ static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
 
        if ((indent_len > 0) && (indent_len == prev_ilen)) {
                GET_CHAR(start_pos + indent_len, cbuf, ch_len);
-               if (ch_len == 1 && (cbuf[0] != '\n'))
+               if (ch_len > 0 && (cbuf[0] != '\n'))
                        do_join = TRUE;
        }
 
@@ -2351,7 +2400,6 @@ static void compose_wrap_line_all(Compose *compose)
                /* we have encountered line break */
                if (ch_len == 1 && *cbuf == '\n') {
                        gint clen;
-                       guint ilen;
                        gchar cb[MB_CUR_MAX];
 
                        /* should we join the next line */
@@ -2386,6 +2434,7 @@ static void compose_wrap_line_all(Compose *compose)
                                /* if text starts with quote fmt or with
                                   indent string, delete them */
                                if (i_len) {
+                                       guint ilen;
                                        ilen =  gtkut_stext_str_compare_n
                                                (text, cur_pos, p_pos, i_len,
                                                 tlen);
@@ -2627,7 +2676,7 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
        return recipient_found;
 }
 
-static gboolean compose_check_entries(Compose *compose)
+static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
 {
        gchar *str;
 
@@ -2637,7 +2686,7 @@ static gboolean compose_check_entries(Compose *compose)
        }
 
        str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
-       if (*str == '\0') {
+       if (*str == '\0' && check_subject == TRUE) {
                AlertValue aval;
 
                aval = alertpanel(_("Send"),
@@ -2656,7 +2705,7 @@ gint compose_send(Compose *compose)
        FolderItem *folder;
        gint val;
 
-       if (compose_check_entries(compose) == FALSE)
+       if (compose_check_entries(compose, TRUE) == FALSE)
                return -1;
 
        val = compose_queue(compose, &msgnum, &folder);
@@ -2687,7 +2736,7 @@ gint compose_send(Compose *compose)
 
        lock = TRUE;
 
-       if (compose_check_entries(compose) == FALSE) {
+       if (compose_check_entries(compose, TRUE) == FALSE) {
                lock = FALSE;
                return 1;
        }
@@ -2780,16 +2829,13 @@ gint compose_send(Compose *compose)
                }
                /* save message to outbox */
                if (prefs_common.savemsg) {
-                       Folder *folder = FOLDER(compose->account->folder);
-                       FolderItem *outbox = NULL;
+                       FolderItem *outbox;
 
-                       if (folder)
-                               outbox = folder->outbox;
-                       if (!outbox)
-                               outbox = folder_get_default_outbox();
+                       outbox = account_get_special_folder
+                               (compose->account, F_OUTBOX);
                        if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
                                alertpanel_error
-                                       (_("Can't save the message to outbox."));
+                                       (_("Can't save the message to Sent."));
                        else
                                folderview_update_item(outbox, TRUE);
                }
@@ -2805,8 +2851,8 @@ static gboolean compose_use_attach(Compose *compose) {
     return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
 }
 
-static gint compose_bounce_write_headers_from_headerlist(Compose *compose, 
-                                                        FILE *fp)
+static gint compose_redirect_write_headers_from_headerlist(Compose *compose, 
+                                                          FILE *fp)
 {
        gchar buf[BUFFSIZE];
        gchar *str;
@@ -2814,17 +2860,14 @@ static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
        GSList *list;
        ComposeHeaderEntry *headerentry;
        gchar *headerentryname;
-       gchar *header_w_colon;
        gchar *cc_hdr;
        gchar *to_hdr;
 
-       debug_print(_("Writing bounce header\n"));
+       debug_print(_("Writing redirect header\n"));
+
+       cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
+       to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
 
-       header_w_colon = g_strconcat("To:", NULL);
-       to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
-       header_w_colon = g_strconcat("Cc:", NULL);
-       cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
-       
        first_address = TRUE;
        for(list = compose->header_list; list; list = list->next) {
                headerentry = ((ComposeHeaderEntry *)list->data);
@@ -2856,7 +2899,7 @@ static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
        return(0);
 }
 
-static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
+static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
 {
        gchar buf[BUFFSIZE];
        gchar *str;
@@ -2866,11 +2909,11 @@ static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
        g_return_val_if_fail(compose->account != NULL, -1);
        g_return_val_if_fail(compose->account->address != NULL, -1);
 
-       /* Date */
+       /* Resent-Date */
        get_rfc822_date(buf, sizeof(buf));
        fprintf(fp, "Resent-Date: %s\n", buf);
 
-       /* From */
+       /* Resent-From */
        if (compose->account->name && *compose->account->name) {
                compose_convert_header
                        (buf, sizeof(buf), compose->account->name,
@@ -2880,8 +2923,26 @@ static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
        } else
                fprintf(fp, "Resent-From: %s\n", compose->account->address);
 
-       /* To */
-       compose_bounce_write_headers_from_headerlist(compose, fp);
+       /* Subject */
+       str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
+       if (*str != '\0') {
+               Xstrdup_a(str, str, return -1);
+               g_strstrip(str);
+               if (*str != '\0') {
+                       compose_convert_header(buf, sizeof(buf), str,
+                                              strlen("Subject: "));
+                       fprintf(fp, "Subject: %s\n", buf);
+               }
+       }
+
+       /* Resent-Message-ID */
+       if (compose->account->gen_msgid) {
+               compose_generate_msgid(compose, buf, sizeof(buf));
+               fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
+               compose->msgid = g_strdup(buf);
+       }
+
+       compose_redirect_write_headers_from_headerlist(compose, fp);
 
        /* separator between header and body */
        fputs("\n", fp);
@@ -2889,14 +2950,14 @@ static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
        return 0;
 }
 
-static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
+static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
 {
        FILE *fp;
        FILE *fdest;
        size_t len;
        gchar buf[BUFFSIZE];
 
-       if ((fp = fopen(compose->bounce_filename, "rb")) == NULL) {
+       if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
@@ -2915,16 +2976,22 @@ static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
 
        while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
                /* should filter returnpath, delivered-to */
-               if ((g_strncasecmp(buf, "Return-Path:",
-                                  strlen("Return-Path:")) == 0)
-                   || (g_strncasecmp(buf, "Delivered-To:",
-                                     strlen("Delivered-To:")) == 0))
+               if (g_strncasecmp(buf, "Return-Path:",
+                                  strlen("Return-Path:")) == 0 ||
+                   g_strncasecmp(buf, "Delivered-To:",
+                                 strlen("Delivered-To:")) == 0 ||
+                   g_strncasecmp(buf, "Received:",
+                                 strlen("Received:")) == 0 ||
+                   g_strncasecmp(buf, "Subject:",
+                                 strlen("Subject:")) == 0 ||
+                   g_strncasecmp(buf, "X-UIDL:",
+                                 strlen("X-UIDL:")) == 0)
                        continue;
 
                if (fputs(buf, fdest) == -1)
                        goto error;
 
-               if (!prefs_common.bounce_keep_from) {
+               if (!prefs_common.redirect_keep_from) {
                        if (g_strncasecmp(buf, "From:",
                                          strlen("From:")) == 0) {
                                fputs(" (by way of ", fdest);
@@ -2948,20 +3015,27 @@ static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
                        goto error;
        }
 
-       compose_bounce_write_headers(compose, fdest);
+       compose_redirect_write_headers(compose, fdest);
 
-       while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
-               if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
+       while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
+               if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
+                       FILE_OP_ERROR(file, "fwrite");
                        goto error;
+               }
        }
 
-       fclose(fdest);
        fclose(fp);
+       if (fclose(fdest) == EOF) {
+               FILE_OP_ERROR(file, "fclose");
+               unlink(file);
+               return -1;
+       }
 
        return 0;
  error:
-       fclose(fdest);
        fclose(fp);
+       fclose(fdest);
+       unlink(file);
 
        return -1;
 }
@@ -3212,11 +3286,14 @@ static gint compose_remove_reedit_target(Compose *compose)
        return 0;
 }
 
-
 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
+{
+       return compose_queue_sub (compose, msgnum, item, FALSE);
+}
+static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
 {
        FolderItem *queue;
-       gchar *tmp, *tmp2, *queue_path;
+       gchar *tmp, *tmp2;
        FILE *fp, *src_fp;
        GSList *cur;
        gchar buf[BUFFSIZE];
@@ -3231,7 +3308,7 @@ static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
 
         lock = TRUE;
        
-       if (compose_check_entries(compose) == FALSE) {
+       if (compose_check_entries(compose, check_subject) == FALSE) {
                 lock = FALSE;
                 return -1;
        }
@@ -3273,8 +3350,8 @@ static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
        tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
                                      G_DIR_SEPARATOR, (gint)compose);
 
-       if (compose->bounce_filename != NULL) {
-               if (compose_bounce_write_to_file(compose, tmp2) < 0) {
+       if (compose->redirect_filename != NULL) {
+               if (compose_redirect_write_to_file(compose, tmp2) < 0) {
                        unlink(tmp2);
                        lock = FALSE;
                        return -1;
@@ -3389,21 +3466,18 @@ static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
                return -1;
        }
 
-       if (compose->account->folder &&
-           FOLDER(compose->account->folder)->queue)
-               queue = FOLDER(compose->account->folder)->queue;
-       else
-               queue = folder_get_default_queue();
-
+       queue = account_get_special_folder(compose->account, F_QUEUE);
+       if (!queue) {
+               g_warning(_("can't find queue folder\n"));
+               unlink(tmp);
+               g_free(tmp);
+               return -1;
+       }
        folder_item_scan(queue);
-       queue_path = folder_item_get_path(queue);
-       if (!is_dir_exist(queue_path))
-               make_dir_hier(queue_path);
        if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
                g_warning(_("can't queue the message\n"));
                unlink(tmp);
                g_free(tmp);
-               g_free(queue_path);
                return -1;
        }
        unlink(tmp);
@@ -3503,6 +3577,36 @@ static void compose_write_attach(Compose *compose, FILE *fp)
        fprintf(fp, "\n--%s--\n", compose->boundary);
 }
 
+#define QUOTE_IF_REQUIRED(out, str)                    \
+{                                                      \
+       if (*str != '"' && strchr(str, ',')) {          \
+               gchar *__tmp;                           \
+               gint len;                               \
+                                                       \
+               len = strlen(str) + 3;                  \
+               Xalloca(__tmp, len, return -1);         \
+               g_snprintf(__tmp, len, "\"%s\"", str);  \
+               out = __tmp;                            \
+       } else {                                        \
+               Xstrdup_a(out, str, return -1);         \
+       }                                               \
+}
+
+#define PUT_RECIPIENT_HEADER(header, str)                                   \
+{                                                                           \
+       if (*str != '\0') {                                                  \
+               Xstrdup_a(str, str, return -1);                              \
+               g_strstrip(str);                                             \
+               if (*str != '\0') {                                          \
+                       compose->to_list = address_list_append               \
+                               (compose->to_list, str);                     \
+                       compose_convert_header                               \
+                               (buf, sizeof(buf), str, strlen(header) + 2); \
+                       fprintf(fp, "%s: %s\n", header, buf);                \
+               }                                                            \
+       }                                                                    \
+}
+
 #define IS_IN_CUSTOM_HEADER(header) \
        (compose->account->add_customhdr && \
         custom_header_find(compose->account->customhdr_list, header) != NULL)
@@ -3565,6 +3669,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
 {
        gchar buf[BUFFSIZE];
        gchar *str;
+       gchar *name;
        /* struct utsname utsbuf; */
 
        g_return_val_if_fail(fp != NULL, -1);
@@ -3584,8 +3689,9 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                        compose_convert_header
                                (buf, sizeof(buf), compose->account->name,
                                 strlen("From: "));
+                       QUOTE_IF_REQUIRED(name, buf);
                        fprintf(fp, "From: %s <%s>\n",
-                               buf, compose->account->address);
+                               name, compose->account->address);
                } else
                        fprintf(fp, "From: %s\n", compose->account->address);
        }
@@ -3595,20 +3701,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
 #if 0 /* NEW COMPOSE GUI */
        if (compose->use_to) {
                str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
-               if (*str != '\0') {
-                       Xstrdup_a(str, str, return -1);
-                       g_strstrip(str);
-                       if (*str != '\0') {
-                               compose->to_list = address_list_append
-                                       (compose->to_list, str);
-                               if (!IS_IN_CUSTOM_HEADER("To")) {
-                                       compose_convert_header
-                                               (buf, sizeof(buf), str,
-                                                strlen("To: "));
-                                       fprintf(fp, "To: %s\n", buf);
-                               }
-                       }
-               }
+               PUT_RECIPIENT_HEADER("To", str);
        }
 #endif
 
@@ -3624,11 +3717,9 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                        compose->newsgroup_list =
                                newsgroup_list_append(compose->newsgroup_list,
                                                      str);
-                       if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
-                               compose_convert_header(buf, sizeof(buf), str,
-                                                      strlen("Newsgroups: "));
-                               fprintf(fp, "Newsgroups: %s\n", buf);
-                       }
+                       compose_convert_header(buf, sizeof(buf), str,
+                                              strlen("Newsgroups: "));
+                       fprintf(fp, "Newsgroups: %s\n", buf);
                }
        }
 #endif
@@ -3637,20 +3728,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
 #if 0 /* NEW COMPOSE GUI */
        if (compose->use_cc) {
                str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
-               if (*str != '\0') {
-                       Xstrdup_a(str, str, return -1);
-                       g_strstrip(str);
-                       if (*str != '\0') {
-                               compose->to_list = address_list_append
-                                       (compose->to_list, str);
-                               if (!IS_IN_CUSTOM_HEADER("Cc")) {
-                                       compose_convert_header
-                                               (buf, sizeof(buf), str,
-                                                strlen("Cc: "));
-                                       fprintf(fp, "Cc: %s\n", buf);
-                               }
-                       }
-               }
+               PUT_RECIPIENT_HEADER("Cc", str);
        }
 #endif
        /* Bcc */
@@ -3658,17 +3736,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
 #if 0 /* NEW COMPOSE GUI */
        if (compose->use_bcc) {
                str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
-               if (*str != '\0') {
-                       Xstrdup_a(str, str, return -1);
-                       g_strstrip(str);
-                       if (*str != '\0') {
-                               compose->to_list = address_list_append
-                                       (compose->to_list, str);
-                               compose_convert_header(buf, sizeof(buf), str,
-                                                      strlen("Bcc: "));
-                               fprintf(fp, "Bcc: %s\n", buf);
-                       }
-               }
+               PUT_RECIPIENT_HEADER("Bcc", str);
        }
 #endif
 
@@ -3803,6 +3871,25 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                        procmime_get_encoding_str(encoding));
        }
 
+       /* PRIORITY */
+       switch (compose->priority) {
+               case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
+                                                  "X-Priority: 1 (Highest)\n");
+                       break;
+               case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
+                                               "X-Priority: 2 (High)\n");
+                       break;
+               case PRIORITY_NORMAL: break;
+               case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
+                                              "X-Priority: 4 (Low)\n");
+                       break;
+               case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
+                                                 "X-Priority: 5 (Lowest)\n");
+                       break;
+               default: debug_print(_("compose: priority unknown : %d\n"),
+                                    compose->priority);
+       }
+
        /* Request Return Receipt */
        if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
                if (compose->return_receipt) {
@@ -4182,7 +4269,7 @@ static GtkWidget *compose_create_others(Compose *compose)
        savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
        gtk_widget_show(savemsg_checkbtn);
        gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
-       if(folder_get_default_outbox()) {
+       if(account_get_special_folder(compose->account, F_OUTBOX)) {
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
        }
        gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
@@ -4192,8 +4279,9 @@ static GtkWidget *compose_create_others(Compose *compose)
        gtk_widget_show(savemsg_entry);
        gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
        gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
-       if(folder_get_default_outbox()) {
-               folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
+       if(account_get_special_folder(compose->account, F_OUTBOX)) {
+               folderidentifier = folder_item_get_identifier(account_get_special_folder
+                                 (compose->account, F_OUTBOX));
                gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
                g_free(folderidentifier);
        }
@@ -4280,6 +4368,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
         GtkPspell * gtkpspell = NULL;
 #endif
 
+       static GdkGeometry geometry;
+
        g_return_val_if_fail(account != NULL, NULL);
 
        debug_print(_("Creating compose window...\n"));
@@ -4296,6 +4386,14 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
        gtk_widget_set_usize(window, -1, prefs_common.compose_height);
        gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
+
+       if (!geometry.max_width) {
+               geometry.max_width = gdk_screen_width();
+               geometry.max_height = gdk_screen_height();
+       }
+       gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
+                                     &geometry, GDK_HINT_MAX_SIZE);
+
        gtk_signal_connect(GTK_OBJECT(window), "delete_event",
                           GTK_SIGNAL_FUNC(compose_delete_cb), compose);
        gtk_signal_connect(GTK_OBJECT(window), "destroy",
@@ -4581,7 +4679,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        compose->exteditor_readdes = -1;
        compose->exteditor_tag     = -1;
 
-       compose->bounce_filename = NULL;
+       compose->redirect_filename = NULL;
        compose->undostruct = undostruct;
 #if USE_PSPELL
        
@@ -4723,6 +4821,10 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        if (!prefs_common.show_ruler)
                gtk_widget_hide(ruler_hbox);
 
+       /* Priority */
+       compose->priority = PRIORITY_NORMAL;
+       compose_update_priority_menu_item(compose);
+
        select_account(compose, account);
        set_toolbar_style(compose);
 
@@ -4868,8 +4970,13 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
 
                if (ac == compose->account) def_menu = num;
 
-               name = g_strdup_printf("%s: %s <%s>",
-                                      ac->account_name, ac->name, ac->address);
+               if (ac->name)
+                       name = g_strdup_printf("%s: %s <%s>",
+                                              ac->account_name,
+                                              ac->name, ac->address);
+               else
+                       name = g_strdup_printf("%s: %s",
+                                              ac->account_name, ac->address);
                MENUITEM_ADD(menu, menuitem, name, ac);
                g_free(name);
                gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
@@ -4883,6 +4990,46 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
        return hbox;
 }
 
+static void compose_set_priority_cb(gpointer data,
+                                   guint action,
+                                   GtkWidget *widget)
+{
+       Compose *compose = (Compose *) data;
+       compose->priority = action;
+}
+
+static void compose_update_priority_menu_item(Compose * compose)
+{
+       GtkItemFactory *ifactory;
+       GtkWidget *menuitem;
+
+       ifactory = gtk_item_factory_from_widget(compose->menubar);
+       
+       switch (compose->priority) {
+               case PRIORITY_HIGHEST:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Priority/Highest");
+                       break;
+               case PRIORITY_HIGH:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Priority/High");
+                       break;
+               case PRIORITY_NORMAL:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Priority/Normal");
+                       break;
+               case PRIORITY_LOW:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Priority/Low");
+                       break;
+               case PRIORITY_LOWEST:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Priority/Lowest");
+                       break;
+       }
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+}      
 static void compose_set_template_menu(Compose *compose)
 {
        GSList *tmpl_list, *cur;
@@ -5014,8 +5161,8 @@ static void compose_destroy(Compose *compose)
        g_free(compose->msgid);
        g_free(compose->boundary);
 
-       if (compose->bounce_filename)
-               g_free(compose->bounce_filename);
+       if (compose->redirect_filename)
+               g_free(compose->redirect_filename);
 
        g_free(compose->exteditor_file);
 
@@ -5917,6 +6064,12 @@ static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
 {
        Compose *compose = (Compose *)data;
        gint val;
+       
+       if (prefs_common.work_offline)
+               if (alertpanel(_("Offline warning"), 
+                              _("You're working offline. Override?"),
+                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+               return;
 
        val = compose_send(compose);
 
@@ -5929,7 +6082,7 @@ static void compose_send_later_cb(gpointer data, guint action,
        Compose *compose = (Compose *)data;
        gint val;
 
-       val = compose_queue(compose, NULL, NULL);
+       val = compose_queue_sub(compose, NULL, NULL, TRUE);
        if (!val) gtk_widget_destroy(compose->window);
 }
 
@@ -5944,11 +6097,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 
        if (lock) return;
 
-       if (compose->account && compose->account->folder &&
-           FOLDER(compose->account->folder)->draft)
-               draft = FOLDER(compose->account->folder)->draft;
-       else
-               draft = folder_get_default_draft();
+       draft = account_get_special_folder(compose->account, F_DRAFT);
        g_return_if_fail(draft != NULL);
 
        lock = TRUE;
@@ -6018,7 +6167,7 @@ static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
        Compose *compose = (Compose *)data;
        GList *file_list;
 
-       if (compose->bounce_filename != NULL)
+       if (compose->redirect_filename != NULL)
                return;
 
        file_list = filesel_select_multiple_files(_("Select file"), NULL);
@@ -6639,20 +6788,23 @@ static gboolean compose_send_control_enter(Compose *compose)
        GtkAccelEntry *accel;
        GtkWidget *send_menu;
        GSList *list;
-       gint ignored_mods = (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK 
-                          | GDK_MOD4_MASK | GDK_MOD5_MASK);
+       GdkModifierType ignored_mods =
+               (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
+                GDK_MOD4_MASK | GDK_MOD5_MASK);
 
        ev = gtk_get_current_event();
        if (ev->type != GDK_KEY_PRESS) return FALSE;
 
        kev = (GdkEventKey *)ev;
+       if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
+               return FALSE;
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
        send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
        list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
        accel = (GtkAccelEntry *)list->data;
        if (accel->accelerator_key == kev->keyval &&
-           (accel->accelerator_mods & ~ignored_mods) == 
+           (accel->accelerator_mods & ~ignored_mods) ==
            (kev->state & ~ignored_mods)) {
                compose_send_cb(compose, 0, NULL);
                return TRUE;