2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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"
135 #define N_ATTACH_COLS (N_COL_COLUMNS)
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
154 } ComposeCallAdvancedAction;
158 PRIORITY_HIGHEST = 1,
167 COMPOSE_INSERT_SUCCESS,
168 COMPOSE_INSERT_READ_ERROR,
169 COMPOSE_INSERT_INVALID_CHARACTER,
170 COMPOSE_INSERT_NO_FILE
171 } ComposeInsertResult;
175 COMPOSE_QUIT_EDITING,
176 COMPOSE_KEEP_EDITING,
178 } ComposeDraftAction;
182 COMPOSE_WRITE_FOR_SEND,
183 COMPOSE_WRITE_FOR_STORE
186 #define B64_LINE_SIZE 57
187 #define B64_BUFFSIZE 77
189 #define MAX_REFERENCES_LEN 999
191 static GList *compose_list = NULL;
193 Compose *compose_generic_new (PrefsAccount *account,
196 GPtrArray *attach_files,
197 GList *listAddress );
199 static Compose *compose_create (PrefsAccount *account,
203 static GtkWidget *compose_account_option_menu_create
205 static void compose_set_out_encoding (Compose *compose);
206 static void compose_set_template_menu (Compose *compose);
207 static void compose_template_apply (Compose *compose,
210 static void compose_destroy (Compose *compose);
212 static void compose_entries_set (Compose *compose,
213 const gchar *mailto);
214 static gint compose_parse_header (Compose *compose,
216 static gchar *compose_parse_references (const gchar *ref,
219 static gchar *compose_quote_fmt (Compose *compose,
226 static void compose_reply_set_entry (Compose *compose,
232 followup_and_reply_to);
233 static void compose_reedit_set_entry (Compose *compose,
236 static void compose_insert_sig (Compose *compose,
238 static gchar *compose_get_signature_str (Compose *compose);
239 static ComposeInsertResult compose_insert_file (Compose *compose,
242 static void compose_attach_append (Compose *compose,
245 const gchar *content_type);
246 static void compose_attach_parts (Compose *compose,
249 static void compose_beautify_paragraph (Compose *compose,
250 GtkTextIter *par_iter,
252 static void compose_wrap_all (Compose *compose);
253 static void compose_wrap_all_full (Compose *compose,
256 static void compose_set_title (Compose *compose);
257 static void compose_select_account (Compose *compose,
258 PrefsAccount *account,
261 static PrefsAccount *compose_current_mail_account(void);
262 /* static gint compose_send (Compose *compose); */
263 static gboolean compose_check_for_valid_recipient
265 static gboolean compose_check_entries (Compose *compose,
266 gboolean check_subject);
267 static gint compose_write_to_file (Compose *compose,
270 gboolean attach_parts);
271 static gint compose_write_body_to_file (Compose *compose,
273 static gint compose_remove_reedit_target (Compose *compose,
275 void compose_remove_draft (Compose *compose);
276 static gint compose_queue_sub (Compose *compose,
280 gboolean check_subject,
281 gboolean remove_reedit_target);
282 static void compose_add_attachments (Compose *compose,
284 static gchar *compose_get_header (Compose *compose);
286 static void compose_convert_header (Compose *compose,
291 gboolean addr_field);
293 static void compose_attach_info_free (AttachInfo *ainfo);
294 static void compose_attach_remove_selected (Compose *compose);
296 static void compose_attach_property (Compose *compose);
297 static void compose_attach_property_create (gboolean *cancelled);
298 static void attach_property_ok (GtkWidget *widget,
299 gboolean *cancelled);
300 static void attach_property_cancel (GtkWidget *widget,
301 gboolean *cancelled);
302 static gint attach_property_delete_event (GtkWidget *widget,
304 gboolean *cancelled);
305 static gboolean attach_property_key_pressed (GtkWidget *widget,
307 gboolean *cancelled);
309 static void compose_exec_ext_editor (Compose *compose);
311 static gint compose_exec_ext_editor_real (const gchar *file);
312 static gboolean compose_ext_editor_kill (Compose *compose);
313 static gboolean compose_input_cb (GIOChannel *source,
314 GIOCondition condition,
316 static void compose_set_ext_editor_sensitive (Compose *compose,
318 #endif /* G_OS_UNIX */
320 static void compose_undo_state_changed (UndoMain *undostruct,
325 static void compose_create_header_entry (Compose *compose);
326 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
327 static void compose_remove_header_entries(Compose *compose);
329 static void compose_update_priority_menu_item(Compose * compose);
331 static void compose_spell_menu_changed (void *data);
333 static void compose_add_field_list ( Compose *compose,
334 GList *listAddress );
336 /* callback functions */
338 static gboolean compose_edit_size_alloc (GtkEditable *widget,
339 GtkAllocation *allocation,
340 GtkSHRuler *shruler);
341 static void account_activated (GtkComboBox *optmenu,
343 static void attach_selected (GtkTreeView *tree_view,
344 GtkTreePath *tree_path,
345 GtkTreeViewColumn *column,
347 static gboolean attach_button_pressed (GtkWidget *widget,
348 GdkEventButton *event,
350 static gboolean attach_key_pressed (GtkWidget *widget,
354 static void compose_send_cb (gpointer data,
357 static void compose_send_later_cb (gpointer data,
361 static void compose_draft_cb (gpointer data,
365 static void compose_attach_cb (gpointer data,
368 static void compose_insert_file_cb (gpointer data,
371 static void compose_insert_sig_cb (gpointer data,
375 static void compose_close_cb (gpointer data,
379 static void compose_set_encoding_cb (gpointer data,
383 static void compose_address_cb (gpointer data,
386 static void compose_template_activate_cb(GtkWidget *widget,
389 static void compose_ext_editor_cb (gpointer data,
393 static gint compose_delete_cb (GtkWidget *widget,
397 static void compose_undo_cb (Compose *compose);
398 static void compose_redo_cb (Compose *compose);
399 static void compose_cut_cb (Compose *compose);
400 static void compose_copy_cb (Compose *compose);
401 static void compose_paste_cb (Compose *compose);
402 static void compose_paste_as_quote_cb (Compose *compose);
403 static void compose_paste_no_wrap_cb (Compose *compose);
404 static void compose_paste_wrap_cb (Compose *compose);
405 static void compose_allsel_cb (Compose *compose);
407 static void compose_advanced_action_cb (Compose *compose,
408 ComposeCallAdvancedAction action);
410 static void compose_grab_focus_cb (GtkWidget *widget,
413 static void compose_changed_cb (GtkTextBuffer *textbuf,
416 static void compose_wrap_cb (gpointer data,
419 static void compose_find_cb (gpointer data,
422 static void compose_toggle_autowrap_cb (gpointer data,
426 static void compose_toggle_ruler_cb (gpointer data,
429 static void compose_toggle_sign_cb (gpointer data,
432 static void compose_toggle_encrypt_cb (gpointer data,
435 static void compose_set_privacy_system_cb(GtkWidget *widget,
437 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
438 static void activate_privacy_system (Compose *compose,
439 PrefsAccount *account,
441 static void compose_use_signing(Compose *compose, gboolean use_signing);
442 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
443 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
445 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
447 static void compose_set_priority_cb (gpointer data,
450 static void compose_reply_change_mode (gpointer data,
454 static void compose_attach_drag_received_cb (GtkWidget *widget,
455 GdkDragContext *drag_context,
458 GtkSelectionData *data,
462 static void compose_insert_drag_received_cb (GtkWidget *widget,
463 GdkDragContext *drag_context,
466 GtkSelectionData *data,
470 static void compose_header_drag_received_cb (GtkWidget *widget,
471 GdkDragContext *drag_context,
474 GtkSelectionData *data,
479 static gboolean compose_drag_drop (GtkWidget *widget,
480 GdkDragContext *drag_context,
482 guint time, gpointer user_data);
484 static void text_inserted (GtkTextBuffer *buffer,
489 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
490 gboolean to_all, gboolean to_ml,
492 gboolean followup_and_reply_to,
495 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
496 ComposeHeaderEntry *headerentry);
497 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
499 ComposeHeaderEntry *headerentry);
501 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
503 static void compose_allow_user_actions (Compose *compose, gboolean allow);
506 static void compose_check_all (Compose *compose);
507 static void compose_highlight_all (Compose *compose);
508 static void compose_check_backwards (Compose *compose);
509 static void compose_check_forwards_go (Compose *compose);
512 static gint compose_defer_auto_save_draft (Compose *compose);
513 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
515 static GtkItemFactoryEntry compose_popup_entries[] =
517 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
518 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
519 {N_("/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
523 static GtkItemFactoryEntry compose_entries[] =
525 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
526 {N_("/_Message/_Send"), "<control>Return",
527 compose_send_cb, 0, NULL},
528 {N_("/_Message/Send _later"), "<shift><control>S",
529 compose_send_later_cb, 0, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
532 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
533 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
534 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
535 {N_("/_Message/_Save"),
536 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
537 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
538 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
540 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
542 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
543 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
544 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
545 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
546 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
547 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
548 {N_("/_Edit/Special paste/as _quotation"),
549 NULL, compose_paste_as_quote_cb, 0, NULL},
550 {N_("/_Edit/Special paste/_wrapped"),
551 NULL, compose_paste_wrap_cb, 0, NULL},
552 {N_("/_Edit/Special paste/_unwrapped"),
553 NULL, compose_paste_no_wrap_cb, 0, NULL},
554 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
555 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
556 {N_("/_Edit/A_dvanced/Move a character backward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
561 {N_("/_Edit/A_dvanced/Move a character forward"),
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
566 {N_("/_Edit/A_dvanced/Move a word backward"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
571 {N_("/_Edit/A_dvanced/Move a word forward"),
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
576 {N_("/_Edit/A_dvanced/Move to beginning of line"),
577 NULL, /* "<control>A" */
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
581 {N_("/_Edit/A_dvanced/Move to end of line"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
586 {N_("/_Edit/A_dvanced/Move to previous line"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
591 {N_("/_Edit/A_dvanced/Move to next line"),
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
596 {N_("/_Edit/A_dvanced/Delete a character backward"),
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
601 {N_("/_Edit/A_dvanced/Delete a character forward"),
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
606 {N_("/_Edit/A_dvanced/Delete a word backward"),
607 NULL, /* "<control>W" */
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
611 {N_("/_Edit/A_dvanced/Delete a word forward"),
612 NULL, /* "<alt>D", */
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
616 {N_("/_Edit/A_dvanced/Delete line"),
618 compose_advanced_action_cb,
619 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
621 {N_("/_Edit/A_dvanced/Delete entire line"),
623 compose_advanced_action_cb,
624 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
626 {N_("/_Edit/A_dvanced/Delete to end of line"),
628 compose_advanced_action_cb,
629 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
631 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
633 "<control>F", compose_find_cb, 0, NULL},
634 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_Edit/_Wrap current paragraph"),
636 "<control>L", compose_wrap_cb, 0, NULL},
637 {N_("/_Edit/Wrap all long _lines"),
638 "<control><alt>L", compose_wrap_cb, 1, NULL},
639 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
640 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_Edit/Edit with e_xternal editor"),
642 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
644 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
645 {N_("/_Spelling/_Check all or check selection"),
646 NULL, compose_check_all, 0, NULL},
647 {N_("/_Spelling/_Highlight all misspelled words"),
648 NULL, compose_highlight_all, 0, NULL},
649 {N_("/_Spelling/Check _backwards misspelled word"),
650 NULL, compose_check_backwards , 0, NULL},
651 {N_("/_Spelling/_Forward to next misspelled word"),
652 NULL, compose_check_forwards_go, 0, NULL},
653 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Spelling/Options"),
655 NULL, NULL, 0, "<Branch>"},
657 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
658 {N_("/_Options/Reply _mode"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Options/Reply _mode/_Normal"), NULL, compose_reply_change_mode, COMPOSE_REPLY, "<RadioItem>"},
660 {N_("/_Options/Reply _mode/_All"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_ALL, "/Options/Reply mode/Normal"},
661 {N_("/_Options/Reply _mode/_Sender"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_SENDER, "/Options/Reply mode/Normal"},
662 {N_("/_Options/Reply _mode/_Mailing-list"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_LIST, "/Options/Reply mode/Normal"},
663 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
664 {N_("/_Options/Privacy _System"), NULL, NULL, 0, "<Branch>"},
665 {N_("/_Options/Privacy _System/None"), NULL, NULL, 0, "<RadioItem>"},
666 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
667 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
668 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
669 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
670 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
671 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
672 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
673 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
674 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
675 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
676 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
677 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
678 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
679 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
681 #define ENC_ACTION(action) \
682 NULL, compose_set_encoding_cb, action, \
683 "/Options/Character encoding/Automatic"
685 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
686 {N_("/_Options/Character _encoding/_Automatic"),
687 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
688 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
690 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
691 ENC_ACTION(C_US_ASCII)},
692 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
693 ENC_ACTION(C_UTF_8)},
694 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
696 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
697 ENC_ACTION(C_ISO_8859_1)},
698 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
699 ENC_ACTION(C_ISO_8859_15)},
700 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
701 ENC_ACTION(C_WINDOWS_1252)},
702 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
704 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
705 ENC_ACTION(C_ISO_8859_2)},
706 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
708 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
709 ENC_ACTION(C_ISO_8859_13)},
710 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
711 ENC_ACTION(C_ISO_8859_4)},
712 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
714 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
715 ENC_ACTION(C_ISO_8859_7)},
716 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
718 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
719 ENC_ACTION(C_ISO_8859_8)},
720 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
721 ENC_ACTION(C_WINDOWS_1255)},
722 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
724 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
725 ENC_ACTION(C_ISO_8859_6)},
726 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
727 ENC_ACTION(C_CP1256)},
728 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
730 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
731 ENC_ACTION(C_ISO_8859_9)},
732 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
735 ENC_ACTION(C_ISO_8859_5)},
736 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
737 ENC_ACTION(C_KOI8_R)},
738 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
739 ENC_ACTION(C_KOI8_U)},
740 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
741 ENC_ACTION(C_WINDOWS_1251)},
742 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
744 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
745 ENC_ACTION(C_ISO_2022_JP)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
749 ENC_ACTION(C_GB2312)},
750 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
752 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
754 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
755 ENC_ACTION(C_EUC_TW)},
756 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
758 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
759 ENC_ACTION(C_EUC_KR)},
760 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
762 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
763 ENC_ACTION(C_TIS_620)},
764 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
765 ENC_ACTION(C_WINDOWS_874)},
767 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
768 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
769 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
770 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
771 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
772 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
773 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
776 static GtkTargetEntry compose_mime_types[] =
778 {"text/uri-list", 0, 0},
779 {"UTF8_STRING", 0, 0},
783 static gboolean compose_put_existing_to_front(MsgInfo *info)
785 GList *compose_list = compose_get_compose_list();
789 for (elem = compose_list; elem != NULL && elem->data != NULL;
791 Compose *c = (Compose*)elem->data;
793 if (!c->targetinfo || !c->targetinfo->msgid ||
797 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
798 gtkut_window_popup(c->window);
806 static GdkColor quote_color1 =
807 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
808 static GdkColor quote_color2 =
809 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
810 static GdkColor quote_color3 =
811 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
813 static GdkColor quote_bgcolor1 =
814 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
815 static GdkColor quote_bgcolor2 =
816 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
817 static GdkColor quote_bgcolor3 =
818 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
820 static GdkColor signature_color = {
827 static GdkColor uri_color = {
834 static void compose_create_tags(GtkTextView *text, Compose *compose)
836 GtkTextBuffer *buffer;
837 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
843 buffer = gtk_text_view_get_buffer(text);
845 if (prefs_common.enable_color) {
846 /* grab the quote colors, converting from an int to a GdkColor */
847 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
849 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
851 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
853 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
855 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
857 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
859 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
861 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
864 signature_color = quote_color1 = quote_color2 = quote_color3 =
865 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
868 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
869 gtk_text_buffer_create_tag(buffer, "quote0",
870 "foreground-gdk", "e_color1,
871 "paragraph-background-gdk", "e_bgcolor1,
873 gtk_text_buffer_create_tag(buffer, "quote1",
874 "foreground-gdk", "e_color2,
875 "paragraph-background-gdk", "e_bgcolor2,
877 gtk_text_buffer_create_tag(buffer, "quote2",
878 "foreground-gdk", "e_color3,
879 "paragraph-background-gdk", "e_bgcolor3,
882 gtk_text_buffer_create_tag(buffer, "quote0",
883 "foreground-gdk", "e_color1,
885 gtk_text_buffer_create_tag(buffer, "quote1",
886 "foreground-gdk", "e_color2,
888 gtk_text_buffer_create_tag(buffer, "quote2",
889 "foreground-gdk", "e_color3,
893 gtk_text_buffer_create_tag(buffer, "signature",
894 "foreground-gdk", &signature_color,
896 gtk_text_buffer_create_tag(buffer, "link",
897 "foreground-gdk", &uri_color,
899 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
900 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
902 color[0] = quote_color1;
903 color[1] = quote_color2;
904 color[2] = quote_color3;
905 color[3] = quote_bgcolor1;
906 color[4] = quote_bgcolor2;
907 color[5] = quote_bgcolor3;
908 color[6] = signature_color;
909 color[7] = uri_color;
910 cmap = gdk_drawable_get_colormap(compose->window->window);
911 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
913 for (i = 0; i < 8; i++) {
914 if (success[i] == FALSE) {
917 g_warning("Compose: color allocation failed.\n");
918 style = gtk_widget_get_style(GTK_WIDGET(text));
919 quote_color1 = quote_color2 = quote_color3 =
920 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
921 signature_color = uri_color = black;
926 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
927 GPtrArray *attach_files)
929 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
932 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item, const gchar *mailto)
934 return compose_generic_new(account, mailto, item, NULL, NULL);
937 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
939 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
942 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
943 GPtrArray *attach_files, GList *listAddress )
946 GtkTextView *textview;
947 GtkTextBuffer *textbuf;
949 GtkItemFactory *ifactory;
951 if (item && item->prefs && item->prefs->enable_default_account)
952 account = account_find_from_id(item->prefs->default_account);
954 if (!account) account = cur_account;
955 g_return_val_if_fail(account != NULL, NULL);
957 compose = compose_create(account, COMPOSE_NEW, FALSE);
959 ifactory = gtk_item_factory_from_widget(compose->menubar);
961 compose->replyinfo = NULL;
962 compose->fwdinfo = NULL;
964 textview = GTK_TEXT_VIEW(compose->text);
965 textbuf = gtk_text_view_get_buffer(textview);
966 compose_create_tags(textview, compose);
968 undo_block(compose->undostruct);
970 if (item && item->prefs && item->prefs->enable_default_dictionary &&
972 gtkaspell_change_dict(compose->gtkaspell,
973 item->prefs->default_dictionary);
974 compose_spell_menu_changed(compose);
977 if (account->auto_sig)
978 compose_insert_sig(compose, FALSE);
979 gtk_text_buffer_get_start_iter(textbuf, &iter);
980 gtk_text_buffer_place_cursor(textbuf, &iter);
982 if (account->protocol != A_NNTP) {
983 if (mailto && *mailto != '\0') {
984 compose_entries_set(compose, mailto);
986 } else if (item && item->prefs->enable_default_to) {
987 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
988 compose_entry_mark_default_to(compose, item->prefs->default_to);
990 if (item && item->ret_rcpt) {
991 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
995 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
996 } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
997 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
1000 * CLAWS: just don't allow return receipt request, even if the user
1001 * may want to send an email. simple but foolproof.
1003 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1005 compose_add_field_list( compose, listAddress );
1011 for (i = 0; i < attach_files->len; i++) {
1012 file = g_ptr_array_index(attach_files, i);
1013 compose_attach_append(compose, file, file, NULL);
1017 compose_show_first_last_header(compose, TRUE);
1019 /* Set save folder */
1020 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1021 gchar *folderidentifier;
1023 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1024 folderidentifier = folder_item_get_identifier(item);
1025 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1026 g_free(folderidentifier);
1029 gtk_widget_grab_focus(compose->header_last->entry);
1031 undo_unblock(compose->undostruct);
1033 if (prefs_common.auto_exteditor)
1034 compose_exec_ext_editor(compose);
1036 compose->modified = FALSE;
1037 compose_set_title(compose);
1041 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1042 gboolean override_pref)
1044 gchar *privacy = NULL;
1046 g_return_if_fail(compose != NULL);
1047 g_return_if_fail(account != NULL);
1049 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1052 if (account->default_privacy_system
1053 && strlen(account->default_privacy_system)) {
1054 privacy = account->default_privacy_system;
1056 GSList *privacy_avail = privacy_get_system_ids();
1057 if (privacy_avail && g_slist_length(privacy_avail)) {
1058 privacy = (gchar *)(privacy_avail->data);
1061 if (privacy != NULL) {
1062 compose->privacy_system = g_strdup(privacy);
1063 compose_update_privacy_system_menu_item(compose, FALSE);
1064 compose_use_encryption(compose, TRUE);
1068 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1070 gchar *privacy = NULL;
1072 if (account->default_privacy_system
1073 && strlen(account->default_privacy_system)) {
1074 privacy = account->default_privacy_system;
1076 GSList *privacy_avail = privacy_get_system_ids();
1077 if (privacy_avail && g_slist_length(privacy_avail)) {
1078 privacy = (gchar *)(privacy_avail->data);
1081 if (privacy != NULL) {
1082 compose->privacy_system = g_strdup(privacy);
1083 compose_update_privacy_system_menu_item(compose, FALSE);
1084 compose_use_signing(compose, TRUE);
1088 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1092 Compose *compose = NULL;
1093 GtkItemFactory *ifactory = NULL;
1095 g_return_val_if_fail(msginfo_list != NULL, NULL);
1097 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1098 g_return_val_if_fail(msginfo != NULL, NULL);
1100 list_len = g_slist_length(msginfo_list);
1104 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1105 FALSE, prefs_common.default_reply_list, FALSE, body);
1107 case COMPOSE_REPLY_WITH_QUOTE:
1108 compose = compose_reply(msginfo, TRUE,
1109 FALSE, prefs_common.default_reply_list, FALSE, body);
1111 case COMPOSE_REPLY_WITHOUT_QUOTE:
1112 compose = compose_reply(msginfo, FALSE,
1113 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1115 case COMPOSE_REPLY_TO_SENDER:
1116 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1117 FALSE, FALSE, TRUE, body);
1119 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1120 compose = compose_followup_and_reply_to(msginfo,
1121 prefs_common.reply_with_quote,
1122 FALSE, FALSE, body);
1124 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1125 compose = compose_reply(msginfo, TRUE,
1126 FALSE, FALSE, TRUE, body);
1128 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1129 compose = compose_reply(msginfo, FALSE,
1130 FALSE, FALSE, TRUE, NULL);
1132 case COMPOSE_REPLY_TO_ALL:
1133 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1134 TRUE, FALSE, FALSE, body);
1136 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1137 compose = compose_reply(msginfo, TRUE,
1138 TRUE, FALSE, FALSE, body);
1140 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1141 compose = compose_reply(msginfo, FALSE,
1142 TRUE, FALSE, FALSE, NULL);
1144 case COMPOSE_REPLY_TO_LIST:
1145 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1146 FALSE, TRUE, FALSE, body);
1148 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1149 compose = compose_reply(msginfo, TRUE,
1150 FALSE, TRUE, FALSE, body);
1152 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1153 compose = compose_reply(msginfo, FALSE,
1154 FALSE, TRUE, FALSE, NULL);
1156 case COMPOSE_FORWARD:
1157 if (prefs_common.forward_as_attachment) {
1158 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1161 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1165 case COMPOSE_FORWARD_INLINE:
1166 /* check if we reply to more than one Message */
1167 if (list_len == 1) {
1168 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1171 /* more messages FALL THROUGH */
1172 case COMPOSE_FORWARD_AS_ATTACH:
1173 compose = compose_forward_multiple(NULL, msginfo_list);
1175 case COMPOSE_REDIRECT:
1176 compose = compose_redirect(NULL, msginfo, FALSE);
1179 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1182 ifactory = gtk_item_factory_from_widget(compose->menubar);
1184 compose->rmode = mode;
1185 switch (compose->rmode) {
1187 case COMPOSE_REPLY_WITH_QUOTE:
1188 case COMPOSE_REPLY_WITHOUT_QUOTE:
1189 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1190 debug_print("reply mode Normal\n");
1191 menu_set_active(ifactory, "/Options/Reply mode/Normal", TRUE);
1192 compose_reply_change_mode(compose, COMPOSE_REPLY, NULL); /* force update */
1194 case COMPOSE_REPLY_TO_SENDER:
1195 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1196 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1197 debug_print("reply mode Sender\n");
1198 menu_set_active(ifactory, "/Options/Reply mode/Sender", TRUE);
1200 case COMPOSE_REPLY_TO_ALL:
1201 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1202 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1203 debug_print("reply mode All\n");
1204 menu_set_active(ifactory, "/Options/Reply mode/All", TRUE);
1206 case COMPOSE_REPLY_TO_LIST:
1207 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1208 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1209 debug_print("reply mode List\n");
1210 menu_set_active(ifactory, "/Options/Reply mode/List", TRUE);
1218 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1219 gboolean to_ml, gboolean to_sender,
1222 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1223 to_sender, FALSE, body);
1226 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1231 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1232 to_sender, TRUE, body);
1235 static void compose_extract_original_charset(Compose *compose)
1237 MsgInfo *info = NULL;
1238 if (compose->replyinfo) {
1239 info = compose->replyinfo;
1240 } else if (compose->fwdinfo) {
1241 info = compose->fwdinfo;
1242 } else if (compose->targetinfo) {
1243 info = compose->targetinfo;
1246 MimeInfo *mimeinfo = procmime_scan_message(info);
1247 MimeInfo *partinfo = mimeinfo;
1248 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1249 partinfo = procmime_mimeinfo_next(partinfo);
1251 compose->orig_charset =
1252 g_strdup(procmime_mimeinfo_get_parameter(
1253 partinfo, "charset"));
1255 procmime_mimeinfo_free_all(mimeinfo);
1259 #define SIGNAL_BLOCK(buffer) { \
1260 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1261 G_CALLBACK(compose_changed_cb), \
1263 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1264 G_CALLBACK(text_inserted), \
1268 #define SIGNAL_UNBLOCK(buffer) { \
1269 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1270 G_CALLBACK(compose_changed_cb), \
1272 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1273 G_CALLBACK(text_inserted), \
1277 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1278 gboolean to_all, gboolean to_ml,
1280 gboolean followup_and_reply_to,
1283 GtkItemFactory *ifactory;
1285 PrefsAccount *account = NULL;
1286 PrefsAccount *reply_account;
1287 GtkTextView *textview;
1288 GtkTextBuffer *textbuf;
1290 g_return_val_if_fail(msginfo != NULL, NULL);
1291 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1293 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1295 g_return_val_if_fail(account != NULL, NULL);
1297 if (to_sender && account->protocol == A_NNTP &&
1298 !followup_and_reply_to) {
1300 account_find_from_address(account->address);
1302 reply_account = compose_current_mail_account();
1306 reply_account = account;
1308 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1310 compose->updating = TRUE;
1312 ifactory = gtk_item_factory_from_widget(compose->menubar);
1314 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1315 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1317 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1318 if (!compose->replyinfo)
1319 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1321 compose_extract_original_charset(compose);
1323 if (msginfo->folder && msginfo->folder->ret_rcpt)
1324 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1326 /* Set save folder */
1327 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1328 gchar *folderidentifier;
1330 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1331 folderidentifier = folder_item_get_identifier(msginfo->folder);
1332 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1333 g_free(folderidentifier);
1336 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1338 textview = (GTK_TEXT_VIEW(compose->text));
1339 textbuf = gtk_text_view_get_buffer(textview);
1340 compose_create_tags(textview, compose);
1342 undo_block(compose->undostruct);
1344 if (msginfo->folder && msginfo->folder->prefs &&
1345 msginfo->folder->prefs &&
1346 msginfo->folder->prefs->enable_default_dictionary &&
1348 gtkaspell_change_dict(compose->gtkaspell,
1349 msginfo->folder->prefs->default_dictionary);
1355 if (prefs_common.quotemark && *prefs_common.quotemark)
1356 qmark = prefs_common.quotemark;
1360 compose_quote_fmt(compose, compose->replyinfo,
1361 prefs_common.quotefmt,
1362 qmark, body, FALSE);
1363 quote_fmt_reset_vartable();
1365 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1366 compose_force_encryption(compose, account, FALSE);
1369 SIGNAL_BLOCK(textbuf);
1371 if (account->auto_sig)
1372 compose_insert_sig(compose, FALSE);
1374 compose_wrap_all(compose);
1376 SIGNAL_UNBLOCK(textbuf);
1378 gtk_widget_grab_focus(compose->text);
1380 undo_unblock(compose->undostruct);
1382 if (prefs_common.auto_exteditor)
1383 compose_exec_ext_editor(compose);
1385 compose->modified = FALSE;
1386 compose_set_title(compose);
1388 compose->updating = FALSE;
1390 if (compose->deferred_destroy) {
1391 compose_destroy(compose);
1398 #define INSERT_FW_HEADER(var, hdr) \
1399 if (msginfo->var && *msginfo->var) { \
1400 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1401 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1402 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1405 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1406 gboolean as_attach, const gchar *body,
1407 gboolean no_extedit,
1411 GtkTextView *textview;
1412 GtkTextBuffer *textbuf;
1415 g_return_val_if_fail(msginfo != NULL, NULL);
1416 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1419 !(account = compose_guess_forward_account_from_msginfo
1421 account = cur_account;
1423 compose = compose_create(account, COMPOSE_FORWARD, batch);
1425 compose->updating = TRUE;
1426 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1427 if (!compose->fwdinfo)
1428 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1430 compose_extract_original_charset(compose);
1432 if (msginfo->subject && *msginfo->subject) {
1433 gchar *buf, *buf2, *p;
1435 buf = p = g_strdup(msginfo->subject);
1436 p += subject_get_prefix_length(p);
1437 memmove(buf, p, strlen(p) + 1);
1439 buf2 = g_strdup_printf("Fw: %s", buf);
1440 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1446 textview = GTK_TEXT_VIEW(compose->text);
1447 textbuf = gtk_text_view_get_buffer(textview);
1448 compose_create_tags(textview, compose);
1450 undo_block(compose->undostruct);
1454 msgfile = procmsg_get_message_file_path(msginfo);
1455 if (!is_file_exist(msgfile))
1456 g_warning("%s: file not exist\n", msgfile);
1458 compose_attach_append(compose, msgfile, msgfile,
1464 MsgInfo *full_msginfo;
1466 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1468 full_msginfo = procmsg_msginfo_copy(msginfo);
1470 if (prefs_common.fw_quotemark &&
1471 *prefs_common.fw_quotemark)
1472 qmark = prefs_common.fw_quotemark;
1476 compose_quote_fmt(compose, full_msginfo,
1477 prefs_common.fw_quotefmt,
1478 qmark, body, FALSE);
1479 quote_fmt_reset_vartable();
1480 compose_attach_parts(compose, msginfo);
1482 procmsg_msginfo_free(full_msginfo);
1485 SIGNAL_BLOCK(textbuf);
1487 if (account->auto_sig)
1488 compose_insert_sig(compose, FALSE);
1490 compose_wrap_all(compose);
1492 SIGNAL_UNBLOCK(textbuf);
1494 gtk_text_buffer_get_start_iter(textbuf, &iter);
1495 gtk_text_buffer_place_cursor(textbuf, &iter);
1497 gtk_widget_grab_focus(compose->header_last->entry);
1499 if (!no_extedit && prefs_common.auto_exteditor)
1500 compose_exec_ext_editor(compose);
1503 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1504 gchar *folderidentifier;
1506 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1507 folderidentifier = folder_item_get_identifier(msginfo->folder);
1508 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1509 g_free(folderidentifier);
1512 undo_unblock(compose->undostruct);
1514 compose->modified = FALSE;
1515 compose_set_title(compose);
1517 compose->updating = FALSE;
1519 if (compose->deferred_destroy) {
1520 compose_destroy(compose);
1527 #undef INSERT_FW_HEADER
1529 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1532 GtkTextView *textview;
1533 GtkTextBuffer *textbuf;
1537 gboolean single_mail = TRUE;
1539 g_return_val_if_fail(msginfo_list != NULL, NULL);
1541 if (g_slist_length(msginfo_list) > 1)
1542 single_mail = FALSE;
1544 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1545 if (((MsgInfo *)msginfo->data)->folder == NULL)
1548 /* guess account from first selected message */
1550 !(account = compose_guess_forward_account_from_msginfo
1551 (msginfo_list->data)))
1552 account = cur_account;
1554 g_return_val_if_fail(account != NULL, NULL);
1556 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1557 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1558 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1561 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1563 compose->updating = TRUE;
1565 textview = GTK_TEXT_VIEW(compose->text);
1566 textbuf = gtk_text_view_get_buffer(textview);
1567 compose_create_tags(textview, compose);
1569 undo_block(compose->undostruct);
1570 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1571 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1573 if (!is_file_exist(msgfile))
1574 g_warning("%s: file not exist\n", msgfile);
1576 compose_attach_append(compose, msgfile, msgfile,
1582 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1583 if (info->subject && *info->subject) {
1584 gchar *buf, *buf2, *p;
1586 buf = p = g_strdup(info->subject);
1587 p += subject_get_prefix_length(p);
1588 memmove(buf, p, strlen(p) + 1);
1590 buf2 = g_strdup_printf("Fw: %s", buf);
1591 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1597 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1598 _("Fw: multiple emails"));
1601 SIGNAL_BLOCK(textbuf);
1603 if (account->auto_sig)
1604 compose_insert_sig(compose, FALSE);
1606 compose_wrap_all(compose);
1608 SIGNAL_UNBLOCK(textbuf);
1610 gtk_text_buffer_get_start_iter(textbuf, &iter);
1611 gtk_text_buffer_place_cursor(textbuf, &iter);
1613 gtk_widget_grab_focus(compose->header_last->entry);
1614 undo_unblock(compose->undostruct);
1615 compose->modified = FALSE;
1616 compose_set_title(compose);
1618 compose->updating = FALSE;
1620 if (compose->deferred_destroy) {
1621 compose_destroy(compose);
1628 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1630 GtkTextIter start = *iter;
1631 GtkTextIter end_iter;
1632 int start_pos = gtk_text_iter_get_offset(&start);
1634 if (!compose->account->sig_sep)
1637 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1638 start_pos+strlen(compose->account->sig_sep));
1640 /* check sig separator */
1641 str = gtk_text_iter_get_text(&start, &end_iter);
1642 if (!strcmp(str, compose->account->sig_sep)) {
1644 /* check end of line (\n) */
1645 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1646 start_pos+strlen(compose->account->sig_sep));
1647 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1648 start_pos+strlen(compose->account->sig_sep)+1);
1649 tmp = gtk_text_iter_get_text(&start, &end_iter);
1650 if (!strcmp(tmp,"\n")) {
1662 static void compose_colorize_signature(Compose *compose)
1664 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1666 GtkTextIter end_iter;
1667 gtk_text_buffer_get_start_iter(buffer, &iter);
1668 while (gtk_text_iter_forward_line(&iter))
1669 if (compose_is_sig_separator(compose, buffer, &iter)) {
1670 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1671 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1675 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1677 Compose *compose = NULL;
1678 PrefsAccount *account = NULL;
1679 GtkTextView *textview;
1680 GtkTextBuffer *textbuf;
1684 gchar buf[BUFFSIZE];
1685 gboolean use_signing = FALSE;
1686 gboolean use_encryption = FALSE;
1687 gchar *privacy_system = NULL;
1688 int priority = PRIORITY_NORMAL;
1689 MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
1691 g_return_val_if_fail(msginfo != NULL, NULL);
1692 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1694 if (compose_put_existing_to_front(msginfo)) {
1698 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1699 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1700 gchar queueheader_buf[BUFFSIZE];
1703 /* Select Account from queue headers */
1704 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1705 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1706 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1707 account = account_find_from_id(id);
1709 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1710 sizeof(queueheader_buf), "NAID:")) {
1711 id = atoi(&queueheader_buf[strlen("NAID:")]);
1712 account = account_find_from_id(id);
1714 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1715 sizeof(queueheader_buf), "MAID:")) {
1716 id = atoi(&queueheader_buf[strlen("MAID:")]);
1717 account = account_find_from_id(id);
1719 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1720 sizeof(queueheader_buf), "S:")) {
1721 account = account_find_from_address(queueheader_buf);
1723 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1724 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1725 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1726 use_signing = param;
1729 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1730 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1731 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1732 use_encryption = param;
1734 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1735 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1736 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1738 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1739 sizeof(queueheader_buf), "X-Priority: ")) {
1740 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1743 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1744 sizeof(queueheader_buf), "RMID:")) {
1745 gchar **tokens = g_strsplit(&queueheader_buf[strlen("RMID:")], "\t", 0);
1746 if (tokens[0] && tokens[1] && tokens[2]) {
1747 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1748 if (orig_item != NULL) {
1749 replyinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1754 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1755 sizeof(queueheader_buf), "FMID:")) {
1756 gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0);
1757 if (tokens[0] && tokens[1] && tokens[2]) {
1758 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1759 if (orig_item != NULL) {
1760 fwdinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1766 account = msginfo->folder->folder->account;
1769 if (!account && prefs_common.reedit_account_autosel) {
1770 gchar from[BUFFSIZE];
1771 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1772 extract_address(from);
1773 account = account_find_from_address(from);
1777 account = cur_account;
1779 g_return_val_if_fail(account != NULL, NULL);
1781 compose = compose_create(account, COMPOSE_REEDIT, batch);
1783 compose->replyinfo = replyinfo;
1784 compose->fwdinfo = fwdinfo;
1786 compose->updating = TRUE;
1787 compose->priority = priority;
1789 if (privacy_system != NULL) {
1790 compose->privacy_system = privacy_system;
1791 compose_use_signing(compose, use_signing);
1792 compose_use_encryption(compose, use_encryption);
1793 compose_update_privacy_system_menu_item(compose, FALSE);
1795 activate_privacy_system(compose, account, FALSE);
1798 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1800 compose_extract_original_charset(compose);
1802 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1803 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1804 gchar queueheader_buf[BUFFSIZE];
1806 /* Set message save folder */
1807 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1810 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1811 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1812 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1814 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1815 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1817 GtkItemFactory *ifactory;
1818 ifactory = gtk_item_factory_from_widget(compose->menubar);
1819 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1824 if (compose_parse_header(compose, msginfo) < 0) {
1825 compose->updating = FALSE;
1826 compose_destroy(compose);
1829 compose_reedit_set_entry(compose, msginfo);
1831 textview = GTK_TEXT_VIEW(compose->text);
1832 textbuf = gtk_text_view_get_buffer(textview);
1833 compose_create_tags(textview, compose);
1835 mark = gtk_text_buffer_get_insert(textbuf);
1836 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1838 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1839 G_CALLBACK(compose_changed_cb),
1842 if (procmime_msginfo_is_encrypted(msginfo)) {
1843 fp = procmime_get_first_encrypted_text_content(msginfo);
1845 compose_force_encryption(compose, account, TRUE);
1848 fp = procmime_get_first_text_content(msginfo);
1851 g_warning("Can't get text part\n");
1855 gboolean prev_autowrap = compose->autowrap;
1857 compose->autowrap = FALSE;
1858 while (fgets(buf, sizeof(buf), fp) != NULL) {
1860 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1862 compose_wrap_all_full(compose, FALSE);
1863 compose->autowrap = prev_autowrap;
1867 compose_attach_parts(compose, msginfo);
1869 compose_colorize_signature(compose);
1871 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1872 G_CALLBACK(compose_changed_cb),
1875 gtk_widget_grab_focus(compose->text);
1877 if (prefs_common.auto_exteditor) {
1878 compose_exec_ext_editor(compose);
1880 compose->modified = FALSE;
1881 compose_set_title(compose);
1883 compose->updating = FALSE;
1885 if (compose->deferred_destroy) {
1886 compose_destroy(compose);
1890 compose->sig_str = compose_get_signature_str(compose);
1895 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1900 GtkItemFactory *ifactory;
1903 g_return_val_if_fail(msginfo != NULL, NULL);
1906 account = account_get_reply_account(msginfo,
1907 prefs_common.reply_account_autosel);
1908 g_return_val_if_fail(account != NULL, NULL);
1910 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1912 compose->updating = TRUE;
1914 ifactory = gtk_item_factory_from_widget(compose->menubar);
1915 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1916 compose->replyinfo = NULL;
1917 compose->fwdinfo = NULL;
1919 compose_show_first_last_header(compose, TRUE);
1921 gtk_widget_grab_focus(compose->header_last->entry);
1923 filename = procmsg_get_message_file_path(msginfo);
1925 if (filename == NULL) {
1926 compose->updating = FALSE;
1927 compose_destroy(compose);
1932 compose->redirect_filename = filename;
1934 /* Set save folder */
1935 item = msginfo->folder;
1936 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1937 gchar *folderidentifier;
1939 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1940 folderidentifier = folder_item_get_identifier(item);
1941 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1942 g_free(folderidentifier);
1945 compose_attach_parts(compose, msginfo);
1947 if (msginfo->subject)
1948 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1950 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1952 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1953 quote_fmt_reset_vartable();
1954 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1956 compose_colorize_signature(compose);
1958 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1959 menu_set_sensitive(ifactory, "/Add...", FALSE);
1960 menu_set_sensitive(ifactory, "/Remove", FALSE);
1961 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1963 ifactory = gtk_item_factory_from_widget(compose->menubar);
1964 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1965 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1966 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1967 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1968 menu_set_sensitive(ifactory, "/Edit", FALSE);
1969 menu_set_sensitive(ifactory, "/Options", FALSE);
1970 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1971 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1973 if (compose->toolbar->draft_btn)
1974 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1975 if (compose->toolbar->insert_btn)
1976 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1977 if (compose->toolbar->attach_btn)
1978 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1979 if (compose->toolbar->sig_btn)
1980 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1981 if (compose->toolbar->exteditor_btn)
1982 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1983 if (compose->toolbar->linewrap_current_btn)
1984 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1985 if (compose->toolbar->linewrap_all_btn)
1986 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1988 compose->modified = FALSE;
1989 compose_set_title(compose);
1990 compose->updating = FALSE;
1992 if (compose->deferred_destroy) {
1993 compose_destroy(compose);
2000 GList *compose_get_compose_list(void)
2002 return compose_list;
2005 void compose_entry_append(Compose *compose, const gchar *address,
2006 ComposeEntryType type)
2010 gboolean in_quote = FALSE;
2011 if (!address || *address == '\0') return;
2018 header = N_("Bcc:");
2020 case COMPOSE_REPLYTO:
2021 header = N_("Reply-To:");
2023 case COMPOSE_NEWSGROUPS:
2024 header = N_("Newsgroups:");
2026 case COMPOSE_FOLLOWUPTO:
2027 header = N_( "Followup-To:");
2034 header = prefs_common.trans_hdr ? gettext(header) : header;
2036 cur = begin = (gchar *)address;
2038 /* we separate the line by commas, but not if we're inside a quoted
2040 while (*cur != '\0') {
2042 in_quote = !in_quote;
2043 if (*cur == ',' && !in_quote) {
2044 gchar *tmp = g_strdup(begin);
2046 tmp[cur-begin]='\0';
2049 while (*tmp == ' ' || *tmp == '\t')
2051 compose_add_header_entry(compose, header, tmp);
2058 gchar *tmp = g_strdup(begin);
2060 tmp[cur-begin]='\0';
2063 while (*tmp == ' ' || *tmp == '\t')
2065 compose_add_header_entry(compose, header, tmp);
2070 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
2072 static GdkColor yellow;
2073 static GdkColor black;
2074 static gboolean yellow_initialised = FALSE;
2078 if (!yellow_initialised) {
2079 gdk_color_parse("#f5f6be", &yellow);
2080 gdk_color_parse("#000000", &black);
2081 yellow_initialised = gdk_colormap_alloc_color(
2082 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2083 yellow_initialised &= gdk_colormap_alloc_color(
2084 gdk_colormap_get_system(), &black, FALSE, TRUE);
2087 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2088 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2089 if (gtk_entry_get_text(entry) &&
2090 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2091 if (yellow_initialised) {
2092 gtk_widget_modify_base(
2093 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2094 GTK_STATE_NORMAL, &yellow);
2095 gtk_widget_modify_text(
2096 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2097 GTK_STATE_NORMAL, &black);
2103 void compose_toolbar_cb(gint action, gpointer data)
2105 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2106 Compose *compose = (Compose*)toolbar_item->parent;
2108 g_return_if_fail(compose != NULL);
2112 compose_send_cb(compose, 0, NULL);
2115 compose_send_later_cb(compose, 0, NULL);
2118 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2121 compose_insert_file_cb(compose, 0, NULL);
2124 compose_attach_cb(compose, 0, NULL);
2127 compose_insert_sig(compose, FALSE);
2130 compose_ext_editor_cb(compose, 0, NULL);
2132 case A_LINEWRAP_CURRENT:
2133 compose_beautify_paragraph(compose, NULL, TRUE);
2135 case A_LINEWRAP_ALL:
2136 compose_wrap_all_full(compose, TRUE);
2139 compose_address_cb(compose, 0, NULL);
2142 case A_CHECK_SPELLING:
2143 compose_check_all(compose);
2151 static void compose_entries_set(Compose *compose, const gchar *mailto)
2155 gchar *subject = NULL;
2160 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2163 compose_entry_append(compose, to, COMPOSE_TO);
2165 compose_entry_append(compose, cc, COMPOSE_CC);
2167 if (!g_utf8_validate (subject, -1, NULL)) {
2168 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2169 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2172 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2176 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2177 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2180 gboolean prev_autowrap = compose->autowrap;
2182 compose->autowrap = FALSE;
2184 mark = gtk_text_buffer_get_insert(buffer);
2185 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2187 if (!g_utf8_validate (body, -1, NULL)) {
2188 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2189 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2192 gtk_text_buffer_insert(buffer, &iter, body, -1);
2194 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2196 compose->autowrap = prev_autowrap;
2197 if (compose->autowrap)
2198 compose_wrap_all(compose);
2207 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2209 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2210 {"Cc:", NULL, TRUE},
2211 {"References:", NULL, FALSE},
2212 {"Bcc:", NULL, TRUE},
2213 {"Newsgroups:", NULL, TRUE},
2214 {"Followup-To:", NULL, TRUE},
2215 {"List-Post:", NULL, FALSE},
2216 {"X-Priority:", NULL, FALSE},
2217 {NULL, NULL, FALSE}};
2233 g_return_val_if_fail(msginfo != NULL, -1);
2235 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2236 procheader_get_header_fields(fp, hentry);
2239 if (hentry[H_REPLY_TO].body != NULL) {
2240 if (hentry[H_REPLY_TO].body[0] != '\0') {
2242 conv_unmime_header(hentry[H_REPLY_TO].body,
2245 g_free(hentry[H_REPLY_TO].body);
2246 hentry[H_REPLY_TO].body = NULL;
2248 if (hentry[H_CC].body != NULL) {
2249 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2250 g_free(hentry[H_CC].body);
2251 hentry[H_CC].body = NULL;
2253 if (hentry[H_REFERENCES].body != NULL) {
2254 if (compose->mode == COMPOSE_REEDIT)
2255 compose->references = hentry[H_REFERENCES].body;
2257 compose->references = compose_parse_references
2258 (hentry[H_REFERENCES].body, msginfo->msgid);
2259 g_free(hentry[H_REFERENCES].body);
2261 hentry[H_REFERENCES].body = NULL;
2263 if (hentry[H_BCC].body != NULL) {
2264 if (compose->mode == COMPOSE_REEDIT)
2266 conv_unmime_header(hentry[H_BCC].body, NULL);
2267 g_free(hentry[H_BCC].body);
2268 hentry[H_BCC].body = NULL;
2270 if (hentry[H_NEWSGROUPS].body != NULL) {
2271 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2272 hentry[H_NEWSGROUPS].body = NULL;
2274 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2275 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2276 compose->followup_to =
2277 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2280 g_free(hentry[H_FOLLOWUP_TO].body);
2281 hentry[H_FOLLOWUP_TO].body = NULL;
2283 if (hentry[H_LIST_POST].body != NULL) {
2286 extract_address(hentry[H_LIST_POST].body);
2287 if (hentry[H_LIST_POST].body[0] != '\0') {
2288 scan_mailto_url(hentry[H_LIST_POST].body,
2289 &to, NULL, NULL, NULL, NULL);
2291 g_free(compose->ml_post);
2292 compose->ml_post = to;
2295 g_free(hentry[H_LIST_POST].body);
2296 hentry[H_LIST_POST].body = NULL;
2299 /* CLAWS - X-Priority */
2300 if (compose->mode == COMPOSE_REEDIT)
2301 if (hentry[H_X_PRIORITY].body != NULL) {
2304 priority = atoi(hentry[H_X_PRIORITY].body);
2305 g_free(hentry[H_X_PRIORITY].body);
2307 hentry[H_X_PRIORITY].body = NULL;
2309 if (priority < PRIORITY_HIGHEST ||
2310 priority > PRIORITY_LOWEST)
2311 priority = PRIORITY_NORMAL;
2313 compose->priority = priority;
2316 if (compose->mode == COMPOSE_REEDIT) {
2317 if (msginfo->inreplyto && *msginfo->inreplyto)
2318 compose->inreplyto = g_strdup(msginfo->inreplyto);
2322 if (msginfo->msgid && *msginfo->msgid)
2323 compose->inreplyto = g_strdup(msginfo->msgid);
2325 if (!compose->references) {
2326 if (msginfo->msgid && *msginfo->msgid) {
2327 if (msginfo->inreplyto && *msginfo->inreplyto)
2328 compose->references =
2329 g_strdup_printf("<%s>\n\t<%s>",
2333 compose->references =
2334 g_strconcat("<", msginfo->msgid, ">",
2336 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2337 compose->references =
2338 g_strconcat("<", msginfo->inreplyto, ">",
2346 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2348 GSList *ref_id_list, *cur;
2352 ref_id_list = references_list_append(NULL, ref);
2353 if (!ref_id_list) return NULL;
2354 if (msgid && *msgid)
2355 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2360 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2361 /* "<" + Message-ID + ">" + CR+LF+TAB */
2362 len += strlen((gchar *)cur->data) + 5;
2364 if (len > MAX_REFERENCES_LEN) {
2365 /* remove second message-ID */
2366 if (ref_id_list && ref_id_list->next &&
2367 ref_id_list->next->next) {
2368 g_free(ref_id_list->next->data);
2369 ref_id_list = g_slist_remove
2370 (ref_id_list, ref_id_list->next->data);
2372 slist_free_strings(ref_id_list);
2373 g_slist_free(ref_id_list);
2380 new_ref = g_string_new("");
2381 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2382 if (new_ref->len > 0)
2383 g_string_append(new_ref, "\n\t");
2384 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2387 slist_free_strings(ref_id_list);
2388 g_slist_free(ref_id_list);
2390 new_ref_str = new_ref->str;
2391 g_string_free(new_ref, FALSE);
2396 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2397 const gchar *fmt, const gchar *qmark,
2398 const gchar *body, gboolean rewrap)
2400 static MsgInfo dummyinfo;
2401 gchar *quote_str = NULL;
2403 gboolean prev_autowrap;
2404 const gchar *trimmed_body = body;
2405 gint cursor_pos = -1;
2406 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2407 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2412 SIGNAL_BLOCK(buffer);
2415 msginfo = &dummyinfo;
2417 if (qmark != NULL) {
2418 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
2419 quote_fmt_scan_string(qmark);
2422 buf = quote_fmt_get_buffer();
2424 alertpanel_error(_("Quote mark format error."));
2426 Xstrdup_a(quote_str, buf, goto error)
2429 if (fmt && *fmt != '\0') {
2430 while (trimmed_body && strlen(trimmed_body) > 1
2431 && trimmed_body[0]=='\n')
2434 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account);
2435 quote_fmt_scan_string(fmt);
2438 buf = quote_fmt_get_buffer();
2440 alertpanel_error(_("Message reply/forward format error."));
2446 prev_autowrap = compose->autowrap;
2447 compose->autowrap = FALSE;
2449 mark = gtk_text_buffer_get_insert(buffer);
2450 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2451 if (g_utf8_validate(buf, -1, NULL)) {
2452 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2454 gchar *tmpout = NULL;
2455 tmpout = conv_codeset_strdup
2456 (buf, conv_get_locale_charset_str_no_utf8(),
2458 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2460 tmpout = g_malloc(strlen(buf)*2+1);
2461 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2463 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2467 cursor_pos = quote_fmt_get_cursor_pos();
2468 compose->set_cursor_pos = cursor_pos;
2469 if (cursor_pos == -1) {
2472 gtk_text_buffer_get_start_iter(buffer, &iter);
2473 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2474 gtk_text_buffer_place_cursor(buffer, &iter);
2476 compose->autowrap = prev_autowrap;
2477 if (compose->autowrap && rewrap)
2478 compose_wrap_all(compose);
2485 SIGNAL_UNBLOCK(buffer);
2491 /* if ml_post is of type addr@host and from is of type
2492 * addr-anything@host, return TRUE
2494 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2496 gchar *left_ml = NULL;
2497 gchar *right_ml = NULL;
2498 gchar *left_from = NULL;
2499 gchar *right_from = NULL;
2500 gboolean result = FALSE;
2502 if (!ml_post || !from)
2505 left_ml = g_strdup(ml_post);
2506 if (strstr(left_ml, "@")) {
2507 right_ml = strstr(left_ml, "@")+1;
2508 *(strstr(left_ml, "@")) = '\0';
2511 left_from = g_strdup(from);
2512 if (strstr(left_from, "@")) {
2513 right_from = strstr(left_from, "@")+1;
2514 *(strstr(left_from, "@")) = '\0';
2517 if (left_ml && left_from && right_ml && right_from
2518 && !strncmp(left_from, left_ml, strlen(left_ml))
2519 && !strcmp(right_from, right_ml)) {
2528 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2530 gchar *my_addr1, *my_addr2;
2532 if (!addr1 || !addr2)
2535 Xstrdup_a(my_addr1, addr1, return FALSE);
2536 Xstrdup_a(my_addr2, addr2, return FALSE);
2538 extract_address(my_addr1);
2539 extract_address(my_addr2);
2541 return !strcasecmp(my_addr1, my_addr2);
2544 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2545 gboolean to_all, gboolean to_ml,
2547 gboolean followup_and_reply_to)
2549 GSList *cc_list = NULL;
2552 gchar *replyto = NULL;
2553 GHashTable *to_table;
2555 gboolean reply_to_ml = FALSE;
2556 gboolean default_reply_to = FALSE;
2558 g_return_if_fail(compose->account != NULL);
2559 g_return_if_fail(msginfo != NULL);
2561 reply_to_ml = to_ml && compose->ml_post;
2563 default_reply_to = msginfo->folder &&
2564 msginfo->folder->prefs->enable_default_reply_to;
2566 if (compose->account->protocol != A_NNTP) {
2567 if (reply_to_ml && !default_reply_to) {
2569 gboolean is_subscr = is_subscription(compose->ml_post,
2572 /* normal answer to ml post with a reply-to */
2573 compose_entry_append(compose,
2576 if (compose->replyto
2577 && !same_address(compose->ml_post, compose->replyto))
2578 compose_entry_append(compose,
2582 /* answer to subscription confirmation */
2583 if (compose->replyto)
2584 compose_entry_append(compose,
2587 else if (msginfo->from)
2588 compose_entry_append(compose,
2593 else if (!(to_all || to_sender) && default_reply_to) {
2594 compose_entry_append(compose,
2595 msginfo->folder->prefs->default_reply_to,
2597 compose_entry_mark_default_to(compose,
2598 msginfo->folder->prefs->default_reply_to);
2603 Xstrdup_a(tmp1, msginfo->from, return);
2604 extract_address(tmp1);
2605 if (to_all || to_sender ||
2606 !account_find_from_address(tmp1))
2607 compose_entry_append(compose,
2608 (compose->replyto && !to_sender)
2609 ? compose->replyto :
2610 msginfo->from ? msginfo->from : "",
2612 else if (!to_all && !to_sender) {
2613 /* reply to the last list of recipients */
2614 compose_entry_append(compose,
2615 msginfo->to ? msginfo->to : "",
2617 compose_entry_append(compose,
2618 msginfo->cc ? msginfo->cc : "",
2623 if (to_sender || (compose->followup_to &&
2624 !strncmp(compose->followup_to, "poster", 6)))
2625 compose_entry_append
2627 (compose->replyto ? compose->replyto :
2628 msginfo->from ? msginfo->from : ""),
2631 else if (followup_and_reply_to || to_all) {
2632 compose_entry_append
2634 (compose->replyto ? compose->replyto :
2635 msginfo->from ? msginfo->from : ""),
2638 compose_entry_append
2640 compose->followup_to ? compose->followup_to :
2641 compose->newsgroups ? compose->newsgroups : "",
2642 COMPOSE_NEWSGROUPS);
2645 compose_entry_append
2647 compose->followup_to ? compose->followup_to :
2648 compose->newsgroups ? compose->newsgroups : "",
2649 COMPOSE_NEWSGROUPS);
2652 if (msginfo->subject && *msginfo->subject) {
2656 buf = p = g_strdup(msginfo->subject);
2657 p += subject_get_prefix_length(p);
2658 memmove(buf, p, strlen(p) + 1);
2660 buf2 = g_strdup_printf("Re: %s", buf);
2661 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2666 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2668 if (to_ml && compose->ml_post) return;
2669 if (!to_all || compose->account->protocol == A_NNTP) return;
2671 if (compose->replyto) {
2672 Xstrdup_a(replyto, compose->replyto, return);
2673 extract_address(replyto);
2675 if (msginfo->from) {
2676 Xstrdup_a(from, msginfo->from, return);
2677 extract_address(from);
2680 if (replyto && from)
2681 cc_list = address_list_append_with_comments(cc_list, from);
2682 if (to_all && msginfo->folder &&
2683 msginfo->folder->prefs->enable_default_reply_to)
2684 cc_list = address_list_append_with_comments(cc_list,
2685 msginfo->folder->prefs->default_reply_to);
2686 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2687 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2689 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2691 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2692 if (compose->account)
2693 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2694 GINT_TO_POINTER(1));
2696 /* remove address on To: and that of current account */
2697 for (cur = cc_list; cur != NULL; ) {
2698 GSList *next = cur->next;
2701 addr = g_strdup(cur->data);
2702 extract_address(addr);
2704 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2705 cc_list = g_slist_remove(cc_list, cur->data);
2707 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2711 hash_free_strings(to_table);
2712 g_hash_table_destroy(to_table);
2715 for (cur = cc_list; cur != NULL; cur = cur->next)
2716 compose_entry_append(compose, (gchar *)cur->data,
2718 slist_free_strings(cc_list);
2719 g_slist_free(cc_list);
2724 #define SET_ENTRY(entry, str) \
2727 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2730 #define SET_ADDRESS(type, str) \
2733 compose_entry_append(compose, str, type); \
2736 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2738 g_return_if_fail(msginfo != NULL);
2740 SET_ENTRY(subject_entry, msginfo->subject);
2741 SET_ENTRY(from_name, msginfo->from);
2742 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2743 SET_ADDRESS(COMPOSE_CC, compose->cc);
2744 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2745 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2746 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2747 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2749 compose_update_priority_menu_item(compose);
2750 compose_update_privacy_system_menu_item(compose, FALSE);
2751 compose_show_first_last_header(compose, TRUE);
2757 static void compose_insert_sig(Compose *compose, gboolean replace)
2759 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2760 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2762 GtkTextIter iter, iter_end;
2764 gchar *search = NULL;
2765 gboolean prev_autowrap;
2766 gboolean found = FALSE, shift = FALSE;
2769 g_return_if_fail(compose->account != NULL);
2771 prev_autowrap = compose->autowrap;
2772 compose->autowrap = FALSE;
2774 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2775 G_CALLBACK(compose_changed_cb),
2778 mark = gtk_text_buffer_get_insert(buffer);
2779 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2780 cur_pos = gtk_text_iter_get_offset (&iter);
2782 gtk_text_buffer_get_end_iter(buffer, &iter);
2784 search = compose->sig_str;
2786 if (replace && search) {
2787 GtkTextIter first_iter, start_iter, end_iter;
2789 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2791 if (compose->sig_str[0] == '\0')
2794 found = gtk_text_iter_forward_search(&first_iter,
2796 GTK_TEXT_SEARCH_TEXT_ONLY,
2797 &start_iter, &end_iter,
2801 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2805 if (replace && !found && search && strlen(search) > 2
2806 && search[0] == '\n' && search[1] == '\n') {
2812 g_free(compose->sig_str);
2813 compose->sig_str = compose_get_signature_str(compose);
2814 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2815 compose->sig_str = g_strdup("");
2817 cur_pos = gtk_text_iter_get_offset(&iter);
2819 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2821 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2823 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2824 gtk_text_iter_forward_char(&iter);
2825 gtk_text_iter_forward_char(&iter);
2826 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2827 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2829 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2830 cur_pos = gtk_text_buffer_get_char_count (buffer);
2832 /* put the cursor where it should be
2833 * either where the quote_fmt says, either before the signature */
2834 if (compose->set_cursor_pos < 0)
2835 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2837 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2838 compose->set_cursor_pos);
2840 gtk_text_buffer_place_cursor(buffer, &iter);
2841 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2842 G_CALLBACK(compose_changed_cb),
2845 compose->autowrap = prev_autowrap;
2846 if (compose->autowrap)
2847 compose_wrap_all(compose);
2850 static gchar *compose_get_signature_str(Compose *compose)
2852 gchar *sig_body = NULL;
2853 gchar *sig_str = NULL;
2854 gchar *utf8_sig_str = NULL;
2856 g_return_val_if_fail(compose->account != NULL, NULL);
2858 if (!compose->account->sig_path)
2861 if (compose->account->sig_type == SIG_FILE) {
2862 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2863 g_warning("can't open signature file: %s\n",
2864 compose->account->sig_path);
2869 if (compose->account->sig_type == SIG_COMMAND)
2870 sig_body = get_command_output(compose->account->sig_path);
2874 tmp = file_read_to_str(compose->account->sig_path);
2877 sig_body = normalize_newlines(tmp);
2881 if (compose->account->sig_sep) {
2882 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2886 sig_str = g_strconcat("\n\n", sig_body, NULL);
2889 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2890 utf8_sig_str = sig_str;
2892 utf8_sig_str = conv_codeset_strdup
2893 (sig_str, conv_get_locale_charset_str_no_utf8(),
2899 return utf8_sig_str;
2902 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2905 GtkTextBuffer *buffer;
2908 const gchar *cur_encoding;
2909 gchar buf[BUFFSIZE];
2912 gboolean prev_autowrap;
2913 gboolean badtxt = FALSE;
2915 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2917 if ((fp = g_fopen(file, "rb")) == NULL) {
2918 FILE_OP_ERROR(file, "fopen");
2919 return COMPOSE_INSERT_READ_ERROR;
2922 prev_autowrap = compose->autowrap;
2923 compose->autowrap = FALSE;
2925 text = GTK_TEXT_VIEW(compose->text);
2926 buffer = gtk_text_view_get_buffer(text);
2927 mark = gtk_text_buffer_get_insert(buffer);
2928 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2930 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2931 G_CALLBACK(text_inserted),
2934 cur_encoding = conv_get_locale_charset_str_no_utf8();
2936 while (fgets(buf, sizeof(buf), fp) != NULL) {
2939 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2940 str = g_strdup(buf);
2942 str = conv_codeset_strdup
2943 (buf, cur_encoding, CS_INTERNAL);
2946 /* strip <CR> if DOS/Windows file,
2947 replace <CR> with <LF> if Macintosh file. */
2950 if (len > 0 && str[len - 1] != '\n') {
2952 if (str[len] == '\r') str[len] = '\n';
2955 gtk_text_buffer_insert(buffer, &iter, str, -1);
2959 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2960 G_CALLBACK(text_inserted),
2962 compose->autowrap = prev_autowrap;
2963 if (compose->autowrap)
2964 compose_wrap_all(compose);
2969 return COMPOSE_INSERT_INVALID_CHARACTER;
2971 return COMPOSE_INSERT_SUCCESS;
2974 static void compose_attach_append(Compose *compose, const gchar *file,
2975 const gchar *filename,
2976 const gchar *content_type)
2984 GtkListStore *store;
2986 gboolean has_binary = FALSE;
2988 if (!is_file_exist(file)) {
2989 g_warning("File %s doesn't exist\n", filename);
2992 if ((size = get_file_size(file)) < 0) {
2993 g_warning("Can't get file size of %s\n", filename);
2997 alertpanel_notice(_("File %s is empty."), filename);
3000 if ((fp = g_fopen(file, "rb")) == NULL) {
3001 alertpanel_error(_("Can't read %s."), filename);
3006 ainfo = g_new0(AttachInfo, 1);
3007 auto_ainfo = g_auto_pointer_new_with_free
3008 (ainfo, (GFreeFunc) compose_attach_info_free);
3009 ainfo->file = g_strdup(file);
3012 ainfo->content_type = g_strdup(content_type);
3013 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
3015 MsgFlags flags = {0, 0};
3017 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
3018 ainfo->encoding = ENC_7BIT;
3020 ainfo->encoding = ENC_8BIT;
3022 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
3023 if (msginfo && msginfo->subject)
3024 name = g_strdup(msginfo->subject);
3026 name = g_path_get_basename(filename ? filename : file);
3028 ainfo->name = g_strdup_printf(_("Message: %s"), name);
3030 procmsg_msginfo_free(msginfo);
3032 if (!g_ascii_strncasecmp(content_type, "text", 4))
3033 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
3035 ainfo->encoding = ENC_BASE64;
3036 name = g_path_get_basename(filename ? filename : file);
3037 ainfo->name = g_strdup(name);
3041 ainfo->content_type = procmime_get_mime_type(file);
3042 if (!ainfo->content_type) {
3043 ainfo->content_type =
3044 g_strdup("application/octet-stream");
3045 ainfo->encoding = ENC_BASE64;
3046 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
3048 procmime_get_encoding_for_text_file(file, &has_binary);
3050 ainfo->encoding = ENC_BASE64;
3051 name = g_path_get_basename(filename ? filename : file);
3052 ainfo->name = g_strdup(name);
3056 if (ainfo->name != NULL
3057 && !strcmp(ainfo->name, ".")) {
3058 g_free(ainfo->name);
3062 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
3063 g_free(ainfo->content_type);
3064 ainfo->content_type = g_strdup("application/octet-stream");
3068 size_text = to_human_readable(size);
3070 store = GTK_LIST_STORE(gtk_tree_view_get_model
3071 (GTK_TREE_VIEW(compose->attach_clist)));
3073 gtk_list_store_append(store, &iter);
3074 gtk_list_store_set(store, &iter,
3075 COL_MIMETYPE, ainfo->content_type,
3076 COL_SIZE, size_text,
3077 COL_NAME, ainfo->name,
3079 COL_AUTODATA, auto_ainfo,
3082 g_auto_pointer_free(auto_ainfo);
3085 static void compose_use_signing(Compose *compose, gboolean use_signing)
3087 GtkItemFactory *ifactory;
3088 GtkWidget *menuitem = NULL;
3090 compose->use_signing = use_signing;
3091 ifactory = gtk_item_factory_from_widget(compose->menubar);
3092 menuitem = gtk_item_factory_get_item
3093 (ifactory, "/Options/Sign");
3094 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3098 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3100 GtkItemFactory *ifactory;
3101 GtkWidget *menuitem = NULL;
3103 compose->use_encryption = use_encryption;
3104 ifactory = gtk_item_factory_from_widget(compose->menubar);
3105 menuitem = gtk_item_factory_get_item
3106 (ifactory, "/Options/Encrypt");
3108 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3112 #define NEXT_PART_NOT_CHILD(info) \
3114 node = info->node; \
3115 while (node->children) \
3116 node = g_node_last_child(node); \
3117 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3120 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3124 MimeInfo *firsttext = NULL;
3125 MimeInfo *encrypted = NULL;
3128 const gchar *partname = NULL;
3130 mimeinfo = procmime_scan_message(msginfo);
3131 if (!mimeinfo) return;
3133 if (mimeinfo->node->children == NULL) {
3134 procmime_mimeinfo_free_all(mimeinfo);
3138 /* find first content part */
3139 child = (MimeInfo *) mimeinfo->node->children->data;
3140 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3141 child = (MimeInfo *)child->node->children->data;
3143 if (child->type == MIMETYPE_TEXT) {
3145 debug_print("First text part found\n");
3146 } else if (compose->mode == COMPOSE_REEDIT &&
3147 child->type == MIMETYPE_APPLICATION &&
3148 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3149 encrypted = (MimeInfo *)child->node->parent->data;
3152 child = (MimeInfo *) mimeinfo->node->children->data;
3153 while (child != NULL) {
3154 if (child == encrypted) {
3155 /* skip this part of tree */
3156 NEXT_PART_NOT_CHILD(child);
3160 if (child->type == MIMETYPE_MULTIPART) {
3161 /* get the actual content */
3162 child = procmime_mimeinfo_next(child);
3166 if (child == firsttext) {
3167 child = procmime_mimeinfo_next(child);
3171 outfile = procmime_get_tmp_file_name(child);
3172 if (procmime_get_part(outfile, child) < 0)
3173 g_warning("Can't get the part of multipart message.");
3175 gchar *content_type;
3177 content_type = procmime_get_content_type_str(child->type, child->subtype);
3179 /* if we meet a pgp signature, we don't attach it, but
3180 * we force signing. */
3181 if (strcmp(content_type, "application/pgp-signature")) {
3182 partname = procmime_mimeinfo_get_parameter(child, "filename");
3183 if (partname == NULL)
3184 partname = procmime_mimeinfo_get_parameter(child, "name");
3185 if (partname == NULL)
3187 compose_attach_append(compose, outfile,
3188 partname, content_type);
3190 compose_force_signing(compose, compose->account);
3192 g_free(content_type);
3195 NEXT_PART_NOT_CHILD(child);
3197 procmime_mimeinfo_free_all(mimeinfo);
3200 #undef NEXT_PART_NOT_CHILD
3205 WAIT_FOR_INDENT_CHAR,
3206 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3209 /* return indent length, we allow:
3210 indent characters followed by indent characters or spaces/tabs,
3211 alphabets and numbers immediately followed by indent characters,
3212 and the repeating sequences of the above
3213 If quote ends with multiple spaces, only the first one is included. */
3214 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3215 const GtkTextIter *start, gint *len)
3217 GtkTextIter iter = *start;
3221 IndentState state = WAIT_FOR_INDENT_CHAR;
3224 gint alnum_count = 0;
3225 gint space_count = 0;
3228 if (prefs_common.quote_chars == NULL) {
3232 while (!gtk_text_iter_ends_line(&iter)) {
3233 wc = gtk_text_iter_get_char(&iter);
3234 if (g_unichar_iswide(wc))
3236 clen = g_unichar_to_utf8(wc, ch);
3240 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3241 is_space = g_unichar_isspace(wc);
3243 if (state == WAIT_FOR_INDENT_CHAR) {
3244 if (!is_indent && !g_unichar_isalnum(wc))
3247 quote_len += alnum_count + space_count + 1;
3248 alnum_count = space_count = 0;
3249 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3252 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3253 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3257 else if (is_indent) {
3258 quote_len += alnum_count + space_count + 1;
3259 alnum_count = space_count = 0;
3262 state = WAIT_FOR_INDENT_CHAR;
3266 gtk_text_iter_forward_char(&iter);
3269 if (quote_len > 0 && space_count > 0)
3275 if (quote_len > 0) {
3277 gtk_text_iter_forward_chars(&iter, quote_len);
3278 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3284 /* return TRUE if the line is itemized */
3285 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3286 const GtkTextIter *start)
3288 GtkTextIter iter = *start;
3293 if (gtk_text_iter_ends_line(&iter))
3297 wc = gtk_text_iter_get_char(&iter);
3298 if (!g_unichar_isspace(wc))
3300 gtk_text_iter_forward_char(&iter);
3301 if (gtk_text_iter_ends_line(&iter))
3305 clen = g_unichar_to_utf8(wc, ch);
3309 if (!strchr("*-+", ch[0]))
3312 gtk_text_iter_forward_char(&iter);
3313 if (gtk_text_iter_ends_line(&iter))
3315 wc = gtk_text_iter_get_char(&iter);
3316 if (g_unichar_isspace(wc))
3322 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3323 const GtkTextIter *start,
3324 GtkTextIter *break_pos,
3328 GtkTextIter iter = *start, line_end = *start;
3329 PangoLogAttr *attrs;
3336 gboolean can_break = FALSE;
3337 gboolean do_break = FALSE;
3338 gboolean was_white = FALSE;
3339 gboolean prev_dont_break = FALSE;
3341 gtk_text_iter_forward_to_line_end(&line_end);
3342 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3343 len = g_utf8_strlen(str, -1);
3344 /* g_print("breaking line: %d: %s (len = %d)\n",
3345 gtk_text_iter_get_line(&iter), str, len); */
3346 attrs = g_new(PangoLogAttr, len + 1);
3348 pango_default_break(str, -1, NULL, attrs, len + 1);
3352 /* skip quote and leading spaces */
3353 for (i = 0; *p != '\0' && i < len; i++) {
3356 wc = g_utf8_get_char(p);
3357 if (i >= quote_len && !g_unichar_isspace(wc))
3359 if (g_unichar_iswide(wc))
3361 else if (*p == '\t')
3365 p = g_utf8_next_char(p);
3368 for (; *p != '\0' && i < len; i++) {
3369 PangoLogAttr *attr = attrs + i;
3373 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3376 was_white = attr->is_white;
3378 /* don't wrap URI */
3379 if ((uri_len = get_uri_len(p)) > 0) {
3381 if (pos > 0 && col > max_col) {
3391 wc = g_utf8_get_char(p);
3392 if (g_unichar_iswide(wc)) {
3394 if (prev_dont_break && can_break && attr->is_line_break)
3396 } else if (*p == '\t')
3400 if (pos > 0 && col > max_col) {
3405 if (*p == '-' || *p == '/')
3406 prev_dont_break = TRUE;
3408 prev_dont_break = FALSE;
3410 p = g_utf8_next_char(p);
3414 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3419 *break_pos = *start;
3420 gtk_text_iter_set_line_offset(break_pos, pos);
3425 static gboolean compose_join_next_line(Compose *compose,
3426 GtkTextBuffer *buffer,
3428 const gchar *quote_str)
3430 GtkTextIter iter_ = *iter, cur, prev, next, end;
3431 PangoLogAttr attrs[3];
3433 gchar *next_quote_str;
3436 gboolean keep_cursor = FALSE;
3438 if (!gtk_text_iter_forward_line(&iter_) ||
3439 gtk_text_iter_ends_line(&iter_))
3442 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3444 if ((quote_str || next_quote_str) &&
3445 strcmp2(quote_str, next_quote_str) != 0) {
3446 g_free(next_quote_str);
3449 g_free(next_quote_str);
3452 if (quote_len > 0) {
3453 gtk_text_iter_forward_chars(&end, quote_len);
3454 if (gtk_text_iter_ends_line(&end))
3458 /* don't join itemized lines */
3459 if (compose_is_itemized(buffer, &end))
3462 /* don't join signature separator */
3463 if (compose_is_sig_separator(compose, buffer, &iter_))
3466 /* delete quote str */
3468 gtk_text_buffer_delete(buffer, &iter_, &end);
3470 /* don't join line breaks put by the user */
3472 gtk_text_iter_backward_char(&cur);
3473 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3474 gtk_text_iter_forward_char(&cur);
3478 gtk_text_iter_forward_char(&cur);
3479 /* delete linebreak and extra spaces */
3480 while (gtk_text_iter_backward_char(&cur)) {
3481 wc1 = gtk_text_iter_get_char(&cur);
3482 if (!g_unichar_isspace(wc1))
3487 while (!gtk_text_iter_ends_line(&cur)) {
3488 wc1 = gtk_text_iter_get_char(&cur);
3489 if (!g_unichar_isspace(wc1))
3491 gtk_text_iter_forward_char(&cur);
3494 if (!gtk_text_iter_equal(&prev, &next)) {
3497 mark = gtk_text_buffer_get_insert(buffer);
3498 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3499 if (gtk_text_iter_equal(&prev, &cur))
3501 gtk_text_buffer_delete(buffer, &prev, &next);
3505 /* insert space if required */
3506 gtk_text_iter_backward_char(&prev);
3507 wc1 = gtk_text_iter_get_char(&prev);
3508 wc2 = gtk_text_iter_get_char(&next);
3509 gtk_text_iter_forward_char(&next);
3510 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3511 pango_default_break(str, -1, NULL, attrs, 3);
3512 if (!attrs[1].is_line_break ||
3513 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3514 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3516 gtk_text_iter_backward_char(&iter_);
3517 gtk_text_buffer_place_cursor(buffer, &iter_);
3526 #define ADD_TXT_POS(bp_, ep_, pti_) \
3527 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3528 last = last->next; \
3529 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3530 last->next = NULL; \
3532 g_warning("alloc error scanning URIs\n"); \
3535 static gboolean automatic_break = FALSE;
3536 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3538 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3539 GtkTextBuffer *buffer;
3540 GtkTextIter iter, break_pos, end_of_line;
3541 gchar *quote_str = NULL;
3543 gboolean wrap_quote = prefs_common.linewrap_quote;
3544 gboolean prev_autowrap = compose->autowrap;
3545 gint startq_offset = -1, noq_offset = -1;
3546 gint uri_start = -1, uri_stop = -1;
3547 gint nouri_start = -1, nouri_stop = -1;
3548 gint num_blocks = 0;
3549 gint quotelevel = -1;
3551 compose->autowrap = FALSE;
3553 buffer = gtk_text_view_get_buffer(text);
3554 undo_wrapping(compose->undostruct, TRUE);
3559 mark = gtk_text_buffer_get_insert(buffer);
3560 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3563 /* move to paragraph start */
3564 gtk_text_iter_set_line_offset(&iter, 0);
3565 if (gtk_text_iter_ends_line(&iter)) {
3566 while (gtk_text_iter_ends_line(&iter) &&
3567 gtk_text_iter_forward_line(&iter))
3570 while (gtk_text_iter_backward_line(&iter)) {
3571 if (gtk_text_iter_ends_line(&iter)) {
3572 gtk_text_iter_forward_line(&iter);
3578 /* go until paragraph end (empty line) */
3580 while (!gtk_text_iter_ends_line(&iter)) {
3581 gchar *scanpos = NULL;
3582 /* parse table - in order of priority */
3584 const gchar *needle; /* token */
3586 /* token search function */
3587 gchar *(*search) (const gchar *haystack,
3588 const gchar *needle);
3589 /* part parsing function */
3590 gboolean (*parse) (const gchar *start,
3591 const gchar *scanpos,
3595 /* part to URI function */
3596 gchar *(*build_uri) (const gchar *bp,
3600 static struct table parser[] = {
3601 {"http://", strcasestr, get_uri_part, make_uri_string},
3602 {"https://", strcasestr, get_uri_part, make_uri_string},
3603 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3604 {"sftp://", strcasestr, get_uri_part, make_uri_string},
3605 {"www.", strcasestr, get_uri_part, make_http_string},
3606 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3607 {"@", strcasestr, get_email_part, make_email_string}
3609 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3610 gint last_index = PARSE_ELEMS;
3612 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3615 if (!prev_autowrap && num_blocks == 0) {
3617 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3618 G_CALLBACK(text_inserted),
3621 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3624 uri_start = uri_stop = -1;
3626 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3630 if (startq_offset == -1) {
3631 startq_offset = gtk_text_iter_get_offset(&iter);
3635 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3636 if (startq_offset == -1)
3637 startq_offset = gtk_text_iter_get_offset(&iter);
3638 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3639 if (quotelevel > 2) {
3640 /* recycle colors */
3641 if (prefs_common.recycle_quote_colors)
3647 if (startq_offset == -1)
3648 noq_offset = gtk_text_iter_get_offset(&iter);
3652 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3655 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3656 prefs_common.linewrap_len,
3658 GtkTextIter prev, next, cur;
3660 if (prev_autowrap != FALSE || force) {
3661 automatic_break = TRUE;
3662 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3663 automatic_break = FALSE;
3664 } else if (quote_str && wrap_quote) {
3665 automatic_break = TRUE;
3666 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3667 automatic_break = FALSE;
3670 /* remove trailing spaces */
3672 gtk_text_iter_backward_char(&cur);
3674 while (!gtk_text_iter_starts_line(&cur)) {
3677 gtk_text_iter_backward_char(&cur);
3678 wc = gtk_text_iter_get_char(&cur);
3679 if (!g_unichar_isspace(wc))
3683 if (!gtk_text_iter_equal(&prev, &next)) {
3684 gtk_text_buffer_delete(buffer, &prev, &next);
3686 gtk_text_iter_forward_char(&break_pos);
3690 gtk_text_buffer_insert(buffer, &break_pos,
3694 compose_join_next_line(compose, buffer, &iter, quote_str);
3696 /* move iter to current line start */
3697 gtk_text_iter_set_line_offset(&iter, 0);
3704 /* move iter to next line start */
3709 if (!prev_autowrap && num_blocks > 0) {
3711 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3712 G_CALLBACK(text_inserted),
3716 while (!gtk_text_iter_ends_line(&end_of_line)) {
3717 gtk_text_iter_forward_char(&end_of_line);
3719 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3721 nouri_start = gtk_text_iter_get_offset(&iter);
3722 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3724 walk_pos = gtk_text_iter_get_offset(&iter);
3725 /* FIXME: this looks phony. scanning for anything in the parse table */
3726 for (n = 0; n < PARSE_ELEMS; n++) {
3729 tmp = parser[n].search(walk, parser[n].needle);
3731 if (scanpos == NULL || tmp < scanpos) {
3740 /* check if URI can be parsed */
3741 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3742 (const gchar **)&ep, FALSE)
3743 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3747 strlen(parser[last_index].needle);
3750 uri_start = walk_pos + (bp - o_walk);
3751 uri_stop = walk_pos + (ep - o_walk);
3755 gtk_text_iter_forward_line(&iter);
3758 if (startq_offset != -1) {
3759 GtkTextIter startquote, endquote;
3760 gtk_text_buffer_get_iter_at_offset(
3761 buffer, &startquote, startq_offset);
3763 switch (quotelevel) {
3764 case 0: gtk_text_buffer_apply_tag_by_name(
3765 buffer, "quote0", &startquote, &endquote);
3767 case 1: gtk_text_buffer_apply_tag_by_name(
3768 buffer, "quote1", &startquote, &endquote);
3770 case 2: gtk_text_buffer_apply_tag_by_name(
3771 buffer, "quote2", &startquote, &endquote);
3775 } else if (noq_offset != -1) {
3776 GtkTextIter startnoquote, endnoquote;
3777 gtk_text_buffer_get_iter_at_offset(
3778 buffer, &startnoquote, noq_offset);
3780 gtk_text_buffer_remove_tag_by_name(
3781 buffer, "quote0", &startnoquote, &endnoquote);
3782 gtk_text_buffer_remove_tag_by_name(
3783 buffer, "quote1", &startnoquote, &endnoquote);
3784 gtk_text_buffer_remove_tag_by_name(
3785 buffer, "quote2", &startnoquote, &endnoquote);
3790 GtkTextIter nouri_start_iter, nouri_end_iter;
3791 gtk_text_buffer_get_iter_at_offset(
3792 buffer, &nouri_start_iter, nouri_start);
3793 gtk_text_buffer_get_iter_at_offset(
3794 buffer, &nouri_end_iter, nouri_stop);
3795 gtk_text_buffer_remove_tag_by_name(
3796 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3798 if (uri_start > 0 && uri_stop > 0) {
3799 GtkTextIter uri_start_iter, uri_end_iter;
3800 gtk_text_buffer_get_iter_at_offset(
3801 buffer, &uri_start_iter, uri_start);
3802 gtk_text_buffer_get_iter_at_offset(
3803 buffer, &uri_end_iter, uri_stop);
3804 gtk_text_buffer_apply_tag_by_name(
3805 buffer, "link", &uri_start_iter, &uri_end_iter);
3811 undo_wrapping(compose->undostruct, FALSE);
3812 compose->autowrap = prev_autowrap;
3815 void compose_action_cb(void *data)
3817 Compose *compose = (Compose *)data;
3818 compose_wrap_all(compose);
3821 static void compose_wrap_all(Compose *compose)
3823 compose_wrap_all_full(compose, FALSE);
3826 static void compose_wrap_all_full(Compose *compose, gboolean force)
3828 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3829 GtkTextBuffer *buffer;
3832 buffer = gtk_text_view_get_buffer(text);
3834 gtk_text_buffer_get_start_iter(buffer, &iter);
3835 while (!gtk_text_iter_is_end(&iter))
3836 compose_beautify_paragraph(compose, &iter, force);
3840 static void compose_set_title(Compose *compose)
3846 edited = compose->modified ? _(" [Edited]") : "";
3848 subject = gtk_editable_get_chars(
3849 GTK_EDITABLE(compose->subject_entry), 0, -1);
3851 if (subject && strlen(subject))
3852 str = g_strdup_printf(_("%s - Compose message%s"),
3855 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3856 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3862 * compose_current_mail_account:
3864 * Find a current mail account (the currently selected account, or the
3865 * default account, if a news account is currently selected). If a
3866 * mail account cannot be found, display an error message.
3868 * Return value: Mail account, or NULL if not found.
3870 static PrefsAccount *
3871 compose_current_mail_account(void)
3875 if (cur_account && cur_account->protocol != A_NNTP)
3878 ac = account_get_default();
3879 if (!ac || ac->protocol == A_NNTP) {
3880 alertpanel_error(_("Account for sending mail is not specified.\n"
3881 "Please select a mail account before sending."));
3888 #define QUOTE_IF_REQUIRED(out, str) \
3890 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3894 len = strlen(str) + 3; \
3895 if ((__tmp = alloca(len)) == NULL) { \
3896 g_warning("can't allocate memory\n"); \
3897 g_string_free(header, TRUE); \
3900 g_snprintf(__tmp, len, "\"%s\"", str); \
3905 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3906 g_warning("can't allocate memory\n"); \
3907 g_string_free(header, TRUE); \
3910 strcpy(__tmp, str); \
3916 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
3918 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3922 len = strlen(str) + 3; \
3923 if ((__tmp = alloca(len)) == NULL) { \
3924 g_warning("can't allocate memory\n"); \
3927 g_snprintf(__tmp, len, "\"%s\"", str); \
3932 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3933 g_warning("can't allocate memory\n"); \
3936 strcpy(__tmp, str); \
3942 static void compose_select_account(Compose *compose, PrefsAccount *account,
3945 GtkItemFactory *ifactory;
3948 g_return_if_fail(account != NULL);
3950 compose->account = account;
3952 if (account->name && *account->name) {
3954 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
3955 from = g_strdup_printf("%s <%s>",
3956 buf, account->address);
3957 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3959 from = g_strdup_printf("<%s>",
3961 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3966 compose_set_title(compose);
3968 ifactory = gtk_item_factory_from_widget(compose->menubar);
3970 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3971 menu_set_active(ifactory, "/Options/Sign", TRUE);
3973 menu_set_active(ifactory, "/Options/Sign", FALSE);
3974 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3975 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3977 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3979 activate_privacy_system(compose, account, FALSE);
3981 if (!init && compose->mode != COMPOSE_REDIRECT) {
3982 undo_block(compose->undostruct);
3983 compose_insert_sig(compose, TRUE);
3984 undo_unblock(compose->undostruct);
3988 gboolean compose_check_for_valid_recipient(Compose *compose) {
3989 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3990 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3991 gboolean recipient_found = FALSE;
3995 /* free to and newsgroup list */
3996 slist_free_strings(compose->to_list);
3997 g_slist_free(compose->to_list);
3998 compose->to_list = NULL;
4000 slist_free_strings(compose->newsgroup_list);
4001 g_slist_free(compose->newsgroup_list);
4002 compose->newsgroup_list = NULL;
4004 /* search header entries for to and newsgroup entries */
4005 for (list = compose->header_list; list; list = list->next) {
4008 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4009 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4011 if (entry[0] != '\0') {
4012 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
4013 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
4014 compose->to_list = address_list_append(compose->to_list, entry);
4015 recipient_found = TRUE;
4018 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
4019 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
4020 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
4021 recipient_found = TRUE;
4028 return recipient_found;
4031 static gboolean compose_check_for_set_recipients(Compose *compose)
4033 if (compose->account->set_autocc && compose->account->auto_cc) {
4034 gboolean found_other = FALSE;
4036 /* search header entries for to and newsgroup entries */
4037 for (list = compose->header_list; list; list = list->next) {
4040 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4041 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4043 if (strcmp(entry, compose->account->auto_cc)
4044 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
4054 if (compose->batch) {
4055 gtk_widget_show_all(compose->window);
4057 aval = alertpanel(_("Send"),
4058 _("The only recipient is the default CC address. Send anyway?"),
4059 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4060 if (aval != G_ALERTALTERNATE)
4064 if (compose->account->set_autobcc && compose->account->auto_bcc) {
4065 gboolean found_other = FALSE;
4067 /* search header entries for to and newsgroup entries */
4068 for (list = compose->header_list; list; list = list->next) {
4071 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4072 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4074 if (strcmp(entry, compose->account->auto_bcc)
4075 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
4085 if (compose->batch) {
4086 gtk_widget_show_all(compose->window);
4088 aval = alertpanel(_("Send"),
4089 _("The only recipient is the default BCC address. Send anyway?"),
4090 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4091 if (aval != G_ALERTALTERNATE)
4098 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
4102 if (compose_check_for_valid_recipient(compose) == FALSE) {
4103 if (compose->batch) {
4104 gtk_widget_show_all(compose->window);
4106 alertpanel_error(_("Recipient is not specified."));
4110 if (compose_check_for_set_recipients(compose) == FALSE) {
4114 if (!compose->batch) {
4115 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4116 if (*str == '\0' && check_subject == TRUE) {
4119 aval = alertpanel(_("Send"),
4120 _("Subject is empty. Send it anyway?"),
4121 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4122 if (aval != G_ALERTALTERNATE)
4130 gint compose_send(Compose *compose)
4133 FolderItem *folder = NULL;
4135 gchar *msgpath = NULL;
4136 gboolean discard_window = FALSE;
4137 gchar *errstr = NULL;
4138 gchar *tmsgid = NULL;
4139 MainWindow *mainwin = mainwindow_get_mainwindow();
4141 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4142 || compose->batch == TRUE)
4143 discard_window = TRUE;
4145 compose_allow_user_actions (compose, FALSE);
4146 compose->sending = TRUE;
4148 if (compose_check_entries(compose, TRUE) == FALSE) {
4149 if (compose->batch) {
4150 gtk_widget_show_all(compose->window);
4156 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
4159 if (compose->batch) {
4160 gtk_widget_show_all(compose->window);
4163 alertpanel_error(_("Could not queue message for sending:\n\n"
4164 "Charset conversion failed."));
4165 } else if (val == -5) {
4166 alertpanel_error(_("Could not queue message for sending:\n\n"
4167 "Couldn't get recipient encryption key."));
4168 } else if (val == -3) {
4169 if (privacy_peek_error())
4170 alertpanel_error(_("Could not queue message for sending:\n\n"
4171 "Signature failed: %s"), privacy_get_error());
4172 } else if (val == -2 && errno != 0) {
4173 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4175 alertpanel_error(_("Could not queue message for sending."));
4180 tmsgid = g_strdup(compose->msgid);
4181 if (discard_window) {
4182 compose->sending = FALSE;
4183 compose_close(compose);
4184 /* No more compose access in the normal codepath
4185 * after this point! */
4190 alertpanel_error(_("The message was queued but could not be "
4191 "sent.\nUse \"Send queued messages\" from "
4192 "the main window to retry."));
4193 if (!discard_window) {
4200 if (msgpath == NULL) {
4201 msgpath = folder_item_fetch_msg(folder, msgnum);
4202 val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum);
4205 val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum);
4209 if (!discard_window) {
4210 compose->sending = FALSE;
4211 compose_allow_user_actions (compose, TRUE);
4213 folder_item_remove_msg(folder, msgnum);
4214 folder_item_scan(folder);
4216 /* make sure we delete that */
4217 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
4219 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
4220 folder_item_remove_msg(folder, tmp->msgnum);
4221 procmsg_msginfo_free(tmp);
4228 folder_item_remove_msg(folder, msgnum);
4229 folder_item_scan(folder);
4231 /* make sure we delete that */
4232 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
4234 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
4235 folder_item_remove_msg(folder, tmp->msgnum);
4236 procmsg_msginfo_free(tmp);
4239 if (!discard_window)
4240 compose_close(compose);
4243 gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
4244 "the main window to retry."), errstr);
4246 alertpanel_error_log(tmp);
4249 alertpanel_error_log(_("The message was queued but could not be "
4250 "sent.\nUse \"Send queued messages\" from "
4251 "the main window to retry."));
4253 if (!discard_window) {
4262 toolbar_main_set_sensitive(mainwin);
4263 main_window_set_menu_sensitive(mainwin);
4269 compose_allow_user_actions (compose, TRUE);
4270 compose->sending = FALSE;
4271 compose->modified = TRUE;
4272 toolbar_main_set_sensitive(mainwin);
4273 main_window_set_menu_sensitive(mainwin);
4278 static gboolean compose_use_attach(Compose *compose)
4280 GtkTreeModel *model = gtk_tree_view_get_model
4281 (GTK_TREE_VIEW(compose->attach_clist));
4282 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4285 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4288 gchar buf[BUFFSIZE];
4290 gboolean first_to_address;
4291 gboolean first_cc_address;
4293 ComposeHeaderEntry *headerentry;
4294 const gchar *headerentryname;
4298 debug_print("Writing redirect header\n");
4300 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4301 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4303 first_to_address = TRUE;
4304 for (list = compose->header_list; list; list = list->next) {
4305 headerentry = ((ComposeHeaderEntry *)list->data);
4306 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4308 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4309 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4310 Xstrdup_a(str, entstr, return -1);
4312 if (str[0] != '\0') {
4313 compose_convert_header
4314 (compose, buf, sizeof(buf), str,
4315 strlen("Resent-To") + 2, TRUE);
4317 if (first_to_address) {
4318 fprintf(fp, "Resent-To: ");
4319 first_to_address = FALSE;
4323 fprintf(fp, "%s", buf);
4327 if (!first_to_address) {
4331 first_cc_address = TRUE;
4332 for (list = compose->header_list; list; list = list->next) {
4333 headerentry = ((ComposeHeaderEntry *)list->data);
4334 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4336 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4337 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4338 Xstrdup_a(str, strg, return -1);
4340 if (str[0] != '\0') {
4341 compose_convert_header
4342 (compose, buf, sizeof(buf), str,
4343 strlen("Resent-Cc") + 2, TRUE);
4345 if (first_cc_address) {
4346 fprintf(fp, "Resent-Cc: ");
4347 first_cc_address = FALSE;
4351 fprintf(fp, "%s", buf);
4355 if (!first_cc_address) {
4362 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4364 gchar buf[BUFFSIZE];
4366 const gchar *entstr;
4367 /* struct utsname utsbuf; */
4369 g_return_val_if_fail(fp != NULL, -1);
4370 g_return_val_if_fail(compose->account != NULL, -1);
4371 g_return_val_if_fail(compose->account->address != NULL, -1);
4374 get_rfc822_date(buf, sizeof(buf));
4375 fprintf(fp, "Resent-Date: %s\n", buf);
4378 if (compose->account->name && *compose->account->name) {
4379 compose_convert_header
4380 (compose, buf, sizeof(buf), compose->account->name,
4381 strlen("From: "), TRUE);
4382 fprintf(fp, "Resent-From: %s <%s>\n",
4383 buf, compose->account->address);
4385 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4388 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4389 if (*entstr != '\0') {
4390 Xstrdup_a(str, entstr, return -1);
4393 compose_convert_header(compose, buf, sizeof(buf), str,
4394 strlen("Subject: "), FALSE);
4395 fprintf(fp, "Subject: %s\n", buf);
4399 /* Resent-Message-ID */
4400 if (compose->account->gen_msgid) {
4401 generate_msgid(buf, sizeof(buf));
4402 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4403 compose->msgid = g_strdup(buf);
4406 compose_redirect_write_headers_from_headerlist(compose, fp);
4408 /* separator between header and body */
4414 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4418 gchar buf[BUFFSIZE];
4420 gboolean skip = FALSE;
4421 gchar *not_included[]={
4422 "Return-Path:", "Delivered-To:", "Received:",
4423 "Subject:", "X-UIDL:", "AF:",
4424 "NF:", "PS:", "SRH:",
4425 "SFN:", "DSR:", "MID:",
4426 "CFG:", "PT:", "S:",
4427 "RQ:", "SSV:", "NSV:",
4428 "SSH:", "R:", "MAID:",
4429 "NAID:", "RMID:", "FMID:",
4430 "SCF:", "RRCPT:", "NG:",
4431 "X-Sylpheed-Privacy", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt",
4432 "X-Sylpheed-End-Special-Headers:",
4435 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4436 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4440 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4442 for (i = 0; not_included[i] != NULL; i++) {
4443 if (g_ascii_strncasecmp(buf, not_included[i],
4444 strlen(not_included[i])) == 0) {
4451 if (fputs(buf, fdest) == -1)
4454 if (!prefs_common.redirect_keep_from) {
4455 if (g_ascii_strncasecmp(buf, "From:",
4456 strlen("From:")) == 0) {
4457 fputs(" (by way of ", fdest);
4458 if (compose->account->name
4459 && *compose->account->name) {
4460 compose_convert_header
4461 (compose, buf, sizeof(buf),
4462 compose->account->name,
4465 fprintf(fdest, "%s <%s>",
4467 compose->account->address);
4469 fprintf(fdest, "%s",
4470 compose->account->address);
4475 if (fputs("\n", fdest) == -1)
4479 compose_redirect_write_headers(compose, fdest);
4481 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4482 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4495 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
4497 GtkTextBuffer *buffer;
4498 GtkTextIter start, end;
4501 const gchar *out_codeset;
4502 EncodingType encoding;
4503 MimeInfo *mimemsg, *mimetext;
4506 if (action == COMPOSE_WRITE_FOR_SEND)
4507 attach_parts = TRUE;
4509 /* create message MimeInfo */
4510 mimemsg = procmime_mimeinfo_new();
4511 mimemsg->type = MIMETYPE_MESSAGE;
4512 mimemsg->subtype = g_strdup("rfc822");
4513 mimemsg->content = MIMECONTENT_MEM;
4514 mimemsg->tmp = TRUE; /* must free content later */
4515 mimemsg->data.mem = compose_get_header(compose);
4517 /* Create text part MimeInfo */
4518 /* get all composed text */
4519 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4520 gtk_text_buffer_get_start_iter(buffer, &start);
4521 gtk_text_buffer_get_end_iter(buffer, &end);
4522 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4523 if (is_ascii_str(chars)) {
4526 out_codeset = CS_US_ASCII;
4527 encoding = ENC_7BIT;
4529 const gchar *src_codeset = CS_INTERNAL;
4531 out_codeset = conv_get_charset_str(compose->out_encoding);
4534 gchar *test_conv_global_out = NULL;
4535 gchar *test_conv_reply = NULL;
4537 /* automatic mode. be automatic. */
4538 codeconv_set_strict(TRUE);
4540 out_codeset = conv_get_outgoing_charset_str();
4542 debug_print("trying to convert to %s\n", out_codeset);
4543 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4546 if (!test_conv_global_out && compose->orig_charset
4547 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4548 out_codeset = compose->orig_charset;
4549 debug_print("failure; trying to convert to %s\n", out_codeset);
4550 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4553 if (!test_conv_global_out && !test_conv_reply) {
4555 out_codeset = CS_INTERNAL;
4556 debug_print("failure; finally using %s\n", out_codeset);
4558 g_free(test_conv_global_out);
4559 g_free(test_conv_reply);
4560 codeconv_set_strict(FALSE);
4563 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4564 out_codeset = CS_ISO_8859_1;
4566 if (prefs_common.encoding_method == CTE_BASE64)
4567 encoding = ENC_BASE64;
4568 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4569 encoding = ENC_QUOTED_PRINTABLE;
4570 else if (prefs_common.encoding_method == CTE_8BIT)
4571 encoding = ENC_8BIT;
4573 encoding = procmime_get_encoding_for_charset(out_codeset);
4575 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4576 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4578 if (action == COMPOSE_WRITE_FOR_SEND) {
4579 codeconv_set_strict(TRUE);
4580 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4581 codeconv_set_strict(FALSE);
4587 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4588 "to the specified %s charset.\n"
4589 "Send it as %s?"), out_codeset, src_codeset);
4590 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4591 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4594 if (aval != G_ALERTALTERNATE) {
4599 out_codeset = src_codeset;
4605 out_codeset = src_codeset;
4611 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4612 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4613 strstr(buf, "\nFrom ") != NULL) {
4614 encoding = ENC_QUOTED_PRINTABLE;
4618 mimetext = procmime_mimeinfo_new();
4619 mimetext->content = MIMECONTENT_MEM;
4620 mimetext->tmp = TRUE; /* must free content later */
4621 /* dup'ed because procmime_encode_content can turn it into a tmpfile
4622 * and free the data, which we need later. */
4623 mimetext->data.mem = g_strdup(buf);
4624 mimetext->type = MIMETYPE_TEXT;
4625 mimetext->subtype = g_strdup("plain");
4626 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4627 g_strdup(out_codeset));
4629 /* protect trailing spaces when signing message */
4630 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4631 privacy_system_can_sign(compose->privacy_system)) {
4632 encoding = ENC_QUOTED_PRINTABLE;
4635 debug_print("main text: %d bytes encoded as %s in %d\n",
4636 strlen(buf), out_codeset, encoding);
4638 /* check for line length limit */
4639 if (action == COMPOSE_WRITE_FOR_SEND &&
4640 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4641 check_line_length(buf, 1000, &line) < 0) {
4645 msg = g_strdup_printf
4646 (_("Line %d exceeds the line length limit (998 bytes).\n"
4647 "The contents of the message might be broken on the way to the delivery.\n"
4649 "Send it anyway?"), line + 1);
4650 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4652 if (aval != G_ALERTALTERNATE) {
4658 if (encoding != ENC_UNKNOWN)
4659 procmime_encode_content(mimetext, encoding);
4661 /* append attachment parts */
4662 if (compose_use_attach(compose) && attach_parts) {
4663 MimeInfo *mimempart;
4664 gchar *boundary = NULL;
4665 mimempart = procmime_mimeinfo_new();
4666 mimempart->content = MIMECONTENT_EMPTY;
4667 mimempart->type = MIMETYPE_MULTIPART;
4668 mimempart->subtype = g_strdup("mixed");
4672 boundary = generate_mime_boundary(NULL);
4673 } while (strstr(buf, boundary) != NULL);
4675 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4678 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4680 g_node_append(mimempart->node, mimetext->node);
4681 g_node_append(mimemsg->node, mimempart->node);
4683 compose_add_attachments(compose, mimempart);
4685 g_node_append(mimemsg->node, mimetext->node);
4689 /* sign message if sending */
4690 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4691 privacy_system_can_sign(compose->privacy_system))
4692 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4695 procmime_write_mimeinfo(mimemsg, fp);
4697 procmime_mimeinfo_free_all(mimemsg);
4702 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4704 GtkTextBuffer *buffer;
4705 GtkTextIter start, end;
4710 if ((fp = g_fopen(file, "wb")) == NULL) {
4711 FILE_OP_ERROR(file, "fopen");
4715 /* chmod for security */
4716 if (change_file_mode_rw(fp, file) < 0) {
4717 FILE_OP_ERROR(file, "chmod");
4718 g_warning("can't change file mode\n");
4721 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4722 gtk_text_buffer_get_start_iter(buffer, &start);
4723 gtk_text_buffer_get_end_iter(buffer, &end);
4724 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4726 chars = conv_codeset_strdup
4727 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4730 if (!chars) return -1;
4733 len = strlen(chars);
4734 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4735 FILE_OP_ERROR(file, "fwrite");
4744 if (fclose(fp) == EOF) {
4745 FILE_OP_ERROR(file, "fclose");
4752 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4755 MsgInfo *msginfo = compose->targetinfo;
4757 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4758 if (!msginfo) return -1;
4760 if (!force && MSG_IS_LOCKED(msginfo->flags))
4763 item = msginfo->folder;
4764 g_return_val_if_fail(item != NULL, -1);
4766 if (procmsg_msg_exist(msginfo) &&
4767 (folder_has_parent_of_type(item, F_QUEUE) ||
4768 folder_has_parent_of_type(item, F_DRAFT)
4769 || msginfo == compose->autosaved_draft)) {
4770 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4771 g_warning("can't remove the old message\n");
4779 void compose_remove_draft(Compose *compose)
4782 MsgInfo *msginfo = compose->targetinfo;
4783 drafts = account_get_special_folder(compose->account, F_DRAFT);
4785 if (procmsg_msg_exist(msginfo)) {
4786 folder_item_remove_msg(drafts, msginfo->msgnum);
4791 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
4792 gboolean remove_reedit_target)
4794 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
4796 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
4797 gchar **msgpath, gboolean check_subject,
4798 gboolean remove_reedit_target)
4805 static gboolean lock = FALSE;
4806 PrefsAccount *mailac = NULL, *newsac = NULL;
4808 debug_print("queueing message...\n");
4809 g_return_val_if_fail(compose->account != NULL, -1);
4813 if (compose_check_entries(compose, check_subject) == FALSE) {
4815 if (compose->batch) {
4816 gtk_widget_show_all(compose->window);
4821 if (!compose->to_list && !compose->newsgroup_list) {
4822 g_warning("can't get recipient list.");
4827 if (compose->to_list) {
4828 if (compose->account->protocol != A_NNTP)
4829 mailac = compose->account;
4830 else if (cur_account && cur_account->protocol != A_NNTP)
4831 mailac = cur_account;
4832 else if (!(mailac = compose_current_mail_account())) {
4834 alertpanel_error(_("No account for sending mails available!"));
4839 if (compose->newsgroup_list) {
4840 if (compose->account->protocol == A_NNTP)
4841 newsac = compose->account;
4842 else if (!newsac->protocol != A_NNTP) {
4844 alertpanel_error(_("No account for posting news available!"));
4849 /* write queue header */
4850 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4851 G_DIR_SEPARATOR, compose);
4852 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4853 FILE_OP_ERROR(tmp, "fopen");
4859 if (change_file_mode_rw(fp, tmp) < 0) {
4860 FILE_OP_ERROR(tmp, "chmod");
4861 g_warning("can't change file mode\n");
4864 /* queueing variables */
4865 fprintf(fp, "AF:\n");
4866 fprintf(fp, "NF:0\n");
4867 fprintf(fp, "PS:10\n");
4868 fprintf(fp, "SRH:1\n");
4869 fprintf(fp, "SFN:\n");
4870 fprintf(fp, "DSR:\n");
4872 fprintf(fp, "MID:<%s>\n", compose->msgid);
4874 fprintf(fp, "MID:\n");
4875 fprintf(fp, "CFG:\n");
4876 fprintf(fp, "PT:0\n");
4877 fprintf(fp, "S:%s\n", compose->account->address);
4878 fprintf(fp, "RQ:\n");
4880 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4882 fprintf(fp, "SSV:\n");
4884 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4886 fprintf(fp, "NSV:\n");
4887 fprintf(fp, "SSH:\n");
4888 /* write recepient list */
4889 if (compose->to_list) {
4890 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4891 for (cur = compose->to_list->next; cur != NULL;
4893 fprintf(fp, ",<%s>", (gchar *)cur->data);
4896 /* write newsgroup list */
4897 if (compose->newsgroup_list) {
4899 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4900 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4901 fprintf(fp, ",%s", (gchar *)cur->data);
4904 /* Sylpheed account IDs */
4906 fprintf(fp, "MAID:%d\n", mailac->account_id);
4908 fprintf(fp, "NAID:%d\n", newsac->account_id);
4911 if (compose->privacy_system != NULL) {
4912 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4913 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4914 if (compose->use_encryption) {
4916 if (mailac && mailac->encrypt_to_self) {
4917 GSList *tmp_list = g_slist_copy(compose->to_list);
4918 tmp_list = g_slist_append(tmp_list, compose->account->address);
4919 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
4920 g_slist_free(tmp_list);
4922 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4924 if (encdata != NULL) {
4925 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4926 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4927 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4929 } /* else we finally dont want to encrypt */
4931 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4932 /* and if encdata was null, it means there's been a problem in
4944 /* Save copy folder */
4945 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4946 gchar *savefolderid;
4948 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4949 fprintf(fp, "SCF:%s\n", savefolderid);
4950 g_free(savefolderid);
4952 /* Save copy folder */
4953 if (compose->return_receipt) {
4954 fprintf(fp, "RRCPT:1\n");
4956 /* Message-ID of message replying to */
4957 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4960 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4961 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4964 /* Message-ID of message forwarding to */
4965 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4968 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4969 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4973 /* end of headers */
4974 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
4976 if (compose->redirect_filename != NULL) {
4977 if (compose_redirect_write_to_file(compose, fp) < 0) {
4986 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
4991 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4995 if (fclose(fp) == EOF) {
4996 FILE_OP_ERROR(tmp, "fclose");
5003 if (item && *item) {
5006 queue = account_get_special_folder(compose->account, F_QUEUE);
5009 g_warning("can't find queue folder\n");
5015 folder_item_scan(queue);
5016 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
5017 g_warning("can't queue the message\n");
5024 if (msgpath == NULL) {
5030 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
5031 compose_remove_reedit_target(compose, FALSE);
5034 if ((msgnum != NULL) && (item != NULL)) {
5042 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
5045 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5047 struct stat statbuf;
5048 gchar *type, *subtype;
5049 GtkTreeModel *model;
5052 model = gtk_tree_view_get_model(tree_view);
5054 if (!gtk_tree_model_get_iter_first(model, &iter))
5057 gtk_tree_model_get(model, &iter,
5061 mimepart = procmime_mimeinfo_new();
5062 mimepart->content = MIMECONTENT_FILE;
5063 mimepart->data.filename = g_strdup(ainfo->file);
5064 mimepart->tmp = FALSE; /* or we destroy our attachment */
5065 mimepart->offset = 0;
5067 stat(ainfo->file, &statbuf);
5068 mimepart->length = statbuf.st_size;
5070 type = g_strdup(ainfo->content_type);
5072 if (!strchr(type, '/')) {
5074 type = g_strdup("application/octet-stream");
5077 subtype = strchr(type, '/') + 1;
5078 *(subtype - 1) = '\0';
5079 mimepart->type = procmime_get_media_type(type);
5080 mimepart->subtype = g_strdup(subtype);
5083 if (mimepart->type == MIMETYPE_MESSAGE &&
5084 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
5085 mimepart->disposition = DISPOSITIONTYPE_INLINE;
5088 g_hash_table_insert(mimepart->typeparameters,
5089 g_strdup("name"), g_strdup(ainfo->name));
5090 g_hash_table_insert(mimepart->dispositionparameters,
5091 g_strdup("filename"), g_strdup(ainfo->name));
5092 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
5096 if (compose->use_signing) {
5097 if (ainfo->encoding == ENC_7BIT)
5098 ainfo->encoding = ENC_QUOTED_PRINTABLE;
5099 else if (ainfo->encoding == ENC_8BIT)
5100 ainfo->encoding = ENC_BASE64;
5103 procmime_encode_content(mimepart, ainfo->encoding);
5105 g_node_append(parent->node, mimepart->node);
5106 } while (gtk_tree_model_iter_next(model, &iter));
5109 #define IS_IN_CUSTOM_HEADER(header) \
5110 (compose->account->add_customhdr && \
5111 custom_header_find(compose->account->customhdr_list, header) != NULL)
5113 static void compose_add_headerfield_from_headerlist(Compose *compose,
5115 const gchar *fieldname,
5116 const gchar *seperator)
5118 gchar *str, *fieldname_w_colon, *trans_fieldname;
5119 gboolean add_field = FALSE;
5121 ComposeHeaderEntry *headerentry;
5122 const gchar * headerentryname;
5125 if (IS_IN_CUSTOM_HEADER(fieldname))
5128 debug_print("Adding %s-fields\n", fieldname);
5130 fieldstr = g_string_sized_new(64);
5132 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
5133 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
5135 for (list = compose->header_list; list; list = list->next) {
5136 headerentry = ((ComposeHeaderEntry *)list->data);
5137 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
5139 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
5140 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
5142 if (str[0] != '\0') {
5144 g_string_append(fieldstr, seperator);
5145 g_string_append(fieldstr, str);
5154 buf = g_new0(gchar, fieldstr->len * 4 + 256);
5155 compose_convert_header
5156 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
5157 strlen(fieldname) + 2, TRUE);
5158 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
5162 g_free(fieldname_w_colon);
5163 g_string_free(fieldstr, TRUE);
5168 static gchar *compose_get_header(Compose *compose)
5170 gchar buf[BUFFSIZE];
5171 const gchar *entry_str;
5175 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5177 gchar *from_name = NULL, *from_address = NULL;
5180 g_return_val_if_fail(compose->account != NULL, NULL);
5181 g_return_val_if_fail(compose->account->address != NULL, NULL);
5183 header = g_string_sized_new(64);
5186 get_rfc822_date(buf, sizeof(buf));
5187 g_string_append_printf(header, "Date: %s\n", buf);
5191 if (compose->account->name && *compose->account->name) {
5193 QUOTE_IF_REQUIRED(buf, compose->account->name);
5194 tmp = g_strdup_printf("%s <%s>",
5195 buf, compose->account->address);
5197 tmp = g_strdup_printf("%s",
5198 compose->account->address);
5200 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5201 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5203 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5204 from_address = g_strdup(compose->account->address);
5206 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5207 /* extract name and address */
5208 if (strstr(spec, " <") && strstr(spec, ">")) {
5209 from_address = g_strdup(strrchr(spec, '<')+1);
5210 *(strrchr(from_address, '>')) = '\0';
5211 from_name = g_strdup(spec);
5212 *(strrchr(from_name, '<')) = '\0';
5215 from_address = g_strdup(spec);
5222 if (from_name && *from_name) {
5223 compose_convert_header
5224 (compose, buf, sizeof(buf), from_name,
5225 strlen("From: "), TRUE);
5226 QUOTE_IF_REQUIRED(name, buf);
5228 g_string_append_printf(header, "From: %s <%s>\n",
5229 name, from_address);
5231 g_string_append_printf(header, "From: %s\n", from_address);
5234 g_free(from_address);
5237 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5240 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5243 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5246 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5249 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5251 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5254 compose_convert_header(compose, buf, sizeof(buf), str,
5255 strlen("Subject: "), FALSE);
5256 g_string_append_printf(header, "Subject: %s\n", buf);
5262 if (compose->account->gen_msgid) {
5263 generate_msgid(buf, sizeof(buf));
5264 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5265 compose->msgid = g_strdup(buf);
5268 if (compose->remove_references == FALSE) {
5270 if (compose->inreplyto && compose->to_list)
5271 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5274 if (compose->references)
5275 g_string_append_printf(header, "References: %s\n", compose->references);
5279 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5282 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5285 if (compose->account->organization &&
5286 strlen(compose->account->organization) &&
5287 !IS_IN_CUSTOM_HEADER("Organization")) {
5288 compose_convert_header(compose, buf, sizeof(buf),
5289 compose->account->organization,
5290 strlen("Organization: "), FALSE);
5291 g_string_append_printf(header, "Organization: %s\n", buf);
5294 /* Program version and system info */
5295 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5296 !compose->newsgroup_list) {
5297 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5299 gtk_major_version, gtk_minor_version, gtk_micro_version,
5302 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5303 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5305 gtk_major_version, gtk_minor_version, gtk_micro_version,
5309 /* custom headers */
5310 if (compose->account->add_customhdr) {
5313 for (cur = compose->account->customhdr_list; cur != NULL;
5315 CustomHeader *chdr = (CustomHeader *)cur->data;
5317 if (custom_header_is_allowed(chdr->name)) {
5318 compose_convert_header
5319 (compose, buf, sizeof(buf),
5320 chdr->value ? chdr->value : "",
5321 strlen(chdr->name) + 2, FALSE);
5322 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5328 switch (compose->priority) {
5329 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5330 "X-Priority: 1 (Highest)\n");
5332 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5333 "X-Priority: 2 (High)\n");
5335 case PRIORITY_NORMAL: break;
5336 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5337 "X-Priority: 4 (Low)\n");
5339 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5340 "X-Priority: 5 (Lowest)\n");
5342 default: debug_print("compose: priority unknown : %d\n",
5346 /* Request Return Receipt */
5347 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5348 if (compose->return_receipt) {
5349 if (compose->account->name
5350 && *compose->account->name) {
5351 compose_convert_header(compose, buf, sizeof(buf),
5352 compose->account->name,
5353 strlen("Disposition-Notification-To: "),
5355 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5357 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5361 /* get special headers */
5362 for (list = compose->header_list; list; list = list->next) {
5363 ComposeHeaderEntry *headerentry;
5366 gchar *headername_wcolon;
5367 gchar *headername_trans;
5370 gboolean standard_header = FALSE;
5372 headerentry = ((ComposeHeaderEntry *)list->data);
5374 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5375 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5380 if (!strstr(tmp, ":")) {
5381 headername_wcolon = g_strconcat(tmp, ":", NULL);
5382 headername = g_strdup(tmp);
5384 headername_wcolon = g_strdup(tmp);
5385 headername = g_strdup(strtok(tmp, ":"));
5389 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5390 Xstrdup_a(headervalue, entry_str, return NULL);
5391 subst_char(headervalue, '\r', ' ');
5392 subst_char(headervalue, '\n', ' ');
5393 string = std_headers;
5394 while (*string != NULL) {
5395 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5396 if (!strcmp(headername_trans,headername_wcolon))
5397 standard_header = TRUE;
5400 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5401 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5404 g_free(headername_wcolon);
5408 g_string_free(header, FALSE);
5413 #undef IS_IN_CUSTOM_HEADER
5415 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5416 gint header_len, gboolean addr_field)
5418 gchar *tmpstr = NULL;
5419 const gchar *out_codeset = NULL;
5421 g_return_if_fail(src != NULL);
5422 g_return_if_fail(dest != NULL);
5424 if (len < 1) return;
5426 tmpstr = g_strdup(src);
5428 subst_char(tmpstr, '\n', ' ');
5429 subst_char(tmpstr, '\r', ' ');
5432 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5433 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5434 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5439 codeconv_set_strict(TRUE);
5440 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5441 conv_get_charset_str(compose->out_encoding));
5442 codeconv_set_strict(FALSE);
5444 if (!dest || *dest == '\0') {
5445 gchar *test_conv_global_out = NULL;
5446 gchar *test_conv_reply = NULL;
5448 /* automatic mode. be automatic. */
5449 codeconv_set_strict(TRUE);
5451 out_codeset = conv_get_outgoing_charset_str();
5453 debug_print("trying to convert to %s\n", out_codeset);
5454 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5457 if (!test_conv_global_out && compose->orig_charset
5458 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5459 out_codeset = compose->orig_charset;
5460 debug_print("failure; trying to convert to %s\n", out_codeset);
5461 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5464 if (!test_conv_global_out && !test_conv_reply) {
5466 out_codeset = CS_INTERNAL;
5467 debug_print("finally using %s\n", out_codeset);
5469 g_free(test_conv_global_out);
5470 g_free(test_conv_reply);
5471 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5473 codeconv_set_strict(FALSE);
5478 static void compose_create_header_entry(Compose *compose)
5480 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5484 GList *combo_list = NULL;
5486 const gchar *header = NULL;
5487 ComposeHeaderEntry *headerentry;
5488 gboolean standard_header = FALSE;
5490 headerentry = g_new0(ComposeHeaderEntry, 1);
5493 combo = gtk_combo_new();
5495 while(*string != NULL) {
5496 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5499 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5500 g_list_free(combo_list);
5501 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5502 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5503 G_CALLBACK(compose_grab_focus_cb), compose);
5504 gtk_widget_show(combo);
5505 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5506 if (compose->header_last) {
5507 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5509 while (*string != NULL) {
5510 if (!strcmp(*string, last_header_entry))
5511 standard_header = TRUE;
5514 if (standard_header)
5515 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5517 if (!compose->header_last || !standard_header) {
5518 switch(compose->account->protocol) {
5520 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5523 header = prefs_common.trans_hdr ? _("To:") : "To:";
5528 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5530 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5531 G_CALLBACK(compose_grab_focus_cb), compose);
5534 entry = gtk_entry_new();
5535 gtk_widget_show(entry);
5536 gtk_tooltips_set_tip(compose->tooltips, entry,
5537 _("Use <tab> to autocomplete from addressbook"), NULL);
5538 gtk_table_attach(GTK_TABLE(compose->header_table), entry, 1, 2, compose->header_nextrow, compose->header_nextrow+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
5540 g_signal_connect(G_OBJECT(entry), "key-press-event",
5541 G_CALLBACK(compose_headerentry_key_press_event_cb),
5543 g_signal_connect(G_OBJECT(entry), "changed",
5544 G_CALLBACK(compose_headerentry_changed_cb),
5546 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5547 G_CALLBACK(compose_grab_focus_cb), compose);
5550 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5551 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5552 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5553 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5554 G_CALLBACK(compose_header_drag_received_cb),
5556 g_signal_connect(G_OBJECT(entry), "drag-drop",
5557 G_CALLBACK(compose_drag_drop),
5560 address_completion_register_entry(GTK_ENTRY(entry), TRUE);
5562 headerentry->compose = compose;
5563 headerentry->combo = combo;
5564 headerentry->entry = entry;
5565 headerentry->headernum = compose->header_nextrow;
5567 compose->header_nextrow++;
5568 compose->header_last = headerentry;
5571 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5573 ComposeHeaderEntry *last_header;
5575 last_header = compose->header_last;
5577 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5578 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5581 static void compose_remove_header_entries(Compose *compose)
5584 for (list = compose->header_list; list; list = list->next) {
5585 ComposeHeaderEntry *headerentry =
5586 (ComposeHeaderEntry *)list->data;
5587 gtk_widget_destroy(headerentry->combo);
5588 gtk_widget_destroy(headerentry->entry);
5589 g_free(headerentry);
5591 g_slist_free(compose->header_list);
5592 compose->header_list = NULL;
5593 compose->header_nextrow = 1;
5594 compose_create_header_entry(compose);
5597 static GtkWidget *compose_create_header(Compose *compose)
5599 GtkWidget *from_optmenu_hbox;
5600 GtkWidget *header_scrolledwin;
5601 GtkWidget *header_table;
5605 /* header labels and entries */
5606 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5607 gtk_widget_show(header_scrolledwin);
5608 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5610 header_table = gtk_table_new(2, 2, FALSE);
5611 gtk_widget_show(header_table);
5612 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5613 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5614 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5617 /* option menu for selecting accounts */
5618 from_optmenu_hbox = compose_account_option_menu_create(compose);
5619 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5620 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5623 compose->header_table = header_table;
5624 compose->header_list = NULL;
5625 compose->header_nextrow = count;
5627 compose_create_header_entry(compose);
5629 compose->table = NULL;
5631 return header_scrolledwin ;
5634 GtkWidget *compose_create_attach(Compose *compose)
5636 GtkWidget *attach_scrwin;
5637 GtkWidget *attach_clist;
5639 GtkListStore *store;
5640 GtkCellRenderer *renderer;
5641 GtkTreeViewColumn *column;
5642 GtkTreeSelection *selection;
5644 /* attachment list */
5645 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5646 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5647 GTK_POLICY_AUTOMATIC,
5648 GTK_POLICY_AUTOMATIC);
5649 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5651 store = gtk_list_store_new(N_ATTACH_COLS,
5656 G_TYPE_AUTO_POINTER,
5658 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5659 (GTK_TREE_MODEL(store)));
5660 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5661 g_object_unref(store);
5663 renderer = gtk_cell_renderer_text_new();
5664 column = gtk_tree_view_column_new_with_attributes
5665 (_("Mime type"), renderer, "text",
5666 COL_MIMETYPE, NULL);
5667 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5669 renderer = gtk_cell_renderer_text_new();
5670 column = gtk_tree_view_column_new_with_attributes
5671 (_("Size"), renderer, "text",
5673 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5675 renderer = gtk_cell_renderer_text_new();
5676 column = gtk_tree_view_column_new_with_attributes
5677 (_("Name"), renderer, "text",
5679 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5681 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5682 prefs_common.use_stripes_everywhere);
5683 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5684 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5686 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5687 G_CALLBACK(attach_selected), compose);
5688 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5689 G_CALLBACK(attach_button_pressed), compose);
5690 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5691 G_CALLBACK(attach_key_pressed), compose);
5694 gtk_drag_dest_set(attach_clist,
5695 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5696 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5697 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5698 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5699 G_CALLBACK(compose_attach_drag_received_cb),
5701 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5702 G_CALLBACK(compose_drag_drop),
5705 compose->attach_scrwin = attach_scrwin;
5706 compose->attach_clist = attach_clist;
5708 return attach_scrwin;
5711 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5712 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5714 static GtkWidget *compose_create_others(Compose *compose)
5717 GtkWidget *savemsg_checkbtn;
5718 GtkWidget *savemsg_entry;
5719 GtkWidget *savemsg_select;
5722 gchar *folderidentifier;
5724 /* Table for settings */
5725 table = gtk_table_new(3, 1, FALSE);
5726 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5727 gtk_widget_show(table);
5728 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5731 /* Save Message to folder */
5732 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5733 gtk_widget_show(savemsg_checkbtn);
5734 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5735 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5736 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5738 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5739 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5741 savemsg_entry = gtk_entry_new();
5742 gtk_widget_show(savemsg_entry);
5743 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5744 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5745 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5746 G_CALLBACK(compose_grab_focus_cb), compose);
5747 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5748 folderidentifier = folder_item_get_identifier(account_get_special_folder
5749 (compose->account, F_OUTBOX));
5750 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5751 g_free(folderidentifier);
5754 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5755 gtk_widget_show(savemsg_select);
5756 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5757 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5758 G_CALLBACK(compose_savemsg_select_cb),
5763 compose->savemsg_checkbtn = savemsg_checkbtn;
5764 compose->savemsg_entry = savemsg_entry;
5769 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5771 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5772 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5775 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5780 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5783 path = folder_item_get_identifier(dest);
5785 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5789 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5790 GdkAtom clip, GtkTextIter *insert_place);
5792 #define BLOCK_WRAP() { \
5793 prev_autowrap = compose->autowrap; \
5794 buffer = gtk_text_view_get_buffer( \
5795 GTK_TEXT_VIEW(compose->text)); \
5796 compose->autowrap = FALSE; \
5798 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5799 G_CALLBACK(compose_changed_cb), \
5801 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5802 G_CALLBACK(text_inserted), \
5805 #define UNBLOCK_WRAP() { \
5806 compose->autowrap = prev_autowrap; \
5807 if (compose->autowrap) \
5808 compose_wrap_all(compose); \
5810 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5811 G_CALLBACK(compose_changed_cb), \
5813 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5814 G_CALLBACK(text_inserted), \
5819 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5823 GtkTextBuffer *buffer;
5825 if (event->button == 3) {
5827 GtkTextIter sel_start, sel_end;
5828 gboolean stuff_selected;
5830 /* move the cursor to allow GtkAspell to check the word
5831 * under the mouse */
5832 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5833 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5835 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5838 stuff_selected = gtk_text_buffer_get_selection_bounds(
5839 GTK_TEXT_VIEW(text)->buffer,
5840 &sel_start, &sel_end);
5842 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5843 /* reselect stuff */
5845 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5846 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5847 &sel_start, &sel_end);
5849 return FALSE; /* pass the event so that the right-click goes through */
5852 if (event->button == 2) {
5857 /* get the middle-click position to paste at the correct place */
5858 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5859 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5861 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5864 entry_paste_clipboard(compose, text,
5865 prefs_common.linewrap_pastes,
5866 GDK_SELECTION_PRIMARY, &iter);
5874 static void compose_spell_menu_changed(void *data)
5876 Compose *compose = (Compose *)data;
5878 GtkWidget *menuitem;
5879 GtkWidget *parent_item;
5880 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5881 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5884 if (compose->gtkaspell == NULL)
5887 parent_item = gtk_item_factory_get_item(ifactory,
5888 "/Spelling/Options");
5890 /* setting the submenu removes /Spelling/Options from the factory
5891 * so we need to save it */
5893 if (parent_item == NULL) {
5894 parent_item = compose->aspell_options_menu;
5895 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5897 compose->aspell_options_menu = parent_item;
5899 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5901 spell_menu = g_slist_reverse(spell_menu);
5902 for (items = spell_menu;
5903 items; items = items->next) {
5904 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
5905 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5906 gtk_widget_show(GTK_WIDGET(menuitem));
5908 g_slist_free(spell_menu);
5910 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
5915 static gboolean compose_force_window_origin = TRUE;
5916 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5923 GtkWidget *handlebox;
5925 GtkWidget *notebook;
5930 GtkWidget *subject_hbox;
5931 GtkWidget *subject_frame;
5932 GtkWidget *subject_entry;
5936 GtkWidget *edit_vbox;
5937 GtkWidget *ruler_hbox;
5939 GtkWidget *scrolledwin;
5941 GtkTextBuffer *buffer;
5942 GtkClipboard *clipboard;
5944 UndoMain *undostruct;
5946 gchar *titles[N_ATTACH_COLS];
5947 guint n_menu_entries;
5948 GtkWidget *popupmenu;
5949 GtkItemFactory *popupfactory;
5950 GtkItemFactory *ifactory;
5951 GtkWidget *tmpl_menu;
5953 GtkWidget *menuitem;
5956 GtkAspell * gtkaspell = NULL;
5959 static GdkGeometry geometry;
5961 g_return_val_if_fail(account != NULL, NULL);
5963 debug_print("Creating compose window...\n");
5964 compose = g_new0(Compose, 1);
5966 titles[COL_MIMETYPE] = _("MIME type");
5967 titles[COL_SIZE] = _("Size");
5968 titles[COL_NAME] = _("Name");
5970 compose->batch = batch;
5971 compose->account = account;
5973 compose->mutex = g_mutex_new();
5974 compose->set_cursor_pos = -1;
5976 compose->tooltips = gtk_tooltips_new();
5978 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5979 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5980 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5982 if (!geometry.max_width) {
5983 geometry.max_width = gdk_screen_width();
5984 geometry.max_height = gdk_screen_height();
5987 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5988 &geometry, GDK_HINT_MAX_SIZE);
5989 if (!geometry.min_width) {
5990 geometry.min_width = 600;
5991 geometry.min_height = 480;
5993 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5994 &geometry, GDK_HINT_MIN_SIZE);
5996 if (compose_force_window_origin)
5997 gtk_widget_set_uposition(window, prefs_common.compose_x,
5998 prefs_common.compose_y);
6000 g_signal_connect(G_OBJECT(window), "delete_event",
6001 G_CALLBACK(compose_delete_cb), compose);
6002 MANAGE_WINDOW_SIGNALS_CONNECT(window);
6003 gtk_widget_realize(window);
6005 gtkut_widget_set_composer_icon(window);
6007 vbox = gtk_vbox_new(FALSE, 0);
6008 gtk_container_add(GTK_CONTAINER(window), vbox);
6010 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
6011 menubar = menubar_create(window, compose_entries,
6012 n_menu_entries, "<Compose>", compose);
6013 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
6015 if (prefs_common.toolbar_detachable) {
6016 handlebox = gtk_handle_box_new();
6018 handlebox = gtk_hbox_new(FALSE, 0);
6020 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
6022 gtk_widget_realize(handlebox);
6023 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
6026 vbox2 = gtk_vbox_new(FALSE, 2);
6027 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
6028 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
6031 notebook = gtk_notebook_new();
6032 gtk_widget_set_size_request(notebook, -1, 130);
6033 gtk_widget_show(notebook);
6035 /* header labels and entries */
6036 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6037 compose_create_header(compose),
6038 gtk_label_new_with_mnemonic(_("Hea_der")));
6039 /* attachment list */
6040 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6041 compose_create_attach(compose),
6042 gtk_label_new_with_mnemonic(_("_Attachments")));
6044 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6045 compose_create_others(compose),
6046 gtk_label_new_with_mnemonic(_("Othe_rs")));
6049 subject_hbox = gtk_hbox_new(FALSE, 0);
6050 gtk_widget_show(subject_hbox);
6052 subject_frame = gtk_frame_new(NULL);
6053 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
6054 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
6055 gtk_widget_show(subject_frame);
6057 subject = gtk_hbox_new(FALSE, 0);
6058 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
6059 gtk_widget_show(subject);
6061 label = gtk_label_new(_("Subject:"));
6062 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
6063 gtk_widget_show(label);
6065 subject_entry = gtk_entry_new();
6066 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
6067 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
6068 G_CALLBACK(compose_grab_focus_cb), compose);
6069 gtk_widget_show(subject_entry);
6070 compose->subject_entry = subject_entry;
6071 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
6073 edit_vbox = gtk_vbox_new(FALSE, 0);
6075 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
6078 ruler_hbox = gtk_hbox_new(FALSE, 0);
6079 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
6081 ruler = gtk_shruler_new();
6082 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
6083 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
6087 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
6088 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
6089 GTK_POLICY_AUTOMATIC,
6090 GTK_POLICY_AUTOMATIC);
6091 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
6093 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
6094 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
6096 text = gtk_text_view_new();
6097 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6098 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
6099 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
6100 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
6101 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
6103 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
6105 g_signal_connect_after(G_OBJECT(text), "size_allocate",
6106 G_CALLBACK(compose_edit_size_alloc),
6108 g_signal_connect(G_OBJECT(buffer), "changed",
6109 G_CALLBACK(compose_changed_cb), compose);
6110 g_signal_connect(G_OBJECT(text), "grab_focus",
6111 G_CALLBACK(compose_grab_focus_cb), compose);
6112 g_signal_connect(G_OBJECT(buffer), "insert_text",
6113 G_CALLBACK(text_inserted), compose);
6114 g_signal_connect(G_OBJECT(text), "button_press_event",
6115 G_CALLBACK(text_clicked), compose);
6116 g_signal_connect(G_OBJECT(subject_entry), "changed",
6117 G_CALLBACK(compose_changed_cb), compose);
6120 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
6121 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
6122 GDK_ACTION_COPY | GDK_ACTION_MOVE);
6123 g_signal_connect(G_OBJECT(text), "drag_data_received",
6124 G_CALLBACK(compose_insert_drag_received_cb),
6126 g_signal_connect(G_OBJECT(text), "drag-drop",
6127 G_CALLBACK(compose_drag_drop),
6129 gtk_widget_show_all(vbox);
6131 /* pane between attach clist and text */
6132 paned = gtk_vpaned_new();
6133 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
6134 gtk_container_add(GTK_CONTAINER(vbox2), paned);
6135 gtk_paned_add1(GTK_PANED(paned), notebook);
6136 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
6137 gtk_widget_show_all(paned);
6140 if (prefs_common.textfont) {
6141 PangoFontDescription *font_desc;
6143 font_desc = pango_font_description_from_string
6144 (prefs_common.textfont);
6146 gtk_widget_modify_font(text, font_desc);
6147 pango_font_description_free(font_desc);
6151 n_entries = sizeof(compose_popup_entries) /
6152 sizeof(compose_popup_entries[0]);
6153 popupmenu = menu_create_items(compose_popup_entries, n_entries,
6154 "<Compose>", &popupfactory,
6157 ifactory = gtk_item_factory_from_widget(menubar);
6158 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6159 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6160 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
6162 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6164 undostruct = undo_init(text);
6165 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
6168 address_completion_start(window);
6170 compose->window = window;
6171 compose->vbox = vbox;
6172 compose->menubar = menubar;
6173 compose->handlebox = handlebox;
6175 compose->vbox2 = vbox2;
6177 compose->paned = paned;
6179 compose->edit_vbox = edit_vbox;
6180 compose->ruler_hbox = ruler_hbox;
6181 compose->ruler = ruler;
6182 compose->scrolledwin = scrolledwin;
6183 compose->text = text;
6185 compose->focused_editable = NULL;
6187 compose->popupmenu = popupmenu;
6188 compose->popupfactory = popupfactory;
6190 compose->tmpl_menu = tmpl_menu;
6192 compose->mode = mode;
6193 compose->rmode = mode;
6195 compose->targetinfo = NULL;
6196 compose->replyinfo = NULL;
6197 compose->fwdinfo = NULL;
6199 compose->replyto = NULL;
6201 compose->bcc = NULL;
6202 compose->followup_to = NULL;
6204 compose->ml_post = NULL;
6206 compose->inreplyto = NULL;
6207 compose->references = NULL;
6208 compose->msgid = NULL;
6209 compose->boundary = NULL;
6211 compose->autowrap = prefs_common.autowrap;
6213 compose->use_signing = FALSE;
6214 compose->use_encryption = FALSE;
6215 compose->privacy_system = NULL;
6217 compose->modified = FALSE;
6219 compose->return_receipt = FALSE;
6221 compose->to_list = NULL;
6222 compose->newsgroup_list = NULL;
6224 compose->undostruct = undostruct;
6226 compose->sig_str = NULL;
6228 compose->exteditor_file = NULL;
6229 compose->exteditor_pid = -1;
6230 compose->exteditor_tag = -1;
6231 compose->draft_timeout_tag = -1;
6234 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6235 if (mode != COMPOSE_REDIRECT) {
6236 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6237 strcmp(prefs_common.dictionary, "")) {
6238 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6239 prefs_common.dictionary,
6240 conv_get_locale_charset_str(),
6241 prefs_common.misspelled_col,
6242 prefs_common.check_while_typing,
6243 prefs_common.recheck_when_changing_dict,
6244 prefs_common.use_alternate,
6245 GTK_TEXT_VIEW(text),
6246 GTK_WINDOW(compose->window),
6247 compose_spell_menu_changed,
6250 alertpanel_error(_("Spell checker could not "
6252 gtkaspell_checkers_strerror());
6253 gtkaspell_checkers_reset_error();
6255 if (!gtkaspell_set_sug_mode(gtkaspell,
6256 prefs_common.aspell_sugmode)) {
6257 debug_print("Aspell: could not set "
6258 "suggestion mode %s\n",
6259 gtkaspell_checkers_strerror());
6260 gtkaspell_checkers_reset_error();
6263 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6267 compose->gtkaspell = gtkaspell;
6268 compose_spell_menu_changed(compose);
6271 compose_select_account(compose, account, TRUE);
6273 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6274 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6275 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6277 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6278 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6280 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6281 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6283 menu_set_sensitive(ifactory, "/Options/Reply mode", compose->mode == COMPOSE_REPLY);
6285 if (account->protocol != A_NNTP)
6286 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6288 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6290 addressbook_set_target_compose(compose);
6292 if (mode != COMPOSE_REDIRECT)
6293 compose_set_template_menu(compose);
6295 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6296 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6299 compose_list = g_list_append(compose_list, compose);
6301 if (!prefs_common.show_ruler)
6302 gtk_widget_hide(ruler_hbox);
6304 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6305 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6306 prefs_common.show_ruler);
6309 compose->priority = PRIORITY_NORMAL;
6310 compose_update_priority_menu_item(compose);
6312 compose_set_out_encoding(compose);
6315 compose_update_actions_menu(compose);
6317 /* Privacy Systems menu */
6318 compose_update_privacy_systems_menu(compose);
6320 activate_privacy_system(compose, account, TRUE);
6321 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6323 gtk_widget_realize(window);
6325 gtk_widget_show(window);
6331 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6336 GtkWidget *optmenubox;
6339 GtkWidget *from_name = NULL;
6341 gint num = 0, def_menu = 0;
6343 accounts = account_get_list();
6344 g_return_val_if_fail(accounts != NULL, NULL);
6346 optmenubox = gtk_event_box_new();
6347 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
6348 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
6350 hbox = gtk_hbox_new(FALSE, 6);
6351 from_name = gtk_entry_new();
6353 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6354 G_CALLBACK(compose_grab_focus_cb), compose);
6356 for (; accounts != NULL; accounts = accounts->next, num++) {
6357 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6358 gchar *name, *from = NULL;
6360 if (ac == compose->account) def_menu = num;
6362 name = g_markup_printf_escaped(_("From: <i>%s</i>"),
6365 if (ac == compose->account) {
6366 if (ac->name && *ac->name) {
6368 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6369 from = g_strdup_printf("%s <%s>",
6371 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6373 from = g_strdup_printf("%s",
6375 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6378 COMBOBOX_ADD(menu, name, ac->account_id);
6383 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
6385 g_signal_connect(G_OBJECT(optmenu), "changed",
6386 G_CALLBACK(account_activated),
6389 gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
6390 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6392 gtk_tooltips_set_tip(compose->tooltips, optmenubox,
6393 _("Account to use for this email"), NULL);
6394 gtk_tooltips_set_tip(compose->tooltips, from_name,
6395 _("Sender address to be used"), NULL);
6397 compose->from_name = from_name;
6402 static void compose_set_priority_cb(gpointer data,
6406 Compose *compose = (Compose *) data;
6407 compose->priority = action;
6410 static void compose_reply_change_mode(gpointer data,
6414 Compose *compose = (Compose *) data;
6415 gboolean was_modified = compose->modified;
6417 gboolean all = FALSE, ml = FALSE, sender = FALSE, followup = FALSE;
6418 if (compose->mode != COMPOSE_REPLY)
6420 g_return_if_fail(compose->replyinfo != NULL);
6422 if (action == COMPOSE_REPLY && prefs_common.default_reply_list)
6424 if (action == COMPOSE_REPLY && compose->rmode == COMPOSE_FOLLOWUP_AND_REPLY_TO)
6426 if (action == COMPOSE_REPLY_TO_ALL)
6428 if (action == COMPOSE_REPLY_TO_SENDER)
6430 if (action == COMPOSE_REPLY_TO_LIST)
6433 compose_remove_header_entries(compose);
6434 compose_reply_set_entry(compose, compose->replyinfo, all, ml, sender, followup);
6435 compose_show_first_last_header(compose, TRUE);
6436 compose->modified = was_modified;
6437 compose_set_title(compose);
6440 static void compose_update_priority_menu_item(Compose * compose)
6442 GtkItemFactory *ifactory;
6443 GtkWidget *menuitem = NULL;
6445 ifactory = gtk_item_factory_from_widget(compose->menubar);
6447 switch (compose->priority) {
6448 case PRIORITY_HIGHEST:
6449 menuitem = gtk_item_factory_get_item
6450 (ifactory, "/Options/Priority/Highest");
6453 menuitem = gtk_item_factory_get_item
6454 (ifactory, "/Options/Priority/High");
6456 case PRIORITY_NORMAL:
6457 menuitem = gtk_item_factory_get_item
6458 (ifactory, "/Options/Priority/Normal");
6461 menuitem = gtk_item_factory_get_item
6462 (ifactory, "/Options/Priority/Low");
6464 case PRIORITY_LOWEST:
6465 menuitem = gtk_item_factory_get_item
6466 (ifactory, "/Options/Priority/Lowest");
6469 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6472 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6474 Compose *compose = (Compose *) data;
6476 GtkItemFactory *ifactory;
6477 gboolean can_sign = FALSE, can_encrypt = FALSE;
6479 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6481 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6484 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6485 g_free(compose->privacy_system);
6486 compose->privacy_system = NULL;
6487 if (systemid != NULL) {
6488 compose->privacy_system = g_strdup(systemid);
6490 can_sign = privacy_system_can_sign(systemid);
6491 can_encrypt = privacy_system_can_encrypt(systemid);
6494 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6496 ifactory = gtk_item_factory_from_widget(compose->menubar);
6497 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6498 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6501 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6503 static gchar *branch_path = "/Options/Privacy System";
6504 GtkItemFactory *ifactory;
6505 GtkWidget *menuitem = NULL;
6507 gboolean can_sign = FALSE, can_encrypt = FALSE;
6508 gboolean found = FALSE;
6510 ifactory = gtk_item_factory_from_widget(compose->menubar);
6512 if (compose->privacy_system != NULL) {
6515 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6516 g_return_if_fail(menuitem != NULL);
6518 amenu = GTK_MENU_SHELL(menuitem)->children;
6520 while (amenu != NULL) {
6521 GList *alist = amenu->next;
6523 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6524 if (systemid != NULL) {
6525 if (strcmp(systemid, compose->privacy_system) == 0) {
6526 menuitem = GTK_WIDGET(amenu->data);
6528 can_sign = privacy_system_can_sign(systemid);
6529 can_encrypt = privacy_system_can_encrypt(systemid);
6533 } else if (strlen(compose->privacy_system) == 0) {
6534 menuitem = GTK_WIDGET(amenu->data);
6537 can_encrypt = FALSE;
6544 if (menuitem != NULL)
6545 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6547 if (warn && !found && strlen(compose->privacy_system)) {
6548 gchar *tmp = g_strdup_printf(
6549 _("The privacy system '%s' cannot be loaded. You "
6550 "will not be able to sign or encrypt this message."),
6551 compose->privacy_system);
6552 alertpanel_warning(tmp);
6557 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6558 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6561 static void compose_set_out_encoding(Compose *compose)
6563 GtkItemFactoryEntry *entry;
6564 GtkItemFactory *ifactory;
6565 CharSet out_encoding;
6566 gchar *path, *p, *q;
6569 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6570 ifactory = gtk_item_factory_from_widget(compose->menubar);
6572 for (entry = compose_entries; entry->callback != compose_address_cb;
6574 if (entry->callback == compose_set_encoding_cb &&
6575 (CharSet)entry->callback_action == out_encoding) {
6576 p = q = path = g_strdup(entry->path);
6588 item = gtk_item_factory_get_item(ifactory, path);
6589 gtk_widget_activate(item);
6596 static void compose_set_template_menu(Compose *compose)
6598 GSList *tmpl_list, *cur;
6602 tmpl_list = template_get_config();
6604 menu = gtk_menu_new();
6606 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6607 Template *tmpl = (Template *)cur->data;
6609 item = gtk_menu_item_new_with_label(tmpl->name);
6610 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6611 g_signal_connect(G_OBJECT(item), "activate",
6612 G_CALLBACK(compose_template_activate_cb),
6614 g_object_set_data(G_OBJECT(item), "template", tmpl);
6615 gtk_widget_show(item);
6618 gtk_widget_show(menu);
6619 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6622 void compose_update_actions_menu(Compose *compose)
6624 GtkItemFactory *ifactory;
6626 ifactory = gtk_item_factory_from_widget(compose->menubar);
6627 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6630 void compose_update_privacy_systems_menu(Compose *compose)
6632 static gchar *branch_path = "/Options/Privacy System";
6633 GtkItemFactory *ifactory;
6634 GtkWidget *menuitem;
6635 GSList *systems, *cur;
6638 GtkWidget *system_none;
6641 ifactory = gtk_item_factory_from_widget(compose->menubar);
6643 /* remove old entries */
6644 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6645 g_return_if_fail(menuitem != NULL);
6647 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6648 while (amenu != NULL) {
6649 GList *alist = amenu->next;
6650 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6654 system_none = gtk_item_factory_get_widget(ifactory,
6655 "/Options/Privacy System/None");
6657 g_signal_connect(G_OBJECT(system_none), "activate",
6658 G_CALLBACK(compose_set_privacy_system_cb), compose);
6660 systems = privacy_get_system_ids();
6661 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6662 gchar *systemid = cur->data;
6664 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6665 widget = gtk_radio_menu_item_new_with_label(group,
6666 privacy_system_get_name(systemid));
6667 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6668 g_strdup(systemid), g_free);
6669 g_signal_connect(G_OBJECT(widget), "activate",
6670 G_CALLBACK(compose_set_privacy_system_cb), compose);
6672 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6673 gtk_widget_show(widget);
6676 g_slist_free(systems);
6679 void compose_reflect_prefs_all(void)
6684 for (cur = compose_list; cur != NULL; cur = cur->next) {
6685 compose = (Compose *)cur->data;
6686 compose_set_template_menu(compose);
6690 void compose_reflect_prefs_pixmap_theme(void)
6695 for (cur = compose_list; cur != NULL; cur = cur->next) {
6696 compose = (Compose *)cur->data;
6697 toolbar_update(TOOLBAR_COMPOSE, compose);
6701 static void compose_template_apply(Compose *compose, Template *tmpl,
6705 GtkTextBuffer *buffer;
6709 gchar *parsed_str = NULL;
6710 gint cursor_pos = 0;
6713 /* process the body */
6715 text = GTK_TEXT_VIEW(compose->text);
6716 buffer = gtk_text_view_get_buffer(text);
6719 gtk_text_buffer_set_text(buffer, "", -1);
6721 mark = gtk_text_buffer_get_insert(buffer);
6722 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6725 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6726 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6729 if (prefs_common.quotemark && *prefs_common.quotemark)
6730 qmark = prefs_common.quotemark;
6734 if (compose->replyinfo != NULL)
6735 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6736 tmpl->value, qmark, NULL, FALSE);
6737 else if (compose->fwdinfo != NULL)
6738 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6739 tmpl->value, qmark, NULL, FALSE);
6744 if (replace && parsed_str && compose->account->auto_sig)
6745 compose_insert_sig(compose, FALSE);
6747 if (replace && parsed_str) {
6748 gtk_text_buffer_get_start_iter(buffer, &iter);
6749 gtk_text_buffer_place_cursor(buffer, &iter);
6753 cursor_pos = quote_fmt_get_cursor_pos();
6754 compose->set_cursor_pos = cursor_pos;
6755 if (cursor_pos == -1)
6757 gtk_text_buffer_get_start_iter(buffer, &iter);
6758 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6759 gtk_text_buffer_place_cursor(buffer, &iter);
6762 /* process the other fields */
6763 compose_template_apply_fields(compose, tmpl);
6764 quote_fmt_reset_vartable();
6765 compose_changed_cb(NULL, compose);
6768 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6770 static MsgInfo dummyinfo;
6771 MsgInfo *msginfo = NULL;
6774 if (compose->replyinfo != NULL)
6775 msginfo = compose->replyinfo;
6776 else if (compose->fwdinfo != NULL)
6777 msginfo = compose->fwdinfo;
6779 msginfo = &dummyinfo;
6781 if (tmpl->to && *tmpl->to != '\0') {
6782 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6783 quote_fmt_scan_string(tmpl->to);
6786 buf = quote_fmt_get_buffer();
6788 alertpanel_error(_("Message To format error."));
6790 compose_entry_append(compose, buf, COMPOSE_TO);
6794 if (tmpl->cc && *tmpl->cc != '\0') {
6795 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6796 quote_fmt_scan_string(tmpl->cc);
6799 buf = quote_fmt_get_buffer();
6801 alertpanel_error(_("Message Cc format error."));
6803 compose_entry_append(compose, buf, COMPOSE_CC);
6807 if (tmpl->bcc && *tmpl->bcc != '\0') {
6808 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6809 quote_fmt_scan_string(tmpl->bcc);
6812 buf = quote_fmt_get_buffer();
6814 alertpanel_error(_("Message Bcc format error."));
6816 compose_entry_append(compose, buf, COMPOSE_BCC);
6820 /* process the subject */
6821 if (tmpl->subject && *tmpl->subject != '\0') {
6822 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6823 quote_fmt_scan_string(tmpl->subject);
6826 buf = quote_fmt_get_buffer();
6828 alertpanel_error(_("Message subject format error."));
6830 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6835 static void compose_destroy(Compose *compose)
6837 GtkTextBuffer *buffer;
6838 GtkClipboard *clipboard;
6840 compose_list = g_list_remove(compose_list, compose);
6842 if (compose->updating) {
6843 debug_print("danger, not destroying anything now\n");
6844 compose->deferred_destroy = TRUE;
6847 /* NOTE: address_completion_end() does nothing with the window
6848 * however this may change. */
6849 address_completion_end(compose->window);
6851 slist_free_strings(compose->to_list);
6852 g_slist_free(compose->to_list);
6853 slist_free_strings(compose->newsgroup_list);
6854 g_slist_free(compose->newsgroup_list);
6855 slist_free_strings(compose->header_list);
6856 g_slist_free(compose->header_list);
6858 procmsg_msginfo_free(compose->targetinfo);
6859 procmsg_msginfo_free(compose->replyinfo);
6860 procmsg_msginfo_free(compose->fwdinfo);
6862 g_free(compose->replyto);
6863 g_free(compose->cc);
6864 g_free(compose->bcc);
6865 g_free(compose->newsgroups);
6866 g_free(compose->followup_to);
6868 g_free(compose->ml_post);
6870 g_free(compose->inreplyto);
6871 g_free(compose->references);
6872 g_free(compose->msgid);
6873 g_free(compose->boundary);
6875 g_free(compose->redirect_filename);
6876 if (compose->undostruct)
6877 undo_destroy(compose->undostruct);
6879 g_free(compose->sig_str);
6881 g_free(compose->exteditor_file);
6883 g_free(compose->orig_charset);
6885 g_free(compose->privacy_system);
6887 if (addressbook_get_target_compose() == compose)
6888 addressbook_set_target_compose(NULL);
6891 if (compose->gtkaspell) {
6892 gtkaspell_delete(compose->gtkaspell);
6893 compose->gtkaspell = NULL;
6897 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6898 prefs_common.compose_height = compose->window->allocation.height;
6900 if (!gtk_widget_get_parent(compose->paned))
6901 gtk_widget_destroy(compose->paned);
6902 gtk_widget_destroy(compose->popupmenu);
6904 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
6905 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
6906 gtk_text_buffer_remove_selection_clipboard(buffer, clipboard);
6908 gtk_widget_destroy(compose->window);
6909 toolbar_destroy(compose->toolbar);
6910 g_free(compose->toolbar);
6911 g_mutex_free(compose->mutex);
6915 static void compose_attach_info_free(AttachInfo *ainfo)
6917 g_free(ainfo->file);
6918 g_free(ainfo->content_type);
6919 g_free(ainfo->name);
6923 static void compose_attach_remove_selected(Compose *compose)
6925 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6926 GtkTreeSelection *selection;
6928 GtkTreeModel *model;
6930 selection = gtk_tree_view_get_selection(tree_view);
6931 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6936 for (cur = sel; cur != NULL; cur = cur->next) {
6937 GtkTreePath *path = cur->data;
6938 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6941 gtk_tree_path_free(path);
6944 for (cur = sel; cur != NULL; cur = cur->next) {
6945 GtkTreeRowReference *ref = cur->data;
6946 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6949 if (gtk_tree_model_get_iter(model, &iter, path))
6950 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6952 gtk_tree_path_free(path);
6953 gtk_tree_row_reference_free(ref);
6959 static struct _AttachProperty
6962 GtkWidget *mimetype_entry;
6963 GtkWidget *encoding_optmenu;
6964 GtkWidget *path_entry;
6965 GtkWidget *filename_entry;
6967 GtkWidget *cancel_btn;
6970 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6972 gtk_tree_path_free((GtkTreePath *)ptr);
6975 static void compose_attach_property(Compose *compose)
6977 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6979 GtkComboBox *optmenu;
6980 GtkTreeSelection *selection;
6982 GtkTreeModel *model;
6985 static gboolean cancelled;
6987 /* only if one selected */
6988 selection = gtk_tree_view_get_selection(tree_view);
6989 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6992 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6996 path = (GtkTreePath *) sel->data;
6997 gtk_tree_model_get_iter(model, &iter, path);
6998 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
7001 g_list_foreach(sel, gtk_tree_path_free_, NULL);
7007 if (!attach_prop.window)
7008 compose_attach_property_create(&cancelled);
7009 gtk_widget_grab_focus(attach_prop.ok_btn);
7010 gtk_widget_show(attach_prop.window);
7011 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
7013 optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
7014 if (ainfo->encoding == ENC_UNKNOWN)
7015 combobox_select_by_data(optmenu, ENC_BASE64);
7017 combobox_select_by_data(optmenu, ainfo->encoding);
7019 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
7020 ainfo->content_type ? ainfo->content_type : "");
7021 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
7022 ainfo->file ? ainfo->file : "");
7023 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
7024 ainfo->name ? ainfo->name : "");
7027 const gchar *entry_text;
7029 gchar *cnttype = NULL;
7036 gtk_widget_hide(attach_prop.window);
7041 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
7042 if (*entry_text != '\0') {
7045 text = g_strstrip(g_strdup(entry_text));
7046 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
7047 cnttype = g_strdup(text);
7050 alertpanel_error(_("Invalid MIME type."));
7056 ainfo->encoding = combobox_get_active_data(optmenu);
7058 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
7059 if (*entry_text != '\0') {
7060 if (is_file_exist(entry_text) &&
7061 (size = get_file_size(entry_text)) > 0)
7062 file = g_strdup(entry_text);
7065 (_("File doesn't exist or is empty."));
7071 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
7072 if (*entry_text != '\0') {
7073 g_free(ainfo->name);
7074 ainfo->name = g_strdup(entry_text);
7078 g_free(ainfo->content_type);
7079 ainfo->content_type = cnttype;
7082 g_free(ainfo->file);
7088 /* update tree store */
7089 text = to_human_readable(ainfo->size);
7090 gtk_tree_model_get_iter(model, &iter, path);
7091 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
7092 COL_MIMETYPE, ainfo->content_type,
7094 COL_NAME, ainfo->name,
7100 gtk_tree_path_free(path);
7103 #define SET_LABEL_AND_ENTRY(str, entry, top) \
7105 label = gtk_label_new(str); \
7106 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
7107 GTK_FILL, 0, 0, 0); \
7108 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
7110 entry = gtk_entry_new(); \
7111 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
7112 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
7115 static void compose_attach_property_create(gboolean *cancelled)
7121 GtkWidget *mimetype_entry;
7124 GtkListStore *optmenu_menu;
7125 GtkWidget *path_entry;
7126 GtkWidget *filename_entry;
7129 GtkWidget *cancel_btn;
7130 GList *mime_type_list, *strlist;
7133 debug_print("Creating attach_property window...\n");
7135 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
7136 gtk_widget_set_size_request(window, 480, -1);
7137 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
7138 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
7139 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
7140 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
7141 g_signal_connect(G_OBJECT(window), "delete_event",
7142 G_CALLBACK(attach_property_delete_event),
7144 g_signal_connect(G_OBJECT(window), "key_press_event",
7145 G_CALLBACK(attach_property_key_pressed),
7148 vbox = gtk_vbox_new(FALSE, 8);
7149 gtk_container_add(GTK_CONTAINER(window), vbox);
7151 table = gtk_table_new(4, 2, FALSE);
7152 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
7153 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
7154 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
7156 label = gtk_label_new(_("MIME type"));
7157 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
7159 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7160 mimetype_entry = gtk_combo_new();
7161 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
7162 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7164 /* stuff with list */
7165 mime_type_list = procmime_get_mime_type_list();
7167 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
7168 MimeType *type = (MimeType *) mime_type_list->data;
7171 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
7173 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
7176 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
7177 (GCompareFunc)strcmp2);
7180 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
7182 for (mime_type_list = strlist; mime_type_list != NULL;
7183 mime_type_list = mime_type_list->next)
7184 g_free(mime_type_list->data);
7185 g_list_free(strlist);
7187 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
7189 label = gtk_label_new(_("Encoding"));
7190 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
7192 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7194 hbox = gtk_hbox_new(FALSE, 0);
7195 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
7196 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7198 optmenu = gtkut_sc_combobox_create(NULL, TRUE);
7199 optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
7201 COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
7202 COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
7203 COMBOBOX_ADD(optmenu_menu, "quoted-printable", ENC_QUOTED_PRINTABLE);
7204 COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
7205 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
7207 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
7209 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
7210 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
7212 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
7213 &ok_btn, GTK_STOCK_OK,
7215 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
7216 gtk_widget_grab_default(ok_btn);
7218 g_signal_connect(G_OBJECT(ok_btn), "clicked",
7219 G_CALLBACK(attach_property_ok),
7221 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
7222 G_CALLBACK(attach_property_cancel),
7225 gtk_widget_show_all(vbox);
7227 attach_prop.window = window;
7228 attach_prop.mimetype_entry = mimetype_entry;
7229 attach_prop.encoding_optmenu = optmenu;
7230 attach_prop.path_entry = path_entry;
7231 attach_prop.filename_entry = filename_entry;
7232 attach_prop.ok_btn = ok_btn;
7233 attach_prop.cancel_btn = cancel_btn;
7236 #undef SET_LABEL_AND_ENTRY
7238 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7244 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7250 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7251 gboolean *cancelled)
7259 static gboolean attach_property_key_pressed(GtkWidget *widget,
7261 gboolean *cancelled)
7263 if (event && event->keyval == GDK_Escape) {
7270 static void compose_exec_ext_editor(Compose *compose)
7277 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7278 G_DIR_SEPARATOR, compose);
7280 if (pipe(pipe_fds) < 0) {
7286 if ((pid = fork()) < 0) {
7293 /* close the write side of the pipe */
7296 compose->exteditor_file = g_strdup(tmp);
7297 compose->exteditor_pid = pid;
7299 compose_set_ext_editor_sensitive(compose, FALSE);
7301 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7302 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7306 } else { /* process-monitoring process */
7312 /* close the read side of the pipe */
7315 if (compose_write_body_to_file(compose, tmp) < 0) {
7316 fd_write_all(pipe_fds[1], "2\n", 2);
7320 pid_ed = compose_exec_ext_editor_real(tmp);
7322 fd_write_all(pipe_fds[1], "1\n", 2);
7326 /* wait until editor is terminated */
7327 waitpid(pid_ed, NULL, 0);
7329 fd_write_all(pipe_fds[1], "0\n", 2);
7336 #endif /* G_OS_UNIX */
7340 static gint compose_exec_ext_editor_real(const gchar *file)
7347 g_return_val_if_fail(file != NULL, -1);
7349 if ((pid = fork()) < 0) {
7354 if (pid != 0) return pid;
7356 /* grandchild process */
7358 if (setpgid(0, getppid()))
7361 if (prefs_common.ext_editor_cmd &&
7362 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7363 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7364 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7366 if (prefs_common.ext_editor_cmd)
7367 g_warning("External editor command line is invalid: '%s'\n",
7368 prefs_common.ext_editor_cmd);
7369 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7372 cmdline = strsplit_with_quote(buf, " ", 1024);
7373 execvp(cmdline[0], cmdline);
7376 g_strfreev(cmdline);
7381 static gboolean compose_ext_editor_kill(Compose *compose)
7383 pid_t pgid = compose->exteditor_pid * -1;
7386 ret = kill(pgid, 0);
7388 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7392 msg = g_strdup_printf
7393 (_("The external editor is still working.\n"
7394 "Force terminating the process?\n"
7395 "process group id: %d"), -pgid);
7396 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7397 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7401 if (val == G_ALERTALTERNATE) {
7402 g_source_remove(compose->exteditor_tag);
7403 g_io_channel_shutdown(compose->exteditor_ch,
7405 g_io_channel_unref(compose->exteditor_ch);
7407 if (kill(pgid, SIGTERM) < 0) perror("kill");
7408 waitpid(compose->exteditor_pid, NULL, 0);
7410 g_warning("Terminated process group id: %d", -pgid);
7411 g_warning("Temporary file: %s",
7412 compose->exteditor_file);
7414 compose_set_ext_editor_sensitive(compose, TRUE);
7416 g_free(compose->exteditor_file);
7417 compose->exteditor_file = NULL;
7418 compose->exteditor_pid = -1;
7419 compose->exteditor_ch = NULL;
7420 compose->exteditor_tag = -1;
7428 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7432 Compose *compose = (Compose *)data;
7435 debug_print(_("Compose: input from monitoring process\n"));
7437 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7439 g_io_channel_shutdown(source, FALSE, NULL);
7440 g_io_channel_unref(source);
7442 waitpid(compose->exteditor_pid, NULL, 0);
7444 if (buf[0] == '0') { /* success */
7445 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7446 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7448 gtk_text_buffer_set_text(buffer, "", -1);
7449 compose_insert_file(compose, compose->exteditor_file);
7450 compose_changed_cb(NULL, compose);
7452 if (g_unlink(compose->exteditor_file) < 0)
7453 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7454 } else if (buf[0] == '1') { /* failed */
7455 g_warning("Couldn't exec external editor\n");
7456 if (g_unlink(compose->exteditor_file) < 0)
7457 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7458 } else if (buf[0] == '2') {
7459 g_warning("Couldn't write to file\n");
7460 } else if (buf[0] == '3') {
7461 g_warning("Pipe read failed\n");
7464 compose_set_ext_editor_sensitive(compose, TRUE);
7466 g_free(compose->exteditor_file);
7467 compose->exteditor_file = NULL;
7468 compose->exteditor_pid = -1;
7469 compose->exteditor_ch = NULL;
7470 compose->exteditor_tag = -1;
7475 static void compose_set_ext_editor_sensitive(Compose *compose,
7478 GtkItemFactory *ifactory;
7480 ifactory = gtk_item_factory_from_widget(compose->menubar);
7482 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7483 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7484 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7485 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7486 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7487 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7488 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7491 gtk_widget_set_sensitive(compose->text, sensitive);
7492 if (compose->toolbar->send_btn)
7493 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7494 if (compose->toolbar->sendl_btn)
7495 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7496 if (compose->toolbar->draft_btn)
7497 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7498 if (compose->toolbar->insert_btn)
7499 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7500 if (compose->toolbar->sig_btn)
7501 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7502 if (compose->toolbar->exteditor_btn)
7503 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7504 if (compose->toolbar->linewrap_current_btn)
7505 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7506 if (compose->toolbar->linewrap_all_btn)
7507 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7509 #endif /* G_OS_UNIX */
7512 * compose_undo_state_changed:
7514 * Change the sensivity of the menuentries undo and redo
7516 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7517 gint redo_state, gpointer data)
7519 GtkWidget *widget = GTK_WIDGET(data);
7520 GtkItemFactory *ifactory;
7522 g_return_if_fail(widget != NULL);
7524 ifactory = gtk_item_factory_from_widget(widget);
7526 switch (undo_state) {
7527 case UNDO_STATE_TRUE:
7528 if (!undostruct->undo_state) {
7529 undostruct->undo_state = TRUE;
7530 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7533 case UNDO_STATE_FALSE:
7534 if (undostruct->undo_state) {
7535 undostruct->undo_state = FALSE;
7536 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7539 case UNDO_STATE_UNCHANGED:
7541 case UNDO_STATE_REFRESH:
7542 menu_set_sensitive(ifactory, "/Edit/Undo",
7543 undostruct->undo_state);
7546 g_warning("Undo state not recognized");
7550 switch (redo_state) {
7551 case UNDO_STATE_TRUE:
7552 if (!undostruct->redo_state) {
7553 undostruct->redo_state = TRUE;
7554 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7557 case UNDO_STATE_FALSE:
7558 if (undostruct->redo_state) {
7559 undostruct->redo_state = FALSE;
7560 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7563 case UNDO_STATE_UNCHANGED:
7565 case UNDO_STATE_REFRESH:
7566 menu_set_sensitive(ifactory, "/Edit/Redo",
7567 undostruct->redo_state);
7570 g_warning("Redo state not recognized");
7575 /* callback functions */
7577 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7578 * includes "non-client" (windows-izm) in calculation, so this calculation
7579 * may not be accurate.
7581 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7582 GtkAllocation *allocation,
7583 GtkSHRuler *shruler)
7585 if (prefs_common.show_ruler) {
7586 gint char_width = 0, char_height = 0;
7587 gint line_width_in_chars;
7589 gtkut_get_font_size(GTK_WIDGET(widget),
7590 &char_width, &char_height);
7591 line_width_in_chars =
7592 (allocation->width - allocation->x) / char_width;
7594 /* got the maximum */
7595 gtk_ruler_set_range(GTK_RULER(shruler),
7596 0.0, line_width_in_chars, 0,
7597 /*line_width_in_chars*/ char_width);
7603 static void account_activated(GtkComboBox *optmenu, gpointer data)
7605 Compose *compose = (Compose *)data;
7608 gchar *folderidentifier;
7609 gint account_id = 0;
7613 /* Get ID of active account in the combo box */
7614 menu = gtk_combo_box_get_model(optmenu);
7615 gtk_combo_box_get_active_iter(optmenu, &iter);
7616 gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
7618 ac = account_find_from_id(account_id);
7619 g_return_if_fail(ac != NULL);
7621 if (ac != compose->account)
7622 compose_select_account(compose, ac, FALSE);
7624 /* Set message save folder */
7625 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7626 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7628 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7629 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7631 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7632 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7633 folderidentifier = folder_item_get_identifier(account_get_special_folder
7634 (compose->account, F_OUTBOX));
7635 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7636 g_free(folderidentifier);
7640 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7641 GtkTreeViewColumn *column, Compose *compose)
7643 compose_attach_property(compose);
7646 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7649 Compose *compose = (Compose *)data;
7650 GtkTreeSelection *attach_selection;
7651 gint attach_nr_selected;
7652 GtkItemFactory *ifactory;
7654 if (!event) return FALSE;
7656 if (event->button == 3) {
7657 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7658 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7659 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7661 if (attach_nr_selected > 0)
7663 menu_set_sensitive(ifactory, "/Remove", TRUE);
7664 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7666 menu_set_sensitive(ifactory, "/Remove", FALSE);
7667 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7670 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7671 NULL, NULL, event->button, event->time);
7678 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7681 Compose *compose = (Compose *)data;
7683 if (!event) return FALSE;
7685 switch (event->keyval) {
7687 compose_attach_remove_selected(compose);
7693 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7695 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7696 toolbar_comp_set_sensitive(compose, allow);
7697 menu_set_sensitive(ifactory, "/Message", allow);
7698 menu_set_sensitive(ifactory, "/Edit", allow);
7700 menu_set_sensitive(ifactory, "/Spelling", allow);
7702 menu_set_sensitive(ifactory, "/Options", allow);
7703 menu_set_sensitive(ifactory, "/Tools", allow);
7704 menu_set_sensitive(ifactory, "/Help", allow);
7706 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7710 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7712 Compose *compose = (Compose *)data;
7714 if (prefs_common.work_offline &&
7715 !inc_offline_should_override(
7716 _("Sylpheed-Claws needs network access in order "
7717 "to send this email.")))
7720 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7721 gtk_timeout_remove(compose->draft_timeout_tag);
7722 compose->draft_timeout_tag = -1;
7725 compose_send(compose);
7728 static void compose_send_later_cb(gpointer data, guint action,
7731 Compose *compose = (Compose *)data;
7735 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
7739 compose_close(compose);
7740 } else if (val == -1) {
7741 alertpanel_error(_("Could not queue message."));
7742 } else if (val == -2) {
7743 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7744 } else if (val == -3) {
7745 if (privacy_peek_error())
7746 alertpanel_error(_("Could not queue message for sending:\n\n"
7747 "Signature failed: %s"), privacy_get_error());
7748 } else if (val == -4) {
7749 alertpanel_error(_("Could not queue message for sending:\n\n"
7750 "Charset conversion failed."));
7751 } else if (val == -5) {
7752 alertpanel_error(_("Could not queue message for sending:\n\n"
7753 "Couldn't get recipient encryption key."));
7755 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
7758 void compose_draft (gpointer data)
7760 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7763 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7765 Compose *compose = (Compose *)data;
7769 MsgFlags flag = {0, 0};
7770 static gboolean lock = FALSE;
7771 MsgInfo *newmsginfo;
7773 gboolean target_locked = FALSE;
7777 draft = account_get_special_folder(compose->account, F_DRAFT);
7778 g_return_if_fail(draft != NULL);
7780 if (!g_mutex_trylock(compose->mutex)) {
7781 /* we don't want to lock the mutex once it's available,
7782 * because as the only other part of compose.c locking
7783 * it is compose_close - which means once unlocked,
7784 * the compose struct will be freed */
7785 debug_print("couldn't lock mutex, probably sending\n");
7791 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7792 G_DIR_SEPARATOR, compose);
7793 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7794 FILE_OP_ERROR(tmp, "fopen");
7798 /* chmod for security */
7799 if (change_file_mode_rw(fp, tmp) < 0) {
7800 FILE_OP_ERROR(tmp, "chmod");
7801 g_warning("can't change file mode\n");
7804 /* Save draft infos */
7805 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7806 fprintf(fp, "S:%s\n", compose->account->address);
7808 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7809 gchar *savefolderid;
7811 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7812 fprintf(fp, "SCF:%s\n", savefolderid);
7813 g_free(savefolderid);
7815 if (compose->return_receipt) {
7816 fprintf(fp, "RRCPT:1\n");
7818 if (compose->privacy_system) {
7819 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7820 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7821 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7824 /* Message-ID of message replying to */
7825 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
7828 folderid = folder_item_get_identifier(compose->replyinfo->folder);
7829 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
7832 /* Message-ID of message forwarding to */
7833 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
7836 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
7837 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
7841 /* end of headers */
7842 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
7844 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
7852 if (compose->targetinfo) {
7853 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7854 flag.perm_flags = target_locked?MSG_LOCKED:0;
7856 flag.tmp_flags = MSG_DRAFT;
7858 folder_item_scan(draft);
7859 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7862 if (action != COMPOSE_AUTO_SAVE)
7863 alertpanel_error(_("Could not save draft."));
7868 if (compose->mode == COMPOSE_REEDIT) {
7869 compose_remove_reedit_target(compose, TRUE);
7872 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7874 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7876 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7878 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7879 if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
7880 procmsg_msginfo_set_flags(newmsginfo, 0,
7881 MSG_HAS_ATTACHMENT);
7883 procmsg_msginfo_free(newmsginfo);
7886 folder_item_scan(draft);
7888 if (action == COMPOSE_QUIT_EDITING) {
7890 g_mutex_unlock(compose->mutex); /* must be done before closing */
7891 compose_close(compose);
7897 path = folder_item_fetch_msg(draft, msgnum);
7899 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7902 if (g_stat(path, &s) < 0) {
7903 FILE_OP_ERROR(path, "stat");
7909 procmsg_msginfo_free(compose->targetinfo);
7910 compose->targetinfo = procmsg_msginfo_new();
7911 compose->targetinfo->msgnum = msgnum;
7912 compose->targetinfo->size = s.st_size;
7913 compose->targetinfo->mtime = s.st_mtime;
7914 compose->targetinfo->folder = draft;
7916 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7917 compose->mode = COMPOSE_REEDIT;
7919 if (action == COMPOSE_AUTO_SAVE) {
7920 compose->autosaved_draft = compose->targetinfo;
7922 compose->modified = FALSE;
7923 compose_set_title(compose);
7927 g_mutex_unlock(compose->mutex);
7930 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7932 Compose *compose = (Compose *)data;
7935 if (compose->redirect_filename != NULL)
7938 file_list = filesel_select_multiple_files_open(_("Select file"));
7943 for ( tmp = file_list; tmp; tmp = tmp->next) {
7944 gchar *file = (gchar *) tmp->data;
7945 gchar *utf8_filename = conv_filename_to_utf8(file);
7946 compose_attach_append(compose, file, utf8_filename, NULL);
7947 compose_changed_cb(NULL, compose);
7949 g_free(utf8_filename);
7951 g_list_free(file_list);
7955 static void compose_insert_file_cb(gpointer data, guint action,
7958 Compose *compose = (Compose *)data;
7961 file_list = filesel_select_multiple_files_open(_("Select file"));
7966 for ( tmp = file_list; tmp; tmp = tmp->next) {
7967 gchar *file = (gchar *) tmp->data;
7968 gchar *filedup = g_strdup(file);
7969 gchar *shortfile = g_path_get_basename(filedup);
7970 ComposeInsertResult res;
7972 res = compose_insert_file(compose, file);
7973 if (res == COMPOSE_INSERT_READ_ERROR) {
7974 alertpanel_error(_("File '%s' could not be read."), shortfile);
7975 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7976 alertpanel_error(_("File '%s' contained invalid characters\n"
7977 "for the current encoding, insertion may be incorrect."), shortfile);
7983 g_list_free(file_list);
7987 static void compose_insert_sig_cb(gpointer data, guint action,
7990 Compose *compose = (Compose *)data;
7992 compose_insert_sig(compose, FALSE);
7995 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7999 Compose *compose = (Compose *)data;
8001 gtkut_widget_get_uposition(widget, &x, &y);
8002 prefs_common.compose_x = x;
8003 prefs_common.compose_y = y;
8005 if (compose->sending || compose->updating)
8007 compose_close_cb(compose, 0, NULL);
8011 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
8013 Compose *compose = (Compose *)data;
8017 if (compose->exteditor_tag != -1) {
8018 if (!compose_ext_editor_kill(compose))
8023 if (compose->modified) {
8024 val = alertpanel(_("Discard message"),
8025 _("This message has been modified. Discard it?"),
8026 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
8029 case G_ALERTDEFAULT:
8030 if (prefs_common.autosave)
8031 compose_remove_draft(compose);
8033 case G_ALERTALTERNATE:
8034 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
8041 compose_close(compose);
8044 static void compose_set_encoding_cb(gpointer data, guint action,
8047 Compose *compose = (Compose *)data;
8049 if (GTK_CHECK_MENU_ITEM(widget)->active)
8050 compose->out_encoding = (CharSet)action;
8053 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
8055 Compose *compose = (Compose *)data;
8057 addressbook_open(compose);
8060 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
8062 Compose *compose = (Compose *)data;
8067 tmpl = g_object_get_data(G_OBJECT(widget), "template");
8068 g_return_if_fail(tmpl != NULL);
8070 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
8072 val = alertpanel(_("Apply template"), msg,
8073 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
8076 if (val == G_ALERTDEFAULT)
8077 compose_template_apply(compose, tmpl, TRUE);
8078 else if (val == G_ALERTALTERNATE)
8079 compose_template_apply(compose, tmpl, FALSE);
8082 static void compose_ext_editor_cb(gpointer data, guint action,
8085 Compose *compose = (Compose *)data;
8087 compose_exec_ext_editor(compose);
8090 static void compose_undo_cb(Compose *compose)
8092 gboolean prev_autowrap = compose->autowrap;
8094 compose->autowrap = FALSE;
8095 undo_undo(compose->undostruct);
8096 compose->autowrap = prev_autowrap;
8099 static void compose_redo_cb(Compose *compose)
8101 gboolean prev_autowrap = compose->autowrap;
8103 compose->autowrap = FALSE;
8104 undo_redo(compose->undostruct);
8105 compose->autowrap = prev_autowrap;
8108 static void entry_cut_clipboard(GtkWidget *entry)
8110 if (GTK_IS_EDITABLE(entry))
8111 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
8112 else if (GTK_IS_TEXT_VIEW(entry))
8113 gtk_text_buffer_cut_clipboard(
8114 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
8115 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
8119 static void entry_copy_clipboard(GtkWidget *entry)
8121 if (GTK_IS_EDITABLE(entry))
8122 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
8123 else if (GTK_IS_TEXT_VIEW(entry))
8124 gtk_text_buffer_copy_clipboard(
8125 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
8126 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
8129 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
8130 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
8132 if (GTK_IS_TEXT_VIEW(entry)) {
8133 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
8134 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
8135 GtkTextIter start_iter, end_iter;
8137 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
8139 if (contents == NULL)
8142 undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);
8144 /* we shouldn't delete the selection when middle-click-pasting, or we
8145 * can't mid-click-paste our own selection */
8146 if (clip != GDK_SELECTION_PRIMARY) {
8147 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
8150 if (insert_place == NULL) {
8151 /* if insert_place isn't specified, insert at the cursor.
8152 * used for Ctrl-V pasting */
8153 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
8154 start = gtk_text_iter_get_offset(&start_iter);
8155 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
8157 /* if insert_place is specified, paste here.
8158 * used for mid-click-pasting */
8159 start = gtk_text_iter_get_offset(insert_place);
8160 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
8164 /* paste unwrapped: mark the paste so it's not wrapped later */
8165 end = start + strlen(contents);
8166 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
8167 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
8168 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
8169 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
8170 /* rewrap paragraph now (after a mid-click-paste) */
8171 mark_start = gtk_text_buffer_get_insert(buffer);
8172 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
8173 gtk_text_iter_backward_char(&start_iter);
8174 compose_beautify_paragraph(compose, &start_iter, TRUE);
8176 } else if (GTK_IS_EDITABLE(entry))
8177 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
8181 static void entry_allsel(GtkWidget *entry)
8183 if (GTK_IS_EDITABLE(entry))
8184 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
8185 else if (GTK_IS_TEXT_VIEW(entry)) {
8186 GtkTextIter startiter, enditer;
8187 GtkTextBuffer *textbuf;
8189 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
8190 gtk_text_buffer_get_start_iter(textbuf, &startiter);
8191 gtk_text_buffer_get_end_iter(textbuf, &enditer);
8193 gtk_text_buffer_move_mark_by_name(textbuf,
8194 "selection_bound", &startiter);
8195 gtk_text_buffer_move_mark_by_name(textbuf,
8196 "insert", &enditer);
8200 static void compose_cut_cb(Compose *compose)
8202 if (compose->focused_editable &&
8203 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8204 entry_cut_clipboard(compose->focused_editable);
8207 static void compose_copy_cb(Compose *compose)
8209 if (compose->focused_editable &&
8210 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8211 entry_copy_clipboard(compose->focused_editable);
8214 static void compose_paste_cb(Compose *compose)
8217 GtkTextBuffer *buffer;
8219 if (compose->focused_editable &&
8220 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8221 entry_paste_clipboard(compose, compose->focused_editable,
8222 prefs_common.linewrap_pastes,
8223 GDK_SELECTION_CLIPBOARD, NULL);
8227 static void compose_paste_as_quote_cb(Compose *compose)
8229 gint wrap_quote = prefs_common.linewrap_quote;
8230 if (compose->focused_editable &&
8231 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
8232 /* let text_insert() (called directly or at a later time
8233 * after the gtk_editable_paste_clipboard) know that
8234 * text is to be inserted as a quotation. implemented
8235 * by using a simple refcount... */
8236 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
8237 G_OBJECT(compose->focused_editable),
8238 "paste_as_quotation"));
8239 g_object_set_data(G_OBJECT(compose->focused_editable),
8240 "paste_as_quotation",
8241 GINT_TO_POINTER(paste_as_quotation + 1));
8242 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
8243 entry_paste_clipboard(compose, compose->focused_editable,
8244 prefs_common.linewrap_pastes,
8245 GDK_SELECTION_CLIPBOARD, NULL);
8246 prefs_common.linewrap_quote = wrap_quote;
8250 static void compose_paste_no_wrap_cb(Compose *compose)
8253 GtkTextBuffer *buffer;
8255 if (compose->focused_editable &&
8256 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8257 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
8258 GDK_SELECTION_CLIPBOARD, NULL);
8262 static void compose_paste_wrap_cb(Compose *compose)
8265 GtkTextBuffer *buffer;
8267 if (compose->focused_editable &&
8268 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8269 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
8270 GDK_SELECTION_CLIPBOARD, NULL);
8274 static void compose_allsel_cb(Compose *compose)
8276 if (compose->focused_editable &&
8277 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8278 entry_allsel(compose->focused_editable);
8281 static void textview_move_beginning_of_line (GtkTextView *text)
8283 GtkTextBuffer *buffer;
8287 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8289 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8290 mark = gtk_text_buffer_get_insert(buffer);
8291 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8292 gtk_text_iter_set_line_offset(&ins, 0);
8293 gtk_text_buffer_place_cursor(buffer, &ins);
8296 static void textview_move_forward_character (GtkTextView *text)
8298 GtkTextBuffer *buffer;
8302 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8304 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8305 mark = gtk_text_buffer_get_insert(buffer);
8306 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8307 if (gtk_text_iter_forward_cursor_position(&ins))
8308 gtk_text_buffer_place_cursor(buffer, &ins);
8311 static void textview_move_backward_character (GtkTextView *text)
8313 GtkTextBuffer *buffer;
8317 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8319 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8320 mark = gtk_text_buffer_get_insert(buffer);
8321 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8322 if (gtk_text_iter_backward_cursor_position(&ins))
8323 gtk_text_buffer_place_cursor(buffer, &ins);
8326 static void textview_move_forward_word (GtkTextView *text)
8328 GtkTextBuffer *buffer;
8333 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8335 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8336 mark = gtk_text_buffer_get_insert(buffer);
8337 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8338 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8339 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8340 gtk_text_iter_backward_word_start(&ins);
8341 gtk_text_buffer_place_cursor(buffer, &ins);
8345 static void textview_move_backward_word (GtkTextView *text)
8347 GtkTextBuffer *buffer;
8352 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8354 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8355 mark = gtk_text_buffer_get_insert(buffer);
8356 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8357 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8358 if (gtk_text_iter_backward_word_starts(&ins, 1))
8359 gtk_text_buffer_place_cursor(buffer, &ins);
8362 static void textview_move_end_of_line (GtkTextView *text)
8364 GtkTextBuffer *buffer;
8368 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8370 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8371 mark = gtk_text_buffer_get_insert(buffer);
8372 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8373 if (gtk_text_iter_forward_to_line_end(&ins))
8374 gtk_text_buffer_place_cursor(buffer, &ins);
8377 static void textview_move_next_line (GtkTextView *text)
8379 GtkTextBuffer *buffer;
8384 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8386 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8387 mark = gtk_text_buffer_get_insert(buffer);
8388 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8389 offset = gtk_text_iter_get_line_offset(&ins);
8390 if (gtk_text_iter_forward_line(&ins)) {
8391 gtk_text_iter_set_line_offset(&ins, offset);
8392 gtk_text_buffer_place_cursor(buffer, &ins);
8396 static void textview_move_previous_line (GtkTextView *text)
8398 GtkTextBuffer *buffer;
8403 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8405 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8406 mark = gtk_text_buffer_get_insert(buffer);
8407 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8408 offset = gtk_text_iter_get_line_offset(&ins);
8409 if (gtk_text_iter_backward_line(&ins)) {
8410 gtk_text_iter_set_line_offset(&ins, offset);
8411 gtk_text_buffer_place_cursor(buffer, &ins);
8415 static void textview_delete_forward_character (GtkTextView *text)
8417 GtkTextBuffer *buffer;
8419 GtkTextIter ins, end_iter;
8421 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8423 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8424 mark = gtk_text_buffer_get_insert(buffer);
8425 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8427 if (gtk_text_iter_forward_char(&end_iter)) {
8428 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8432 static void textview_delete_backward_character (GtkTextView *text)
8434 GtkTextBuffer *buffer;
8436 GtkTextIter ins, end_iter;
8438 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8440 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8441 mark = gtk_text_buffer_get_insert(buffer);
8442 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8444 if (gtk_text_iter_backward_char(&end_iter)) {
8445 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8449 static void textview_delete_forward_word (GtkTextView *text)
8451 GtkTextBuffer *buffer;
8453 GtkTextIter ins, end_iter;
8455 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8457 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8458 mark = gtk_text_buffer_get_insert(buffer);
8459 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8461 if (gtk_text_iter_forward_word_end(&end_iter)) {
8462 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8466 static void textview_delete_backward_word (GtkTextView *text)
8468 GtkTextBuffer *buffer;
8470 GtkTextIter ins, end_iter;
8472 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8474 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8475 mark = gtk_text_buffer_get_insert(buffer);
8476 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8478 if (gtk_text_iter_backward_word_start(&end_iter)) {
8479 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8483 static void textview_delete_line (GtkTextView *text)
8485 GtkTextBuffer *buffer;
8487 GtkTextIter ins, start_iter, end_iter;
8490 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8492 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8493 mark = gtk_text_buffer_get_insert(buffer);
8494 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8497 gtk_text_iter_set_line_offset(&start_iter, 0);
8500 if (gtk_text_iter_ends_line(&end_iter))
8501 found = gtk_text_iter_forward_char(&end_iter);
8503 found = gtk_text_iter_forward_to_line_end(&end_iter);
8506 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8509 static void textview_delete_to_line_end (GtkTextView *text)
8511 GtkTextBuffer *buffer;
8513 GtkTextIter ins, end_iter;
8516 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8518 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8519 mark = gtk_text_buffer_get_insert(buffer);
8520 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8522 if (gtk_text_iter_ends_line(&end_iter))
8523 found = gtk_text_iter_forward_char(&end_iter);
8525 found = gtk_text_iter_forward_to_line_end(&end_iter);
8527 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8530 static void compose_advanced_action_cb(Compose *compose,
8531 ComposeCallAdvancedAction action)
8533 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8535 void (*do_action) (GtkTextView *text);
8536 } action_table[] = {
8537 {textview_move_beginning_of_line},
8538 {textview_move_forward_character},
8539 {textview_move_backward_character},
8540 {textview_move_forward_word},
8541 {textview_move_backward_word},
8542 {textview_move_end_of_line},
8543 {textview_move_next_line},
8544 {textview_move_previous_line},
8545 {textview_delete_forward_character},
8546 {textview_delete_backward_character},
8547 {textview_delete_forward_word},
8548 {textview_delete_backward_word},
8549 {textview_delete_line},
8550 {NULL}, /* gtk_stext_delete_line_n */
8551 {textview_delete_to_line_end}
8554 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8556 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8557 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8558 if (action_table[action].do_action)
8559 action_table[action].do_action(text);
8561 g_warning("Not implemented yet.");
8565 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8569 if (GTK_IS_EDITABLE(widget)) {
8570 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8571 gtk_editable_set_position(GTK_EDITABLE(widget),
8574 if (widget->parent && widget->parent->parent
8575 && widget->parent->parent->parent) {
8576 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8577 gint y = widget->allocation.y;
8578 gint height = widget->allocation.height;
8579 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8580 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8582 if (y < (int)shown->value) {
8583 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8585 if (y + height > (int)shown->value + (int)shown->page_size) {
8586 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8587 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8588 y + height - (int)shown->page_size - 1);
8590 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8591 (int)shown->upper - (int)shown->page_size - 1);
8598 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8599 compose->focused_editable = widget;
8602 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8604 compose->modified = TRUE;
8605 compose_set_title(compose);
8608 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8610 Compose *compose = (Compose *)data;
8613 compose_wrap_all_full(compose, TRUE);
8615 compose_beautify_paragraph(compose, NULL, TRUE);
8618 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8620 Compose *compose = (Compose *)data;
8622 message_search_compose(compose);
8625 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8628 Compose *compose = (Compose *)data;
8629 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8630 if (compose->autowrap)
8631 compose_wrap_all_full(compose, TRUE);
8632 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8635 static void compose_toggle_sign_cb(gpointer data, guint action,
8638 Compose *compose = (Compose *)data;
8640 if (GTK_CHECK_MENU_ITEM(widget)->active)
8641 compose->use_signing = TRUE;
8643 compose->use_signing = FALSE;
8646 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8649 Compose *compose = (Compose *)data;
8651 if (GTK_CHECK_MENU_ITEM(widget)->active)
8652 compose->use_encryption = TRUE;
8654 compose->use_encryption = FALSE;
8657 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8659 g_free(compose->privacy_system);
8661 compose->privacy_system = g_strdup(account->default_privacy_system);
8662 compose_update_privacy_system_menu_item(compose, warn);
8665 static void compose_toggle_ruler_cb(gpointer data, guint action,
8668 Compose *compose = (Compose *)data;
8670 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8671 gtk_widget_show(compose->ruler_hbox);
8672 prefs_common.show_ruler = TRUE;
8674 gtk_widget_hide(compose->ruler_hbox);
8675 gtk_widget_queue_resize(compose->edit_vbox);
8676 prefs_common.show_ruler = FALSE;
8680 static void compose_attach_drag_received_cb (GtkWidget *widget,
8681 GdkDragContext *context,
8684 GtkSelectionData *data,
8689 Compose *compose = (Compose *)user_data;
8692 if (gdk_atom_name(data->type) &&
8693 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8694 && gtk_drag_get_source_widget(context) !=
8695 summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
8696 list = uri_list_extract_filenames((const gchar *)data->data);
8697 for (tmp = list; tmp != NULL; tmp = tmp->next)
8698 compose_attach_append
8699 (compose, (const gchar *)tmp->data,
8700 (const gchar *)tmp->data, NULL);
8701 if (list) compose_changed_cb(NULL, compose);
8702 list_free_strings(list);
8704 } else if (gtk_drag_get_source_widget(context)
8705 == summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
8706 /* comes from our summaryview */
8707 SummaryView * summaryview = NULL;
8708 GSList * list = NULL, *cur = NULL;
8710 if (mainwindow_get_mainwindow())
8711 summaryview = mainwindow_get_mainwindow()->summaryview;
8714 list = summary_get_selected_msg_list(summaryview);
8716 for (cur = list; cur; cur = cur->next) {
8717 MsgInfo *msginfo = (MsgInfo *)cur->data;
8720 file = procmsg_get_message_file_full(msginfo,
8723 compose_attach_append(compose, (const gchar *)file,
8724 (const gchar *)file, "message/rfc822");
8732 static gboolean compose_drag_drop(GtkWidget *widget,
8733 GdkDragContext *drag_context,
8735 guint time, gpointer user_data)
8737 /* not handling this signal makes compose_insert_drag_received_cb
8742 static void compose_insert_drag_received_cb (GtkWidget *widget,
8743 GdkDragContext *drag_context,
8746 GtkSelectionData *data,
8751 Compose *compose = (Compose *)user_data;
8754 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8756 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8757 AlertValue val = G_ALERTDEFAULT;
8759 switch (prefs_common.compose_dnd_mode) {
8760 case COMPOSE_DND_ASK:
8761 val = alertpanel_full(_("Insert or attach?"),
8762 _("Do you want to insert the contents of the file(s) "
8763 "into the message body, or attach it to the email?"),
8764 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
8765 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
8767 case COMPOSE_DND_INSERT:
8768 val = G_ALERTALTERNATE;
8770 case COMPOSE_DND_ATTACH:
8774 /* unexpected case */
8775 g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
8778 if (val & G_ALERTDISABLE) {
8779 val &= ~G_ALERTDISABLE;
8780 /* remember what action to perform by default, only if we don't click Cancel */
8781 if (val == G_ALERTALTERNATE)
8782 prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
8783 else if (val == G_ALERTOTHER)
8784 prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
8787 if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
8788 gtk_drag_finish(drag_context, FALSE, FALSE, time);
8790 } else if (val == G_ALERTOTHER) {
8791 compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
8794 list = uri_list_extract_filenames((const gchar *)data->data);
8795 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8796 compose_insert_file(compose, (const gchar *)tmp->data);
8798 list_free_strings(list);
8800 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8803 #if GTK_CHECK_VERSION(2, 8, 0)
8804 /* do nothing, handled by GTK */
8806 gchar *tmpfile = get_tmp_file();
8807 str_write_to_file((const gchar *)data->data, tmpfile);
8808 compose_insert_file(compose, tmpfile);
8811 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8815 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8818 static void compose_header_drag_received_cb (GtkWidget *widget,
8819 GdkDragContext *drag_context,
8822 GtkSelectionData *data,
8827 GtkEditable *entry = (GtkEditable *)user_data;
8828 gchar *email = (gchar *)data->data;
8830 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8833 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8834 gchar *decoded=g_new(gchar, strlen(email));
8837 email += strlen("mailto:");
8838 decode_uri(decoded, email); /* will fit */
8839 gtk_editable_delete_text(entry, 0, -1);
8840 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8841 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8845 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8848 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8851 Compose *compose = (Compose *)data;
8853 if (GTK_CHECK_MENU_ITEM(widget)->active)
8854 compose->return_receipt = TRUE;
8856 compose->return_receipt = FALSE;
8859 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8862 Compose *compose = (Compose *)data;
8864 if (GTK_CHECK_MENU_ITEM(widget)->active)
8865 compose->remove_references = TRUE;
8867 compose->remove_references = FALSE;
8870 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8872 ComposeHeaderEntry *headerentry)
8874 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8875 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8876 !(event->state & GDK_MODIFIER_MASK) &&
8877 (event->keyval == GDK_BackSpace) &&
8878 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8879 gtk_container_remove
8880 (GTK_CONTAINER(headerentry->compose->header_table),
8881 headerentry->combo);
8882 gtk_container_remove
8883 (GTK_CONTAINER(headerentry->compose->header_table),
8884 headerentry->entry);
8885 headerentry->compose->header_list =
8886 g_slist_remove(headerentry->compose->header_list,
8888 g_free(headerentry);
8889 } else if (event->keyval == GDK_Tab) {
8890 if (headerentry->compose->header_last == headerentry) {
8891 /* Override default next focus, and give it to subject_entry
8892 * instead of notebook tabs
8894 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8895 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8902 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8903 ComposeHeaderEntry *headerentry)
8905 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8906 headerentry->compose->header_list =
8907 g_slist_append(headerentry->compose->header_list,
8910 compose_create_header_entry(headerentry->compose);
8911 g_signal_handlers_disconnect_matched
8912 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8913 0, 0, NULL, NULL, headerentry);
8915 /* Automatically scroll down */
8916 compose_show_first_last_header(headerentry->compose, FALSE);
8922 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8924 GtkAdjustment *vadj;
8926 g_return_if_fail(compose);
8927 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8928 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8930 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8931 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8934 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8935 const gchar *text, gint len, Compose *compose)
8937 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8938 (G_OBJECT(compose->text), "paste_as_quotation"));
8941 g_return_if_fail(text != NULL);
8943 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8944 G_CALLBACK(text_inserted),
8946 if (paste_as_quotation) {
8953 new_text = g_strndup(text, len);
8954 if (prefs_common.quotemark && *prefs_common.quotemark)
8955 qmark = prefs_common.quotemark;
8959 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8960 gtk_text_buffer_place_cursor(buffer, iter);
8962 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8963 quote_fmt_reset_vartable();
8965 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8966 GINT_TO_POINTER(paste_as_quotation - 1));
8968 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8969 gtk_text_buffer_place_cursor(buffer, iter);
8971 if (strcmp(text, "\n") || automatic_break
8972 || gtk_text_iter_starts_line(iter))
8973 gtk_text_buffer_insert(buffer, iter, text, len);
8975 debug_print("insert nowrap \\n\n");
8976 gtk_text_buffer_insert_with_tags_by_name(buffer,
8977 iter, text, len, "no_join", NULL);
8981 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8983 compose_beautify_paragraph(compose, iter, FALSE);
8985 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8986 gtk_text_buffer_delete_mark(buffer, mark);
8988 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8989 G_CALLBACK(text_inserted),
8991 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8993 if (prefs_common.autosave &&
8994 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8995 compose->draft_timeout_tag = gtk_timeout_add
8996 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8998 static gint compose_defer_auto_save_draft(Compose *compose)
9000 compose->draft_timeout_tag = -1;
9001 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
9006 static void compose_check_all(Compose *compose)
9008 if (compose->gtkaspell)
9009 gtkaspell_check_all(compose->gtkaspell);
9012 static void compose_highlight_all(Compose *compose)
9014 if (compose->gtkaspell)
9015 gtkaspell_highlight_all(compose->gtkaspell);
9018 static void compose_check_backwards(Compose *compose)
9020 if (compose->gtkaspell)
9021 gtkaspell_check_backwards(compose->gtkaspell);
9023 GtkItemFactory *ifactory;
9024 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
9025 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
9026 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
9030 static void compose_check_forwards_go(Compose *compose)
9032 if (compose->gtkaspell)
9033 gtkaspell_check_forwards_go(compose->gtkaspell);
9035 GtkItemFactory *ifactory;
9036 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
9037 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
9038 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
9044 *\brief Guess originating forward account from MsgInfo and several
9045 * "common preference" settings. Return NULL if no guess.
9047 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
9049 PrefsAccount *account = NULL;
9051 g_return_val_if_fail(msginfo, NULL);
9052 g_return_val_if_fail(msginfo->folder, NULL);
9053 g_return_val_if_fail(msginfo->folder->prefs, NULL);
9055 if (msginfo->folder->prefs->enable_default_account)
9056 account = account_find_from_id(msginfo->folder->prefs->default_account);
9059 account = msginfo->folder->folder->account;
9061 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
9063 Xstrdup_a(to, msginfo->to, return NULL);
9064 extract_address(to);
9065 account = account_find_from_address(to);
9068 if (!account && prefs_common.forward_account_autosel) {
9070 if (!procheader_get_header_from_msginfo
9071 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
9072 extract_address(cc);
9073 account = account_find_from_address(cc);
9080 gboolean compose_close(Compose *compose)
9084 if (!g_mutex_trylock(compose->mutex)) {
9085 /* we have to wait for the (possibly deferred by auto-save)
9086 * drafting to be done, before destroying the compose under
9088 debug_print("waiting for drafting to finish...\n");
9089 g_timeout_add (500, (GSourceFunc) compose_close, compose);
9092 g_return_val_if_fail(compose, FALSE);
9093 gtkut_widget_get_uposition(compose->window, &x, &y);
9094 prefs_common.compose_x = x;
9095 prefs_common.compose_y = y;
9096 g_mutex_unlock(compose->mutex);
9097 compose_destroy(compose);
9102 * Add entry field for each address in list.
9103 * \param compose E-Mail composition object.
9104 * \param listAddress List of (formatted) E-Mail addresses.
9106 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
9111 addr = ( gchar * ) node->data;
9112 compose_entry_append( compose, addr, COMPOSE_TO );
9113 node = g_list_next( node );
9117 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
9118 guint action, gboolean opening_multiple)
9121 GSList *new_msglist = NULL;
9122 MsgInfo *tmp_msginfo = NULL;
9123 gboolean originally_enc = FALSE;
9124 Compose *compose = NULL;
9126 g_return_if_fail(msgview != NULL);
9128 g_return_if_fail(msginfo_list != NULL);
9130 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
9131 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
9132 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
9134 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
9135 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
9136 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
9137 orig_msginfo, mimeinfo);
9138 if (tmp_msginfo != NULL) {
9139 new_msglist = g_slist_append(NULL, tmp_msginfo);
9140 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
9141 originally_enc = TRUE;
9147 if (!opening_multiple)
9148 body = messageview_get_selection(msgview);
9151 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
9152 procmsg_msginfo_free(tmp_msginfo);
9153 g_slist_free(new_msglist);
9155 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
9157 if (originally_enc) {
9158 compose_force_encryption(compose, compose->account, FALSE);
9164 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
9167 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
9168 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
9169 GSList *cur = msginfo_list;
9170 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
9171 "messages. Opening the windows "
9172 "could take some time. Do you "
9173 "want to continue?"),
9174 g_slist_length(msginfo_list));
9175 if (g_slist_length(msginfo_list) > 9
9176 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
9177 != G_ALERTALTERNATE) {
9182 /* We'll open multiple compose windows */
9183 /* let the WM place the next windows */
9184 compose_force_window_origin = FALSE;
9185 for (; cur; cur = cur->next) {
9187 tmplist.data = cur->data;
9188 tmplist.next = NULL;
9189 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
9191 compose_force_window_origin = TRUE;
9193 /* forwarding multiple mails as attachments is done via a
9194 * single compose window */
9195 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
9199 void compose_set_position(Compose *compose, gint pos)
9201 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9203 gtkut_text_view_set_position(text, pos);
9206 gboolean compose_search_string(Compose *compose,
9207 const gchar *str, gboolean case_sens)
9209 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9211 return gtkut_text_view_search_string(text, str, case_sens);
9214 gboolean compose_search_string_backward(Compose *compose,
9215 const gchar *str, gboolean case_sens)
9217 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9219 return gtkut_text_view_search_string_backward(text, str, case_sens);