2004-11-22 [colin] 0.9.12cvs158.4
[claws.git] / src / compose.c
index 9eadf1b5211a1b7087c427ab223daa38c99dd1bc..dbd86ff2ff37e04232733b0f25a33b102f2a4eba 100644 (file)
@@ -1295,6 +1295,10 @@ void compose_reedit(MsgInfo *msginfo)
        g_signal_handlers_block_by_func(G_OBJECT(textbuf),
                                        G_CALLBACK(compose_changed_cb),
                                        compose);
+                                       
+       g_signal_handlers_block_by_func(G_OBJECT(textbuf),
+                                       G_CALLBACK(text_inserted),
+                                       compose);
 
        if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
                g_warning("Can't get text part\n");
@@ -1302,12 +1306,16 @@ void compose_reedit(MsgInfo *msginfo)
                while (fgets(buf, sizeof(buf), fp) != NULL) {
                        strcrchomp(buf);
                        gtk_text_buffer_insert(textbuf, &iter, buf, -1);
+                       gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
                }
                fclose(fp);
        }
        
        compose_attach_parts(compose, msginfo);
 
+       g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
+                                       G_CALLBACK(text_inserted),
+                                       compose);
        g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
                                        G_CALLBACK(compose_changed_cb),
                                        compose);
@@ -2210,7 +2218,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
                        MsgInfo *msginfo;
                        MsgFlags flags = {0, 0};
 
-                       if (procmime_get_encoding_for_file(file) == ENC_7BIT)
+                       if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
                                ainfo->encoding = ENC_7BIT;
                        else
                                ainfo->encoding = ENC_8BIT;
@@ -2226,8 +2234,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
                        procmsg_msginfo_free(msginfo);
                } else {
                        if (!g_ascii_strncasecmp(content_type, "text", 4))
-                               ainfo->encoding =
-                                       procmime_get_encoding_for_file(file);
+                               ainfo->encoding = procmime_get_encoding_for_text_file(file);
                        else
                                ainfo->encoding = ENC_BASE64;
                        name = g_path_get_basename(filename ? filename : file);
@@ -2241,7 +2248,8 @@ static void compose_attach_append(Compose *compose, const gchar *file,
                                g_strdup("application/octet-stream");
                        ainfo->encoding = ENC_BASE64;
                } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
-                       ainfo->encoding = procmime_get_encoding_for_file(file);
+                       ainfo->encoding =
+                               procmime_get_encoding_for_text_file(file);
                else
                        ainfo->encoding = ENC_BASE64;
                name = g_path_get_basename(filename ? filename : file);
@@ -2591,16 +2599,17 @@ static void compose_wrap_line(Compose *compose)
 #undef WRAP_DEBUG
 #ifdef WRAP_DEBUG
 /* Darko: used when I debug wrapping */
-void dump_text(GtkTextBuffer textbuf, int pos, int tlen, int breakoncr)
+void dump_text(GtkTextBuffer *textbuf, int pos, int tlen, int breakoncr)
 {
        gint i, clen;
        gchar cbuf[CHAR_BUF_SIZE];
+       GtkTextIter iter, end_iter;
 
        printf("%d [", pos);
        gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
        gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
        for (; gtk_text_iter_forward_char(&iter) &&
-                    gtk_text_iter_compare(&iter, &end_iter) < 0;)
+                    gtk_text_iter_compare(&iter, &end_iter) < 0;) {
                GET_CHAR(&iter, cbuf, clen);
                if (clen < 0) break;
                if (breakoncr && clen == 1 && cbuf[0] == '\n')
@@ -2907,7 +2916,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                                is_new_line = TRUE;
 #ifdef WRAP_DEBUG
                                g_print("after delete l_pos=");
-                               dump_text(text, line_pos, tlen, 1);
+                               dump_text(textbuf, line_pos, tlen, 1);
 #endif
                                /* move beginning of line if we are on LF */
                                gtk_text_buffer_get_iter_at_offset(textbuf,
@@ -2948,8 +2957,8 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
 
 #ifdef WRAP_DEBUG
                        g_print("should wrap cur_pos=%d ", cur_pos);
-                       dump_text(text, p_pos, tlen, 1);
-                       dump_text(text, line_pos, tlen, 1);
+                       dump_text(textbuf, p_pos, tlen, 1);
+                       dump_text(textbuf, line_pos, tlen, 1);
 #endif
                        /* force wrapping if it is one long word but not URL */
                        if (line_pos - p_pos <= i_len)
@@ -3001,7 +3010,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                            gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
 #ifdef WRAP_DEBUG
                                g_print("found URL at ");
-                               dump_text(text, line_pos, tlen, 1);
+                               dump_text(textbuf, line_pos, tlen, 1);
 #endif
                                continue;
                        }
@@ -3027,8 +3036,8 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                                do_delete = FALSE;
 #ifdef WRAP_DEBUG
                        g_print("after CR insert ");
-                       dump_text(text, line_pos, tlen, 1);
-                       dump_text(text, cur_pos, tlen, 1);
+                       dump_text(textbuf, line_pos, tlen, 1);
+                       dump_text(textbuf, cur_pos, tlen, 1);
 #endif
 
                        /* should we insert quotation ? */
@@ -3048,7 +3057,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                                        }
 #ifdef WRAP_DEBUG
                                        g_print("after quote insert ");
-                                       dump_text(text, line_pos, tlen, 1);
+                                       dump_text(textbuf, line_pos, tlen, 1);
 #endif
                                }
                        }
@@ -3312,7 +3321,16 @@ gint compose_send(Compose *compose)
                folder_item_scan(folder);
                if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
                        gtk_widget_destroy(compose->window);
-       }
+       } else {
+               alertpanel_error(_("The message was queued but could not be "
+                                  "sent.\nUse \"Send queued messages\" from "
+                                  "the main window to retry."));
+               if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
+                       compose_allow_user_actions (compose, TRUE);
+                       compose->sending = FALSE;               
+               }
+               return -1;
+       }
 
        return 0;
 
@@ -3429,7 +3447,7 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
 
        /* Resent-Message-ID */
        if (compose->account->gen_msgid) {
-               generate_msgid(compose->account->address, buf, sizeof(buf));
+               generate_msgid(buf, sizeof(buf));
                fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
                compose->msgid = g_strdup(buf);
        }
@@ -3844,7 +3862,9 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                        gchar *encdata;
 
                        encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
-                       fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n", encdata);
+                       if (encdata != NULL)
+                               fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n", 
+                                       encdata);
                        g_free(encdata);
                }
        }
@@ -4112,27 +4132,20 @@ static gchar *compose_get_header(Compose *compose)
        compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
 
        /* Subject */
-       str = (gpointer)gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
+       str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
        if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
-               gchar *tmpstr;
-
-               tmpstr = g_strdup(str);
-               if (tmpstr == NULL) {
-                       g_string_free(header, TRUE);
-                       return NULL;
-               }
                g_strstrip(str);
                if (*str != '\0') {
                        compose_convert_header(buf, sizeof(buf), str,
                                               strlen("Subject: "), FALSE);
                        g_string_append_printf(header, "Subject: %s\n", buf);
                }
-               g_free(tmpstr);
        }
+       g_free(str);
 
        /* Message-ID */
        if (compose->account->gen_msgid) {
-               generate_msgid(compose->account->address, buf, sizeof(buf));
+               generate_msgid(buf, sizeof(buf));
                g_string_append_printf(header, "Message-ID: <%s>\n", buf);
                compose->msgid = g_strdup(buf);
        }