2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
123 #include "combobox.h"
137 #define N_ATTACH_COLS (N_COL_COLUMNS)
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
148 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
154 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
155 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
156 } ComposeCallAdvancedAction;
160 PRIORITY_HIGHEST = 1,
169 COMPOSE_INSERT_SUCCESS,
170 COMPOSE_INSERT_READ_ERROR,
171 COMPOSE_INSERT_INVALID_CHARACTER,
172 COMPOSE_INSERT_NO_FILE
173 } ComposeInsertResult;
177 COMPOSE_WRITE_FOR_SEND,
178 COMPOSE_WRITE_FOR_STORE
181 #define B64_LINE_SIZE 57
182 #define B64_BUFFSIZE 77
184 #define MAX_REFERENCES_LEN 999
186 static GList *compose_list = NULL;
188 static Compose *compose_generic_new (PrefsAccount *account,
191 GPtrArray *attach_files,
192 GList *listAddress );
194 static Compose *compose_create (PrefsAccount *account,
198 static void compose_entry_mark_default_to (Compose *compose,
199 const gchar *address);
200 static Compose *compose_followup_and_reply_to (MsgInfo *msginfo,
205 static Compose *compose_forward_multiple (PrefsAccount *account,
206 GSList *msginfo_list);
207 static Compose *compose_reply (MsgInfo *msginfo,
213 static Compose *compose_reply_mode (ComposeMode mode,
214 GSList *msginfo_list,
216 static void compose_template_apply_fields(Compose *compose, Template *tmpl);
217 static void compose_update_privacy_systems_menu(Compose *compose);
219 static GtkWidget *compose_account_option_menu_create
221 static void compose_set_out_encoding (Compose *compose);
222 static void compose_set_template_menu (Compose *compose);
223 static void compose_template_apply (Compose *compose,
226 static void compose_destroy (Compose *compose);
228 static void compose_entries_set (Compose *compose,
229 const gchar *mailto);
230 static gint compose_parse_header (Compose *compose,
232 static gchar *compose_parse_references (const gchar *ref,
235 static gchar *compose_quote_fmt (Compose *compose,
241 gboolean need_unescape,
242 const gchar *err_msg);
244 static void compose_reply_set_entry (Compose *compose,
250 followup_and_reply_to);
251 static void compose_reedit_set_entry (Compose *compose,
254 static void compose_insert_sig (Compose *compose,
256 static gchar *compose_get_signature_str (Compose *compose);
257 static ComposeInsertResult compose_insert_file (Compose *compose,
260 static gboolean compose_attach_append (Compose *compose,
263 const gchar *content_type);
264 static void compose_attach_parts (Compose *compose,
267 static void compose_beautify_paragraph (Compose *compose,
268 GtkTextIter *par_iter,
270 static void compose_wrap_all (Compose *compose);
271 static void compose_wrap_all_full (Compose *compose,
274 static void compose_set_title (Compose *compose);
275 static void compose_select_account (Compose *compose,
276 PrefsAccount *account,
279 static PrefsAccount *compose_current_mail_account(void);
280 /* static gint compose_send (Compose *compose); */
281 static gboolean compose_check_for_valid_recipient
283 static gboolean compose_check_entries (Compose *compose,
284 gboolean check_everything);
285 static gint compose_write_to_file (Compose *compose,
288 gboolean attach_parts);
289 static gint compose_write_body_to_file (Compose *compose,
291 static gint compose_remove_reedit_target (Compose *compose,
293 static void compose_remove_draft (Compose *compose);
294 static gint compose_queue_sub (Compose *compose,
298 gboolean check_subject,
299 gboolean remove_reedit_target);
300 static void compose_add_attachments (Compose *compose,
302 static gchar *compose_get_header (Compose *compose);
304 static void compose_convert_header (Compose *compose,
309 gboolean addr_field);
311 static void compose_attach_info_free (AttachInfo *ainfo);
312 static void compose_attach_remove_selected (Compose *compose);
314 static void compose_attach_property (Compose *compose);
315 static void compose_attach_property_create (gboolean *cancelled);
316 static void attach_property_ok (GtkWidget *widget,
317 gboolean *cancelled);
318 static void attach_property_cancel (GtkWidget *widget,
319 gboolean *cancelled);
320 static gint attach_property_delete_event (GtkWidget *widget,
322 gboolean *cancelled);
323 static gboolean attach_property_key_pressed (GtkWidget *widget,
325 gboolean *cancelled);
327 static void compose_exec_ext_editor (Compose *compose);
329 static gint compose_exec_ext_editor_real (const gchar *file);
330 static gboolean compose_ext_editor_kill (Compose *compose);
331 static gboolean compose_input_cb (GIOChannel *source,
332 GIOCondition condition,
334 static void compose_set_ext_editor_sensitive (Compose *compose,
336 #endif /* G_OS_UNIX */
338 static void compose_undo_state_changed (UndoMain *undostruct,
343 static void compose_create_header_entry (Compose *compose);
344 static void compose_add_header_entry (Compose *compose, const gchar *header, gchar *text);
345 static void compose_remove_header_entries(Compose *compose);
347 static void compose_update_priority_menu_item(Compose * compose);
349 static void compose_spell_menu_changed (void *data);
351 static void compose_add_field_list ( Compose *compose,
352 GList *listAddress );
354 /* callback functions */
356 static gboolean compose_edit_size_alloc (GtkEditable *widget,
357 GtkAllocation *allocation,
358 GtkSHRuler *shruler);
359 static void account_activated (GtkComboBox *optmenu,
361 static void attach_selected (GtkTreeView *tree_view,
362 GtkTreePath *tree_path,
363 GtkTreeViewColumn *column,
365 static gboolean attach_button_pressed (GtkWidget *widget,
366 GdkEventButton *event,
368 static gboolean attach_key_pressed (GtkWidget *widget,
371 static void compose_send_cb (gpointer data,
374 static void compose_send_later_cb (gpointer data,
378 static void compose_draft_cb (gpointer data,
382 static void compose_attach_cb (gpointer data,
385 static void compose_insert_file_cb (gpointer data,
388 static void compose_insert_sig_cb (gpointer data,
392 static void compose_close_cb (gpointer data,
396 static void compose_set_encoding_cb (gpointer data,
400 static void compose_address_cb (gpointer data,
403 static void compose_template_activate_cb(GtkWidget *widget,
406 static void compose_ext_editor_cb (gpointer data,
410 static gint compose_delete_cb (GtkWidget *widget,
414 static void compose_undo_cb (Compose *compose);
415 static void compose_redo_cb (Compose *compose);
416 static void compose_cut_cb (Compose *compose);
417 static void compose_copy_cb (Compose *compose);
418 static void compose_paste_cb (Compose *compose);
419 static void compose_paste_as_quote_cb (Compose *compose);
420 static void compose_paste_no_wrap_cb (Compose *compose);
421 static void compose_paste_wrap_cb (Compose *compose);
422 static void compose_allsel_cb (Compose *compose);
424 static void compose_advanced_action_cb (Compose *compose,
425 ComposeCallAdvancedAction action);
427 static void compose_grab_focus_cb (GtkWidget *widget,
430 static void compose_changed_cb (GtkTextBuffer *textbuf,
433 static void compose_wrap_cb (gpointer data,
436 static void compose_find_cb (gpointer data,
439 static void compose_toggle_autowrap_cb (gpointer data,
443 static void compose_toggle_ruler_cb (gpointer data,
446 static void compose_toggle_sign_cb (gpointer data,
449 static void compose_toggle_encrypt_cb (gpointer data,
452 static void compose_set_privacy_system_cb(GtkWidget *widget,
454 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
455 static void activate_privacy_system (Compose *compose,
456 PrefsAccount *account,
458 static void compose_use_signing(Compose *compose, gboolean use_signing);
459 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
460 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
462 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
464 static void compose_set_priority_cb (gpointer data,
467 static void compose_reply_change_mode (gpointer data,
471 static void compose_attach_drag_received_cb (GtkWidget *widget,
472 GdkDragContext *drag_context,
475 GtkSelectionData *data,
479 static void compose_insert_drag_received_cb (GtkWidget *widget,
480 GdkDragContext *drag_context,
483 GtkSelectionData *data,
487 static void compose_header_drag_received_cb (GtkWidget *widget,
488 GdkDragContext *drag_context,
491 GtkSelectionData *data,
496 static gboolean compose_drag_drop (GtkWidget *widget,
497 GdkDragContext *drag_context,
499 guint time, gpointer user_data);
501 static void text_inserted (GtkTextBuffer *buffer,
506 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
507 gboolean to_all, gboolean to_ml,
509 gboolean followup_and_reply_to,
512 static gboolean compose_headerentry_changed_cb (GtkWidget *entry,
513 ComposeHeaderEntry *headerentry);
514 static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
516 ComposeHeaderEntry *headerentry);
518 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
520 static void compose_allow_user_actions (Compose *compose, gboolean allow);
523 static void compose_check_all (Compose *compose);
524 static void compose_highlight_all (Compose *compose);
525 static void compose_check_backwards (Compose *compose);
526 static void compose_check_forwards_go (Compose *compose);
529 static gint compose_defer_auto_save_draft (Compose *compose);
530 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
532 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
535 static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
536 FolderItem *folder_item);
539 static GtkItemFactoryEntry compose_popup_entries[] =
541 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
542 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
543 {"/---", NULL, NULL, 0, "<Separator>"},
544 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
547 static GtkItemFactoryEntry compose_entries[] =
549 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
550 {N_("/_Message/S_end"), "<control>Return",
551 compose_send_cb, 0, NULL},
552 {N_("/_Message/Send _later"), "<shift><control>S",
553 compose_send_later_cb, 0, NULL},
554 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
555 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
556 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
557 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
558 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
559 {N_("/_Message/_Save"),
560 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
561 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
562 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
564 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
565 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
566 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
567 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
568 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
569 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
570 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
571 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
572 {N_("/_Edit/Special paste/as _quotation"),
573 NULL, compose_paste_as_quote_cb, 0, NULL},
574 {N_("/_Edit/Special paste/_wrapped"),
575 NULL, compose_paste_wrap_cb, 0, NULL},
576 {N_("/_Edit/Special paste/_unwrapped"),
577 NULL, compose_paste_no_wrap_cb, 0, NULL},
578 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
579 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
580 {N_("/_Edit/A_dvanced/Move a character backward"),
582 compose_advanced_action_cb,
583 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
585 {N_("/_Edit/A_dvanced/Move a character forward"),
587 compose_advanced_action_cb,
588 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
590 {N_("/_Edit/A_dvanced/Move a word backward"),
592 compose_advanced_action_cb,
593 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
595 {N_("/_Edit/A_dvanced/Move a word forward"),
597 compose_advanced_action_cb,
598 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
600 {N_("/_Edit/A_dvanced/Move to beginning of line"),
601 NULL, /* "<control>A" */
602 compose_advanced_action_cb,
603 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
605 {N_("/_Edit/A_dvanced/Move to end of line"),
607 compose_advanced_action_cb,
608 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
610 {N_("/_Edit/A_dvanced/Move to previous line"),
612 compose_advanced_action_cb,
613 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
615 {N_("/_Edit/A_dvanced/Move to next line"),
617 compose_advanced_action_cb,
618 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
620 {N_("/_Edit/A_dvanced/Delete a character backward"),
622 compose_advanced_action_cb,
623 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
625 {N_("/_Edit/A_dvanced/Delete a character forward"),
627 compose_advanced_action_cb,
628 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
630 {N_("/_Edit/A_dvanced/Delete a word backward"),
631 NULL, /* "<control>W" */
632 compose_advanced_action_cb,
633 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
635 {N_("/_Edit/A_dvanced/Delete a word forward"),
636 NULL, /* "<alt>D", */
637 compose_advanced_action_cb,
638 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
640 {N_("/_Edit/A_dvanced/Delete line"),
642 compose_advanced_action_cb,
643 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
645 {N_("/_Edit/A_dvanced/Delete entire line"),
647 compose_advanced_action_cb,
648 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
650 {N_("/_Edit/A_dvanced/Delete to end of line"),
652 compose_advanced_action_cb,
653 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
655 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
657 "<control>F", compose_find_cb, 0, NULL},
658 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Edit/_Wrap current paragraph"),
660 "<control>L", compose_wrap_cb, 0, NULL},
661 {N_("/_Edit/Wrap all long _lines"),
662 "<control><alt>L", compose_wrap_cb, 1, NULL},
663 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
664 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
665 {N_("/_Edit/Edit with e_xternal editor"),
666 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
668 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Spelling/_Check all or check selection"),
670 NULL, compose_check_all, 0, NULL},
671 {N_("/_Spelling/_Highlight all misspelled words"),
672 NULL, compose_highlight_all, 0, NULL},
673 {N_("/_Spelling/Check _backwards misspelled word"),
674 NULL, compose_check_backwards , 0, NULL},
675 {N_("/_Spelling/_Forward to next misspelled word"),
676 NULL, compose_check_forwards_go, 0, NULL},
677 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
678 {N_("/_Spelling/Options"),
679 NULL, NULL, 0, "<Branch>"},
681 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
682 {N_("/_Options/Reply _mode"), NULL, NULL, 0, "<Branch>"},
683 {N_("/_Options/Reply _mode/_Normal"), NULL, compose_reply_change_mode, COMPOSE_REPLY, "<RadioItem>"},
684 {N_("/_Options/Reply _mode/_All"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_ALL, "/Options/Reply mode/Normal"},
685 {N_("/_Options/Reply _mode/_Sender"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_SENDER, "/Options/Reply mode/Normal"},
686 {N_("/_Options/Reply _mode/_Mailing-list"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_LIST, "/Options/Reply mode/Normal"},
687 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
688 {N_("/_Options/Privacy _System"), NULL, NULL, 0, "<Branch>"},
689 {N_("/_Options/Privacy _System/None"), NULL, NULL, 0, "<RadioItem>"},
690 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
691 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
692 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
693 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
694 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
695 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
696 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
697 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
698 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
699 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
700 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
701 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
702 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
703 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
705 #define ENC_ACTION(action) \
706 NULL, compose_set_encoding_cb, action, \
707 "/Options/Character encoding/Automatic"
709 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
710 {N_("/_Options/Character _encoding/_Automatic"),
711 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
712 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
714 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
715 ENC_ACTION(C_US_ASCII)},
716 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
717 ENC_ACTION(C_UTF_8)},
718 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
720 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
721 ENC_ACTION(C_ISO_8859_1)},
722 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
723 ENC_ACTION(C_ISO_8859_15)},
724 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
725 ENC_ACTION(C_WINDOWS_1252)},
726 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
728 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
729 ENC_ACTION(C_ISO_8859_2)},
730 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
732 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
733 ENC_ACTION(C_ISO_8859_13)},
734 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
735 ENC_ACTION(C_ISO_8859_4)},
736 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
738 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
739 ENC_ACTION(C_ISO_8859_7)},
740 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
742 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
743 ENC_ACTION(C_ISO_8859_8)},
744 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
745 ENC_ACTION(C_WINDOWS_1255)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
749 ENC_ACTION(C_ISO_8859_6)},
750 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
751 ENC_ACTION(C_CP1256)},
752 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
754 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
755 ENC_ACTION(C_ISO_8859_9)},
756 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
758 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
759 ENC_ACTION(C_ISO_8859_5)},
760 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
761 ENC_ACTION(C_KOI8_R)},
762 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
763 ENC_ACTION(C_KOI8_U)},
764 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
765 ENC_ACTION(C_WINDOWS_1251)},
766 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
768 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
769 ENC_ACTION(C_ISO_2022_JP)},
770 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
772 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
773 ENC_ACTION(C_GB2312)},
774 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
776 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
778 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
779 ENC_ACTION(C_EUC_TW)},
780 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
782 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
783 ENC_ACTION(C_EUC_KR)},
784 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
786 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
787 ENC_ACTION(C_TIS_620)},
788 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
789 ENC_ACTION(C_WINDOWS_874)},
791 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
792 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
793 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
794 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
795 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
796 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
797 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
800 static GtkTargetEntry compose_mime_types[] =
802 {"text/uri-list", 0, 0},
803 {"UTF8_STRING", 0, 0},
807 static gboolean compose_put_existing_to_front(MsgInfo *info)
809 GList *compose_list = compose_get_compose_list();
813 for (elem = compose_list; elem != NULL && elem->data != NULL;
815 Compose *c = (Compose*)elem->data;
817 if (!c->targetinfo || !c->targetinfo->msgid ||
821 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
822 gtkut_window_popup(c->window);
830 static GdkColor quote_color1 =
831 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
832 static GdkColor quote_color2 =
833 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
834 static GdkColor quote_color3 =
835 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
837 static GdkColor quote_bgcolor1 =
838 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
839 static GdkColor quote_bgcolor2 =
840 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
841 static GdkColor quote_bgcolor3 =
842 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
844 static GdkColor signature_color = {
851 static GdkColor uri_color = {
858 static void compose_create_tags(GtkTextView *text, Compose *compose)
860 GtkTextBuffer *buffer;
861 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
867 buffer = gtk_text_view_get_buffer(text);
869 if (prefs_common.enable_color) {
870 /* grab the quote colors, converting from an int to a GdkColor */
871 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
873 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
875 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
877 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
879 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
881 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
883 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
885 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
888 signature_color = quote_color1 = quote_color2 = quote_color3 =
889 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
892 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
893 gtk_text_buffer_create_tag(buffer, "quote0",
894 "foreground-gdk", "e_color1,
895 "paragraph-background-gdk", "e_bgcolor1,
897 gtk_text_buffer_create_tag(buffer, "quote1",
898 "foreground-gdk", "e_color2,
899 "paragraph-background-gdk", "e_bgcolor2,
901 gtk_text_buffer_create_tag(buffer, "quote2",
902 "foreground-gdk", "e_color3,
903 "paragraph-background-gdk", "e_bgcolor3,
906 gtk_text_buffer_create_tag(buffer, "quote0",
907 "foreground-gdk", "e_color1,
909 gtk_text_buffer_create_tag(buffer, "quote1",
910 "foreground-gdk", "e_color2,
912 gtk_text_buffer_create_tag(buffer, "quote2",
913 "foreground-gdk", "e_color3,
917 gtk_text_buffer_create_tag(buffer, "signature",
918 "foreground-gdk", &signature_color,
920 gtk_text_buffer_create_tag(buffer, "link",
921 "foreground-gdk", &uri_color,
923 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
924 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
926 color[0] = quote_color1;
927 color[1] = quote_color2;
928 color[2] = quote_color3;
929 color[3] = quote_bgcolor1;
930 color[4] = quote_bgcolor2;
931 color[5] = quote_bgcolor3;
932 color[6] = signature_color;
933 color[7] = uri_color;
934 cmap = gdk_drawable_get_colormap(compose->window->window);
935 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
937 for (i = 0; i < 8; i++) {
938 if (success[i] == FALSE) {
941 g_warning("Compose: color allocation failed.\n");
942 style = gtk_widget_get_style(GTK_WIDGET(text));
943 quote_color1 = quote_color2 = quote_color3 =
944 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
945 signature_color = uri_color = black;
950 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
951 GPtrArray *attach_files)
953 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
956 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item, const gchar *mailto)
958 return compose_generic_new(account, mailto, item, NULL, NULL);
961 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
963 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
966 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
967 GPtrArray *attach_files, GList *listAddress )
970 GtkTextView *textview;
971 GtkTextBuffer *textbuf;
973 GtkItemFactory *ifactory;
975 if (item && item->prefs && item->prefs->enable_default_account)
976 account = account_find_from_id(item->prefs->default_account);
978 if (!account) account = cur_account;
979 g_return_val_if_fail(account != NULL, NULL);
981 compose = compose_create(account, COMPOSE_NEW, FALSE);
983 ifactory = gtk_item_factory_from_widget(compose->menubar);
985 compose->replyinfo = NULL;
986 compose->fwdinfo = NULL;
988 textview = GTK_TEXT_VIEW(compose->text);
989 textbuf = gtk_text_view_get_buffer(textview);
990 compose_create_tags(textview, compose);
992 undo_block(compose->undostruct);
994 compose_set_dictionaries_from_folder_prefs(compose, item);
997 if (account->auto_sig)
998 compose_insert_sig(compose, FALSE);
999 gtk_text_buffer_get_start_iter(textbuf, &iter);
1000 gtk_text_buffer_place_cursor(textbuf, &iter);
1002 if (account->protocol != A_NNTP) {
1003 if (mailto && *mailto != '\0') {
1004 compose_entries_set(compose, mailto);
1006 } else if (item && item->prefs->enable_default_to) {
1007 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
1008 compose_entry_mark_default_to(compose, item->prefs->default_to);
1010 if (item && item->ret_rcpt) {
1011 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1015 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
1016 } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
1017 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
1020 * CLAWS: just don't allow return receipt request, even if the user
1021 * may want to send an email. simple but foolproof.
1023 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1025 compose_add_field_list( compose, listAddress );
1027 if (prefs_common.compose_with_format) {
1028 MsgInfo* dummyinfo = NULL;
1030 if ( prefs_common.compose_subject_format
1031 && *prefs_common.compose_subject_format != '\0' )
1033 gchar *subject = NULL;
1037 dummyinfo = compose_msginfo_new_from_compose(compose);
1039 /* decode \-escape sequences in the internal representation of the quote format */
1040 tmp = malloc(strlen(prefs_common.compose_subject_format)+1);
1041 pref_get_unescaped_pref(tmp, prefs_common.compose_subject_format);
1043 subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
1045 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account,
1046 compose->gtkaspell);
1048 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account);
1050 quote_fmt_scan_string(tmp);
1053 buf = quote_fmt_get_buffer();
1055 alertpanel_error(_("New message subject format error."));
1057 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
1058 quote_fmt_reset_vartable();
1064 if ( prefs_common.compose_body_format
1065 && *prefs_common.compose_body_format != '\0' )
1068 GtkTextBuffer *buffer;
1069 GtkTextIter start, end;
1072 if ( dummyinfo == NULL )
1073 dummyinfo = compose_msginfo_new_from_compose(compose);
1075 text = GTK_TEXT_VIEW(compose->text);
1076 buffer = gtk_text_view_get_buffer(text);
1077 gtk_text_buffer_get_start_iter(buffer, &start);
1078 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
1079 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
1081 compose_quote_fmt(compose, dummyinfo,
1082 prefs_common.compose_body_format,
1083 NULL, tmp, FALSE, TRUE,
1084 _("New message body format error at line %d."));
1085 quote_fmt_reset_vartable();
1090 procmsg_msginfo_free( dummyinfo );
1097 for (i = 0; i < attach_files->len; i++) {
1098 file = g_ptr_array_index(attach_files, i);
1099 compose_attach_append(compose, file, file, NULL);
1103 compose_show_first_last_header(compose, TRUE);
1105 /* Set save folder */
1106 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1107 gchar *folderidentifier;
1109 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1110 folderidentifier = folder_item_get_identifier(item);
1111 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1112 g_free(folderidentifier);
1115 gtk_widget_grab_focus(compose->header_last->entry);
1117 undo_unblock(compose->undostruct);
1119 if (prefs_common.auto_exteditor)
1120 compose_exec_ext_editor(compose);
1122 compose->modified = FALSE;
1123 compose_set_title(compose);
1127 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1128 gboolean override_pref)
1130 gchar *privacy = NULL;
1132 g_return_if_fail(compose != NULL);
1133 g_return_if_fail(account != NULL);
1135 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1138 if (account->default_privacy_system
1139 && strlen(account->default_privacy_system)) {
1140 privacy = account->default_privacy_system;
1142 GSList *privacy_avail = privacy_get_system_ids();
1143 if (privacy_avail && g_slist_length(privacy_avail)) {
1144 privacy = (gchar *)(privacy_avail->data);
1147 if (privacy != NULL) {
1148 if (compose->privacy_system == NULL)
1149 compose->privacy_system = g_strdup(privacy);
1150 compose_update_privacy_system_menu_item(compose, FALSE);
1151 compose_use_encryption(compose, TRUE);
1155 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1157 gchar *privacy = NULL;
1159 if (account->default_privacy_system
1160 && strlen(account->default_privacy_system)) {
1161 privacy = account->default_privacy_system;
1163 GSList *privacy_avail = privacy_get_system_ids();
1164 if (privacy_avail && g_slist_length(privacy_avail)) {
1165 privacy = (gchar *)(privacy_avail->data);
1168 if (privacy != NULL) {
1169 if (compose->privacy_system == NULL)
1170 compose->privacy_system = g_strdup(privacy);
1171 compose_update_privacy_system_menu_item(compose, FALSE);
1172 compose_use_signing(compose, TRUE);
1176 static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1180 Compose *compose = NULL;
1181 GtkItemFactory *ifactory = NULL;
1183 g_return_val_if_fail(msginfo_list != NULL, NULL);
1185 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1186 g_return_val_if_fail(msginfo != NULL, NULL);
1188 list_len = g_slist_length(msginfo_list);
1192 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1193 FALSE, prefs_common.default_reply_list, FALSE, body);
1195 case COMPOSE_REPLY_WITH_QUOTE:
1196 compose = compose_reply(msginfo, TRUE,
1197 FALSE, prefs_common.default_reply_list, FALSE, body);
1199 case COMPOSE_REPLY_WITHOUT_QUOTE:
1200 compose = compose_reply(msginfo, FALSE,
1201 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1203 case COMPOSE_REPLY_TO_SENDER:
1204 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1205 FALSE, FALSE, TRUE, body);
1207 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1208 compose = compose_followup_and_reply_to(msginfo,
1209 prefs_common.reply_with_quote,
1210 FALSE, FALSE, body);
1212 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1213 compose = compose_reply(msginfo, TRUE,
1214 FALSE, FALSE, TRUE, body);
1216 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1217 compose = compose_reply(msginfo, FALSE,
1218 FALSE, FALSE, TRUE, NULL);
1220 case COMPOSE_REPLY_TO_ALL:
1221 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1222 TRUE, FALSE, FALSE, body);
1224 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1225 compose = compose_reply(msginfo, TRUE,
1226 TRUE, FALSE, FALSE, body);
1228 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1229 compose = compose_reply(msginfo, FALSE,
1230 TRUE, FALSE, FALSE, NULL);
1232 case COMPOSE_REPLY_TO_LIST:
1233 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1234 FALSE, TRUE, FALSE, body);
1236 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1237 compose = compose_reply(msginfo, TRUE,
1238 FALSE, TRUE, FALSE, body);
1240 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1241 compose = compose_reply(msginfo, FALSE,
1242 FALSE, TRUE, FALSE, NULL);
1244 case COMPOSE_FORWARD:
1245 if (prefs_common.forward_as_attachment) {
1246 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1249 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1253 case COMPOSE_FORWARD_INLINE:
1254 /* check if we reply to more than one Message */
1255 if (list_len == 1) {
1256 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1259 /* more messages FALL THROUGH */
1260 case COMPOSE_FORWARD_AS_ATTACH:
1261 compose = compose_forward_multiple(NULL, msginfo_list);
1263 case COMPOSE_REDIRECT:
1264 compose = compose_redirect(NULL, msginfo, FALSE);
1267 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1270 ifactory = gtk_item_factory_from_widget(compose->menubar);
1272 compose->rmode = mode;
1273 switch (compose->rmode) {
1275 case COMPOSE_REPLY_WITH_QUOTE:
1276 case COMPOSE_REPLY_WITHOUT_QUOTE:
1277 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1278 debug_print("reply mode Normal\n");
1279 menu_set_active(ifactory, "/Options/Reply mode/Normal", TRUE);
1280 compose_reply_change_mode(compose, COMPOSE_REPLY, NULL); /* force update */
1282 case COMPOSE_REPLY_TO_SENDER:
1283 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1284 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1285 debug_print("reply mode Sender\n");
1286 menu_set_active(ifactory, "/Options/Reply mode/Sender", TRUE);
1288 case COMPOSE_REPLY_TO_ALL:
1289 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1290 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1291 debug_print("reply mode All\n");
1292 menu_set_active(ifactory, "/Options/Reply mode/All", TRUE);
1294 case COMPOSE_REPLY_TO_LIST:
1295 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1296 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1297 debug_print("reply mode List\n");
1298 menu_set_active(ifactory, "/Options/Reply mode/Mailing-list", TRUE);
1306 static Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1307 gboolean to_ml, gboolean to_sender,
1310 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1311 to_sender, FALSE, body);
1314 static Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1319 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1320 to_sender, TRUE, body);
1323 static void compose_extract_original_charset(Compose *compose)
1325 MsgInfo *info = NULL;
1326 if (compose->replyinfo) {
1327 info = compose->replyinfo;
1328 } else if (compose->fwdinfo) {
1329 info = compose->fwdinfo;
1330 } else if (compose->targetinfo) {
1331 info = compose->targetinfo;
1334 MimeInfo *mimeinfo = procmime_scan_message(info);
1335 MimeInfo *partinfo = mimeinfo;
1336 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1337 partinfo = procmime_mimeinfo_next(partinfo);
1339 compose->orig_charset =
1340 g_strdup(procmime_mimeinfo_get_parameter(
1341 partinfo, "charset"));
1343 procmime_mimeinfo_free_all(mimeinfo);
1347 #define SIGNAL_BLOCK(buffer) { \
1348 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1349 G_CALLBACK(compose_changed_cb), \
1351 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1352 G_CALLBACK(text_inserted), \
1356 #define SIGNAL_UNBLOCK(buffer) { \
1357 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1358 G_CALLBACK(compose_changed_cb), \
1360 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1361 G_CALLBACK(text_inserted), \
1365 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1366 gboolean to_all, gboolean to_ml,
1368 gboolean followup_and_reply_to,
1371 GtkItemFactory *ifactory;
1373 PrefsAccount *account = NULL;
1374 PrefsAccount *reply_account;
1375 GtkTextView *textview;
1376 GtkTextBuffer *textbuf;
1378 g_return_val_if_fail(msginfo != NULL, NULL);
1379 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1381 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1383 g_return_val_if_fail(account != NULL, NULL);
1385 if (to_sender && account->protocol == A_NNTP &&
1386 !followup_and_reply_to) {
1388 account_find_from_address(account->address);
1390 reply_account = compose_current_mail_account();
1394 reply_account = account;
1396 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1398 compose->updating = TRUE;
1400 ifactory = gtk_item_factory_from_widget(compose->menubar);
1402 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1403 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1405 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1406 if (!compose->replyinfo)
1407 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1409 compose_extract_original_charset(compose);
1411 if (msginfo->folder && msginfo->folder->ret_rcpt)
1412 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1414 /* Set save folder */
1415 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1416 gchar *folderidentifier;
1418 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1419 folderidentifier = folder_item_get_identifier(msginfo->folder);
1420 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1421 g_free(folderidentifier);
1424 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1426 textview = (GTK_TEXT_VIEW(compose->text));
1427 textbuf = gtk_text_view_get_buffer(textview);
1428 compose_create_tags(textview, compose);
1430 undo_block(compose->undostruct);
1432 compose_set_dictionaries_from_folder_prefs(compose, msginfo->folder);
1438 if (prefs_common.quotemark && *prefs_common.quotemark)
1439 qmark = prefs_common.quotemark;
1443 compose_quote_fmt(compose, compose->replyinfo,
1444 prefs_common.quotefmt,
1445 qmark, body, FALSE, TRUE,
1446 _("Message reply format error at line %d."));
1447 quote_fmt_reset_vartable();
1449 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1450 compose_force_encryption(compose, account, FALSE);
1453 SIGNAL_BLOCK(textbuf);
1455 if (account->auto_sig)
1456 compose_insert_sig(compose, FALSE);
1458 compose_wrap_all(compose);
1460 SIGNAL_UNBLOCK(textbuf);
1462 gtk_widget_grab_focus(compose->text);
1464 undo_unblock(compose->undostruct);
1466 if (prefs_common.auto_exteditor)
1467 compose_exec_ext_editor(compose);
1469 compose->modified = FALSE;
1470 compose_set_title(compose);
1472 compose->updating = FALSE;
1474 if (compose->deferred_destroy) {
1475 compose_destroy(compose);
1482 #define INSERT_FW_HEADER(var, hdr) \
1483 if (msginfo->var && *msginfo->var) { \
1484 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1485 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1486 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1489 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1490 gboolean as_attach, const gchar *body,
1491 gboolean no_extedit,
1495 GtkTextView *textview;
1496 GtkTextBuffer *textbuf;
1499 g_return_val_if_fail(msginfo != NULL, NULL);
1500 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1503 !(account = compose_guess_forward_account_from_msginfo
1505 account = cur_account;
1507 compose = compose_create(account, COMPOSE_FORWARD, batch);
1509 compose->updating = TRUE;
1510 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1511 if (!compose->fwdinfo)
1512 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1514 compose_extract_original_charset(compose);
1516 if (msginfo->subject && *msginfo->subject) {
1517 gchar *buf, *buf2, *p;
1519 buf = p = g_strdup(msginfo->subject);
1520 p += subject_get_prefix_length(p);
1521 memmove(buf, p, strlen(p) + 1);
1523 buf2 = g_strdup_printf("Fw: %s", buf);
1524 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1530 textview = GTK_TEXT_VIEW(compose->text);
1531 textbuf = gtk_text_view_get_buffer(textview);
1532 compose_create_tags(textview, compose);
1534 undo_block(compose->undostruct);
1538 msgfile = procmsg_get_message_file_path(msginfo);
1539 if (!is_file_exist(msgfile))
1540 g_warning("%s: file not exist\n", msgfile);
1542 compose_attach_append(compose, msgfile, msgfile,
1548 MsgInfo *full_msginfo;
1550 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1552 full_msginfo = procmsg_msginfo_copy(msginfo);
1554 if (prefs_common.fw_quotemark &&
1555 *prefs_common.fw_quotemark)
1556 qmark = prefs_common.fw_quotemark;
1560 compose_quote_fmt(compose, full_msginfo,
1561 prefs_common.fw_quotefmt,
1562 qmark, body, FALSE, TRUE,
1563 _("Message forward format error at line %d."));
1564 quote_fmt_reset_vartable();
1565 compose_attach_parts(compose, msginfo);
1567 procmsg_msginfo_free(full_msginfo);
1570 SIGNAL_BLOCK(textbuf);
1572 if (account->auto_sig)
1573 compose_insert_sig(compose, FALSE);
1575 compose_wrap_all(compose);
1577 SIGNAL_UNBLOCK(textbuf);
1579 gtk_text_buffer_get_start_iter(textbuf, &iter);
1580 gtk_text_buffer_place_cursor(textbuf, &iter);
1582 gtk_widget_grab_focus(compose->header_last->entry);
1584 if (!no_extedit && prefs_common.auto_exteditor)
1585 compose_exec_ext_editor(compose);
1588 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1589 gchar *folderidentifier;
1591 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1592 folderidentifier = folder_item_get_identifier(msginfo->folder);
1593 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1594 g_free(folderidentifier);
1597 undo_unblock(compose->undostruct);
1599 compose->modified = FALSE;
1600 compose_set_title(compose);
1602 compose->updating = FALSE;
1604 if (compose->deferred_destroy) {
1605 compose_destroy(compose);
1612 #undef INSERT_FW_HEADER
1614 static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1617 GtkTextView *textview;
1618 GtkTextBuffer *textbuf;
1622 gboolean single_mail = TRUE;
1624 g_return_val_if_fail(msginfo_list != NULL, NULL);
1626 if (g_slist_length(msginfo_list) > 1)
1627 single_mail = FALSE;
1629 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1630 if (((MsgInfo *)msginfo->data)->folder == NULL)
1633 /* guess account from first selected message */
1635 !(account = compose_guess_forward_account_from_msginfo
1636 (msginfo_list->data)))
1637 account = cur_account;
1639 g_return_val_if_fail(account != NULL, NULL);
1641 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1642 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1643 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1646 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1648 compose->updating = TRUE;
1650 textview = GTK_TEXT_VIEW(compose->text);
1651 textbuf = gtk_text_view_get_buffer(textview);
1652 compose_create_tags(textview, compose);
1654 undo_block(compose->undostruct);
1655 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1656 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1658 if (!is_file_exist(msgfile))
1659 g_warning("%s: file not exist\n", msgfile);
1661 compose_attach_append(compose, msgfile, msgfile,
1667 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1668 if (info->subject && *info->subject) {
1669 gchar *buf, *buf2, *p;
1671 buf = p = g_strdup(info->subject);
1672 p += subject_get_prefix_length(p);
1673 memmove(buf, p, strlen(p) + 1);
1675 buf2 = g_strdup_printf("Fw: %s", buf);
1676 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1682 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1683 _("Fw: multiple emails"));
1686 SIGNAL_BLOCK(textbuf);
1688 if (account->auto_sig)
1689 compose_insert_sig(compose, FALSE);
1691 compose_wrap_all(compose);
1693 SIGNAL_UNBLOCK(textbuf);
1695 gtk_text_buffer_get_start_iter(textbuf, &iter);
1696 gtk_text_buffer_place_cursor(textbuf, &iter);
1698 gtk_widget_grab_focus(compose->header_last->entry);
1699 undo_unblock(compose->undostruct);
1700 compose->modified = FALSE;
1701 compose_set_title(compose);
1703 compose->updating = FALSE;
1705 if (compose->deferred_destroy) {
1706 compose_destroy(compose);
1713 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1715 GtkTextIter start = *iter;
1716 GtkTextIter end_iter;
1717 int start_pos = gtk_text_iter_get_offset(&start);
1719 if (!compose->account->sig_sep)
1722 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1723 start_pos+strlen(compose->account->sig_sep));
1725 /* check sig separator */
1726 str = gtk_text_iter_get_text(&start, &end_iter);
1727 if (!strcmp(str, compose->account->sig_sep)) {
1729 /* check end of line (\n) */
1730 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1731 start_pos+strlen(compose->account->sig_sep));
1732 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1733 start_pos+strlen(compose->account->sig_sep)+1);
1734 tmp = gtk_text_iter_get_text(&start, &end_iter);
1735 if (!strcmp(tmp,"\n")) {
1747 static void compose_colorize_signature(Compose *compose)
1749 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1751 GtkTextIter end_iter;
1752 gtk_text_buffer_get_start_iter(buffer, &iter);
1753 while (gtk_text_iter_forward_line(&iter))
1754 if (compose_is_sig_separator(compose, buffer, &iter)) {
1755 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1756 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1760 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1762 Compose *compose = NULL;
1763 PrefsAccount *account = NULL;
1764 GtkTextView *textview;
1765 GtkTextBuffer *textbuf;
1769 gchar buf[BUFFSIZE];
1770 gboolean use_signing = FALSE;
1771 gboolean use_encryption = FALSE;
1772 gchar *privacy_system = NULL;
1773 int priority = PRIORITY_NORMAL;
1774 MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
1776 g_return_val_if_fail(msginfo != NULL, NULL);
1777 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1779 if (compose_put_existing_to_front(msginfo)) {
1783 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1784 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1785 gchar queueheader_buf[BUFFSIZE];
1788 /* Select Account from queue headers */
1789 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1790 sizeof(queueheader_buf), "X-Claws-Account-Id:")) {
1791 id = atoi(&queueheader_buf[strlen("X-Claws-Account-Id:")]);
1792 account = account_find_from_id(id);
1794 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1795 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1796 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1797 account = account_find_from_id(id);
1799 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1800 sizeof(queueheader_buf), "NAID:")) {
1801 id = atoi(&queueheader_buf[strlen("NAID:")]);
1802 account = account_find_from_id(id);
1804 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1805 sizeof(queueheader_buf), "MAID:")) {
1806 id = atoi(&queueheader_buf[strlen("MAID:")]);
1807 account = account_find_from_id(id);
1809 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1810 sizeof(queueheader_buf), "S:")) {
1811 account = account_find_from_address(queueheader_buf);
1813 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1814 sizeof(queueheader_buf), "X-Claws-Sign:")) {
1815 param = atoi(&queueheader_buf[strlen("X-Claws-Sign:")]);
1816 use_signing = param;
1819 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1820 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1821 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1822 use_signing = param;
1825 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1826 sizeof(queueheader_buf), "X-Claws-Encrypt:")) {
1827 param = atoi(&queueheader_buf[strlen("X-Claws-Encrypt:")]);
1828 use_encryption = param;
1830 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1831 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1832 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1833 use_encryption = param;
1835 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1836 sizeof(queueheader_buf), "X-Claws-Privacy-System:")) {
1837 privacy_system = g_strdup(&queueheader_buf[strlen("X-Claws-Privacy-System:")]);
1839 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1840 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1841 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1843 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1844 sizeof(queueheader_buf), "X-Priority: ")) {
1845 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1848 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1849 sizeof(queueheader_buf), "RMID:")) {
1850 gchar **tokens = g_strsplit(&queueheader_buf[strlen("RMID:")], "\t", 0);
1851 if (tokens[0] && tokens[1] && tokens[2]) {
1852 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1853 if (orig_item != NULL) {
1854 replyinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1859 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1860 sizeof(queueheader_buf), "FMID:")) {
1861 gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0);
1862 if (tokens[0] && tokens[1] && tokens[2]) {
1863 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1864 if (orig_item != NULL) {
1865 fwdinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1871 account = msginfo->folder->folder->account;
1874 if (!account && prefs_common.reedit_account_autosel) {
1875 gchar from[BUFFSIZE];
1876 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1877 extract_address(from);
1878 account = account_find_from_address(from);
1882 account = cur_account;
1884 g_return_val_if_fail(account != NULL, NULL);
1886 compose = compose_create(account, COMPOSE_REEDIT, batch);
1888 compose->replyinfo = replyinfo;
1889 compose->fwdinfo = fwdinfo;
1891 compose->updating = TRUE;
1892 compose->priority = priority;
1894 if (privacy_system != NULL) {
1895 compose->privacy_system = privacy_system;
1896 compose_use_signing(compose, use_signing);
1897 compose_use_encryption(compose, use_encryption);
1898 compose_update_privacy_system_menu_item(compose, FALSE);
1900 activate_privacy_system(compose, account, FALSE);
1903 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1905 compose_extract_original_charset(compose);
1907 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1908 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1909 gchar queueheader_buf[BUFFSIZE];
1911 /* Set message save folder */
1912 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1915 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1916 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1917 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1919 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1920 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1922 GtkItemFactory *ifactory;
1923 ifactory = gtk_item_factory_from_widget(compose->menubar);
1924 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1929 if (compose_parse_header(compose, msginfo) < 0) {
1930 compose->updating = FALSE;
1931 compose_destroy(compose);
1934 compose_reedit_set_entry(compose, msginfo);
1936 textview = GTK_TEXT_VIEW(compose->text);
1937 textbuf = gtk_text_view_get_buffer(textview);
1938 compose_create_tags(textview, compose);
1940 mark = gtk_text_buffer_get_insert(textbuf);
1941 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1943 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1944 G_CALLBACK(compose_changed_cb),
1947 if (procmime_msginfo_is_encrypted(msginfo)) {
1948 fp = procmime_get_first_encrypted_text_content(msginfo);
1950 compose_force_encryption(compose, account, TRUE);
1953 fp = procmime_get_first_text_content(msginfo);
1956 g_warning("Can't get text part\n");
1960 gboolean prev_autowrap = compose->autowrap;
1962 compose->autowrap = FALSE;
1963 while (fgets(buf, sizeof(buf), fp) != NULL) {
1965 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1967 compose_wrap_all_full(compose, FALSE);
1968 compose->autowrap = prev_autowrap;
1972 compose_attach_parts(compose, msginfo);
1974 compose_colorize_signature(compose);
1976 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1977 G_CALLBACK(compose_changed_cb),
1980 gtk_widget_grab_focus(compose->text);
1982 if (prefs_common.auto_exteditor) {
1983 compose_exec_ext_editor(compose);
1985 compose->modified = FALSE;
1986 compose_set_title(compose);
1988 compose->updating = FALSE;
1990 if (compose->deferred_destroy) {
1991 compose_destroy(compose);
1995 compose->sig_str = compose_get_signature_str(compose);
2000 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
2005 GtkItemFactory *ifactory;
2008 g_return_val_if_fail(msginfo != NULL, NULL);
2011 account = account_get_reply_account(msginfo,
2012 prefs_common.reply_account_autosel);
2013 g_return_val_if_fail(account != NULL, NULL);
2015 compose = compose_create(account, COMPOSE_REDIRECT, batch);
2017 compose->updating = TRUE;
2019 ifactory = gtk_item_factory_from_widget(compose->menubar);
2020 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
2021 compose->replyinfo = NULL;
2022 compose->fwdinfo = NULL;
2024 compose_show_first_last_header(compose, TRUE);
2026 gtk_widget_grab_focus(compose->header_last->entry);
2028 filename = procmsg_get_message_file_path(msginfo);
2030 if (filename == NULL) {
2031 compose->updating = FALSE;
2032 compose_destroy(compose);
2037 compose->redirect_filename = filename;
2039 /* Set save folder */
2040 item = msginfo->folder;
2041 if (item && item->prefs && item->prefs->save_copy_to_folder) {
2042 gchar *folderidentifier;
2044 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
2045 folderidentifier = folder_item_get_identifier(item);
2046 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
2047 g_free(folderidentifier);
2050 compose_attach_parts(compose, msginfo);
2052 if (msginfo->subject)
2053 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
2055 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
2057 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE, FALSE,
2058 _("Message redirect format error at line %d."));
2059 quote_fmt_reset_vartable();
2060 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
2062 compose_colorize_signature(compose);
2064 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
2065 menu_set_sensitive(ifactory, "/Add...", FALSE);
2066 menu_set_sensitive(ifactory, "/Remove", FALSE);
2067 menu_set_sensitive(ifactory, "/Properties...", FALSE);
2069 ifactory = gtk_item_factory_from_widget(compose->menubar);
2070 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
2071 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
2072 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
2073 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
2074 menu_set_sensitive(ifactory, "/Edit", FALSE);
2075 menu_set_sensitive(ifactory, "/Options", FALSE);
2076 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
2077 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
2079 if (compose->toolbar->draft_btn)
2080 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
2081 if (compose->toolbar->insert_btn)
2082 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
2083 if (compose->toolbar->attach_btn)
2084 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
2085 if (compose->toolbar->sig_btn)
2086 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
2087 if (compose->toolbar->exteditor_btn)
2088 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
2089 if (compose->toolbar->linewrap_current_btn)
2090 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
2091 if (compose->toolbar->linewrap_all_btn)
2092 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
2094 compose->modified = FALSE;
2095 compose_set_title(compose);
2096 compose->updating = FALSE;
2098 if (compose->deferred_destroy) {
2099 compose_destroy(compose);
2106 GList *compose_get_compose_list(void)
2108 return compose_list;
2111 void compose_entry_append(Compose *compose, const gchar *address,
2112 ComposeEntryType type)
2114 const gchar *header;
2116 gboolean in_quote = FALSE;
2117 if (!address || *address == '\0') return;
2124 header = N_("Bcc:");
2126 case COMPOSE_REPLYTO:
2127 header = N_("Reply-To:");
2129 case COMPOSE_NEWSGROUPS:
2130 header = N_("Newsgroups:");
2132 case COMPOSE_FOLLOWUPTO:
2133 header = N_( "Followup-To:");
2140 header = prefs_common_translated_header_name(header);
2142 cur = begin = (gchar *)address;
2144 /* we separate the line by commas, but not if we're inside a quoted
2146 while (*cur != '\0') {
2148 in_quote = !in_quote;
2149 if (*cur == ',' && !in_quote) {
2150 gchar *tmp = g_strdup(begin);
2152 tmp[cur-begin]='\0';
2155 while (*tmp == ' ' || *tmp == '\t')
2157 compose_add_header_entry(compose, header, tmp);
2164 gchar *tmp = g_strdup(begin);
2166 tmp[cur-begin]='\0';
2169 while (*tmp == ' ' || *tmp == '\t')
2171 compose_add_header_entry(compose, header, tmp);
2176 static void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
2178 static GdkColor yellow;
2179 static GdkColor black;
2180 static gboolean yellow_initialised = FALSE;
2184 if (!yellow_initialised) {
2185 gdk_color_parse("#f5f6be", &yellow);
2186 gdk_color_parse("#000000", &black);
2187 yellow_initialised = gdk_colormap_alloc_color(
2188 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2189 yellow_initialised &= gdk_colormap_alloc_color(
2190 gdk_colormap_get_system(), &black, FALSE, TRUE);
2193 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2194 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2195 if (gtk_entry_get_text(entry) &&
2196 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2197 if (yellow_initialised) {
2198 gtk_widget_modify_base(
2199 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2200 GTK_STATE_NORMAL, &yellow);
2201 gtk_widget_modify_text(
2202 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2203 GTK_STATE_NORMAL, &black);
2209 void compose_toolbar_cb(gint action, gpointer data)
2211 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2212 Compose *compose = (Compose*)toolbar_item->parent;
2214 g_return_if_fail(compose != NULL);
2218 compose_send_cb(compose, 0, NULL);
2221 compose_send_later_cb(compose, 0, NULL);
2224 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2227 compose_insert_file_cb(compose, 0, NULL);
2230 compose_attach_cb(compose, 0, NULL);
2233 compose_insert_sig(compose, FALSE);
2236 compose_ext_editor_cb(compose, 0, NULL);
2238 case A_LINEWRAP_CURRENT:
2239 compose_beautify_paragraph(compose, NULL, TRUE);
2241 case A_LINEWRAP_ALL:
2242 compose_wrap_all_full(compose, TRUE);
2245 compose_address_cb(compose, 0, NULL);
2248 case A_CHECK_SPELLING:
2249 compose_check_all(compose);
2257 static void compose_entries_set(Compose *compose, const gchar *mailto)
2261 gchar *subject = NULL;
2265 gchar *attach = NULL;
2267 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body, &attach);
2270 compose_entry_append(compose, to, COMPOSE_TO);
2272 compose_entry_append(compose, cc, COMPOSE_CC);
2274 if (!g_utf8_validate (subject, -1, NULL)) {
2275 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2276 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2279 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2283 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2284 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2287 gboolean prev_autowrap = compose->autowrap;
2289 compose->autowrap = FALSE;
2291 mark = gtk_text_buffer_get_insert(buffer);
2292 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2294 if (!g_utf8_validate (body, -1, NULL)) {
2295 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2296 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2299 gtk_text_buffer_insert(buffer, &iter, body, -1);
2301 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2303 compose->autowrap = prev_autowrap;
2304 if (compose->autowrap)
2305 compose_wrap_all(compose);
2309 gchar *utf8_filename = conv_filename_to_utf8(attach);
2310 if (utf8_filename) {
2311 if (compose_attach_append(compose, attach, utf8_filename, NULL)) {
2312 alertpanel_notice(_("The file '%s' has been attached."), attach);
2314 g_free(utf8_filename);
2316 alertpanel_error(_("Couldn't attach a file (charset conversion failed)."));
2326 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2328 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2329 {"Cc:", NULL, TRUE},
2330 {"References:", NULL, FALSE},
2331 {"Bcc:", NULL, TRUE},
2332 {"Newsgroups:", NULL, TRUE},
2333 {"Followup-To:", NULL, TRUE},
2334 {"List-Post:", NULL, FALSE},
2335 {"X-Priority:", NULL, FALSE},
2336 {NULL, NULL, FALSE}};
2352 g_return_val_if_fail(msginfo != NULL, -1);
2354 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2355 procheader_get_header_fields(fp, hentry);
2358 if (hentry[H_REPLY_TO].body != NULL) {
2359 if (hentry[H_REPLY_TO].body[0] != '\0') {
2361 conv_unmime_header(hentry[H_REPLY_TO].body,
2364 g_free(hentry[H_REPLY_TO].body);
2365 hentry[H_REPLY_TO].body = NULL;
2367 if (hentry[H_CC].body != NULL) {
2368 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2369 g_free(hentry[H_CC].body);
2370 hentry[H_CC].body = NULL;
2372 if (hentry[H_REFERENCES].body != NULL) {
2373 if (compose->mode == COMPOSE_REEDIT)
2374 compose->references = hentry[H_REFERENCES].body;
2376 compose->references = compose_parse_references
2377 (hentry[H_REFERENCES].body, msginfo->msgid);
2378 g_free(hentry[H_REFERENCES].body);
2380 hentry[H_REFERENCES].body = NULL;
2382 if (hentry[H_BCC].body != NULL) {
2383 if (compose->mode == COMPOSE_REEDIT)
2385 conv_unmime_header(hentry[H_BCC].body, NULL);
2386 g_free(hentry[H_BCC].body);
2387 hentry[H_BCC].body = NULL;
2389 if (hentry[H_NEWSGROUPS].body != NULL) {
2390 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2391 hentry[H_NEWSGROUPS].body = NULL;
2393 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2394 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2395 compose->followup_to =
2396 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2399 g_free(hentry[H_FOLLOWUP_TO].body);
2400 hentry[H_FOLLOWUP_TO].body = NULL;
2402 if (hentry[H_LIST_POST].body != NULL) {
2405 extract_address(hentry[H_LIST_POST].body);
2406 if (hentry[H_LIST_POST].body[0] != '\0') {
2407 scan_mailto_url(hentry[H_LIST_POST].body,
2408 &to, NULL, NULL, NULL, NULL, NULL);
2410 g_free(compose->ml_post);
2411 compose->ml_post = to;
2414 g_free(hentry[H_LIST_POST].body);
2415 hentry[H_LIST_POST].body = NULL;
2418 /* CLAWS - X-Priority */
2419 if (compose->mode == COMPOSE_REEDIT)
2420 if (hentry[H_X_PRIORITY].body != NULL) {
2423 priority = atoi(hentry[H_X_PRIORITY].body);
2424 g_free(hentry[H_X_PRIORITY].body);
2426 hentry[H_X_PRIORITY].body = NULL;
2428 if (priority < PRIORITY_HIGHEST ||
2429 priority > PRIORITY_LOWEST)
2430 priority = PRIORITY_NORMAL;
2432 compose->priority = priority;
2435 if (compose->mode == COMPOSE_REEDIT) {
2436 if (msginfo->inreplyto && *msginfo->inreplyto)
2437 compose->inreplyto = g_strdup(msginfo->inreplyto);
2441 if (msginfo->msgid && *msginfo->msgid)
2442 compose->inreplyto = g_strdup(msginfo->msgid);
2444 if (!compose->references) {
2445 if (msginfo->msgid && *msginfo->msgid) {
2446 if (msginfo->inreplyto && *msginfo->inreplyto)
2447 compose->references =
2448 g_strdup_printf("<%s>\n\t<%s>",
2452 compose->references =
2453 g_strconcat("<", msginfo->msgid, ">",
2455 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2456 compose->references =
2457 g_strconcat("<", msginfo->inreplyto, ">",
2465 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2467 GSList *ref_id_list, *cur;
2471 ref_id_list = references_list_append(NULL, ref);
2472 if (!ref_id_list) return NULL;
2473 if (msgid && *msgid)
2474 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2479 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2480 /* "<" + Message-ID + ">" + CR+LF+TAB */
2481 len += strlen((gchar *)cur->data) + 5;
2483 if (len > MAX_REFERENCES_LEN) {
2484 /* remove second message-ID */
2485 if (ref_id_list && ref_id_list->next &&
2486 ref_id_list->next->next) {
2487 g_free(ref_id_list->next->data);
2488 ref_id_list = g_slist_remove
2489 (ref_id_list, ref_id_list->next->data);
2491 slist_free_strings(ref_id_list);
2492 g_slist_free(ref_id_list);
2499 new_ref = g_string_new("");
2500 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2501 if (new_ref->len > 0)
2502 g_string_append(new_ref, "\n\t");
2503 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2506 slist_free_strings(ref_id_list);
2507 g_slist_free(ref_id_list);
2509 new_ref_str = new_ref->str;
2510 g_string_free(new_ref, FALSE);
2515 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2516 const gchar *fmt, const gchar *qmark,
2517 const gchar *body, gboolean rewrap,
2518 gboolean need_unescape,
2519 const gchar *err_msg)
2521 MsgInfo* dummyinfo = NULL;
2522 gchar *quote_str = NULL;
2524 gboolean prev_autowrap;
2525 const gchar *trimmed_body = body;
2526 gint cursor_pos = -1;
2527 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2528 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2533 SIGNAL_BLOCK(buffer);
2536 dummyinfo = compose_msginfo_new_from_compose(compose);
2537 msginfo = dummyinfo;
2540 if (qmark != NULL) {
2542 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
2543 compose->gtkaspell);
2545 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
2547 quote_fmt_scan_string(qmark);
2550 buf = quote_fmt_get_buffer();
2552 alertpanel_error(_("Quote mark format error."));
2554 Xstrdup_a(quote_str, buf, goto error)
2557 if (fmt && *fmt != '\0') {
2560 while (*trimmed_body == '\n')
2564 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account,
2565 compose->gtkaspell);
2567 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account);
2569 if (need_unescape) {
2572 /* decode \-escape sequences in the internal representation of the quote format */
2573 tmp = malloc(strlen(fmt)+1);
2574 pref_get_unescaped_pref(tmp, fmt);
2575 quote_fmt_scan_string(tmp);
2579 quote_fmt_scan_string(fmt);
2583 buf = quote_fmt_get_buffer();
2585 gint line = quote_fmt_get_line();
2586 gchar *msg = g_strdup_printf(err_msg, line);
2587 alertpanel_error(msg);
2594 prev_autowrap = compose->autowrap;
2595 compose->autowrap = FALSE;
2597 mark = gtk_text_buffer_get_insert(buffer);
2598 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2599 if (g_utf8_validate(buf, -1, NULL)) {
2600 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2602 gchar *tmpout = NULL;
2603 tmpout = conv_codeset_strdup
2604 (buf, conv_get_locale_charset_str_no_utf8(),
2606 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2608 tmpout = g_malloc(strlen(buf)*2+1);
2609 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2611 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2615 cursor_pos = quote_fmt_get_cursor_pos();
2616 compose->set_cursor_pos = cursor_pos;
2617 if (cursor_pos == -1) {
2620 gtk_text_buffer_get_start_iter(buffer, &iter);
2621 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2622 gtk_text_buffer_place_cursor(buffer, &iter);
2624 compose->autowrap = prev_autowrap;
2625 if (compose->autowrap && rewrap)
2626 compose_wrap_all(compose);
2633 SIGNAL_UNBLOCK(buffer);
2635 procmsg_msginfo_free( dummyinfo );
2640 /* if ml_post is of type addr@host and from is of type
2641 * addr-anything@host, return TRUE
2643 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2645 gchar *left_ml = NULL;
2646 gchar *right_ml = NULL;
2647 gchar *left_from = NULL;
2648 gchar *right_from = NULL;
2649 gboolean result = FALSE;
2651 if (!ml_post || !from)
2654 left_ml = g_strdup(ml_post);
2655 if (strstr(left_ml, "@")) {
2656 right_ml = strstr(left_ml, "@")+1;
2657 *(strstr(left_ml, "@")) = '\0';
2660 left_from = g_strdup(from);
2661 if (strstr(left_from, "@")) {
2662 right_from = strstr(left_from, "@")+1;
2663 *(strstr(left_from, "@")) = '\0';
2666 if (left_ml && left_from && right_ml && right_from
2667 && !strncmp(left_from, left_ml, strlen(left_ml))
2668 && !strcmp(right_from, right_ml)) {
2677 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2679 gchar *my_addr1, *my_addr2;
2681 if (!addr1 || !addr2)
2684 Xstrdup_a(my_addr1, addr1, return FALSE);
2685 Xstrdup_a(my_addr2, addr2, return FALSE);
2687 extract_address(my_addr1);
2688 extract_address(my_addr2);
2690 return !strcasecmp(my_addr1, my_addr2);
2693 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2694 gboolean to_all, gboolean to_ml,
2696 gboolean followup_and_reply_to)
2698 GSList *cc_list = NULL;
2701 gchar *replyto = NULL;
2702 GHashTable *to_table;
2704 gboolean reply_to_ml = FALSE;
2705 gboolean default_reply_to = FALSE;
2707 g_return_if_fail(compose->account != NULL);
2708 g_return_if_fail(msginfo != NULL);
2710 reply_to_ml = to_ml && compose->ml_post;
2712 default_reply_to = msginfo->folder &&
2713 msginfo->folder->prefs->enable_default_reply_to;
2715 if (compose->account->protocol != A_NNTP) {
2716 if (reply_to_ml && !default_reply_to) {
2718 gboolean is_subscr = is_subscription(compose->ml_post,
2721 /* normal answer to ml post with a reply-to */
2722 compose_entry_append(compose,
2725 if (compose->replyto
2726 && !same_address(compose->ml_post, compose->replyto))
2727 compose_entry_append(compose,
2731 /* answer to subscription confirmation */
2732 if (compose->replyto)
2733 compose_entry_append(compose,
2736 else if (msginfo->from)
2737 compose_entry_append(compose,
2742 else if (!(to_all || to_sender) && default_reply_to) {
2743 compose_entry_append(compose,
2744 msginfo->folder->prefs->default_reply_to,
2746 compose_entry_mark_default_to(compose,
2747 msginfo->folder->prefs->default_reply_to);
2752 Xstrdup_a(tmp1, msginfo->from, return);
2753 extract_address(tmp1);
2754 if (to_all || to_sender ||
2755 !account_find_from_address(tmp1))
2756 compose_entry_append(compose,
2757 (compose->replyto && !to_sender)
2758 ? compose->replyto :
2759 msginfo->from ? msginfo->from : "",
2761 else if (!to_all && !to_sender) {
2762 if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
2763 !folder_has_parent_of_type(msginfo->folder, F_OUTBOX) &&
2764 !folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
2765 compose_entry_append(compose,
2766 msginfo->from ? msginfo->from : "",
2769 /* replying to own mail, use original recp */
2770 compose_entry_append(compose,
2771 msginfo->to ? msginfo->to : "",
2773 compose_entry_append(compose,
2774 msginfo->cc ? msginfo->cc : "",
2780 if (to_sender || (compose->followup_to &&
2781 !strncmp(compose->followup_to, "poster", 6)))
2782 compose_entry_append
2784 (compose->replyto ? compose->replyto :
2785 msginfo->from ? msginfo->from : ""),
2788 else if (followup_and_reply_to || to_all) {
2789 compose_entry_append
2791 (compose->replyto ? compose->replyto :
2792 msginfo->from ? msginfo->from : ""),
2795 compose_entry_append
2797 compose->followup_to ? compose->followup_to :
2798 compose->newsgroups ? compose->newsgroups : "",
2799 COMPOSE_NEWSGROUPS);
2802 compose_entry_append
2804 compose->followup_to ? compose->followup_to :
2805 compose->newsgroups ? compose->newsgroups : "",
2806 COMPOSE_NEWSGROUPS);
2809 if (msginfo->subject && *msginfo->subject) {
2813 buf = p = g_strdup(msginfo->subject);
2814 p += subject_get_prefix_length(p);
2815 memmove(buf, p, strlen(p) + 1);
2817 buf2 = g_strdup_printf("Re: %s", buf);
2818 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2823 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2825 if (to_ml && compose->ml_post) return;
2826 if (!to_all || compose->account->protocol == A_NNTP) return;
2828 if (compose->replyto) {
2829 Xstrdup_a(replyto, compose->replyto, return);
2830 extract_address(replyto);
2832 if (msginfo->from) {
2833 Xstrdup_a(from, msginfo->from, return);
2834 extract_address(from);
2837 if (replyto && from)
2838 cc_list = address_list_append_with_comments(cc_list, from);
2839 if (to_all && msginfo->folder &&
2840 msginfo->folder->prefs->enable_default_reply_to)
2841 cc_list = address_list_append_with_comments(cc_list,
2842 msginfo->folder->prefs->default_reply_to);
2843 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2844 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2846 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2848 g_hash_table_insert(to_table, g_utf8_strdown(replyto, -1), GINT_TO_POINTER(1));
2849 if (compose->account) {
2850 g_hash_table_insert(to_table, g_utf8_strdown(compose->account->address, -1),
2851 GINT_TO_POINTER(1));
2853 /* remove address on To: and that of current account */
2854 for (cur = cc_list; cur != NULL; ) {
2855 GSList *next = cur->next;
2858 addr = g_utf8_strdown(cur->data, -1);
2859 extract_address(addr);
2861 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2862 cc_list = g_slist_remove(cc_list, cur->data);
2864 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2868 hash_free_strings(to_table);
2869 g_hash_table_destroy(to_table);
2872 for (cur = cc_list; cur != NULL; cur = cur->next)
2873 compose_entry_append(compose, (gchar *)cur->data,
2875 slist_free_strings(cc_list);
2876 g_slist_free(cc_list);
2881 #define SET_ENTRY(entry, str) \
2884 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2887 #define SET_ADDRESS(type, str) \
2890 compose_entry_append(compose, str, type); \
2893 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2895 g_return_if_fail(msginfo != NULL);
2897 SET_ENTRY(subject_entry, msginfo->subject);
2898 SET_ENTRY(from_name, msginfo->from);
2899 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2900 SET_ADDRESS(COMPOSE_CC, compose->cc);
2901 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2902 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2903 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2904 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2906 compose_update_priority_menu_item(compose);
2907 compose_update_privacy_system_menu_item(compose, FALSE);
2908 compose_show_first_last_header(compose, TRUE);
2914 static void compose_insert_sig(Compose *compose, gboolean replace)
2916 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2917 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2919 GtkTextIter iter, iter_end;
2921 gchar *search = NULL;
2922 gboolean prev_autowrap;
2923 gboolean found = FALSE, shift = FALSE;
2926 g_return_if_fail(compose->account != NULL);
2928 prev_autowrap = compose->autowrap;
2929 compose->autowrap = FALSE;
2931 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2932 G_CALLBACK(compose_changed_cb),
2935 mark = gtk_text_buffer_get_insert(buffer);
2936 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2937 cur_pos = gtk_text_iter_get_offset (&iter);
2939 gtk_text_buffer_get_end_iter(buffer, &iter);
2941 search = compose->sig_str;
2943 if (replace && search) {
2944 GtkTextIter first_iter, start_iter, end_iter;
2946 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2948 if (compose->sig_str[0] == '\0')
2951 found = gtk_text_iter_forward_search(&first_iter,
2953 GTK_TEXT_SEARCH_TEXT_ONLY,
2954 &start_iter, &end_iter,
2958 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2962 if (replace && !found && search && strlen(search) > 2
2963 && search[0] == '\n' && search[1] == '\n') {
2969 g_free(compose->sig_str);
2970 compose->sig_str = compose_get_signature_str(compose);
2971 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2972 compose->sig_str = g_strdup("");
2974 cur_pos = gtk_text_iter_get_offset(&iter);
2976 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2978 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2980 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2981 gtk_text_iter_forward_char(&iter);
2982 gtk_text_iter_forward_char(&iter);
2983 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2984 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2986 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2987 cur_pos = gtk_text_buffer_get_char_count (buffer);
2989 /* put the cursor where it should be
2990 * either where the quote_fmt says, either before the signature */
2991 if (compose->set_cursor_pos < 0)
2992 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2994 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2995 compose->set_cursor_pos);
2997 gtk_text_buffer_place_cursor(buffer, &iter);
2998 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2999 G_CALLBACK(compose_changed_cb),
3002 compose->autowrap = prev_autowrap;
3003 if (compose->autowrap)
3004 compose_wrap_all(compose);
3007 static gchar *compose_get_signature_str(Compose *compose)
3009 gchar *sig_body = NULL;
3010 gchar *sig_str = NULL;
3011 gchar *utf8_sig_str = NULL;
3013 g_return_val_if_fail(compose->account != NULL, NULL);
3015 if (!compose->account->sig_path)
3018 if (compose->account->sig_type == SIG_FILE) {
3019 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
3020 g_warning("can't open signature file: %s\n",
3021 compose->account->sig_path);
3026 if (compose->account->sig_type == SIG_COMMAND)
3027 sig_body = get_command_output(compose->account->sig_path);
3031 tmp = file_read_to_str(compose->account->sig_path);
3034 sig_body = normalize_newlines(tmp);
3038 if (compose->account->sig_sep) {
3039 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
3043 sig_str = g_strconcat("\n\n", sig_body, NULL);
3046 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
3047 utf8_sig_str = sig_str;
3049 utf8_sig_str = conv_codeset_strdup
3050 (sig_str, conv_get_locale_charset_str_no_utf8(),
3056 return utf8_sig_str;
3059 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
3062 GtkTextBuffer *buffer;
3065 const gchar *cur_encoding;
3066 gchar buf[BUFFSIZE];
3069 gboolean prev_autowrap;
3070 gboolean badtxt = FALSE;
3072 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
3074 if ((fp = g_fopen(file, "rb")) == NULL) {
3075 FILE_OP_ERROR(file, "fopen");
3076 return COMPOSE_INSERT_READ_ERROR;
3079 prev_autowrap = compose->autowrap;
3080 compose->autowrap = FALSE;
3082 text = GTK_TEXT_VIEW(compose->text);
3083 buffer = gtk_text_view_get_buffer(text);
3084 mark = gtk_text_buffer_get_insert(buffer);
3085 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3087 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3088 G_CALLBACK(text_inserted),
3091 cur_encoding = conv_get_locale_charset_str_no_utf8();
3093 while (fgets(buf, sizeof(buf), fp) != NULL) {
3096 if (g_utf8_validate(buf, -1, NULL) == TRUE)
3097 str = g_strdup(buf);
3099 str = conv_codeset_strdup
3100 (buf, cur_encoding, CS_INTERNAL);
3103 /* strip <CR> if DOS/Windows file,
3104 replace <CR> with <LF> if Macintosh file. */
3107 if (len > 0 && str[len - 1] != '\n') {
3109 if (str[len] == '\r') str[len] = '\n';
3112 gtk_text_buffer_insert(buffer, &iter, str, -1);
3116 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3117 G_CALLBACK(text_inserted),
3119 compose->autowrap = prev_autowrap;
3120 if (compose->autowrap)
3121 compose_wrap_all(compose);
3126 return COMPOSE_INSERT_INVALID_CHARACTER;
3128 return COMPOSE_INSERT_SUCCESS;
3131 static gboolean compose_attach_append(Compose *compose, const gchar *file,
3132 const gchar *filename,
3133 const gchar *content_type)
3141 GtkListStore *store;
3143 gboolean has_binary = FALSE;
3145 if (!is_file_exist(file)) {
3146 gchar *file_from_uri = g_filename_from_uri(file, NULL, NULL);
3147 gboolean result = FALSE;
3148 if (file_from_uri && is_file_exist(file_from_uri)) {
3149 result = compose_attach_append(
3150 compose, file_from_uri,
3154 g_free(file_from_uri);
3157 alertpanel_error("File %s doesn't exist\n", filename);
3160 if ((size = get_file_size(file)) < 0) {
3161 alertpanel_error("Can't get file size of %s\n", filename);
3165 alertpanel_error(_("File %s is empty."), filename);
3168 if ((fp = g_fopen(file, "rb")) == NULL) {
3169 alertpanel_error(_("Can't read %s."), filename);
3174 ainfo = g_new0(AttachInfo, 1);
3175 auto_ainfo = g_auto_pointer_new_with_free
3176 (ainfo, (GFreeFunc) compose_attach_info_free);
3177 ainfo->file = g_strdup(file);
3180 ainfo->content_type = g_strdup(content_type);
3181 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
3183 MsgFlags flags = {0, 0};
3185 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
3186 ainfo->encoding = ENC_7BIT;
3188 ainfo->encoding = ENC_8BIT;
3190 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
3191 if (msginfo && msginfo->subject)
3192 name = g_strdup(msginfo->subject);
3194 name = g_path_get_basename(filename ? filename : file);
3196 ainfo->name = g_strdup_printf(_("Message: %s"), name);
3198 procmsg_msginfo_free(msginfo);
3200 if (!g_ascii_strncasecmp(content_type, "text", 4))
3201 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
3203 ainfo->encoding = ENC_BASE64;
3204 name = g_path_get_basename(filename ? filename : file);
3205 ainfo->name = g_strdup(name);
3209 ainfo->content_type = procmime_get_mime_type(file);
3210 if (!ainfo->content_type) {
3211 ainfo->content_type =
3212 g_strdup("application/octet-stream");
3213 ainfo->encoding = ENC_BASE64;
3214 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
3216 procmime_get_encoding_for_text_file(file, &has_binary);
3218 ainfo->encoding = ENC_BASE64;
3219 name = g_path_get_basename(filename ? filename : file);
3220 ainfo->name = g_strdup(name);
3224 if (ainfo->name != NULL
3225 && !strcmp(ainfo->name, ".")) {
3226 g_free(ainfo->name);
3230 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
3231 g_free(ainfo->content_type);
3232 ainfo->content_type = g_strdup("application/octet-stream");
3236 size_text = to_human_readable(size);
3238 store = GTK_LIST_STORE(gtk_tree_view_get_model
3239 (GTK_TREE_VIEW(compose->attach_clist)));
3241 gtk_list_store_append(store, &iter);
3242 gtk_list_store_set(store, &iter,
3243 COL_MIMETYPE, ainfo->content_type,
3244 COL_SIZE, size_text,
3245 COL_NAME, ainfo->name,
3247 COL_AUTODATA, auto_ainfo,
3250 g_auto_pointer_free(auto_ainfo);
3254 static void compose_use_signing(Compose *compose, gboolean use_signing)
3256 GtkItemFactory *ifactory;
3257 GtkWidget *menuitem = NULL;
3259 compose->use_signing = use_signing;
3260 ifactory = gtk_item_factory_from_widget(compose->menubar);
3261 menuitem = gtk_item_factory_get_item
3262 (ifactory, "/Options/Sign");
3263 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3267 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3269 GtkItemFactory *ifactory;
3270 GtkWidget *menuitem = NULL;
3272 compose->use_encryption = use_encryption;
3273 ifactory = gtk_item_factory_from_widget(compose->menubar);
3274 menuitem = gtk_item_factory_get_item
3275 (ifactory, "/Options/Encrypt");
3277 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3281 #define NEXT_PART_NOT_CHILD(info) \
3283 node = info->node; \
3284 while (node->children) \
3285 node = g_node_last_child(node); \
3286 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3289 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3293 MimeInfo *firsttext = NULL;
3294 MimeInfo *encrypted = NULL;
3297 const gchar *partname = NULL;
3299 mimeinfo = procmime_scan_message(msginfo);
3300 if (!mimeinfo) return;
3302 if (mimeinfo->node->children == NULL) {
3303 procmime_mimeinfo_free_all(mimeinfo);
3307 /* find first content part */
3308 child = (MimeInfo *) mimeinfo->node->children->data;
3309 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3310 child = (MimeInfo *)child->node->children->data;
3312 if (child->type == MIMETYPE_TEXT) {
3314 debug_print("First text part found\n");
3315 } else if (compose->mode == COMPOSE_REEDIT &&
3316 child->type == MIMETYPE_APPLICATION &&
3317 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3318 encrypted = (MimeInfo *)child->node->parent->data;
3321 child = (MimeInfo *) mimeinfo->node->children->data;
3322 while (child != NULL) {
3325 if (child == encrypted) {
3326 /* skip this part of tree */
3327 NEXT_PART_NOT_CHILD(child);
3331 if (child->type == MIMETYPE_MULTIPART) {
3332 /* get the actual content */
3333 child = procmime_mimeinfo_next(child);
3337 if (child == firsttext) {
3338 child = procmime_mimeinfo_next(child);
3342 outfile = procmime_get_tmp_file_name(child);
3343 if ((err = procmime_get_part(outfile, child)) < 0)
3344 g_warning("Can't get the part of multipart message. (%s)", strerror(-err));
3346 gchar *content_type;
3348 content_type = procmime_get_content_type_str(child->type, child->subtype);
3350 /* if we meet a pgp signature, we don't attach it, but
3351 * we force signing. */
3352 if (strcmp(content_type, "application/pgp-signature") &&
3353 strcmp(content_type, "application/pkcs7-signature") &&
3354 strcmp(content_type, "application/x-pkcs7-signature")) {
3355 partname = procmime_mimeinfo_get_parameter(child, "filename");
3356 if (partname == NULL)
3357 partname = procmime_mimeinfo_get_parameter(child, "name");
3358 if (partname == NULL)
3360 compose_attach_append(compose, outfile,
3361 partname, content_type);
3363 compose_force_signing(compose, compose->account);
3365 g_free(content_type);
3368 NEXT_PART_NOT_CHILD(child);
3370 procmime_mimeinfo_free_all(mimeinfo);
3373 #undef NEXT_PART_NOT_CHILD
3378 WAIT_FOR_INDENT_CHAR,
3379 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3382 /* return indent length, we allow:
3383 indent characters followed by indent characters or spaces/tabs,
3384 alphabets and numbers immediately followed by indent characters,
3385 and the repeating sequences of the above
3386 If quote ends with multiple spaces, only the first one is included. */
3387 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3388 const GtkTextIter *start, gint *len)
3390 GtkTextIter iter = *start;
3394 IndentState state = WAIT_FOR_INDENT_CHAR;
3397 gint alnum_count = 0;
3398 gint space_count = 0;
3401 if (prefs_common.quote_chars == NULL) {
3405 while (!gtk_text_iter_ends_line(&iter)) {
3406 wc = gtk_text_iter_get_char(&iter);
3407 if (g_unichar_iswide(wc))
3409 clen = g_unichar_to_utf8(wc, ch);
3413 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3414 is_space = g_unichar_isspace(wc);
3416 if (state == WAIT_FOR_INDENT_CHAR) {
3417 if (!is_indent && !g_unichar_isalnum(wc))
3420 quote_len += alnum_count + space_count + 1;
3421 alnum_count = space_count = 0;
3422 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3425 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3426 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3430 else if (is_indent) {
3431 quote_len += alnum_count + space_count + 1;
3432 alnum_count = space_count = 0;
3435 state = WAIT_FOR_INDENT_CHAR;
3439 gtk_text_iter_forward_char(&iter);
3442 if (quote_len > 0 && space_count > 0)
3448 if (quote_len > 0) {
3450 gtk_text_iter_forward_chars(&iter, quote_len);
3451 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3457 /* return TRUE if the line is itemized */
3458 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3459 const GtkTextIter *start)
3461 GtkTextIter iter = *start;
3466 if (gtk_text_iter_ends_line(&iter))
3470 wc = gtk_text_iter_get_char(&iter);
3471 if (!g_unichar_isspace(wc))
3473 gtk_text_iter_forward_char(&iter);
3474 if (gtk_text_iter_ends_line(&iter))
3478 clen = g_unichar_to_utf8(wc, ch);
3482 if (!strchr("*-+", ch[0]))
3485 gtk_text_iter_forward_char(&iter);
3486 if (gtk_text_iter_ends_line(&iter))
3488 wc = gtk_text_iter_get_char(&iter);
3489 if (g_unichar_isspace(wc))
3495 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3496 const GtkTextIter *start,
3497 GtkTextIter *break_pos,
3501 GtkTextIter iter = *start, line_end = *start;
3502 PangoLogAttr *attrs;
3509 gboolean can_break = FALSE;
3510 gboolean do_break = FALSE;
3511 gboolean was_white = FALSE;
3512 gboolean prev_dont_break = FALSE;
3514 gtk_text_iter_forward_to_line_end(&line_end);
3515 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3516 len = g_utf8_strlen(str, -1);
3517 /* g_print("breaking line: %d: %s (len = %d)\n",
3518 gtk_text_iter_get_line(&iter), str, len); */
3519 attrs = g_new(PangoLogAttr, len + 1);
3521 pango_default_break(str, -1, NULL, attrs, len + 1);
3525 /* skip quote and leading spaces */
3526 for (i = 0; *p != '\0' && i < len; i++) {
3529 wc = g_utf8_get_char(p);
3530 if (i >= quote_len && !g_unichar_isspace(wc))
3532 if (g_unichar_iswide(wc))
3534 else if (*p == '\t')
3538 p = g_utf8_next_char(p);
3541 for (; *p != '\0' && i < len; i++) {
3542 PangoLogAttr *attr = attrs + i;
3546 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3549 was_white = attr->is_white;
3551 /* don't wrap URI */
3552 if ((uri_len = get_uri_len(p)) > 0) {
3554 if (pos > 0 && col > max_col) {
3564 wc = g_utf8_get_char(p);
3565 if (g_unichar_iswide(wc)) {
3567 if (prev_dont_break && can_break && attr->is_line_break)
3569 } else if (*p == '\t')
3573 if (pos > 0 && col > max_col) {
3578 if (*p == '-' || *p == '/')
3579 prev_dont_break = TRUE;
3581 prev_dont_break = FALSE;
3583 p = g_utf8_next_char(p);
3587 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3592 *break_pos = *start;
3593 gtk_text_iter_set_line_offset(break_pos, pos);
3598 static gboolean compose_join_next_line(Compose *compose,
3599 GtkTextBuffer *buffer,
3601 const gchar *quote_str)
3603 GtkTextIter iter_ = *iter, cur, prev, next, end;
3604 PangoLogAttr attrs[3];
3606 gchar *next_quote_str;
3609 gboolean keep_cursor = FALSE;
3611 if (!gtk_text_iter_forward_line(&iter_) ||
3612 gtk_text_iter_ends_line(&iter_))
3615 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3617 if ((quote_str || next_quote_str) &&
3618 strcmp2(quote_str, next_quote_str) != 0) {
3619 g_free(next_quote_str);
3622 g_free(next_quote_str);
3625 if (quote_len > 0) {
3626 gtk_text_iter_forward_chars(&end, quote_len);
3627 if (gtk_text_iter_ends_line(&end))
3631 /* don't join itemized lines */
3632 if (compose_is_itemized(buffer, &end))
3635 /* don't join signature separator */
3636 if (compose_is_sig_separator(compose, buffer, &iter_))
3639 /* delete quote str */
3641 gtk_text_buffer_delete(buffer, &iter_, &end);
3643 /* don't join line breaks put by the user */
3645 gtk_text_iter_backward_char(&cur);
3646 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3647 gtk_text_iter_forward_char(&cur);
3651 gtk_text_iter_forward_char(&cur);
3652 /* delete linebreak and extra spaces */
3653 while (gtk_text_iter_backward_char(&cur)) {
3654 wc1 = gtk_text_iter_get_char(&cur);
3655 if (!g_unichar_isspace(wc1))
3660 while (!gtk_text_iter_ends_line(&cur)) {
3661 wc1 = gtk_text_iter_get_char(&cur);
3662 if (!g_unichar_isspace(wc1))
3664 gtk_text_iter_forward_char(&cur);
3667 if (!gtk_text_iter_equal(&prev, &next)) {
3670 mark = gtk_text_buffer_get_insert(buffer);
3671 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3672 if (gtk_text_iter_equal(&prev, &cur))
3674 gtk_text_buffer_delete(buffer, &prev, &next);
3678 /* insert space if required */
3679 gtk_text_iter_backward_char(&prev);
3680 wc1 = gtk_text_iter_get_char(&prev);
3681 wc2 = gtk_text_iter_get_char(&next);
3682 gtk_text_iter_forward_char(&next);
3683 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3684 pango_default_break(str, -1, NULL, attrs, 3);
3685 if (!attrs[1].is_line_break ||
3686 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3687 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3689 gtk_text_iter_backward_char(&iter_);
3690 gtk_text_buffer_place_cursor(buffer, &iter_);
3699 #define ADD_TXT_POS(bp_, ep_, pti_) \
3700 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3701 last = last->next; \
3702 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3703 last->next = NULL; \
3705 g_warning("alloc error scanning URIs\n"); \
3708 static gboolean automatic_break = FALSE;
3709 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3711 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3712 GtkTextBuffer *buffer;
3713 GtkTextIter iter, break_pos, end_of_line;
3714 gchar *quote_str = NULL;
3716 gboolean wrap_quote = prefs_common.linewrap_quote;
3717 gboolean prev_autowrap = compose->autowrap;
3718 gint startq_offset = -1, noq_offset = -1;
3719 gint uri_start = -1, uri_stop = -1;
3720 gint nouri_start = -1, nouri_stop = -1;
3721 gint num_blocks = 0;
3722 gint quotelevel = -1;
3724 compose->autowrap = FALSE;
3726 buffer = gtk_text_view_get_buffer(text);
3727 undo_wrapping(compose->undostruct, TRUE);
3732 mark = gtk_text_buffer_get_insert(buffer);
3733 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3736 /* move to paragraph start */
3737 gtk_text_iter_set_line_offset(&iter, 0);
3738 if (gtk_text_iter_ends_line(&iter)) {
3739 while (gtk_text_iter_ends_line(&iter) &&
3740 gtk_text_iter_forward_line(&iter))
3743 while (gtk_text_iter_backward_line(&iter)) {