2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.
21 #include "claws-features.h"
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
35 #include <pango/pango-break.h>
40 #include <sys/types.h>
46 # include <sys/wait.h>
50 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
54 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
61 #include "mainwindow.h"
63 #ifndef USE_ALT_ADDRBOOK
64 #include "addressbook.h"
66 #include "addressbook-dbus.h"
67 #include "addressadd.h"
69 #include "folderview.h"
72 #include "stock_pixmap.h"
73 #include "send_message.h"
76 #include "customheader.h"
77 #include "prefs_common.h"
78 #include "prefs_account.h"
82 #include "procheader.h"
84 #include "statusbar.h"
86 #include "quoted-printable.h"
90 #include "gtkshruler.h"
92 #include "alertpanel.h"
93 #include "manage_window.h"
95 #include "folder_item_prefs.h"
96 #include "addr_compl.h"
97 #include "quote_fmt.h"
99 #include "foldersel.h"
102 #include "message_search.h"
103 #include "combobox.h"
107 #include "autofaces.h"
108 #include "spell_entry.h"
122 #define N_ATTACH_COLS (N_COL_COLUMNS)
126 COMPOSE_CALL_ADVANCED_ACTION_UNDEFINED = -1,
127 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE = 0,
128 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
129 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
130 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
131 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
132 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
133 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
134 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
135 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
136 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
138 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
141 } ComposeCallAdvancedAction;
145 PRIORITY_HIGHEST = 1,
154 COMPOSE_INSERT_SUCCESS,
155 COMPOSE_INSERT_READ_ERROR,
156 COMPOSE_INSERT_INVALID_CHARACTER,
157 COMPOSE_INSERT_NO_FILE
158 } ComposeInsertResult;
162 COMPOSE_WRITE_FOR_SEND,
163 COMPOSE_WRITE_FOR_STORE
168 COMPOSE_QUOTE_FORCED,
175 SUBJECT_FIELD_PRESENT,
180 #define B64_LINE_SIZE 57
181 #define B64_BUFFSIZE 77
183 #define MAX_REFERENCES_LEN 999
185 #define COMPOSE_DRAFT_TIMEOUT_UNSET -1
186 #define COMPOSE_DRAFT_TIMEOUT_FORBIDDEN -2
188 static GdkColor default_header_bgcolor = {
195 static GdkColor default_header_color = {
202 static GList *compose_list = NULL;
203 static GSList *extra_headers = NULL;
205 static Compose *compose_generic_new (PrefsAccount *account,
209 GList *listAddress );
211 static Compose *compose_create (PrefsAccount *account,
216 static void compose_entry_indicate (Compose *compose,
217 const gchar *address);
218 static Compose *compose_followup_and_reply_to (MsgInfo *msginfo,
219 ComposeQuoteMode quote_mode,
223 static Compose *compose_forward_multiple (PrefsAccount *account,
224 GSList *msginfo_list);
225 static Compose *compose_reply (MsgInfo *msginfo,
226 ComposeQuoteMode quote_mode,
231 static Compose *compose_reply_mode (ComposeMode mode,
232 GSList *msginfo_list,
234 static void compose_template_apply_fields(Compose *compose, Template *tmpl);
235 static void compose_update_privacy_systems_menu(Compose *compose);
237 static GtkWidget *compose_account_option_menu_create
239 static void compose_set_out_encoding (Compose *compose);
240 static void compose_set_template_menu (Compose *compose);
241 static void compose_destroy (Compose *compose);
243 static MailField compose_entries_set (Compose *compose,
245 ComposeEntryType to_type);
246 static gint compose_parse_header (Compose *compose,
248 static gint compose_parse_manual_headers (Compose *compose,
250 HeaderEntry *entries);
251 static gchar *compose_parse_references (const gchar *ref,
254 static gchar *compose_quote_fmt (Compose *compose,
260 gboolean need_unescape,
261 const gchar *err_msg);
263 static void compose_reply_set_entry (Compose *compose,
269 followup_and_reply_to);
270 static void compose_reedit_set_entry (Compose *compose,
273 static void compose_insert_sig (Compose *compose,
275 static ComposeInsertResult compose_insert_file (Compose *compose,
278 static gboolean compose_attach_append (Compose *compose,
281 const gchar *content_type,
282 const gchar *charset);
283 static void compose_attach_parts (Compose *compose,
286 static gboolean compose_beautify_paragraph (Compose *compose,
287 GtkTextIter *par_iter,
289 static void compose_wrap_all (Compose *compose);
290 static void compose_wrap_all_full (Compose *compose,
293 static void compose_set_title (Compose *compose);
294 static void compose_select_account (Compose *compose,
295 PrefsAccount *account,
298 static PrefsAccount *compose_current_mail_account(void);
299 /* static gint compose_send (Compose *compose); */
300 static gboolean compose_check_for_valid_recipient
302 static gboolean compose_check_entries (Compose *compose,
303 gboolean check_everything);
304 static gint compose_write_to_file (Compose *compose,
307 gboolean attach_parts);
308 static gint compose_write_body_to_file (Compose *compose,
310 static gint compose_remove_reedit_target (Compose *compose,
312 static void compose_remove_draft (Compose *compose);
313 static gint compose_queue_sub (Compose *compose,
317 gboolean perform_checks,
318 gboolean remove_reedit_target);
319 static int compose_add_attachments (Compose *compose,
321 static gchar *compose_get_header (Compose *compose);
322 static gchar *compose_get_manual_headers_info (Compose *compose);
324 static void compose_convert_header (Compose *compose,
329 gboolean addr_field);
331 static void compose_attach_info_free (AttachInfo *ainfo);
332 static void compose_attach_remove_selected (GtkAction *action,
335 static void compose_template_apply (Compose *compose,
338 static void compose_attach_property (GtkAction *action,
340 static void compose_attach_property_create (gboolean *cancelled);
341 static void attach_property_ok (GtkWidget *widget,
342 gboolean *cancelled);
343 static void attach_property_cancel (GtkWidget *widget,
344 gboolean *cancelled);
345 static gint attach_property_delete_event (GtkWidget *widget,
347 gboolean *cancelled);
348 static gboolean attach_property_key_pressed (GtkWidget *widget,
350 gboolean *cancelled);
352 static void compose_exec_ext_editor (Compose *compose);
354 static gint compose_exec_ext_editor_real (const gchar *file,
355 GdkNativeWindow socket_wid);
356 static gboolean compose_ext_editor_kill (Compose *compose);
357 static gboolean compose_input_cb (GIOChannel *source,
358 GIOCondition condition,
360 static void compose_set_ext_editor_sensitive (Compose *compose,
362 static gboolean compose_get_ext_editor_cmd_valid();
363 static gboolean compose_get_ext_editor_uses_socket();
364 static gboolean compose_ext_editor_plug_removed_cb
367 #endif /* G_OS_UNIX */
369 static void compose_undo_state_changed (UndoMain *undostruct,
374 static void compose_create_header_entry (Compose *compose);
375 static void compose_add_header_entry (Compose *compose, const gchar *header,
376 gchar *text, ComposePrefType pref_type);
377 static void compose_remove_header_entries(Compose *compose);
379 static void compose_update_priority_menu_item(Compose * compose);
381 static void compose_spell_menu_changed (void *data);
382 static void compose_dict_changed (void *data);
384 static void compose_add_field_list ( Compose *compose,
385 GList *listAddress );
387 /* callback functions */
389 static void compose_notebook_size_alloc (GtkNotebook *notebook,
390 GtkAllocation *allocation,
392 static gboolean compose_edit_size_alloc (GtkEditable *widget,
393 GtkAllocation *allocation,
394 GtkSHRuler *shruler);
395 static void account_activated (GtkComboBox *optmenu,
397 static void attach_selected (GtkTreeView *tree_view,
398 GtkTreePath *tree_path,
399 GtkTreeViewColumn *column,
401 static gboolean attach_button_pressed (GtkWidget *widget,
402 GdkEventButton *event,
404 static gboolean attach_key_pressed (GtkWidget *widget,
407 static void compose_send_cb (GtkAction *action, gpointer data);
408 static void compose_send_later_cb (GtkAction *action, gpointer data);
410 static void compose_save_cb (GtkAction *action,
413 static void compose_attach_cb (GtkAction *action,
415 static void compose_insert_file_cb (GtkAction *action,
417 static void compose_insert_sig_cb (GtkAction *action,
419 static void compose_replace_sig_cb (GtkAction *action,
422 static void compose_close_cb (GtkAction *action,
424 static void compose_print_cb (GtkAction *action,
427 static void compose_set_encoding_cb (GtkAction *action, GtkRadioAction *current, gpointer data);
429 static void compose_address_cb (GtkAction *action,
431 static void about_show_cb (GtkAction *action,
433 static void compose_template_activate_cb(GtkWidget *widget,
436 static void compose_ext_editor_cb (GtkAction *action,
439 static gint compose_delete_cb (GtkWidget *widget,
443 static void compose_undo_cb (GtkAction *action,
445 static void compose_redo_cb (GtkAction *action,
447 static void compose_cut_cb (GtkAction *action,
449 static void compose_copy_cb (GtkAction *action,
451 static void compose_paste_cb (GtkAction *action,
453 static void compose_paste_as_quote_cb (GtkAction *action,
455 static void compose_paste_no_wrap_cb (GtkAction *action,
457 static void compose_paste_wrap_cb (GtkAction *action,
459 static void compose_allsel_cb (GtkAction *action,
462 static void compose_advanced_action_cb (GtkAction *action,
465 static void compose_grab_focus_cb (GtkWidget *widget,
468 static void compose_changed_cb (GtkTextBuffer *textbuf,
471 static void compose_wrap_cb (GtkAction *action,
473 static void compose_wrap_all_cb (GtkAction *action,
475 static void compose_find_cb (GtkAction *action,
477 static void compose_toggle_autowrap_cb (GtkToggleAction *action,
479 static void compose_toggle_autoindent_cb(GtkToggleAction *action,
482 static void compose_toggle_ruler_cb (GtkToggleAction *action,
484 static void compose_toggle_sign_cb (GtkToggleAction *action,
486 static void compose_toggle_encrypt_cb (GtkToggleAction *action,
488 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data);
489 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
490 static void activate_privacy_system (Compose *compose,
491 PrefsAccount *account,
493 static void compose_use_signing(Compose *compose, gboolean use_signing);
494 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
495 static void compose_toggle_return_receipt_cb(GtkToggleAction *action,
497 static void compose_toggle_remove_refs_cb(GtkToggleAction *action,
499 static void compose_set_priority_cb (GtkAction *action, GtkRadioAction *current, gpointer data);
500 static void compose_reply_change_mode (Compose *compose, ComposeMode action);
501 static void compose_reply_change_mode_cb(GtkAction *action, GtkRadioAction *current, gpointer data);
503 static void compose_attach_drag_received_cb (GtkWidget *widget,
504 GdkDragContext *drag_context,
507 GtkSelectionData *data,
511 static void compose_insert_drag_received_cb (GtkWidget *widget,
512 GdkDragContext *drag_context,
515 GtkSelectionData *data,
519 static void compose_header_drag_received_cb (GtkWidget *widget,
520 GdkDragContext *drag_context,
523 GtkSelectionData *data,
528 static gboolean compose_drag_drop (GtkWidget *widget,
529 GdkDragContext *drag_context,
531 guint time, gpointer user_data);
532 static gboolean completion_set_focus_to_subject
537 static void text_inserted (GtkTextBuffer *buffer,
542 static Compose *compose_generic_reply(MsgInfo *msginfo,
543 ComposeQuoteMode quote_mode,
547 gboolean followup_and_reply_to,
550 static void compose_headerentry_changed_cb (GtkWidget *entry,
551 ComposeHeaderEntry *headerentry);
552 static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
554 ComposeHeaderEntry *headerentry);
555 static gboolean compose_headerentry_button_clicked_cb (GtkWidget *button,
556 ComposeHeaderEntry *headerentry);
558 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
560 static void compose_allow_user_actions (Compose *compose, gboolean allow);
562 static void compose_nothing_cb (GtkAction *action, gpointer data)
568 static void compose_check_all (GtkAction *action, gpointer data);
569 static void compose_highlight_all (GtkAction *action, gpointer data);
570 static void compose_check_backwards (GtkAction *action, gpointer data);
571 static void compose_check_forwards_go (GtkAction *action, gpointer data);
574 static PrefsAccount *compose_find_account (MsgInfo *msginfo);
576 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
579 static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
580 FolderItem *folder_item);
582 static void compose_attach_update_label(Compose *compose);
583 static void compose_set_folder_prefs(Compose *compose, FolderItem *folder,
584 gboolean respect_default_to);
585 static void compose_subject_entry_activated(GtkWidget *widget, gpointer data);
586 static void from_name_activate_cb(GtkWidget *widget, gpointer data);
588 static GtkActionEntry compose_popup_entries[] =
590 {"Compose", NULL, "Compose", NULL, NULL, NULL },
591 {"Compose/Add", NULL, N_("_Add..."), NULL, NULL, G_CALLBACK(compose_attach_cb) },
592 {"Compose/Remove", NULL, N_("_Remove"), NULL, NULL, G_CALLBACK(compose_attach_remove_selected) },
593 {"Compose/---", NULL, "---", NULL, NULL, NULL },
594 {"Compose/Properties", NULL, N_("_Properties..."), NULL, NULL, G_CALLBACK(compose_attach_property) },
597 static GtkActionEntry compose_entries[] =
599 {"Menu", NULL, "Menu", NULL, NULL, NULL },
601 {"Message", NULL, N_("_Message"), NULL, NULL, NULL },
602 {"Edit", NULL, N_("_Edit"), NULL, NULL, NULL },
604 {"Spelling", NULL, N_("_Spelling"), NULL, NULL, NULL },
606 {"Options", NULL, N_("_Options"), NULL, NULL, NULL },
607 {"Tools", NULL, N_("_Tools"), NULL, NULL, NULL },
608 {"Help", NULL, N_("_Help"), NULL, NULL, NULL },
610 {"Message/Send", NULL, N_("S_end"), "<control>Return", NULL, G_CALLBACK(compose_send_cb) },
611 {"Message/SendLater", NULL, N_("Send _later"), "<shift><control>S", NULL, G_CALLBACK(compose_send_later_cb) },
612 {"Message/---", NULL, "---", NULL, NULL, NULL },
614 {"Message/AttachFile", NULL, N_("_Attach file"), "<control>M", NULL, G_CALLBACK(compose_attach_cb) },
615 {"Message/InsertFile", NULL, N_("_Insert file"), "<control>I", NULL, G_CALLBACK(compose_insert_file_cb) },
616 {"Message/InsertSig", NULL, N_("Insert si_gnature"), "<control>G", NULL, G_CALLBACK(compose_insert_sig_cb) },
617 {"Message/ReplaceSig", NULL, N_("_Replace signature"), NULL, NULL, G_CALLBACK(compose_replace_sig_cb) },
618 /* {"Message/---", NULL, "---", NULL, NULL, NULL }, */
619 {"Message/Save", NULL, N_("_Save"), "<control>S", NULL, G_CALLBACK(compose_save_cb) }, /*COMPOSE_KEEP_EDITING*/
620 /* {"Message/---", NULL, "---", NULL, NULL, NULL }, */
621 {"Message/Print", NULL, N_("_Print"), NULL, NULL, G_CALLBACK(compose_print_cb) },
622 /* {"Message/---", NULL, "---", NULL, NULL, NULL }, */
623 {"Message/Close", NULL, N_("_Close"), "<control>W", NULL, G_CALLBACK(compose_close_cb) },
626 {"Edit/Undo", NULL, N_("_Undo"), "<control>Z", NULL, G_CALLBACK(compose_undo_cb) },
627 {"Edit/Redo", NULL, N_("_Redo"), "<control>Y", NULL, G_CALLBACK(compose_redo_cb) },
628 {"Edit/---", NULL, "---", NULL, NULL, NULL },
630 {"Edit/Cut", NULL, N_("Cu_t"), "<control>X", NULL, G_CALLBACK(compose_cut_cb) },
631 {"Edit/Copy", NULL, N_("_Copy"), "<control>C", NULL, G_CALLBACK(compose_copy_cb) },
632 {"Edit/Paste", NULL, N_("_Paste"), "<control>V", NULL, G_CALLBACK(compose_paste_cb) },
634 {"Edit/SpecialPaste", NULL, N_("_Special paste"), NULL, NULL, NULL },
635 {"Edit/SpecialPaste/AsQuotation", NULL, N_("As _quotation"), NULL, NULL, G_CALLBACK(compose_paste_as_quote_cb) },
636 {"Edit/SpecialPaste/Wrapped", NULL, N_("_Wrapped"), NULL, NULL, G_CALLBACK(compose_paste_wrap_cb) },
637 {"Edit/SpecialPaste/Unwrapped", NULL, N_("_Unwrapped"), NULL, NULL, G_CALLBACK(compose_paste_no_wrap_cb) },
639 {"Edit/SelectAll", NULL, N_("Select _all"), "<control>A", NULL, G_CALLBACK(compose_allsel_cb) },
641 {"Edit/Advanced", NULL, N_("A_dvanced"), NULL, NULL, NULL },
642 {"Edit/Advanced/BackChar", NULL, N_("Move a character backward"), "<shift><control>B", NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER*/
643 {"Edit/Advanced/ForwChar", NULL, N_("Move a character forward"), "<shift><control>F", NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER*/
644 {"Edit/Advanced/BackWord", NULL, N_("Move a word backward"), NULL, NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD*/
645 {"Edit/Advanced/ForwWord", NULL, N_("Move a word forward"), NULL, NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD*/
646 {"Edit/Advanced/BegLine", NULL, N_("Move to beginning of line"), NULL, NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE*/
647 {"Edit/Advanced/EndLine", NULL, N_("Move to end of line"), NULL, NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE*/
648 {"Edit/Advanced/PrevLine", NULL, N_("Move to previous line"), "<control>P", NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE*/
649 {"Edit/Advanced/NextLine", NULL, N_("Move to next line"), "<control>N", NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE*/
650 {"Edit/Advanced/DelBackChar", NULL, N_("Delete a character backward"), "<control>H", NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER*/
651 {"Edit/Advanced/DelForwChar", NULL, N_("Delete a character forward"), "<control>D", NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER*/
652 {"Edit/Advanced/DelBackWord", NULL, N_("Delete a word backward"), NULL, NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD*/
653 {"Edit/Advanced/DelForwWord", NULL, N_("Delete a word forward"), NULL, NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD*/
654 {"Edit/Advanced/DelLine", NULL, N_("Delete line"), "<control>U", NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE*/
655 {"Edit/Advanced/DelEndLine", NULL, N_("Delete to end of line"), "<control>K", NULL, G_CALLBACK(compose_advanced_action_cb) }, /*COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END*/
657 /* {"Edit/---", NULL, "---", NULL, NULL, NULL }, */
658 {"Edit/Find", NULL, N_("_Find"), "<control>F", NULL, G_CALLBACK(compose_find_cb) },
660 /* {"Edit/---", NULL, "---", NULL, NULL, NULL }, */
661 {"Edit/WrapPara", NULL, N_("_Wrap current paragraph"), "<control>L", NULL, G_CALLBACK(compose_wrap_cb) }, /* 0 */
662 {"Edit/WrapAllLines", NULL, N_("Wrap all long _lines"), "<control><alt>L", NULL, G_CALLBACK(compose_wrap_all_cb) }, /* 1 */
663 /* {"Edit/---", NULL, "---", NULL, NULL, NULL }, */
664 {"Edit/ExtEditor", NULL, N_("Edit with e_xternal editor"), "<shift><control>X", NULL, G_CALLBACK(compose_ext_editor_cb) },
667 {"Spelling/CheckAllSel", NULL, N_("_Check all or check selection"), NULL, NULL, G_CALLBACK(compose_check_all) },
668 {"Spelling/HighlightAll", NULL, N_("_Highlight all misspelled words"), NULL, NULL, G_CALLBACK(compose_highlight_all) },
669 {"Spelling/CheckBackwards", NULL, N_("Check _backwards misspelled word"), NULL, NULL, G_CALLBACK(compose_check_backwards) },
670 {"Spelling/ForwardNext", NULL, N_("_Forward to next misspelled word"), NULL, NULL, G_CALLBACK(compose_check_forwards_go) },
672 {"Spelling/---", NULL, "---", NULL, NULL, NULL },
673 {"Spelling/Options", NULL, N_("_Options"), NULL, NULL, NULL },
677 {"Options/ReplyMode", NULL, N_("Reply _mode"), NULL, NULL, NULL },
678 {"Options/---", NULL, "---", NULL, NULL, NULL },
679 {"Options/PrivacySystem", NULL, N_("Privacy _System"), NULL, NULL, NULL },
680 {"Options/PrivacySystem/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(compose_nothing_cb) },
682 /* {"Options/---", NULL, "---", NULL, NULL, NULL }, */
683 {"Options/Priority", NULL, N_("_Priority"), NULL, NULL, NULL },
685 {"Options/Encoding", NULL, N_("Character _encoding"), NULL, NULL, NULL },
686 {"Options/Encoding/---", NULL, "---", NULL, NULL, NULL },
687 #define ENC_ACTION(cs_char,c_char,string) \
688 {"Options/Encoding/" cs_char, NULL, N_(string), NULL, NULL, c_char }
690 {"Options/Encoding/Western", NULL, N_("Western European"), NULL, NULL, NULL },
691 {"Options/Encoding/Baltic", NULL, N_("Baltic"), NULL, NULL, NULL },
692 {"Options/Encoding/Hebrew", NULL, N_("Hebrew"), NULL, NULL, NULL },
693 {"Options/Encoding/Arabic", NULL, N_("Arabic"), NULL, NULL, NULL },
694 {"Options/Encoding/Cyrillic", NULL, N_("Cyrillic"), NULL, NULL, NULL },
695 {"Options/Encoding/Japanese", NULL, N_("Japanese"), NULL, NULL, NULL },
696 {"Options/Encoding/Chinese", NULL, N_("Chinese"), NULL, NULL, NULL },
697 {"Options/Encoding/Korean", NULL, N_("Korean"), NULL, NULL, NULL },
698 {"Options/Encoding/Thai", NULL, N_("Thai"), NULL, NULL, NULL },
701 {"Tools/AddressBook", NULL, N_("_Address book"), NULL, NULL, G_CALLBACK(compose_address_cb) },
703 {"Tools/Template", NULL, N_("_Template"), NULL, NULL, NULL },
704 {"Tools/Template/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(compose_nothing_cb) },
705 {"Tools/Actions", NULL, N_("Actio_ns"), NULL, NULL, NULL },
706 {"Tools/Actions/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(compose_nothing_cb) },
709 {"Help/About", NULL, N_("_About"), NULL, NULL, G_CALLBACK(about_show_cb) },
712 static GtkToggleActionEntry compose_toggle_entries[] =
714 {"Edit/AutoWrap", NULL, N_("Aut_o wrapping"), "<shift><control>L", NULL, G_CALLBACK(compose_toggle_autowrap_cb), FALSE }, /* Toggle */
715 {"Edit/AutoIndent", NULL, N_("Auto _indent"), NULL, NULL, G_CALLBACK(compose_toggle_autoindent_cb), FALSE }, /* Toggle */
716 {"Options/Sign", NULL, N_("Si_gn"), NULL, NULL, G_CALLBACK(compose_toggle_sign_cb), FALSE }, /* Toggle */
717 {"Options/Encrypt", NULL, N_("_Encrypt"), NULL, NULL, G_CALLBACK(compose_toggle_encrypt_cb), FALSE }, /* Toggle */
718 {"Options/RequestRetRcpt", NULL, N_("_Request Return Receipt"), NULL, NULL, G_CALLBACK(compose_toggle_return_receipt_cb), FALSE }, /* Toggle */
719 {"Options/RemoveReferences", NULL, N_("Remo_ve references"), NULL, NULL, G_CALLBACK(compose_toggle_remove_refs_cb), FALSE }, /* Toggle */
720 {"Tools/ShowRuler", NULL, N_("Show _ruler"), NULL, NULL, G_CALLBACK(compose_toggle_ruler_cb), FALSE }, /* Toggle */
723 static GtkRadioActionEntry compose_radio_rm_entries[] =
725 {"Options/ReplyMode/Normal", NULL, N_("_Normal"), NULL, NULL, COMPOSE_REPLY }, /* RADIO compose_reply_change_mode_cb */
726 {"Options/ReplyMode/All", NULL, N_("_All"), NULL, NULL, COMPOSE_REPLY_TO_ALL }, /* RADIO compose_reply_change_mode_cb */
727 {"Options/ReplyMode/Sender", NULL, N_("_Sender"), NULL, NULL, COMPOSE_REPLY_TO_SENDER }, /* RADIO compose_reply_change_mode_cb */
728 {"Options/ReplyMode/List", NULL, N_("_Mailing-list"), NULL, NULL, COMPOSE_REPLY_TO_LIST }, /* RADIO compose_reply_change_mode_cb */
731 static GtkRadioActionEntry compose_radio_prio_entries[] =
733 {"Options/Priority/Highest", NULL, N_("_Highest"), NULL, NULL, PRIORITY_HIGHEST }, /* RADIO compose_set_priority_cb */
734 {"Options/Priority/High", NULL, N_("Hi_gh"), NULL, NULL, PRIORITY_HIGH }, /* RADIO compose_set_priority_cb */
735 {"Options/Priority/Normal", NULL, N_("_Normal"), NULL, NULL, PRIORITY_NORMAL }, /* RADIO compose_set_priority_cb */
736 {"Options/Priority/Low", NULL, N_("Lo_w"), NULL, NULL, PRIORITY_LOW }, /* RADIO compose_set_priority_cb */
737 {"Options/Priority/Lowest", NULL, N_("_Lowest"), NULL, NULL, PRIORITY_LOWEST }, /* RADIO compose_set_priority_cb */
740 static GtkRadioActionEntry compose_radio_enc_entries[] =
742 ENC_ACTION(CS_AUTO, C_AUTO, N_("_Automatic")), /* RADIO compose_set_encoding_cb */
743 ENC_ACTION(CS_US_ASCII, C_US_ASCII, N_("7bit ASCII (US-ASC_II)")), /* RADIO compose_set_encoding_cb */
744 ENC_ACTION(CS_UTF_8, C_UTF_8, N_("Unicode (_UTF-8)")), /* RADIO compose_set_encoding_cb */
745 ENC_ACTION("Western/"CS_ISO_8859_1, C_ISO_8859_1, "ISO-8859-_1"), /* RADIO compose_set_encoding_cb */
746 ENC_ACTION("Western/"CS_ISO_8859_15, C_ISO_8859_15, "ISO-8859-15"), /* RADIO compose_set_encoding_cb */
747 ENC_ACTION("Western/"CS_WINDOWS_1252, C_WINDOWS_1252, "Windows-1252"), /* RADIO compose_set_encoding_cb */
748 ENC_ACTION(CS_ISO_8859_2, C_ISO_8859_2, N_("Central European (ISO-8859-_2)")), /* RADIO compose_set_encoding_cb */
749 ENC_ACTION("Baltic/"CS_ISO_8859_13, C_ISO_8859_13, "ISO-8859-13"), /* RADIO compose_set_encoding_cb */
750 ENC_ACTION("Baltic/"CS_ISO_8859_4, C_ISO_8859_14, "ISO-8859-_4"), /* RADIO compose_set_encoding_cb */
751 ENC_ACTION(CS_ISO_8859_7, C_ISO_8859_7, N_("Greek (ISO-8859-_7)")), /* RADIO compose_set_encoding_cb */
752 ENC_ACTION("Hebrew/"CS_ISO_8859_8, C_ISO_8859_8, "ISO-8859-_8"), /* RADIO compose_set_encoding_cb */
753 ENC_ACTION("Hebrew/"CS_WINDOWS_1255, C_WINDOWS_1255, "Windows-1255"), /* RADIO compose_set_encoding_cb */
754 ENC_ACTION("Arabic/"CS_ISO_8859_6, C_ISO_8859_6, "ISO-8859-_6"), /* RADIO compose_set_encoding_cb */
755 ENC_ACTION("Arabic/"CS_WINDOWS_1256, C_WINDOWS_1256, "Windows-1256"), /* RADIO compose_set_encoding_cb */
756 ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, N_("Turkish (ISO-8859-_9)")), /* RADIO compose_set_encoding_cb */
757 ENC_ACTION("Cyrillic/"CS_ISO_8859_5, C_ISO_8859_5, "ISO-8859-_5"), /* RADIO compose_set_encoding_cb */
758 ENC_ACTION("Cyrillic/"CS_KOI8_R, C_KOI8_R, "KOI8-_R"), /* RADIO compose_set_encoding_cb */
759 ENC_ACTION("Cyrillic/"CS_MACCYR, C_MACCYR, "_Mac-Cyrillic"), /* RADIO compose_set_encoding_cb */
760 ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO compose_set_encoding_cb */
761 ENC_ACTION("Cyrillic/"CS_WINDOWS_1251, C_WINDOWS_1251, "Windows-1251"), /* RADIO compose_set_encoding_cb */
762 ENC_ACTION("Japanese/"CS_ISO_2022_JP, C_ISO_2022_JP, "ISO-2022-_JP"), /* RADIO compose_set_encoding_cb */
763 ENC_ACTION("Japanese/"CS_ISO_2022_JP_2, C_ISO_2022_JP_2, "ISO-2022-JP-_2"), /* RADIO compose_set_encoding_cb */
764 ENC_ACTION("Japanese/"CS_EUC_JP, C_EUC_JP, "_EUC-JP"), /* RADIO compose_set_encoding_cb */
765 ENC_ACTION("Japanese/"CS_SHIFT_JIS, C_SHIFT_JIS, "_Shift-JIS"), /* RADIO compose_set_encoding_cb */
766 ENC_ACTION("Chinese/"CS_GB18030, C_GB18030, "_GB18030"), /* RADIO compose_set_encoding_cb */
767 ENC_ACTION("Chinese/"CS_GB2312, C_GB2312, "_GB2312"), /* RADIO compose_set_encoding_cb */
768 ENC_ACTION("Chinese/"CS_GBK, C_GBK, "GB_K"), /* RADIO compose_set_encoding_cb */
769 ENC_ACTION("Chinese/"CS_BIG5, C_BIG5, "_Big5-JP"), /* RADIO compose_set_encoding_cb */
770 ENC_ACTION("Chinese/"CS_EUC_TW, C_EUC_TW, "EUC-_TW"), /* RADIO compose_set_encoding_cb */
771 ENC_ACTION("Korean/"CS_EUC_KR, C_EUC_KR, "_EUC-KR"), /* RADIO compose_set_encoding_cb */
772 ENC_ACTION("Korean/"CS_ISO_2022_KR, C_ISO_2022_KR, "_ISO-2022-KR"), /* RADIO compose_set_encoding_cb */
773 ENC_ACTION("Thai/"CS_TIS_620, C_TIS_620, "_TIS-620-KR"), /* RADIO compose_set_encoding_cb */
774 ENC_ACTION("Thai/"CS_WINDOWS_874, C_WINDOWS_874, "_Windows-874"), /* RADIO compose_set_encoding_cb */
777 static GtkTargetEntry compose_mime_types[] =
779 {"text/uri-list", 0, 0},
780 {"UTF8_STRING", 0, 0},
784 static gboolean compose_put_existing_to_front(MsgInfo *info)
786 const GList *compose_list = compose_get_compose_list();
787 const GList *elem = NULL;
790 for (elem = compose_list; elem != NULL && elem->data != NULL;
792 Compose *c = (Compose*)elem->data;
794 if (!c->targetinfo || !c->targetinfo->msgid ||
798 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
799 gtkut_window_popup(c->window);
807 static GdkColor quote_color1 =
808 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
809 static GdkColor quote_color2 =
810 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
811 static GdkColor quote_color3 =
812 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
814 static GdkColor quote_bgcolor1 =
815 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
816 static GdkColor quote_bgcolor2 =
817 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
818 static GdkColor quote_bgcolor3 =
819 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
821 static GdkColor signature_color = {
828 static GdkColor uri_color = {
835 static void compose_create_tags(GtkTextView *text, Compose *compose)
837 GtkTextBuffer *buffer;
838 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
839 #if !GTK_CHECK_VERSION(2, 24, 0)
846 buffer = gtk_text_view_get_buffer(text);
848 if (prefs_common.enable_color) {
849 /* grab the quote colors, converting from an int to a GdkColor */
850 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
852 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
854 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
856 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
858 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
860 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
862 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
864 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
867 signature_color = quote_color1 = quote_color2 = quote_color3 =
868 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
871 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
872 compose->quote0_tag = gtk_text_buffer_create_tag(buffer, "quote0",
873 "foreground-gdk", "e_color1,
874 "paragraph-background-gdk", "e_bgcolor1,
876 compose->quote1_tag = gtk_text_buffer_create_tag(buffer, "quote1",
877 "foreground-gdk", "e_color2,
878 "paragraph-background-gdk", "e_bgcolor2,
880 compose->quote2_tag = gtk_text_buffer_create_tag(buffer, "quote2",
881 "foreground-gdk", "e_color3,
882 "paragraph-background-gdk", "e_bgcolor3,
885 compose->quote0_tag = gtk_text_buffer_create_tag(buffer, "quote0",
886 "foreground-gdk", "e_color1,
888 compose->quote1_tag = gtk_text_buffer_create_tag(buffer, "quote1",
889 "foreground-gdk", "e_color2,
891 compose->quote2_tag = gtk_text_buffer_create_tag(buffer, "quote2",
892 "foreground-gdk", "e_color3,
896 compose->signature_tag = gtk_text_buffer_create_tag(buffer, "signature",
897 "foreground-gdk", &signature_color,
900 compose->uri_tag = gtk_text_buffer_create_tag(buffer, "link",
901 "foreground-gdk", &uri_color,
903 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
904 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
906 #if !GTK_CHECK_VERSION(2, 24, 0)
907 color[0] = quote_color1;
908 color[1] = quote_color2;
909 color[2] = quote_color3;
910 color[3] = quote_bgcolor1;
911 color[4] = quote_bgcolor2;
912 color[5] = quote_bgcolor3;
913 color[6] = signature_color;
914 color[7] = uri_color;
916 cmap = gdk_drawable_get_colormap(gtk_widget_get_window(compose->window));
917 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
919 for (i = 0; i < 8; i++) {
920 if (success[i] == FALSE) {
921 g_warning("Compose: color allocation failed.");
922 quote_color1 = quote_color2 = quote_color3 =
923 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
924 signature_color = uri_color = black;
930 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
933 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
936 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item, const gchar *mailto)
938 return compose_generic_new(account, mailto, item, NULL, NULL);
941 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
943 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
946 #define SCROLL_TO_CURSOR(compose) { \
947 GtkTextMark *cmark = gtk_text_buffer_get_insert( \
948 gtk_text_view_get_buffer( \
949 GTK_TEXT_VIEW(compose->text))); \
950 gtk_text_view_scroll_mark_onscreen( \
951 GTK_TEXT_VIEW(compose->text), \
955 static void compose_set_save_to(Compose *compose, const gchar *folderidentifier)
958 if (folderidentifier) {
959 #if !GTK_CHECK_VERSION(2, 24, 0)
960 combobox_unset_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo));
962 combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo));
964 prefs_common.compose_save_to_history = add_history(
965 prefs_common.compose_save_to_history, folderidentifier);
966 #if !GTK_CHECK_VERSION(2, 24, 0)
967 combobox_set_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo),
968 prefs_common.compose_save_to_history);
970 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo),
971 prefs_common.compose_save_to_history);
975 entry = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(compose->savemsg_combo)));
976 if (folderidentifier)
977 gtk_entry_set_text(GTK_ENTRY(entry), folderidentifier);
979 gtk_entry_set_text(GTK_ENTRY(entry), "");
982 static gchar *compose_get_save_to(Compose *compose)
985 gchar *result = NULL;
986 entry = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(compose->savemsg_combo)));
987 result = gtk_editable_get_chars(entry, 0, -1);
990 #if !GTK_CHECK_VERSION(2, 24, 0)
991 combobox_unset_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo));
993 combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo));
995 prefs_common.compose_save_to_history = add_history(
996 prefs_common.compose_save_to_history, result);
997 #if !GTK_CHECK_VERSION(2, 24, 0)
998 combobox_set_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo),
999 prefs_common.compose_save_to_history);
1001 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo),
1002 prefs_common.compose_save_to_history);
1008 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
1009 GList *attach_files, GList *listAddress )
1012 GtkTextView *textview;
1013 GtkTextBuffer *textbuf;
1015 const gchar *subject_format = NULL;
1016 const gchar *body_format = NULL;
1017 gchar *mailto_from = NULL;
1018 PrefsAccount *mailto_account = NULL;
1019 MsgInfo* dummyinfo = NULL;
1020 gint cursor_pos = -1;
1021 MailField mfield = NO_FIELD_PRESENT;
1025 /* check if mailto defines a from */
1026 if (mailto && *mailto != '\0') {
1027 scan_mailto_url(mailto, &mailto_from, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1028 /* mailto defines a from, check if we can get account prefs from it,
1029 if not, the account prefs will be guessed using other ways, but we'll keep
1032 mailto_account = account_find_from_address(mailto_from, TRUE);
1033 if (mailto_account == NULL) {
1035 Xstrdup_a(tmp_from, mailto_from, return NULL);
1036 extract_address(tmp_from);
1037 mailto_account = account_find_from_address(tmp_from, TRUE);
1041 account = mailto_account;
1044 /* if no account prefs set from mailto, set if from folder prefs (if any) */
1045 if (!mailto_account && item && item->prefs && item->prefs->enable_default_account)
1046 account = account_find_from_id(item->prefs->default_account);
1048 /* if no account prefs set, fallback to the current one */
1049 if (!account) account = cur_account;
1050 cm_return_val_if_fail(account != NULL, NULL);
1052 compose = compose_create(account, item, COMPOSE_NEW, FALSE);
1054 /* override from name if mailto asked for it */
1056 gtk_entry_set_text(GTK_ENTRY(compose->from_name), mailto_from);
1057 g_free(mailto_from);
1059 /* override from name according to folder properties */
1060 if (item && item->prefs &&
1061 item->prefs->compose_with_format &&
1062 item->prefs->compose_override_from_format &&
1063 *item->prefs->compose_override_from_format != '\0') {
1068 dummyinfo = compose_msginfo_new_from_compose(compose);
1070 /* decode \-escape sequences in the internal representation of the quote format */
1071 tmp = g_malloc(strlen(item->prefs->compose_override_from_format)+1);
1072 pref_get_unescaped_pref(tmp, item->prefs->compose_override_from_format);
1075 quote_fmt_init(dummyinfo, NULL, NULL, FALSE, compose->account, FALSE,
1076 compose->gtkaspell);
1078 quote_fmt_init(dummyinfo, NULL, NULL, FALSE, compose->account, FALSE);
1080 quote_fmt_scan_string(tmp);
1083 buf = quote_fmt_get_buffer();
1085 alertpanel_error(_("New message From format error."));
1087 gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
1088 quote_fmt_reset_vartable();
1093 compose->replyinfo = NULL;
1094 compose->fwdinfo = NULL;
1096 textview = GTK_TEXT_VIEW(compose->text);
1097 textbuf = gtk_text_view_get_buffer(textview);
1098 compose_create_tags(textview, compose);
1100 undo_block(compose->undostruct);
1102 compose_set_dictionaries_from_folder_prefs(compose, item);
1105 if (account->auto_sig)
1106 compose_insert_sig(compose, FALSE);
1107 gtk_text_buffer_get_start_iter(textbuf, &iter);
1108 gtk_text_buffer_place_cursor(textbuf, &iter);
1110 if (account->protocol != A_NNTP) {
1111 if (mailto && *mailto != '\0') {
1112 mfield = compose_entries_set(compose, mailto, COMPOSE_TO);
1115 compose_set_folder_prefs(compose, item, TRUE);
1117 if (item && item->ret_rcpt) {
1118 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", TRUE);
1121 if (mailto && *mailto != '\0') {
1122 if (!strchr(mailto, '@'))
1123 mfield = compose_entries_set(compose, mailto, COMPOSE_NEWSGROUPS);
1125 mfield = compose_entries_set(compose, mailto, COMPOSE_TO);
1126 } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
1127 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS, PREF_FOLDER);
1128 mfield = TO_FIELD_PRESENT;
1131 * CLAWS: just don't allow return receipt request, even if the user
1132 * may want to send an email. simple but foolproof.
1134 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", FALSE);
1136 compose_add_field_list( compose, listAddress );
1138 if (item && item->prefs && item->prefs->compose_with_format) {
1139 subject_format = item->prefs->compose_subject_format;
1140 body_format = item->prefs->compose_body_format;
1141 } else if (account->compose_with_format) {
1142 subject_format = account->compose_subject_format;
1143 body_format = account->compose_body_format;
1144 } else if (prefs_common.compose_with_format) {
1145 subject_format = prefs_common.compose_subject_format;
1146 body_format = prefs_common.compose_body_format;
1149 if (subject_format || body_format) {
1152 && *subject_format != '\0' )
1154 gchar *subject = NULL;
1159 dummyinfo = compose_msginfo_new_from_compose(compose);
1161 /* decode \-escape sequences in the internal representation of the quote format */
1162 tmp = g_malloc(strlen(subject_format)+1);
1163 pref_get_unescaped_pref(tmp, subject_format);
1165 subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
1167 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account, FALSE,
1168 compose->gtkaspell);
1170 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account, FALSE);
1172 quote_fmt_scan_string(tmp);
1175 buf = quote_fmt_get_buffer();
1177 alertpanel_error(_("New message subject format error."));
1179 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
1180 compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
1181 quote_fmt_reset_vartable();
1185 mfield = SUBJECT_FIELD_PRESENT;
1189 && *body_format != '\0' )
1192 GtkTextBuffer *buffer;
1193 GtkTextIter start, end;
1197 dummyinfo = compose_msginfo_new_from_compose(compose);
1199 text = GTK_TEXT_VIEW(compose->text);
1200 buffer = gtk_text_view_get_buffer(text);
1201 gtk_text_buffer_get_start_iter(buffer, &start);
1202 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
1203 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
1205 compose_quote_fmt(compose, dummyinfo,
1207 NULL, tmp, FALSE, TRUE,
1208 _("The body of the \"New message\" template has an error at line %d."));
1209 compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
1210 quote_fmt_reset_vartable();
1214 if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
1215 gtkaspell_highlight_all(compose->gtkaspell);
1217 mfield = BODY_FIELD_PRESENT;
1221 procmsg_msginfo_free( &dummyinfo );
1227 for (curr = attach_files ; curr != NULL ; curr = curr->next) {
1228 ainfo = (AttachInfo *) curr->data;
1229 compose_attach_append(compose, ainfo->file, ainfo->file,
1230 ainfo->content_type, ainfo->charset);
1234 compose_show_first_last_header(compose, TRUE);
1236 /* Set save folder */
1237 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1238 gchar *folderidentifier;
1240 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1241 folderidentifier = folder_item_get_identifier(item);
1242 compose_set_save_to(compose, folderidentifier);
1243 g_free(folderidentifier);
1246 /* Place cursor according to provided input (mfield) */
1248 case NO_FIELD_PRESENT:
1249 if (compose->header_last)
1250 gtk_widget_grab_focus(compose->header_last->entry);
1252 case TO_FIELD_PRESENT:
1253 buf = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
1255 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
1258 gtk_widget_grab_focus(compose->subject_entry);
1260 case SUBJECT_FIELD_PRESENT:
1261 textview = GTK_TEXT_VIEW(compose->text);
1264 textbuf = gtk_text_view_get_buffer(textview);
1267 mark = gtk_text_buffer_get_insert(textbuf);
1268 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1269 gtk_text_buffer_insert(textbuf, &iter, "", -1);
1271 * SUBJECT_FIELD_PRESENT and BODY_FIELD_PRESENT
1272 * only defers where it comes to the variable body
1273 * is not null. If no body is present compose->text
1274 * will be null in which case you cannot place the
1275 * cursor inside the component so. An empty component
1276 * is therefore created before placing the cursor
1278 case BODY_FIELD_PRESENT:
1279 cursor_pos = quote_fmt_get_cursor_pos();
1280 if (cursor_pos == -1)
1281 gtk_widget_grab_focus(compose->header_last->entry);
1283 gtk_widget_grab_focus(compose->text);
1287 undo_unblock(compose->undostruct);
1289 if (prefs_common.auto_exteditor)
1290 compose_exec_ext_editor(compose);
1292 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET;
1294 SCROLL_TO_CURSOR(compose);
1296 compose->modified = FALSE;
1297 compose_set_title(compose);
1299 hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
1304 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1305 gboolean override_pref, const gchar *system)
1307 const gchar *privacy = NULL;
1309 cm_return_if_fail(compose != NULL);
1310 cm_return_if_fail(account != NULL);
1312 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1315 if (account->default_privacy_system && strlen(account->default_privacy_system))
1316 privacy = account->default_privacy_system;
1320 GSList *privacy_avail = privacy_get_system_ids();
1321 if (privacy_avail && g_slist_length(privacy_avail)) {
1322 privacy = (gchar *)(privacy_avail->data);
1325 if (privacy != NULL) {
1327 g_free(compose->privacy_system);
1328 compose->privacy_system = NULL;
1329 g_free(compose->encdata);
1330 compose->encdata = NULL;
1332 if (compose->privacy_system == NULL)
1333 compose->privacy_system = g_strdup(privacy);
1334 else if (*(compose->privacy_system) == '\0') {
1335 g_free(compose->privacy_system);
1336 g_free(compose->encdata);
1337 compose->encdata = NULL;
1338 compose->privacy_system = g_strdup(privacy);
1340 compose_update_privacy_system_menu_item(compose, FALSE);
1341 compose_use_encryption(compose, TRUE);
1345 static void compose_force_signing(Compose *compose, PrefsAccount *account, const gchar *system)
1347 const gchar *privacy = NULL;
1349 if (account->default_privacy_system && strlen(account->default_privacy_system))
1350 privacy = account->default_privacy_system;
1354 GSList *privacy_avail = privacy_get_system_ids();
1355 if (privacy_avail && g_slist_length(privacy_avail)) {
1356 privacy = (gchar *)(privacy_avail->data);
1360 if (privacy != NULL) {
1362 g_free(compose->privacy_system);
1363 compose->privacy_system = NULL;
1364 g_free(compose->encdata);
1365 compose->encdata = NULL;
1367 if (compose->privacy_system == NULL)
1368 compose->privacy_system = g_strdup(privacy);
1369 compose_update_privacy_system_menu_item(compose, FALSE);
1370 compose_use_signing(compose, TRUE);
1374 static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1378 Compose *compose = NULL;
1380 cm_return_val_if_fail(msginfo_list != NULL, NULL);
1382 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1383 cm_return_val_if_fail(msginfo != NULL, NULL);
1385 list_len = g_slist_length(msginfo_list);
1389 case COMPOSE_REPLY_TO_ADDRESS:
1390 compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
1391 FALSE, prefs_common.default_reply_list, FALSE, body);
1393 case COMPOSE_REPLY_WITH_QUOTE:
1394 compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED,
1395 FALSE, prefs_common.default_reply_list, FALSE, body);
1397 case COMPOSE_REPLY_WITHOUT_QUOTE:
1398 compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP,
1399 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1401 case COMPOSE_REPLY_TO_SENDER:
1402 compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
1403 FALSE, FALSE, TRUE, body);
1405 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1406 compose = compose_followup_and_reply_to(msginfo,
1407 COMPOSE_QUOTE_CHECK,
1408 FALSE, FALSE, body);
1410 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1411 compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED,
1412 FALSE, FALSE, TRUE, body);
1414 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1415 compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP,
1416 FALSE, FALSE, TRUE, NULL);
1418 case COMPOSE_REPLY_TO_ALL:
1419 compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
1420 TRUE, FALSE, FALSE, body);
1422 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1423 compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED,
1424 TRUE, FALSE, FALSE, body);
1426 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1427 compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP,
1428 TRUE, FALSE, FALSE, NULL);
1430 case COMPOSE_REPLY_TO_LIST:
1431 compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
1432 FALSE, TRUE, FALSE, body);
1434 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1435 compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED,
1436 FALSE, TRUE, FALSE, body);
1438 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1439 compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP,
1440 FALSE, TRUE, FALSE, NULL);
1442 case COMPOSE_FORWARD:
1443 if (prefs_common.forward_as_attachment) {
1444 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1447 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1451 case COMPOSE_FORWARD_INLINE:
1452 /* check if we reply to more than one Message */
1453 if (list_len == 1) {
1454 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1457 /* more messages FALL THROUGH */
1458 case COMPOSE_FORWARD_AS_ATTACH:
1459 compose = compose_forward_multiple(NULL, msginfo_list);
1461 case COMPOSE_REDIRECT:
1462 compose = compose_redirect(NULL, msginfo, FALSE);
1465 g_warning("compose_reply_mode(): invalid Compose Mode: %d", mode);
1468 if (compose == NULL) {
1469 alertpanel_error(_("Unable to reply. The original email probably doesn't exist."));
1473 compose->rmode = mode;
1474 switch (compose->rmode) {
1476 case COMPOSE_REPLY_WITH_QUOTE:
1477 case COMPOSE_REPLY_WITHOUT_QUOTE:
1478 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1479 debug_print("reply mode Normal\n");
1480 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/ReplyMode/Normal", TRUE);
1481 compose_reply_change_mode(compose, COMPOSE_REPLY); /* force update */
1483 case COMPOSE_REPLY_TO_SENDER:
1484 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1485 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1486 debug_print("reply mode Sender\n");
1487 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/ReplyMode/Sender", TRUE);
1489 case COMPOSE_REPLY_TO_ALL:
1490 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1491 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1492 debug_print("reply mode All\n");
1493 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/ReplyMode/All", TRUE);
1495 case COMPOSE_REPLY_TO_LIST:
1496 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1497 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1498 debug_print("reply mode List\n");
1499 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/ReplyMode/List", TRUE);
1501 case COMPOSE_REPLY_TO_ADDRESS:
1502 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/ReplyMode", FALSE);
1510 static Compose *compose_reply(MsgInfo *msginfo,
1511 ComposeQuoteMode quote_mode,
1517 return compose_generic_reply(msginfo, quote_mode, to_all, to_ml,
1518 to_sender, FALSE, body);
1521 static Compose *compose_followup_and_reply_to(MsgInfo *msginfo,
1522 ComposeQuoteMode quote_mode,
1527 return compose_generic_reply(msginfo, quote_mode, to_all, FALSE,
1528 to_sender, TRUE, body);
1531 static void compose_extract_original_charset(Compose *compose)
1533 MsgInfo *info = NULL;
1534 if (compose->replyinfo) {
1535 info = compose->replyinfo;
1536 } else if (compose->fwdinfo) {
1537 info = compose->fwdinfo;
1538 } else if (compose->targetinfo) {
1539 info = compose->targetinfo;
1542 MimeInfo *mimeinfo = procmime_scan_message_short(info);
1543 MimeInfo *partinfo = mimeinfo;
1544 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1545 partinfo = procmime_mimeinfo_next(partinfo);
1547 compose->orig_charset =
1548 g_strdup(procmime_mimeinfo_get_parameter(
1549 partinfo, "charset"));
1551 procmime_mimeinfo_free_all(&mimeinfo);
1555 #define SIGNAL_BLOCK(buffer) { \
1556 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1557 G_CALLBACK(compose_changed_cb), \
1559 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1560 G_CALLBACK(text_inserted), \
1564 #define SIGNAL_UNBLOCK(buffer) { \
1565 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1566 G_CALLBACK(compose_changed_cb), \
1568 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1569 G_CALLBACK(text_inserted), \
1573 static Compose *compose_generic_reply(MsgInfo *msginfo,
1574 ComposeQuoteMode quote_mode,
1575 gboolean to_all, gboolean to_ml,
1577 gboolean followup_and_reply_to,
1581 PrefsAccount *account = NULL;
1582 GtkTextView *textview;
1583 GtkTextBuffer *textbuf;
1584 gboolean quote = FALSE;
1585 const gchar *qmark = NULL;
1586 const gchar *body_fmt = NULL;
1587 gchar *s_system = NULL;
1589 cm_return_val_if_fail(msginfo != NULL, NULL);
1590 cm_return_val_if_fail(msginfo->folder != NULL, NULL);
1592 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1594 cm_return_val_if_fail(account != NULL, NULL);
1596 compose = compose_create(account, msginfo->folder, COMPOSE_REPLY, FALSE);
1598 compose->updating = TRUE;
1600 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/RemoveReferences", FALSE);
1601 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/RemoveReferences", TRUE);
1603 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1604 if (!compose->replyinfo)
1605 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1607 compose_extract_original_charset(compose);
1609 if (msginfo->folder && msginfo->folder->ret_rcpt)
1610 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", TRUE);
1612 /* Set save folder */
1613 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1614 gchar *folderidentifier;
1616 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1617 folderidentifier = folder_item_get_identifier(msginfo->folder);
1618 compose_set_save_to(compose, folderidentifier);
1619 g_free(folderidentifier);
1622 if (compose_parse_header(compose, msginfo) < 0) {
1623 compose->updating = FALSE;
1624 compose_destroy(compose);
1628 /* override from name according to folder properties */
1629 if (msginfo->folder && msginfo->folder->prefs &&
1630 msginfo->folder->prefs->reply_with_format &&
1631 msginfo->folder->prefs->reply_override_from_format &&
1632 *msginfo->folder->prefs->reply_override_from_format != '\0') {
1637 /* decode \-escape sequences in the internal representation of the quote format */
1638 tmp = g_malloc(strlen(msginfo->folder->prefs->reply_override_from_format)+1);
1639 pref_get_unescaped_pref(tmp, msginfo->folder->prefs->reply_override_from_format);
1642 quote_fmt_init(compose->replyinfo, NULL, NULL, FALSE, compose->account, FALSE,
1643 compose->gtkaspell);
1645 quote_fmt_init(compose->replyinfo, NULL, NULL, FALSE, compose->account, FALSE);
1647 quote_fmt_scan_string(tmp);
1650 buf = quote_fmt_get_buffer();
1652 alertpanel_error(_("The \"From\" field of the \"Reply\" template contains an invalid email address."));
1654 gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
1655 quote_fmt_reset_vartable();
1660 textview = (GTK_TEXT_VIEW(compose->text));
1661 textbuf = gtk_text_view_get_buffer(textview);
1662 compose_create_tags(textview, compose);
1664 undo_block(compose->undostruct);
1666 compose_set_dictionaries_from_folder_prefs(compose, msginfo->folder);
1667 gtkaspell_block_check(compose->gtkaspell);
1670 if (quote_mode == COMPOSE_QUOTE_FORCED ||
1671 (quote_mode == COMPOSE_QUOTE_CHECK && prefs_common.reply_with_quote)) {
1672 /* use the reply format of folder (if enabled), or the account's one
1673 (if enabled) or fallback to the global reply format, which is always
1674 enabled (even if empty), and use the relevant quotemark */
1676 if (msginfo->folder && msginfo->folder->prefs &&
1677 msginfo->folder->prefs->reply_with_format) {
1678 qmark = msginfo->folder->prefs->reply_quotemark;
1679 body_fmt = msginfo->folder->prefs->reply_body_format;
1681 } else if (account->reply_with_format) {
1682 qmark = account->reply_quotemark;
1683 body_fmt = account->reply_body_format;
1686 qmark = prefs_common.quotemark;
1687 if (prefs_common.quotefmt && *prefs_common.quotefmt)
1688 body_fmt = gettext(prefs_common.quotefmt);
1695 /* empty quotemark is not allowed */
1696 if (qmark == NULL || *qmark == '\0')
1698 compose_quote_fmt(compose, compose->replyinfo,
1699 body_fmt, qmark, body, FALSE, TRUE,
1700 _("The body of the \"Reply\" template has an error at line %d."));
1701 compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
1702 quote_fmt_reset_vartable();
1705 if (MSG_IS_ENCRYPTED(compose->replyinfo->flags)) {
1706 compose_force_encryption(compose, account, FALSE, s_system);
1709 privacy_msginfo_get_signed_state(compose->replyinfo, &s_system);
1710 if (MSG_IS_SIGNED(compose->replyinfo->flags) && account->default_sign_reply) {
1711 compose_force_signing(compose, account, s_system);
1715 SIGNAL_BLOCK(textbuf);
1717 if (account->auto_sig)
1718 compose_insert_sig(compose, FALSE);
1720 compose_wrap_all(compose);
1723 if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
1724 gtkaspell_highlight_all(compose->gtkaspell);
1725 gtkaspell_unblock_check(compose->gtkaspell);
1727 SIGNAL_UNBLOCK(textbuf);
1729 gtk_widget_grab_focus(compose->text);
1731 undo_unblock(compose->undostruct);
1733 if (prefs_common.auto_exteditor)
1734 compose_exec_ext_editor(compose);
1736 compose->modified = FALSE;
1737 compose_set_title(compose);
1739 compose->updating = FALSE;
1740 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
1741 SCROLL_TO_CURSOR(compose);
1743 if (compose->deferred_destroy) {
1744 compose_destroy(compose);
1752 #define INSERT_FW_HEADER(var, hdr) \
1753 if (msginfo->var && *msginfo->var) { \
1754 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1755 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1756 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1759 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1760 gboolean as_attach, const gchar *body,
1761 gboolean no_extedit,
1765 GtkTextView *textview;
1766 GtkTextBuffer *textbuf;
1767 gint cursor_pos = -1;
1770 cm_return_val_if_fail(msginfo != NULL, NULL);
1771 cm_return_val_if_fail(msginfo->folder != NULL, NULL);
1773 if (!account && !(account = compose_find_account(msginfo)))
1774 account = cur_account;
1776 if (!prefs_common.forward_as_attachment)
1777 mode = COMPOSE_FORWARD_INLINE;
1779 mode = COMPOSE_FORWARD;
1780 compose = compose_create(account, msginfo->folder, mode, batch);
1782 compose->updating = TRUE;
1783 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1784 if (!compose->fwdinfo)
1785 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1787 compose_extract_original_charset(compose);
1789 if (msginfo->subject && *msginfo->subject) {
1790 gchar *buf, *buf2, *p;
1792 buf = p = g_strdup(msginfo->subject);
1793 p += subject_get_prefix_length(p);
1794 memmove(buf, p, strlen(p) + 1);
1796 buf2 = g_strdup_printf("Fw: %s", buf);
1797 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1803 /* override from name according to folder properties */
1804 if (msginfo->folder && msginfo->folder->prefs &&
1805 msginfo->folder->prefs->forward_with_format &&
1806 msginfo->folder->prefs->forward_override_from_format &&
1807 *msginfo->folder->prefs->forward_override_from_format != '\0') {
1811 MsgInfo *full_msginfo = NULL;
1814 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1816 full_msginfo = procmsg_msginfo_copy(msginfo);
1818 /* decode \-escape sequences in the internal representation of the quote format */
1819 tmp = g_malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
1820 pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
1823 gtkaspell_block_check(compose->gtkaspell);
1824 quote_fmt_init(full_msginfo, NULL, NULL, FALSE, compose->account, FALSE,
1825 compose->gtkaspell);
1827 quote_fmt_init(full_msginfo, NULL, NULL, FALSE, compose->account, FALSE);
1829 quote_fmt_scan_string(tmp);
1832 buf = quote_fmt_get_buffer();
1834 alertpanel_error(_("The \"From\" field of the \"Forward\" template contains an invalid email address."));
1836 gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
1837 quote_fmt_reset_vartable();
1840 procmsg_msginfo_free(&full_msginfo);
1843 textview = GTK_TEXT_VIEW(compose->text);
1844 textbuf = gtk_text_view_get_buffer(textview);
1845 compose_create_tags(textview, compose);
1847 undo_block(compose->undostruct);
1851 msgfile = procmsg_get_message_file(msginfo);
1852 if (!is_file_exist(msgfile))
1853 g_warning("%s: file does not exist", msgfile);
1855 compose_attach_append(compose, msgfile, msgfile,
1856 "message/rfc822", NULL);
1860 const gchar *qmark = NULL;
1861 const gchar *body_fmt = NULL;
1862 MsgInfo *full_msginfo;
1864 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1866 full_msginfo = procmsg_msginfo_copy(msginfo);
1868 /* use the forward format of folder (if enabled), or the account's one
1869 (if enabled) or fallback to the global forward format, which is always
1870 enabled (even if empty), and use the relevant quotemark */
1871 if (msginfo->folder && msginfo->folder->prefs &&
1872 msginfo->folder->prefs->forward_with_format) {
1873 qmark = msginfo->folder->prefs->forward_quotemark;
1874 body_fmt = msginfo->folder->prefs->forward_body_format;
1876 } else if (account->forward_with_format) {
1877 qmark = account->forward_quotemark;
1878 body_fmt = account->forward_body_format;
1881 qmark = prefs_common.fw_quotemark;
1882 if (prefs_common.fw_quotefmt && *prefs_common.fw_quotefmt)
1883 body_fmt = gettext(prefs_common.fw_quotefmt);
1888 /* empty quotemark is not allowed */
1889 if (qmark == NULL || *qmark == '\0')
1892 compose_quote_fmt(compose, full_msginfo,
1893 body_fmt, qmark, body, FALSE, TRUE,
1894 _("The body of the \"Forward\" template has an error at line %d."));
1895 compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
1896 quote_fmt_reset_vartable();
1897 compose_attach_parts(compose, msginfo);
1899 procmsg_msginfo_free(&full_msginfo);
1902 SIGNAL_BLOCK(textbuf);
1904 if (account->auto_sig)
1905 compose_insert_sig(compose, FALSE);
1907 compose_wrap_all(compose);
1910 if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
1911 gtkaspell_highlight_all(compose->gtkaspell);
1912 gtkaspell_unblock_check(compose->gtkaspell);
1914 SIGNAL_UNBLOCK(textbuf);
1916 cursor_pos = quote_fmt_get_cursor_pos();
1917 if (cursor_pos == -1)
1918 gtk_widget_grab_focus(compose->header_last->entry);
1920 gtk_widget_grab_focus(compose->text);
1922 if (!no_extedit && prefs_common.auto_exteditor)
1923 compose_exec_ext_editor(compose);
1926 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1927 gchar *folderidentifier;
1929 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1930 folderidentifier = folder_item_get_identifier(msginfo->folder);
1931 compose_set_save_to(compose, folderidentifier);
1932 g_free(folderidentifier);
1935 undo_unblock(compose->undostruct);
1937 compose->modified = FALSE;
1938 compose_set_title(compose);
1940 compose->updating = FALSE;
1941 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
1942 SCROLL_TO_CURSOR(compose);
1944 if (compose->deferred_destroy) {
1945 compose_destroy(compose);
1949 hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
1954 #undef INSERT_FW_HEADER
1956 static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1959 GtkTextView *textview;
1960 GtkTextBuffer *textbuf;
1964 gboolean single_mail = TRUE;
1966 cm_return_val_if_fail(msginfo_list != NULL, NULL);
1968 if (g_slist_length(msginfo_list) > 1)
1969 single_mail = FALSE;
1971 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1972 if (((MsgInfo *)msginfo->data)->folder == NULL)
1975 /* guess account from first selected message */
1977 !(account = compose_find_account(msginfo_list->data)))
1978 account = cur_account;
1980 cm_return_val_if_fail(account != NULL, NULL);
1982 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1983 if (msginfo->data) {
1984 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1985 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1989 if (msginfo_list == NULL || msginfo_list->data == NULL) {
1990 g_warning("no msginfo_list");
1994 compose = compose_create(account, ((MsgInfo *)msginfo_list->data)->folder, COMPOSE_FORWARD, FALSE);
1996 compose->updating = TRUE;
1998 /* override from name according to folder properties */
1999 if (msginfo_list->data) {
2000 MsgInfo *msginfo = msginfo_list->data;
2002 if (msginfo->folder && msginfo->folder->prefs &&
2003 msginfo->folder->prefs->forward_with_format &&
2004 msginfo->folder->prefs->forward_override_from_format &&
2005 *msginfo->folder->prefs->forward_override_from_format != '\0') {
2010 /* decode \-escape sequences in the internal representation of the quote format */
2011 tmp = g_malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
2012 pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
2015 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
2016 compose->gtkaspell);
2018 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
2020 quote_fmt_scan_string(tmp);
2023 buf = quote_fmt_get_buffer();
2025 alertpanel_error(_("The \"From\" field of the \"Forward\" template contains an invalid email address."));
2027 gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
2028 quote_fmt_reset_vartable();
2034 textview = GTK_TEXT_VIEW(compose->text);
2035 textbuf = gtk_text_view_get_buffer(textview);
2036 compose_create_tags(textview, compose);
2038 undo_block(compose->undostruct);
2039 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
2040 msgfile = procmsg_get_message_file((MsgInfo *)msginfo->data);
2042 if (!is_file_exist(msgfile))
2043 g_warning("%s: file does not exist", msgfile);
2045 compose_attach_append(compose, msgfile, msgfile,
2046 "message/rfc822", NULL);
2051 MsgInfo *info = (MsgInfo *)msginfo_list->data;
2052 if (info->subject && *info->subject) {
2053 gchar *buf, *buf2, *p;
2055 buf = p = g_strdup(info->subject);
2056 p += subject_get_prefix_length(p);
2057 memmove(buf, p, strlen(p) + 1);
2059 buf2 = g_strdup_printf("Fw: %s", buf);
2060 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2066 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
2067 _("Fw: multiple emails"));
2070 SIGNAL_BLOCK(textbuf);
2072 if (account->auto_sig)
2073 compose_insert_sig(compose, FALSE);
2075 compose_wrap_all(compose);
2077 SIGNAL_UNBLOCK(textbuf);
2079 gtk_text_buffer_get_start_iter(textbuf, &iter);
2080 gtk_text_buffer_place_cursor(textbuf, &iter);
2082 if (prefs_common.auto_exteditor)
2083 compose_exec_ext_editor(compose);
2085 gtk_widget_grab_focus(compose->header_last->entry);
2086 undo_unblock(compose->undostruct);
2087 compose->modified = FALSE;
2088 compose_set_title(compose);
2090 compose->updating = FALSE;
2091 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
2092 SCROLL_TO_CURSOR(compose);
2094 if (compose->deferred_destroy) {
2095 compose_destroy(compose);
2099 hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
2104 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
2106 GtkTextIter start = *iter;
2107 GtkTextIter end_iter;
2108 int start_pos = gtk_text_iter_get_offset(&start);
2110 if (!compose->account->sig_sep)
2113 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2114 start_pos+strlen(compose->account->sig_sep));
2116 /* check sig separator */
2117 str = gtk_text_iter_get_text(&start, &end_iter);
2118 if (!strcmp(str, compose->account->sig_sep)) {
2120 /* check end of line (\n) */
2121 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
2122 start_pos+strlen(compose->account->sig_sep));
2123 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2124 start_pos+strlen(compose->account->sig_sep)+1);
2125 tmp = gtk_text_iter_get_text(&start, &end_iter);
2126 if (!strcmp(tmp,"\n")) {
2138 static gboolean compose_update_folder_hook(gpointer source, gpointer data)
2140 FolderUpdateData *hookdata = (FolderUpdateData *)source;
2141 Compose *compose = (Compose *)data;
2142 FolderItem *old_item = NULL;
2143 FolderItem *new_item = NULL;
2144 gchar *old_id, *new_id;
2146 if (!(hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM)
2147 && !(hookdata->update_flags & FOLDER_MOVE_FOLDERITEM))
2150 old_item = hookdata->item;
2151 new_item = hookdata->item2;
2153 old_id = folder_item_get_identifier(old_item);
2154 new_id = new_item ? folder_item_get_identifier(new_item) : g_strdup("NULL");
2156 if (compose->targetinfo && compose->targetinfo->folder == old_item) {
2157 debug_print("updating targetinfo folder: %s -> %s\n", old_id, new_id);
2158 compose->targetinfo->folder = new_item;
2161 if (compose->replyinfo && compose->replyinfo->folder == old_item) {
2162 debug_print("updating replyinfo folder: %s -> %s\n", old_id, new_id);
2163 compose->replyinfo->folder = new_item;
2166 if (compose->fwdinfo && compose->fwdinfo->folder == old_item) {
2167 debug_print("updating fwdinfo folder: %s -> %s\n", old_id, new_id);
2168 compose->fwdinfo->folder = new_item;
2176 static void compose_colorize_signature(Compose *compose)
2178 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
2180 GtkTextIter end_iter;
2181 gtk_text_buffer_get_start_iter(buffer, &iter);
2182 while (gtk_text_iter_forward_line(&iter))
2183 if (compose_is_sig_separator(compose, buffer, &iter)) {
2184 gtk_text_buffer_get_end_iter(buffer, &end_iter);
2185 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
2189 #define BLOCK_WRAP() { \
2190 prev_autowrap = compose->autowrap; \
2191 buffer = gtk_text_view_get_buffer( \
2192 GTK_TEXT_VIEW(compose->text)); \
2193 compose->autowrap = FALSE; \
2195 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
2196 G_CALLBACK(compose_changed_cb), \
2198 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
2199 G_CALLBACK(text_inserted), \
2202 #define UNBLOCK_WRAP() { \
2203 compose->autowrap = prev_autowrap; \
2204 if (compose->autowrap) { \
2205 gint old = compose->draft_timeout_tag; \
2206 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_FORBIDDEN; \
2207 compose_wrap_all(compose); \
2208 compose->draft_timeout_tag = old; \
2211 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
2212 G_CALLBACK(compose_changed_cb), \
2214 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
2215 G_CALLBACK(text_inserted), \
2219 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
2221 Compose *compose = NULL;
2222 PrefsAccount *account = NULL;
2223 GtkTextView *textview;
2224 GtkTextBuffer *textbuf;
2228 gboolean use_signing = FALSE;
2229 gboolean use_encryption = FALSE;
2230 gchar *privacy_system = NULL;
2231 int priority = PRIORITY_NORMAL;
2232 MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
2233 gboolean autowrap = prefs_common.autowrap;
2234 gboolean autoindent = prefs_common.auto_indent;
2235 HeaderEntry *manual_headers = NULL;
2237 cm_return_val_if_fail(msginfo != NULL, NULL);
2238 cm_return_val_if_fail(msginfo->folder != NULL, NULL);
2240 if (compose_put_existing_to_front(msginfo)) {
2244 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
2245 folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
2246 folder_has_parent_of_type(msginfo->folder, F_OUTBOX)) {
2247 gchar *queueheader_buf = NULL;
2250 /* Select Account from queue headers */
2251 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2252 "X-Claws-Account-Id:")) {
2253 id = atoi(&queueheader_buf[strlen("X-Claws-Account-Id:")]);
2254 account = account_find_from_id(id);
2255 g_free(queueheader_buf);
2257 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2258 "X-Sylpheed-Account-Id:")) {
2259 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
2260 account = account_find_from_id(id);
2261 g_free(queueheader_buf);
2263 if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2265 id = atoi(&queueheader_buf[strlen("NAID:")]);
2266 account = account_find_from_id(id);
2267 g_free(queueheader_buf);
2269 if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2271 id = atoi(&queueheader_buf[strlen("MAID:")]);
2272 account = account_find_from_id(id);
2273 g_free(queueheader_buf);
2275 if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2277 account = account_find_from_address(queueheader_buf, FALSE);
2278 g_free(queueheader_buf);
2280 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2282 param = atoi(&queueheader_buf[strlen("X-Claws-Sign:")]);
2283 use_signing = param;
2284 g_free(queueheader_buf);
2286 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2287 "X-Sylpheed-Sign:")) {
2288 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
2289 use_signing = param;
2290 g_free(queueheader_buf);
2292 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2293 "X-Claws-Encrypt:")) {
2294 param = atoi(&queueheader_buf[strlen("X-Claws-Encrypt:")]);
2295 use_encryption = param;
2296 g_free(queueheader_buf);
2298 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2299 "X-Sylpheed-Encrypt:")) {
2300 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
2301 use_encryption = param;
2302 g_free(queueheader_buf);
2304 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2305 "X-Claws-Auto-Wrapping:")) {
2306 param = atoi(&queueheader_buf[strlen("X-Claws-Auto-Wrapping:")]);
2308 g_free(queueheader_buf);
2310 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2311 "X-Claws-Auto-Indent:")) {
2312 param = atoi(&queueheader_buf[strlen("X-Claws-Auto-Indent:")]);
2314 g_free(queueheader_buf);
2316 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2317 "X-Claws-Privacy-System:")) {
2318 privacy_system = g_strdup(&queueheader_buf[strlen("X-Claws-Privacy-System:")]);
2319 g_free(queueheader_buf);
2321 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2322 "X-Sylpheed-Privacy-System:")) {
2323 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
2324 g_free(queueheader_buf);
2326 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2328 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
2330 g_free(queueheader_buf);
2332 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2334 gchar **tokens = g_strsplit(&queueheader_buf[strlen("RMID:")], "\t", 0);
2335 if (tokens && tokens[0] && tokens[1] && tokens[2]) {
2336 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
2337 if (orig_item != NULL) {
2338 replyinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
2342 g_free(queueheader_buf);
2344 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2346 gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0);
2347 if (tokens && tokens[0] && tokens[1] && tokens[2]) {
2348 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
2349 if (orig_item != NULL) {
2350 fwdinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
2354 g_free(queueheader_buf);
2356 /* Get manual headers */
2357 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf,
2358 "X-Claws-Manual-Headers:")) {
2359 gchar *listmh = g_strdup(&queueheader_buf[strlen("X-Claws-Manual-Headers:")]);
2360 if (listmh && *listmh != '\0') {
2361 debug_print("Got manual headers: %s\n", listmh);
2362 manual_headers = procheader_entries_from_str(listmh);
2365 g_free(queueheader_buf);
2368 account = msginfo->folder->folder->account;
2371 if (!account && prefs_common.reedit_account_autosel) {
2373 if (!procheader_get_header_from_msginfo(msginfo, &from, "FROM:")) {
2374 extract_address(from);
2375 account = account_find_from_address(from, FALSE);
2380 account = cur_account;
2382 cm_return_val_if_fail(account != NULL, NULL);
2384 compose = compose_create(account, msginfo->folder, COMPOSE_REEDIT, batch);
2386 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoWrap", autowrap);
2387 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoIndent", autoindent);
2388 compose->autowrap = autowrap;
2389 compose->replyinfo = replyinfo;
2390 compose->fwdinfo = fwdinfo;
2392 compose->updating = TRUE;
2393 compose->priority = priority;
2395 if (privacy_system != NULL) {
2396 compose->privacy_system = privacy_system;
2397 compose_use_signing(compose, use_signing);
2398 compose_use_encryption(compose, use_encryption);
2399 compose_update_privacy_system_menu_item(compose, FALSE);
2401 activate_privacy_system(compose, account, FALSE);
2404 compose->targetinfo = procmsg_msginfo_copy(msginfo);
2406 compose_extract_original_charset(compose);
2408 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
2409 folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
2410 folder_has_parent_of_type(msginfo->folder, F_OUTBOX)) {
2411 gchar *queueheader_buf = NULL;
2413 /* Set message save folder */
2414 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "SCF:")) {
2415 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
2416 compose_set_save_to(compose, &queueheader_buf[4]);
2417 g_free(queueheader_buf);
2419 if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "RRCPT:")) {
2420 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
2422 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", TRUE);
2424 g_free(queueheader_buf);
2428 if (compose_parse_header(compose, msginfo) < 0) {
2429 compose->updating = FALSE;
2430 compose_destroy(compose);
2433 compose_reedit_set_entry(compose, msginfo);
2435 textview = GTK_TEXT_VIEW(compose->text);
2436 textbuf = gtk_text_view_get_buffer(textview);
2437 compose_create_tags(textview, compose);
2439 mark = gtk_text_buffer_get_insert(textbuf);
2440 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
2442 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
2443 G_CALLBACK(compose_changed_cb),
2446 if (MSG_IS_ENCRYPTED(msginfo->flags)) {
2447 fp = procmime_get_first_encrypted_text_content(msginfo);
2449 compose_force_encryption(compose, account, TRUE, NULL);
2452 fp = procmime_get_first_text_content(msginfo);
2455 g_warning("Can't get text part");
2459 gchar buf[BUFFSIZE];
2460 gboolean prev_autowrap;
2461 GtkTextBuffer *buffer;
2463 while (fgets(buf, sizeof(buf), fp) != NULL) {
2465 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
2471 compose_attach_parts(compose, msginfo);
2473 compose_colorize_signature(compose);
2475 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
2476 G_CALLBACK(compose_changed_cb),
2479 if (manual_headers != NULL) {
2480 if (compose_parse_manual_headers(compose, msginfo, manual_headers) < 0) {
2481 procheader_entries_free(manual_headers);
2482 compose->updating = FALSE;
2483 compose_destroy(compose);
2486 procheader_entries_free(manual_headers);
2489 gtk_widget_grab_focus(compose->text);
2491 if (prefs_common.auto_exteditor) {
2492 compose_exec_ext_editor(compose);
2494 compose->modified = FALSE;
2495 compose_set_title(compose);
2497 compose->updating = FALSE;
2498 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
2499 SCROLL_TO_CURSOR(compose);
2501 if (compose->deferred_destroy) {
2502 compose_destroy(compose);
2506 compose->sig_str = account_get_signature_str(compose->account);
2508 hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
2513 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
2520 cm_return_val_if_fail(msginfo != NULL, NULL);
2523 account = account_get_reply_account(msginfo,
2524 prefs_common.reply_account_autosel);
2525 cm_return_val_if_fail(account != NULL, NULL);
2527 compose = compose_create(account, msginfo->folder, COMPOSE_REDIRECT, batch);
2529 compose->updating = TRUE;
2531 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
2532 compose->replyinfo = NULL;
2533 compose->fwdinfo = NULL;
2535 compose_show_first_last_header(compose, TRUE);
2537 gtk_widget_grab_focus(compose->header_last->entry);
2539 filename = procmsg_get_message_file(msginfo);
2541 if (filename == NULL) {
2542 compose->updating = FALSE;
2543 compose_destroy(compose);
2548 compose->redirect_filename = filename;
2550 /* Set save folder */
2551 item = msginfo->folder;
2552 if (item && item->prefs && item->prefs->save_copy_to_folder) {
2553 gchar *folderidentifier;
2555 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
2556 folderidentifier = folder_item_get_identifier(item);
2557 compose_set_save_to(compose, folderidentifier);
2558 g_free(folderidentifier);
2561 compose_attach_parts(compose, msginfo);
2563 if (msginfo->subject)
2564 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
2566 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
2568 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE, FALSE,
2569 _("The body of the \"Redirect\" template has an error at line %d."));
2570 quote_fmt_reset_vartable();
2571 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
2573 compose_colorize_signature(compose);
2576 cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Add", FALSE);
2577 cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Remove", FALSE);
2578 cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Properties", FALSE);
2580 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/Save", FALSE);
2581 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertFile", FALSE);
2582 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/AttachFile", FALSE);
2583 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertSig", FALSE);
2584 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/ReplaceSig", FALSE);
2585 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit", FALSE);
2586 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options", FALSE);
2587 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools/ShowRuler", FALSE);
2588 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools/Actions", FALSE);
2590 if (compose->toolbar->draft_btn)
2591 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
2592 if (compose->toolbar->insert_btn)
2593 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
2594 if (compose->toolbar->attach_btn)
2595 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
2596 if (compose->toolbar->sig_btn)
2597 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
2598 if (compose->toolbar->exteditor_btn)
2599 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
2600 if (compose->toolbar->linewrap_current_btn)
2601 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
2602 if (compose->toolbar->linewrap_all_btn)
2603 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
2605 compose->modified = FALSE;
2606 compose_set_title(compose);
2607 compose->updating = FALSE;
2608 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
2609 SCROLL_TO_CURSOR(compose);
2611 if (compose->deferred_destroy) {
2612 compose_destroy(compose);
2616 hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
2621 const GList *compose_get_compose_list(void)
2623 return compose_list;
2626 void compose_entry_append(Compose *compose, const gchar *address,
2627 ComposeEntryType type, ComposePrefType pref_type)
2629 const gchar *header;
2631 gboolean in_quote = FALSE;
2632 if (!address || *address == '\0') return;
2639 header = N_("Bcc:");
2641 case COMPOSE_REPLYTO:
2642 header = N_("Reply-To:");
2644 case COMPOSE_NEWSGROUPS:
2645 header = N_("Newsgroups:");
2647 case COMPOSE_FOLLOWUPTO:
2648 header = N_( "Followup-To:");
2650 case COMPOSE_INREPLYTO:
2651 header = N_( "In-Reply-To:");
2658 header = prefs_common_translated_header_name(header);
2660 cur = begin = (gchar *)address;
2662 /* we separate the line by commas, but not if we're inside a quoted
2664 while (*cur != '\0') {
2666 in_quote = !in_quote;
2667 if (*cur == ',' && !in_quote) {
2668 gchar *tmp = g_strdup(begin);
2670 tmp[cur-begin]='\0';
2673 while (*tmp == ' ' || *tmp == '\t')
2675 compose_add_header_entry(compose, header, tmp, pref_type);
2676 compose_entry_indicate(compose, tmp);
2683 gchar *tmp = g_strdup(begin);
2685 tmp[cur-begin]='\0';
2686 while (*tmp == ' ' || *tmp == '\t')
2688 compose_add_header_entry(compose, header, tmp, pref_type);
2689 compose_entry_indicate(compose, tmp);
2694 static void compose_entry_indicate(Compose *compose, const gchar *mailto)
2699 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2700 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2701 if (gtk_entry_get_text(entry) &&
2702 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2703 gtk_widget_modify_base(
2704 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2705 GTK_STATE_NORMAL, &default_header_bgcolor);
2706 gtk_widget_modify_text(
2707 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2708 GTK_STATE_NORMAL, &default_header_color);
2713 void compose_toolbar_cb(gint action, gpointer data)
2715 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2716 Compose *compose = (Compose*)toolbar_item->parent;
2718 cm_return_if_fail(compose != NULL);
2722 compose_send_cb(NULL, compose);
2725 compose_send_later_cb(NULL, compose);
2728 compose_draft(compose, COMPOSE_QUIT_EDITING);
2731 compose_insert_file_cb(NULL, compose);
2734 compose_attach_cb(NULL, compose);
2737 compose_insert_sig(compose, FALSE);
2740 compose_insert_sig(compose, TRUE);
2743 compose_ext_editor_cb(NULL, compose);
2745 case A_LINEWRAP_CURRENT:
2746 compose_beautify_paragraph(compose, NULL, TRUE);
2748 case A_LINEWRAP_ALL:
2749 compose_wrap_all_full(compose, TRUE);
2752 compose_address_cb(NULL, compose);
2755 case A_CHECK_SPELLING:
2756 compose_check_all(NULL, compose);
2764 static MailField compose_entries_set(Compose *compose, const gchar *mailto, ComposeEntryType to_type)
2769 gchar *subject = NULL;
2773 gchar **attach = NULL;
2774 gchar *inreplyto = NULL;
2775 MailField mfield = NO_FIELD_PRESENT;
2777 /* get mailto parts but skip from */
2778 scan_mailto_url(mailto, NULL, &to, &cc, &bcc, &subject, &body, &attach, &inreplyto);
2781 compose_entry_append(compose, to, to_type, PREF_MAILTO);
2782 mfield = TO_FIELD_PRESENT;
2785 compose_entry_append(compose, cc, COMPOSE_CC, PREF_MAILTO);
2787 compose_entry_append(compose, bcc, COMPOSE_BCC, PREF_MAILTO);
2789 if (!g_utf8_validate (subject, -1, NULL)) {
2790 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2791 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2794 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2796 mfield = SUBJECT_FIELD_PRESENT;
2799 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2800 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2803 gboolean prev_autowrap = compose->autowrap;
2805 compose->autowrap = FALSE;
2807 mark = gtk_text_buffer_get_insert(buffer);
2808 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2810 if (!g_utf8_validate (body, -1, NULL)) {
2811 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2812 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2815 gtk_text_buffer_insert(buffer, &iter, body, -1);
2817 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2819 compose->autowrap = prev_autowrap;
2820 if (compose->autowrap)
2821 compose_wrap_all(compose);
2822 mfield = BODY_FIELD_PRESENT;
2826 gint i = 0, att = 0;
2827 gchar *warn_files = NULL;
2828 while (attach[i] != NULL) {
2829 gchar *utf8_filename = conv_filename_to_utf8(attach[i]);
2830 if (utf8_filename) {
2831 if (compose_attach_append(compose, attach[i], utf8_filename, NULL, NULL)) {
2832 gchar *tmp = g_strdup_printf("%s%s\n",
2833 warn_files?warn_files:"",
2839 g_free(utf8_filename);
2841 alertpanel_error(_("Couldn't attach a file (charset conversion failed)."));
2846 alertpanel_notice(ngettext(
2847 "The following file has been attached: \n%s",
2848 "The following files have been attached: \n%s", att), warn_files);
2853 compose_entry_append(compose, inreplyto, COMPOSE_INREPLYTO, PREF_MAILTO);
2866 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2868 static HeaderEntry hentry[] = {
2869 {"Reply-To:", NULL, TRUE },
2870 {"Cc:", NULL, TRUE },
2871 {"References:", NULL, FALSE },
2872 {"Bcc:", NULL, TRUE },
2873 {"Newsgroups:", NULL, TRUE },
2874 {"Followup-To:", NULL, TRUE },
2875 {"List-Post:", NULL, FALSE },
2876 {"X-Priority:", NULL, FALSE },
2877 {NULL, NULL, FALSE }
2894 cm_return_val_if_fail(msginfo != NULL, -1);
2896 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2897 procheader_get_header_fields(fp, hentry);
2900 if (hentry[H_REPLY_TO].body != NULL) {
2901 if (hentry[H_REPLY_TO].body[0] != '\0') {
2903 conv_unmime_header(hentry[H_REPLY_TO].body,
2906 g_free(hentry[H_REPLY_TO].body);
2907 hentry[H_REPLY_TO].body = NULL;
2909 if (hentry[H_CC].body != NULL) {
2910 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL, TRUE);
2911 g_free(hentry[H_CC].body);
2912 hentry[H_CC].body = NULL;
2914 if (hentry[H_REFERENCES].body != NULL) {
2915 if (compose->mode == COMPOSE_REEDIT)
2916 compose->references = hentry[H_REFERENCES].body;
2918 compose->references = compose_parse_references
2919 (hentry[H_REFERENCES].body, msginfo->msgid);
2920 g_free(hentry[H_REFERENCES].body);
2922 hentry[H_REFERENCES].body = NULL;
2924 if (hentry[H_BCC].body != NULL) {
2925 if (compose->mode == COMPOSE_REEDIT)
2927 conv_unmime_header(hentry[H_BCC].body, NULL, TRUE);
2928 g_free(hentry[H_BCC].body);
2929 hentry[H_BCC].body = NULL;
2931 if (hentry[H_NEWSGROUPS].body != NULL) {
2932 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2933 hentry[H_NEWSGROUPS].body = NULL;
2935 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2936 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2937 compose->followup_to =
2938 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2941 g_free(hentry[H_FOLLOWUP_TO].body);
2942 hentry[H_FOLLOWUP_TO].body = NULL;
2944 if (hentry[H_LIST_POST].body != NULL) {
2945 gchar *to = NULL, *start = NULL;
2947 extract_address(hentry[H_LIST_POST].body);
2948 if (hentry[H_LIST_POST].body[0] != '\0') {
2949 start = strstr(hentry[H_LIST_POST].body, "mailto:");
2951 scan_mailto_url(start ? start : hentry[H_LIST_POST].body,
2952 NULL, &to, NULL, NULL, NULL, NULL, NULL, NULL);
2955 g_free(compose->ml_post);
2956 compose->ml_post = to;
2959 g_free(hentry[H_LIST_POST].body);
2960 hentry[H_LIST_POST].body = NULL;
2963 /* CLAWS - X-Priority */
2964 if (compose->mode == COMPOSE_REEDIT)
2965 if (hentry[H_X_PRIORITY].body != NULL) {
2968 priority = atoi(hentry[H_X_PRIORITY].body);
2969 g_free(hentry[H_X_PRIORITY].body);
2971 hentry[H_X_PRIORITY].body = NULL;
2973 if (priority < PRIORITY_HIGHEST ||
2974 priority > PRIORITY_LOWEST)
2975 priority = PRIORITY_NORMAL;
2977 compose->priority = priority;
2980 if (compose->mode == COMPOSE_REEDIT) {
2981 if (msginfo->inreplyto && *msginfo->inreplyto)
2982 compose->inreplyto = g_strdup(msginfo->inreplyto);
2984 if (msginfo->msgid && *msginfo->msgid)
2985 compose->msgid = g_strdup(msginfo->msgid);
2987 if (msginfo->msgid && *msginfo->msgid)
2988 compose->inreplyto = g_strdup(msginfo->msgid);
2990 if (!compose->references) {
2991 if (msginfo->msgid && *msginfo->msgid) {
2992 if (msginfo->inreplyto && *msginfo->inreplyto)
2993 compose->references =
2994 g_strdup_printf("<%s>\n\t<%s>",
2998 compose->references =
2999 g_strconcat("<", msginfo->msgid, ">",
3001 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
3002 compose->references =
3003 g_strconcat("<", msginfo->inreplyto, ">",
3012 static gint compose_parse_manual_headers(Compose *compose, MsgInfo *msginfo, HeaderEntry *entries)
3017 cm_return_val_if_fail(msginfo != NULL, -1);
3019 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
3020 procheader_get_header_fields(fp, entries);
3024 while (he != NULL && he->name != NULL) {
3026 GtkListStore *model = NULL;
3028 debug_print("Adding manual header: %s with value %s\n", he->name, he->body);
3029 model = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(compose->header_last->combo)));
3030 COMBOBOX_ADD(model, he->name, COMPOSE_TO);
3031 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(compose->header_last->combo), &iter);
3032 gtk_entry_set_text(GTK_ENTRY(compose->header_last->entry), he->body);
3039 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
3041 GSList *ref_id_list, *cur;
3045 ref_id_list = references_list_append(NULL, ref);
3046 if (!ref_id_list) return NULL;
3047 if (msgid && *msgid)
3048 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
3053 for (cur = ref_id_list; cur != NULL; cur = cur->next)
3054 /* "<" + Message-ID + ">" + CR+LF+TAB */
3055 len += strlen((gchar *)cur->data) + 5;
3057 if (len > MAX_REFERENCES_LEN) {
3058 /* remove second message-ID */
3059 if (ref_id_list && ref_id_list->next &&
3060 ref_id_list->next->next) {
3061 g_free(ref_id_list->next->data);
3062 ref_id_list = g_slist_remove
3063 (ref_id_list, ref_id_list->next->data);
3065 slist_free_strings_full(ref_id_list);
3072 new_ref = g_string_new("");
3073 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
3074 if (new_ref->len > 0)
3075 g_string_append(new_ref, "\n\t");
3076 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
3079 slist_free_strings_full(ref_id_list);
3081 new_ref_str = new_ref->str;
3082 g_string_free(new_ref, FALSE);
3087 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
3088 const gchar *fmt, const gchar *qmark,
3089 const gchar *body, gboolean rewrap,
3090 gboolean need_unescape,
3091 const gchar *err_msg)
3093 MsgInfo* dummyinfo = NULL;
3094 gchar *quote_str = NULL;
3096 gboolean prev_autowrap;
3097 const gchar *trimmed_body = body;
3098 gint cursor_pos = -1;
3099 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3100 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
3105 SIGNAL_BLOCK(buffer);
3108 dummyinfo = compose_msginfo_new_from_compose(compose);
3109 msginfo = dummyinfo;
3112 if (qmark != NULL) {
3114 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
3115 compose->gtkaspell);
3117 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
3119 quote_fmt_scan_string(qmark);
3122 buf = quote_fmt_get_buffer();
3124 alertpanel_error(_("The \"Quotation mark\" of the template is invalid."));
3126 Xstrdup_a(quote_str, buf, goto error)
3129 if (fmt && *fmt != '\0') {
3132 while (*trimmed_body == '\n')
3136 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account, FALSE,
3137 compose->gtkaspell);
3139 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account, FALSE);
3141 if (need_unescape) {
3144 /* decode \-escape sequences in the internal representation of the quote format */
3145 tmp = g_malloc(strlen(fmt)+1);
3146 pref_get_unescaped_pref(tmp, fmt);
3147 quote_fmt_scan_string(tmp);
3151 quote_fmt_scan_string(fmt);
3155 buf = quote_fmt_get_buffer();
3157 gint line = quote_fmt_get_line();
3158 alertpanel_error(err_msg, line);
3164 prev_autowrap = compose->autowrap;
3165 compose->autowrap = FALSE;
3167 mark = gtk_text_buffer_get_insert(buffer);
3168 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3169 if (g_utf8_validate(buf, -1, NULL)) {
3170 gtk_text_buffer_insert(buffer, &iter, buf, -1);
3172 gchar *tmpout = NULL;
3173 tmpout = conv_codeset_strdup
3174 (buf, conv_get_locale_charset_str_no_utf8(),
3176 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
3178 tmpout = g_malloc(strlen(buf)*2+1);
3179 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
3181 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
3185 cursor_pos = quote_fmt_get_cursor_pos();
3186 if (cursor_pos == -1)
3187 cursor_pos = gtk_text_iter_get_offset(&iter);
3188 compose->set_cursor_pos = cursor_pos;
3190 gtk_text_buffer_get_start_iter(buffer, &iter);
3191 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
3192 gtk_text_buffer_place_cursor(buffer, &iter);
3194 compose->autowrap = prev_autowrap;
3195 if (compose->autowrap && rewrap)
3196 compose_wrap_all(compose);
3203 SIGNAL_UNBLOCK(buffer);
3205 procmsg_msginfo_free( &dummyinfo );
3210 /* if ml_post is of type addr@host and from is of type
3211 * addr-anything@host, return TRUE
3213 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
3215 gchar *left_ml = NULL;
3216 gchar *right_ml = NULL;
3217 gchar *left_from = NULL;
3218 gchar *right_from = NULL;
3219 gboolean result = FALSE;
3221 if (!ml_post || !from)
3224 left_ml = g_strdup(ml_post);
3225 if (strstr(left_ml, "@")) {
3226 right_ml = strstr(left_ml, "@")+1;
3227 *(strstr(left_ml, "@")) = '\0';
3230 left_from = g_strdup(from);
3231 if (strstr(left_from, "@")) {
3232 right_from = strstr(left_from, "@")+1;
3233 *(strstr(left_from, "@")) = '\0';
3236 if (right_ml && right_from
3237 && !strncmp(left_from, left_ml, strlen(left_ml))
3238 && !strcmp(right_from, right_ml)) {
3247 static void compose_set_folder_prefs(Compose *compose, FolderItem *folder,
3248 gboolean respect_default_to)
3252 if (!folder || !folder->prefs)
3255 if (respect_default_to && folder->prefs->enable_default_to) {
3256 compose_entry_append(compose, folder->prefs->default_to,
3257 COMPOSE_TO, PREF_FOLDER);
3258 compose_entry_indicate(compose, folder->prefs->default_to);
3260 if (folder->prefs->enable_default_cc) {
3261 compose_entry_append(compose, folder->prefs->default_cc,
3262 COMPOSE_CC, PREF_FOLDER);
3263 compose_entry_indicate(compose, folder->prefs->default_cc);
3265 if (folder->prefs->enable_default_bcc) {
3266 compose_entry_append(compose, folder->prefs->default_bcc,
3267 COMPOSE_BCC, PREF_FOLDER);
3268 compose_entry_indicate(compose, folder->prefs->default_bcc);
3270 if (folder->prefs->enable_default_replyto) {
3271 compose_entry_append(compose, folder->prefs->default_replyto,
3272 COMPOSE_REPLYTO, PREF_FOLDER);
3273 compose_entry_indicate(compose, folder->prefs->default_replyto);
3277 static void compose_reply_set_subject(Compose *compose, MsgInfo *msginfo)
3282 if (!compose || !msginfo)
3285 if (msginfo->subject && *msginfo->subject) {
3286 buf = p = g_strdup(msginfo->subject);
3287 p += subject_get_prefix_length(p);
3288 memmove(buf, p, strlen(p) + 1);
3290 buf2 = g_strdup_printf("Re: %s", buf);
3291 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
3296 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
3299 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
3300 gboolean to_all, gboolean to_ml,
3302 gboolean followup_and_reply_to)
3304 GSList *cc_list = NULL;
3307 gchar *replyto = NULL;
3308 gchar *ac_email = NULL;
3310 gboolean reply_to_ml = FALSE;
3311 gboolean default_reply_to = FALSE;
3313 cm_return_if_fail(compose->account != NULL);
3314 cm_return_if_fail(msginfo != NULL);
3316 reply_to_ml = to_ml && compose->ml_post;
3318 default_reply_to = msginfo->folder &&
3319 msginfo->folder->prefs->enable_default_reply_to;
3321 if (compose->account->protocol != A_NNTP) {
3322 compose_set_folder_prefs(compose, msginfo->folder, FALSE);
3324 if (reply_to_ml && !default_reply_to) {
3326 gboolean is_subscr = is_subscription(compose->ml_post,
3329 /* normal answer to ml post with a reply-to */
3330 compose_entry_append(compose,
3332 COMPOSE_TO, PREF_ML);
3333 if (compose->replyto)
3334 compose_entry_append(compose,
3336 COMPOSE_CC, PREF_ML);
3338 /* answer to subscription confirmation */
3339 if (compose->replyto)
3340 compose_entry_append(compose,
3342 COMPOSE_TO, PREF_ML);
3343 else if (msginfo->from)
3344 compose_entry_append(compose,
3346 COMPOSE_TO, PREF_ML);
3349 else if (!(to_all || to_sender) && default_reply_to) {
3350 compose_entry_append(compose,
3351 msginfo->folder->prefs->default_reply_to,
3352 COMPOSE_TO, PREF_FOLDER);
3353 compose_entry_indicate(compose,
3354 msginfo->folder->prefs->default_reply_to);
3360 compose_entry_append(compose, msginfo->from,
3361 COMPOSE_TO, PREF_NONE);
3363 Xstrdup_a(tmp1, msginfo->from, return);
3364 extract_address(tmp1);
3365 compose_entry_append(compose,
3366 (!account_find_from_address(tmp1, FALSE))
3369 COMPOSE_TO, PREF_NONE);
3370 if (compose->replyto)
3371 compose_entry_append(compose,
3373 COMPOSE_CC, PREF_NONE);
3375 if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
3376 !folder_has_parent_of_type(msginfo->folder, F_OUTBOX) &&
3377 !folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
3378 if (compose->replyto) {
3379 compose_entry_append(compose,
3381 COMPOSE_TO, PREF_NONE);
3383 compose_entry_append(compose,
3384 msginfo->from ? msginfo->from : "",
3385 COMPOSE_TO, PREF_NONE);
3388 /* replying to own mail, use original recp */
3389 compose_entry_append(compose,
3390 msginfo->to ? msginfo->to : "",
3391 COMPOSE_TO, PREF_NONE);
3392 compose_entry_append(compose,
3393 msginfo->cc ? msginfo->cc : "",
3394 COMPOSE_CC, PREF_NONE);
3399 if (to_sender || (compose->followup_to &&
3400 !strncmp(compose->followup_to, "poster", 6)))
3401 compose_entry_append
3403 (compose->replyto ? compose->replyto :
3404 msginfo->from ? msginfo->from : ""),
3405 COMPOSE_TO, PREF_NONE);
3407 else if (followup_and_reply_to || to_all) {
3408 compose_entry_append
3410 (compose->replyto ? compose->replyto :
3411 msginfo->from ? msginfo->from : ""),
3412 COMPOSE_TO, PREF_NONE);
3414 compose_entry_append
3416 compose->followup_to ? compose->followup_to :
3417 compose->newsgroups ? compose->newsgroups : "",
3418 COMPOSE_NEWSGROUPS, PREF_NONE);
3420 compose_entry_append
3422 msginfo->cc ? msginfo->cc : "",
3423 COMPOSE_CC, PREF_NONE);
3426 compose_entry_append
3428 compose->followup_to ? compose->followup_to :
3429 compose->newsgroups ? compose->newsgroups : "",
3430 COMPOSE_NEWSGROUPS, PREF_NONE);
3432 compose_reply_set_subject(compose, msginfo);
3434 if (to_ml && compose->ml_post) return;
3435 if (!to_all || compose->account->protocol == A_NNTP) return;
3437 if (compose->replyto) {
3438 Xstrdup_a(replyto, compose->replyto, return);
3439 extract_address(replyto);
3441 if (msginfo->from) {
3442 Xstrdup_a(from, msginfo->from, return);
3443 extract_address(from);
3446 if (replyto && from)
3447 cc_list = address_list_append_with_comments(cc_list, from);
3448 if (to_all && msginfo->folder &&
3449 msginfo->folder->prefs->enable_default_reply_to)
3450 cc_list = address_list_append_with_comments(cc_list,
3451 msginfo->folder->prefs->default_reply_to);
3452 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
3453 cc_list = address_list_append_with_comments(cc_list, compose->cc);
3455 ac_email = g_utf8_strdown(compose->account->address, -1);
3458 for (cur = cc_list; cur != NULL; cur = cur->next) {
3459 gchar *addr = g_utf8_strdown(cur->data, -1);
3460 extract_address(addr);
3462 if (strcmp(ac_email, addr))
3463 compose_entry_append(compose, (gchar *)cur->data,
3464 COMPOSE_CC, PREF_NONE);
3466 debug_print("Cc address same as compose account's, ignoring\n");
3471 slist_free_strings_full(cc_list);
3477 #define SET_ENTRY(entry, str) \
3480 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
3483 #define SET_ADDRESS(type, str) \
3486 compose_entry_append(compose, str, type, PREF_NONE); \
3489 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
3491 cm_return_if_fail(msginfo != NULL);
3493 SET_ENTRY(subject_entry, msginfo->subject);
3494 SET_ENTRY(from_name, msginfo->from);
3495 SET_ADDRESS(COMPOSE_TO, msginfo->to);
3496 SET_ADDRESS(COMPOSE_CC, compose->cc);
3497 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
3498 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
3499 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
3500 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
3502 compose_update_priority_menu_item(compose);
3503 compose_update_privacy_system_menu_item(compose, FALSE);
3504 compose_show_first_last_header(compose, TRUE);
3510 static void compose_insert_sig(Compose *compose, gboolean replace)
3512 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3513 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
3515 GtkTextIter iter, iter_end;
3516 gint cur_pos, ins_pos;
3517 gboolean prev_autowrap;
3518 gboolean found = FALSE;
3519 gboolean exists = FALSE;
3521 cm_return_if_fail(compose->account != NULL);
3525 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3526 G_CALLBACK(compose_changed_cb),
3529 mark = gtk_text_buffer_get_insert(buffer);
3530 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3531 cur_pos = gtk_text_iter_get_offset (&iter);
3534 gtk_text_buffer_get_end_iter(buffer, &iter);
3536 exists = (compose->sig_str != NULL);
3539 GtkTextIter first_iter, start_iter, end_iter;
3541 gtk_text_buffer_get_start_iter(buffer, &first_iter);
3543 if (!exists || compose->sig_str[0] == '\0')
3546 found = gtk_text_iter_forward_to_tag_toggle(&first_iter,
3547 compose->signature_tag);
3550 /* include previous \n\n */
3551 gtk_text_iter_backward_chars(&first_iter, 1);
3552 start_iter = first_iter;
3553 end_iter = first_iter;
3555 found = gtk_text_iter_forward_to_tag_toggle(&end_iter,
3556 compose->signature_tag);
3557 found &= gtk_text_iter_forward_to_tag_toggle(&end_iter,
3558 compose->signature_tag);
3560 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
3566 g_free(compose->sig_str);
3567 compose->sig_str = account_get_signature_str(compose->account);
3569 cur_pos = gtk_text_iter_get_offset(&iter);
3571 if (!compose->sig_str || (replace && !compose->account->auto_sig)) {
3572 g_free(compose->sig_str);
3573 compose->sig_str = NULL;
3575 if (compose->sig_inserted == FALSE)
3576 gtk_text_buffer_insert(buffer, &iter, "\n", -1);
3577 compose->sig_inserted = TRUE;
3579 cur_pos = gtk_text_iter_get_offset(&iter);
3580 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
3582 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
3583 gtk_text_iter_forward_chars(&iter, 1);
3584 gtk_text_buffer_get_end_iter(buffer, &iter_end);
3585 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
3587 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
3588 cur_pos = gtk_text_buffer_get_char_count (buffer);
3591 /* put the cursor where it should be
3592 * either where the quote_fmt says, either where it was */
3593 if (compose->set_cursor_pos < 0)
3594 gtk_text_buffer_get_iter_at_offset(buffer, &iter, ins_pos);
3596 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
3597 compose->set_cursor_pos);
3599 compose->set_cursor_pos = -1;
3600 gtk_text_buffer_place_cursor(buffer, &iter);
3601 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3602 G_CALLBACK(compose_changed_cb),
3608 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
3611 GtkTextBuffer *buffer;
3614 const gchar *cur_encoding;
3615 gchar buf[BUFFSIZE];
3618 gboolean prev_autowrap;
3621 GString *file_contents = NULL;
3622 ComposeInsertResult result = COMPOSE_INSERT_SUCCESS;
3624 cm_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
3626 /* get the size of the file we are about to insert */
3627 ret = g_stat(file, &file_stat);
3629 gchar *shortfile = g_path_get_basename(file);
3630 alertpanel_error(_("Could not get size of file '%s'."), shortfile);
3632 return COMPOSE_INSERT_NO_FILE;
3633 } else if (prefs_common.warn_large_insert == TRUE) {
3635 /* ask user for confirmation if the file is large */
3636 if (prefs_common.warn_large_insert_size < 0 ||
3637 file_stat.st_size > (prefs_common.warn_large_insert_size * 1024)) {
3641 msg = g_strdup_printf(_("You are about to insert a file of %s "
3642 "in the message body. Are you sure you want to do that?"),
3643 to_human_readable(file_stat.st_size));
3644 aval = alertpanel_full(_("Are you sure?"), msg, GTK_STOCK_CANCEL,
3645 g_strconcat("+", _("_Insert"), NULL), NULL, TRUE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
3648 /* do we ask for confirmation next time? */
3649 if (aval & G_ALERTDISABLE) {
3650 /* no confirmation next time, disable feature in preferences */
3651 aval &= ~G_ALERTDISABLE;
3652 prefs_common.warn_large_insert = FALSE;
3655 /* abort file insertion if user canceled action */
3656 if (aval != G_ALERTALTERNATE) {
3657 return COMPOSE_INSERT_NO_FILE;
3663 if ((fp = g_fopen(file, "rb")) == NULL) {
3664 FILE_OP_ERROR(file, "fopen");
3665 return COMPOSE_INSERT_READ_ERROR;
3668 prev_autowrap = compose->autowrap;
3669 compose->autowrap = FALSE;
3671 text = GTK_TEXT_VIEW(compose->text);
3672 buffer = gtk_text_view_get_buffer(text);
3673 mark = gtk_text_buffer_get_insert(buffer);
3674 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3676 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3677 G_CALLBACK(text_inserted),
3680 cur_encoding = conv_get_locale_charset_str_no_utf8();
3682 file_contents = g_string_new("");
3683 while (fgets(buf, sizeof(buf), fp) != NULL) {
3686 if (g_utf8_validate(buf, -1, NULL) == TRUE)
3687 str = g_strdup(buf);
3689 codeconv_set_strict(TRUE);
3690 str = conv_codeset_strdup
3691 (buf, cur_encoding, CS_INTERNAL);
3692 codeconv_set_strict(FALSE);
3695 result = COMPOSE_INSERT_INVALID_CHARACTER;
3701 /* strip <CR> if DOS/Windows file,
3702 replace <CR> with <LF> if Macintosh file. */
3705 if (len > 0 && str[len - 1] != '\n') {
3707 if (str[len] == '\r') str[len] = '\n';
3710 file_contents = g_string_append(file_contents, str);
3714 if (result == COMPOSE_INSERT_SUCCESS) {
3715 gtk_text_buffer_insert(buffer, &iter, file_contents->str, -1);
3717 compose_changed_cb(NULL, compose);
3718 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3719 G_CALLBACK(text_inserted),
3721 compose->autowrap = prev_autowrap;
3722 if (compose->autowrap)
3723 compose_wrap_all(compose);
3726 g_string_free(file_contents, TRUE);
3732 static gboolean compose_attach_append(Compose *compose, const gchar *file,
3733 const gchar *filename,
3734 const gchar *content_type,
3735 const gchar *charset)
3743 GtkListStore *store;
3745 gboolean has_binary = FALSE;
3747 if (!is_file_exist(file)) {
3748 gchar *file_from_uri = g_filename_from_uri(file, NULL, NULL);
3749 gboolean result = FALSE;
3750 if (file_from_uri && is_file_exist(file_from_uri)) {
3751 result = compose_attach_append(
3752 compose, file_from_uri,
3753 filename, content_type,
3756 g_free(file_from_uri);
3759 alertpanel_error("File %s doesn't exist or permission denied\n", filename);
3762 if ((size = get_file_size(file)) < 0) {
3763 alertpanel_error("Can't get file size of %s\n", filename);
3767 /* In batch mode, we allow 0-length files to be attached no questions asked */
3768 if (size == 0 && !compose->batch) {
3769 gchar * msg = g_strdup_printf(_("File %s is empty."), filename);
3770 AlertValue aval = alertpanel_full(_("Empty file"), msg,
3771 GTK_STOCK_CANCEL, g_strconcat("+", _("_Attach anyway"), NULL), NULL, FALSE,
3772 NULL, ALERT_WARNING, G_ALERTDEFAULT);
3775 if (aval != G_ALERTALTERNATE) {
3779 if ((fp = g_fopen(file, "rb")) == NULL) {
3780 alertpanel_error(_("Can't read %s."), filename);
3785 ainfo = g_new0(AttachInfo, 1);
3786 auto_ainfo = g_auto_pointer_new_with_free
3787 (ainfo, (GFreeFunc) compose_attach_info_free);
3788 ainfo->file = g_strdup(file);
3791 ainfo->content_type = g_strdup(content_type);
3792 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
3794 MsgFlags flags = {0, 0};
3796 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
3797 ainfo->encoding = ENC_7BIT;
3799 ainfo->encoding = ENC_8BIT;
3801 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
3802 if (msginfo && msginfo->subject)
3803 name = g_strdup(msginfo->subject);
3805 name = g_path_get_basename(filename ? filename : file);
3807 ainfo->name = g_strdup_printf(_("Message: %s"), name);
3809 procmsg_msginfo_free(&msginfo);
3811 if (!g_ascii_strncasecmp(content_type, "text/", 5)) {
3812 ainfo->charset = g_strdup(charset);
3813 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
3815 ainfo->encoding = ENC_BASE64;
3817 name = g_path_get_basename(filename ? filename : file);
3818 ainfo->name = g_strdup(name);
3822 ainfo->content_type = procmime_get_mime_type(file);
3823 if (!ainfo->content_type) {
3824 ainfo->content_type =
3825 g_strdup("application/octet-stream");
3826 ainfo->encoding = ENC_BASE64;
3827 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text/", 5))
3829 procmime_get_encoding_for_text_file(file, &has_binary);
3831 ainfo->encoding = ENC_BASE64;
3832 name = g_path_get_basename(filename ? filename : file);
3833 ainfo->name = g_strdup(name);
3837 if (ainfo->name != NULL
3838 && !strcmp(ainfo->name, ".")) {
3839 g_free(ainfo->name);
3843 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
3844 g_free(ainfo->content_type);
3845 ainfo->content_type = g_strdup("application/octet-stream");
3846 g_free(ainfo->charset);
3847 ainfo->charset = NULL;
3850 ainfo->size = (goffset)size;
3851 size_text = to_human_readable((goffset)size);
3853 store = GTK_LIST_STORE(gtk_tree_view_get_model
3854 (GTK_TREE_VIEW(compose->attach_clist)));
3856 gtk_list_store_append(store, &iter);
3857 gtk_list_store_set(store, &iter,
3858 COL_MIMETYPE, ainfo->content_type,
3859 COL_SIZE, size_text,
3860 COL_NAME, ainfo->name,
3861 COL_CHARSET, ainfo->charset,
3863 COL_AUTODATA, auto_ainfo,
3866 g_auto_pointer_free(auto_ainfo);
3867 compose_attach_update_label(compose);
3871 static void compose_use_signing(Compose *compose, gboolean use_signing)
3873 compose->use_signing = use_signing;
3874 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Sign", use_signing);
3877 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3879 compose->use_encryption = use_encryption;
3880 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Encrypt", use_encryption);
3883 #define NEXT_PART_NOT_CHILD(info) \
3885 node = info->node; \
3886 while (node->children) \
3887 node = g_node_last_child(node); \
3888 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3891 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3895 MimeInfo *firsttext = NULL;
3896 MimeInfo *encrypted = NULL;
3899 const gchar *partname = NULL;
3901 mimeinfo = procmime_scan_message(msginfo);
3902 if (!mimeinfo) return;
3904 if (mimeinfo->node->children == NULL) {
3905 procmime_mimeinfo_free_all(&mimeinfo);
3909 /* find first content part */
3910 child = (MimeInfo *) mimeinfo->node->children->data;
3911 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3912 child = (MimeInfo *)child->node->children->data;
3915 if (child->type == MIMETYPE_TEXT) {
3917 debug_print("First text part found\n");
3918 } else if (compose->mode == COMPOSE_REEDIT &&
3919 child->type == MIMETYPE_APPLICATION &&
3920 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3921 encrypted = (MimeInfo *)child->node->parent->data;
3924 child = (MimeInfo *) mimeinfo->node->children->data;
3925 while (child != NULL) {
3928 if (child == encrypted) {
3929 /* skip this part of tree */
3930 NEXT_PART_NOT_CHILD(child);
3934 if (child->type == MIMETYPE_MULTIPART) {
3935 /* get the actual content */
3936 child = procmime_mimeinfo_next(child);
3940 if (child == firsttext) {
3941 child = procmime_mimeinfo_next(child);
3945 outfile = procmime_get_tmp_file_name(child);
3946 if ((err = procmime_get_part(outfile, child)) < 0)
3947 g_warning("Can't get the part of multipart message. (%s)", g_strerror(-err));
3949 gchar *content_type;
3951 content_type = procmime_get_content_type_str(child->type, child->subtype);
3953 /* if we meet a pgp signature, we don't attach it, but
3954 * we force signing. */
3955 if ((strcmp(content_type, "application/pgp-signature") &&
3956 strcmp(content_type, "application/pkcs7-signature") &&
3957 strcmp(content_type, "application/x-pkcs7-signature"))
3958 || compose->mode == COMPOSE_REDIRECT) {
3959 partname = procmime_mimeinfo_get_parameter(child, "filename");
3960 if (partname == NULL)
3961 partname = procmime_mimeinfo_get_parameter(child, "name");
3962 if (partname == NULL)
3964 compose_attach_append(compose, outfile,
3965 partname, content_type,
3966 procmime_mimeinfo_get_parameter(child, "charset"));
3968 compose_force_signing(compose, compose->account, NULL);
3970 g_free(content_type);
3973 NEXT_PART_NOT_CHILD(child);
3975 procmime_mimeinfo_free_all(&mimeinfo);
3978 #undef NEXT_PART_NOT_CHILD
3983 WAIT_FOR_INDENT_CHAR,
3984 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3987 /* return indent length, we allow:
3988 indent characters followed by indent characters or spaces/tabs,
3989 alphabets and numbers immediately followed by indent characters,
3990 and the repeating sequences of the above
3991 If quote ends with multiple spaces, only the first one is included. */
3992 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3993 const GtkTextIter *start, gint *len)
3995 GtkTextIter iter = *start;
3999 IndentState state = WAIT_FOR_INDENT_CHAR;
4002 gint alnum_count = 0;
4003 gint space_count = 0;
4006 if (prefs_common.quote_chars == NULL) {
4010 while (!gtk_text_iter_ends_line(&iter)) {
4011 wc = gtk_text_iter_get_char(&iter);
4012 if (g_unichar_iswide(wc))
4014 clen = g_unichar_to_utf8(wc, ch);
4018 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
4019 is_space = g_unichar_isspace(wc);
4021 if (state == WAIT_FOR_INDENT_CHAR) {
4022 if (!is_indent && !g_unichar_isalnum(wc))
4025 quote_len += alnum_count + space_count + 1;
4026 alnum_count = space_count = 0;
4027 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
4030 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
4031 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
4035 else if (is_indent) {
4036 quote_len += alnum_count + space_count + 1;
4037 alnum_count = space_count = 0;
4040 state = WAIT_FOR_INDENT_CHAR;
4044 gtk_text_iter_forward_char(&iter);
4047 if (quote_len > 0 && space_count > 0)
4053 if (quote_len > 0) {
4055 gtk_text_iter_forward_chars(&iter, quote_len);
4056 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
4062 /* return >0 if the line is itemized */
4063 static int compose_itemized_length(GtkTextBuffer *buffer,
4064 const GtkTextIter *start)
4066 GtkTextIter iter = *start;
4071 if (gtk_text_iter_ends_line(&iter))
4076 wc = gtk_text_iter_get_char(&iter);
4077 if (!g_unichar_isspace(wc))
4079 gtk_text_iter_forward_char(&iter);
4080 if (gtk_text_iter_ends_line(&iter))
4084 clen = g_unichar_to_utf8(wc, ch);
4088 if (!strchr("*-+", ch[0]))
4091 gtk_text_iter_forward_char(&iter);
4092 if (gtk_text_iter_ends_line(&iter))
4094 wc = gtk_text_iter_get_char(&iter);
4095 if (g_unichar_isspace(wc)) {
4101 /* return the string at the start of the itemization */
4102 static gchar * compose_get_itemized_chars(GtkTextBuffer *buffer,
4103 const GtkTextIter *start)
4105 GtkTextIter iter = *start;
4108 GString *item_chars = g_string_new("");
4111 if (gtk_text_iter_ends_line(&iter))
4116 wc = gtk_text_iter_get_char(&iter);
4117 if (!g_unichar_isspace(wc))
4119 gtk_text_iter_forward_char(&iter);
4120 if (gtk_text_iter_ends_line(&iter))
4122 g_string_append_unichar(item_chars, wc);
4125 str = item_chars->str;
4126 g_string_free(item_chars, FALSE);
4130 /* return the number of spaces at a line's start */
4131 static int compose_left_offset_length(GtkTextBuffer *buffer,
4132 const GtkTextIter *start)
4134 GtkTextIter iter = *start;
4137 if (gtk_text_iter_ends_line(&iter))
4141 wc = gtk_text_iter_get_char(&iter);
4142 if (!g_unichar_isspace(wc))
4145 gtk_text_iter_forward_char(&iter);
4146 if (gtk_text_iter_ends_line(&iter))
4150 gtk_text_iter_forward_char(&iter);
4151 if (gtk_text_iter_ends_line(&iter))
4156 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
4157 const GtkTextIter *start,
4158 GtkTextIter *break_pos,
4162 GtkTextIter iter = *start, line_end = *start;
4163 PangoLogAttr *attrs;
4170 gboolean can_break = FALSE;
4171 gboolean do_break = FALSE;
4172 gboolean was_white = FALSE;
4173 gboolean prev_dont_break = FALSE;
4175 gtk_text_iter_forward_to_line_end(&line_end);
4176 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
4177 len = g_utf8_strlen(str, -1);
4181 g_warning("compose_get_line_break_pos: len = 0!");
4185 /* g_print("breaking line: %d: %s (len = %d)\n",
4186 gtk_text_iter_get_line(&iter), str, len); */
4188 attrs = g_new(PangoLogAttr, len + 1);
4190 pango_default_break(str, -1, NULL, attrs, len + 1);
4194 /* skip quote and leading spaces */
4195 for (i = 0; *p != '\0' && i < len; i++) {
4198 wc = g_utf8_get_char(p);
4199 if (i >= quote_len && !g_unichar_isspace(wc))
4201 if (g_unichar_iswide(wc))
4203 else if (*p == '\t')
4207 p = g_utf8_next_char(p);
4210 for (; *p != '\0' && i < len; i++) {
4211 PangoLogAttr *attr = attrs + i;
4215 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
4218 was_white = attr->is_white;
4220 /* don't wrap URI */
4221 if ((uri_len = get_uri_len(p)) > 0) {
4223 if (pos > 0 && col > max_col) {
4233 wc = g_utf8_get_char(p);
4234 if (g_unichar_iswide(wc)) {
4236 if (prev_dont_break && can_break && attr->is_line_break)
4238 } else if (*p == '\t')
4242 if (pos > 0 && col > max_col) {
4247 if (*p == '-' || *p == '/')
4248 prev_dont_break = TRUE;
4250 prev_dont_break = FALSE;
4252 p = g_utf8_next_char(p);
4256 /* debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col); */
4261 *break_pos = *start;
4262 gtk_text_iter_set_line_offset(break_pos, pos);
4267 static gboolean compose_join_next_line(Compose *compose,
4268 GtkTextBuffer *buffer,
4270 const gchar *quote_str)
4272 GtkTextIter iter_ = *iter, cur, prev, next, end;
4273 PangoLogAttr attrs[3];
4275 gchar *next_quote_str;
4278 gboolean keep_cursor = FALSE;
4280 if (!gtk_text_iter_forward_line(&iter_) ||
4281 gtk_text_iter_ends_line(&iter_)) {
4284 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
4286 if ((quote_str || next_quote_str) &&
4287 strcmp2(quote_str, next_quote_str) != 0) {
4288 g_free(next_quote_str);
4291 g_free(next_quote_str);
4294 if (quote_len > 0) {
4295 gtk_text_iter_forward_chars(&end, quote_len);
4296 if (gtk_text_iter_ends_line(&end)) {
4301 /* don't join itemized lines */
4302 if (compose_itemized_length(buffer, &end) > 0) {
4306 /* don't join signature separator */
4307 if (compose_is_sig_separator(compose, buffer, &iter_)) {
4310 /* delete quote str */
4312 gtk_text_buffer_delete(buffer, &iter_, &end);
4314 /* don't join line breaks put by the user */
4316 gtk_text_iter_backward_char(&cur);
4317 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
4318 gtk_text_iter_forward_char(&cur);
4322 gtk_text_iter_forward_char(&cur);
4323 /* delete linebreak and extra spaces */
4324 while (gtk_text_iter_backward_char(&cur)) {
4325 wc1 = gtk_text_iter_get_char(&cur);
4326 if (!g_unichar_isspace(wc1))
4331 while (!gtk_text_iter_ends_line(&cur)) {
4332 wc1 = gtk_text_iter_get_char(&cur);
4333 if (!g_unichar_isspace(wc1))
4335 gtk_text_iter_forward_char(&cur);
4338 if (!gtk_text_iter_equal(&prev, &next)) {
4341 mark = gtk_text_buffer_get_insert(buffer);
4342 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
4343 if (gtk_text_iter_equal(&prev, &cur))
4345 gtk_text_buffer_delete(buffer, &prev, &next);
4349 /* insert space if required */
4350 gtk_text_iter_backward_char(&prev);
4351 wc1 = gtk_text_iter_get_char(&prev);
4352 wc2 = gtk_text_iter_get_char(&next);
4353 gtk_text_iter_forward_char(&next);
4354 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
4355 pango_default_break(str, -1, NULL, attrs, 3);
4356 if (!attrs[1].is_line_break ||
4357 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
4358 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
4360 gtk_text_iter_backward_char(&iter_);
4361 gtk_text_buffer_place_cursor(buffer, &iter_);
4370 #define ADD_TXT_POS(bp_, ep_, pti_) \
4371 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
4372 last = last->next; \
4373 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
4374 last->next = NULL; \
4376 g_warning("alloc error scanning URIs"); \
4379 static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
4381 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
4382 GtkTextBuffer *buffer;
4383 GtkTextIter iter, break_pos, end_of_line;
4384 gchar *quote_str = NULL;
4386 gboolean wrap_quote = force || prefs_common.linewrap_quote;
4387 gboolean prev_autowrap = compose->autowrap;
4388 gint startq_offset = -1, noq_offset = -1;
4389 gint uri_start = -1, uri_stop = -1;
4390 gint nouri_start = -1, nouri_stop = -1;
4391 gint num_blocks = 0;
4392 gint quotelevel = -1;
4393 gboolean modified = force;
4394 gboolean removed = FALSE;
4395 gboolean modified_before_remove = FALSE;
4397 gboolean start = TRUE;
4398 gint itemized_len = 0, rem_item_len = 0;
4399 gchar *itemized_chars = NULL;
4400 gboolean item_continuation = FALSE;
4405 if (compose->draft_timeout_tag == COMPOSE_DRAFT_TIMEOUT_FORBIDDEN) {
4409 compose->autowrap = FALSE;
4411 buffer = gtk_text_view_get_buffer(text);
4412 undo_wrapping(compose->undostruct, TRUE);
4417 mark = gtk_text_buffer_get_insert(buffer);
4418 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
4422 if (compose->draft_timeout_tag == COMPOSE_DRAFT_TIMEOUT_FORBIDDEN) {
4423 if (gtk_text_iter_ends_line(&iter)) {
4424 while (gtk_text_iter_ends_line(&iter) &&
4425 gtk_text_iter_forward_line(&iter))
4428 while (gtk_text_iter_backward_line(&iter)) {
4429 if (gtk_text_iter_ends_line(&iter)) {
4430 gtk_text_iter_forward_line(&iter);
4436 /* move to line start */
4437 gtk_text_iter_set_line_offset(&iter, 0);
4440 itemized_len = compose_itemized_length(buffer, &iter);
4442 if (!itemized_len) {
4443 itemized_len = compose_left_offset_length(buffer, &iter);
4444 item_continuation = TRUE;
4448 itemized_chars = compose_get_itemized_chars(buffer, &iter);
4450 /* go until paragraph end (empty line) */
4451 while (start || !gtk_text_iter_ends_line(&iter)) {
4452 gchar *scanpos = NULL;
4453 /* parse table - in order of priority */
4455 const gchar *needle; /* token */
4457 /* token search function */
4458 gchar *(*search) (const gchar *haystack,
4459 const gchar *needle);
4460 /* part parsing function */
4461 gboolean (*parse) (const gchar *start,
4462 const gchar *scanpos,
4466 /* part to URI function */
4467 gchar *(*build_uri) (const gchar *bp,
4471 static struct table parser[] = {
4472 {"http://", strcasestr, get_uri_part, make_uri_string},
4473 {"https://", strcasestr, get_uri_part, make_uri_string},
4474 {"ftp://", strcasestr, get_uri_part, make_uri_string},
4475 {"sftp://", strcasestr, get_uri_part, make_uri_string},
4476 {"gopher://",strcasestr, get_uri_part, make_uri_string},
4477 {"www.", strcasestr, get_uri_part, make_http_string},
4478 {"mailto:", strcasestr, get_uri_part, make_uri_string},
4479 {"@", strcasestr, get_email_part, make_email_string}
4481 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
4482 gint last_index = PARSE_ELEMS;
4484 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
4488 if (!prev_autowrap && num_blocks == 0) {
4490 g_signal_handlers_block_by_func(G_OBJECT(buffer),
4491 G_CALLBACK(text_inserted),
4494 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
4497 uri_start = uri_stop = -1;
4499 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
4502 /* debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str); */
4503 if (startq_offset == -1)
4504 startq_offset = gtk_text_iter_get_offset(&iter);
4505 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
4506 if (quotelevel > 2) {
4507 /* recycle colors */
4508 if (prefs_common.recycle_quote_colors)
4517 if (startq_offset == -1)
4518 noq_offset = gtk_text_iter_get_offset(&iter);
4522 if (prev_autowrap == FALSE && !force && !wrap_quote) {
4525 if (gtk_text_iter_ends_line(&iter)) {
4527 } else if (compose_get_line_break_pos(buffer, &iter, &break_pos,
4528 prefs_common.linewrap_len,
4530 GtkTextIter prev, next, cur;
4531 if (prev_autowrap != FALSE || force) {
4532 compose->automatic_break = TRUE;
4534 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
4535 compose->automatic_break = FALSE;
4536 if (itemized_len && compose->autoindent) {
4537 gtk_text_buffer_insert(buffer, &break_pos, itemized_chars, -1);
4538 if (!item_continuation)
4539 gtk_text_buffer_insert(buffer, &break_pos, " ", 2);
4541 } else if (quote_str && wrap_quote) {
4542 compose->automatic_break = TRUE;
4544 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
4545 compose->automatic_break = FALSE;
4546 if (itemized_len && compose->autoindent) {
4547 gtk_text_buffer_insert(buffer, &break_pos, itemized_chars, -1);
4548 if (!item_continuation)
4549 gtk_text_buffer_insert(buffer, &break_pos, " ", 2);
4553 /* remove trailing spaces */
4555 rem_item_len = itemized_len;
4556 while (compose->autoindent && rem_item_len-- > 0)
4557 gtk_text_iter_backward_char(&cur);
4558 gtk_text_iter_backward_char(&cur);
4561 while (!gtk_text_iter_starts_line(&cur)) {
4564 gtk_text_iter_backward_char(&cur);
4565 wc = gtk_text_iter_get_char(&cur);
4566 if (!g_unichar_isspace(wc))
4570 if (!gtk_text_iter_equal(&prev, &next)) {
4571 gtk_text_buffer_delete(buffer, &prev, &next);
4573 gtk_text_iter_forward_char(&break_pos);
4577 gtk_text_buffer_insert(buffer, &break_pos,
4581 modified |= compose_join_next_line(compose, buffer, &iter, quote_str);
4583 /* move iter to current line start */
4584 gtk_text_iter_set_line_offset(&iter, 0);
4591 /* move iter to next line start */
4597 if (!prev_autowrap && num_blocks > 0) {
4599 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
4600 G_CALLBACK(text_inserted),
4604 while (!gtk_text_iter_ends_line(&end_of_line)) {
4605 gtk_text_iter_forward_char(&end_of_line);
4607 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
4609 nouri_start = gtk_text_iter_get_offset(&iter);
4610 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
4612 walk_pos = gtk_text_iter_get_offset(&iter);
4613 /* FIXME: this looks phony. scanning for anything in the parse table */
4614 for (n = 0; n < PARSE_ELEMS; n++) {
4617 tmp = parser[n].search(walk, parser[n].needle);
4619 if (scanpos == NULL || tmp < scanpos) {
4628 /* check if URI can be parsed */
4629 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
4630 (const gchar **)&ep, FALSE)
4631 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
4635 strlen(parser[last_index].needle);
4638 uri_start = walk_pos + (bp - o_walk);
4639 uri_stop = walk_pos + (ep - o_walk);
4643 gtk_text_iter_forward_line(&iter);
4646 if (startq_offset != -1) {
4647 GtkTextIter startquote, endquote;
4648 gtk_text_buffer_get_iter_at_offset(
4649 buffer, &startquote, startq_offset);
4652 switch (quotelevel) {
4654 if (!gtk_text_iter_has_tag(&startquote, compose->quote0_tag) ||
4655 !gtk_text_iter_has_tag(&end_of_line, compose->quote0_tag)) {
4656 gtk_text_buffer_apply_tag_by_name(
4657 buffer, "quote0", &startquote, &endquote);
4658 gtk_text_buffer_remove_tag_by_name(
4659 buffer, "quote1", &startquote, &endquote);
4660 gtk_text_buffer_remove_tag_by_name(
4661 buffer, "quote2", &startquote, &endquote);
4666 if (!gtk_text_iter_has_tag(&startquote, compose->quote1_tag) ||
4667 !gtk_text_iter_has_tag(&end_of_line, compose->quote1_tag)) {
4668 gtk_text_buffer_apply_tag_by_name(
4669 buffer, "quote1", &startquote, &endquote);
4670 gtk_text_buffer_remove_tag_by_name(
4671 buffer, "quote0", &startquote, &endquote);
4672 gtk_text_buffer_remove_tag_by_name(
4673 buffer, "quote2", &startquote, &endquote);
4678 if (!gtk_text_iter_has_tag(&startquote, compose->quote2_tag) ||
4679 !gtk_text_iter_has_tag(&end_of_line, compose->quote2_tag)) {
4680 gtk_text_buffer_apply_tag_by_name(
4681 buffer, "quote2", &startquote, &endquote);
4682 gtk_text_buffer_remove_tag_by_name(
4683 buffer, "quote0", &startquote, &endquote);
4684 gtk_text_buffer_remove_tag_by_name(
4685 buffer, "quote1", &startquote, &endquote);
4691 } else if (noq_offset != -1) {
4692 GtkTextIter startnoquote, endnoquote;
4693 gtk_text_buffer_get_iter_at_offset(
4694 buffer, &startnoquote, noq_offset);
4697 if ((gtk_text_iter_has_tag(&startnoquote, compose->quote0_tag)
4698 && gtk_text_iter_has_tag(&end_of_line, compose->quote0_tag)) ||
4699 (gtk_text_iter_has_tag(&startnoquote, compose->quote1_tag)
4700 && gtk_text_iter_has_tag(&end_of_line, compose->quote1_tag)) ||
4701 (gtk_text_iter_has_tag(&startnoquote, compose->quote2_tag)
4702 && gtk_text_iter_has_tag(&end_of_line, compose->quote2_tag))) {
4703 gtk_text_buffer_remove_tag_by_name(
4704 buffer, "quote0", &startnoquote, &endnoquote);
4705 gtk_text_buffer_remove_tag_by_name(
4706 buffer, "quote1", &startnoquote, &endnoquote);
4707 gtk_text_buffer_remove_tag_by_name(
4708 buffer, "quote2", &startnoquote, &endnoquote);
4714 if (uri_start != nouri_start && uri_stop != nouri_stop) {
4715 GtkTextIter nouri_start_iter, nouri_end_iter;
4716 gtk_text_buffer_get_iter_at_offset(
4717 buffer, &nouri_start_iter, nouri_start);
4718 gtk_text_buffer_get_iter_at_offset(
4719 buffer, &nouri_end_iter, nouri_stop);
4720 if (gtk_text_iter_has_tag(&nouri_start_iter, compose->uri_tag) &&
4721 gtk_text_iter_has_tag(&nouri_end_iter, compose->uri_tag)) {
4722 gtk_text_buffer_remove_tag_by_name(
4723 buffer, "link", &nouri_start_iter, &nouri_end_iter);
4724 modified_before_remove = modified;
4729 if (uri_start >= 0 && uri_stop > 0) {
4730 GtkTextIter uri_start_iter, uri_end_iter, back;
4731 gtk_text_buffer_get_iter_at_offset(
4732 buffer, &uri_start_iter, uri_start);
4733 gtk_text_buffer_get_iter_at_offset(
4734 buffer, &uri_end_iter, uri_stop);
4735 back = uri_end_iter;
4736 gtk_text_iter_backward_char(&back);
4737 if (!gtk_text_iter_has_tag(&uri_start_iter, compose->uri_tag) ||
4738 !gtk_text_iter_has_tag(&back, compose->uri_tag)) {
4739 gtk_text_buffer_apply_tag_by_name(
4740 buffer, "link", &uri_start_iter, &uri_end_iter);
4742 if (removed && !modified_before_remove) {
4748 /* debug_print("not modified, out after %d lines\n", lines); */
4752 /* debug_print("modified, out after %d lines\n", lines); */
4754 g_free(itemized_chars);
4757 undo_wrapping(compose->undostruct, FALSE);
4758 compose->autowrap = prev_autowrap;
4763 void compose_action_cb(void *data)
4765 Compose *compose = (Compose *)data;
4766 compose_wrap_all(compose);
4769 static void compose_wrap_all(Compose *compose)
4771 compose_wrap_all_full(compose, FALSE);
4774 static void compose_wrap_all_full(Compose *compose, gboolean force)
4776 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
4777 GtkTextBuffer *buffer;
4779 gboolean modified = TRUE;
4781 buffer = gtk_text_view_get_buffer(text);
4783 gtk_text_buffer_get_start_iter(buffer, &iter);
4785 undo_wrapping(compose->undostruct, TRUE);
4787 while (!gtk_text_iter_is_end(&iter) && modified)
4788 modified = compose_beautify_paragraph(compose, &iter, force);
4790 undo_wrapping(compose->undostruct, FALSE);
4794 static void compose_set_title(Compose *compose)
4800 edited = compose->modified ? _(" [Edited]") : "";
4802 subject = gtk_editable_get_chars(
4803 GTK_EDITABLE(compose->subject_entry), 0, -1);
4805 #ifndef GENERIC_UMPC
4806 if (subject && strlen(subject))
4807 str = g_strdup_printf(_("%s - Compose message%s"),
4810 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
4812 str = g_strdup(_("Compose message"));
4815 gtk_window_set_title(GTK_WINDOW(compose->window), str);
4821 * compose_current_mail_account:
4823 * Find a current mail account (the currently selected account, or the
4824 * default account, if a news account is currently selected). If a
4825 * mail account cannot be found, display an error message.
4827 * Return value: Mail account, or NULL if not found.
4829 static PrefsAccount *
4830 compose_current_mail_account(void)
4834 if (cur_account && cur_account->protocol != A_NNTP)
4837 ac = account_get_default();
4838 if (!ac || ac->protocol == A_NNTP) {
4839 alertpanel_error(_("Account for sending mail is not specified.\n"
4840 "Please select a mail account before sending."));
4847 #define QUOTE_IF_REQUIRED(out, str) \
4849 if (*str != '"' && strpbrk(str, ",.:;[]<>()@\\\"")) { \
4853 len = strlen(str) + 3; \
4854 if ((__tmp = alloca(len)) == NULL) { \
4855 g_warning("can't allocate memory"); \
4856 g_string_free(header, TRUE); \
4859 g_snprintf(__tmp, len, "\"%s\"", str); \
4864 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4865 g_warning("can't allocate memory"); \
4866 g_string_free(header, TRUE); \
4869 strcpy(__tmp, str); \
4875 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
4877 if (*str != '"' && strpbrk(str, ",.:;[]<>()@\\\"")) { \
4881 len = strlen(str) + 3; \
4882 if ((__tmp = alloca(len)) == NULL) { \
4883 g_warning("can't allocate memory"); \
4886 g_snprintf(__tmp, len, "\"%s\"", str); \
4891 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4892 g_warning("can't allocate memory"); \
4895 strcpy(__tmp, str); \
4901 static void compose_select_account(Compose *compose, PrefsAccount *account,
4904 gchar *from = NULL, *header = NULL;
4905 ComposeHeaderEntry *header_entry;
4906 #if GTK_CHECK_VERSION(2, 24, 0)
4910 cm_return_if_fail(account != NULL);
4912 compose->account = account;
4913 if (account->name && *account->name) {
4915 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
4916 qbuf = escape_internal_quotes(buf, '"');
4917 from = g_strdup_printf("%s <%s>",
4918 qbuf, account->address);
4921 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
4923 from = g_strdup_printf("<%s>",
4925 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
4930 compose_set_title(compose);
4932 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
4933 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Sign", TRUE);
4935 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Sign", FALSE);
4936 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
4937 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Encrypt", TRUE);
4939 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Encrypt", FALSE);
4941 activate_privacy_system(compose, account, FALSE);
4943 if (!init && compose->mode != COMPOSE_REDIRECT) {
4944 undo_block(compose->undostruct);
4945 compose_insert_sig(compose, TRUE);
4946 undo_unblock(compose->undostruct);
4949 header_entry = (ComposeHeaderEntry *) compose->header_list->data;
4950 #if !GTK_CHECK_VERSION(2, 24, 0)
4951 header = gtk_combo_box_get_active_text(GTK_COMBO_BOX(header_entry->combo));
4953 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(header_entry->combo), &iter))
4954 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(
4955 header_entry->combo)), &iter, COMBOBOX_TEXT, &header, -1);
4958 if (header && !strlen(gtk_entry_get_text(GTK_ENTRY(header_entry->entry)))) {
4959 if (account->protocol == A_NNTP) {
4960 if (!strcmp(header, _("To:")))
4961 combobox_select_by_text(
4962 GTK_COMBO_BOX(header_entry->combo),
4965 if (!strcmp(header, _("Newsgroups:")))
4966 combobox_select_by_text(
4967 GTK_COMBO_BOX(header_entry->combo),
4975 /* use account's dict info if set */
4976 if (compose->gtkaspell) {
4977 if (account->enable_default_dictionary)
4978 gtkaspell_change_dict(compose->gtkaspell,
4979 account->default_dictionary, FALSE);
4980 if (account->enable_default_alt_dictionary)
4981 gtkaspell_change_alt_dict(compose->gtkaspell,
4982 account->default_alt_dictionary);
4983 if (account->enable_default_dictionary
4984 || account->enable_default_alt_dictionary)
4985 compose_spell_menu_changed(compose);
4990 gboolean compose_check_for_valid_recipient(Compose *compose) {
4991 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
4992 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
4993 gboolean recipient_found = FALSE;
4997 /* free to and newsgroup list */
4998 slist_free_strings_full(compose->to_list);
4999 compose->to_list = NULL;
5001 slist_free_strings_full(compose->newsgroup_list);
5002 compose->newsgroup_list = NULL;
5004 /* search header entries for to and newsgroup entries */
5005 for (list = compose->header_list; list; list = list->next) {
5008 header = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
5009 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
5012 if (entry[0] != '\0') {
5013 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
5014 if (!g_ascii_strcasecmp(header, prefs_common_translated_header_name(*strptr))) {
5015 compose->to_list = address_list_append(compose->to_list, entry);
5016 recipient_found = TRUE;
5019 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
5020 if (!g_ascii_strcasecmp(header, prefs_common_translated_header_name(*strptr))) {
5021 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
5022 recipient_found = TRUE;
5029 return recipient_found;
5032 static gboolean compose_check_for_set_recipients(Compose *compose)
5034 if (compose->account->set_autocc && compose->account->auto_cc) {
5035 gboolean found_other = FALSE;
5037 /* search header entries for to and newsgroup entries */
5038 for (list = compose->header_list; list; list = list->next) {
5041 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
5042 header = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
5045 if (strcmp(entry, compose->account->auto_cc)
5046 || strcmp(header, prefs_common_translated_header_name("Cc:"))) {
5057 if (compose->batch) {
5058 gtk_widget_show_all(compose->window);
5060 text = g_strdup_printf(_("The only recipient is the default '%s' address. Send anyway?"),
5061 prefs_common_translated_header_name("Cc"));
5062 aval = alertpanel(_("Send"),
5064 GTK_STOCK_CANCEL, g_strconcat("+", _("_Send"), NULL), NULL);
5066 if (aval != G_ALERTALTERNATE)
5070 if (compose->account->set_autobcc && compose->account->auto_bcc) {
5071 gboolean found_other = FALSE;
5073 /* search header entries for to and newsgroup entries */
5074 for (list = compose->header_list; list; list = list->next) {
5077 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
5078 header = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
5081 if (strcmp(entry, compose->account->auto_bcc)
5082 || strcmp(header, prefs_common_translated_header_name("Bcc:"))) {
5094 if (compose->batch) {
5095 gtk_widget_show_all(compose->window);
5097 text = g_strdup_printf(_("The only recipient is the default '%s' address. Send anyway?"),
5098 prefs_common_translated_header_name("Bcc"));
5099 aval = alertpanel(_("Send"),
5101 GTK_STOCK_CANCEL, g_strconcat("+", _("_Send"), NULL), NULL);
5103 if (aval != G_ALERTALTERNATE)
5110 static gboolean compose_check_entries(Compose *compose, gboolean check_everything)
5114 if (compose_check_for_valid_recipient(compose) == FALSE) {
5115 if (compose->batch) {
5116 gtk_widget_show_all(compose->window);
5118 alertpanel_error(_("Recipient is not specified."));
5122 if (compose_check_for_set_recipients(compose) == FALSE) {
5126 if (!compose->batch && prefs_common.warn_empty_subj == TRUE) {
5127 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
5128 if (*str == '\0' && check_everything == TRUE &&
5129 compose->mode != COMPOSE_REDIRECT) {
5131 gchar *button_label;
5134 if (compose->sending)
5135 button_label = g_strconcat("+", _("_Send"), NULL);
5137 button_label = g_strconcat("+", _("_Queue"), NULL);
5138 message = g_strdup_printf(_("Subject is empty. %s"),
5139 compose->sending?_("Send it anyway?"):
5140 _("Queue it anyway?"));
5142 aval = alertpanel_full(compose->sending?_("Send"):_("Send later"), message,
5143 GTK_STOCK_CANCEL, button_label, NULL, TRUE, NULL,
5144 ALERT_QUESTION, G_ALERTDEFAULT);
5146 if (aval & G_ALERTDISABLE) {
5147 aval &= ~G_ALERTDISABLE;
5148 prefs_common.warn_empty_subj = FALSE;
5150 if (aval != G_ALERTALTERNATE)
5155 if (!compose->batch && prefs_common.warn_sending_many_recipients_num > 0
5156 && check_everything == TRUE) {
5160 /* count To and Cc recipients */
5161 for (list = compose->header_list; list; list = list->next) {
5165 header = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
5166 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
5169 if ((entry[0] != '\0')
5170 && (strcmp(header, prefs_common_translated_header_name("To:"))
5171 || strcmp(header, prefs_common_translated_header_name("Cc:")))) {
5177 if (cnt > prefs_common.warn_sending_many_recipients_num) {
5179 gchar *button_label;
5182 if (compose->sending)
5183 button_label = g_strconcat("+", _("_Send"), NULL);
5185 button_label = g_strconcat("+", _("_Queue"), NULL);
5186 message = g_strdup_printf(_("Sending to %d recipients. %s"), cnt,
5187 compose->sending?_("Send it anyway?"):
5188 _("Queue it anyway?"));
5190 aval = alertpanel_full(compose->sending?_("Send"):_("Send later"), message,
5191 GTK_STOCK_CANCEL, button_label, NULL, TRUE, NULL,
5192 ALERT_QUESTION, G_ALERTDEFAULT);
5194 if (aval & G_ALERTDISABLE) {
5195 aval &= ~G_ALERTDISABLE;
5196 prefs_common.warn_sending_many_recipients_num = 0;
5198 if (aval != G_ALERTALTERNATE)
5203 if (check_everything && hooks_invoke(COMPOSE_CHECK_BEFORE_SEND_HOOKLIST, compose))
5209 gint compose_send(Compose *compose)
5212 FolderItem *folder = NULL;
5214 gchar *msgpath = NULL;
5215 gboolean discard_window = FALSE;
5216 gchar *errstr = NULL;
5217 gchar *tmsgid = NULL;
5218 MainWindow *mainwin = mainwindow_get_mainwindow();
5219 gboolean queued_removed = FALSE;
5221 if (prefs_common.send_dialog_invisible
5222 || compose->batch == TRUE)
5223 discard_window = TRUE;
5225 compose_allow_user_actions (compose, FALSE);
5226 compose->sending = TRUE;
5228 if (compose_check_entries(compose, TRUE) == FALSE) {
5229 if (compose->batch) {
5230 gtk_widget_show_all(compose->window);
5236 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
5239 if (compose->batch) {
5240 gtk_widget_show_all(compose->window);
5243 alertpanel_error(_("Could not queue message for sending:\n\n"
5244 "Charset conversion failed."));
5245 } else if (val == -5) {
5246 alertpanel_error(_("Could not queue message for sending:\n\n"
5247 "Couldn't get recipient encryption key."));
5248 } else if (val == -6) {
5250 } else if (val == -3) {
5251 if (privacy_peek_error())
5252 alertpanel_error(_("Could not queue message for sending:\n\n"
5253 "Signature failed: %s"), privacy_get_error());
5254 } else if (val == -2 && errno != 0) {
5255 alertpanel_error(_("Could not queue message for sending:\n\n%s."), g_strerror(errno));
5257 alertpanel_error(_("Could not queue message for sending."));
5262 tmsgid = compose->msgid ? g_strdup(compose->msgid) : NULL;
5263 if (discard_window) {
5264 compose->sending = FALSE;
5265 compose_close(compose);
5266 /* No more compose access in the normal codepath
5267 * after this point! */
5272 alertpanel_error(_("The message was queued but could not be "
5273 "sent.\nUse \"Send queued messages\" from "
5274 "the main window to retry."));
5275 if (!discard_window) {
5282 if (msgpath == NULL) {
5283 msgpath = folder_item_fetch_msg(folder, msgnum);
5284 val = procmsg_send_message_queue_with_lock(msgpath, &errstr, folder, msgnum, &queued_removed);
5287 val = procmsg_send_message_queue_with_lock(msgpath, &errstr, folder, msgnum, &queued_removed);
5288 claws_unlink(msgpath);
5291 if (!discard_window) {
5293 if (!queued_removed)
5294 folder_item_remove_msg(folder, msgnum);
5295 folder_item_scan(folder);
5297 /* make sure we delete that */
5298 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
5300 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
5301 folder_item_remove_msg(folder, tmp->msgnum);
5302 procmsg_msginfo_free(&tmp);
5309 if (!queued_removed)
5310 folder_item_remove_msg(folder, msgnum);
5311 folder_item_scan(folder);
5313 /* make sure we delete that */
5314 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
5316 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
5317 folder_item_remove_msg(folder, tmp->msgnum);
5318 procmsg_msginfo_free(&tmp);
5321 if (!discard_window) {
5322 compose->sending = FALSE;
5323 compose_allow_user_actions (compose, TRUE);
5324 compose_close(compose);
5328 alertpanel_error_log(_("%s\nUse \"Send queued messages\" from "
5329 "the main window to retry."), errstr);
5332 alertpanel_error_log(_("The message was queued but could not be "
5333 "sent.\nUse \"Send queued messages\" from "
5334 "the main window to retry."));
5336 if (!discard_window) {
5345 toolbar_main_set_sensitive(mainwin);
5346 main_window_set_menu_sensitive(mainwin);
5352 compose_allow_user_actions (compose, TRUE);
5353 compose->sending = FALSE;
5354 compose->modified = TRUE;
5355 toolbar_main_set_sensitive(mainwin);
5356 main_window_set_menu_sensitive(mainwin);
5361 static gboolean compose_use_attach(Compose *compose)
5363 GtkTreeModel *model = gtk_tree_view_get_model
5364 (GTK_TREE_VIEW(compose->attach_clist));
5365 return gtk_tree_model_iter_n_children(model, NULL) > 0;
5368 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
5371 gchar buf[BUFFSIZE];
5373 gboolean first_to_address;
5374 gboolean first_cc_address;
5376 ComposeHeaderEntry *headerentry;
5377 const gchar *headerentryname;
5378 const gchar *cc_hdr;
5379 const gchar *to_hdr;
5380 gboolean err = FALSE;
5382 debug_print("Writing redirect header\n");
5384 cc_hdr = prefs_common_translated_header_name("Cc:");
5385 to_hdr = prefs_common_translated_header_name("To:");
5387 first_to_address = TRUE;
5388 for (list = compose->header_list; list; list = list->next) {
5389 headerentry = ((ComposeHeaderEntry *)list->data);
5390 headerentryname = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo)))));
5392 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
5393 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5394 Xstrdup_a(str, entstr, return -1);
5396 if (str[0] != '\0') {
5397 compose_convert_header
5398 (compose, buf, sizeof(buf), str,
5399 strlen("Resent-To") + 2, TRUE);
5401 if (first_to_address) {
5402 err |= (fprintf(fp, "Resent-To: ") < 0);
5403 first_to_address = FALSE;
5405 err |= (fprintf(fp, ",") < 0);
5407 err |= (fprintf(fp, "%s", buf) < 0);
5411 if (!first_to_address) {
5412 err |= (fprintf(fp, "\n") < 0);
5415 first_cc_address = TRUE;
5416 for (list = compose->header_list; list; list = list->next) {
5417 headerentry = ((ComposeHeaderEntry *)list->data);
5418 headerentryname = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo)))));
5420 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
5421 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5422 Xstrdup_a(str, strg, return -1);
5424 if (str[0] != '\0') {
5425 compose_convert_header
5426 (compose, buf, sizeof(buf), str,
5427 strlen("Resent-Cc") + 2, TRUE);
5429 if (first_cc_address) {
5430 err |= (fprintf(fp, "Resent-Cc: ") < 0);
5431 first_cc_address = FALSE;
5433 err |= (fprintf(fp, ",") < 0);
5435 err |= (fprintf(fp, "%s", buf) < 0);
5439 if (!first_cc_address) {
5440 err |= (fprintf(fp, "\n") < 0);
5443 return (err ? -1:0);
5446 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
5448 gchar date[RFC822_DATE_BUFFSIZE];
5449 gchar buf[BUFFSIZE];
5451 const gchar *entstr;
5452 /* struct utsname utsbuf; */
5453 gboolean err = FALSE;
5455 cm_return_val_if_fail(fp != NULL, -1);
5456 cm_return_val_if_fail(compose->account != NULL, -1);
5457 cm_return_val_if_fail(compose->account->address != NULL, -1);
5460 if (prefs_common.hide_timezone)
5461 get_rfc822_date_hide_tz(date, sizeof(date));
5463 get_rfc822_date(date, sizeof(date));
5464 err |= (fprintf(fp, "Resent-Date: %s\n", buf) < 0);
5467 if (compose->account->name && *compose->account->name) {
5468 compose_convert_header
5469 (compose, buf, sizeof(buf), compose->account->name,
5470 strlen("From: "), TRUE);
5471 err |= (fprintf(fp, "Resent-From: %s <%s>\n",
5472 buf, compose->account->address) < 0);
5474 err |= (fprintf(fp, "Resent-From: %s\n", compose->account->address) < 0);
5477 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
5478 if (*entstr != '\0') {
5479 Xstrdup_a(str, entstr, return -1);
5482 compose_convert_header(compose, buf, sizeof(buf), str,
5483 strlen("Subject: "), FALSE);
5484 err |= (fprintf(fp, "Subject: %s\n", buf) < 0);
5488 /* Resent-Message-ID */
5489 if (compose->account->gen_msgid) {
5490 gchar *addr = prefs_account_generate_msgid(compose->account);
5491 err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", addr) < 0);
5493 g_free(compose->msgid);
5494 compose->msgid = addr;
5496 compose->msgid = NULL;
5499 if (compose_redirect_write_headers_from_headerlist(compose, fp))
5502 /* separator between header and body */
5503 err |= (fputs("\n", fp) == EOF);
5505 return (err ? -1:0);
5508 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
5513 gchar rewrite_buf[BUFFSIZE];
5515 gboolean skip = FALSE;
5516 gboolean err = FALSE;
5517 gchar *not_included[]={
5518 "Return-Path:", "Delivered-To:", "Received:",
5519 "Subject:", "X-UIDL:", "AF:",
5520 "NF:", "PS:", "SRH:",
5521 "SFN:", "DSR:", "MID:",
5522 "CFG:", "PT:", "S:",
5523 "RQ:", "SSV:", "NSV:",
5524 "SSH:", "R:", "MAID:",
5525 "NAID:", "RMID:", "FMID:",
5526 "SCF:", "RRCPT:", "NG:",
5527 "X-Claws-Privacy", "X-Claws-Sign:", "X-Claws-Encrypt",
5528 "X-Claws-End-Special-Headers:", "X-Claws-Account-Id:",
5529 "X-Sylpheed-Privacy", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt",
5530 "X-Sylpheed-End-Special-Headers:", "X-Sylpheed-Account-Id:",
5531 "X-Claws-Auto-Wrapping:", "X-Claws-Auto-Indent:",
5536 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
5537 FILE_OP_ERROR(compose->redirect_filename, "fopen");
5541 while ((ret = procheader_get_one_field_asis(&buf, fp)) != -1) {
5543 for (i = 0; not_included[i] != NULL; i++) {
5544 if (g_ascii_strncasecmp(buf, not_included[i],
5545 strlen(not_included[i])) == 0) {
5555 if (fputs(buf, fdest) == -1) {
5561 if (!prefs_common.redirect_keep_from) {
5562 if (g_ascii_strncasecmp(buf, "From:",
5563 strlen("From:")) == 0) {
5564 err |= (fputs(" (by way of ", fdest) == EOF);
5565 if (compose->account->name
5566 && *compose->account->name) {
5567 gchar buffer[BUFFSIZE];
5569 compose_convert_header
5570 (compose, buffer, sizeof(buffer),
5571 compose->account->name,
5574 err |= (fprintf(fdest, "%s <%s>",
5576 compose->account->address) < 0);
5578 err |= (fprintf(fdest, "%s",
5579 compose->account->address) < 0);
5580 err |= (fputs(")", fdest) == EOF);
5586 if (fputs("\n", fdest) == -1)
5593 if (compose_redirect_write_headers(compose, fdest))
5596 while ((len = fread(rewrite_buf, sizeof(gchar), sizeof(rewrite_buf), fp)) > 0) {
5597 if (fwrite(rewrite_buf, sizeof(gchar), len, fdest) != len)
5611 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
5613 GtkTextBuffer *buffer;
5614 GtkTextIter start, end;
5615 gchar *chars, *tmp_enc_file, *content;
5617 const gchar *out_codeset;
5618 EncodingType encoding = ENC_UNKNOWN;
5619 MimeInfo *mimemsg, *mimetext;
5621 const gchar *src_codeset = CS_INTERNAL;
5622 gchar *from_addr = NULL;
5623 gchar *from_name = NULL;
5626 if (action == COMPOSE_WRITE_FOR_SEND) {
5627 attach_parts = TRUE;
5629 /* We're sending the message, generate a Message-ID
5631 if (compose->msgid == NULL &&
5632 compose->account->gen_msgid) {
5633 compose->msgid = prefs_account_generate_msgid(compose->account);
5637 /* create message MimeInfo */
5638 mimemsg = procmime_mimeinfo_new();
5639 mimemsg->type = MIMETYPE_MESSAGE;
5640 mimemsg->subtype = g_strdup("rfc822");
5641 mimemsg->content = MIMECONTENT_MEM;
5642 mimemsg->tmp = TRUE; /* must free content later */
5643 mimemsg->data.mem = compose_get_header(compose);
5645 /* Create text part MimeInfo */
5646 /* get all composed text */
5647 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
5648 gtk_text_buffer_get_start_iter(buffer, &start);
5649 gtk_text_buffer_get_end_iter(buffer, &end);
5650 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
5652 out_codeset = conv_get_charset_str(compose->out_encoding);
5654 if (!out_codeset && is_ascii_str(chars)) {
5655 out_codeset = CS_US_ASCII;
5656 } else if (prefs_common.outgoing_fallback_to_ascii &&
5657 is_ascii_str(chars)) {
5658 out_codeset = CS_US_ASCII;
5659 encoding = ENC_7BIT;
5663 gchar *test_conv_global_out = NULL;
5664 gchar *test_conv_reply = NULL;
5666 /* automatic mode. be automatic. */
5667 codeconv_set_strict(TRUE);
5669 out_codeset = conv_get_outgoing_charset_str();
5671 debug_print("trying to convert to %s\n", out_codeset);
5672 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
5675 if (!test_conv_global_out && compose->orig_charset
5676 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5677 out_codeset = compose->orig_charset;
5678 debug_print("failure; trying to convert to %s\n", out_codeset);
5679 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
5682 if (!test_conv_global_out && !test_conv_reply) {
5684 out_codeset = CS_INTERNAL;
5685 debug_print("failure; finally using %s\n", out_codeset);
5687 g_free(test_conv_global_out);
5688 g_free(test_conv_reply);
5689 codeconv_set_strict(FALSE);
5692 if (encoding == ENC_UNKNOWN) {
5693 if (prefs_common.encoding_method == CTE_BASE64)
5694 encoding = ENC_BASE64;
5695 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
5696 encoding = ENC_QUOTED_PRINTABLE;
5697 else if (prefs_common.encoding_method == CTE_8BIT)
5698 encoding = ENC_8BIT;
5700 encoding = procmime_get_encoding_for_charset(out_codeset);
5703 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
5704 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
5706 if (action == COMPOSE_WRITE_FOR_SEND) {
5707 codeconv_set_strict(TRUE);
5708 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
5709 codeconv_set_strict(FALSE);
5714 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
5715 "to the specified %s charset.\n"
5716 "Send it as %s?"), out_codeset, src_codeset);
5717 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL,
5718 g_strconcat("+", _("_Send"), NULL), NULL, FALSE,
5719 NULL, ALERT_ERROR, G_ALERTDEFAULT);
5722 if (aval != G_ALERTALTERNATE) {
5727 out_codeset = src_codeset;
5733 out_codeset = src_codeset;
5738 if (prefs_common.rewrite_first_from && (encoding == ENC_8BIT || encoding == ENC_7BIT)) {
5739 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
5740 strstr(buf, "\nFrom ") != NULL) {
5741 encoding = ENC_QUOTED_PRINTABLE;
5745 mimetext = procmime_mimeinfo_new();
5746 mimetext->content = MIMECONTENT_MEM;
5747 mimetext->tmp = TRUE; /* must free content later */
5748 /* dup'ed because procmime_encode_content can turn it into a tmpfile
5749 * and free the data, which we need later. */
5750 mimetext->data.mem = g_strdup(buf);
5751 mimetext->type = MIMETYPE_TEXT;
5752 mimetext->subtype = g_strdup("plain");
5753 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
5754 g_strdup(out_codeset));
5756 /* protect trailing spaces when signing message */
5757 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
5758 privacy_system_can_sign(compose->privacy_system)) {
5759 encoding = ENC_QUOTED_PRINTABLE;
5763 debug_print("main text: %Id bytes encoded as %s in %d\n",
5765 debug_print("main text: %zd bytes encoded as %s in %d\n",
5767 strlen(buf), out_codeset, encoding);
5769 /* check for line length limit */
5770 if (action == COMPOSE_WRITE_FOR_SEND &&
5771 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
5772 check_line_length(buf, 1000, &line) < 0) {
5775 msg = g_strdup_printf
5776 (_("Line %d exceeds the line length limit (998 bytes).\n"
5777 "The contents of the message might be broken on the way to the delivery.\n"
5779 "Send it anyway?"), line + 1);
5780 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
5782 if (aval != G_ALERTALTERNATE) {
5788 if (encoding != ENC_UNKNOWN)
5789 procmime_encode_content(mimetext, encoding);
5791 /* append attachment parts */
5792 if (compose_use_attach(compose) && attach_parts) {
5793 MimeInfo *mimempart;
5794 gchar *boundary = NULL;
5795 mimempart = procmime_mimeinfo_new();
5796 mimempart->content = MIMECONTENT_EMPTY;
5797 mimempart->type = MIMETYPE_MULTIPART;
5798 mimempart->subtype = g_strdup("mixed");
5802 boundary = generate_mime_boundary(NULL);
5803 } while (strstr(buf, boundary) != NULL);
5805 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
5808 mimetext->disposition = DISPOSITIONTYPE_INLINE;
5810 g_node_append(mimempart->node, mimetext->node);
5811 g_node_append(mimemsg->node, mimempart->node);
5813 if (compose_add_attachments(compose, mimempart) < 0)
5816 g_node_append(mimemsg->node, mimetext->node);
5820 if (strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) != 0) {
5821 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5822 /* extract name and address */
5823 if (strstr(spec, " <") && strstr(spec, ">")) {
5824 from_addr = g_strdup(strrchr(spec, '<')+1);
5825 *(strrchr(from_addr, '>')) = '\0';
5826 from_name = g_strdup(spec);
5827 *(strrchr(from_name, '<')) = '\0';
5834 /* sign message if sending */
5835 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
5836 privacy_system_can_sign(compose->privacy_system))
5837 if (!privacy_sign(compose->privacy_system, mimemsg,
5838 compose->account, from_addr)) {
5846 if (compose->use_encryption) {
5847 if (compose->encdata != NULL &&
5848 strcmp(compose->encdata, "_DONT_ENCRYPT_")) {
5850 /* First, write an unencrypted copy and save it to outbox, if
5851 * user wants that. */
5852 if (compose->account->save_encrypted_as_clear_text) {
5853 debug_print("saving sent message unencrypted...\n");
5854 FILE *tmpfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmp_enc_file);
5858 /* fp now points to a file with headers written,
5859 * let's make a copy. */
5861 content = file_read_stream_to_str(fp);
5863 str_write_to_file(content, tmp_enc_file);
5866 /* Now write the unencrypted body. */
5867 if ((tmpfp = g_fopen(tmp_enc_file, "a")) != NULL) {
5868 procmime_write_mimeinfo(mimemsg, tmpfp);
5871 outbox = folder_find_item_from_identifier(compose_get_save_to(compose));
5873 outbox = folder_get_default_outbox();
5875 procmsg_save_to_outbox(outbox, tmp_enc_file, TRUE);
5876 claws_unlink(tmp_enc_file);
5878 g_warning("Can't open file '%s'", tmp_enc_file);
5881 g_warning("couldn't get tempfile");
5884 if (!privacy_encrypt(compose->privacy_system, mimemsg, compose->encdata)) {
5885 debug_print("Couldn't encrypt mime structure: %s.\n",
5886 privacy_get_error());
5887 alertpanel_error(_("Couldn't encrypt the email: %s"),
5888 privacy_get_error());
5893 procmime_write_mimeinfo(mimemsg, fp);
5895 procmime_mimeinfo_free_all(&mimemsg);
5900 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
5902 GtkTextBuffer *buffer;
5903 GtkTextIter start, end;
5908 if ((fp = g_fopen(file, "wb")) == NULL) {
5909 FILE_OP_ERROR(file, "fopen");
5913 /* chmod for security */
5914 if (change_file_mode_rw(fp, file) < 0) {
5915 FILE_OP_ERROR(file, "chmod");
5916 g_warning("can't change file mode");
5919 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
5920 gtk_text_buffer_get_start_iter(buffer, &start);
5921 gtk_text_buffer_get_end_iter(buffer, &end);
5922 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
5924 chars = conv_codeset_strdup
5925 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
5934 len = strlen(chars);
5935 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
5936 FILE_OP_ERROR(file, "fwrite");
5945 if (fclose(fp) == EOF) {
5946 FILE_OP_ERROR(file, "fclose");
5953 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
5956 MsgInfo *msginfo = compose->targetinfo;
5958 cm_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
5959 if (!msginfo) return -1;
5961 if (!force && MSG_IS_LOCKED(msginfo->flags))
5964 item = msginfo->folder;
5965 cm_return_val_if_fail(item != NULL, -1);
5967 if (procmsg_msg_exist(msginfo) &&
5968 (folder_has_parent_of_type(item, F_QUEUE) ||
5969 folder_has_parent_of_type(item, F_DRAFT)
5970 || msginfo == compose->autosaved_draft)) {
5971 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
5972 g_warning("can't remove the old message");
5975 debug_print("removed reedit target %d\n", msginfo->msgnum);
5982 static void compose_remove_draft(Compose *compose)
5985 MsgInfo *msginfo = compose->targetinfo;
5986 drafts = account_get_special_folder(compose->account, F_DRAFT);
5988 if (procmsg_msg_exist(msginfo)) {
5989 folder_item_remove_msg(drafts, msginfo->msgnum);
5994 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
5995 gboolean remove_reedit_target)
5997 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
6000 static gboolean compose_warn_encryption(Compose *compose)
6002 const gchar *warning = privacy_get_encrypt_warning(compose->privacy_system);
6003 AlertValue val = G_ALERTALTERNATE;
6005 if (warning == NULL)
6008 val = alertpanel_full(_("Encryption warning"), warning,
6009 GTK_STOCK_CANCEL, g_strconcat("+", _("C_ontinue"), NULL), NULL,
6010 TRUE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6011 if (val & G_ALERTDISABLE) {
6012 val &= ~G_ALERTDISABLE;
6013 if (val == G_ALERTALTERNATE)
6014 privacy_inhibit_encrypt_warning(compose->privacy_system,
6018 if (val == G_ALERTALTERNATE) {
6025 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
6026 gchar **msgpath, gboolean perform_checks,
6027 gboolean remove_reedit_target)
6034 PrefsAccount *mailac = NULL, *newsac = NULL;
6035 gboolean err = FALSE;
6037 debug_print("queueing message...\n");
6038 cm_return_val_if_fail(compose->account != NULL, -1);
6040 if (compose_check_entries(compose, perform_checks) == FALSE) {
6041 if (compose->batch) {
6042 gtk_widget_show_all(compose->window);
6047 if (!compose->to_list && !compose->newsgroup_list) {
6048 g_warning("can't get recipient list.");
6052 if (compose->to_list) {
6053 if (compose->account->protocol != A_NNTP)
6054 mailac = compose->account;
6055 else if (cur_account && cur_account->protocol != A_NNTP)
6056 mailac = cur_account;
6057 else if (!(mailac = compose_current_mail_account())) {
6058 alertpanel_error(_("No account for sending mails available!"));
6063 if (compose->newsgroup_list) {
6064 if (compose->account->protocol == A_NNTP)
6065 newsac = compose->account;
6067 alertpanel_error(_("Selected account isn't NNTP: Posting is impossible."));
6072 /* write queue header */
6073 tmp = g_strdup_printf("%s%cqueue.%p%08x", get_tmp_dir(),
6074 G_DIR_SEPARATOR, compose, (guint) rand());
6075 debug_print("queuing to %s\n", tmp);
6076 if ((fp = g_fopen(tmp, "w+b")) == NULL) {
6077 FILE_OP_ERROR(tmp, "fopen");
6082 if (change_file_mode_rw(fp, tmp) < 0) {
6083 FILE_OP_ERROR(tmp, "chmod");
6084 g_warning("can't change file mode");
6087 /* queueing variables */
6088 err |= (fprintf(fp, "AF:\n") < 0);
6089 err |= (fprintf(fp, "NF:0\n") < 0);
6090 err |= (fprintf(fp, "PS:10\n") < 0);
6091 err |= (fprintf(fp, "SRH:1\n") < 0);
6092 err |= (fprintf(fp, "SFN:\n") < 0);
6093 err |= (fprintf(fp, "DSR:\n") < 0);
6095 err |= (fprintf(fp, "MID:<%s>\n", compose->msgid) < 0);
6097 err |= (fprintf(fp, "MID:\n") < 0);
6098 err |= (fprintf(fp, "CFG:\n") < 0);
6099 err |= (fprintf(fp, "PT:0\n") < 0);
6100 err |= (fprintf(fp, "S:%s\n", compose->account->address) < 0);
6101 err |= (fprintf(fp, "RQ:\n") < 0);
6103 err |= (fprintf(fp, "SSV:%s\n", mailac->smtp_server) < 0);
6105 err |= (fprintf(fp, "SSV:\n") < 0);
6107 err |= (fprintf(fp, "NSV:%s\n", newsac->nntp_server) < 0);
6109 err |= (fprintf(fp, "NSV:\n") < 0);
6110 err |= (fprintf(fp, "SSH:\n") < 0);
6111 /* write recepient list */
6112 if (compose->to_list) {
6113 err |= (fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data) < 0);
6114 for (cur = compose->to_list->next; cur != NULL;
6116 err |= (fprintf(fp, ",<%s>", (gchar *)cur->data) < 0);
6117 err |= (fprintf(fp, "\n") < 0);
6119 /* write newsgroup list */
6120 if (compose->newsgroup_list) {
6121 err |= (fprintf(fp, "NG:") < 0);
6122 err |= (fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data) < 0);
6123 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
6124 err |= (fprintf(fp, ",%s", (gchar *)cur->data) < 0);
6125 err |= (fprintf(fp, "\n") < 0);
6127 /* Sylpheed account IDs */
6129 err |= (fprintf(fp, "MAID:%d\n", mailac->account_id) < 0);
6131 err |= (fprintf(fp, "NAID:%d\n", newsac->account_id) < 0);
6134 if (compose->privacy_system != NULL) {
6135 err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0);
6136 err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
6137 if (compose->use_encryption) {
6138 if (!compose_warn_encryption(compose)) {
6144 if (mailac && mailac->encrypt_to_self) {
6145 GSList *tmp_list = g_slist_copy(compose->to_list);
6146 tmp_list = g_slist_append(tmp_list, compose->account->address);
6147 compose->encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
6148 g_slist_free(tmp_list);
6150 compose->encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
6152 if (compose->encdata != NULL) {
6153 if (strcmp(compose->encdata, "_DONT_ENCRYPT_")) {
6154 err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
6155 err |= (fprintf(fp, "X-Claws-Encrypt-Data:%s\n",
6156 compose->encdata) < 0);
6157 } /* else we finally dont want to encrypt */
6159 err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
6160 /* and if encdata was null, it means there's been a problem in
6163 g_warning("failed to write queue message");
6172 /* Save copy folder */
6173 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6174 gchar *savefolderid;
6176 savefolderid = compose_get_save_to(compose);
6177 err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0);
6178 g_free(savefolderid);
6180 /* Save copy folder */
6181 if (compose->return_receipt) {
6182 err |= (fprintf(fp, "RRCPT:1\n") < 0);
6184 /* Message-ID of message replying to */
6185 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
6186 gchar *folderid = NULL;
6188 if (compose->replyinfo->folder)
6189 folderid = folder_item_get_identifier(compose->replyinfo->folder);
6190 if (folderid == NULL)
6191 folderid = g_strdup("NULL");
6193 err |= (fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid) < 0);
6196 /* Message-ID of message forwarding to */
6197 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
6198 gchar *folderid = NULL;
6200 if (compose->fwdinfo->folder)
6201 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
6202 if (folderid == NULL)
6203 folderid = g_strdup("NULL");
6205 err |= (fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid) < 0);
6209 err |= (fprintf(fp, "X-Claws-Auto-Wrapping:%d\n", compose->autowrap) < 0);
6210 err |= (fprintf(fp, "X-Claws-Auto-Indent:%d\n", compose->autoindent) < 0);
6212 /* end of headers */
6213 err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
6215 if (compose->redirect_filename != NULL) {
6216 if (compose_redirect_write_to_file(compose, fp) < 0) {
6224 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
6228 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
6232 g_warning("failed to write queue message");
6238 if (fclose(fp) == EOF) {
6239 FILE_OP_ERROR(tmp, "fclose");
6245 if (item && *item) {
6248 queue = account_get_special_folder(compose->account, F_QUEUE);
6251 g_warning("can't find queue folder");
6256 folder_item_scan(queue);
6257 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
6258 g_warning("can't queue the message");
6264 if (msgpath == NULL) {
6270 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
6271 compose_remove_reedit_target(compose, FALSE);
6274 if ((msgnum != NULL) && (item != NULL)) {
6282 static int compose_add_attachments(Compose *compose, MimeInfo *parent)
6285 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6288 gchar *type, *subtype;
6289 GtkTreeModel *model;
6292 model = gtk_tree_view_get_model(tree_view);
6294 if (!gtk_tree_model_get_iter_first(model, &iter))
6297 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6299 if (!is_file_exist(ainfo->file)) {
6300 gchar *msg = g_strdup_printf(_("Attachment %s doesn't exist anymore. Ignore?"), ainfo->file);
6301 AlertValue val = alertpanel_full(_("Warning"), msg, _("Cancel sending"), _("Ignore attachment"),
6302 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
6304 if (val == G_ALERTDEFAULT) {
6309 if (g_stat(ainfo->file, &statbuf) < 0)
6312 mimepart = procmime_mimeinfo_new();
6313 mimepart->content = MIMECONTENT_FILE;
6314 mimepart->data.filename = g_strdup(ainfo->file);
6315 mimepart->tmp = FALSE; /* or we destroy our attachment */
6316 mimepart->offset = 0;
6317 mimepart->length = statbuf.st_size;
6319 type = g_strdup(ainfo->content_type);
6321 if (!strchr(type, '/')) {
6323 type = g_strdup("application/octet-stream");
6326 subtype = strchr(type, '/') + 1;
6327 *(subtype - 1) = '\0';
6328 mimepart->type = procmime_get_media_type(type);
6329 mimepart->subtype = g_strdup(subtype);
6332 if (mimepart->type == MIMETYPE_MESSAGE &&
6333 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
6334 mimepart->disposition = DISPOSITIONTYPE_INLINE;
6335 } else if (mimepart->type == MIMETYPE_TEXT) {
6336 if (!ainfo->name && g_ascii_strcasecmp(mimepart->subtype, "plain")) {
6337 /* Text parts with no name come from multipart/alternative
6338 * forwards. Make sure the recipient won't look at the
6339 * original HTML part by mistake. */
6340 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
6341 ainfo->name = g_strdup_printf(_("Original %s part"),
6345 g_hash_table_insert(mimepart->typeparameters,
6346 g_strdup("charset"), g_strdup(ainfo->charset));
6348 if (ainfo->name && mimepart->type != MIMETYPE_MESSAGE) {
6349 if (mimepart->type == MIMETYPE_APPLICATION &&
6350 !strcmp2(mimepart->subtype, "octet-stream"))
6351 g_hash_table_insert(mimepart->typeparameters,
6352 g_strdup("name"), g_strdup(ainfo->name));
6353 g_hash_table_insert(mimepart->dispositionparameters,
6354 g_strdup("filename"), g_strdup(ainfo->name));
6355 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
6358 if (mimepart->type == MIMETYPE_MESSAGE
6359 || mimepart->type == MIMETYPE_MULTIPART)
6360 ainfo->encoding = ENC_BINARY;
6361 else if (compose->use_signing) {
6362 if (ainfo->encoding == ENC_7BIT)
6363 ainfo->encoding = ENC_QUOTED_PRINTABLE;
6364 else if (ainfo->encoding == ENC_8BIT)
6365 ainfo->encoding = ENC_BASE64;
6368 procmime_encode_content(mimepart, ainfo->encoding);
6370 g_node_append(parent->node, mimepart->node);
6371 } while (gtk_tree_model_iter_next(model, &iter));
6376 static gchar *compose_quote_list_of_addresses(gchar *str)
6378 GSList *list = NULL, *item = NULL;
6379 gchar *qname = NULL, *faddr = NULL, *result = NULL;
6381 list = address_list_append_with_comments(list, str);
6382 for (item = list; item != NULL; item = item->next) {
6383 gchar *spec = item->data;
6384 gchar *endofname = strstr(spec, " <");
6385 if (endofname != NULL) {
6388 QUOTE_IF_REQUIRED_NORMAL(qname, spec, return NULL);
6389 qqname = escape_internal_quotes(qname, '"');
6391 if (*qname != *spec || qqname != qname) { /* has been quoted, compute new */
6392 gchar *addr = g_strdup(endofname);
6393 gchar *name = (qqname != qname)? qqname: g_strdup(qname);
6394 faddr = g_strconcat(name, addr, NULL);
6397 debug_print("new auto-quoted address: '%s'\n", faddr);
6401 result = g_strdup((faddr != NULL)? faddr: spec);
6403 result = g_strconcat(result,
6405 (faddr != NULL)? faddr: spec,
6408 if (faddr != NULL) {
6413 slist_free_strings_full(list);
6418 #define IS_IN_CUSTOM_HEADER(header) \
6419 (compose->account->add_customhdr && \
6420 custom_header_find(compose->account->customhdr_list, header) != NULL)
6422 static const gchar *compose_untranslated_header_name(gchar *header_name)
6424 /* return the untranslated header name, if header_name is a known
6425 header name, in either its translated or untranslated form, with
6426 or without trailing colon. return NULL if no matching header name
6427 is found or if header_name is NULL. */
6428 gchar *translated_header_name;
6429 gchar *translated_header_name_wcolon;
6430 const gchar *untranslated_header_name;
6431 const gchar *untranslated_header_name_wcolon;
6434 cm_return_val_if_fail(header_name != NULL, NULL);
6436 for (i = 0; HEADERS[i].header_name != NULL; i++) {
6437 untranslated_header_name = HEADERS[i].header_name;
6438 untranslated_header_name_wcolon = HEADERS[i].header_name_w_colon;
6440 translated_header_name = gettext(untranslated_header_name);
6441 translated_header_name_wcolon = gettext(untranslated_header_name_wcolon);
6443 if (!strcmp(header_name, untranslated_header_name) ||
6444 !strcmp(header_name, translated_header_name)) {
6445 return untranslated_header_name;
6447 if (!strcmp(header_name, untranslated_header_name_wcolon) ||
6448 !strcmp(header_name, translated_header_name_wcolon)) {
6449 return untranslated_header_name_wcolon;
6453 debug_print("compose_untranslated_header_name: unknown header '%s'\n", header_name);
6457 static void compose_add_headerfield_from_headerlist(Compose *compose,
6459 const gchar *fieldname,
6460 const gchar *seperator)
6462 gchar *str, *fieldname_w_colon;
6463 gboolean add_field = FALSE;
6465 ComposeHeaderEntry *headerentry;
6466 const gchar *headerentryname;
6467 const gchar *trans_fieldname;
6470 if (IS_IN_CUSTOM_HEADER(fieldname))
6473 debug_print("Adding %s-fields\n", fieldname);
6475 fieldstr = g_string_sized_new(64);
6477 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
6478 trans_fieldname = prefs_common_translated_header_name(fieldname_w_colon);
6480 for (list = compose->header_list; list; list = list->next) {
6481 headerentry = ((ComposeHeaderEntry *)list->data);
6482 headerentryname = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo)))));
6484 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
6485 gchar * ustr = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
6487 str = compose_quote_list_of_addresses(ustr);
6489 if (str != NULL && str[0] != '\0') {
6491 g_string_append(fieldstr, seperator);
6492 g_string_append(fieldstr, str);
6501 buf = g_new0(gchar, fieldstr->len * 4 + 256);
6502 compose_convert_header
6503 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
6504 strlen(fieldname) + 2, TRUE);
6505 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
6509 g_free(fieldname_w_colon);
6510 g_string_free(fieldstr, TRUE);
6515 static gchar *compose_get_manual_headers_info(Compose *compose)
6517 GString *sh_header = g_string_new(" ");
6519 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
6521 for (list = compose->header_list; list; list = list->next) {
6522 ComposeHeaderEntry *headerentry;
6525 gchar *headername_wcolon;
6526 const gchar *headername_trans;
6528 gboolean standard_header = FALSE;
6530 headerentry = ((ComposeHeaderEntry *)list->data);
6532 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo))))));
6534 if (*tmp == '\0' || strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
6539 if (!strstr(tmp, ":")) {
6540 headername_wcolon = g_strconcat(tmp, ":", NULL);
6541 headername = g_strdup(tmp);
6543 headername_wcolon = g_strdup(tmp);
6544 headername = g_strdup(strtok(tmp, ":"));
6548 string = std_headers;
6549 while (*string != NULL) {
6550 headername_trans = prefs_common_translated_header_name(*string);
6551 if (!strcmp(headername_trans, headername_wcolon))
6552 standard_header = TRUE;
6555 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
6556 g_string_append_printf(sh_header, "%s ", headername);
6558 g_free(headername_wcolon);
6560 g_string_truncate(sh_header, strlen(sh_header->str) - 1); /* remove last space */
6561 return g_string_free(sh_header, FALSE);
6564 static gchar *compose_get_header(Compose *compose)
6566 gchar date[RFC822_DATE_BUFFSIZE];
6567 gchar buf[BUFFSIZE];
6568 const gchar *entry_str;
6572 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
6574 gchar *from_name = NULL, *from_address = NULL;
6577 cm_return_val_if_fail(compose->account != NULL, NULL);
6578 cm_return_val_if_fail(compose->account->address != NULL, NULL);
6580 header = g_string_sized_new(64);
6583 if (prefs_common.hide_timezone)
6584 get_rfc822_date_hide_tz(date, sizeof(date));
6586 get_rfc822_date(date, sizeof(date));
6587 g_string_append_printf(header, "Date: %s\n", date);
6591 if (compose->account->name && *compose->account->name) {
6593 QUOTE_IF_REQUIRED(buf, compose->account->name);
6594 tmp = g_strdup_printf("%s <%s>",
6595 buf, compose->account->address);
6597 tmp = g_strdup_printf("%s",
6598 compose->account->address);
6600 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
6601 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
6603 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
6604 from_address = g_strdup(compose->account->address);
6606 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
6607 /* extract name and address */
6608 if (strstr(spec, " <") && strstr(spec, ">")) {
6609 from_address = g_strdup(strrchr(spec, '<')+1);
6610 *(strrchr(from_address, '>')) = '\0';
6611 from_name = g_strdup(spec);
6612 *(strrchr(from_name, '<')) = '\0';
6615 from_address = g_strdup(spec);
6622 if (from_name && *from_name) {
6624 compose_convert_header
6625 (compose, buf, sizeof(buf), from_name,
6626 strlen("From: "), TRUE);
6627 QUOTE_IF_REQUIRED(name, buf);
6628 qname = escape_internal_quotes(name, '"');
6630 g_string_append_printf(header, "From: %s <%s>\n",
6631 qname, from_address);
6632 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") &&
6633 compose->return_receipt) {
6634 compose_convert_header(compose, buf, sizeof(buf), from_name,
6635 strlen("Disposition-Notification-To: "),
6637 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, from_address);
6642 g_string_append_printf(header, "From: %s\n", from_address);
6643 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") &&
6644 compose->return_receipt)
6645 g_string_append_printf(header, "Disposition-Notification-To: %s\n", from_address);
6649 g_free(from_address);
6652 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
6655 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
6658 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
6662 * If this account is a NNTP account remove Bcc header from
6663 * message body since it otherwise will be publicly shown
6665 if (compose->account->protocol != A_NNTP)
6666 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
6669 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
6671 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
6674 compose_convert_header(compose, buf, sizeof(buf), str,
6675 strlen("Subject: "), FALSE);
6676 g_string_append_printf(header, "Subject: %s\n", buf);
6682 if (compose->msgid != NULL && strlen(compose->msgid) > 0) {
6683 g_string_append_printf(header, "Message-ID: <%s>\n",
6687 if (compose->remove_references == FALSE) {
6689 if (compose->inreplyto && compose->to_list)
6690 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
6693 if (compose->references)
6694 g_string_append_printf(header, "References: %s\n", compose->references);
6698 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
6701 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
6704 if (compose->account->organization &&
6705 strlen(compose->account->organization) &&
6706 !IS_IN_CUSTOM_HEADER("Organization")) {
6707 compose_convert_header(compose, buf, sizeof(buf),
6708 compose->account->organization,
6709 strlen("Organization: "), FALSE);
6710 g_string_append_printf(header, "Organization: %s\n", buf);
6713 /* Program version and system info */
6714 if (compose->account->gen_xmailer &&
6715 g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
6716 !compose->newsgroup_list) {
6717 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
6719 gtk_major_version, gtk_minor_version, gtk_micro_version,
6722 if (compose->account->gen_xmailer &&
6723 g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
6724 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
6726 gtk_major_version, gtk_minor_version, gtk_micro_version,
6730 /* custom headers */
6731 if (compose->account->add_customhdr) {
6734 for (cur = compose->account->customhdr_list; cur != NULL;
6736 CustomHeader *chdr = (CustomHeader *)cur->data;
6738 if (custom_header_is_allowed(chdr->name)
6739 && chdr->value != NULL
6740 && *(chdr->value) != '\0') {
6741 compose_convert_header
6742 (compose, buf, sizeof(buf),
6744 strlen(chdr->name) + 2, FALSE);
6745 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
6750 /* Automatic Faces and X-Faces */
6751 if (get_account_xface (buf, sizeof(buf), compose->account->account_name) == 0) {
6752 g_string_append_printf(header, "X-Face: %s\n", buf);
6754 else if (get_default_xface (buf, sizeof(buf)) == 0) {
6755 g_string_append_printf(header, "X-Face: %s\n", buf);
6757 if (get_account_face (buf, sizeof(buf), compose->account->account_name) == 0) {
6758 g_string_append_printf(header, "Face: %s\n", buf);
6760 else if (get_default_face (buf, sizeof(buf)) == 0) {
6761 g_string_append_printf(header, "Face: %s\n", buf);
6765 switch (compose->priority) {
6766 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
6767 "X-Priority: 1 (Highest)\n");
6769 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
6770 "X-Priority: 2 (High)\n");
6772 case PRIORITY_NORMAL: break;
6773 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
6774 "X-Priority: 4 (Low)\n");
6776 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
6777 "X-Priority: 5 (Lowest)\n");
6779 default: debug_print("compose: priority unknown : %d\n",
6783 /* get special headers */
6784 for (list = compose->header_list; list; list = list->next) {
6785 ComposeHeaderEntry *headerentry;
6788 gchar *headername_wcolon;
6789 const gchar *headername_trans;
6792 gboolean standard_header = FALSE;
6794 headerentry = ((ComposeHeaderEntry *)list->data);
6796 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo))))));
6798 if (*tmp == '\0' || strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
6803 if (!strstr(tmp, ":")) {
6804 headername_wcolon = g_strconcat(tmp, ":", NULL);
6805 headername = g_strdup(tmp);
6807 headername_wcolon = g_strdup(tmp);
6808 headername = g_strdup(strtok(tmp, ":"));
6812 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
6813 Xstrdup_a(headervalue, entry_str, return NULL);
6814 subst_char(headervalue, '\r', ' ');
6815 subst_char(headervalue, '\n', ' ');
6816 g_strstrip(headervalue);
6817 if (*headervalue != '\0') {
6818 string = std_headers;
6819 while (*string != NULL && !standard_header) {
6820 headername_trans = prefs_common_translated_header_name(*string);
6821 /* support mixed translated and untranslated headers */
6822 if (!strcmp(headername_trans, headername_wcolon) || !strcmp(*string, headername_wcolon))
6823 standard_header = TRUE;
6826 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername)) {
6827 /* store untranslated header name */
6828 g_string_append_printf(header, "%s %s\n",
6829 compose_untranslated_header_name(headername_wcolon), headervalue);
6833 g_free(headername_wcolon);
6837 g_string_free(header, FALSE);
6842 #undef IS_IN_CUSTOM_HEADER
6844 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
6845 gint header_len, gboolean addr_field)
6847 gchar *tmpstr = NULL;
6848 const gchar *out_codeset = NULL;
6850 cm_return_if_fail(src != NULL);
6851 cm_return_if_fail(dest != NULL);
6853 if (len < 1) return;
6855 tmpstr = g_strdup(src);
6857 subst_char(tmpstr, '\n', ' ');
6858 subst_char(tmpstr, '\r', ' ');
6861 if (!g_utf8_validate(tmpstr, -1, NULL)) {
6862 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
6863 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
6868 codeconv_set_strict(TRUE);
6869 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
6870 conv_get_charset_str(compose->out_encoding));
6871 codeconv_set_strict(FALSE);
6873 if (!dest || *dest == '\0') {
6874 gchar *test_conv_global_out = NULL;
6875 gchar *test_conv_reply = NULL;
6877 /* automatic mode. be automatic. */
6878 codeconv_set_strict(TRUE);
6880 out_codeset = conv_get_outgoing_charset_str();
6882 debug_print("trying to convert to %s\n", out_codeset);
6883 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
6886 if (!test_conv_global_out && compose->orig_charset
6887 && strcmp(compose->orig_charset, CS_US_ASCII)) {
6888 out_codeset = compose->orig_charset;
6889 debug_print("failure; trying to convert to %s\n", out_codeset);
6890 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
6893 if (!test_conv_global_out && !test_conv_reply) {
6895 out_codeset = CS_INTERNAL;
6896 debug_print("finally using %s\n", out_codeset);
6898 g_free(test_conv_global_out);
6899 g_free(test_conv_reply);
6900 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
6902 codeconv_set_strict(FALSE);
6907 static void compose_add_to_addressbook_cb(GtkMenuItem *menuitem, gpointer user_data)
6911 cm_return_if_fail(user_data != NULL);
6913 address = g_strdup(gtk_entry_get_text(GTK_ENTRY(user_data)));
6914 g_strstrip(address);
6915 if (*address != '\0') {
6916 gchar *name = procheader_get_fromname(address);
6917 extract_address(address);
6918 #ifndef USE_ALT_ADDRBOOK
6919 addressbook_add_contact(name, address, NULL, NULL);
6921 debug_print("%s: %s\n", name, address);
6922 if (addressadd_selection(name, address, NULL, NULL)) {
6923 debug_print( "addressbook_add_contact - added\n" );
6930 static void compose_entry_popup_extend(GtkEntry *entry, GtkMenu *menu, gpointer user_data)
6932 GtkWidget *menuitem;
6935 cm_return_if_fail(menu != NULL);
6936 cm_return_if_fail(GTK_IS_MENU_SHELL(menu));
6938 menuitem = gtk_separator_menu_item_new();
6939 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem);
6940 gtk_widget_show(menuitem);
6942 menuitem = gtk_menu_item_new_with_mnemonic(_("Add to address _book"));
6943 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem);
6945 address = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
6946 g_strstrip(address);
6947 if (*address == '\0') {
6948 gtk_widget_set_sensitive(GTK_WIDGET(menuitem), FALSE);
6951 g_signal_connect(G_OBJECT(menuitem), "activate",
6952 G_CALLBACK(compose_add_to_addressbook_cb), entry);
6953 gtk_widget_show(menuitem);
6956 void compose_add_extra_header(gchar *header, GtkListStore *model)
6959 if (strcmp(header, "")) {
6960 COMBOBOX_ADD(model, header, COMPOSE_TO);
6964 void compose_add_extra_header_entries(GtkListStore *model)
6968 gchar buf[BUFFSIZE];
6971 if (extra_headers == NULL) {
6972 exhrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "extraheaderrc", NULL);
6973 if ((exh = g_fopen(exhrc, "rb")) == NULL) {
6974 debug_print("extra headers file not found\n");
6975 goto extra_headers_done;
6977 while (fgets(buf, BUFFSIZE, exh) != NULL) {
6978 lastc = strlen(buf) - 1; /* remove trailing control chars */
6979 while (lastc >= 0 && buf[lastc] != ':')
6980 buf[lastc--] = '\0';
6981 if (lastc > 0 && buf[0] != '#' && buf[lastc] == ':') {
6982 buf[lastc] = '\0'; /* remove trailing : for comparison */
6983 if (custom_header_is_allowed(buf)) {
6985 extra_headers = g_slist_prepend(extra_headers, g_strdup(buf));
6988 g_message("disallowed extra header line: %s\n", buf);
6992 g_message("invalid extra header line: %s\n", buf);
6998 extra_headers = g_slist_prepend(extra_headers, g_strdup("")); /* end of list */
6999 extra_headers = g_slist_reverse(extra_headers);
7001 g_slist_foreach(extra_headers, (GFunc)compose_add_extra_header, (gpointer)model);
7004 static void compose_create_header_entry(Compose *compose)
7006 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
7013 const gchar *header = NULL;
7014 ComposeHeaderEntry *headerentry;
7015 gboolean standard_header = FALSE;
7016 GtkListStore *model;
7019 headerentry = g_new0(ComposeHeaderEntry, 1);
7021 /* Combo box model */
7022 model = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
7023 #if !GTK_CHECK_VERSION(2, 24, 0)
7024 combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
7026 COMBOBOX_ADD(model, prefs_common_translated_header_name("To:"),
7028 COMBOBOX_ADD(model, prefs_common_translated_header_name("Cc:"),
7030 COMBOBOX_ADD(model, prefs_common_translated_header_name("Bcc:"),
7032 COMBOBOX_ADD(model, prefs_common_translated_header_name("Newsgroups:"),
7033 COMPOSE_NEWSGROUPS);
7034 COMBOBOX_ADD(model, prefs_common_translated_header_name("Reply-To:"),
7036 COMBOBOX_ADD(model, prefs_common_translated_header_name("Followup-To:"),
7037 COMPOSE_FOLLOWUPTO);
7038 compose_add_extra_header_entries(model);
7041 #if GTK_CHECK_VERSION(2, 24, 0)
7042 combo = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(model));
7043 GtkCellRenderer *cell = gtk_cell_renderer_text_new();
7044 gtk_cell_renderer_set_alignment(cell, 0.0, 0.5);
7045 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
7046 gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(combo), 0);
7048 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
7049 g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN(combo))), "grab_focus",
7050 G_CALLBACK(compose_grab_focus_cb), compose);
7051 gtk_widget_show(combo);
7053 /* Putting only the combobox child into focus chain of its parent causes
7054 * the parent to be skipped when changing focus via Tab or Shift+Tab.
7055 * This eliminates need to pres Tab twice in order to really get from the
7056 * combobox to next widget. */
7058 l = g_list_prepend(l, gtk_bin_get_child(GTK_BIN(combo)));
7059 gtk_container_set_focus_chain(GTK_CONTAINER(combo), l);
7062 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1,
7063 compose->header_nextrow, compose->header_nextrow+1,
7064 GTK_SHRINK, GTK_FILL, 0, 0);
7065 if (compose->header_last && (compose->draft_timeout_tag != COMPOSE_DRAFT_TIMEOUT_FORBIDDEN)) {
7066 const gchar *last_header_entry = gtk_entry_get_text(
7067 GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))));
7069 while (*string != NULL) {
7070 if (!strcmp(prefs_common_translated_header_name(*string), last_header_entry))
7071 standard_header = TRUE;
7074 if (standard_header)
7075 header = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))));
7077 if (!compose->header_last || !standard_header) {
7078 switch(compose->account->protocol) {
7080 header = prefs_common_translated_header_name("Newsgroups:");
7083 header = prefs_common_translated_header_name("To:");
7088 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((combo)))), header);
7090 gtk_editable_set_editable(
7091 GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((combo)))),
7092 prefs_common.type_any_header);
7094 g_signal_connect_after(G_OBJECT(gtk_bin_get_child(GTK_BIN((combo)))), "grab_focus",
7095 G_CALLBACK(compose_grab_focus_cb), compose);
7097 /* Entry field with cleanup button */
7098 button = gtk_button_new();
7099 gtk_button_set_image(GTK_BUTTON(button),
7100 gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
7101 gtk_widget_show(button);
7102 CLAWS_SET_TIP(button,
7103 _("Delete entry contents"));
7104 entry = gtk_entry_new();
7105 gtk_widget_show(entry);
7106 CLAWS_SET_TIP(entry,
7107 _("Use <tab> to autocomplete from addressbook"));
7108 hbox = gtk_hbox_new (FALSE, 0);
7109 gtk_widget_show(hbox);
7110 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
7111 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
7112 gtk_table_attach(GTK_TABLE(compose->header_table), hbox, 1, 2,
7113 compose->header_nextrow, compose->header_nextrow+1,
7114 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
7116 g_signal_connect(G_OBJECT(entry), "key-press-event",
7117 G_CALLBACK(compose_headerentry_key_press_event_cb),
7119 g_signal_connect(G_OBJECT(entry), "changed",
7120 G_CALLBACK(compose_headerentry_changed_cb),
7122 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
7123 G_CALLBACK(compose_grab_focus_cb), compose);
7125 g_signal_connect(G_OBJECT(button), "clicked",
7126 G_CALLBACK(compose_headerentry_button_clicked_cb),
7130 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
7131 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
7132 GDK_ACTION_COPY | GDK_ACTION_MOVE);
7133 g_signal_connect(G_OBJECT(entry), "drag_data_received",
7134 G_CALLBACK(compose_header_drag_received_cb),
7136 g_signal_connect(G_OBJECT(entry), "drag-drop",
7137 G_CALLBACK(compose_drag_drop),
7139 g_signal_connect(G_OBJECT(entry), "populate-popup",
7140 G_CALLBACK(compose_entry_popup_extend),
7143 address_completion_register_entry(GTK_ENTRY(entry), TRUE);
7145 headerentry->compose = compose;
7146 headerentry->combo = combo;
7147 headerentry->entry = entry;
7148 headerentry->button = button;
7149 headerentry->hbox = hbox;
7150 headerentry->headernum = compose->header_nextrow;
7151 headerentry->type = PREF_NONE;
7153 compose->header_nextrow++;
7154 compose->header_last = headerentry;
7155 compose->header_list =
7156 g_slist_append(compose->header_list,
7160 static void compose_add_header_entry(Compose *compose, const gchar *header,
7161 gchar *text, ComposePrefType pref_type)
7163 ComposeHeaderEntry *last_header = compose->header_last;
7164 gchar *tmp = g_strdup(text), *email;
7165 gboolean replyto_hdr;
7167 replyto_hdr = (!strcasecmp(header,
7168 prefs_common_translated_header_name("Reply-To:")) ||
7170 prefs_common_translated_header_name("Followup-To:")) ||
7172 prefs_common_translated_header_name("In-Reply-To:")));
7174 extract_address(tmp);
7175 email = g_utf8_strdown(tmp, -1);
7177 if (replyto_hdr == FALSE &&
7178 g_hash_table_lookup(compose->email_hashtable, email) != NULL)
7180 debug_print("Ignoring duplicate address - %s %s, pref_type: %d\n",
7181 header, text, (gint) pref_type);
7187 if (!strcasecmp(header, prefs_common_translated_header_name("In-Reply-To:")))
7188 gtk_entry_set_text(GTK_ENTRY(
7189 gtk_bin_get_child(GTK_BIN(last_header->combo))), header);
7191 combobox_select_by_text(GTK_COMBO_BOX(last_header->combo), header);
7192 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
7193 last_header->type = pref_type;
7195 if (replyto_hdr == FALSE)
7196 g_hash_table_insert(compose->email_hashtable, email,
7197 GUINT_TO_POINTER(1));
7204 static void compose_destroy_headerentry(Compose *compose,
7205 ComposeHeaderEntry *headerentry)
7207 gchar *text = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
7210 extract_address(text);
7211 email = g_utf8_strdown(text, -1);
7212 g_hash_table_remove(compose->email_hashtable, email);
7216 gtk_widget_destroy(headerentry->combo);
7217 gtk_widget_destroy(headerentry->entry);
7218 gtk_widget_destroy(headerentry->button);
7219 gtk_widget_destroy(headerentry->hbox);
7220 g_free(headerentry);
7223 static void compose_remove_header_entries(Compose *compose)
7226 for (list = compose->header_list; list; list = list->next)
7227 compose_destroy_headerentry(compose, (ComposeHeaderEntry *)list->data);
7229 compose->header_last = NULL;
7230 g_slist_free(compose->header_list);
7231 compose->header_list = NULL;
7232 compose->header_nextrow = 1;
7233 compose_create_header_entry(compose);
7236 static GtkWidget *compose_create_header(Compose *compose)
7238 GtkWidget *from_optmenu_hbox;
7239 GtkWidget *header_table_main;
7240 GtkWidget *header_scrolledwin;
7241 GtkWidget *header_table;
7243 /* parent with account selection and from header */
7244 header_table_main = gtk_table_new(2, 2, FALSE);
7245 gtk_widget_show(header_table_main);
7246 gtk_container_set_border_width(GTK_CONTAINER(header_table_main), BORDER_WIDTH);
7248 from_optmenu_hbox = compose_account_option_menu_create(compose);
7249 gtk_table_attach(GTK_TABLE(header_table_main), from_optmenu_hbox,
7250 0, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
7252 /* child with header labels and entries */
7253 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
7254 gtk_widget_show(header_scrolledwin);
7255 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
7257 header_table = gtk_table_new(2, 2, FALSE);
7258 gtk_widget_show(header_table);
7259 gtk_container_set_border_width(GTK_CONTAINER(header_table), 0);
7260 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
7261 gtk_container_set_focus_vadjustment(GTK_CONTAINER(header_table),
7262 gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(header_scrolledwin)));
7263 gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_bin_get_child(GTK_BIN(header_scrolledwin))), GTK_SHADOW_NONE);
7265 gtk_table_attach(GTK_TABLE(header_table_main), header_scrolledwin,
7266 0, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 2);
7268 compose->header_table = header_table;
7269 compose->header_list = NULL;
7270 compose->header_nextrow = 0;
7272 compose_create_header_entry(compose);
7274 compose->table = NULL;
7276 return header_table_main;
7279 static gboolean popup_attach_button_pressed(GtkWidget *widget, gpointer data)
7281 Compose *compose = (Compose *)data;
7282 GdkEventButton event;
7285 event.time = gtk_get_current_event_time();
7287 return attach_button_pressed(compose->attach_clist, &event, compose);
7290 static GtkWidget *compose_create_attach(Compose *compose)
7292 GtkWidget *attach_scrwin;
7293 GtkWidget *attach_clist;
7295 GtkListStore *store;
7296 GtkCellRenderer *renderer;
7297 GtkTreeViewColumn *column;
7298 GtkTreeSelection *selection;
7300 /* attachment list */
7301 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
7302 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
7303 GTK_POLICY_AUTOMATIC,
7304 GTK_POLICY_AUTOMATIC);
7305 gtk_widget_set_size_request(attach_scrwin, -1, 80);
7307 store = gtk_list_store_new(N_ATTACH_COLS,
7313 G_TYPE_AUTO_POINTER,
7315 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
7316 (GTK_TREE_MODEL(store)));
7317 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
7318 g_object_unref(store);
7320 renderer = gtk_cell_renderer_text_new();
7321 column = gtk_tree_view_column_new_with_attributes
7322 (_("Mime type"), renderer, "text",
7323 COL_MIMETYPE, NULL);
7324 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
7326 renderer = gtk_cell_renderer_text_new();
7327 column = gtk_tree_view_column_new_with_attributes
7328 (_("Size"), renderer, "text",
7330 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
7332 renderer = gtk_cell_renderer_text_new();
7333 column = gtk_tree_view_column_new_with_attributes
7334 (_("Name"), renderer, "text",
7336 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
7338 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
7339 prefs_common.use_stripes_everywhere);
7340 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
7341 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
7343 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
7344 G_CALLBACK(attach_selected), compose);
7345 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
7346 G_CALLBACK(attach_button_pressed), compose);
7347 g_signal_connect(G_OBJECT(attach_clist), "popup-menu",
7348 G_CALLBACK(popup_attach_button_pressed), compose);
7349 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
7350 G_CALLBACK(attach_key_pressed), compose);
7353 gtk_drag_dest_set(attach_clist,
7354 GTK_DEST_DEFAULT_ALL, compose_mime_types,
7355 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
7356 GDK_ACTION_COPY | GDK_ACTION_MOVE);
7357 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
7358 G_CALLBACK(compose_attach_drag_received_cb),
7360 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
7361 G_CALLBACK(compose_drag_drop),
7364 compose->attach_scrwin = attach_scrwin;
7365 compose->attach_clist = attach_clist;
7367 return attach_scrwin;
7370 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
7371 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
7373 static GtkWidget *compose_create_others(Compose *compose)
7376 GtkWidget *savemsg_checkbtn;
7377 GtkWidget *savemsg_combo;
7378 GtkWidget *savemsg_select;
7381 gchar *folderidentifier;
7383 /* Table for settings */
7384 table = gtk_table_new(3, 1, FALSE);
7385 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
7386 gtk_widget_show(table);
7387 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
7390 /* Save Message to folder */
7391 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
7392 gtk_widget_show(savemsg_checkbtn);
7393 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
7394 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7395 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
7397 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
7398 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7400 #if !GTK_CHECK_VERSION(2, 24, 0)
7401 savemsg_combo = gtk_combo_box_entry_new_text();
7403 savemsg_combo = gtk_combo_box_text_new_with_entry();
7405 compose->savemsg_checkbtn = savemsg_checkbtn;
7406 compose->savemsg_combo = savemsg_combo;
7407 gtk_widget_show(savemsg_combo);
7409 if (prefs_common.compose_save_to_history)
7410 #if !GTK_CHECK_VERSION(2, 24, 0)
7411 combobox_set_popdown_strings(GTK_COMBO_BOX(savemsg_combo),
7412 prefs_common.compose_save_to_history);
7414 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(savemsg_combo),
7415 prefs_common.compose_save_to_history);
7417 gtk_table_attach(GTK_TABLE(table), savemsg_combo, 1, 2, rowcount, rowcount + 1, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
7418 gtk_widget_set_sensitive(GTK_WIDGET(savemsg_combo), prefs_common.savemsg);
7419 g_signal_connect_after(G_OBJECT(savemsg_combo), "grab_focus",
7420 G_CALLBACK(compose_grab_focus_cb), compose);
7421 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7422 folderidentifier = folder_item_get_identifier(account_get_special_folder
7423 (compose->account, F_OUTBOX));
7424 compose_set_save_to(compose, folderidentifier);
7425 g_free(folderidentifier);
7428 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
7429 gtk_widget_show(savemsg_select);
7430 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
7431 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
7432 G_CALLBACK(compose_savemsg_select_cb),
7438 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
7440 gtk_widget_set_sensitive(GTK_WIDGET(compose->savemsg_combo),
7441 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
7444 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
7449 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE,
7450 _("Select folder to save message to"));
7453 path = folder_item_get_identifier(dest);
7455 compose_set_save_to(compose, path);
7459 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
7460 GdkAtom clip, GtkTextIter *insert_place);
7463 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
7467 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7469 if (event->button == 3) {
7471 GtkTextIter sel_start, sel_end;
7472 gboolean stuff_selected;
7474 /* move the cursor to allow GtkAspell to check the word
7475 * under the mouse */
7476 if (event->x && event->y) {
7477 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
7478 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
7480 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
7483 GtkTextMark *mark = gtk_text_buffer_get_insert(buffer);
7484 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
7487 stuff_selected = gtk_text_buffer_get_selection_bounds(
7489 &sel_start, &sel_end);
7491 gtk_text_buffer_place_cursor (buffer, &iter);
7492 /* reselect stuff */
7494 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
7495 gtk_text_buffer_select_range(buffer,
7496 &sel_start, &sel_end);
7498 return FALSE; /* pass the event so that the right-click goes through */
7501 if (event->button == 2) {
7506 /* get the middle-click position to paste at the correct place */
7507 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
7508 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
7510 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
7513 entry_paste_clipboard(compose, text,
7514 prefs_common.linewrap_pastes,
7515 GDK_SELECTION_PRIMARY, &iter);
7523 static void compose_spell_menu_changed(void *data)
7525 Compose *compose = (Compose *)data;
7527 GtkWidget *menuitem;
7528 GtkWidget *parent_item;
7529 GtkMenu *menu = GTK_MENU(gtk_menu_new());
7532 if (compose->gtkaspell == NULL)
7535 parent_item = gtk_ui_manager_get_widget(compose->ui_manager,
7536 "/Menu/Spelling/Options");
7538 /* setting the submenu removes /Spelling/Options from the factory
7539 * so we need to save it */
7541 if (parent_item == NULL) {
7542 parent_item = compose->aspell_options_menu;
7543 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), NULL);
7545 compose->aspell_options_menu = parent_item;
7547 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
7549 spell_menu = g_slist_reverse(spell_menu);
7550 for (items = spell_menu;
7551 items; items = items->next) {
7552 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
7553 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
7554 gtk_widget_show(GTK_WIDGET(menuitem));
7556 g_slist_free(spell_menu);
7558 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
7559 gtk_widget_show(parent_item);
7562 static void compose_dict_changed(void *data)
7564 Compose *compose = (Compose *) data;
7566 if(!compose->gtkaspell)
7568 if(compose->gtkaspell->recheck_when_changing_dict == FALSE)
7571 gtkaspell_highlight_all(compose->gtkaspell);
7572 claws_spell_entry_recheck_all(CLAWS_SPELL_ENTRY(compose->subject_entry));
7576 static gboolean compose_popup_menu(GtkWidget *widget, gpointer data)
7578 Compose *compose = (Compose *)data;
7579 GdkEventButton event;
7582 event.time = gtk_get_current_event_time();
7586 return text_clicked(compose->text, &event, compose);
7589 static gboolean compose_force_window_origin = TRUE;
7590 static Compose *compose_create(PrefsAccount *account,
7599 GtkWidget *handlebox;
7601 GtkWidget *notebook;
7603 GtkWidget *attach_hbox;
7604 GtkWidget *attach_lab1;
7605 GtkWidget *attach_lab2;
7610 GtkWidget *subject_hbox;
7611 GtkWidget *subject_frame;
7612 GtkWidget *subject_entry;
7616 GtkWidget *edit_vbox;
7617 GtkWidget *ruler_hbox;
7619 GtkWidget *scrolledwin;
7621 GtkTextBuffer *buffer;
7622 GtkClipboard *clipboard;
7624 UndoMain *undostruct;
7626 GtkWidget *popupmenu;
7627 GtkWidget *tmpl_menu;
7628 GtkActionGroup *action_group = NULL;
7631 GtkAspell * gtkaspell = NULL;
7634 static GdkGeometry geometry;
7636 cm_return_val_if_fail(account != NULL, NULL);
7638 gtkut_convert_int_to_gdk_color(prefs_common.default_header_bgcolor,
7639 &default_header_bgcolor);
7640 gtkut_convert_int_to_gdk_color(prefs_common.default_header_color,
7641 &default_header_color);
7643 debug_print("Creating compose window...\n");
7644 compose = g_new0(Compose, 1);
7646 compose->batch = batch;
7647 compose->account = account;
7648 compose->folder = folder;
7650 compose->mutex = cm_mutex_new();
7651 compose->set_cursor_pos = -1;
7653 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose");
7655 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
7656 gtk_widget_set_size_request(window, prefs_common.compose_width,
7657 prefs_common.compose_height);
7659 if (!geometry.max_width) {
7660 geometry.max_width = gdk_screen_width();
7661 geometry.max_height = gdk_screen_height();
7664 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
7665 &geometry, GDK_HINT_MAX_SIZE);
7666 if (!geometry.min_width) {
7667 geometry.min_width = 600;
7668 geometry.min_height = 440;
7670 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
7671 &geometry, GDK_HINT_MIN_SIZE);
7673 #ifndef GENERIC_UMPC
7674 if (compose_force_window_origin)
7675 gtk_window_move(GTK_WINDOW(window), prefs_common.compose_x,
7676 prefs_common.compose_y);
7678 g_signal_connect(G_OBJECT(window), "delete_event",
7679 G_CALLBACK(compose_delete_cb), compose);
7680 MANAGE_WINDOW_SIGNALS_CONNECT(window);
7681 gtk_widget_realize(window);
7683 gtkut_widget_set_composer_icon(window);
7685 vbox = gtk_vbox_new(FALSE, 0);
7686 gtk_container_add(GTK_CONTAINER(window), vbox);
7688 compose->ui_manager = gtk_ui_manager_new();
7689 action_group = cm_menu_create_action_group_full(compose->ui_manager,"Menu", compose_entries,
7690 G_N_ELEMENTS(compose_entries), (gpointer)compose);
7691 gtk_action_group_add_toggle_actions(action_group, compose_toggle_entries,
7692 G_N_ELEMENTS(compose_toggle_entries), (gpointer)compose);
7693 gtk_action_group_add_radio_actions(action_group, compose_radio_rm_entries,
7694 G_N_ELEMENTS(compose_radio_rm_entries), COMPOSE_REPLY, G_CALLBACK(compose_reply_change_mode_cb), (gpointer)compose);
7695 gtk_action_group_add_radio_actions(action_group, compose_radio_prio_entries,
7696 G_N_ELEMENTS(compose_radio_prio_entries), PRIORITY_NORMAL, G_CALLBACK(compose_set_priority_cb), (gpointer)compose);
7697 gtk_action_group_add_radio_actions(action_group, compose_radio_enc_entries,
7698 G_N_ELEMENTS(compose_radio_enc_entries), C_AUTO, G_CALLBACK(compose_set_encoding_cb), (gpointer)compose);
7700 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENUBAR)
7702 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Message", "Message", GTK_UI_MANAGER_MENU)
7703 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Edit", "Edit", GTK_UI_MANAGER_MENU)
7705 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Spelling", "Spelling", GTK_UI_MANAGER_MENU)
7707 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Options", "Options", GTK_UI_MANAGER_MENU)
7708 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Tools", "Tools", GTK_UI_MANAGER_MENU)
7709 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Help", "Help", GTK_UI_MANAGER_MENU)
7712 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Send", "Message/Send", GTK_UI_MANAGER_MENUITEM)
7713 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "SendLater", "Message/SendLater", GTK_UI_MANAGER_MENUITEM)
7714 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
7715 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "AttachFile", "Message/AttachFile", GTK_UI_MANAGER_MENUITEM)
7716 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "InsertFile", "Message/InsertFile", GTK_UI_MANAGER_MENUITEM)
7717 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "InsertSig", "Message/InsertSig", GTK_UI_MANAGER_MENUITEM)
7718 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "ReplaceSig", "Message/ReplaceSig", GTK_UI_MANAGER_MENUITEM)
7719 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
7720 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Save", "Message/Save", GTK_UI_MANAGER_MENUITEM)
7721 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Separator3", "Message/---", GTK_UI_MANAGER_SEPARATOR)
7722 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Print", "Message/Print", GTK_UI_MANAGER_MENUITEM)
7723 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Separator4", "Message/---", GTK_UI_MANAGER_SEPARATOR)
7724 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Close", "Message/Close", GTK_UI_MANAGER_MENUITEM)
7727 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Undo", "Edit/Undo", GTK_UI_MANAGER_MENUITEM)
7728 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Redo", "Edit/Redo", GTK_UI_MANAGER_MENUITEM)
7729 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Separator1", "Edit/---", GTK_UI_MANAGER_SEPARATOR)
7731 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Cut", "Edit/Cut", GTK_UI_MANAGER_MENUITEM)
7732 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Copy", "Edit/Copy", GTK_UI_MANAGER_MENUITEM)
7733 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Paste", "Edit/Paste", GTK_UI_MANAGER_MENUITEM)
7735 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "SpecialPaste", "Edit/SpecialPaste", GTK_UI_MANAGER_MENU)
7736 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/SpecialPaste", "AsQuotation", "Edit/SpecialPaste/AsQuotation", GTK_UI_MANAGER_MENUITEM)
7737 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/SpecialPaste", "Wrapped", "Edit/SpecialPaste/Wrapped", GTK_UI_MANAGER_MENUITEM)
7738 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/SpecialPaste", "Unwrapped", "Edit/SpecialPaste/Unwrapped", GTK_UI_MANAGER_MENUITEM)
7740 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "SelectAll", "Edit/SelectAll", GTK_UI_MANAGER_MENUITEM)
7742 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Advanced", "Edit/Advanced", GTK_UI_MANAGER_MENU)
7743 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "BackChar", "Edit/Advanced/BackChar", GTK_UI_MANAGER_MENUITEM)
7744 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "ForwChar", "Edit/Advanced/ForwChar", GTK_UI_MANAGER_MENUITEM)
7745 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "BackWord", "Edit/Advanced/BackWord", GTK_UI_MANAGER_MENUITEM)
7746 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "ForwWord", "Edit/Advanced/ForwWord", GTK_UI_MANAGER_MENUITEM)
7747 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "BegLine", "Edit/Advanced/BegLine", GTK_UI_MANAGER_MENUITEM)
7748 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "EndLine", "Edit/Advanced/EndLine", GTK_UI_MANAGER_MENUITEM)
7749 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "PrevLine", "Edit/Advanced/PrevLine", GTK_UI_MANAGER_MENUITEM)
7750 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "NextLine", "Edit/Advanced/NextLine", GTK_UI_MANAGER_MENUITEM)
7751 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "DelBackChar", "Edit/Advanced/DelBackChar", GTK_UI_MANAGER_MENUITEM)
7752 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "DelForwChar", "Edit/Advanced/DelForwChar", GTK_UI_MANAGER_MENUITEM)
7753 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "DelBackWord", "Edit/Advanced/DelBackWord", GTK_UI_MANAGER_MENUITEM)
7754 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "DelForwWord", "Edit/Advanced/DelForwWord", GTK_UI_MANAGER_MENUITEM)
7755 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "DelLine", "Edit/Advanced/DelLine", GTK_UI_MANAGER_MENUITEM)
7756 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit/Advanced", "DelEndLine", "Edit/Advanced/DelEndLine", GTK_UI_MANAGER_MENUITEM)
7758 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Separator2", "Edit/---", GTK_UI_MANAGER_SEPARATOR)
7760 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Find", "Edit/Find", GTK_UI_MANAGER_MENUITEM)
7761 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "WrapPara", "Edit/WrapPara", GTK_UI_MANAGER_MENUITEM)
7762 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "WrapAllLines", "Edit/WrapAllLines", GTK_UI_MANAGER_MENUITEM)
7763 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "AutoWrap", "Edit/AutoWrap", GTK_UI_MANAGER_MENUITEM)
7764 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "AutoIndent", "Edit/AutoIndent", GTK_UI_MANAGER_MENUITEM)
7766 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Separator3", "Edit/---", GTK_UI_MANAGER_SEPARATOR)
7768 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "ExtEditor", "Edit/ExtEditor", GTK_UI_MANAGER_MENUITEM)
7772 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Spelling", "CheckAllSel", "Spelling/CheckAllSel", GTK_UI_MANAGER_MENUITEM)
7773 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Spelling", "HighlightAll", "Spelling/HighlightAll", GTK_UI_MANAGER_MENUITEM)
7774 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Spelling", "CheckBackwards", "Spelling/CheckBackwards", GTK_UI_MANAGER_MENUITEM)
7775 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Spelling", "ForwardNext", "Spelling/ForwardNext", GTK_UI_MANAGER_MENUITEM)
7776 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Spelling", "Separator1", "Spelling/---", GTK_UI_MANAGER_SEPARATOR)
7777 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Spelling", "Options", "Spelling/Options", GTK_UI_MANAGER_MENU)
7781 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "ReplyMode", "Options/ReplyMode", GTK_UI_MANAGER_MENU)
7782 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/ReplyMode", "Normal", "Options/ReplyMode/Normal", GTK_UI_MANAGER_MENUITEM)
7783 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/ReplyMode", "All", "Options/ReplyMode/All", GTK_UI_MANAGER_MENUITEM)
7784 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/ReplyMode", "Sender", "Options/ReplyMode/Sender", GTK_UI_MANAGER_MENUITEM)
7785 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/ReplyMode", "List", "Options/ReplyMode/List", GTK_UI_MANAGER_MENUITEM)
7787 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Separator1", "Options/---", GTK_UI_MANAGER_SEPARATOR)
7788 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "PrivacySystem", "Options/PrivacySystem", GTK_UI_MANAGER_MENU)
7789 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/PrivacySystem", "PlaceHolder", "Options/PrivacySystem/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
7790 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Sign", "Options/Sign", GTK_UI_MANAGER_MENUITEM)
7791 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Encrypt", "Options/Encrypt", GTK_UI_MANAGER_MENUITEM)
7794 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Separator2", "Options/---", GTK_UI_MANAGER_SEPARATOR)
7795 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Priority", "Options/Priority", GTK_UI_MANAGER_MENU)
7796 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Priority", "Highest", "Options/Priority/Highest", GTK_UI_MANAGER_MENUITEM)
7797 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Priority", "High", "Options/Priority/High", GTK_UI_MANAGER_MENUITEM)
7798 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Priority", "Normal", "Options/Priority/Normal", GTK_UI_MANAGER_MENUITEM)
7799 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Priority", "Low", "Options/Priority/Low", GTK_UI_MANAGER_MENUITEM)
7800 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Priority", "Lowest", "Options/Priority/Lowest", GTK_UI_MANAGER_MENUITEM)
7802 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Separator3", "Options/---", GTK_UI_MANAGER_SEPARATOR)
7803 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "RequestRetRcpt", "Options/RequestRetRcpt", GTK_UI_MANAGER_MENUITEM)
7804 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Separator4", "Options/---", GTK_UI_MANAGER_SEPARATOR)
7805 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "RemoveReferences", "Options/RemoveReferences", GTK_UI_MANAGER_MENUITEM)
7806 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Separator5", "Options/---", GTK_UI_MANAGER_SEPARATOR)
7808 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Encoding", "Options/Encoding", GTK_UI_MANAGER_MENU)
7810 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", CS_AUTO, "Options/Encoding/"CS_AUTO, GTK_UI_MANAGER_MENUITEM)
7811 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Separator1", "Options/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
7812 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", CS_US_ASCII, "Options/Encoding/"CS_US_ASCII, GTK_UI_MANAGER_MENUITEM)
7813 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", CS_UTF_8, "Options/Encoding/"CS_UTF_8, GTK_UI_MANAGER_MENUITEM)
7814 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Separator2", "Options/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
7816 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Western", "Options/Encoding/Western", GTK_UI_MANAGER_MENU)
7817 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Western", CS_ISO_8859_1, "Options/Encoding/Western/"CS_ISO_8859_1, GTK_UI_MANAGER_MENUITEM)
7818 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Western", CS_ISO_8859_15, "Options/Encoding/Western/"CS_ISO_8859_15, GTK_UI_MANAGER_MENUITEM)
7819 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Western", CS_WINDOWS_1252, "Options/Encoding/Western/"CS_WINDOWS_1252, GTK_UI_MANAGER_MENUITEM)
7821 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", CS_ISO_8859_2, "Options/Encoding/"CS_ISO_8859_2, GTK_UI_MANAGER_MENUITEM)
7823 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Baltic", "Options/Encoding/Baltic", GTK_UI_MANAGER_MENU)
7824 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Baltic", CS_ISO_8859_13, "Options/Encoding/Baltic/"CS_ISO_8859_13, GTK_UI_MANAGER_MENUITEM)
7825 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Baltic", CS_ISO_8859_4, "Options/Encoding/Baltic/"CS_ISO_8859_4, GTK_UI_MANAGER_MENUITEM)
7827 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", CS_ISO_8859_7, "Options/Encoding/"CS_ISO_8859_7, GTK_UI_MANAGER_MENUITEM)
7829 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Hebrew", "Options/Encoding/Hebrew", GTK_UI_MANAGER_MENU)
7830 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Hebrew", CS_ISO_8859_8, "Options/Encoding/Hebrew/"CS_ISO_8859_8, GTK_UI_MANAGER_MENUITEM)
7831 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Hebrew", CS_WINDOWS_1255, "Options/Encoding/Hebrew/"CS_WINDOWS_1255, GTK_UI_MANAGER_MENUITEM)
7833 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Arabic", "Options/Encoding/Arabic", GTK_UI_MANAGER_MENU)
7834 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Arabic", CS_ISO_8859_6, "Options/Encoding/Arabic/"CS_ISO_8859_6, GTK_UI_MANAGER_MENUITEM)
7835 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Arabic", CS_WINDOWS_1256, "Options/Encoding/Arabic/"CS_WINDOWS_1256, GTK_UI_MANAGER_MENUITEM)
7837 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", CS_ISO_8859_9, "Options/Encoding/"CS_ISO_8859_9, GTK_UI_MANAGER_MENUITEM)
7839 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Cyrillic", "Options/Encoding/Cyrillic", GTK_UI_MANAGER_MENU)
7840 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_ISO_8859_5, "Options/Encoding/Cyrillic/"CS_ISO_8859_5, GTK_UI_MANAGER_MENUITEM)
7841 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_KOI8_R, "Options/Encoding/Cyrillic/"CS_KOI8_R, GTK_UI_MANAGER_MENUITEM)
7842 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_MACCYR, "Options/Encoding/Cyrillic/"CS_MACCYR, GTK_UI_MANAGER_MENUITEM)
7843 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_KOI8_U, "Options/Encoding/Cyrillic/"CS_KOI8_U, GTK_UI_MANAGER_MENUITEM)
7844 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_WINDOWS_1251, "Options/Encoding/Cyrillic/"CS_WINDOWS_1251, GTK_UI_MANAGER_MENUITEM)
7846 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Japanese", "Options/Encoding/Japanese", GTK_UI_MANAGER_MENU)
7847 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Japanese", CS_ISO_2022_JP, "Options/Encoding/Japanese/"CS_ISO_2022_JP, GTK_UI_MANAGER_MENUITEM)
7848 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Japanese", CS_ISO_2022_JP_2, "Options/Encoding/Japanese/"CS_ISO_2022_JP_2, GTK_UI_MANAGER_MENUITEM)
7849 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Japanese", CS_EUC_JP, "Options/Encoding/Japanese/"CS_EUC_JP, GTK_UI_MANAGER_MENUITEM)
7850 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Japanese", CS_SHIFT_JIS, "Options/Encoding/Japanese/"CS_SHIFT_JIS, GTK_UI_MANAGER_MENUITEM)
7852 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Chinese", "Options/Encoding/Chinese", GTK_UI_MANAGER_MENU)
7853 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_GB18030, "Options/Encoding/Chinese/"CS_GB18030, GTK_UI_MANAGER_MENUITEM)
7854 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_GB2312, "Options/Encoding/Chinese/"CS_GB2312, GTK_UI_MANAGER_MENUITEM)
7855 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_GBK, "Options/Encoding/Chinese/"CS_GBK, GTK_UI_MANAGER_MENUITEM)
7856 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_BIG5, "Options/Encoding/Chinese/"CS_BIG5, GTK_UI_MANAGER_MENUITEM)
7857 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_EUC_TW, "Options/Encoding/Chinese/"CS_EUC_TW, GTK_UI_MANAGER_MENUITEM)
7859 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Korean", "Options/Encoding/Korean", GTK_UI_MANAGER_MENU)
7860 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Korean", CS_EUC_KR, "Options/Encoding/Korean/"CS_EUC_KR, GTK_UI_MANAGER_MENUITEM)
7861 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Korean", CS_ISO_2022_KR, "Options/Encoding/Korean/"CS_ISO_2022_KR, GTK_UI_MANAGER_MENUITEM)
7863 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Thai", "Options/Encoding/Thai", GTK_UI_MANAGER_MENU)
7864 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Thai", CS_TIS_620, "Options/Encoding/Thai/"CS_TIS_620, GTK_UI_MANAGER_MENUITEM)
7865 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Thai", CS_WINDOWS_874, "Options/Encoding/Thai/"CS_WINDOWS_874, GTK_UI_MANAGER_MENUITEM)
7869 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools", "ShowRuler", "Tools/ShowRuler", GTK_UI_MANAGER_MENUITEM)
7870 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools", "AddressBook", "Tools/AddressBook", GTK_UI_MANAGER_MENUITEM)
7871 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools", "Template", "Tools/Template", GTK_UI_MANAGER_MENU)
7872 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools/Template", "PlaceHolder", "Tools/Template/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
7873 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools", "Actions", "Tools/Actions", GTK_UI_MANAGER_MENU)
7874 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools/Actions", "PlaceHolder", "Tools/Actions/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
7877 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Help", "About", "Help/About", GTK_UI_MANAGER_MENUITEM)
7879 menubar = gtk_ui_manager_get_widget(compose->ui_manager, "/Menu");
7880 gtk_widget_show_all(menubar);
7882 gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(compose->ui_manager));
7883 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
7885 if (prefs_common.toolbar_detachable) {
7886 handlebox = gtk_handle_box_new();
7888 handlebox = gtk_hbox_new(FALSE, 0);
7890 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
7892 gtk_widget_realize(handlebox);
7893 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
7896 vbox2 = gtk_vbox_new(FALSE, 2);
7897 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
7898 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
7901 notebook = gtk_notebook_new();
7902 gtk_widget_show(notebook);
7904 /* header labels and entries */
7905 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
7906 compose_create_header(compose),
7907 gtk_label_new_with_mnemonic(_("Hea_der")));
7908 /* attachment list */
7909 attach_hbox = gtk_hbox_new(FALSE, 0);
7910 gtk_widget_show(attach_hbox);
7912 attach_lab1 = gtk_label_new_with_mnemonic(_("_Attachments"));
7913 gtk_widget_show(attach_lab1);
7914 gtk_box_pack_start(GTK_BOX(attach_hbox), attach_lab1, TRUE, TRUE, 0);
7916 attach_lab2 = gtk_label_new("");
7917 gtk_widget_show(attach_lab2);
7918 gtk_box_pack_start(GTK_BOX(attach_hbox), attach_lab2, FALSE, FALSE, 0);
7920 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
7921 compose_create_attach(compose),
7924 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
7925 compose_create_others(compose),
7926 gtk_label_new_with_mnemonic(_("Othe_rs")));
7929 subject_hbox = gtk_hbox_new(FALSE, 0);
7930 gtk_widget_show(subject_hbox);
7932 subject_frame = gtk_frame_new(NULL);
7933 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
7934 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
7935 gtk_widget_show(subject_frame);
7937 subject = gtk_hbox_new(FALSE, HSPACING_NARROW);
7938 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
7939 gtk_widget_show(subject);
7941 label = gtk_label_new_with_mnemonic(_("S_ubject:"));
7942 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
7943 gtk_widget_show(label);
7946 subject_entry = claws_spell_entry_new();
7948 subject_entry = gtk_entry_new();
7950 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
7951 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
7952 G_CALLBACK(compose_grab_focus_cb), compose);
7953 gtk_label_set_mnemonic_widget(GTK_LABEL(label), subject_entry);
7954 gtk_widget_show(subject_entry);
7955 compose->subject_entry = subject_entry;
7956 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
7958 edit_vbox = gtk_vbox_new(FALSE, 0);
7960 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
7963 ruler_hbox = gtk_hbox_new(FALSE, 0);
7964 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
7966 ruler = gtk_shruler_new(GTK_ORIENTATION_HORIZONTAL);
7967 gtk_shruler_set_range(GTK_SHRULER(ruler), 0.0, 100.0, 1.0);
7968 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
7972 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
7973 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
7974 GTK_POLICY_AUTOMATIC,
7975 GTK_POLICY_AUTOMATIC);
7976 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
7978 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
7980 text = gtk_text_view_new();
7981 if (prefs_common.show_compose_margin) {
7982 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
7983 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
7985 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7986 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
7987 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
7988 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
7989 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
7991 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
7992 g_signal_connect_after(G_OBJECT(text), "size_allocate",
7993 G_CALLBACK(compose_edit_size_alloc),
7995 g_signal_connect(G_OBJECT(buffer), "changed",
7996 G_CALLBACK(compose_changed_cb), compose);
7997 g_signal_connect(G_OBJECT(text), "grab_focus",
7998 G_CALLBACK(compose_grab_focus_cb), compose);
7999 g_signal_connect(G_OBJECT(buffer), "insert_text",
8000 G_CALLBACK(text_inserted), compose);
8001 g_signal_connect(G_OBJECT(text), "button_press_event",
8002 G_CALLBACK(text_clicked), compose);
8003 g_signal_connect(G_OBJECT(text), "popup-menu",
8004 G_CALLBACK(compose_popup_menu), compose);
8005 g_signal_connect(G_OBJECT(subject_entry), "changed",
8006 G_CALLBACK(compose_changed_cb), compose);
8007 g_signal_connect(G_OBJECT(subject_entry), "activate",
8008 G_CALLBACK(compose_subject_entry_activated), compose);
8011 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
8012 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
8013 GDK_ACTION_COPY | GDK_ACTION_MOVE);
8014 g_signal_connect(G_OBJECT(text), "drag_data_received",
8015 G_CALLBACK(compose_insert_drag_received_cb),
8017 g_signal_connect(G_OBJECT(text), "drag-drop",
8018 G_CALLBACK(compose_drag_drop),
8020 g_signal_connect(G_OBJECT(text), "key-press-event",
8021 G_CALLBACK(completion_set_focus_to_subject),
8023 gtk_widget_show_all(vbox);
8025 /* pane between attach clist and text */
8026 paned = gtk_vpaned_new();
8027 gtk_container_add(GTK_CONTAINER(vbox2), paned);
8028 gtk_paned_pack1(GTK_PANED(paned), notebook, FALSE, FALSE);
8029 gtk_paned_pack2(GTK_PANED(paned), edit_vbox, TRUE, FALSE);
8030 gtk_paned_set_position(GTK_PANED(paned), prefs_common.compose_notebook_height);
8031 g_signal_connect(G_OBJECT(notebook), "size_allocate",
8032 G_CALLBACK(compose_notebook_size_alloc), paned);
8034 gtk_widget_show_all(paned);
8037 if (prefs_common.textfont) {
8038 PangoFontDescription *font_desc;
8040 font_desc = pango_font_description_from_string
8041 (prefs_common.textfont);
8043 gtk_widget_modify_font(text, font_desc);
8044 pango_font_description_free(font_desc);
8048 gtk_action_group_add_actions(action_group, compose_popup_entries,
8049 G_N_ELEMENTS(compose_popup_entries), (gpointer)compose);
8050 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/", "Popup", NULL, GTK_UI_MANAGER_MENUBAR)
8051 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Popup", "Compose", "Compose", GTK_UI_MANAGER_MENU)
8052 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Popup/Compose", "Add", "Compose/Add", GTK_UI_MANAGER_MENUITEM)
8053 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Popup/Compose", "Remove", "Compose/Remove", GTK_UI_MANAGER_MENUITEM)
8054 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Popup/Compose", "Separator1", "Compose/---", GTK_UI_MANAGER_SEPARATOR)
8055 MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Popup/Compose", "Properties", "Compose/Properties", GTK_UI_MANAGER_MENUITEM)
8057 popupmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(gtk_ui_manager_get_widget(compose->ui_manager, "/Popup/Compose")));
8059 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Undo", FALSE);
8060 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Redo", FALSE);
8061 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/RemoveReferences", FALSE);
8063 tmpl_menu = gtk_ui_manager_get_widget(compose->ui_manager, "/Menu/Tools/Template");
8065 undostruct = undo_init(text);
8066 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
8069 address_completion_start(window);
8071 compose->window = window;
8072 compose->vbox = vbox;
8073 compose->menubar = menubar;
8074 compose->handlebox = handlebox;
8076 compose->vbox2 = vbox2;
8078 compose->paned = paned;
8080 compose->attach_label = attach_lab2;
8082 compose->notebook = notebook;
8083 compose->edit_vbox = edit_vbox;
8084 compose->ruler_hbox = ruler_hbox;
8085 compose->ruler = ruler;
8086 compose->scrolledwin = scrolledwin;
8087 compose->text = text;
8089 compose->focused_editable = NULL;
8091 compose->popupmenu = popupmenu;
8093 compose->tmpl_menu = tmpl_menu;
8095 compose->mode = mode;
8096 compose->rmode = mode;
8098 compose->targetinfo = NULL;
8099 compose->replyinfo = NULL;
8100 compose->fwdinfo = NULL;
8102 compose->email_hashtable = g_hash_table_new_full(g_str_hash,
8103 g_str_equal, (GDestroyNotify) g_free, NULL);
8105 compose->replyto = NULL;
8107 compose->bcc = NULL;
8108 compose->followup_to = NULL;
8110 compose->ml_post = NULL;
8112 compose->inreplyto = NULL;
8113 compose->references = NULL;
8114 compose->msgid = NULL;
8115 compose->boundary = NULL;
8117 compose->autowrap = prefs_common.autowrap;
8118 compose->autoindent = prefs_common.auto_indent;
8119 compose->use_signing = FALSE;
8120 compose->use_encryption = FALSE;
8121 compose->privacy_system = NULL;
8122 compose->encdata = NULL;
8124 compose->modified = FALSE;
8126 compose->return_receipt = FALSE;
8128 compose->to_list = NULL;
8129 compose->newsgroup_list = NULL;
8131 compose->undostruct = undostruct;
8133 compose->sig_str = NULL;
8135 compose->exteditor_file = NULL;
8136 compose->exteditor_pid = -1;
8137 compose->exteditor_tag = -1;
8138 compose->exteditor_socket = NULL;
8139 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_FORBIDDEN; /* inhibit auto-drafting while loading */
8141 compose->folder_update_callback_id =
8142 hooks_register_hook(FOLDER_UPDATE_HOOKLIST,
8143 compose_update_folder_hook,
8144 (gpointer) compose);
8147 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", FALSE);
8148 if (mode != COMPOSE_REDIRECT) {
8149 if (prefs_common.enable_aspell && prefs_common.dictionary &&
8150 strcmp(prefs_common.dictionary, "")) {
8151 gtkaspell = gtkaspell_new(prefs_common.dictionary,
8152 prefs_common.alt_dictionary,
8153 conv_get_locale_charset_str(),
8154 prefs_common.misspelled_col,
8155 prefs_common.check_while_typing,
8156 prefs_common.recheck_when_changing_dict,
8157 prefs_common.use_alternate,
8158 prefs_common.use_both_dicts,
8159 GTK_TEXT_VIEW(text),
8160 GTK_WINDOW(compose->window),
8161 compose_dict_changed,
8162 compose_spell_menu_changed,
8165 alertpanel_error(_("Spell checker could not "
8167 gtkaspell_checkers_strerror());
8168 gtkaspell_checkers_reset_error();
8170 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", TRUE);
8174 compose->gtkaspell = gtkaspell;
8175 compose_spell_menu_changed(compose);
8176 claws_spell_entry_set_gtkaspell(CLAWS_SPELL_ENTRY(subject_entry), gtkaspell);
8179 compose_select_account(compose, account, TRUE);
8181 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoWrap", prefs_common.autowrap);
8182 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoIndent", prefs_common.auto_indent);
8184 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
8185 compose_entry_append(compose, account->auto_cc, COMPOSE_CC, PREF_ACCOUNT);
8187 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
8188 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC, PREF_ACCOUNT);
8190 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
8191 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO, PREF_ACCOUNT);
8193 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/ReplyMode", compose->mode == COMPOSE_REPLY);
8194 if (account->protocol != A_NNTP)
8195 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))),
8196 prefs_common_translated_header_name("To:"));
8198 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))),
8199 prefs_common_translated_header_name("Newsgroups:"));
8201 #ifndef USE_ALT_ADDRBOOK
8202 addressbook_set_target_compose(compose);
8204 if (mode != COMPOSE_REDIRECT)
8205 compose_set_template_menu(compose);
8207 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools/Template", FALSE);
8210 compose_list = g_list_append(compose_list, compose);
8212 if (!prefs_common.show_ruler)
8213 gtk_widget_hide(ruler_hbox);
8215 cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Tools/ShowRuler", prefs_common.show_ruler);
8218 compose->priority = PRIORITY_NORMAL;
8219 compose_update_priority_menu_item(compose);
8221 compose_set_out_encoding(compose);
8224 compose_update_actions_menu(compose);
8226 /* Privacy Systems menu */
8227 compose_update_privacy_systems_menu(compose);
8229 activate_privacy_system(compose, account, TRUE);
8230 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
8232 gtk_widget_realize(window);
8234 gtk_widget_show(window);
8240 static GtkWidget *compose_account_option_menu_create(Compose *compose)
8245 GtkWidget *optmenubox;
8246 GtkWidget *fromlabel;
8249 GtkWidget *from_name = NULL;
8251 gint num = 0, def_menu = 0;
8253 accounts = account_get_list();
8254 cm_return_val_if_fail(accounts != NULL, NULL);
8256 optmenubox = gtk_event_box_new();
8257 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
8258 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
8260 hbox = gtk_hbox_new(FALSE, 4);
8261 from_name = gtk_entry_new();
8263 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
8264 G_CALLBACK(compose_grab_focus_cb), compose);
8265 g_signal_connect_after(G_OBJECT(from_name), "activate",
8266 G_CALLBACK(from_name_activate_cb), optmenu);
8268 for (; accounts != NULL; accounts = accounts->next, num++) {
8269 PrefsAccount *ac = (PrefsAccount *)accounts->data;
8270 gchar *name, *from = NULL;
8272 if (ac == compose->account) def_menu = num;
8274 name = g_markup_printf_escaped("<i>%s</i>",
8277 if (ac == compose->account) {
8278 if (ac->name && *ac->name) {
8280 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
8281 from = g_strdup_printf("%s <%s>",
8283 gtk_entry_set_text(GTK_ENTRY(from_name), from);
8285 from = g_strdup_printf("%s",
8287 gtk_entry_set_text(GTK_ENTRY(from_name), from);
8289 if (cur_account != compose->account) {
8290 gtk_widget_modify_base(
8291 GTK_WIDGET(from_name),
8292 GTK_STATE_NORMAL, &default_header_bgcolor);
8293 gtk_widget_modify_text(
8294 GTK_WIDGET(from_name),
8295 GTK_STATE_NORMAL, &default_header_color);
8298 COMBOBOX_ADD(menu, name, ac->account_id);
8303 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
8305 g_signal_connect(G_OBJECT(optmenu), "changed",
8306 G_CALLBACK(account_activated),
8308 g_signal_connect(G_OBJECT(from_name), "populate-popup",
8309 G_CALLBACK(compose_entry_popup_extend),
8312 fromlabel = gtk_label_new_with_mnemonic(_("_From:"));
8313 gtk_label_set_mnemonic_widget(GTK_LABEL(fromlabel), from_name);
8315 gtk_box_pack_start(GTK_BOX(hbox), fromlabel, FALSE, FALSE, 4);
8316 gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
8317 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
8319 /* Putting only the GtkEntry into focus chain of parent hbox causes
8320 * the account selector combobox next to it to be unreachable when
8321 * navigating widgets in GtkTable with up/down arrow keys.
8322 * Note: gtk_widget_set_can_focus() was not enough. */
8324 l = g_list_prepend(l, from_name);
8325 gtk_container_set_focus_chain(GTK_CONTAINER(hbox), l);
8328 CLAWS_SET_TIP(optmenubox,
8329 _("Account to use for this email"));
8330 CLAWS_SET_TIP(from_name,
8331 _("Sender address to be used"));
8333 compose->account_combo = optmenu;
8334 compose->from_name = from_name;
8339 static void compose_set_priority_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
8341 gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
8342 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
8343 Compose *compose = (Compose *) data;
8345 compose->priority = value;
8349 static void compose_reply_change_mode(Compose *compose,
8352 gboolean was_modified = compose->modified;
8354 gboolean all = FALSE, ml = FALSE, sender = FALSE, followup = FALSE;
8356 cm_return_if_fail(compose->replyinfo != NULL);
8358 if (action == COMPOSE_REPLY && prefs_common.default_reply_list)
8360 if (action == COMPOSE_REPLY && compose->rmode == COMPOSE_FOLLOWUP_AND_REPLY_TO)
8362 if (action == COMPOSE_REPLY_TO_ALL)
8364 if (action == COMPOSE_REPLY_TO_SENDER)
8366 if (action == COMPOSE_REPLY_TO_LIST)
8369 compose_remove_header_entries(compose);
8370 compose_reply_set_entry(compose, compose->replyinfo, all, ml, sender, followup);
8371 if (compose->account->set_autocc && compose->account->auto_cc)
8372 compose_entry_append(compose, compose->account->auto_cc, COMPOSE_CC, PREF_ACCOUNT);
8374 if (compose->account->set_autobcc && compose->account->auto_bcc)
8375 compose_entry_append(compose, compose->account->auto_bcc, COMPOSE_BCC, PREF_ACCOUNT);
8377 if (compose->account->set_autoreplyto && compose->account->auto_replyto)
8378 compose_entry_append(compose, compose->account->auto_replyto, COMPOSE_REPLYTO, PREF_ACCOUNT);
8379 compose_show_first_last_header(compose, TRUE);
8380 compose->modified = was_modified;
8381 compose_set_title(compose);
8384 static void compose_reply_change_mode_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
8386 gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
8387 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
8388 Compose *compose = (Compose *) data;
8391 compose_reply_change_mode(compose, value);
8394 static void compose_update_priority_menu_item(Compose * compose)
8396 GtkWidget *menuitem = NULL;
8397 switch (compose->priority) {
8398 case PRIORITY_HIGHEST:
8399 menuitem = gtk_ui_manager_get_widget
8400 (compose->ui_manager, "/Menu/Options/Priority/Highest");
8403 menuitem = gtk_ui_manager_get_widget
8404 (compose->ui_manager, "/Menu/Options/Priority/High");
8406 case PRIORITY_NORMAL:
8407 menuitem = gtk_ui_manager_get_widget
8408 (compose->ui_manager, "/Menu/Options/Priority/Normal");
8411 menuitem = gtk_ui_manager_get_widget
8412 (compose->ui_manager, "/Menu/Options/Priority/Low");
8414 case PRIORITY_LOWEST:
8415 menuitem = gtk_ui_manager_get_widget
8416 (compose->ui_manager, "/Menu/Options/Priority/Lowest");
8419 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
8422 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
8424 Compose *compose = (Compose *) data;
8426 gboolean can_sign = FALSE, can_encrypt = FALSE;
8428 cm_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
8430 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
8433 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
8434 g_free(compose->privacy_system);
8435 compose->privacy_system = NULL;
8436 g_free(compose->encdata);
8437 compose->encdata = NULL;
8438 if (systemid != NULL) {
8439 compose->privacy_system = g_strdup(systemid);
8441 can_sign = privacy_system_can_sign(systemid);
8442 can_encrypt = privacy_system_can_encrypt(systemid);
8445 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
8447 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Sign", can_sign);
8448 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Encrypt", can_encrypt);
8451 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
8453 static gchar *branch_path = "/Menu/Options/PrivacySystem";
8454 GtkWidget *menuitem = NULL;
8455 GList *children, *amenu;
8456 gboolean can_sign = FALSE, can_encrypt = FALSE;
8457 gboolean found = FALSE;
8459 if (compose->privacy_system != NULL) {
8461 menuitem = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
8462 gtk_ui_manager_get_widget(compose->ui_manager, branch_path)));
8463 cm_return_if_fail(menuitem != NULL);
8465 children = gtk_container_get_children(GTK_CONTAINER(GTK_MENU_SHELL(menuitem)));
8468 while (amenu != NULL) {
8469 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
8470 if (systemid != NULL) {
8471 if (strcmp(systemid, compose->privacy_system) == 0 &&
8472 GTK_IS_CHECK_MENU_ITEM(amenu->data)) {
8473 menuitem = GTK_WIDGET(amenu->data);
8475 can_sign = privacy_system_can_sign(systemid);
8476 can_encrypt = privacy_system_can_encrypt(systemid);
8480 } else if (strlen(compose->privacy_system) == 0 &&
8481 GTK_IS_CHECK_MENU_ITEM(amenu->data)) {
8482 menuitem = GTK_WIDGET(amenu->data);
8485 can_encrypt = FALSE;
8490 amenu = amenu->next;
8492 g_list_free(children);
8493 if (menuitem != NULL)
8494 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
8496 if (warn && !found && strlen(compose->privacy_system)) {
8497 alertpanel_warning(_("The privacy system '%s' cannot be loaded. You "
8498 "will not be able to sign or encrypt this message."),
8499 compose->privacy_system);
8503 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Sign", can_sign);
8504 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Encrypt", can_encrypt);
8507 static void compose_set_out_encoding(Compose *compose)
8509 CharSet out_encoding;
8510 const gchar *branch = NULL;
8511 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
8513 switch(out_encoding) {
8514 case C_AUTO: branch = "Menu/Options/Encoding/" CS_AUTO; break;
8515 case C_US_ASCII: branch = "Menu/Options/Encoding/" CS_US_ASCII; break;
8516 case C_UTF_8: branch = "Menu/Options/Encoding/" CS_UTF_8; break;
8517 case C_ISO_8859_2: branch = "Menu/Options/Encoding/" CS_ISO_8859_2; break;
8518 case C_ISO_8859_7: branch = "Menu/Options/Encoding/" CS_ISO_8859_7; break;
8519 case C_ISO_8859_9: branch = "Menu/Options/Encoding/" CS_ISO_8859_9; break;
8520 case C_ISO_8859_1: branch = "Menu/Options/Encoding/Western/" CS_ISO_8859_1; break;
8521 case C_ISO_8859_15: branch = "Menu/Options/Encoding/Western/" CS_ISO_8859_15; break;
8522 case C_WINDOWS_1252: branch = "Menu/Options/Encoding/Western/" CS_WINDOWS_1252; break;
8523 case C_ISO_8859_13: branch = "Menu/Options/Encoding/Baltic/" CS_ISO_8859_13; break;
8524 case C_ISO_8859_4: branch = "Menu/Options/Encoding/Baltic" CS_ISO_8859_4; break;
8525 case C_ISO_8859_8: branch = "Menu/Options/Encoding/Hebrew/" CS_ISO_8859_8; break;
8526 case C_WINDOWS_1255: branch = "Menu/Options/Encoding/Hebrew/" CS_WINDOWS_1255; break;
8527 case C_ISO_8859_6: branch = "Menu/Options/Encoding/Arabic/" CS_ISO_8859_6; break;
8528 case C_WINDOWS_1256: branch = "Menu/Options/Encoding/Arabic/" CS_WINDOWS_1256; break;
8529 case C_ISO_8859_5: branch = "Menu/Options/Encoding/Cyrillic/" CS_ISO_8859_5; break;
8530 case C_KOI8_R: branch = "Menu/Options/Encoding/Cyrillic/" CS_KOI8_R; break;
8531 case C_MACCYR: branch = "Menu/Options/Encoding/Cyrillic/" CS_MACCYR; break;
8532 case C_KOI8_U: branch = "Menu/Options/Encoding/Cyrillic/" CS_KOI8_U; break;
8533 case C_WINDOWS_1251: branch = "Menu/Options/Encoding/Cyrillic/" CS_WINDOWS_1251; break;
8534 case C_ISO_2022_JP: branch = "Menu/Options/Encoding/Japanese/" CS_ISO_2022_JP; break;
8535 case C_ISO_2022_JP_2: branch = "Menu/Options/Encoding/Japanese/" CS_ISO_2022_JP_2; break;
8536 case C_EUC_JP: branch = "Menu/Options/Encoding/Japanese/" CS_EUC_JP; break;
8537 case C_SHIFT_JIS: branch = "Menu/Options/Encoding/Japanese/" CS_SHIFT_JIS; break;
8538 case C_GB18030: branch = "Menu/Options/Encoding/Chinese/" CS_GB18030; break;
8539 case C_GB2312: branch = "Menu/Options/Encoding/Chinese/" CS_GB2312; break;
8540 case C_GBK: branch = "Menu/Options/Encoding/Chinese/" CS_GBK; break;
8541 case C_BIG5: branch = "Menu/Options/Encoding/Chinese/" CS_BIG5; break;
8542 case C_EUC_TW: branch = "Menu/Options/Encoding/Chinese/" CS_EUC_TW; break;
8543 case C_EUC_KR: branch = "Menu/Options/Encoding/Korean/" CS_EUC_KR; break;
8544 case C_ISO_2022_KR: branch = "Menu/Options/Encoding/Korean/" CS_ISO_2022_KR; break;
8545 case C_TIS_620: branch = "Menu/Options/Encoding/Thai/" CS_TIS_620; break;
8546 case C_WINDOWS_874: branch = "Menu/Options/Encoding/Thai/" CS_WINDOWS_874; break;
8547 default: branch = "Menu/Options/Encoding/" CS_AUTO; break;
8549 cm_toggle_menu_set_active_full(compose->ui_manager, (gchar *)branch, TRUE);
8552 static void compose_set_template_menu(Compose *compose)
8554 GSList *tmpl_list, *cur;
8558 tmpl_list = template_get_config();
8560 menu = gtk_menu_new();
8562 gtk_menu_set_accel_group (GTK_MENU (menu),
8563 gtk_ui_manager_get_accel_group(compose->ui_manager));
8564 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
8565 Template *tmpl = (Template *)cur->data;
8566 gchar *accel_path = NULL;
8567 item = gtk_menu_item_new_with_label(tmpl->name);
8568 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
8569 g_signal_connect(G_OBJECT(item), "activate",
8570 G_CALLBACK(compose_template_activate_cb),
8572 g_object_set_data(G_OBJECT(item), "template", tmpl);
8573 gtk_widget_show(item);
8574 accel_path = g_strconcat("<ComposeTemplates>" , "/", tmpl->name, NULL);
8575 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
8579 gtk_widget_show(menu);
8580 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
8583 void compose_update_actions_menu(Compose *compose)
8585 action_update_compose_menu(compose->ui_manager, "/Menu/Tools/Actions", compose);
8588 static void compose_update_privacy_systems_menu(Compose *compose)
8590 static gchar *branch_path = "/Menu/Options/PrivacySystem";
8591 GSList *systems, *cur;
8593 GtkWidget *system_none;
8595 GtkWidget *privacy_menuitem = gtk_ui_manager_get_widget(compose->ui_manager, branch_path);
8596 GtkWidget *privacy_menu = gtk_menu_new();
8598 system_none = gtk_radio_menu_item_new_with_mnemonic(NULL, _("_None"));
8599 g_object_set_data_full(G_OBJECT(system_none), "privacy_system", NULL, NULL);
8601 g_signal_connect(G_OBJECT(system_none), "activate",
8602 G_CALLBACK(compose_set_privacy_system_cb), compose);
8604 gtk_menu_shell_append(GTK_MENU_SHELL(privacy_menu), system_none);
8605 gtk_widget_show(system_none);
8607 systems = privacy_get_system_ids();
8608 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
8609 gchar *systemid = cur->data;
8611 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
8612 widget = gtk_radio_menu_item_new_with_label(group,
8613 privacy_system_get_name(systemid));
8614 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
8615 g_strdup(systemid), g_free);
8616 g_signal_connect(G_OBJECT(widget), "activate",
8617 G_CALLBACK(compose_set_privacy_system_cb), compose);
8619 gtk_menu_shell_append(GTK_MENU_SHELL(privacy_menu), widget);
8620 gtk_widget_show(widget);
8623 g_slist_free(systems);
8624 gtk_menu_item_set_submenu(GTK_MENU_ITEM(privacy_menuitem), privacy_menu);
8625 gtk_widget_show_all(privacy_menu);
8626 gtk_widget_show_all(privacy_menuitem);
8629 void compose_reflect_prefs_all(void)
8634 for (cur = compose_list; cur != NULL; cur = cur->next) {
8635 compose = (Compose *)cur->data;
8636 compose_set_template_menu(compose);
8640 void compose_reflect_prefs_pixmap_theme(void)
8645 for (cur = compose_list; cur != NULL; cur = cur->next) {
8646 compose = (Compose *)cur->data;
8647 toolbar_update(TOOLBAR_COMPOSE, compose);
8651 static const gchar *compose_quote_char_from_context(Compose *compose)
8653 const gchar *qmark = NULL;
8655 cm_return_val_if_fail(compose != NULL, NULL);
8657 switch (compose->mode) {
8658 /* use forward-specific quote char */
8659 case COMPOSE_FORWARD:
8660 case COMPOSE_FORWARD_AS_ATTACH:
8661 case COMPOSE_FORWARD_INLINE:
8662 if (compose->folder && compose->folder->prefs &&
8663 compose->folder->prefs->forward_with_format)
8664 qmark = compose->folder->prefs->forward_quotemark;
8665 else if (compose->account->forward_with_format)
8666 qmark = compose->account->forward_quotemark;
8668 qmark = prefs_common.fw_quotemark;
8671 /* use reply-specific quote char in all other modes */
8673 if (compose->folder && compose->folder->prefs &&
8674 compose->folder->prefs->reply_with_format)
8675 qmark = compose->folder->prefs->reply_quotemark;
8676 else if (compose->account->reply_with_format)
8677 qmark = compose->account->reply_quotemark;
8679 qmark = prefs_common.quotemark;
8683 if (qmark == NULL || *qmark == '\0')
8689 static void compose_template_apply(Compose *compose, Template *tmpl,
8693 GtkTextBuffer *buffer;
8697 gchar *parsed_str = NULL;
8698 gint cursor_pos = 0;
8699 const gchar *err_msg = _("The body of the template has an error at line %d.");
8702 /* process the body */
8704 text = GTK_TEXT_VIEW(compose->text);
8705 buffer = gtk_text_view_get_buffer(text);
8708 qmark = compose_quote_char_from_context(compose);
8710 if (compose->replyinfo != NULL) {
8713 gtk_text_buffer_set_text(buffer, "", -1);
8714 mark = gtk_text_buffer_get_insert(buffer);
8715 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
8717 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
8718 tmpl->value, qmark, NULL, FALSE, FALSE, err_msg);
8720 } else if (compose->fwdinfo != NULL) {
8723 gtk_text_buffer_set_text(buffer, "", -1);
8724 mark = gtk_text_buffer_get_insert(buffer);
8725 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
8727 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
8728 tmpl->value, qmark, NULL, FALSE, FALSE, err_msg);
8731 MsgInfo* dummyinfo = compose_msginfo_new_from_compose(compose);
8733 GtkTextIter start, end;
8736 gtk_text_buffer_get_start_iter(buffer, &start);
8737 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
8738 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
8740 /* clear the buffer now */
8742 gtk_text_buffer_set_text(buffer, "", -1);
8744 parsed_str = compose_quote_fmt(compose, dummyinfo,
8745 tmpl->value, qmark, tmp, FALSE, FALSE, err_msg);
8746 procmsg_msginfo_free( &dummyinfo );
8752 gtk_text_buffer_set_text(buffer, "", -1);
8753 mark = gtk_text_buffer_get_insert(buffer);
8754 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
8757 if (replace && parsed_str && compose->account->auto_sig)
8758 compose_insert_sig(compose, FALSE);
8760 if (replace && parsed_str) {
8761 gtk_text_buffer_get_start_iter(buffer, &iter);
8762 gtk_text_buffer_place_cursor(buffer, &iter);
8766 cursor_pos = quote_fmt_get_cursor_pos();
8767 compose->set_cursor_pos = cursor_pos;
8768 if (cursor_pos == -1)
8770 gtk_text_buffer_get_start_iter(buffer, &iter);
8771 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
8772 gtk_text_buffer_place_cursor(buffer, &iter);
8775 /* process the other fields */
8777 compose_template_apply_fields(compose, tmpl);
8778 compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
8779 quote_fmt_reset_vartable();
8780 compose_changed_cb(NULL, compose);
8783 if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
8784 gtkaspell_highlight_all(compose->gtkaspell);
8788 static void compose_template_apply_fields_error(const gchar *header)
8793 tr = g_strdup(C_("'%s' stands for a header name",
8794 "Template '%s' format error."));
8795 text = g_strdup_printf(tr, prefs_common_translated_header_name(header));
8796 alertpanel_error(text);
8802 static void compose_template_apply_fields(Compose *compose, Template *tmpl)
8804 MsgInfo* dummyinfo = NULL;
8805 MsgInfo *msginfo = NULL;
8808 if (compose->replyinfo != NULL)
8809 msginfo = compose->replyinfo;
8810 else if (compose->fwdinfo != NULL)
8811 msginfo = compose->fwdinfo;
8813 dummyinfo = compose_msginfo_new_from_compose(compose);
8814 msginfo = dummyinfo;
8817 if (tmpl->from && *tmpl->from != '\0') {
8819 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
8820 compose->gtkaspell);
8822 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
8824 quote_fmt_scan_string(tmpl->from);
8827 buf = quote_fmt_get_buffer();
8829 compose_template_apply_fields_error("From");
8831 gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
8835 if (tmpl->to && *tmpl->to != '\0') {
8837 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
8838 compose->gtkaspell);
8840 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
8842 quote_fmt_scan_string(tmpl->to);
8845 buf = quote_fmt_get_buffer();
8847 compose_template_apply_fields_error("To");
8849 compose_entry_append(compose, buf, COMPOSE_TO, PREF_TEMPLATE);
8853 if (tmpl->cc && *tmpl->cc != '\0') {
8855 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
8856 compose->gtkaspell);
8858 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
8860 quote_fmt_scan_string(tmpl->cc);
8863 buf = quote_fmt_get_buffer();
8865 compose_template_apply_fields_error("Cc");
8867 compose_entry_append(compose, buf, COMPOSE_CC, PREF_TEMPLATE);
8871 if (tmpl->bcc && *tmpl->bcc != '\0') {
8873 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
8874 compose->gtkaspell);
8876 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
8878 quote_fmt_scan_string(tmpl->bcc);
8881 buf = quote_fmt_get_buffer();
8883 compose_template_apply_fields_error("Bcc");
8885 compose_entry_append(compose, buf, COMPOSE_BCC, PREF_TEMPLATE);
8889 if (tmpl->replyto && *tmpl->replyto != '\0') {
8891 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
8892 compose->gtkaspell);
8894 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
8896 quote_fmt_scan_string(tmpl->replyto);
8899 buf = quote_fmt_get_buffer();
8901 compose_template_apply_fields_error("Reply-To");
8903 compose_entry_append(compose, buf, COMPOSE_REPLYTO, PREF_TEMPLATE);
8907 /* process the subject */
8908 if (tmpl->subject && *tmpl->subject != '\0') {
8910 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
8911 compose->gtkaspell);
8913 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
8915 quote_fmt_scan_string(tmpl->subject);
8918 buf = quote_fmt_get_buffer();
8920 compose_template_apply_fields_error("Subject");
8922 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
8926 procmsg_msginfo_free( &dummyinfo );
8929 static void compose_destroy(Compose *compose)
8931 GtkAllocation allocation;
8932 GtkTextBuffer *buffer;
8933 GtkClipboard *clipboard;
8935 compose_list = g_list_remove(compose_list, compose);
8937 if (compose->updating) {
8938 debug_print("danger, not destroying anything now\n");
8939 compose->deferred_destroy = TRUE;
8943 /* NOTE: address_completion_end() does nothing with the window
8944 * however this may change. */
8945 address_completion_end(compose->window);
8947 slist_free_strings_full(compose->to_list);
8948 slist_free_strings_full(compose->newsgroup_list);
8949 slist_free_strings_full(compose->header_list);
8951 slist_free_strings_full(extra_headers);
8952 extra_headers = NULL;
8954 compose->header_list = compose->newsgroup_list = compose->to_list = NULL;
8956 g_hash_table_destroy(compose->email_hashtable);
8958 hooks_unregister_hook(FOLDER_UPDATE_HOOKLIST,
8959 compose->folder_update_callback_id);
8961 procmsg_msginfo_free(&(compose->targetinfo));
8962 procmsg_msginfo_free(&(compose->replyinfo));
8963 procmsg_msginfo_free(&(compose->fwdinfo));
8965 g_free(compose->replyto);
8966 g_free(compose->cc);
8967 g_free(compose->bcc);
8968 g_free(compose->newsgroups);
8969 g_free(compose->followup_to);
8971 g_free(compose->ml_post);
8973 g_free(compose->inreplyto);
8974 g_free(compose->references);
8975 g_free(compose->msgid);
8976 g_free(compose->boundary);
8978 g_free(compose->redirect_filename);
8979 if (compose->undostruct)
8980 undo_destroy(compose->undostruct);
8982 g_free(compose->sig_str);
8984 g_free(compose->exteditor_file);
8986 g_free(compose->orig_charset);
8988 g_free(compose->privacy_system);
8989 g_free(compose->encdata);
8991 #ifndef USE_ALT_ADDRBOOK
8992 if (addressbook_get_target_compose() == compose)
8993 addressbook_set_target_compose(NULL);
8996 if (compose->gtkaspell) {
8997 gtkaspell_delete(compose->gtkaspell);
8998 compose->gtkaspell = NULL;
9002 if (!compose->batch) {
9003 gtk_widget_get_allocation(compose->window, &allocation);
9004 prefs_common.compose_width = allocation.width;
9005 prefs_common.compose_height = allocation.height;
9008 if (!gtk_widget_get_parent(compose->paned))
9009 gtk_widget_destroy(compose->paned);
9010 gtk_widget_destroy(compose->popupmenu);
9012 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
9013 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
9014 gtk_text_buffer_remove_selection_clipboard(buffer, clipboard);
9016 gtk_widget_destroy(compose->window);
9017 toolbar_destroy(compose->toolbar);
9018 g_free(compose->toolbar);
9019 cm_mutex_free(compose->mutex);
9023 static void compose_attach_info_free(AttachInfo *ainfo)
9025 g_free(ainfo->file);
9026 g_free(ainfo->content_type);
9027 g_free(ainfo->name);
9028 g_free(ainfo->charset);
9032 static void compose_attach_update_label(Compose *compose)
9037 GtkTreeModel *model;
9041 if (compose == NULL)
9044 model = gtk_tree_view_get_model(GTK_TREE_VIEW(compose->attach_clist));
9045 if (!gtk_tree_model_get_iter_first(model, &iter)) {
9046 gtk_label_set_text(GTK_LABEL(compose->attach_label), "");
9050 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
9051 total_size = ainfo->size;
9052 while(gtk_tree_model_iter_next(model, &iter)) {
9053 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
9054 total_size += ainfo->size;
9057 text = g_strdup_printf(" (%d/%s)", i, to_human_readable(total_size));
9058 gtk_label_set_text(GTK_LABEL(compose->attach_label), text);
9062 static void compose_attach_remove_selected(GtkAction *action, gpointer data)
9064 Compose *compose = (Compose *)data;
9065 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
9066 GtkTreeSelection *selection;
9068 GtkTreeModel *model;
9070 selection = gtk_tree_view_get_selection(tree_view);
9071 sel = gtk_tree_selection_get_selected_rows(selection, &model);
9076 for (cur = sel; cur != NULL; cur = cur->next) {
9077 GtkTreePath *path = cur->data;
9078 GtkTreeRowReference *ref = gtk_tree_row_reference_new
9081 gtk_tree_path_free(path);
9084 for (cur = sel; cur != NULL; cur = cur->next) {
9085 GtkTreeRowReference *ref = cur->data;
9086 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
9089 if (gtk_tree_model_get_iter(model, &iter, path))
9090 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
9092 gtk_tree_path_free(path);
9093 gtk_tree_row_reference_free(ref);
9097 compose_attach_update_label(compose);
9100 static struct _AttachProperty
9103 GtkWidget *mimetype_entry;
9104 GtkWidget *encoding_optmenu;
9105 GtkWidget *path_entry;
9106 GtkWidget *filename_entry;
9108 GtkWidget *cancel_btn;
9111 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
9113 gtk_tree_path_free((GtkTreePath *)ptr);
9116 static void compose_attach_property(GtkAction *action, gpointer data)
9118 Compose *compose = (Compose *)data;
9119 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
9121 GtkComboBox *optmenu;
9122 GtkTreeSelection *selection;
9124 GtkTreeModel *model;
9127 static gboolean cancelled;
9129 /* only if one selected */
9130 selection = gtk_tree_view_get_selection(tree_view);
9131 if (gtk_tree_selection_count_selected_rows(selection) != 1)
9134 sel = gtk_tree_selection_get_selected_rows(selection, &model);
9138 path = (GtkTreePath *) sel->data;
9139 gtk_tree_model_get_iter(model, &iter, path);
9140 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
9143 g_list_foreach(sel, gtk_tree_path_free_, NULL);
9149 if (!attach_prop.window)
9150 compose_attach_property_create(&cancelled);
9151 gtk_window_set_modal(GTK_WINDOW(attach_prop.window), TRUE);
9152 gtk_widget_grab_focus(attach_prop.ok_btn);
9153 gtk_widget_show(attach_prop.window);
9154 gtk_window_set_transient_for(GTK_WINDOW(attach_prop.window),
9155 GTK_WINDOW(compose->window));
9157 optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
9158 if (ainfo->encoding == ENC_UNKNOWN)
9159 combobox_select_by_data(optmenu, ENC_BASE64);
9161 combobox_select_by_data(optmenu, ainfo->encoding);
9163 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
9164 ainfo->content_type ? ainfo->content_type : "");
9165 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
9166 ainfo->file ? ainfo->file : "");
9167 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
9168 ainfo->name ? ainfo->name : "");
9171 const gchar *entry_text;
9173 gchar *cnttype = NULL;
9180 gtk_widget_hide(attach_prop.window);
9181 gtk_window_set_modal(GTK_WINDOW(attach_prop.window), FALSE);
9186 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
9187 if (*entry_text != '\0') {
9190 text = g_strstrip(g_strdup(entry_text));
9191 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
9192 cnttype = g_strdup(text);
9195 alertpanel_error(_("Invalid MIME type."));
9201 ainfo->encoding = combobox_get_active_data(optmenu);
9203 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
9204 if (*entry_text != '\0') {
9205 if (is_file_exist(entry_text) &&
9206 (size = get_file_size(entry_text)) > 0)
9207 file = g_strdup(entry_text);
9210 (_("File doesn't exist or is empty."));
9216 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
9217 if (*entry_text != '\0') {
9218 g_free(ainfo->name);
9219 ainfo->name = g_strdup(entry_text);
9223 g_free(ainfo->content_type);
9224 ainfo->content_type = cnttype;
9227 g_free(ainfo->file);
9231 ainfo->size = (goffset)size;
9233 /* update tree store */
9234 text = to_human_readable(ainfo->size);
9235 gtk_tree_model_get_iter(model, &iter, path);
9236 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
9237 COL_MIMETYPE, ainfo->content_type,
9239 COL_NAME, ainfo->name,
9240 COL_CHARSET, ainfo->charset,
9246 gtk_tree_path_free(path);
9249 #define SET_LABEL_AND_ENTRY(str, entry, top) \
9251 label = gtk_label_new(str); \
9252 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
9253 GTK_FILL, 0, 0, 0); \
9254 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
9256 entry = gtk_entry_new(); \
9257 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
9258 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
9261 static void compose_attach_property_create(gboolean *cancelled)
9267 GtkWidget *mimetype_entry;
9270 GtkListStore *optmenu_menu;
9271 GtkWidget *path_entry;
9272 GtkWidget *filename_entry;
9275 GtkWidget *cancel_btn;
9276 GList *mime_type_list, *strlist;
9279 debug_print("Creating attach_property window...\n");
9281 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose_attach_property");
9282 gtk_widget_set_size_request(window, 480, -1);
9283 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
9284 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
9285 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
9286 g_signal_connect(G_OBJECT(window), "delete_event",
9287 G_CALLBACK(attach_property_delete_event),
9289 g_signal_connect(G_OBJECT(window), "key_press_event",
9290 G_CALLBACK(attach_property_key_pressed),
9293 vbox = gtk_vbox_new(FALSE, 8);
9294 gtk_container_add(GTK_CONTAINER(window), vbox);
9296 table = gtk_table_new(4, 2, FALSE);
9297 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
9298 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
9299 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
9301 label = gtk_label_new(_("MIME type"));
9302 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
9304 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
9305 #if !GTK_CHECK_VERSION(2, 24, 0)
9306 mimetype_entry = gtk_combo_box_entry_new_text();
9308 mimetype_entry = gtk_combo_box_text_new_with_entry();
9310 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
9311 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
9313 /* stuff with list */
9314 mime_type_list = procmime_get_mime_type_list();
9316 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
9317 MimeType *type = (MimeType *) mime_type_list->data;
9320 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
9322 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
9325 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
9326 (GCompareFunc)strcmp2);
9329 for (mime_type_list = strlist; mime_type_list != NULL;
9330 mime_type_list = mime_type_list->next) {
9331 #if !GTK_CHECK_VERSION(2, 24, 0)
9332 gtk_combo_box_append_text(GTK_COMBO_BOX(mimetype_entry), mime_type_list->data);
9334 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(mimetype_entry), mime_type_list->data);
9336 g_free(mime_type_list->data);
9338 g_list_free(strlist);
9339 gtk_combo_box_set_active(GTK_COMBO_BOX(mimetype_entry), 0);
9340 mimetype_entry = gtk_bin_get_child(GTK_BIN((mimetype_entry)));
9342 label = gtk_label_new(_("Encoding"));
9343 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
9345 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
9347 hbox = gtk_hbox_new(FALSE, 0);
9348 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
9349 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
9351 optmenu = gtkut_sc_combobox_create(NULL, TRUE);
9352 optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
9354 COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
9355 COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
9356 COMBOBOX_ADD(optmenu_menu, "quoted-printable", ENC_QUOTED_PRINTABLE);
9357 COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
9358 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
9360 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
9362 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
9363 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
9365 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
9366 &ok_btn, GTK_STOCK_OK,
9368 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
9369 gtk_widget_grab_default(ok_btn);
9371 g_signal_connect(G_OBJECT(ok_btn), "clicked",
9372 G_CALLBACK(attach_property_ok),
9374 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
9375 G_CALLBACK(attach_property_cancel),
9378 gtk_widget_show_all(vbox);
9380 attach_prop.window = window;
9381 attach_prop.mimetype_entry = mimetype_entry;
9382 attach_prop.encoding_optmenu = optmenu;
9383 attach_prop.path_entry = path_entry;
9384 attach_prop.filename_entry = filename_entry;
9385 attach_prop.ok_btn = ok_btn;
9386 attach_prop.cancel_btn = cancel_btn;
9389 #undef SET_LABEL_AND_ENTRY
9391 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
9397 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
9403 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
9404 gboolean *cancelled)
9412 static gboolean attach_property_key_pressed(GtkWidget *widget,
9414 gboolean *cancelled)
9416 if (event && event->keyval == GDK_KEY_Escape) {
9420 if (event && event->keyval == GDK_KEY_Return) {
9428 static void compose_exec_ext_editor(Compose *compose)
9433 GdkNativeWindow socket_wid = 0;
9437 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
9438 G_DIR_SEPARATOR, compose);
9440 if (compose_get_ext_editor_uses_socket()) {
9441 /* Only allow one socket */
9442 if (compose->exteditor_socket != NULL) {
9443 if (gtk_widget_is_focus(compose->exteditor_socket)) {
9444 /* Move the focus off of the socket */
9445 gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
9450 /* Create the receiving GtkSocket */
9451 socket = gtk_socket_new ();
9452 g_signal_connect (GTK_OBJECT(socket), "plug-removed",
9453 G_CALLBACK(compose_ext_editor_plug_removed_cb),
9455 gtk_box_pack_start(GTK_BOX(compose->edit_vbox), socket, TRUE, TRUE, 0);
9456 gtk_widget_set_size_request(socket, prefs_common.compose_width, -1);
9457 /* Realize the socket so that we can use its ID */
9458 gtk_widget_realize(socket);
9459 socket_wid = gtk_socket_get_id(GTK_SOCKET (socket));
9460 compose->exteditor_socket = socket;
9463 if (pipe(pipe_fds) < 0) {
9469 if ((pid = fork()) < 0) {
9476 /* close the write side of the pipe */
9479 compose->exteditor_file = g_strdup(tmp);
9480 compose->exteditor_pid = pid;
9482 compose_set_ext_editor_sensitive(compose, FALSE);
9485 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
9487 compose->exteditor_ch = g_io_channel_win32_new_fd(pipe_fds[0]);
9489 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
9493 } else { /* process-monitoring process */
9499 /* close the read side of the pipe */
9502 if (compose_write_body_to_file(compose, tmp) < 0) {
9503 fd_write_all(pipe_fds[1], "2\n", 2);
9507 pid_ed = compose_exec_ext_editor_real(tmp, socket_wid);
9509 fd_write_all(pipe_fds[1], "1\n", 2);
9513 /* wait until editor is terminated */
9514 waitpid(pid_ed, NULL, 0);
9516 fd_write_all(pipe_fds[1], "0\n", 2);
9523 #endif /* G_OS_UNIX */
9526 static gboolean compose_can_autosave(Compose *compose)
9528 if (compose->privacy_system && compose->use_encryption)
9529 return prefs_common.autosave && prefs_common.autosave_encrypted;
9531 return prefs_common.autosave;
9535 static gboolean compose_get_ext_editor_cmd_valid()
9537 gboolean has_s = FALSE;
9538 gboolean has_w = FALSE;
9539 const gchar *p = prefs_common_get_ext_editor_cmd();
9542 while ((p = strchr(p, '%'))) {
9548 } else if (*p == 'w') {
9559 static gint compose_exec_ext_editor_real(const gchar *file, GdkNativeWindow socket_wid)
9566 cm_return_val_if_fail(file != NULL, -1);
9568 if ((pid = fork()) < 0) {
9573 if (pid != 0) return pid;
9575 /* grandchild process */
9577 if (setpgid(0, getppid()))
9580 if (compose_get_ext_editor_cmd_valid()) {
9581 if (compose_get_ext_editor_uses_socket()) {
9582 p = g_strdup(prefs_common_get_ext_editor_cmd());
9583 s = strstr(p, "%w");
9585 if (strstr(p, "%s") < s)
9586 buf = g_strdup_printf(p, file, socket_wid);
9588 buf = g_strdup_printf(p, socket_wid, file);
9591 buf = g_strdup_printf(prefs_common_get_ext_editor_cmd(), file);
9594 if (prefs_common_get_ext_editor_cmd())
9595 g_warning("External editor command-line is invalid: '%s'",
9596 prefs_common_get_ext_editor_cmd());
9597 buf = g_strdup_printf(DEFAULT_EDITOR_CMD, file);
9600 cmdline = strsplit_with_quote(buf, " ", 0);
9602 execvp(cmdline[0], cmdline);
9605 g_strfreev(cmdline);
9610 static gboolean compose_ext_editor_kill(Compose *compose)
9612 pid_t pgid = compose->exteditor_pid * -1;
9615 ret = kill(pgid, 0);
9617 if (ret == 0 || (ret == -1 && EPERM == errno)) {
9621 msg = g_strdup_printf
9622 (_("The external editor is still working.\n"
9623 "Force terminating the process?\n"
9624 "process group id: %d"), -pgid);
9625 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
9626 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
9630 if (val == G_ALERTALTERNATE) {
9631 g_source_remove(compose->exteditor_tag);
9632 g_io_channel_shutdown(compose->exteditor_ch,
9634 g_io_channel_unref(compose->exteditor_ch);
9636 if (kill(pgid, SIGTERM) < 0) perror("kill");
9637 waitpid(compose->exteditor_pid, NULL, 0);
9639 g_warning("Terminated process group id: %d. "
9640 "Temporary file: %s", -pgid, compose->exteditor_file);
9642 compose_set_ext_editor_sensitive(compose, TRUE);
9644 g_free(compose->exteditor_file);
9645 compose->exteditor_file = NULL;
9646 compose->exteditor_pid = -1;
9647 compose->exteditor_ch = NULL;
9648 compose->exteditor_tag = -1;
9656 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
9660 Compose *compose = (Compose *)data;
9663 debug_print("Compose: input from monitoring process\n");
9665 if (g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL) != G_IO_STATUS_NORMAL) {
9670 g_io_channel_shutdown(source, FALSE, NULL);
9671 g_io_channel_unref(source);
9673 waitpid(compose->exteditor_pid, NULL, 0);
9675 if (buf[0] == '0') { /* success */
9676 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9677 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
9678 GtkTextIter start, end;
9681 gtk_text_buffer_set_text(buffer, "", -1);
9682 compose_insert_file(compose, compose->exteditor_file);
9683 compose_changed_cb(NULL, compose);
9685 /* Check if we should save the draft or not */
9686 if (compose_can_autosave(compose))
9687 compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
9689 if (claws_unlink(compose->exteditor_file) < 0)
9690 FILE_OP_ERROR(compose->exteditor_file, "unlink");
9692 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
9693 gtk_text_buffer_get_start_iter(buffer, &start);
9694 gtk_text_buffer_get_end_iter(buffer, &end);
9695 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
9696 if (chars && strlen(chars) > 0)
9697 compose->modified = TRUE;
9699 } else if (buf[0] == '1') { /* failed */
9700 g_warning("Couldn't exec external editor");
9701 if (claws_unlink(compose->exteditor_file) < 0)
9702 FILE_OP_ERROR(compose->exteditor_file, "unlink");
9703 } else if (buf[0] == '2') {
9704 g_warning("Couldn't write to file");
9705 } else if (buf[0] == '3') {
9706 g_warning("Pipe read failed");
9709 compose_set_ext_editor_sensitive(compose, TRUE);
9711 g_free(compose->exteditor_file);
9712 compose->exteditor_file = NULL;
9713 compose->exteditor_pid = -1;
9714 compose->exteditor_ch = NULL;
9715 compose->exteditor_tag = -1;
9716 if (compose->exteditor_socket) {
9717 gtk_widget_destroy(compose->exteditor_socket);
9718 compose->exteditor_socket = NULL;
9725 static char *ext_editor_menu_entries[] = {
9726 "Menu/Message/Send",
9727 "Menu/Message/SendLater",
9728 "Menu/Message/InsertFile",
9729 "Menu/Message/InsertSig",
9730 "Menu/Message/ReplaceSig",
9731 "Menu/Message/Save",
9732 "Menu/Message/Print",
9737 "Menu/Tools/ShowRuler",
9738 "Menu/Tools/Actions",
9743 static void compose_set_ext_editor_sensitive(Compose *compose,
9748 for (i = 0; ext_editor_menu_entries[i]; ++i) {
9749 cm_menu_set_sensitive_full(compose->ui_manager,
9750 ext_editor_menu_entries[i], sensitive);
9753 if (compose_get_ext_editor_uses_socket()) {
9755 if (compose->exteditor_socket)
9756 gtk_widget_hide(compose->exteditor_socket);
9757 gtk_widget_show(compose->scrolledwin);
9758 if (prefs_common.show_ruler)
9759 gtk_widget_show(compose->ruler_hbox);
9760 /* Fix the focus, as it doesn't go anywhere when the
9761 * socket is hidden or destroyed */
9762 gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
9764 g_assert (compose->exteditor_socket != NULL);
9765 /* Fix the focus, as it doesn't go anywhere when the
9766 * edit box is hidden */
9767 if (gtk_widget_is_focus(compose->text))
9768 gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
9769 gtk_widget_hide(compose->scrolledwin);
9770 gtk_widget_hide(compose->ruler_hbox);
9771 gtk_widget_show(compose->exteditor_socket);
9774 gtk_widget_set_sensitive(compose->text, sensitive);
9776 if (compose->toolbar->send_btn)
9777 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
9778 if (compose->toolbar->sendl_btn)
9779 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
9780 if (compose->toolbar->draft_btn)
9781 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
9782 if (compose->toolbar->insert_btn)
9783 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
9784 if (compose->toolbar->sig_btn)
9785 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
9786 if (compose->toolbar->exteditor_btn)
9787 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
9788 if (compose->toolbar->linewrap_current_btn)
9789 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
9790 if (compose->toolbar->linewrap_all_btn)
9791 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
9794 static gboolean compose_get_ext_editor_uses_socket()
9796 return (prefs_common_get_ext_editor_cmd() &&
9797 strstr(prefs_common_get_ext_editor_cmd(), "%w"));
9800 static gboolean compose_ext_editor_plug_removed_cb(GtkSocket *socket, Compose *compose)
9802 compose->exteditor_socket = NULL;
9803 /* returning FALSE allows destruction of the socket */
9806 #endif /* G_OS_UNIX */
9809 * compose_undo_state_changed:
9811 * Change the sensivity of the menuentries undo and redo
9813 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
9814 gint redo_state, gpointer data)
9816 Compose *compose = (Compose *)data;
9818 switch (undo_state) {
9819 case UNDO_STATE_TRUE:
9820 if (!undostruct->undo_state) {
9821 undostruct->undo_state = TRUE;
9822 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Undo", TRUE);
9825 case UNDO_STATE_FALSE:
9826 if (undostruct->undo_state) {
9827 undostruct->undo_state = FALSE;
9828 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Undo", FALSE);
9831 case UNDO_STATE_UNCHANGED:
9833 case UNDO_STATE_REFRESH:
9834 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Undo", undostruct->undo_state);
9837 g_warning("Undo state not recognized");
9841 switch (redo_state) {
9842 case UNDO_STATE_TRUE:
9843 if (!undostruct->redo_state) {
9844 undostruct->redo_state = TRUE;
9845 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Redo", TRUE);
9848 case UNDO_STATE_FALSE:
9849 if (undostruct->redo_state) {
9850 undostruct->redo_state = FALSE;
9851 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Redo", FALSE);
9854 case UNDO_STATE_UNCHANGED:
9856 case UNDO_STATE_REFRESH:
9857 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Redo", undostruct->redo_state);
9860 g_warning("Redo state not recognized");
9865 /* callback functions */
9867 static void compose_notebook_size_alloc(GtkNotebook *notebook,
9868 GtkAllocation *allocation,
9871 prefs_common.compose_notebook_height = gtk_paned_get_position(paned);
9874 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
9875 * includes "non-client" (windows-izm) in calculation, so this calculation
9876 * may not be accurate.
9878 static gboolean compose_edit_size_alloc(GtkEditable *widget,
9879 GtkAllocation *allocation,
9880 GtkSHRuler *shruler)
9882 if (prefs_common.show_ruler) {
9883 gint char_width = 0, char_height = 0;
9884 gint line_width_in_chars;
9886 gtkut_get_font_size(GTK_WIDGET(widget),
9887 &char_width, &char_height);
9888 line_width_in_chars =
9889 (allocation->width - allocation->x) / char_width;
9891 /* got the maximum */
9892 gtk_shruler_set_range(GTK_SHRULER(shruler),
9893 0.0, line_width_in_chars, 0);
9902 ComposePrefType type;
9903 gboolean entry_marked;
9906 static void account_activated(GtkComboBox *optmenu, gpointer data)
9908 Compose *compose = (Compose *)data;
9911 gchar *folderidentifier;
9912 gint account_id = 0;
9915 GSList *list, *saved_list = NULL;
9916 HeaderEntryState *state;
9918 /* Get ID of active account in the combo box */
9919 menu = gtk_combo_box_get_model(optmenu);
9920 cm_return_if_fail(gtk_combo_box_get_active_iter(optmenu, &iter));
9921 gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
9923 ac = account_find_from_id(account_id);
9924 cm_return_if_fail(ac != NULL);
9926 if (ac != compose->account) {
9927 compose_select_account(compose, ac, FALSE);
9929 for (list = compose->header_list; list; list = list->next) {
9930 ComposeHeaderEntry *hentry=(ComposeHeaderEntry *)list->data;
9932 if (hentry->type == PREF_ACCOUNT || !list->next) {
9933 compose_destroy_headerentry(compose, hentry);
9936 state = g_malloc0(sizeof(HeaderEntryState));
9937 state->header = gtk_editable_get_chars(GTK_EDITABLE(
9938 gtk_bin_get_child(GTK_BIN(hentry->combo))), 0, -1);
9939 state->entry = gtk_editable_get_chars(
9940 GTK_EDITABLE(hentry->entry), 0, -1);
9941 state->type = hentry->type;
9943 saved_list = g_slist_append(saved_list, state);
9944 compose_destroy_headerentry(compose, hentry);
9947 compose->header_last = NULL;
9948 g_slist_free(compose->header_list);
9949 compose->header_list = NULL;
9950 compose->header_nextrow = 1;
9951 compose_create_header_entry(compose);
9953 if (ac->set_autocc && ac->auto_cc)
9954 compose_entry_append(compose, ac->auto_cc,
9955 COMPOSE_CC, PREF_ACCOUNT);
9956 if (ac->set_autobcc && ac->auto_bcc)
9957 compose_entry_append(compose, ac->auto_bcc,
9958 COMPOSE_BCC, PREF_ACCOUNT);
9959 if (ac->set_autoreplyto && ac->auto_replyto)
9960 compose_entry_append(compose, ac->auto_replyto,
9961 COMPOSE_REPLYTO, PREF_ACCOUNT);
9963 for (list = saved_list; list; list = list->next) {
9964 state = (HeaderEntryState *) list->data;
9966 compose_add_header_entry(compose, state->header,
9967 state->entry, state->type);
9969 g_free(state->header);
9970 g_free(state->entry);
9973 g_slist_free(saved_list);
9975 combobox_select_by_data(GTK_COMBO_BOX(compose->header_last->combo),
9976 (ac->protocol == A_NNTP) ?
9977 COMPOSE_NEWSGROUPS : COMPOSE_TO);
9980 /* Set message save folder */
9981 if (account_get_special_folder(compose->account, F_OUTBOX)) {
9982 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
9984 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
9985 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
9987 compose_set_save_to(compose, NULL);
9988 if (account_get_special_folder(compose->account, F_OUTBOX)) {
9989 folderidentifier = folder_item_get_identifier(account_get_special_folder
9990 (compose->account, F_OUTBOX));
9991 compose_set_save_to(compose, folderidentifier);
9992 g_free(folderidentifier);
9996 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
9997 GtkTreeViewColumn *column, Compose *compose)
9999 compose_attach_property(NULL, compose);
10002 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
10005 Compose *compose = (Compose *)data;
10006 GtkTreeSelection *attach_selection;
10007 gint attach_nr_selected;
10010 if (!event) return FALSE;
10012 if (event->button == 3) {
10013 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
10014 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
10016 /* If no rows, or just one row is selected, right-click should
10017 * open menu relevant to the row being right-clicked on. We
10018 * achieve that by selecting the clicked row first. If more
10019 * than one row is selected, we shouldn't modify the selection,
10020 * as user may want to remove selected rows (attachments). */
10021 if (attach_nr_selected < 2) {
10022 gtk_tree_selection_unselect_all(attach_selection);
10023 attach_nr_selected = 0;
10024 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget),
10025 event->x, event->y, &path, NULL, NULL, NULL);
10026 if (path != NULL) {
10027 gtk_tree_selection_select_path(attach_selection, path);
10028 gtk_tree_path_free(path);
10029 attach_nr_selected++;
10033 cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Remove", (attach_nr_selected > 0));
10034 /* Properties menu item makes no sense with more than one row
10035 * selected, the properties dialog can only edit one attachment. */
10036 cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Properties", (attach_nr_selected == 1));
10038 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
10039 NULL, NULL, event->button, event->time);
10046 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
10049 Compose *compose = (Compose *)data;
10051 if (!event) return FALSE;
10053 switch (event->keyval) {
10054 case GDK_KEY_Delete:
10055 compose_attach_remove_selected(NULL, compose);
10061 static void compose_allow_user_actions (Compose *compose, gboolean allow)
10063 toolbar_comp_set_sensitive(compose, allow);
10064 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message", allow);
10065 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit", allow);
10067 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", allow);
10069 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options", allow);
10070 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools", allow);
10071 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Help", allow);
10073 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
10077 static void compose_send_cb(GtkAction *action, gpointer data)
10079 Compose *compose = (Compose *)data;
10082 if (compose->exteditor_tag != -1) {
10083 debug_print("ignoring send: external editor still open\n");
10087 if (prefs_common.work_offline &&
10088 !inc_offline_should_override(TRUE,
10089 _("Claws Mail needs network access in order "
10090 "to send this email.")))
10093 if (compose->draft_timeout_tag >= 0) { /* CLAWS: disable draft timeout */
10094 g_source_remove(compose->draft_timeout_tag);
10095 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET;
10098 compose_send(compose);
10101 static void compose_send_later_cb(GtkAction *action, gpointer data)
10103 Compose *compose = (Compose *)data;
10107 compose_allow_user_actions(compose, FALSE);
10108 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
10109 compose_allow_user_actions(compose, TRUE);
10113 compose_close(compose);
10114 } else if (val == -1) {
10115 alertpanel_error(_("Could not queue message."));
10116 } else if (val == -2) {
10117 alertpanel_error(_("Could not queue message:\n\n%s."), g_strerror(errno));
10118 } else if (val == -3) {
10119 if (privacy_peek_error())
10120 alertpanel_error(_("Could not queue message for sending:\n\n"
10121 "Signature failed: %s"), privacy_get_error());
10122 } else if (val == -4) {
10123 alertpanel_error(_("Could not queue message for sending:\n\n"
10124 "Charset conversion failed."));
10125 } else if (val == -5) {
10126 alertpanel_error(_("Could not queue message for sending:\n\n"
10127 "Couldn't get recipient encryption key."));
10128 } else if (val == -6) {
10131 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
10134 #define DRAFTED_AT_EXIT "drafted_at_exit"
10135 static void compose_register_draft(MsgInfo *info)
10137 gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
10138 DRAFTED_AT_EXIT, NULL);
10139 FILE *fp = g_fopen(filepath, "ab");
10142 fprintf(fp, "%s\t%d\n", folder_item_get_identifier(info->folder),
10150 gboolean compose_draft (gpointer data, guint action)
10152 Compose *compose = (Compose *)data;
10157 MsgFlags flag = {0, 0};
10158 static gboolean lock = FALSE;
10159 MsgInfo *newmsginfo;
10161 gboolean target_locked = FALSE;
10162 gboolean err = FALSE;
10164 if (lock) return FALSE;
10166 if (compose->sending)
10169 draft = account_get_special_folder(compose->account, F_DRAFT);
10170 cm_return_val_if_fail(draft != NULL, FALSE);
10172 if (!g_mutex_trylock(compose->mutex)) {
10173 /* we don't want to lock the mutex once it's available,
10174 * because as the only other part of compose.c locking
10175 * it is compose_close - which means once unlocked,
10176 * the compose struct will be freed */
10177 debug_print("couldn't lock mutex, probably sending\n");
10183 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
10184 G_DIR_SEPARATOR, compose);
10185 if ((fp = g_fopen(tmp, "wb")) == NULL) {
10186 FILE_OP_ERROR(tmp, "fopen");
10190 /* chmod for security */
10191 if (change_file_mode_rw(fp, tmp) < 0) {
10192 FILE_OP_ERROR(tmp, "chmod");
10193 g_warning("can't change file mode");
10196 /* Save draft infos */
10197 err |= (fprintf(fp, "X-Claws-Account-Id:%d\n", compose->account->account_id) < 0);
10198 err |= (fprintf(fp, "S:%s\n", compose->account->address) < 0);
10200 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
10201 gchar *savefolderid;
10203 savefolderid = compose_get_save_to(compose);
10204 err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0);
10205 g_free(savefolderid);
10207 if (compose->return_receipt) {
10208 err |= (fprintf(fp, "RRCPT:1\n") < 0);
10210 if (compose->privacy_system) {
10211 err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
10212 err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
10213 err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0);
10216 /* Message-ID of message replying to */
10217 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
10218 gchar *folderid = NULL;
10220 if (compose->replyinfo->folder)
10221 folderid = folder_item_get_identifier(compose->replyinfo->folder);
10222 if (folderid == NULL)
10223 folderid = g_strdup("NULL");
10225 err |= (fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid) < 0);
10228 /* Message-ID of message forwarding to */
10229 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
10230 gchar *folderid = NULL;
10232 if (compose->fwdinfo->folder)
10233 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
10234 if (folderid == NULL)
10235 folderid = g_strdup("NULL");
10237 err |= (fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid) < 0);
10241 err |= (fprintf(fp, "X-Claws-Auto-Wrapping:%d\n", compose->autowrap) < 0);
10242 err |= (fprintf(fp, "X-Claws-Auto-Indent:%d\n", compose->autoindent) < 0);
10244 sheaders = compose_get_manual_headers_info(compose);
10245 err |= (fprintf(fp, "X-Claws-Manual-Headers:%s\n", sheaders) < 0);
10248 /* end of headers */
10249 err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
10256 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
10260 if (fclose(fp) == EOF) {
10264 flag.perm_flags = MSG_NEW|MSG_UNREAD;
10265 if (compose->targetinfo) {
10266 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
10268 flag.perm_flags |= MSG_LOCKED;
10270 flag.tmp_flags = MSG_DRAFT;
10272 folder_item_scan(draft);
10273 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
10274 MsgInfo *tmpinfo = NULL;
10275 debug_print("didn't get msgnum after adding draft [%s]\n", compose->msgid?compose->msgid:"no msgid");
10276 if (compose->msgid) {
10277 tmpinfo = folder_item_get_msginfo_by_msgid(draft, compose->msgid);
10280 msgnum = tmpinfo->msgnum;
10281 procmsg_msginfo_free(&tmpinfo);
10282 debug_print("got draft msgnum %d from scanning\n", msgnum);
10284 debug_print("didn't get draft msgnum after scanning\n");
10287 debug_print("got draft msgnum %d from adding\n", msgnum);
10293 if (action != COMPOSE_AUTO_SAVE) {
10294 if (action != COMPOSE_DRAFT_FOR_EXIT)
10295 alertpanel_error(_("Could not save draft."));
10298 gtkut_window_popup(compose->window);
10299 val = alertpanel_full(_("Could not save draft"),
10300 _("Could not save draft.\n"
10301 "Do you want to cancel exit or discard this email?"),
10302 _("_Cancel exit"), _("_Discard email"), NULL,
10303 FALSE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
10304 if (val == G_ALERTALTERNATE) {
10306 g_mutex_unlock(compose->mutex); /* must be done before closing */
10307 compose_close(compose);
10311 g_mutex_unlock(compose->mutex); /* must be done before closing */
10320 if (compose->mode == COMPOSE_REEDIT) {
10321 compose_remove_reedit_target(compose, TRUE);
10324 newmsginfo = folder_item_get_msginfo(draft, msgnum);
10327 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
10329 procmsg_msginfo_set_flags(newmsginfo, MSG_NEW|MSG_UNREAD|MSG_LOCKED, MSG_DRAFT);
10331 procmsg_msginfo_set_flags(newmsginfo, MSG_NEW|MSG_UNREAD, MSG_DRAFT);
10332 if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
10333 procmsg_msginfo_set_flags(newmsginfo, 0,
10334 MSG_HAS_ATTACHMENT);
10336 if (action == COMPOSE_DRAFT_FOR_EXIT) {
10337 compose_register_draft(newmsginfo);
10339 procmsg_msginfo_free(&newmsginfo);
10342 folder_item_scan(draft);
10344 if (action == COMPOSE_QUIT_EDITING || action == COMPOSE_DRAFT_FOR_EXIT) {
10346 g_mutex_unlock(compose->mutex); /* must be done before closing */
10347 compose_close(compose);
10353 path = folder_item_fetch_msg(draft, msgnum);
10354 if (path == NULL) {
10355 debug_print("can't fetch %s:%d\n", draft->path, msgnum);
10358 if (g_stat(path, &s) < 0) {
10359 FILE_OP_ERROR(path, "stat");
10365 procmsg_msginfo_free(&(compose->targetinfo));
10366 compose->targetinfo = procmsg_msginfo_new();
10367 compose->targetinfo->msgnum = msgnum;
10368 compose->targetinfo->size = (goffset)s.st_size;
10369 compose->targetinfo->mtime = s.st_mtime;
10370 compose->targetinfo->folder = draft;
10372 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
10373 compose->mode = COMPOSE_REEDIT;
10375 if (action == COMPOSE_AUTO_SAVE) {
10376 compose->autosaved_draft = compose->targetinfo;
10378 compose->modified = FALSE;
10379 compose_set_title(compose);
10383 g_mutex_unlock(compose->mutex);
10387 void compose_clear_exit_drafts(void)
10389 gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
10390 DRAFTED_AT_EXIT, NULL);
10391 if (is_file_exist(filepath))
10392 claws_unlink(filepath);
10397 void compose_reopen_exit_drafts(void)
10399 gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
10400 DRAFTED_AT_EXIT, NULL);
10401 FILE *fp = g_fopen(filepath, "rb");
10405 while (fgets(buf, sizeof(buf), fp)) {
10406 gchar **parts = g_strsplit(buf, "\t", 2);
10407 const gchar *folder = parts[0];
10408 int msgnum = parts[1] ? atoi(parts[1]):-1;
10410 if (folder && *folder && msgnum > -1) {
10411 FolderItem *item = folder_find_item_from_identifier(folder);
10412 MsgInfo *info = folder_item_get_msginfo(item, msgnum);
10414 compose_reedit(info, FALSE);
10421 compose_clear_exit_drafts();
10424 static void compose_save_cb(GtkAction *action, gpointer data)
10426 Compose *compose = (Compose *)data;
10427 compose_draft(compose, COMPOSE_KEEP_EDITING);
10428 compose->rmode = COMPOSE_REEDIT;
10431 void compose_attach_from_list(Compose *compose, GList *file_list, gboolean free_data)
10433 if (compose && file_list) {
10436 for ( tmp = file_list; tmp; tmp = tmp->next) {
10437 gchar *file = (gchar *) tmp->data;
10438 gchar *utf8_filename = conv_filename_to_utf8(file);
10439 compose_attach_append(compose, file, utf8_filename, NULL, NULL);
10440 compose_changed_cb(NULL, compose);
10445 g_free(utf8_filename);
10450 static void compose_attach_cb(GtkAction *action, gpointer data)
10452 Compose *compose = (Compose *)data;
10455 if (compose->redirect_filename != NULL)
10458 /* Set focus_window properly, in case we were called via popup menu,
10459 * which unsets it (via focus_out_event callback on compose window). */
10460 manage_window_focus_in(compose->window, NULL, NULL);
10462 file_list = filesel_select_multiple_files_open(_("Select file"), NULL);
10465 compose_attach_from_list(compose, file_list, TRUE);
10466 g_list_free(file_list);
10470 static void compose_insert_file_cb(GtkAction *action, gpointer data)
10472 Compose *compose = (Compose *)data;
10474 gint files_inserted = 0;
10476 file_list = filesel_select_multiple_files_open(_("Select file"), NULL);
10481 for ( tmp = file_list; tmp; tmp = tmp->next) {
10482 gchar *file = (gchar *) tmp->data;
10483 gchar *filedup = g_strdup(file);
10484 gchar *shortfile = g_path_get_basename(filedup);
10485 ComposeInsertResult res;
10486 /* insert the file if the file is short or if the user confirmed that
10487 he/she wants to insert the large file */
10488 res = compose_insert_file(compose, file);
10489 if (res == COMPOSE_INSERT_READ_ERROR) {
10490 alertpanel_error(_("File '%s' could not be read."), shortfile);
10491 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
10492 alertpanel_error(_("File '%s' contained invalid characters\n"
10493 "for the current encoding, insertion may be incorrect."),
10495 } else if (res == COMPOSE_INSERT_SUCCESS)
10502 g_list_free(file_list);
10506 if (files_inserted > 0 && compose->gtkaspell &&
10507 compose->gtkaspell->check_while_typing)
10508 gtkaspell_highlight_all(compose->gtkaspell);
10512 static void compose_insert_sig_cb(GtkAction *action, gpointer data)
10514 Compose *compose = (Compose *)data;
10516 compose_insert_sig(compose, FALSE);
10519 static void compose_replace_sig_cb(GtkAction *action, gpointer data)
10521 Compose *compose = (Compose *)data;
10523 compose_insert_sig(compose, TRUE);
10526 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
10530 Compose *compose = (Compose *)data;
10532 gtkut_widget_get_uposition(widget, &x, &y);
10533 if (!compose->batch) {
10534 prefs_common.compose_x = x;
10535 prefs_common.compose_y = y;
10537 if (compose->sending || compose->updating)
10539 compose_close_cb(NULL, compose);
10543 void compose_close_toolbar(Compose *compose)
10545 compose_close_cb(NULL, compose);
10548 static void compose_close_cb(GtkAction *action, gpointer data)
10550 Compose *compose = (Compose *)data;
10554 if (compose->exteditor_tag != -1) {
10555 if (!compose_ext_editor_kill(compose))
10560 if (compose->modified) {
10561 gboolean reedit = (compose->rmode == COMPOSE_REEDIT);
10562 if (!g_mutex_trylock(compose->mutex)) {
10563 /* we don't want to lock the mutex once it's available,
10564 * because as the only other part of compose.c locking
10565 * it is compose_close - which means once unlocked,
10566 * the compose struct will be freed */
10567 debug_print("couldn't lock mutex, probably sending\n");
10571 val = alertpanel(_("Discard message"),
10572 _("This message has been modified. Discard it?"),
10573 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
10575 val = alertpanel(_("Save changes"),
10576 _("This message has been modified. Save the latest changes?"),
10577 _("_Don't save"), g_strconcat("+", _("_Save to Drafts"), NULL),
10580 g_mutex_unlock(compose->mutex);
10582 case G_ALERTDEFAULT:
10583 if (compose_can_autosave(compose) && !reedit)
10584 compose_remove_draft(compose);
10586 case G_ALERTALTERNATE:
10587 compose_draft(data, COMPOSE_QUIT_EDITING);
10594 compose_close(compose);
10597 static void compose_print_cb(GtkAction *action, gpointer data)
10599 Compose *compose = (Compose *) data;
10601 compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
10602 if (compose->targetinfo)
10603 messageview_print(compose->targetinfo, FALSE, -1, -1, 0);
10606 static void compose_set_encoding_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
10608 gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
10609 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
10610 Compose *compose = (Compose *) data;
10613 compose->out_encoding = (CharSet)value;
10616 static void compose_address_cb(GtkAction *action, gpointer data)
10618 Compose *compose = (Compose *)data;
10620 #ifndef USE_ALT_ADDRBOOK
10621 addressbook_open(compose);
10623 GError* error = NULL;
10624 addressbook_connect_signals(compose);
10625 addressbook_dbus_open(TRUE, &error);
10627 g_warning("%s", error->message);
10628 g_error_free(error);
10633 static void about_show_cb(GtkAction *action, gpointer data)
10638 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
10640 Compose *compose = (Compose *)data;
10645 tmpl = g_object_get_data(G_OBJECT(widget), "template");
10646 cm_return_if_fail(tmpl != NULL);
10648 msg = g_strdup_printf(_("Do you want to apply the template '%s'?"),
10650 val = alertpanel(_("Apply template"), msg,
10651 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
10654 if (val == G_ALERTDEFAULT)
10655 compose_template_apply(compose, tmpl, TRUE);
10656 else if (val == G_ALERTALTERNATE)
10657 compose_template_apply(compose, tmpl, FALSE);
10660 static void compose_ext_editor_cb(GtkAction *action, gpointer data)
10662 Compose *compose = (Compose *)data;
10665 if (compose->exteditor_tag != -1) {
10666 debug_print("ignoring open external editor: external editor still open\n");
10670 compose_exec_ext_editor(compose);
10673 static void compose_undo_cb(GtkAction *action, gpointer data)
10675 Compose *compose = (Compose *)data;
10676 gboolean prev_autowrap = compose->autowrap;
10678 compose->autowrap = FALSE;
10679 undo_undo(compose->undostruct);
10680 compose->autowrap = prev_autowrap;
10683 static void compose_redo_cb(GtkAction *action, gpointer data)
10685 Compose *compose = (Compose *)data;
10686 gboolean prev_autowrap = compose->autowrap;
10688 compose->autowrap = FALSE;
10689 undo_redo(compose->undostruct);
10690 compose->autowrap = prev_autowrap;
10693 static void entry_cut_clipboard(GtkWidget *entry)
10695 if (GTK_IS_EDITABLE(entry))
10696 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
10697 else if (GTK_IS_TEXT_VIEW(entry))
10698 gtk_text_buffer_cut_clipboard(
10699 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
10700 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
10704 static void entry_copy_clipboard(GtkWidget *entry)
10706 if (GTK_IS_EDITABLE(entry))
10707 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
10708 else if (GTK_IS_TEXT_VIEW(entry))
10709 gtk_text_buffer_copy_clipboard(
10710 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
10711 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
10714 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
10715 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
10717 if (GTK_IS_TEXT_VIEW(entry)) {
10718 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
10719 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
10720 GtkTextIter start_iter, end_iter;
10722 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
10724 if (contents == NULL)
10727 /* we shouldn't delete the selection when middle-click-pasting, or we
10728 * can't mid-click-paste our own selection */
10729 if (clip != GDK_SELECTION_PRIMARY) {
10730 undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);
10731 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
10734 if (insert_place == NULL) {
10735 /* if insert_place isn't specified, insert at the cursor.
10736 * used for Ctrl-V pasting */
10737 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
10738 start = gtk_text_iter_get_offset(&start_iter);
10739 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
10741 /* if insert_place is specified, paste here.
10742 * used for mid-click-pasting */
10743 start = gtk_text_iter_get_offset(insert_place);
10744 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
10745 if (prefs_common.primary_paste_unselects)
10746 gtk_text_buffer_select_range(buffer, insert_place, insert_place);
10750 /* paste unwrapped: mark the paste so it's not wrapped later */
10751 end = start + strlen(contents);
10752 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
10753 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
10754 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
10755 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
10756 /* rewrap paragraph now (after a mid-click-paste) */
10757 mark_start = gtk_text_buffer_get_insert(buffer);
10758 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
10759 gtk_text_iter_backward_char(&start_iter);
10760 compose_beautify_paragraph(compose, &start_iter, TRUE);
10762 } else if (GTK_IS_EDITABLE(entry))
10763 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
10765 compose->modified = TRUE;
10768 static void entry_allsel(GtkWidget *entry)
10770 if (GTK_IS_EDITABLE(entry))
10771 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
10772 else if (GTK_IS_TEXT_VIEW(entry)) {
10773 GtkTextIter startiter, enditer;
10774 GtkTextBuffer *textbuf;
10776 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
10777 gtk_text_buffer_get_start_iter(textbuf, &startiter);
10778 gtk_text_buffer_get_end_iter(textbuf, &enditer);
10780 gtk_text_buffer_move_mark_by_name(textbuf,
10781 "selection_bound", &startiter);
10782 gtk_text_buffer_move_mark_by_name(textbuf,
10783 "insert", &enditer);
10787 static void compose_cut_cb(GtkAction *action, gpointer data)
10789 Compose *compose = (Compose *)data;
10790 if (compose->focused_editable
10791 #ifndef GENERIC_UMPC
10792 && gtk_widget_has_focus(compose->focused_editable)
10795 entry_cut_clipboard(compose->focused_editable);
10798 static void compose_copy_cb(GtkAction *action, gpointer data)
10800 Compose *compose = (Compose *)data;
10801 if (compose->focused_editable
10802 #ifndef GENERIC_UMPC
10803 && gtk_widget_has_focus(compose->focused_editable)
10806 entry_copy_clipboard(compose->focused_editable);
10809 static void compose_paste_cb(GtkAction *action, gpointer data)
10811 Compose *compose = (Compose *)data;
10812 gint prev_autowrap;
10813 GtkTextBuffer *buffer;
10815 if (compose->focused_editable &&
10816 #ifndef GENERIC_UMPC
10817 gtk_widget_has_focus(compose->focused_editable)
10820 entry_paste_clipboard(compose, compose->focused_editable,
10821 prefs_common.linewrap_pastes,
10822 GDK_SELECTION_CLIPBOARD, NULL);
10827 #ifndef GENERIC_UMPC
10828 gtk_widget_has_focus(compose->text) &&
10830 compose->gtkaspell &&
10831 compose->gtkaspell->check_while_typing)
10832 gtkaspell_highlight_all(compose->gtkaspell);
10836 static void compose_paste_as_quote_cb(GtkAction *action, gpointer data)
10838 Compose *compose = (Compose *)data;
10839 gint wrap_quote = prefs_common.linewrap_quote;
10840 if (compose->focused_editable
10841 #ifndef GENERIC_UMPC
10842 && gtk_widget_has_focus(compose->focused_editable)
10845 /* let text_insert() (called directly or at a later time
10846 * after the gtk_editable_paste_clipboard) know that
10847 * text is to be inserted as a quotation. implemented
10848 * by using a simple refcount... */
10849 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
10850 G_OBJECT(compose->focused_editable),
10851 "paste_as_quotation"));
10852 g_object_set_data(G_OBJECT(compose->focused_editable),
10853 "paste_as_quotation",
10854 GINT_TO_POINTER(paste_as_quotation + 1));
10855 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
10856 entry_paste_clipboard(compose, compose->focused_editable,
10857 prefs_common.linewrap_pastes,
10858 GDK_SELECTION_CLIPBOARD, NULL);
10859 prefs_common.linewrap_quote = wrap_quote;
10863 static void compose_paste_no_wrap_cb(GtkAction *action, gpointer data)
10865 Compose *compose = (Compose *)data;
10866 gint prev_autowrap;
10867 GtkTextBuffer *buffer;
10869 if (compose->focused_editable
10870 #ifndef GENERIC_UMPC
10871 && gtk_widget_has_focus(compose->focused_editable)
10874 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
10875 GDK_SELECTION_CLIPBOARD, NULL);
10880 #ifndef GENERIC_UMPC
10881 gtk_widget_has_focus(compose->text) &&
10883 compose->gtkaspell &&
10884 compose->gtkaspell->check_while_typing)
10885 gtkaspell_highlight_all(compose->gtkaspell);
10889 static void compose_paste_wrap_cb(GtkAction *action, gpointer data)
10891 Compose *compose = (Compose *)data;
10892 gint prev_autowrap;
10893 GtkTextBuffer *buffer;
10895 if (compose->focused_editable
10896 #ifndef GENERIC_UMPC
10897 && gtk_widget_has_focus(compose->focused_editable)
10900 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
10901 GDK_SELECTION_CLIPBOARD, NULL);
10906 #ifndef GENERIC_UMPC
10907 gtk_widget_has_focus(compose->text) &&
10909 compose->gtkaspell &&
10910 compose->gtkaspell->check_while_typing)
10911 gtkaspell_highlight_all(compose->gtkaspell);
10915 static void compose_allsel_cb(GtkAction *action, gpointer data)
10917 Compose *compose = (Compose *)data;
10918 if (compose->focused_editable
10919 #ifndef GENERIC_UMPC
10920 && gtk_widget_has_focus(compose->focused_editable)
10923 entry_allsel(compose->focused_editable);
10926 static void textview_move_beginning_of_line (GtkTextView *text)
10928 GtkTextBuffer *buffer;
10932 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
10934 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
10935 mark = gtk_text_buffer_get_insert(buffer);
10936 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
10937 gtk_text_iter_set_line_offset(&ins, 0);
10938 gtk_text_buffer_place_cursor(buffer, &ins);
10941 static void textview_move_forward_character (GtkTextView *text)
10943 GtkTextBuffer *buffer;
10947 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
10949 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
10950 mark = gtk_text_buffer_get_insert(buffer);
10951 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
10952 if (gtk_text_iter_forward_cursor_position(&ins))
10953 gtk_text_buffer_place_cursor(buffer, &ins);
10956 static void textview_move_backward_character (GtkTextView *text)
10958 GtkTextBuffer *buffer;
10962 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
10964 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
10965 mark = gtk_text_buffer_get_insert(buffer);
10966 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
10967 if (gtk_text_iter_backward_cursor_position(&ins))
10968 gtk_text_buffer_place_cursor(buffer, &ins);
10971 static void textview_move_forward_word (GtkTextView *text)
10973 GtkTextBuffer *buffer;
10978 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
10980 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
10981 mark = gtk_text_buffer_get_insert(buffer);
10982 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
10983 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
10984 if (gtk_text_iter_forward_word_ends(&ins, count)) {
10985 gtk_text_iter_backward_word_start(&ins);
10986 gtk_text_buffer_place_cursor(buffer, &ins);
10990 static void textview_move_backward_word (GtkTextView *text)
10992 GtkTextBuffer *buffer;
10996 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
10998 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
10999 mark = gtk_text_buffer_get_insert(buffer);
11000 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11001 if (gtk_text_iter_backward_word_starts(&ins, 1))
11002 gtk_text_buffer_place_cursor(buffer, &ins);
11005 static void textview_move_end_of_line (GtkTextView *text)
11007 GtkTextBuffer *buffer;
11011 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11013 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11014 mark = gtk_text_buffer_get_insert(buffer);
11015 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11016 if (gtk_text_iter_forward_to_line_end(&ins))
11017 gtk_text_buffer_place_cursor(buffer, &ins);
11020 static void textview_move_next_line (GtkTextView *text)
11022 GtkTextBuffer *buffer;
11027 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11029 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11030 mark = gtk_text_buffer_get_insert(buffer);
11031 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11032 offset = gtk_text_iter_get_line_offset(&ins);
11033 if (gtk_text_iter_forward_line(&ins)) {
11034 gtk_text_iter_set_line_offset(&ins, offset);
11035 gtk_text_buffer_place_cursor(buffer, &ins);
11039 static void textview_move_previous_line (GtkTextView *text)
11041 GtkTextBuffer *buffer;
11046 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11048 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11049 mark = gtk_text_buffer_get_insert(buffer);
11050 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11051 offset = gtk_text_iter_get_line_offset(&ins);
11052 if (gtk_text_iter_backward_line(&ins)) {
11053 gtk_text_iter_set_line_offset(&ins, offset);
11054 gtk_text_buffer_place_cursor(buffer, &ins);
11058 static void textview_delete_forward_character (GtkTextView *text)
11060 GtkTextBuffer *buffer;
11062 GtkTextIter ins, end_iter;
11064 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11066 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11067 mark = gtk_text_buffer_get_insert(buffer);
11068 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11070 if (gtk_text_iter_forward_char(&end_iter)) {
11071 gtk_text_buffer_delete(buffer, &ins, &end_iter);
11075 static void textview_delete_backward_character (GtkTextView *text)
11077 GtkTextBuffer *buffer;
11079 GtkTextIter ins, end_iter;
11081 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11083 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11084 mark = gtk_text_buffer_get_insert(buffer);
11085 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11087 if (gtk_text_iter_backward_char(&end_iter)) {
11088 gtk_text_buffer_delete(buffer, &end_iter, &ins);
11092 static void textview_delete_forward_word (GtkTextView *text)
11094 GtkTextBuffer *buffer;
11096 GtkTextIter ins, end_iter;
11098 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11100 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11101 mark = gtk_text_buffer_get_insert(buffer);
11102 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11104 if (gtk_text_iter_forward_word_end(&end_iter)) {
11105 gtk_text_buffer_delete(buffer, &ins, &end_iter);
11109 static void textview_delete_backward_word (GtkTextView *text)
11111 GtkTextBuffer *buffer;
11113 GtkTextIter ins, end_iter;
11115 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11117 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11118 mark = gtk_text_buffer_get_insert(buffer);
11119 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11121 if (gtk_text_iter_backward_word_start(&end_iter)) {
11122 gtk_text_buffer_delete(buffer, &end_iter, &ins);
11126 static void textview_delete_line (GtkTextView *text)
11128 GtkTextBuffer *buffer;
11130 GtkTextIter ins, start_iter, end_iter;
11132 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11134 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11135 mark = gtk_text_buffer_get_insert(buffer);
11136 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11139 gtk_text_iter_set_line_offset(&start_iter, 0);
11142 if (gtk_text_iter_ends_line(&end_iter)){
11143 if (!gtk_text_iter_forward_char(&end_iter))
11144 gtk_text_iter_backward_char(&start_iter);
11147 gtk_text_iter_forward_to_line_end(&end_iter);
11148 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
11151 static void textview_delete_to_line_end (GtkTextView *text)
11153 GtkTextBuffer *buffer;
11155 GtkTextIter ins, end_iter;
11157 cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
11159 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
11160 mark = gtk_text_buffer_get_insert(buffer);
11161 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
11163 if (gtk_text_iter_ends_line(&end_iter))
11164 gtk_text_iter_forward_char(&end_iter);
11166 gtk_text_iter_forward_to_line_end(&end_iter);
11167 gtk_text_buffer_delete(buffer, &ins, &end_iter);
11170 #define DO_ACTION(name, act) { \
11171 if(!strcmp(name, a_name)) { \
11175 static ComposeCallAdvancedAction compose_call_advanced_action_from_path(GtkAction *action)
11177 const gchar *a_name = gtk_action_get_name(action);
11178 DO_ACTION("Edit/Advanced/BackChar", COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER);
11179 DO_ACTION("Edit/Advanced/ForwChar", COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER);
11180 DO_ACTION("Edit/Advanced/BackWord", COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD);
11181 DO_ACTION("Edit/Advanced/ForwWord", COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD);
11182 DO_ACTION("Edit/Advanced/BegLine", COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE);
11183 DO_ACTION("Edit/Advanced/EndLine", COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE);
11184 DO_ACTION("Edit/Advanced/PrevLine", COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE);
11185 DO_ACTION("Edit/Advanced/NextLine", COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE);
11186 DO_ACTION("Edit/Advanced/DelBackChar", COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER);
11187 DO_ACTION("Edit/Advanced/DelForwChar", COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER);
11188 DO_ACTION("Edit/Advanced/DelBackWord", COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD);
11189 DO_ACTION("Edit/Advanced/DelForwWord", COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD);
11190 DO_ACTION("Edit/Advanced/DelLine", COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE);
11191 DO_ACTION("Edit/Advanced/DelEndLine", COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END);
11192 return COMPOSE_CALL_ADVANCED_ACTION_UNDEFINED;
11195 static void compose_advanced_action_cb(GtkAction *gaction, gpointer data)
11197 Compose *compose = (Compose *)data;
11198 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
11199 ComposeCallAdvancedAction action = COMPOSE_CALL_ADVANCED_ACTION_UNDEFINED;
11201 action = compose_call_advanced_action_from_path(gaction);
11204 void (*do_action) (GtkTextView *text);
11205 } action_table[] = {
11206 {textview_move_beginning_of_line},
11207 {textview_move_forward_character},
11208 {textview_move_backward_character},
11209 {textview_move_forward_word},
11210 {textview_move_backward_word},
11211 {textview_move_end_of_line},
11212 {textview_move_next_line},
11213 {textview_move_previous_line},
11214 {textview_delete_forward_character},
11215 {textview_delete_backward_character},
11216 {textview_delete_forward_word},
11217 {textview_delete_backward_word},
11218 {textview_delete_line},
11219 {textview_delete_to_line_end}
11222 if (!gtk_widget_has_focus(GTK_WIDGET(text))) return;
11224 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
11225 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
11226 if (action_table[action].do_action)
11227 action_table[action].do_action(text);
11229 g_warning("Not implemented yet.");
11233 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
11235 GtkAllocation allocation;
11239 if (GTK_IS_EDITABLE(widget)) {
11240 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
11241 gtk_editable_set_position(GTK_EDITABLE(widget),
11244 if ((parent = gtk_widget_get_parent(widget))
11245 && (parent = gtk_widget_get_parent(parent))
11246 && (parent = gtk_widget_get_parent(parent))) {
11247 if (GTK_IS_SCROLLED_WINDOW(parent)) {
11248 gtk_widget_get_allocation(widget, &allocation);
11249 gint y = allocation.y;
11250 gint height = allocation.height;
11251 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
11252 (GTK_SCROLLED_WINDOW(parent));
11254 gfloat value = gtk_adjustment_get_value(shown);
11255 gfloat upper = gtk_adjustment_get_upper(shown);
11256 gfloat page_size = gtk_adjustment_get_page_size(shown);
11257 if (y < (int)value) {
11258 gtk_adjustment_set_value(shown, y - 1);
11260 if ((y + height) > ((int)value + (int)page_size)) {
11261 if ((y - height - 1) < ((int)upper - (int)page_size)) {
11262 gtk_adjustment_set_value(shown,
11263 y + height - (int)page_size - 1);
11265 gtk_adjustment_set_value(shown,
11266 (int)upper - (int)page_size - 1);
11273 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
11274 compose->focused_editable = widget;
11276 #ifdef GENERIC_UMPC
11277 if (GTK_IS_TEXT_VIEW(widget)
11278 && gtk_paned_get_child1(GTK_PANED(compose->paned)) != compose->edit_vbox) {
11279 g_object_ref(compose->notebook);
11280 g_object_ref(compose->edit_vbox);
11281 gtk_container_remove(GTK_CONTAINER(compose->paned), compose->notebook);
11282 gtk_container_remove(GTK_CONTAINER(compose->paned), compose->edit_vbox);
11283 gtk_paned_add1(GTK_PANED(compose->paned), compose->edit_vbox);
11284 gtk_paned_add2(GTK_PANED(compose->paned), compose->notebook);
11285 g_object_unref(compose->notebook);
11286 g_object_unref(compose->edit_vbox);
11287 g_signal_handlers_block_by_func(G_OBJECT(widget),
11288 G_CALLBACK(compose_grab_focus_cb),
11290 gtk_widget_grab_focus(widget);
11291 g_signal_handlers_unblock_by_func(G_OBJECT(widget),
11292 G_CALLBACK(compose_grab_focus_cb),
11294 } else if (!GTK_IS_TEXT_VIEW(widget)
11295 && gtk_paned_get_child1(GTK_PANED(compose->paned)) != compose->notebook) {
11296 g_object_ref(compose->notebook);
11297 g_object_ref(compose->edit_vbox);
11298 gtk_container_remove(GTK_CONTAINER(compose->paned), compose->notebook);
11299 gtk_container_remove(GTK_CONTAINER(compose->paned), compose->edit_vbox);
11300 gtk_paned_add1(GTK_PANED(compose->paned), compose->notebook);
11301 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
11302 g_object_unref(compose->notebook);
11303 g_object_unref(compose->edit_vbox);
11304 g_signal_handlers_block_by_func(G_OBJECT(widget),
11305 G_CALLBACK(compose_grab_focus_cb),
11307 gtk_widget_grab_focus(widget);
11308 g_signal_handlers_unblock_by_func(G_OBJECT(widget),
11309 G_CALLBACK(compose_grab_focus_cb),
11315 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
11317 compose->modified = TRUE;
11318 /* compose_beautify_paragraph(compose, NULL, TRUE); */
11319 #ifndef GENERIC_UMPC
11320 compose_set_title(compose);
11324 static void compose_wrap_cb(GtkAction *action, gpointer data)
11326 Compose *compose = (Compose *)data;
11327 compose_beautify_paragraph(compose, NULL, TRUE);
11330 static void compose_wrap_all_cb(GtkAction *action, gpointer data)
11332 Compose *compose = (Compose *)data;
11333 compose_wrap_all_full(compose, TRUE);
11336 static void compose_find_cb(GtkAction *action, gpointer data)
11338 Compose *compose = (Compose *)data;
11340 message_search_compose(compose);
11343 static void compose_toggle_autowrap_cb(GtkToggleAction *action,
11346 Compose *compose = (Compose *)data;
11347 compose->autowrap = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
11348 if (compose->autowrap)
11349 compose_wrap_all_full(compose, TRUE);
11350 compose->autowrap = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
11353 static void compose_toggle_autoindent_cb(GtkToggleAction *action,
11356 Compose *compose = (Compose *)data;
11357 compose->autoindent = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
11360 static void compose_toggle_sign_cb(GtkToggleAction *action, gpointer data)
11362 Compose *compose = (Compose *)data;
11364 compose->use_signing = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
11367 static void compose_toggle_encrypt_cb(GtkToggleAction *action, gpointer data)
11369 Compose *compose = (Compose *)data;
11371 compose->use_encryption = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
11374 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
11376 g_free(compose->privacy_system);
11377 g_free(compose->encdata);
11379 compose->privacy_system = g_strdup(account->default_privacy_system);
11380 compose_update_privacy_system_menu_item(compose, warn);
11383 static void compose_toggle_ruler_cb(GtkToggleAction *action, gpointer data)
11385 Compose *compose = (Compose *)data;
11387 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
11388 gtk_widget_show(compose->ruler_hbox);
11389 prefs_common.show_ruler = TRUE;
11391 gtk_widget_hide(compose->ruler_hbox);
11392 gtk_widget_queue_resize(compose->edit_vbox);
11393 prefs_common.show_ruler = FALSE;
11397 static void compose_attach_drag_received_cb (GtkWidget *widget,
11398 GdkDragContext *context,
11401 GtkSelectionData *data,
11404 gpointer user_data)
11406 Compose *compose = (Compose *)user_data;
11410 type = gtk_selection_data_get_data_type(data);
11411 if ((gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "text/uri-list"))
11412 && gtk_drag_get_source_widget(context) !=
11413 summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
11414 list = uri_list_extract_filenames(
11415 (const gchar *)gtk_selection_data_get_data(data));
11416 for (tmp = list; tmp != NULL; tmp = tmp->next) {
11417 gchar *utf8_filename = conv_filename_to_utf8((const gchar *)tmp->data);
11418 compose_attach_append
11419 (compose, (const gchar *)tmp->data,
11420 utf8_filename, NULL, NULL);
11421 g_free(utf8_filename);
11423 if (list) compose_changed_cb(NULL, compose);
11424 list_free_strings(list);
11426 } else if (gtk_drag_get_source_widget(context)
11427 == summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
11428 /* comes from our summaryview */
11429 SummaryView * summaryview = NULL;
11430 GSList * list = NULL, *cur = NULL;
11432 if (mainwindow_get_mainwindow())
11433 summaryview = mainwindow_get_mainwindow()->summaryview;
11436 list = summary_get_selected_msg_list(summaryview);
11438 for (cur = list; cur; cur = cur->next) {
11439 MsgInfo *msginfo = (MsgInfo *)cur->data;
11440 gchar *file = NULL;
11442 file = procmsg_get_message_file_full(msginfo,
11445 compose_attach_append(compose, (const gchar *)file,
11446 (const gchar *)file, "message/rfc822", NULL);
11450 g_slist_free(list);
11454 static gboolean compose_drag_drop(GtkWidget *widget,
11455 GdkDragContext *drag_context,
11457 guint time, gpointer user_data)
11459 /* not handling this signal makes compose_insert_drag_received_cb
11464 static gboolean completion_set_focus_to_subject
11465 (GtkWidget *widget,
11466 GdkEventKey *event,
11469 cm_return_val_if_fail(compose != NULL, FALSE);
11471 /* make backtab move to subject field */
11472 if(event->keyval == GDK_KEY_ISO_Left_Tab) {
11473 gtk_widget_grab_focus(compose->subject_entry);
11479 static void compose_insert_drag_received_cb (GtkWidget *widget,
11480 GdkDragContext *drag_context,
11483 GtkSelectionData *data,
11486 gpointer user_data)
11488 Compose *compose = (Compose *)user_data;
11494 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
11496 type = gtk_selection_data_get_data_type(data);
11497 if (gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "text/uri-list")) {
11498 AlertValue val = G_ALERTDEFAULT;
11499 const gchar* ddata = (const gchar *)gtk_selection_data_get_data(data);
11501 list = uri_list_extract_filenames(ddata);
11502 num_files = g_list_length(list);
11503 if (list == NULL && strstr(ddata, "://")) {
11504 /* Assume a list of no files, and data has ://, is a remote link */
11505 gchar *tmpdata = g_strstrip(g_strdup(ddata));
11506 gchar *tmpfile = get_tmp_file();
11507 str_write_to_file(tmpdata, tmpfile);
11509 compose_insert_file(compose, tmpfile);
11510 claws_unlink(tmpfile);
11512 gtk_drag_finish(drag_context, TRUE, FALSE, time);
11513 compose_beautify_paragraph(compose, NULL, TRUE);
11516 switch (prefs_common.compose_dnd_mode) {
11517 case COMPOSE_DND_ASK:
11518 msg = g_strdup_printf(
11520 "Do you want to insert the contents of the file "
11521 "into the message body, or attach it to the email?",
11522 "Do you want to insert the contents of the %d files "
11523 "into the message body, or attach them to the email?",
11526 val = alertpanel_full(_("Insert or attach?"), msg,
11527 GTK_STOCK_CANCEL, g_strconcat("+", _("_Insert"), NULL), _("_Attach"),
11528 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
11531 case COMPOSE_DND_INSERT:
11532 val = G_ALERTALTERNATE;
11534 case COMPOSE_DND_ATTACH:
11535 val = G_ALERTOTHER;
11538 /* unexpected case */
11539 g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
11542 if (val & G_ALERTDISABLE) {
11543 val &= ~G_ALERTDISABLE;
11544 /* remember what action to perform by default, only if we don't click Cancel */
11545 if (val == G_ALERTALTERNATE)
11546 prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
11547 else if (val == G_ALERTOTHER)
11548 prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
11551 if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
11552 gtk_drag_finish(drag_context, FALSE, FALSE, time);
11553 list_free_strings(list);
11556 } else if (val == G_ALERTOTHER) {
11557 compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
11558 list_free_strings(list);
11563 for (tmp = list; tmp != NULL; tmp = tmp->next) {
11564 compose_insert_file(compose, (const gchar *)tmp->data);
11566 list_free_strings(list);
11568 gtk_drag_finish(drag_context, TRUE, FALSE, time);
11573 static void compose_header_drag_received_cb (GtkWidget *widget,
11574 GdkDragContext *drag_context,
11577 GtkSelectionData *data,
11580 gpointer user_data)
11582 GtkEditable *entry = (GtkEditable *)user_data;
11583 const gchar *email = (const gchar *)gtk_selection_data_get_data(data);
11585 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
11588 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
11589 gchar *decoded=g_new(gchar, strlen(email));
11592 decode_uri(decoded, email + strlen("mailto:")); /* will fit */
11593 gtk_editable_delete_text(entry, 0, -1);
11594 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
11595 gtk_drag_finish(drag_context, TRUE, FALSE, time);
11599 gtk_drag_finish(drag_context, TRUE, FALSE, time);
11602 static void compose_toggle_return_receipt_cb(GtkToggleAction *action, gpointer data)
11604 Compose *compose = (Compose *)data;
11606 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
11607 compose->return_receipt = TRUE;
11609 compose->return_receipt = FALSE;
11612 static void compose_toggle_remove_refs_cb(GtkToggleAction *action, gpointer data)
11614 Compose *compose = (Compose *)data;
11616 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
11617 compose->remove_references = TRUE;
11619 compose->remove_references = FALSE;
11622 static gboolean compose_headerentry_button_clicked_cb (GtkWidget *button,
11623 ComposeHeaderEntry *headerentry)
11625 gtk_entry_set_text(GTK_ENTRY(headerentry->entry), "");
11629 static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
11630 GdkEventKey *event,
11631 ComposeHeaderEntry *headerentry)
11633 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
11634 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
11635 !(event->state & GDK_MODIFIER_MASK) &&
11636 (event->keyval == GDK_KEY_BackSpace) &&
11637 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
11638 gtk_container_remove
11639 (GTK_CONTAINER(headerentry->compose->header_table),
11640 headerentry->combo);
11641 gtk_container_remove
11642 (GTK_CONTAINER(headerentry->compose->header_table),
11643 headerentry->entry);
11644 headerentry->compose->header_list =
11645 g_slist_remove(headerentry->compose->header_list,
11647 g_free(headerentry);
11648 } else if (event->keyval == GDK_KEY_Tab) {
11649 if (headerentry->compose->header_last == headerentry) {
11650 /* Override default next focus, and give it to subject_entry
11651 * instead of notebook tabs
11653 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
11654 gtk_widget_grab_focus(headerentry->compose->subject_entry);
11661 static gboolean scroll_postpone(gpointer data)
11663 Compose *compose = (Compose *)data;
11665 if (compose->batch)
11668 GTK_EVENTS_FLUSH();
11669 compose_show_first_last_header(compose, FALSE);
11673 static void compose_headerentry_changed_cb(GtkWidget *entry,
11674 ComposeHeaderEntry *headerentry)
11676 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
11677 compose_create_header_entry(headerentry->compose);
11678 g_signal_handlers_disconnect_matched
11679 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
11680 0, 0, NULL, NULL, headerentry);
11682 if (!headerentry->compose->batch)
11683 g_timeout_add(0, scroll_postpone, headerentry->compose);
11687 static gboolean compose_defer_auto_save_draft(Compose *compose)
11689 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET;
11690 compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
11694 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
11696 GtkAdjustment *vadj;
11698 cm_return_if_fail(compose);
11703 cm_return_if_fail(GTK_IS_WIDGET(compose->header_table));
11704 cm_return_if_fail(GTK_IS_VIEWPORT(gtk_widget_get_parent(compose->header_table)));
11705 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(
11706 gtk_widget_get_parent(compose->header_table)));
11707 gtk_adjustment_set_value(vadj, (show_first ?
11708 gtk_adjustment_get_lower(vadj) :
11709 (gtk_adjustment_get_upper(vadj) -
11710 gtk_adjustment_get_page_size(vadj))));
11711 gtk_adjustment_changed(vadj);
11714 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
11715 const gchar *text, gint len, Compose *compose)
11717 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
11718 (G_OBJECT(compose->text), "paste_as_quotation"));
11721 cm_return_if_fail(text != NULL);
11723 g_signal_handlers_block_by_func(G_OBJECT(buffer),
11724 G_CALLBACK(text_inserted),
11726 if (paste_as_quotation) {
11728 const gchar *qmark;
11730 GtkTextIter start_iter;
11733 len = strlen(text);
11735 new_text = g_strndup(text, len);
11737 qmark = compose_quote_char_from_context(compose);
11739 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
11740 gtk_text_buffer_place_cursor(buffer, iter);
11742 pos = gtk_text_iter_get_offset(iter);
11744 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE, FALSE,
11745 _("Quote format error at line %d."));
11746 quote_fmt_reset_vartable();
11748 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
11749 GINT_TO_POINTER(paste_as_quotation - 1));
11751 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
11752 gtk_text_buffer_place_cursor(buffer, iter);
11753 gtk_text_buffer_delete_mark(buffer, mark);
11755 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, pos);
11756 mark = gtk_text_buffer_create_mark(buffer, NULL, &start_iter, FALSE);
11757 compose_beautify_paragraph(compose, &start_iter, FALSE);
11758 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark);
11759 gtk_text_buffer_delete_mark(buffer, mark);
11761 if (strcmp(text, "\n") || compose->automatic_break
11762 || gtk_text_iter_starts_line(iter)) {
11763 GtkTextIter before_ins;
11764 gtk_text_buffer_insert(buffer, iter, text, len);
11765 if (!strstr(text, "\n") && gtk_text_iter_has_tag(iter, compose->no_join_tag)) {
11766 before_ins = *iter;
11767 gtk_text_iter_backward_chars(&before_ins, len);
11768 gtk_text_buffer_remove_tag_by_name(buffer, "no_join", &before_ins, iter);
11771 /* check if the preceding is just whitespace or quote */
11772 GtkTextIter start_line;
11773 gchar *tmp = NULL, *quote = NULL;
11774 gint quote_len = 0, is_normal = 0;
11775 start_line = *iter;
11776 gtk_text_iter_set_line_offset(&start_line, 0);
11777 tmp = gtk_text_buffer_get_text(buffer, &start_line, iter, FALSE);
11780 if (*tmp == '\0') {
11783 quote = compose_get_quote_str(buffer, &start_line, "e_len);
11791 gtk_text_buffer_insert(buffer, iter, text, len);
11793 gtk_text_buffer_insert_with_tags_by_name(buffer,
11794 iter, text, len, "no_join", NULL);
11799 if (!paste_as_quotation) {
11800 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
11801 compose_beautify_paragraph(compose, iter, FALSE);
11802 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
11803 gtk_text_buffer_delete_mark(buffer, mark);
11806 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
11807 G_CALLBACK(text_inserted),
11809 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
11811 if (compose_can_autosave(compose) &&
11812 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0 &&
11813 compose->draft_timeout_tag != COMPOSE_DRAFT_TIMEOUT_FORBIDDEN /* disabled while loading */)
11814 compose->draft_timeout_tag = g_timeout_add
11815 (500, (GSourceFunc) compose_defer_auto_save_draft, compose);
11819 static void compose_check_all(GtkAction *action, gpointer data)
11821 Compose *compose = (Compose *)data;
11822 if (!compose->gtkaspell)
11825 if (gtk_widget_has_focus(compose->subject_entry))
11826 claws_spell_entry_check_all(
11827 CLAWS_SPELL_ENTRY(compose->subject_entry));
11829 gtkaspell_check_all(compose->gtkaspell);
11832 static void compose_highlight_all(GtkAction *action, gpointer data)
11834 Compose *compose = (Compose *)data;
11835 if (compose->gtkaspell) {
11836 claws_spell_entry_recheck_all(
11837 CLAWS_SPELL_ENTRY(compose->subject_entry));
11838 gtkaspell_highlight_all(compose->gtkaspell);
11842 static void compose_check_backwards(GtkAction *action, gpointer data)
11844 Compose *compose = (Compose *)data;
11845 if (!compose->gtkaspell) {
11846 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", FALSE);
11850 if (gtk_widget_has_focus(compose->subject_entry))
11851 claws_spell_entry_check_backwards(
11852 CLAWS_SPELL_ENTRY(compose->subject_entry));
11854 gtkaspell_check_backwards(compose->gtkaspell);
11857 static void compose_check_forwards_go(GtkAction *action, gpointer data)
11859 Compose *compose = (Compose *)data;
11860 if (!compose->gtkaspell) {
11861 cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", FALSE);
11865 if (gtk_widget_has_focus(compose->subject_entry))
11866 claws_spell_entry_check_forwards_go(
11867 CLAWS_SPELL_ENTRY(compose->subject_entry));
11869 gtkaspell_check_forwards_go(compose->gtkaspell);
11874 *\brief Guess originating forward account from MsgInfo and several
11875 * "common preference" settings. Return NULL if no guess.
11877 static PrefsAccount *compose_find_account(MsgInfo *msginfo)
11879 PrefsAccount *account = NULL;
11881 cm_return_val_if_fail(msginfo, NULL);
11882 cm_return_val_if_fail(msginfo->folder, NULL);
11883 cm_return_val_if_fail(msginfo->folder->prefs, NULL);
11885 if (msginfo->folder->prefs->enable_default_account)
11886 account = account_find_from_id(msginfo->folder->prefs->default_account);
11888 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
11890 Xstrdup_a(to, msginfo->to, return NULL);
11891 extract_address(to);
11892 account = account_find_from_address(to, FALSE);
11895 if (!account && prefs_common.forward_account_autosel) {
11897 if (!procheader_get_header_from_msginfo
11898 (msginfo, &cc, "Cc:")) {
11899 gchar *buf = cc + strlen("Cc:");
11900 extract_address(buf);
11901 account = account_find_from_address(buf, FALSE);
11906 if (!account && prefs_common.forward_account_autosel) {
11907 gchar *deliveredto = NULL;
11908 if (!procheader_get_header_from_msginfo
11909 (msginfo, &deliveredto, "Delivered-To:")) {
11910 gchar *buf = deliveredto + strlen("Delivered-To:");
11911 extract_address(buf);
11912 account = account_find_from_address(buf, FALSE);
11913 g_free(deliveredto);
11918 account = msginfo->folder->folder->account;
11923 gboolean compose_close(Compose *compose)
11927 cm_return_val_if_fail(compose, FALSE);
11929 if (!g_mutex_trylock(compose->mutex)) {
11930 /* we have to wait for the (possibly deferred by auto-save)
11931 * drafting to be done, before destroying the compose under
11933 debug_print("waiting for drafting to finish...\n");
11934 compose_allow_user_actions(compose, FALSE);
11935 if (compose->close_timeout_tag == 0) {
11936 compose->close_timeout_tag =
11937 g_timeout_add (500, (GSourceFunc) compose_close,
11943 if (compose->draft_timeout_tag >= 0) {
11944 g_source_remove(compose->draft_timeout_tag);
11945 compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_FORBIDDEN;
11948 gtkut_widget_get_uposition(compose->window, &x, &y);
11949 if (!compose->batch) {
11950 prefs_common.compose_x = x;
11951 prefs_common.compose_y = y;
11953 g_mutex_unlock(compose->mutex);
11954 compose_destroy(compose);
11959 * Add entry field for each address in list.
11960 * \param compose E-Mail composition object.
11961 * \param listAddress List of (formatted) E-Mail addresses.
11963 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
11966 node = listAddress;
11968 addr = ( gchar * ) node->data;
11969 compose_entry_append( compose, addr, COMPOSE_TO, PREF_NONE );
11970 node = g_list_next( node );
11974 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
11975 guint action, gboolean opening_multiple)
11977 gchar *body = NULL;
11978 GSList *new_msglist = NULL;
11979 MsgInfo *tmp_msginfo = NULL;
11980 gboolean originally_enc = FALSE;
11981 gboolean originally_sig = FALSE;
11982 Compose *compose = NULL;
11983 gchar *s_system = NULL;
11985 cm_return_if_fail(msgview != NULL);
11987 cm_return_if_fail(msginfo_list != NULL);
11989 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
11990 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
11991 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
11993 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
11994 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
11995 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
11996 orig_msginfo, mimeinfo);
11997 if (tmp_msginfo != NULL) {
11998 new_msglist = g_slist_append(NULL, tmp_msginfo);
12000 originally_enc = MSG_IS_ENCRYPTED(orig_msginfo->flags);
12001 privacy_msginfo_get_signed_state(orig_msginfo, &s_system);
12002 originally_sig = MSG_IS_SIGNED(orig_msginfo->flags);
12004 tmp_msginfo->folder = orig_msginfo->folder;
12005 tmp_msginfo->msgnum = orig_msginfo->msgnum;
12006 if (orig_msginfo->tags) {
12007 tmp_msginfo->tags = g_slist_copy(orig_msginfo->tags);
12008 tmp_msginfo->folder->tags_dirty = TRUE;
12014 if (!opening_multiple)
12015 body = messageview_get_selection(msgview);
12018 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
12019 procmsg_msginfo_free(&tmp_msginfo);
12020 g_slist_free(new_msglist);
12022 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
12024 if (compose && originally_enc) {
12025 compose_force_encryption(compose, compose->account, FALSE, s_system);
12028 if (compose && originally_sig && compose->account->default_sign_reply) {
12029 compose_force_signing(compose, compose->account, s_system);
12033 hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
12036 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
12039 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
12040 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
12041 GSList *cur = msginfo_list;
12042 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
12043 "messages. Opening the windows "
12044 "could take some time. Do you "
12045 "want to continue?"),
12046 g_slist_length(msginfo_list));
12047 if (g_slist_length(msginfo_list) > 9
12048 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
12049 != G_ALERTALTERNATE) {
12054 /* We'll open multiple compose windows */
12055 /* let the WM place the next windows */
12056 compose_force_window_origin = FALSE;
12057 for (; cur; cur = cur->next) {
12059 tmplist.data = cur->data;
12060 tmplist.next = NULL;
12061 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
12063 compose_force_window_origin = TRUE;
12065 /* forwarding multiple mails as attachments is done via a
12066 * single compose window */
12067 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
12071 void compose_check_for_email_account(Compose *compose)
12073 PrefsAccount *ac = NULL, *curr = NULL;
12079 if (compose->account && compose->account->protocol == A_NNTP) {
12080 ac = account_get_cur_account();
12081 if (ac->protocol == A_NNTP) {
12082 list = account_get_list();
12084 for( ; list != NULL ; list = g_list_next(list)) {
12085 curr = (PrefsAccount *) list->data;
12086 if (curr->protocol != A_NNTP) {
12092 combobox_select_by_data(GTK_COMBO_BOX(compose->account_combo),
12097 void compose_reply_to_address(MessageView *msgview, MsgInfo *msginfo,
12098 const gchar *address)
12100 GSList *msginfo_list = NULL;
12101 gchar *body = messageview_get_selection(msgview);
12104 msginfo_list = g_slist_prepend(msginfo_list, msginfo);
12106 compose = compose_reply_mode(COMPOSE_REPLY_TO_ADDRESS, msginfo_list, body);
12107 compose_check_for_email_account(compose);
12108 compose_set_folder_prefs(compose, msginfo->folder, FALSE);
12109 compose_entry_append(compose, address, COMPOSE_TO, PREF_NONE);
12110 compose_reply_set_subject(compose, msginfo);
12113 hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
12116 void compose_set_position(Compose *compose, gint pos)
12118 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
12120 gtkut_text_view_set_position(text, pos);
12123 gboolean compose_search_string(Compose *compose,
12124 const gchar *str, gboolean case_sens)
12126 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
12128 return gtkut_text_view_search_string(text, str, case_sens);
12131 gboolean compose_search_string_backward(Compose *compose,
12132 const gchar *str, gboolean case_sens)
12134 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
12136 return gtkut_text_view_search_string_backward(text, str, case_sens);
12139 /* allocate a msginfo structure and populate its data from a compose data structure */
12140 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
12142 MsgInfo *newmsginfo;
12144 gchar date[RFC822_DATE_BUFFSIZE];
12146 cm_return_val_if_fail( compose != NULL, NULL );
12148 newmsginfo = procmsg_msginfo_new();
12151 get_rfc822_date(date, sizeof(date));
12152 newmsginfo->date = g_strdup(date);
12155 if (compose->from_name) {
12156 newmsginfo->from = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
12157 newmsginfo->fromname = procheader_get_fromname(newmsginfo->from);
12161 if (compose->subject_entry)
12162 newmsginfo->subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
12164 /* to, cc, reply-to, newsgroups */
12165 for (list = compose->header_list; list; list = list->next) {
12166 gchar *header = gtk_editable_get_chars(
12168 gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
12169 gchar *entry = gtk_editable_get_chars(
12170 GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
12172 if ( strcasecmp(header, prefs_common_translated_header_name("To:")) == 0 ) {
12173 if ( newmsginfo->to == NULL ) {
12174 newmsginfo->to = g_strdup(entry);
12175 } else if (entry && *entry) {
12176 gchar *tmp = g_strconcat(newmsginfo->to, ", ", entry, NULL);
12177 g_free(newmsginfo->to);
12178 newmsginfo->to = tmp;
12181 if ( strcasecmp(header, prefs_common_translated_header_name("Cc:")) == 0 ) {
12182 if ( newmsginfo->cc == NULL ) {
12183 newmsginfo->cc = g_strdup(entry);
12184 } else if (entry && *entry) {
12185 gchar *tmp = g_strconcat(newmsginfo->cc, ", ", entry, NULL);
12186 g_free(newmsginfo->cc);
12187 newmsginfo->cc = tmp;
12190 if ( strcasecmp(header,
12191 prefs_common_translated_header_name("Newsgroups:")) == 0 ) {
12192 if ( newmsginfo->newsgroups == NULL ) {
12193 newmsginfo->newsgroups = g_strdup(entry);
12194 } else if (entry && *entry) {
12195 gchar *tmp = g_strconcat(newmsginfo->newsgroups, ", ", entry, NULL);
12196 g_free(newmsginfo->newsgroups);
12197 newmsginfo->newsgroups = tmp;
12205 /* other data is unset */
12211 /* update compose's dictionaries from folder dict settings */
12212 static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
12213 FolderItem *folder_item)
12215 cm_return_if_fail(compose != NULL);
12217 if (compose->gtkaspell && folder_item && folder_item->prefs) {
12218 FolderItemPrefs *prefs = folder_item->prefs;
12220 if (prefs->enable_default_dictionary)
12221 gtkaspell_change_dict(compose->gtkaspell,
12222 prefs->default_dictionary, FALSE);
12223 if (folder_item->prefs->enable_default_alt_dictionary)
12224 gtkaspell_change_alt_dict(compose->gtkaspell,
12225 prefs->default_alt_dictionary);
12226 if (prefs->enable_default_dictionary
12227 || prefs->enable_default_alt_dictionary)
12228 compose_spell_menu_changed(compose);
12233 static void compose_subject_entry_activated(GtkWidget *widget, gpointer data)
12235 Compose *compose = (Compose *)data;
12237 cm_return_if_fail(compose != NULL);
12239 gtk_widget_grab_focus(compose->text);
12242 static void from_name_activate_cb(GtkWidget *widget, gpointer data)
12244 gtk_combo_box_popup(GTK_COMBO_BOX(data));