2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkvpaned.h>
36 #include <gtk/gtkentry.h>
37 #include <gtk/gtkeditable.h>
38 #include <gtk/gtkwindow.h>
39 #include <gtk/gtksignal.h>
40 #include <gtk/gtkvbox.h>
41 #include <gtk/gtkcontainer.h>
42 #include <gtk/gtkhandlebox.h>
43 #include <gtk/gtktoolbar.h>
44 #include <gtk/gtktable.h>
45 #include <gtk/gtkhbox.h>
46 #include <gtk/gtklabel.h>
47 #include <gtk/gtkscrolledwindow.h>
48 #include <gtk/gtktreeview.h>
49 #include <gtk/gtkliststore.h>
50 #include <gtk/gtktreeselection.h>
51 #include <gtk/gtktreemodel.h>
53 #include <gtk/gtkdnd.h>
58 #include <sys/types.h>
62 /* #include <sys/utsname.h> */
69 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
76 #include "mainwindow.h"
78 #include "addressbook.h"
79 #include "folderview.h"
82 #include "stock_pixmap.h"
83 #include "send_message.h"
86 #include "customheader.h"
87 #include "prefs_common.h"
88 #include "prefs_account.h"
92 #include "procheader.h"
94 #include "statusbar.h"
97 #include "quoted-printable.h"
100 #include "gtkutils.h"
102 #include "alertpanel.h"
103 #include "manage_window.h"
104 #include "gtkshruler.h"
106 #include "addr_compl.h"
107 #include "quote_fmt.h"
108 #include "template.h"
110 #include "foldersel.h"
123 #define N_ATTACH_COLS (N_COL_COLUMNS)
127 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
128 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
129 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
130 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
131 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
132 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
133 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
134 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
135 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
136 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
138 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
141 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
142 } ComposeCallAdvancedAction;
146 PRIORITY_HIGHEST = 1,
155 COMPOSE_INSERT_SUCCESS,
156 COMPOSE_INSERT_READ_ERROR,
157 COMPOSE_INSERT_INVALID_CHARACTER,
158 COMPOSE_INSERT_NO_FILE
159 } ComposeInsertResult;
163 COMPOSE_QUIT_EDITING,
164 COMPOSE_KEEP_EDITING,
166 } ComposeDraftAction;
170 COMPOSE_WRITE_FOR_SEND,
171 COMPOSE_WRITE_FOR_STORE
174 #define B64_LINE_SIZE 57
175 #define B64_BUFFSIZE 77
177 #define MAX_REFERENCES_LEN 999
179 static GdkColor quote_color = {0, 0, 0, 0xbfff};
181 static GList *compose_list = NULL;
183 Compose *compose_generic_new (PrefsAccount *account,
186 GPtrArray *attach_files,
187 GList *listAddress );
189 static Compose *compose_create (PrefsAccount *account,
192 static GtkWidget *compose_account_option_menu_create
194 static void compose_set_template_menu (Compose *compose);
195 static void compose_template_apply (Compose *compose,
198 static void compose_destroy (Compose *compose);
200 static void compose_entries_set (Compose *compose,
201 const gchar *mailto);
202 static gint compose_parse_header (Compose *compose,
204 static gchar *compose_parse_references (const gchar *ref,
207 static gchar *compose_quote_fmt (Compose *compose,
213 static void compose_reply_set_entry (Compose *compose,
219 followup_and_reply_to);
220 static void compose_reedit_set_entry (Compose *compose,
222 static void compose_insert_sig (Compose *compose,
224 static gchar *compose_get_signature_str (Compose *compose);
225 static ComposeInsertResult compose_insert_file (Compose *compose,
227 static void compose_attach_append (Compose *compose,
230 const gchar *content_type);
231 static void compose_attach_parts (Compose *compose,
233 static void compose_wrap_line (Compose *compose);
234 static void compose_wrap_line_all (Compose *compose);
235 static void compose_wrap_line_all_full (Compose *compose,
237 static void compose_set_title (Compose *compose);
238 static void compose_select_account (Compose *compose,
239 PrefsAccount *account,
242 static PrefsAccount *compose_current_mail_account(void);
243 /* static gint compose_send (Compose *compose); */
244 static gboolean compose_check_for_valid_recipient
246 static gboolean compose_check_entries (Compose *compose,
247 gboolean check_subject);
248 static gint compose_write_to_file (Compose *compose,
251 static gint compose_write_body_to_file (Compose *compose,
253 static gint compose_remove_reedit_target (Compose *compose);
254 void compose_remove_draft (Compose *compose);
255 static gint compose_queue (Compose *compose,
258 static gint compose_queue_sub (Compose *compose,
261 gboolean check_subject);
262 static void compose_add_attachments (Compose *compose,
264 static gchar *compose_get_header (Compose *compose);
266 static void compose_convert_header (gchar *dest,
270 gboolean addr_field);
272 static void compose_attach_info_free (AttachInfo *ainfo);
273 static void compose_attach_remove_selected (Compose *compose);
275 static void compose_attach_property (Compose *compose);
276 static void compose_attach_property_create (gboolean *cancelled);
277 static void attach_property_ok (GtkWidget *widget,
278 gboolean *cancelled);
279 static void attach_property_cancel (GtkWidget *widget,
280 gboolean *cancelled);
281 static gint attach_property_delete_event (GtkWidget *widget,
283 gboolean *cancelled);
284 static gboolean attach_property_key_pressed (GtkWidget *widget,
286 gboolean *cancelled);
288 static void compose_exec_ext_editor (Compose *compose);
289 static gint compose_exec_ext_editor_real (const gchar *file);
290 static gboolean compose_ext_editor_kill (Compose *compose);
291 static void compose_input_cb (gpointer data,
293 GdkInputCondition condition);
294 static void compose_set_ext_editor_sensitive (Compose *compose,
297 static void compose_undo_state_changed (UndoMain *undostruct,
302 static gint calc_cursor_xpos (GtkTextView *text,
306 static void compose_create_header_entry (Compose *compose);
307 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
308 static void compose_update_priority_menu_item(Compose * compose);
310 static void compose_add_field_list ( Compose *compose,
311 GList *listAddress );
313 /* callback functions */
315 static gboolean compose_edit_size_alloc (GtkEditable *widget,
316 GtkAllocation *allocation,
317 GtkSHRuler *shruler);
318 static void account_activated (GtkMenuItem *menuitem,
320 static void attach_selected (GtkTreeView *tree_view,
321 GtkTreePath *tree_path,
322 GtkTreeViewColumn *column,
324 static gboolean attach_button_pressed (GtkWidget *widget,
325 GdkEventButton *event,
327 static gboolean attach_key_pressed (GtkWidget *widget,
331 static void compose_send_cb (gpointer data,
334 static void compose_send_later_cb (gpointer data,
338 static void compose_draft_cb (gpointer data,
342 static void compose_attach_cb (gpointer data,
345 static void compose_insert_file_cb (gpointer data,
348 static void compose_insert_sig_cb (gpointer data,
352 static void compose_close_cb (gpointer data,
356 static void compose_address_cb (gpointer data,
359 static void compose_template_activate_cb(GtkWidget *widget,
362 static void compose_ext_editor_cb (gpointer data,
366 static gint compose_delete_cb (GtkWidget *widget,
369 static void compose_destroy_cb (GtkWidget *widget,
372 static void compose_undo_cb (Compose *compose);
373 static void compose_redo_cb (Compose *compose);
374 static void compose_cut_cb (Compose *compose);
375 static void compose_copy_cb (Compose *compose);
376 static void compose_paste_cb (Compose *compose);
377 static void compose_paste_as_quote_cb (Compose *compose);
378 static void compose_allsel_cb (Compose *compose);
380 static void compose_advanced_action_cb (Compose *compose,
381 ComposeCallAdvancedAction action);
383 static void compose_grab_focus_cb (GtkWidget *widget,
385 static void compose_grab_focus_before_cb(GtkWidget *widget,
388 static void compose_changed_cb (GtkTextBuffer *textbuf,
391 static void compose_toggle_autowrap_cb (gpointer data,
396 static void compose_toggle_to_cb (gpointer data,
399 static void compose_toggle_cc_cb (gpointer data,
402 static void compose_toggle_bcc_cb (gpointer data,
405 static void compose_toggle_replyto_cb (gpointer data,
408 static void compose_toggle_followupto_cb(gpointer data,
411 static void compose_toggle_attach_cb (gpointer data,
415 static void compose_toggle_ruler_cb (gpointer data,
418 static void compose_toggle_sign_cb (gpointer data,
421 static void compose_toggle_encrypt_cb (gpointer data,
424 static void compose_set_privacy_system_cb(GtkWidget *widget,
426 static void compose_update_privacy_system_menu_item(Compose * compose);
427 static void activate_privacy_system (Compose *compose,
428 PrefsAccount *account);
429 static void compose_use_signing(Compose *compose, gboolean use_signing);
430 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
431 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
433 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
435 static void compose_set_priority_cb (gpointer data,
439 static void compose_attach_drag_received_cb (GtkWidget *widget,
440 GdkDragContext *drag_context,
443 GtkSelectionData *data,
447 static void compose_insert_drag_received_cb (GtkWidget *widget,
448 GdkDragContext *drag_context,
451 GtkSelectionData *data,
455 static void compose_header_drag_received_cb (GtkWidget *widget,
456 GdkDragContext *drag_context,
459 GtkSelectionData *data,
464 static gboolean compose_drag_drop (GtkWidget *widget,
465 GdkDragContext *drag_context,
467 guint time, gpointer user_data);
469 static void to_activated (GtkWidget *widget,
471 static void newsgroups_activated (GtkWidget *widget,
473 static void cc_activated (GtkWidget *widget,
475 static void bcc_activated (GtkWidget *widget,
477 static void replyto_activated (GtkWidget *widget,
479 static void followupto_activated (GtkWidget *widget,
481 static void subject_activated (GtkWidget *widget,
485 static void text_inserted (GtkTextBuffer *buffer,
490 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
491 gboolean to_all, gboolean to_ml,
493 gboolean followup_and_reply_to,
496 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
497 ComposeHeaderEntry *headerentry);
498 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
500 ComposeHeaderEntry *headerentry);
502 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
504 static void compose_allow_user_actions (Compose *compose, gboolean allow);
507 static void compose_check_all (Compose *compose);
508 static void compose_highlight_all (Compose *compose);
509 static void compose_check_backwards (Compose *compose);
510 static void compose_check_forwards_go (Compose *compose);
513 static gint compose_defer_auto_save_draft (Compose *compose);
514 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
516 static void compose_close (Compose *compose);
518 static GtkItemFactoryEntry compose_popup_entries[] =
520 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
521 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
522 {N_("/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
526 static GtkItemFactoryEntry compose_entries[] =
528 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
529 {N_("/_Message/_Send"), "<control>Return",
530 compose_send_cb, 0, NULL},
531 {N_("/_Message/Send _later"), "<shift><control>S",
532 compose_send_later_cb, 0, NULL},
533 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
535 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
536 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
537 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
538 {N_("/_Message/_Save"),
539 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
540 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
541 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
543 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
544 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
545 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
546 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
547 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
548 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
549 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
550 {N_("/_Edit/Paste as _quotation"),
551 NULL, compose_paste_as_quote_cb, 0, NULL},
552 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
553 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
554 {N_("/_Edit/A_dvanced/Move a character backward"),
556 compose_advanced_action_cb,
557 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
559 {N_("/_Edit/A_dvanced/Move a character forward"),
561 compose_advanced_action_cb,
562 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
564 {N_("/_Edit/A_dvanced/Move a word backward"),
566 compose_advanced_action_cb,
567 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
569 {N_("/_Edit/A_dvanced/Move a word forward"),
571 compose_advanced_action_cb,
572 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
574 {N_("/_Edit/A_dvanced/Move to beginning of line"),
575 NULL, /* "<control>A" */
576 compose_advanced_action_cb,
577 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
579 {N_("/_Edit/A_dvanced/Move to end of line"),
581 compose_advanced_action_cb,
582 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
584 {N_("/_Edit/A_dvanced/Move to previous line"),
586 compose_advanced_action_cb,
587 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
589 {N_("/_Edit/A_dvanced/Move to next line"),
591 compose_advanced_action_cb,
592 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
594 {N_("/_Edit/A_dvanced/Delete a character backward"),
596 compose_advanced_action_cb,
597 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
599 {N_("/_Edit/A_dvanced/Delete a character forward"),
601 compose_advanced_action_cb,
602 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
604 {N_("/_Edit/A_dvanced/Delete a word backward"),
605 NULL, /* "<control>W" */
606 compose_advanced_action_cb,
607 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
609 {N_("/_Edit/A_dvanced/Delete a word forward"),
610 NULL, /* "<alt>D", */
611 compose_advanced_action_cb,
612 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
614 {N_("/_Edit/A_dvanced/Delete line"),
616 compose_advanced_action_cb,
617 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
619 {N_("/_Edit/A_dvanced/Delete entire line"),
621 compose_advanced_action_cb,
622 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
624 {N_("/_Edit/A_dvanced/Delete to end of line"),
626 compose_advanced_action_cb,
627 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
629 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_Edit/_Wrap current paragraph"),
631 "<control>L", compose_wrap_line, 0, NULL},
632 {N_("/_Edit/Wrap all long _lines"),
633 "<control><alt>L", compose_wrap_line_all, 0, NULL},
634 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
635 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Edit/Edit with e_xternal editor"),
637 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
639 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Spelling/_Check all or check selection"),
641 NULL, compose_check_all, 0, NULL},
642 {N_("/_Spelling/_Highlight all misspelled words"),
643 NULL, compose_highlight_all, 0, NULL},
644 {N_("/_Spelling/Check _backwards misspelled word"),
645 NULL, compose_check_backwards , 0, NULL},
646 {N_("/_Spelling/_Forward to next misspelled word"),
647 NULL, compose_check_forwards_go, 0, NULL},
648 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Spelling/_Spelling Configuration"),
650 NULL, NULL, 0, "<Branch>"},
652 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
653 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
655 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
656 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
657 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
660 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
661 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
662 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
663 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
664 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
665 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
666 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
667 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
668 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
669 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
670 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
671 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
672 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
673 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
676 static GtkTargetEntry compose_mime_types[] =
678 {"text/uri-list", 0, 0},
679 {"text/plain", 0, 0},
683 static gboolean compose_put_existing_to_front(MsgInfo *info)
685 GList *compose_list = compose_get_compose_list();
689 for (elem = compose_list; elem != NULL && elem->data != NULL;
691 Compose *c = (Compose*)elem->data;
693 if (!c->targetinfo || !c->targetinfo->msgid ||
697 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
698 gtkut_window_popup(c->window);
706 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
707 GPtrArray *attach_files)
709 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
712 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
714 return compose_generic_new(account, NULL, item, NULL, NULL);
717 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
719 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
722 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
723 GPtrArray *attach_files, GList *listAddress )
726 GtkTextView *textview;
727 GtkTextBuffer *textbuf;
729 GtkItemFactory *ifactory;
731 if (item && item->prefs && item->prefs->enable_default_account)
732 account = account_find_from_id(item->prefs->default_account);
734 if (!account) account = cur_account;
735 g_return_val_if_fail(account != NULL, NULL);
737 compose = compose_create(account, COMPOSE_NEW);
738 ifactory = gtk_item_factory_from_widget(compose->menubar);
740 compose->replyinfo = NULL;
741 compose->fwdinfo = NULL;
743 textview = GTK_TEXT_VIEW(compose->text);
744 textbuf = gtk_text_view_get_buffer(textview);
746 undo_block(compose->undostruct);
748 if (item && item->prefs && item->prefs->enable_default_dictionary &&
750 gtkaspell_change_dict(compose->gtkaspell,
751 item->prefs->default_dictionary);
754 if (account->auto_sig)
755 compose_insert_sig(compose, FALSE);
756 gtk_text_buffer_get_start_iter(textbuf, &iter);
757 gtk_text_buffer_place_cursor(textbuf, &iter);
759 if (account->protocol != A_NNTP) {
760 if (mailto && *mailto != '\0') {
761 compose_entries_set(compose, mailto);
763 } else if (item && item->prefs->enable_default_to) {
764 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
765 compose_entry_mark_default_to(compose, item->prefs->default_to);
767 if (item && item->ret_rcpt) {
768 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
772 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
775 * CLAWS: just don't allow return receipt request, even if the user
776 * may want to send an email. simple but foolproof.
778 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
780 compose_add_field_list( compose, listAddress );
786 for (i = 0; i < attach_files->len; i++) {
787 file = g_ptr_array_index(attach_files, i);
788 compose_attach_append(compose, file, file, NULL);
792 compose_show_first_last_header(compose, TRUE);
794 /* Set save folder */
795 if (item && item->prefs && item->prefs->save_copy_to_folder) {
796 gchar *folderidentifier;
798 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
799 folderidentifier = folder_item_get_identifier(item);
800 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
801 g_free(folderidentifier);
804 gtk_widget_grab_focus(compose->header_last->entry);
806 undo_unblock(compose->undostruct);
808 if (prefs_common.auto_exteditor)
809 compose_exec_ext_editor(compose);
815 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
816 const gchar *followupto, gchar * to)
820 if (!account) account = cur_account;
821 g_return_val_if_fail(account != NULL, NULL);
822 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
824 compose = compose_create(account, COMPOSE_NEW);
826 if (prefs_common.auto_sig)
827 compose_insert_sig(compose);
828 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
829 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
831 compose_entry_append(compose, to, COMPOSE_TO);
832 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
833 gtk_widget_grab_focus(compose->subject_entry);
839 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
844 g_return_if_fail(msginfo_list != NULL);
846 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
847 g_return_if_fail(msginfo != NULL);
849 list_len = g_slist_length(msginfo_list);
853 compose_reply(msginfo, prefs_common.reply_with_quote,
854 FALSE, prefs_common.default_reply_list, FALSE, body);
856 case COMPOSE_REPLY_WITH_QUOTE:
857 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
859 case COMPOSE_REPLY_WITHOUT_QUOTE:
860 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
862 case COMPOSE_REPLY_TO_SENDER:
863 compose_reply(msginfo, prefs_common.reply_with_quote,
864 FALSE, FALSE, TRUE, body);
866 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
867 compose_followup_and_reply_to(msginfo,
868 prefs_common.reply_with_quote,
871 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
872 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
874 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
875 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
877 case COMPOSE_REPLY_TO_ALL:
878 compose_reply(msginfo, prefs_common.reply_with_quote,
879 TRUE, FALSE, FALSE, body);
881 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
882 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
884 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
885 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
887 case COMPOSE_REPLY_TO_LIST:
888 compose_reply(msginfo, prefs_common.reply_with_quote,
889 FALSE, TRUE, FALSE, body);
891 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
892 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
894 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
895 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
897 case COMPOSE_FORWARD:
898 if (prefs_common.forward_as_attachment) {
899 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
902 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
906 case COMPOSE_FORWARD_INLINE:
907 /* check if we reply to more than one Message */
909 compose_forward(NULL, msginfo, FALSE, body, FALSE);
912 /* more messages FALL THROUGH */
913 case COMPOSE_FORWARD_AS_ATTACH:
914 compose_forward_multiple(NULL, msginfo_list);
916 case COMPOSE_REDIRECT:
917 compose_redirect(NULL, msginfo);
920 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
924 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
925 gboolean to_ml, gboolean to_sender,
928 compose_generic_reply(msginfo, quote, to_all, to_ml,
929 to_sender, FALSE, body);
932 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
937 compose_generic_reply(msginfo, quote, to_all, FALSE,
938 to_sender, TRUE, body);
941 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
942 gboolean to_all, gboolean to_ml,
944 gboolean followup_and_reply_to,
947 GtkItemFactory *ifactory;
949 PrefsAccount *account = NULL;
950 PrefsAccount *reply_account;
951 GtkTextView *textview;
952 GtkTextBuffer *textbuf;
956 g_return_if_fail(msginfo != NULL);
957 g_return_if_fail(msginfo->folder != NULL);
959 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
961 g_return_if_fail(account != NULL);
963 if (to_sender && account->protocol == A_NNTP &&
964 !followup_and_reply_to) {
966 account_find_from_address(account->address);
968 reply_account = compose_current_mail_account();
972 reply_account = account;
974 compose = compose_create(account, COMPOSE_REPLY);
975 ifactory = gtk_item_factory_from_widget(compose->menubar);
977 menu_set_active(ifactory, "/Options/Remove references", FALSE);
978 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
980 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
981 if (!compose->replyinfo)
982 compose->replyinfo = procmsg_msginfo_copy(msginfo);
984 if (msginfo->folder && msginfo->folder->ret_rcpt)
985 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
987 /* Set save folder */
988 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
989 gchar *folderidentifier;
991 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
992 folderidentifier = folder_item_get_identifier(msginfo->folder);
993 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
994 g_free(folderidentifier);
997 if (compose_parse_header(compose, msginfo) < 0) return;
998 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
999 to_sender, followup_and_reply_to);
1000 compose_show_first_last_header(compose, TRUE);
1002 textview = (GTK_TEXT_VIEW(compose->text));
1003 textbuf = gtk_text_view_get_buffer(textview);
1005 undo_block(compose->undostruct);
1007 if (msginfo->folder && msginfo->folder->prefs &&
1008 msginfo->folder->prefs &&
1009 msginfo->folder->prefs->enable_default_dictionary &&
1011 gtkaspell_change_dict(compose->gtkaspell,
1012 msginfo->folder->prefs->default_dictionary);
1018 if (prefs_common.quotemark && *prefs_common.quotemark)
1019 qmark = prefs_common.quotemark;
1023 compose_quote_fmt(compose, compose->replyinfo,
1024 prefs_common.quotefmt,
1028 if (account->auto_sig)
1029 compose_insert_sig(compose, FALSE);
1031 cursor_pos = quote_fmt_get_cursor_pos();
1032 gtk_text_buffer_get_start_iter(textbuf, &iter);
1033 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1034 gtk_text_buffer_place_cursor(textbuf, &iter);
1036 if (quote && prefs_common.linewrap_quote)
1037 compose_wrap_line_all(compose);
1039 gtk_widget_grab_focus(compose->text);
1041 undo_unblock(compose->undostruct);
1043 if (prefs_common.auto_exteditor)
1044 compose_exec_ext_editor(compose);
1047 #define INSERT_FW_HEADER(var, hdr) \
1048 if (msginfo->var && *msginfo->var) { \
1049 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1050 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1051 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1054 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1055 gboolean as_attach, const gchar *body,
1056 gboolean no_extedit)
1059 GtkTextView *textview;
1060 GtkTextBuffer *textbuf;
1063 g_return_val_if_fail(msginfo != NULL, NULL);
1064 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1067 !(account = compose_guess_forward_account_from_msginfo
1069 account = cur_account;
1071 compose = compose_create(account, COMPOSE_FORWARD);
1073 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1074 if (!compose->fwdinfo)
1075 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1077 if (msginfo->subject && *msginfo->subject) {
1078 gchar *buf, *buf2, *p;
1080 buf = p = g_strdup(msginfo->subject);
1081 p += subject_get_prefix_length(p);
1082 memmove(buf, p, strlen(p) + 1);
1084 buf2 = g_strdup_printf("Fw: %s", buf);
1085 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1091 textview = GTK_TEXT_VIEW(compose->text);
1092 textbuf = gtk_text_view_get_buffer(textview);
1097 msgfile = procmsg_get_message_file_path(msginfo);
1098 if (!is_file_exist(msgfile))
1099 g_warning("%s: file not exist\n", msgfile);
1101 compose_attach_append(compose, msgfile, msgfile,
1107 MsgInfo *full_msginfo;
1109 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1111 full_msginfo = procmsg_msginfo_copy(msginfo);
1113 if (prefs_common.fw_quotemark &&
1114 *prefs_common.fw_quotemark)
1115 qmark = prefs_common.fw_quotemark;
1119 compose_quote_fmt(compose, full_msginfo,
1120 prefs_common.fw_quotefmt,
1122 compose_attach_parts(compose, msginfo);
1124 procmsg_msginfo_free(full_msginfo);
1127 if (account->auto_sig)
1128 compose_insert_sig(compose, FALSE);
1130 if (prefs_common.linewrap_quote)
1131 compose_wrap_line_all(compose);
1133 gtk_text_buffer_get_start_iter(textbuf, &iter);
1134 gtk_text_buffer_place_cursor(textbuf, &iter);
1136 #if 0 /* NEW COMPOSE GUI */
1137 if (account->protocol != A_NNTP)
1138 gtk_widget_grab_focus(compose->to_entry);
1140 gtk_widget_grab_focus(compose->newsgroups_entry);
1142 gtk_widget_grab_focus(compose->header_last->entry);
1144 if (!no_extedit && prefs_common.auto_exteditor)
1145 compose_exec_ext_editor(compose);
1148 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1149 gchar *folderidentifier;
1151 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1152 folderidentifier = folder_item_get_identifier(msginfo->folder);
1153 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1154 g_free(folderidentifier);
1160 #undef INSERT_FW_HEADER
1162 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1165 GtkTextView *textview;
1166 GtkTextBuffer *textbuf;
1171 g_return_val_if_fail(msginfo_list != NULL, NULL);
1173 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1174 if (((MsgInfo *)msginfo->data)->folder == NULL)
1177 /* guess account from first selected message */
1179 !(account = compose_guess_forward_account_from_msginfo
1180 (msginfo_list->data)))
1181 account = cur_account;
1183 g_return_val_if_fail(account != NULL, NULL);
1185 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1186 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1187 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1190 compose = compose_create(account, COMPOSE_FORWARD);
1192 textview = GTK_TEXT_VIEW(compose->text);
1193 textbuf = gtk_text_view_get_buffer(textview);
1195 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1196 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1197 if (!is_file_exist(msgfile))
1198 g_warning("%s: file not exist\n", msgfile);
1200 compose_attach_append(compose, msgfile, msgfile,
1205 if (account->auto_sig)
1206 compose_insert_sig(compose, FALSE);
1208 if (prefs_common.linewrap_quote)
1209 compose_wrap_line_all(compose);
1211 gtk_text_buffer_get_start_iter(textbuf, &iter);
1212 gtk_text_buffer_place_cursor(textbuf, &iter);
1214 gtk_widget_grab_focus(compose->header_last->entry);
1216 #if 0 /* NEW COMPOSE GUI */
1217 if (account->protocol != A_NNTP)
1218 gtk_widget_grab_focus(compose->to_entry);
1220 gtk_widget_grab_focus(compose->newsgroups_entry);
1226 void compose_reedit(MsgInfo *msginfo)
1229 PrefsAccount *account = NULL;
1230 GtkTextView *textview;
1231 GtkTextBuffer *textbuf;
1235 gchar buf[BUFFSIZE];
1236 gboolean use_signing = FALSE;
1237 gboolean use_encryption = FALSE;
1238 gchar *privacy_system = NULL;
1240 g_return_if_fail(msginfo != NULL);
1241 g_return_if_fail(msginfo->folder != NULL);
1243 if (compose_put_existing_to_front(msginfo))
1246 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1247 gchar queueheader_buf[BUFFSIZE];
1250 /* Select Account from queue headers */
1251 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1252 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1253 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1254 account = account_find_from_id(id);
1256 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1257 sizeof(queueheader_buf), "NAID:")) {
1258 id = atoi(&queueheader_buf[strlen("NAID:")]);
1259 account = account_find_from_id(id);
1261 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1262 sizeof(queueheader_buf), "MAID:")) {
1263 id = atoi(&queueheader_buf[strlen("MAID:")]);
1264 account = account_find_from_id(id);
1266 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1267 sizeof(queueheader_buf), "S:")) {
1268 account = account_find_from_address(queueheader_buf);
1270 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1271 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1272 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1273 use_signing = param;
1276 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1277 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1278 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1279 use_encryption = param;
1281 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1282 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1283 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1285 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1286 sizeof(queueheader_buf), "X-Priority: ")) {
1287 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1288 compose->priority = param;
1291 account = msginfo->folder->folder->account;
1293 if (!account && prefs_common.reedit_account_autosel) {
1294 gchar from[BUFFSIZE];
1295 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1296 extract_address(from);
1297 account = account_find_from_address(from);
1300 if (!account) account = cur_account;
1301 g_return_if_fail(account != NULL);
1303 compose = compose_create(account, COMPOSE_REEDIT);
1304 compose->privacy_system = privacy_system;
1305 compose_use_signing(compose, use_signing);
1306 compose_use_encryption(compose, use_encryption);
1307 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1309 if (msginfo->folder->stype == F_QUEUE
1310 || msginfo->folder->stype == F_DRAFT) {
1311 gchar queueheader_buf[BUFFSIZE];
1313 /* Set message save folder */
1314 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1317 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1318 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1319 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1323 if (compose_parse_header(compose, msginfo) < 0) return;
1324 compose_reedit_set_entry(compose, msginfo);
1326 textview = GTK_TEXT_VIEW(compose->text);
1327 textbuf = gtk_text_view_get_buffer(textview);
1328 mark = gtk_text_buffer_get_insert(textbuf);
1329 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1331 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1332 G_CALLBACK(compose_changed_cb),
1335 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1336 G_CALLBACK(text_inserted),
1339 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1340 g_warning("Can't get text part\n");
1342 while (fgets(buf, sizeof(buf), fp) != NULL) {
1344 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1345 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1350 compose_attach_parts(compose, msginfo);
1352 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1353 G_CALLBACK(text_inserted),
1355 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1356 G_CALLBACK(compose_changed_cb),
1359 gtk_widget_grab_focus(compose->text);
1361 if (prefs_common.auto_exteditor)
1362 compose_exec_ext_editor(compose);
1365 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1369 GtkItemFactory *ifactory;
1372 g_return_val_if_fail(msginfo != NULL, NULL);
1375 account = account_get_reply_account(msginfo,
1376 prefs_common.reply_account_autosel);
1377 g_return_val_if_fail(account != NULL, NULL);
1379 compose = compose_create(account, COMPOSE_REDIRECT);
1380 ifactory = gtk_item_factory_from_widget(compose->menubar);
1382 compose->replyinfo = NULL;
1383 compose->fwdinfo = NULL;
1385 compose_show_first_last_header(compose, TRUE);
1387 gtk_widget_grab_focus(compose->header_last->entry);
1389 filename = procmsg_get_message_file(msginfo);
1390 if (filename == NULL)
1393 compose->redirect_filename = filename;
1395 /* Set save folder */
1396 item = msginfo->folder;
1397 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1398 gchar *folderidentifier;
1400 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1401 folderidentifier = folder_item_get_identifier(item);
1402 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1403 g_free(folderidentifier);
1406 compose_attach_parts(compose, msginfo);
1408 if (msginfo->subject)
1409 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1411 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1413 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1414 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
1416 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1417 menu_set_sensitive(ifactory, "/Add...", FALSE);
1418 menu_set_sensitive(ifactory, "/Remove", FALSE);
1419 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1421 ifactory = gtk_item_factory_from_widget(compose->menubar);
1422 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1423 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1424 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1425 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1426 menu_set_sensitive(ifactory, "/Edit", FALSE);
1427 menu_set_sensitive(ifactory, "/Options/Sign", FALSE);
1428 menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
1429 menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
1430 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1431 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1432 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1434 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1435 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1436 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1437 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1438 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1439 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1440 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1445 GList *compose_get_compose_list(void)
1447 return compose_list;
1450 void compose_entry_append(Compose *compose, const gchar *address,
1451 ComposeEntryType type)
1455 if (!address || *address == '\0') return;
1457 #if 0 /* NEW COMPOSE GUI */
1460 entry = GTK_ENTRY(compose->cc_entry);
1463 entry = GTK_ENTRY(compose->bcc_entry);
1465 case COMPOSE_NEWSGROUPS:
1466 entry = GTK_ENTRY(compose->newsgroups_entry);
1470 entry = GTK_ENTRY(compose->to_entry);
1474 text = gtk_entry_get_text(entry);
1476 gtk_entry_append_text(entry, ", ");
1477 gtk_entry_append_text(entry, address);
1485 header = N_("Bcc:");
1487 case COMPOSE_REPLYTO:
1488 header = N_("Reply-To:");
1490 case COMPOSE_NEWSGROUPS:
1491 header = N_("Newsgroups:");
1493 case COMPOSE_FOLLOWUPTO:
1494 header = N_( "Followup-To:");
1501 header = prefs_common.trans_hdr ? gettext(header) : header;
1503 compose_add_header_entry(compose, header, (gchar *)address);
1506 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1508 static GtkStyle *bold_style = NULL;
1509 static GdkColor bold_color;
1513 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1514 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1515 if (gtk_entry_get_text(entry) &&
1516 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1517 gtk_widget_ensure_style(GTK_WIDGET(entry));
1519 PangoFontDescription *font_desc = NULL;
1520 gtkut_convert_int_to_gdk_color
1521 (prefs_common.color_new, &bold_color);
1522 bold_style = gtk_style_copy(gtk_widget_get_style
1523 (GTK_WIDGET(entry)));
1525 font_desc = pango_font_description_from_string
1528 if (bold_style->font_desc)
1529 pango_font_description_free
1530 (bold_style->font_desc);
1531 bold_style->font_desc = font_desc;
1533 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1535 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1540 void compose_toolbar_cb(gint action, gpointer data)
1542 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1543 Compose *compose = (Compose*)toolbar_item->parent;
1545 g_return_if_fail(compose != NULL);
1549 compose_send_cb(compose, 0, NULL);
1552 compose_send_later_cb(compose, 0, NULL);
1555 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1558 compose_insert_file_cb(compose, 0, NULL);
1561 compose_attach_cb(compose, 0, NULL);
1564 compose_insert_sig(compose, FALSE);
1567 compose_ext_editor_cb(compose, 0, NULL);
1569 case A_LINEWRAP_CURRENT:
1570 compose_wrap_line(compose);
1572 case A_LINEWRAP_ALL:
1573 compose_wrap_line_all(compose);
1576 compose_address_cb(compose, 0, NULL);
1579 case A_CHECK_SPELLING:
1580 compose_check_all(compose);
1588 static void compose_entries_set(Compose *compose, const gchar *mailto)
1593 gchar *subject = NULL;
1598 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1601 compose_entry_append(compose, to, COMPOSE_TO);
1603 compose_entry_append(compose, cc, COMPOSE_CC);
1605 compose_entry_append(compose, bcc, COMPOSE_BCC);
1607 if (!g_utf8_validate (subject, -1, NULL)) {
1608 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1609 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1612 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1615 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1616 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1620 mark = gtk_text_buffer_get_insert(buffer);
1621 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1623 if (!g_utf8_validate (body, -1, NULL)) {
1624 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1625 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1628 gtk_text_buffer_insert(buffer, &iter, body, -1);
1630 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1640 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1642 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1643 {"Cc:", NULL, TRUE},
1644 {"References:", NULL, FALSE},
1645 {"Bcc:", NULL, TRUE},
1646 {"Newsgroups:", NULL, TRUE},
1647 {"Followup-To:", NULL, TRUE},
1648 {"List-Post:", NULL, FALSE},
1649 {"X-Priority:", NULL, FALSE},
1650 {NULL, NULL, FALSE}};
1666 g_return_val_if_fail(msginfo != NULL, -1);
1668 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1669 procheader_get_header_fields(fp, hentry);
1672 if (hentry[H_REPLY_TO].body != NULL) {
1673 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1674 compose->replyto = hentry[H_REPLY_TO].body;
1675 hentry[H_REPLY_TO].body = NULL;
1677 if (hentry[H_CC].body != NULL) {
1678 conv_unmime_header_overwrite(hentry[H_CC].body);
1679 compose->cc = hentry[H_CC].body;
1680 hentry[H_CC].body = NULL;
1682 if (hentry[H_REFERENCES].body != NULL) {
1683 if (compose->mode == COMPOSE_REEDIT)
1684 compose->references = hentry[H_REFERENCES].body;
1686 compose->references = compose_parse_references
1687 (hentry[H_REFERENCES].body, msginfo->msgid);
1688 g_free(hentry[H_REFERENCES].body);
1690 hentry[H_REFERENCES].body = NULL;
1692 if (hentry[H_BCC].body != NULL) {
1693 if (compose->mode == COMPOSE_REEDIT) {
1694 conv_unmime_header_overwrite(hentry[H_BCC].body);
1695 compose->bcc = hentry[H_BCC].body;
1697 g_free(hentry[H_BCC].body);
1698 hentry[H_BCC].body = NULL;
1700 if (hentry[H_NEWSGROUPS].body != NULL) {
1701 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1702 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1703 hentry[H_NEWSGROUPS].body = NULL;
1705 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1706 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1707 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1708 hentry[H_FOLLOWUP_TO].body = NULL;
1710 if (hentry[H_LIST_POST].body != NULL) {
1713 extract_address(hentry[H_LIST_POST].body);
1714 if (hentry[H_LIST_POST].body[0] != '\0') {
1715 scan_mailto_url(hentry[H_LIST_POST].body,
1716 &to, NULL, NULL, NULL, NULL);
1718 g_free(compose->ml_post);
1719 compose->ml_post = to;
1722 g_free(hentry[H_LIST_POST].body);
1723 hentry[H_LIST_POST].body = NULL;
1726 /* CLAWS - X-Priority */
1727 if (compose->mode == COMPOSE_REEDIT)
1728 if (hentry[H_X_PRIORITY].body != NULL) {
1731 priority = atoi(hentry[H_X_PRIORITY].body);
1732 g_free(hentry[H_X_PRIORITY].body);
1734 hentry[H_X_PRIORITY].body = NULL;
1736 if (priority < PRIORITY_HIGHEST ||
1737 priority > PRIORITY_LOWEST)
1738 priority = PRIORITY_NORMAL;
1740 compose->priority = priority;
1743 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1744 compose->inreplyto = g_strdup(msginfo->inreplyto);
1745 else if (compose->mode != COMPOSE_REEDIT &&
1746 msginfo->msgid && *msginfo->msgid) {
1747 compose->inreplyto = g_strdup(msginfo->msgid);
1749 if (!compose->references) {
1750 if (msginfo->inreplyto && *msginfo->inreplyto)
1751 compose->references =
1752 g_strdup_printf("<%s>\n\t<%s>",
1756 compose->references =
1757 g_strconcat("<", msginfo->msgid, ">",
1765 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1767 GSList *ref_id_list, *cur;
1771 ref_id_list = references_list_append(NULL, ref);
1772 if (!ref_id_list) return NULL;
1773 if (msgid && *msgid)
1774 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1779 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1780 /* "<" + Message-ID + ">" + CR+LF+TAB */
1781 len += strlen((gchar *)cur->data) + 5;
1783 if (len > MAX_REFERENCES_LEN) {
1784 /* remove second message-ID */
1785 if (ref_id_list && ref_id_list->next &&
1786 ref_id_list->next->next) {
1787 g_free(ref_id_list->next->data);
1788 ref_id_list = g_slist_remove
1789 (ref_id_list, ref_id_list->next->data);
1791 slist_free_strings(ref_id_list);
1792 g_slist_free(ref_id_list);
1799 new_ref = g_string_new("");
1800 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1801 if (new_ref->len > 0)
1802 g_string_append(new_ref, "\n\t");
1803 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
1806 slist_free_strings(ref_id_list);
1807 g_slist_free(ref_id_list);
1809 new_ref_str = new_ref->str;
1810 g_string_free(new_ref, FALSE);
1815 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1816 const gchar *fmt, const gchar *qmark,
1819 static MsgInfo dummyinfo;
1820 gchar *quote_str = NULL;
1824 const gchar *trimmed_body = body;
1827 msginfo = &dummyinfo;
1829 if (qmark != NULL) {
1830 quote_fmt_init(msginfo, NULL, NULL);
1831 quote_fmt_scan_string(qmark);
1834 buf = quote_fmt_get_buffer();
1836 alertpanel_error(_("Quote mark format error."));
1838 Xstrdup_a(quote_str, buf, return NULL)
1841 if (fmt && *fmt != '\0') {
1842 while (trimmed_body && strlen(trimmed_body) > 1
1843 && trimmed_body[0]=='\n')
1846 quote_fmt_init(msginfo, quote_str, trimmed_body);
1847 quote_fmt_scan_string(fmt);
1850 buf = quote_fmt_get_buffer();
1852 alertpanel_error(_("Message reply/forward format error."));
1858 for (p = buf; *p != '\0'; ) {
1859 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1860 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1864 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1865 G_CALLBACK(compose_changed_cb),
1867 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1868 G_CALLBACK(text_inserted),
1871 mark = gtk_text_buffer_get_insert(buffer);
1872 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1874 lastp = strchr(p, '\n');
1875 len = lastp ? lastp - p + 1 : -1;
1877 gtk_text_buffer_insert(buffer, &iter, p, len);
1879 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1880 G_CALLBACK(compose_changed_cb),
1882 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1883 G_CALLBACK(text_inserted),
1895 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1896 gboolean to_all, gboolean to_ml,
1898 gboolean followup_and_reply_to)
1900 GSList *cc_list = NULL;
1903 gchar *replyto = NULL;
1904 GHashTable *to_table;
1906 g_return_if_fail(compose->account != NULL);
1907 g_return_if_fail(msginfo != NULL);
1909 if (compose->account->protocol != A_NNTP) {
1910 if (!compose->replyto && to_ml && compose->ml_post
1911 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1912 compose_entry_append(compose,
1915 else if (!(to_all || to_sender)
1917 && msginfo->folder->prefs->enable_default_reply_to) {
1918 compose_entry_append(compose,
1919 msginfo->folder->prefs->default_reply_to,
1922 compose_entry_append(compose,
1923 (compose->replyto && !to_sender)
1924 ? compose->replyto :
1925 msginfo->from ? msginfo->from : "",
1928 if (to_sender || (compose->followup_to &&
1929 !strncmp(compose->followup_to, "poster", 6)))
1930 compose_entry_append
1932 (compose->replyto ? compose->replyto :
1933 msginfo->from ? msginfo->from : ""),
1936 else if (followup_and_reply_to || to_all) {
1937 compose_entry_append
1939 (compose->replyto ? compose->replyto :
1940 msginfo->from ? msginfo->from : ""),
1943 compose_entry_append
1945 compose->followup_to ? compose->followup_to :
1946 compose->newsgroups ? compose->newsgroups : "",
1947 COMPOSE_NEWSGROUPS);
1950 compose_entry_append
1952 compose->followup_to ? compose->followup_to :
1953 compose->newsgroups ? compose->newsgroups : "",
1954 COMPOSE_NEWSGROUPS);
1957 if (msginfo->subject && *msginfo->subject) {
1961 buf = p = g_strdup(msginfo->subject);
1962 p += subject_get_prefix_length(p);
1963 memmove(buf, p, strlen(p) + 1);
1965 buf2 = g_strdup_printf("Re: %s", buf);
1966 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1971 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1973 if (to_ml && compose->ml_post) return;
1974 if (!to_all || compose->account->protocol == A_NNTP) return;
1976 if (compose->replyto) {
1977 Xstrdup_a(replyto, compose->replyto, return);
1978 extract_address(replyto);
1980 if (msginfo->from) {
1981 Xstrdup_a(from, msginfo->from, return);
1982 extract_address(from);
1985 if (replyto && from)
1986 cc_list = address_list_append_with_comments(cc_list, from);
1987 if (to_all && msginfo->folder &&
1988 msginfo->folder->prefs->enable_default_reply_to)
1989 cc_list = address_list_append_with_comments(cc_list,
1990 msginfo->folder->prefs->default_reply_to);
1991 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1992 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1994 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1996 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1997 if (compose->account)
1998 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1999 GINT_TO_POINTER(1));
2001 /* remove address on To: and that of current account */
2002 for (cur = cc_list; cur != NULL; ) {
2003 GSList *next = cur->next;
2006 addr = g_strdup(cur->data);
2007 extract_address(addr);
2009 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2010 cc_list = g_slist_remove(cc_list, cur->data);
2012 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2016 hash_free_strings(to_table);
2017 g_hash_table_destroy(to_table);
2020 for (cur = cc_list; cur != NULL; cur = cur->next)
2021 compose_entry_append(compose, (gchar *)cur->data,
2023 slist_free_strings(cc_list);
2024 g_slist_free(cc_list);
2029 #define SET_ENTRY(entry, str) \
2032 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2035 #define SET_ADDRESS(type, str) \
2038 compose_entry_append(compose, str, type); \
2041 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2043 g_return_if_fail(msginfo != NULL);
2045 SET_ENTRY(subject_entry, msginfo->subject);
2046 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2047 SET_ADDRESS(COMPOSE_CC, compose->cc);
2048 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2049 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2050 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2051 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2053 compose_update_priority_menu_item(compose);
2054 compose_update_privacy_system_menu_item(compose);
2055 compose_show_first_last_header(compose, TRUE);
2061 static void compose_insert_sig(Compose *compose, gboolean replace)
2063 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2064 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2070 g_return_if_fail(compose->account != NULL);
2072 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2073 G_CALLBACK(compose_changed_cb),
2076 mark = gtk_text_buffer_get_insert(buffer);
2077 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2078 cur_pos = gtk_text_iter_get_offset (&iter);
2080 gtk_text_buffer_get_end_iter(buffer, &iter);
2082 if (replace && compose->sig_str) {
2084 GtkTextIter first_iter, start_iter, end_iter;
2086 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2088 if (compose->sig_str[0] == '\0')
2091 found = gtk_text_iter_forward_search(&first_iter,
2093 GTK_TEXT_SEARCH_TEXT_ONLY,
2094 &start_iter, &end_iter,
2098 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2103 g_free(compose->sig_str);
2104 compose->sig_str = compose_get_signature_str(compose);
2105 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2106 compose->sig_str = g_strdup("");
2108 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2110 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2111 cur_pos = gtk_text_buffer_get_char_count (buffer);
2113 gtk_text_buffer_get_iter_at_offset (buffer, &iter, cur_pos);
2114 gtk_text_buffer_place_cursor (buffer, &iter);
2116 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2117 G_CALLBACK(compose_changed_cb),
2122 static gchar *compose_get_signature_str(Compose *compose)
2124 gchar *sig_body = NULL;
2125 gchar *sig_str = NULL;
2127 g_return_val_if_fail(compose->account != NULL, NULL);
2129 if (!compose->account->sig_path)
2132 if (compose->account->sig_type == SIG_FILE) {
2133 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2134 g_warning("can't open signature file: %s\n",
2135 compose->account->sig_path);
2140 if (compose->account->sig_type == SIG_COMMAND)
2141 sig_body = get_command_output(compose->account->sig_path);
2145 tmp = file_read_to_str(compose->account->sig_path);
2148 sig_body = normalize_newlines(tmp);
2152 if (compose->account->sig_sep)
2153 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2156 sig_str = g_strconcat("\n\n", sig_body, NULL);
2163 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2166 GtkTextBuffer *buffer;
2169 gchar buf[BUFFSIZE];
2172 gboolean badtxt = FALSE;
2174 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2176 if ((fp = fopen(file, "rb")) == NULL) {
2177 FILE_OP_ERROR(file, "fopen");
2178 return COMPOSE_INSERT_READ_ERROR;
2181 text = GTK_TEXT_VIEW(compose->text);
2182 buffer = gtk_text_view_get_buffer(text);
2183 mark = gtk_text_buffer_get_insert(buffer);
2184 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2186 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2187 G_CALLBACK(text_inserted),
2190 while (fgets(buf, sizeof(buf), fp) != NULL) {
2191 const gchar *cur_encoding = conv_get_current_charset_str();
2193 if (!g_utf8_validate(buf, -1, NULL))
2194 str = conv_codeset_strdup(buf, cur_encoding, CS_UTF_8);
2196 str = g_strdup(buf);
2200 /* strip <CR> if DOS/Windows file,
2201 replace <CR> with <LF> if Macintosh file. */
2204 if (len > 0 && str[len - 1] != '\n') {
2206 if (str[len] == '\r') str[len] = '\n';
2208 gtk_text_buffer_insert(buffer, &iter, str, -1);
2213 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2214 G_CALLBACK(text_inserted),
2220 return COMPOSE_INSERT_INVALID_CHARACTER;
2222 return COMPOSE_INSERT_SUCCESS;
2225 static void compose_attach_append(Compose *compose, const gchar *file,
2226 const gchar *filename,
2227 const gchar *content_type)
2235 GtkListStore *store;
2238 if (!is_file_exist(file)) {
2239 g_warning("File %s doesn't exist\n", file);
2242 if ((size = get_file_size(file)) < 0) {
2243 g_warning("Can't get file size of %s\n", file);
2247 alertpanel_notice(_("File %s is empty."), file);
2250 if ((fp = fopen(file, "rb")) == NULL) {
2251 alertpanel_error(_("Can't read %s."), file);
2256 #if 0 /* NEW COMPOSE GUI */
2257 if (!compose->use_attach) {
2258 GtkItemFactory *ifactory;
2260 ifactory = gtk_item_factory_from_widget(compose->menubar);
2261 menu_set_active(ifactory, "/View/Attachment", TRUE);
2264 ainfo = g_new0(AttachInfo, 1);
2265 auto_ainfo = g_auto_pointer_new_with_free
2266 (ainfo, (GFreeFunc) compose_attach_info_free);
2267 ainfo->file = g_strdup(file);
2270 ainfo->content_type = g_strdup(content_type);
2271 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2273 MsgFlags flags = {0, 0};
2275 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2276 ainfo->encoding = ENC_7BIT;
2278 ainfo->encoding = ENC_8BIT;
2280 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2281 if (msginfo && msginfo->subject)
2282 name = g_strdup(msginfo->subject);
2284 name = g_path_get_basename(filename ? filename : file);
2286 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2288 procmsg_msginfo_free(msginfo);
2290 if (!g_ascii_strncasecmp(content_type, "text", 4))
2291 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2293 ainfo->encoding = ENC_BASE64;
2294 name = g_path_get_basename(filename ? filename : file);
2295 ainfo->name = g_strdup(name);
2299 ainfo->content_type = procmime_get_mime_type(file);
2300 if (!ainfo->content_type) {
2301 ainfo->content_type =
2302 g_strdup("application/octet-stream");
2303 ainfo->encoding = ENC_BASE64;
2304 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2306 procmime_get_encoding_for_text_file(file);
2308 ainfo->encoding = ENC_BASE64;
2309 name = g_path_get_basename(filename ? filename : file);
2310 ainfo->name = g_strdup(name);
2314 if (!strcmp(ainfo->content_type, "unknown")) {
2315 g_free(ainfo->content_type);
2316 ainfo->content_type = g_strdup("application/octet-stream");
2320 size_text = to_human_readable(size);
2322 store = GTK_LIST_STORE(gtk_tree_view_get_model
2323 (GTK_TREE_VIEW(compose->attach_clist)));
2325 gtk_list_store_append(store, &iter);
2326 gtk_list_store_set(store, &iter,
2327 COL_MIMETYPE, ainfo->content_type,
2328 COL_SIZE, size_text,
2329 COL_NAME, ainfo->name,
2331 COL_AUTODATA, auto_ainfo,
2334 g_auto_pointer_free(auto_ainfo);
2337 static void compose_use_signing(Compose *compose, gboolean use_signing)
2339 GtkItemFactory *ifactory;
2340 GtkWidget *menuitem = NULL;
2342 compose->use_signing = use_signing;
2343 ifactory = gtk_item_factory_from_widget(compose->menubar);
2344 menuitem = gtk_item_factory_get_item
2345 (ifactory, "/Options/Sign");
2346 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2350 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2352 GtkItemFactory *ifactory;
2353 GtkWidget *menuitem = NULL;
2355 compose->use_encryption = use_encryption;
2356 ifactory = gtk_item_factory_from_widget(compose->menubar);
2357 menuitem = gtk_item_factory_get_item
2358 (ifactory, "/Options/Encrypt");
2360 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2364 #define NEXT_PART_NOT_CHILD(info) \
2366 node = info->node; \
2367 while (node->children) \
2368 node = g_node_last_child(node); \
2369 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2372 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2376 MimeInfo *firsttext = NULL;
2377 MimeInfo *encrypted = NULL;
2380 const gchar *partname = NULL;
2382 mimeinfo = procmime_scan_message(msginfo);
2383 if (!mimeinfo) return;
2385 if (mimeinfo->node->children == NULL) {
2386 procmime_mimeinfo_free_all(mimeinfo);
2390 /* find first content part */
2391 child = (MimeInfo *) mimeinfo->node->children->data;
2392 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2393 child = (MimeInfo *)child->node->children->data;
2395 if (child->type == MIMETYPE_TEXT) {
2397 debug_print("First text part found\n");
2398 } else if (compose->mode == COMPOSE_REEDIT &&
2399 child->type == MIMETYPE_APPLICATION &&
2400 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2402 val = alertpanel(_("Encrypted message"),
2403 _("Cannot re-edit an encrypted message. \n"
2404 "Discard encrypted part?"),
2405 _("Yes"), _("No"), NULL);
2406 if (val == G_ALERTDEFAULT)
2407 encrypted = (MimeInfo *)child->node->parent->data;
2410 child = (MimeInfo *) mimeinfo->node->children->data;
2411 while (child != NULL) {
2412 if (child == encrypted) {
2413 /* skip this part of tree */
2414 NEXT_PART_NOT_CHILD(child);
2418 if (child->type == MIMETYPE_MULTIPART) {
2419 /* get the actual content */
2420 child = procmime_mimeinfo_next(child);
2424 if (child == firsttext) {
2425 child = procmime_mimeinfo_next(child);
2429 outfile = procmime_get_tmp_file_name(child);
2430 if (procmime_get_part(outfile, child) < 0)
2431 g_warning("Can't get the part of multipart message.");
2433 gchar *content_type;
2435 content_type = procmime_get_content_type_str(child->type, child->subtype);
2436 partname = procmime_mimeinfo_get_parameter(child, "name");
2437 if (partname == NULL)
2439 compose_attach_append(compose, outfile,
2440 partname, content_type);
2441 g_free(content_type);
2444 NEXT_PART_NOT_CHILD(child);
2446 procmime_mimeinfo_free_all(mimeinfo);
2450 #define CHAR_BUF_SIZE 8
2451 #undef NEXT_PART_NOT_CHILD
2453 #define GET_CHAR(iter_p, buf, len) \
2455 GtkTextIter end_iter; \
2457 end_iter = *iter_p; \
2458 gtk_text_iter_forward_char(&end_iter); \
2459 tmp = gtk_text_buffer_get_text(textbuf, iter_p, &end_iter, FALSE); \
2461 glong items_read, items_witten; \
2462 GError *error = NULL; \
2463 gunichar *wide_char; \
2464 strncpy2(buf, tmp, CHAR_BUF_SIZE); \
2465 wide_char = g_utf8_to_ucs4(tmp, -1, \
2466 &items_read, &items_witten, \
2468 if (error != NULL) { \
2469 g_warning("%s\n", error->message); \
2470 g_error_free(error); \
2472 len = wide_char && g_unichar_iswide(*wide_char) ? 2 : 1; \
2473 g_free(wide_char); \
2481 #define DISP_WIDTH(len) \
2482 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2483 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2485 #define SPACE_CHARS " \t"
2487 static void compose_wrap_line(Compose *compose)
2489 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2490 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2492 GtkTextIter insert_iter, iter;
2493 gint ch_len, last_ch_len;
2494 gchar cbuf[CHAR_BUF_SIZE], last_ch;
2496 gint p_start, p_end;
2497 gint line_pos, cur_pos;
2498 gint line_len, cur_len;
2499 gboolean line_end, quoted;
2501 text_len = gtk_text_buffer_get_char_count(textbuf);
2502 mark = gtk_text_buffer_get_insert(textbuf);
2503 gtk_text_buffer_get_iter_at_mark(textbuf, &insert_iter, mark);
2504 cur_pos = gtk_text_iter_get_offset(&insert_iter);
2505 GET_CHAR(&insert_iter, cbuf, ch_len);
2506 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2507 GtkTextIter prev_iter;
2509 return; /* on the paragraph mark */
2510 prev_iter = insert_iter;
2511 gtk_text_iter_backward_char(&prev_iter);
2512 GET_CHAR(&prev_iter, cbuf, ch_len);
2513 if (ch_len == 1 && *cbuf == '\n')
2514 return; /* on the paragraph mark */
2517 /* find paragraph start. */
2518 line_end = quoted = FALSE;
2519 for (iter = insert_iter; gtk_text_iter_backward_char(&iter);) {
2520 GET_CHAR(&iter, cbuf, ch_len);
2521 if (ch_len == 1 && *cbuf == '\n') {
2523 return; /* quoted part */
2525 gtk_text_iter_forward_chars(&iter, 2);
2531 && strchr(prefs_common.quote_chars, *cbuf))
2533 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2539 p_start = gtk_text_iter_get_offset(&iter);
2541 /* find paragraph end. */
2543 for (iter = insert_iter; gtk_text_iter_forward_char(&iter);) {
2544 GET_CHAR(&iter, cbuf, ch_len);
2545 if (ch_len == 1 && *cbuf == '\n') {
2548 gtk_text_iter_backward_char(&iter);
2553 if (line_end && ch_len == 1 &&
2554 strchr(prefs_common.quote_chars, *cbuf))
2555 return; /* quoted part */
2560 p_end = gtk_text_iter_get_offset(&iter);
2562 if (p_end >= text_len)
2565 if (p_start >= p_end)
2568 line_len = cur_len = 0;
2572 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2573 gboolean space = FALSE;
2575 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2577 GET_CHAR(&iter, cbuf, ch_len);
2584 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2587 if (ch_len == 1 && *cbuf == '\n') {
2588 gboolean replace = FALSE;
2589 GtkTextIter next_iter = iter;
2591 gtk_text_iter_forward_char(&next_iter);
2593 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2594 if (cur_pos + 1 < p_end) {
2595 GET_CHAR(&next_iter, cbuf, ch_len);
2597 !isspace(*(guchar *)cbuf))
2601 gtk_text_buffer_delete(textbuf, &iter, &next_iter);
2603 gtk_text_buffer_insert(textbuf, &iter, " ", 1);
2609 gtk_text_buffer_get_iter_at_offset
2610 (textbuf, &iter, cur_pos);
2615 last_ch_len = ch_len;
2619 line_pos = cur_pos + 1;
2620 line_len = cur_len + ch_len;
2623 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
2625 if (cur_len + ch_len > prefs_common.linewrap_len &&
2628 GtkTextIter prev_iter = iter;
2630 gtk_text_iter_backward_char(&prev_iter);
2632 GET_CHAR(&prev_iter, cbuf, ch_len);
2633 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2634 gtk_text_buffer_delete(textbuf, &prev_iter, &iter);
2644 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
2648 cur_len = cur_len - line_len + ch_len;
2654 line_pos = cur_pos + 1;
2655 line_len = cur_len + ch_len;
2663 /* Darko: used when I debug wrapping */
2664 void dump_text(GtkTextBuffer *textbuf, int pos, int tlen, int breakoncr)
2667 gchar cbuf[CHAR_BUF_SIZE];
2668 GtkTextIter iter, end_iter;
2670 printf("%d [", pos);
2671 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
2672 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
2673 for (; gtk_text_iter_forward_char(&iter) &&
2674 gtk_text_iter_compare(&iter, &end_iter) < 0;) {
2675 GET_CHAR(&iter, cbuf, clen);
2676 if (clen < 0) break;
2677 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2679 fwrite(cbuf, clen, 1, stdout);
2687 WAIT_FOR_INDENT_CHAR,
2688 WAIT_FOR_INDENT_CHAR_OR_SPACE
2691 /* return indent length, we allow:
2692 > followed by spaces/tabs
2693 | followed by spaces/tabs
2694 uppercase characters immediately followed by >,
2695 and the repeating sequences of the above */
2696 /* return indent length */
2697 static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint text_len)
2700 guint i, ch_len, alnum_cnt = 0;
2701 IndentState state = WAIT_FOR_INDENT_CHAR;
2702 gchar cbuf[CHAR_BUF_SIZE];
2706 if (prefs_common.quote_chars == NULL) {
2710 for (i = start_pos; i < text_len; i++) {
2713 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, i);
2714 GET_CHAR(&iter, cbuf, ch_len);
2718 if (cbuf[0] == '\n')
2721 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2722 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2725 case WAIT_FOR_SPACE:
2726 if (is_space == FALSE)
2728 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2730 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2731 if (is_indent == FALSE && is_space == FALSE &&
2732 !isupper((guchar)cbuf[0]))
2734 if (is_space == TRUE) {
2736 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2737 } else if (is_indent == TRUE) {
2739 state = WAIT_FOR_SPACE;
2742 state = WAIT_FOR_INDENT_CHAR;
2745 case WAIT_FOR_INDENT_CHAR:
2746 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2748 if (is_indent == TRUE) {
2750 && !strchr(prefs_common.quote_chars, cbuf[0]))
2753 state = WAIT_FOR_SPACE;
2764 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2770 /* insert quotation string when line was wrapped */
2771 static guint ins_quote(GtkTextBuffer *textbuf, GtkTextIter *iter,
2773 guint prev_line_pos, guint text_len,
2779 GtkTextIter iter1, iter2;
2782 gtk_text_buffer_get_iter_at_offset(textbuf, &iter1,
2784 gtk_text_buffer_get_iter_at_offset(textbuf, &iter2,
2785 prev_line_pos + indent_len);
2786 text = gtk_text_buffer_get_text(textbuf, &iter1, &iter2, FALSE);
2787 if (!text) return 0;
2789 gtk_text_buffer_insert(textbuf, iter, text, -1);
2790 ins_len = g_utf8_strlen(text, -1);
2798 static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint start_pos)
2802 GtkTextIter end_iter;
2803 if (!compose->account->sig_sep)
2806 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos+1);
2807 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2808 start_pos+strlen(compose->account->sig_sep)+1);
2810 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),
2811 compose->account->sig_sep)) {
2813 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2814 start_pos+strlen(compose->account->sig_sep)+1);
2815 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2816 start_pos+strlen(compose->account->sig_sep)+2);
2818 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),"\n"));
2827 /* check if we should join the next line */
2828 static gboolean join_next_line_is_needed(GtkTextBuffer *textbuf,
2829 guint start_pos, guint tlen,
2830 guint prev_ilen, gboolean autowrap)
2832 guint indent_len, ch_len;
2833 gboolean do_join = FALSE;
2834 gchar cbuf[CHAR_BUF_SIZE];
2836 indent_len = get_indent_length(textbuf, start_pos, tlen);
2838 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2840 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2841 start_pos + indent_len);
2842 GET_CHAR(&iter, cbuf, ch_len);
2844 if (ch_len > 0 && (cbuf[0] != '\n'))
2851 static void compose_wrap_line_all(Compose *compose)
2853 compose_wrap_line_all_full(compose, FALSE);
2856 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2858 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2859 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2860 GtkTextIter iter, end_iter;
2862 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2863 gint line_len = 0, cur_len = 0;
2865 gboolean is_new_line = TRUE, do_delete = FALSE;
2867 gboolean linewrap_quote = prefs_common.linewrap_quote;
2868 gboolean set_editable_pos = FALSE;
2869 gint editable_pos = 0;
2870 guint linewrap_len = prefs_common.linewrap_len;
2871 gchar *qfmt = prefs_common.quotemark;
2872 gchar cbuf[CHAR_BUF_SIZE];
2873 GtkTextMark *cursor_mark = gtk_text_buffer_get_insert(textbuf);
2875 tlen = gtk_text_buffer_get_char_count(textbuf);
2877 for (; cur_pos < tlen; cur_pos++) {
2878 /* mark position of new line - needed for quotation wrap */
2881 i_len = get_indent_length(textbuf, cur_pos, tlen);
2883 is_new_line = FALSE;
2887 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2888 GET_CHAR(&iter, cbuf, ch_len);
2890 /* fix line length for tabs */
2891 if (ch_len == 1 && *cbuf == '\t') {
2892 guint tab_width = 8;
2893 guint tab_offset = line_len % tab_width;
2895 line_len += tab_width - tab_offset - 1;
2899 /* we have encountered line break */
2900 if (ch_len == 1 && *cbuf == '\n') {
2902 gchar cb[CHAR_BUF_SIZE];
2904 /* should we join the next line */
2905 if ((autowrap || i_len != cur_len) && do_delete &&
2906 !is_sig_separator(compose, textbuf, cur_pos+i_len) &&
2907 join_next_line_is_needed
2908 (textbuf, cur_pos + 1, tlen, i_len, autowrap)) {
2913 /* skip delete if it is continuous URL */
2914 if (do_delete && (line_pos - p_pos <= i_len) &&
2915 gtkut_text_buffer_is_uri_string(textbuf, line_pos,
2919 /* should we delete to perform smart wrapping */
2920 if (line_len < linewrap_len && do_delete) {
2921 /* get rid of newline */
2922 gtk_text_buffer_get_iter_at_offset(textbuf,
2926 gtk_text_iter_forward_char(&end_iter);
2927 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
2930 /* if text starts with quote fmt or with
2931 indent string, delete them */
2934 ilen = gtkut_text_buffer_str_compare_n
2935 (textbuf, cur_pos, p_pos, i_len,
2939 gtk_text_iter_forward_chars
2941 gtk_text_buffer_delete(textbuf,
2948 gtk_text_buffer_get_iter_at_offset(textbuf,
2951 GET_CHAR(&iter, cb, clen);
2953 /* insert space if it's alphanumeric */
2954 if ((cur_pos != line_pos) &&
2955 ((clen > 1) || isalnum((guchar)cb[0]))) {
2956 GtkTextIter cursor_iter;
2957 gboolean go_back = FALSE;
2958 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2959 if (gtk_text_iter_get_offset(&iter) ==
2960 gtk_text_iter_get_offset(&cursor_iter))
2963 gtk_text_buffer_insert(textbuf, &iter,
2966 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2967 gtk_text_iter_backward_chars(&cursor_iter, 1);
2968 gtk_text_buffer_place_cursor(textbuf, &cursor_iter);
2973 /* and start over with current line */
2974 cur_pos = p_pos - 1;
2976 line_len = cur_len = 0;
2980 g_print("after delete l_pos=");
2981 dump_text(textbuf, line_pos, tlen, 1);
2983 /* move beginning of line if we are on LF */
2984 gtk_text_buffer_get_iter_at_offset(textbuf,
2987 GET_CHAR(&iter, cb, clen);
2988 if (clen == 1 && *cb == '\n')
2991 g_print("new line_pos=%d\n", line_pos);
2997 /* mark new line beginning */
2998 line_pos = cur_pos + 1;
2999 line_len = cur_len = 0;
3010 /* possible line break */
3011 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
3012 line_pos = cur_pos + 1;
3013 line_len = cur_len + ch_len;
3016 /* are we over wrapping length set in preferences ? */
3017 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
3021 g_print("should wrap cur_pos=%d ", cur_pos);
3022 dump_text(textbuf, p_pos, tlen, 1);
3023 dump_text(textbuf, line_pos, tlen, 1);
3025 /* force wrapping if it is one long word but not URL */
3026 if (line_pos - p_pos <= i_len)
3027 if (!gtkut_text_buffer_is_uri_string
3028 (textbuf, line_pos, tlen))
3029 line_pos = cur_pos - 1;
3031 g_print("new line_pos=%d\n", line_pos);
3034 gtk_text_buffer_get_iter_at_offset(textbuf,
3037 GET_CHAR(&iter, cbuf, clen);
3039 /* if next character is space delete it */
3040 if (clen == 1 && isspace(*(guchar *)cbuf)) {
3041 if (p_pos + i_len != line_pos ||
3042 !gtkut_text_buffer_is_uri_string
3043 (textbuf, line_pos, tlen)) {
3044 /* workaround for correct cursor
3046 if (set_editable_pos == FALSE) {
3047 GtkTextMark *ins = gtk_text_buffer_get_insert(textbuf);
3048 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, ins);
3049 editable_pos = gtk_text_iter_get_offset(&iter);
3050 if (editable_pos == line_pos)
3051 set_editable_pos = TRUE;
3053 gtk_text_buffer_get_iter_at_offset(textbuf,
3056 gtk_text_buffer_get_iter_at_offset(textbuf,
3059 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
3060 //gtk_stext_set_point(text, line_pos);
3061 //gtk_stext_backward_delete(text, 1);
3070 /* if it is URL at beginning of line don't wrap */
3071 if (p_pos + i_len == line_pos &&
3072 gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
3074 g_print("found URL at ");
3075 dump_text(textbuf, line_pos, tlen, 1);
3081 gtk_text_buffer_get_iter_at_offset(textbuf,
3084 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
3085 //gtk_stext_set_point(text, line_pos);
3086 //gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
3087 //gtk_stext_compact_buffer(text);
3090 /* for loop will increase it */
3091 cur_pos = line_pos - 1;
3092 /* start over with current line */
3094 line_len = cur_len = 0;
3095 if (autowrap || i_len > 0) {
3100 g_print("after CR insert ");
3101 dump_text(textbuf, line_pos, tlen, 1);
3102 dump_text(textbuf, cur_pos, tlen, 1);
3105 /* should we insert quotation ? */
3106 if (linewrap_quote && i_len) {
3107 /* only if line is not already quoted */
3108 if (!gtkut_text_buffer_str_compare
3109 (textbuf, line_pos, tlen, qfmt)) {
3112 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
3114 if (line_pos - p_pos > i_len) {
3116 (textbuf, &iter, i_len, p_pos,
3121 g_print("after quote insert ");
3122 dump_text(textbuf, line_pos, tlen, 1);
3130 line_pos = cur_pos + 1;
3131 line_len = cur_len + ch_len;
3133 /* advance to next character in buffer */
3137 if (set_editable_pos && editable_pos <= tlen) {
3138 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, editable_pos);
3139 gtk_text_buffer_place_cursor(textbuf, &iter);
3144 #undef CHAR_BUF_SIZE