2004-08-21 [colin] 0.9.12cvs70.1
[claws.git] / src / compose.c
index a170a4945dd7392ac5a75f081254fd851b83c939..9f807f887e6184f024a885d70e624773f32d4f63 100644 (file)
@@ -489,6 +489,8 @@ static gboolean compose_headerentry_button_pressed (GtkWidget *entry,
 
 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
 
+static void compose_allow_user_actions (Compose *compose, gboolean allow);
+
 #if USE_ASPELL
 static void compose_check_all             (Compose *compose);
 static void compose_highlight_all         (Compose *compose);
@@ -511,6 +513,9 @@ static GtkItemFactoryEntry compose_popup_entries[] =
 static GtkItemFactoryEntry compose_entries[] =
 {
        {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
+       {N_("/_File/_Save"),
+                                               "<control>S", compose_draft_cb, 1, NULL},
+       {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Attach file"),             "<control>M", compose_attach_cb,      0, NULL},
        {N_("/_File/_Insert file"),             "<control>I", compose_insert_file_cb, 0, NULL},
        {N_("/_File/Insert si_gnature"),        "<control>G", compose_insert_sig_cb,  0, NULL},
@@ -644,11 +649,6 @@ static GtkItemFactoryEntry compose_entries[] =
                                        compose_send_cb, 0, NULL},
        {N_("/_Message/Send _later"),   "<shift><control>S",
                                        compose_send_later_cb,  0, NULL},
-       {N_("/_Message/---"),           NULL, NULL, 0, "<Separator>"},
-       {N_("/_Message/Save to _draft folder"),
-                                       "<shift><control>D", compose_draft_cb, 0, NULL},
-       {N_("/_Message/Save and _keep editing"),
-                                       "<control>S", compose_draft_cb, 1, NULL},
 #if 0 /* NEW COMPOSE GUI */
        {N_("/_Message/---"),           NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/_To"),           NULL, compose_toggle_to_cb     , 0, "<ToggleItem>"},
@@ -1376,12 +1376,11 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        menu_set_sensitive(ifactory, "/Property...", FALSE);
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
+       menu_set_sensitive(ifactory, "/File/Save", FALSE);
        menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
        menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
        menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
        menu_set_sensitive(ifactory, "/Edit", FALSE);
-       menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
-       menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
 #if USE_GPGME
        menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
        menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
@@ -3261,20 +3260,30 @@ gint compose_send(Compose *compose)
 {
        gint msgnum;
        FolderItem *folder;
-       gint val;
+       gint val = -1;
        gchar *msgpath;
 
+       compose_allow_user_actions (compose, FALSE);
+       compose->sending = TRUE;
+
        if (compose_check_entries(compose, TRUE) == FALSE)
-               return -1;
+               goto bail;
 
        val = compose_queue(compose, &msgnum, &folder);
+
        if (val) {
                alertpanel_error(_("Could not queue message for sending"));
-               return -1;
+               goto bail;
        }
 
+       compose->sending = FALSE;       
+       gtk_widget_destroy(compose->window);
+       /* No more compose access in the normal codepath after this point! */
+
        if (msgnum == 0) {
-               alertpanel_error(_("The message was queued but could not be sent.\nUse \"Send queued messages\" from the main window to retry."));
+               alertpanel_error(_("The message was queued but could not be "
+                                  "sent.\nUse \"Send queued messages\" from "
+                                  "the main window to retry."));
                return 0;
        }
        
@@ -3282,11 +3291,18 @@ gint compose_send(Compose *compose)
        val = procmsg_send_message_queue(msgpath);
        g_free(msgpath);
 
-       folder_item_remove_msg(folder, msgnum);
-       
-       folder_item_scan(folder);
+       if (val == 0) {
+               folder_item_remove_msg(folder, msgnum);
+               folder_item_scan(folder);
+       }
+
+       return 0;
 
-       return val;
+bail:
+       compose_allow_user_actions (compose, TRUE);
+       compose->sending = FALSE;
+
+       return -1;
 }
 
 #if 0 /* compose restructure */
@@ -3674,6 +3690,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        gchar *canon_buf;
        const gchar *out_codeset;
        EncodingType encoding;
+       gboolean already_encoded = FALSE;
 
        if ((fp = fopen(file, "wb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
@@ -3717,6 +3734,9 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                    compose->use_signing && !compose->gnupg_mode &&
                    encoding == ENC_8BIT)
                        encoding = ENC_BASE64;
+               
+               if (compose->use_encryption && compose->gnupg_mode)
+                       encoding = ENC_8BIT; /* this will be encrypted to a 7bit string */
 #endif
 
                src_codeset = CS_UTF_8;
@@ -3726,16 +3746,18 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
 
                buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
                if (!buf) {
-                       AlertValue aval;
+                       AlertValue aval = G_ALERTDEFAULT;
                        gchar *msg;
 
-                       msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
+                       if (!is_draft) {
+                               msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
                                                "%s to %s.\n"
                                                "Send it anyway?"), src_codeset, out_codeset);
-                       aval = alertpanel
-                               (_("Error"), msg, _("Yes"), _("+No"), NULL);
-                       g_free(msg);
-
+                               aval = alertpanel_with_type
+                                       (_("Error"), msg, _("Yes"), _("+No"), NULL, NULL, ALERT_ERROR);
+                               g_free(msg);
+                       }
+                       
                        if (aval != G_ALERTDEFAULT) {
                                g_free(chars);
                                fclose(fp);
@@ -3756,6 +3778,17 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
 
 #if USE_GPGME
        if (!is_draft && compose->use_signing && compose->gnupg_mode) {
+               gchar *outbuf;
+
+               if (encoding == ENC_QUOTED_PRINTABLE) {
+                       outbuf = g_malloc(strlen(buf) * 4);
+                       qp_encode_line(outbuf, buf);
+                       g_free(buf);
+                       buf = g_strdup(outbuf);
+                       already_encoded = TRUE;
+                       g_free(outbuf);
+               }
+               
                if (compose_clearsign_text(compose, &buf) < 0) {
                        g_warning("clearsign failed\n");
                        fclose(fp);
@@ -3812,10 +3845,14 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        } else if (encoding == ENC_QUOTED_PRINTABLE) {
                gchar *outbuf;
                size_t outlen;
-
-               outbuf = g_malloc(len * 4);
-               qp_encode_line(outbuf, buf);
-               outlen = strlen(outbuf);
+               if (!already_encoded) {
+                       outbuf = g_malloc(len * 4);
+                       qp_encode_line(outbuf, buf);
+                       outlen = strlen(outbuf);
+               } else {
+                       outbuf = g_strdup(buf);
+                       outlen = len;
+               }
                if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) {
                        FILE_OP_ERROR(file, "fwrite");
                        fclose(fp);
@@ -4325,8 +4362,7 @@ static gint compose_write_headers_from_headerlist(Compose *compose,
 
                if (!g_strcasecmp(trans_hdr, headerentryname)) {
                        const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
-                       gchar *tmpstr = conv_codeset_strdup(entstr, CS_UTF_8, conv_get_current_charset_str());
-                       Xstrdup_a(str, tmpstr, return -1);
+                       Xstrdup_a(str, entstr, return -1);
                        g_strstrip(str);
                        if (str[0] != '\0') {
                                if (write_header)
@@ -4334,7 +4370,6 @@ static gint compose_write_headers_from_headerlist(Compose *compose,
                                g_string_append(headerstr, str);
                                write_header = TRUE;
                        }
-                       g_free(tmpstr);
                }
        }
        if (write_header) {
@@ -4516,6 +4551,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
 #endif
        /* Organization */
        if (compose->account->organization &&
+           strlen(compose->account->organization) &&
            !IS_IN_CUSTOM_HEADER("Organization")) {
                compose_convert_header(buf, sizeof(buf),
                                       compose->account->organization,
@@ -4956,7 +4992,7 @@ GtkWidget *compose_create_attach(Compose *compose)
        attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
                                       GTK_POLICY_AUTOMATIC,
-                                      GTK_POLICY_ALWAYS);
+                                      GTK_POLICY_AUTOMATIC);
        gtk_widget_set_size_request(attach_scrwin, -1, 80);
 
        attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
@@ -5131,9 +5167,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        compose->account = account;
 
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-       gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
+       gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
        gtk_widget_set_size_request(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();
@@ -5232,7 +5267,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        /* text widget */
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
-                                      GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+                                      GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
        gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
        gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
 
@@ -6336,8 +6371,6 @@ static void compose_set_ext_editor_sensitive(Compose *compose,
 
        menu_set_sensitive(ifactory, "/Message/Send", sensitive);
        menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
-       menu_set_sensitive(ifactory, "/Message/Save to draft folder",
-                          sensitive);
        menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
        menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
        menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
@@ -6568,13 +6601,7 @@ static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
                compose->draft_timeout_tag = -1;
        }
 
-       compose_allow_user_actions (compose, FALSE);
-       compose->sending = TRUE;
-       val = compose_send(compose);
-       compose_allow_user_actions (compose, TRUE);
-       compose->sending = FALSE;
-
-       if (val == 0) gtk_widget_destroy(compose->window);
+       compose_send(compose);
 }
 
 static void compose_send_later_cb(gpointer data, guint action,
@@ -6713,11 +6740,10 @@ static void compose_insert_file_cb(gpointer data, guint action,
                for ( tmp = file_list; tmp; tmp = tmp->next) {
                        gchar *file = (gchar *) tmp->data;
                        gchar *filedup = g_strdup(file);
-                       gchar *shortfile;
+                       const gchar *shortfile = g_basename(filedup);
                        ComposeInsertResult res;
 
                        res = compose_insert_file(compose, file);
-                       shortfile = g_basename(filedup);
                        if (res == COMPOSE_INSERT_READ_ERROR) {
                                alertpanel_error(_("File '%s' could not be read."), shortfile);
                        } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {