Fix wrapping crash when URL is wider than wrapping margin.
[claws.git] / src / compose.c
index 5332fa4f48f8aa272a28a3a7b0a953420513a925..04f19c3d2a905e3cd1cddb81de5ddbf48e740702 100644 (file)
@@ -430,6 +430,12 @@ static void compose_show_first_last_header (Compose *compose, gboolean show_firs
 
 static void compose_ctl_enter_send_shortcut_cb(GtkWidget *w, Compose *compose);
 
+static void compose_check_backwards(Compose *compose);
+
+static void compose_check_forwards_go(Compose *compose);
+
+
+
 static GtkItemFactoryEntry compose_popup_entries[] =
 {
        {N_("/_Add..."),        NULL, compose_attach_cb, 0, NULL},
@@ -456,6 +462,11 @@ static GtkItemFactoryEntry compose_entries[] =
        {N_("/_Edit/_Paste"),           "<control>V", compose_paste_cb,  0, NULL},
        {N_("/_Edit/Select _all"),      "<control>A", compose_allsel_cb, 0, NULL},
        {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
+#if USE_PSPELL
+       {N_("/_Edit/Check backwards misspelled word"),  "<control>;", compose_check_backwards , 0, NULL},
+       {N_("/_Edit/Forward to next misspelled word"),  "<control>!", compose_check_forwards_go, 0, NULL},
+       {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
+#endif
        {N_("/_Edit/_Wrap current paragraph"),
                                        "<alt>L", compose_wrap_line, 0, NULL},
        {N_("/_Edit/Wrap all long _lines"),
@@ -1204,7 +1215,7 @@ Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
 void compose_reedit(MsgInfo *msginfo)
 {
        Compose *compose;
-       PrefsAccount *account;
+       PrefsAccount *account = NULL;
        GtkSText *text;
        FILE *fp;
        gchar buf[BUFFSIZE];
@@ -1213,9 +1224,23 @@ void compose_reedit(MsgInfo *msginfo)
        g_return_if_fail(msginfo->folder != NULL);
 
         if (msginfo->folder->stype == F_QUEUE) {
-               gchar account_address[BUFFSIZE];
-               if (!get_header_from_msginfo(msginfo, account_address, sizeof(account_address), "S:")) {
-                       account = account_find_from_address(account_address);
+               gchar queueheader_buf[BUFFSIZE];
+               gint id;
+
+               /* Select Account from queue headers */
+               if (!get_header_from_msginfo(msginfo, queueheader_buf, 
+                                            sizeof(queueheader_buf), "NAID:")) {
+                       id = atoi(&queueheader_buf[5]);
+                       account = account_find_from_id(id);
+               }
+               if (!account && !get_header_from_msginfo(msginfo, queueheader_buf, 
+                                                   sizeof(queueheader_buf), "MAID:")) {
+                       id = atoi(&queueheader_buf[5]);
+                       account = account_find_from_id(id);
+               }
+               if (!account && !get_header_from_msginfo(msginfo, queueheader_buf, 
+                                                               sizeof(queueheader_buf), "S:")) {
+                       account = account_find_from_address(queueheader_buf);
                }
        } else 
                account = msginfo->folder->folder->account;
@@ -1233,6 +1258,19 @@ void compose_reedit(MsgInfo *msginfo)
        compose = compose_create(account, COMPOSE_REEDIT);
        compose->targetinfo = procmsg_msginfo_copy(msginfo);
 
+        if (msginfo->folder->stype == F_QUEUE) {
+               gchar queueheader_buf[BUFFSIZE];
+
+               /* Set message save folder */
+               if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
+                       gint startpos = 0;
+
+                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
+                       gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
+                       gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
+               }
+       }
+       
        if (compose_parse_header(compose, msginfo) < 0) return;
        compose_reedit_set_entry(compose, msginfo);
 
@@ -2293,6 +2331,11 @@ static void compose_wrap_line_all(Compose *compose)
                                        do_delete = FALSE;
                        }
 
+                       /* skip delete if it is continuous URL */
+                       if (do_delete && (line_pos - p_pos <= i_len) &&
+                           gtkut_stext_is_uri_string(text, line_pos, tlen))
+                               do_delete = FALSE;
+
 #ifdef WRAP_DEBUG
                        printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
                                qlen, line_len, linewrap_len, do_delete);
@@ -2857,6 +2900,46 @@ static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
        return -1;
 }
 
+
+#ifdef USE_GPGME
+/*
+ * interfaces to rfc2015 to keep out the prefs stuff there.
+ * returns 0 on success and -1 on error. */
+static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
+{
+       const char *keyid = NULL;
+       GSList *key_list;
+
+       switch (compose->account->sign_key) {
+       case SIGN_KEY_DEFAULT:
+               *pkey_list = NULL;
+               return 0;               /* nothing to do */
+
+       case SIGN_KEY_BY_FROM:
+               keyid = compose->account->address;
+               break;
+
+       case SIGN_KEY_CUSTOM:
+               keyid = compose->account->sign_key_id;
+               break;
+
+       default:
+               g_assert_not_reached ();
+       }
+
+       key_list = rfc2015_create_signers_list(keyid);
+
+       if (!key_list) {
+           alertpanel_error("Could not find any key associated with currently "
+                               "selected keyid `%s'!", keyid);
+           return -1;
+       }
+       
+       *pkey_list = key_list;
+       return 0;
+}
+#endif /* USE_GPGME */
+
 static gint compose_write_to_file(Compose *compose, const gchar *file,
                                  gboolean is_draft)
 {
@@ -2972,13 +3055,17 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
 
 #if USE_GPGME
        if (compose->use_signing) {
-               if (rfc2015_sign(file, compose->account) < 0) {
+               GSList *key_list;
+               
+               if (compose_create_signers_list(compose, &key_list) == -1 ||
+                       rfc2015_sign(file, key_list) < 0) {
+                   
                        unlink(file);
                        return -1;
                }
        }
        if (compose->use_encryption) {
-               if (rfc2015_encrypt(file, compose->to_list) < 0) {
+               if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
                        unlink(file);
                        return -1;
                }
@@ -4294,19 +4381,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
                           GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
                           compose);
-#if USE_PSPELL
-        if (prefs_common.enable_pspell) {
-               gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
-                                                     prefs_common.pspell_path,
-                                                     prefs_common.dictionary,
-                                                     prefs_common.pspell_sugmode,
-                                                     conv_get_current_charset_str());
-               if (gtkpspell == NULL)
-                       prefs_common.enable_pspell = FALSE;
-               else
-                       gtkpspell_attach(gtkpspell, GTK_STEXT(text));
-        }
-#endif
        gtk_widget_show_all(vbox);
 
        /* pane between attach clist and text */
@@ -4481,6 +4555,24 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        compose->bounce_filename = NULL;
        compose->undostruct = undostruct;
+#if USE_PSPELL
+       menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
+       menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
+        if (prefs_common.enable_pspell) {
+               gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
+                                         conv_get_current_charset_str(),
+                                         GTK_STEXT(text));
+               if (!gtkpspell) {
+                       alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
+                       gtkpspell_checkers_reset();
+               } else {
+
+                       gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode);
+                       menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", TRUE);
+                       menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", TRUE);
+                       }
+        }
+#endif
 
        compose_set_title(compose);
 
@@ -4555,10 +4647,10 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 #if USE_GPGME
        menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
-                                      prefs_common.default_sign);
+                                      account->default_sign);
        menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
-                                      prefs_common.default_encrypt);
+                                      account->default_encrypt);
 #endif /* USE_GPGME */
 
        addressbook_set_target_compose(compose);
@@ -4868,6 +4960,12 @@ static void compose_destroy(Compose *compose)
        if (addressbook_get_target_compose() == compose)
                addressbook_set_target_compose(NULL);
 
+#if USE_PSPELL
+        if (compose->gtkpspell) {
+               gtkpspell_delete(compose->gtkpspell);
+        }
+#endif
+
        prefs_common.compose_width = compose->scrolledwin->allocation.width;
        prefs_common.compose_height = compose->window->allocation.height;
 
@@ -5883,12 +5981,6 @@ static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
                        return;
                }
        }
-#if USE_PSPELL
-        if (compose->gtkpspell) {
-               gtkpspell_detach(compose->gtkpspell);
-               compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
-        }
-#endif
        gtk_widget_destroy(compose->window);
 }
 
@@ -6357,10 +6449,10 @@ static void compose_ctl_enter_send_shortcut_cb(GtkWidget *w, Compose *compose)
        GtkAccelEntry  *accel;
        GtkWidget      *send_button;
        GSList *list;
-       GdkEvent *e= gtk_get_current_event();
+       GdkEventKey *e= (GdkEventKey *) gtk_get_current_event();
        
        if (e->type != GDK_KEY_PRESS || 
-           !( ((GdkEventKey *)e)->state & GDK_CONTROL_MASK) )
+           !( e->keyval == GDK_Return && e->state & GDK_CONTROL_MASK) )
                return;
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
@@ -6370,4 +6462,30 @@ static void compose_ctl_enter_send_shortcut_cb(GtkWidget *w, Compose *compose)
        if (accel->accelerator_key == GDK_Return && 
            accel->accelerator_mods == GDK_CONTROL_MASK)
                compose_send_cb(compose, 0, NULL);
-}      
+}
+
+#if USE_PSPELL
+static void compose_check_backwards(Compose *compose)
+{
+       if (compose->gtkpspell) 
+               gtkpspell_check_backwards(compose->gtkpspell);
+       else {
+               GtkItemFactory *ifactory;
+               ifactory = gtk_item_factory_from_widget(compose->popupmenu);
+               menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
+               menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
+       }
+}
+
+static void compose_check_forwards_go(Compose *compose)
+{
+       if (compose->gtkpspell) 
+               gtkpspell_check_forwards_go(compose->gtkpspell);
+       else {
+               GtkItemFactory *ifactory;
+               ifactory = gtk_item_factory_from_widget(compose->popupmenu);
+               menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
+               menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
+       }
+}
+#endif