2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
123 #include "combobox.h"
135 #define N_ATTACH_COLS (N_COL_COLUMNS)
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
154 } ComposeCallAdvancedAction;
158 PRIORITY_HIGHEST = 1,
167 COMPOSE_INSERT_SUCCESS,
168 COMPOSE_INSERT_READ_ERROR,
169 COMPOSE_INSERT_INVALID_CHARACTER,
170 COMPOSE_INSERT_NO_FILE
171 } ComposeInsertResult;
175 COMPOSE_QUIT_EDITING,
176 COMPOSE_KEEP_EDITING,
178 } ComposeDraftAction;
182 COMPOSE_WRITE_FOR_SEND,
183 COMPOSE_WRITE_FOR_STORE
186 #define B64_LINE_SIZE 57
187 #define B64_BUFFSIZE 77
189 #define MAX_REFERENCES_LEN 999
191 static GList *compose_list = NULL;
193 Compose *compose_generic_new (PrefsAccount *account,
196 GPtrArray *attach_files,
197 GList *listAddress );
199 static Compose *compose_create (PrefsAccount *account,
203 static GtkWidget *compose_account_option_menu_create
205 static void compose_set_out_encoding (Compose *compose);
206 static void compose_set_template_menu (Compose *compose);
207 static void compose_template_apply (Compose *compose,
210 static void compose_destroy (Compose *compose);
212 static void compose_entries_set (Compose *compose,
213 const gchar *mailto);
214 static gint compose_parse_header (Compose *compose,
216 static gchar *compose_parse_references (const gchar *ref,
219 static gchar *compose_quote_fmt (Compose *compose,
226 static void compose_reply_set_entry (Compose *compose,
232 followup_and_reply_to);
233 static void compose_reedit_set_entry (Compose *compose,
236 static void compose_insert_sig (Compose *compose,
238 static gchar *compose_get_signature_str (Compose *compose);
239 static ComposeInsertResult compose_insert_file (Compose *compose,
242 static void compose_attach_append (Compose *compose,
245 const gchar *content_type);
246 static void compose_attach_parts (Compose *compose,
249 static void compose_beautify_paragraph (Compose *compose,
250 GtkTextIter *par_iter,
252 static void compose_wrap_all (Compose *compose);
253 static void compose_wrap_all_full (Compose *compose,
256 static void compose_set_title (Compose *compose);
257 static void compose_select_account (Compose *compose,
258 PrefsAccount *account,
261 static PrefsAccount *compose_current_mail_account(void);
262 /* static gint compose_send (Compose *compose); */
263 static gboolean compose_check_for_valid_recipient
265 static gboolean compose_check_entries (Compose *compose,
266 gboolean check_subject);
267 static gint compose_write_to_file (Compose *compose,
270 gboolean attach_parts);
271 static gint compose_write_body_to_file (Compose *compose,
273 static gint compose_remove_reedit_target (Compose *compose,
275 void compose_remove_draft (Compose *compose);
276 static gint compose_queue_sub (Compose *compose,
280 gboolean check_subject,
281 gboolean remove_reedit_target);
282 static void compose_add_attachments (Compose *compose,
284 static gchar *compose_get_header (Compose *compose);
286 static void compose_convert_header (Compose *compose,
291 gboolean addr_field);
293 static void compose_attach_info_free (AttachInfo *ainfo);
294 static void compose_attach_remove_selected (Compose *compose);
296 static void compose_attach_property (Compose *compose);
297 static void compose_attach_property_create (gboolean *cancelled);
298 static void attach_property_ok (GtkWidget *widget,
299 gboolean *cancelled);
300 static void attach_property_cancel (GtkWidget *widget,
301 gboolean *cancelled);
302 static gint attach_property_delete_event (GtkWidget *widget,
304 gboolean *cancelled);
305 static gboolean attach_property_key_pressed (GtkWidget *widget,
307 gboolean *cancelled);
309 static void compose_exec_ext_editor (Compose *compose);
311 static gint compose_exec_ext_editor_real (const gchar *file);
312 static gboolean compose_ext_editor_kill (Compose *compose);
313 static gboolean compose_input_cb (GIOChannel *source,
314 GIOCondition condition,
316 static void compose_set_ext_editor_sensitive (Compose *compose,
318 #endif /* G_OS_UNIX */
320 static void compose_undo_state_changed (UndoMain *undostruct,
325 static void compose_create_header_entry (Compose *compose);
326 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
327 static void compose_update_priority_menu_item(Compose * compose);
329 static void compose_spell_menu_changed (void *data);
331 static void compose_add_field_list ( Compose *compose,
332 GList *listAddress );
334 /* callback functions */
336 static gboolean compose_edit_size_alloc (GtkEditable *widget,
337 GtkAllocation *allocation,
338 GtkSHRuler *shruler);
339 static void account_activated (GtkComboBox *optmenu,
341 static void attach_selected (GtkTreeView *tree_view,
342 GtkTreePath *tree_path,
343 GtkTreeViewColumn *column,
345 static gboolean attach_button_pressed (GtkWidget *widget,
346 GdkEventButton *event,
348 static gboolean attach_key_pressed (GtkWidget *widget,
352 static void compose_send_cb (gpointer data,
355 static void compose_send_later_cb (gpointer data,
359 static void compose_draft_cb (gpointer data,
363 static void compose_attach_cb (gpointer data,
366 static void compose_insert_file_cb (gpointer data,
369 static void compose_insert_sig_cb (gpointer data,
373 static void compose_close_cb (gpointer data,
377 static void compose_set_encoding_cb (gpointer data,
381 static void compose_address_cb (gpointer data,
384 static void compose_template_activate_cb(GtkWidget *widget,
387 static void compose_ext_editor_cb (gpointer data,
391 static gint compose_delete_cb (GtkWidget *widget,
395 static void compose_undo_cb (Compose *compose);
396 static void compose_redo_cb (Compose *compose);
397 static void compose_cut_cb (Compose *compose);
398 static void compose_copy_cb (Compose *compose);
399 static void compose_paste_cb (Compose *compose);
400 static void compose_paste_as_quote_cb (Compose *compose);
401 static void compose_paste_no_wrap_cb (Compose *compose);
402 static void compose_paste_wrap_cb (Compose *compose);
403 static void compose_allsel_cb (Compose *compose);
405 static void compose_advanced_action_cb (Compose *compose,
406 ComposeCallAdvancedAction action);
408 static void compose_grab_focus_cb (GtkWidget *widget,
411 static void compose_changed_cb (GtkTextBuffer *textbuf,
414 static void compose_wrap_cb (gpointer data,
417 static void compose_find_cb (gpointer data,
420 static void compose_toggle_autowrap_cb (gpointer data,
424 static void compose_toggle_ruler_cb (gpointer data,
427 static void compose_toggle_sign_cb (gpointer data,
430 static void compose_toggle_encrypt_cb (gpointer data,
433 static void compose_set_privacy_system_cb(GtkWidget *widget,
435 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
436 static void activate_privacy_system (Compose *compose,
437 PrefsAccount *account,
439 static void compose_use_signing(Compose *compose, gboolean use_signing);
440 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
441 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
443 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
445 static void compose_set_priority_cb (gpointer data,
449 static void compose_attach_drag_received_cb (GtkWidget *widget,
450 GdkDragContext *drag_context,
453 GtkSelectionData *data,
457 static void compose_insert_drag_received_cb (GtkWidget *widget,
458 GdkDragContext *drag_context,
461 GtkSelectionData *data,
465 static void compose_header_drag_received_cb (GtkWidget *widget,
466 GdkDragContext *drag_context,
469 GtkSelectionData *data,
474 static gboolean compose_drag_drop (GtkWidget *widget,
475 GdkDragContext *drag_context,
477 guint time, gpointer user_data);
479 static void text_inserted (GtkTextBuffer *buffer,
484 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
485 gboolean to_all, gboolean to_ml,
487 gboolean followup_and_reply_to,
490 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
491 ComposeHeaderEntry *headerentry);
492 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
494 ComposeHeaderEntry *headerentry);
496 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
498 static void compose_allow_user_actions (Compose *compose, gboolean allow);
501 static void compose_check_all (Compose *compose);
502 static void compose_highlight_all (Compose *compose);
503 static void compose_check_backwards (Compose *compose);
504 static void compose_check_forwards_go (Compose *compose);
507 static gint compose_defer_auto_save_draft (Compose *compose);
508 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
510 static GtkItemFactoryEntry compose_popup_entries[] =
512 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
513 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
514 {N_("/---"), NULL, NULL, 0, "<Separator>"},
515 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
518 static GtkItemFactoryEntry compose_entries[] =
520 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
521 {N_("/_Message/_Send"), "<control>Return",
522 compose_send_cb, 0, NULL},
523 {N_("/_Message/Send _later"), "<shift><control>S",
524 compose_send_later_cb, 0, NULL},
525 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
527 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
528 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
529 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
530 {N_("/_Message/_Save"),
531 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
532 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
533 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
535 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
536 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
537 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
538 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
539 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
540 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
541 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
542 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
543 {N_("/_Edit/Special paste/as _quotation"),
544 NULL, compose_paste_as_quote_cb, 0, NULL},
545 {N_("/_Edit/Special paste/_wrapped"),
546 NULL, compose_paste_wrap_cb, 0, NULL},
547 {N_("/_Edit/Special paste/_unwrapped"),
548 NULL, compose_paste_no_wrap_cb, 0, NULL},
549 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
550 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
551 {N_("/_Edit/A_dvanced/Move a character backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
556 {N_("/_Edit/A_dvanced/Move a character forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
561 {N_("/_Edit/A_dvanced/Move a word backward"),
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
566 {N_("/_Edit/A_dvanced/Move a word forward"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
571 {N_("/_Edit/A_dvanced/Move to beginning of line"),
572 NULL, /* "<control>A" */
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
576 {N_("/_Edit/A_dvanced/Move to end of line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
581 {N_("/_Edit/A_dvanced/Move to previous line"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
586 {N_("/_Edit/A_dvanced/Move to next line"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
591 {N_("/_Edit/A_dvanced/Delete a character backward"),
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
596 {N_("/_Edit/A_dvanced/Delete a character forward"),
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
601 {N_("/_Edit/A_dvanced/Delete a word backward"),
602 NULL, /* "<control>W" */
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
606 {N_("/_Edit/A_dvanced/Delete a word forward"),
607 NULL, /* "<alt>D", */
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
611 {N_("/_Edit/A_dvanced/Delete line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
616 {N_("/_Edit/A_dvanced/Delete entire line"),
618 compose_advanced_action_cb,
619 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
621 {N_("/_Edit/A_dvanced/Delete to end of line"),
623 compose_advanced_action_cb,
624 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
626 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
628 "<control>F", compose_find_cb, 0, NULL},
629 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_Edit/_Wrap current paragraph"),
631 "<control>L", compose_wrap_cb, 0, NULL},
632 {N_("/_Edit/Wrap all long _lines"),
633 "<control><alt>L", compose_wrap_cb, 1, NULL},
634 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
635 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Edit/Edit with e_xternal editor"),
637 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
639 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Spelling/_Check all or check selection"),
641 NULL, compose_check_all, 0, NULL},
642 {N_("/_Spelling/_Highlight all misspelled words"),
643 NULL, compose_highlight_all, 0, NULL},
644 {N_("/_Spelling/Check _backwards misspelled word"),
645 NULL, compose_check_backwards , 0, NULL},
646 {N_("/_Spelling/_Forward to next misspelled word"),
647 NULL, compose_check_forwards_go, 0, NULL},
648 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Spelling/Options"),
650 NULL, NULL, 0, "<Branch>"},
652 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
653 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
655 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
656 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
657 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
660 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
661 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
662 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
663 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
664 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
665 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
666 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
667 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
668 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
670 #define ENC_ACTION(action) \
671 NULL, compose_set_encoding_cb, action, \
672 "/Options/Character encoding/Automatic"
674 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
675 {N_("/_Options/Character _encoding/_Automatic"),
676 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
677 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
679 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
680 ENC_ACTION(C_US_ASCII)},
681 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
682 ENC_ACTION(C_UTF_8)},
683 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
685 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
686 ENC_ACTION(C_ISO_8859_1)},
687 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
688 ENC_ACTION(C_ISO_8859_15)},
689 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
690 ENC_ACTION(C_WINDOWS_1252)},
691 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
693 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
694 ENC_ACTION(C_ISO_8859_2)},
695 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
697 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
698 ENC_ACTION(C_ISO_8859_13)},
699 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
700 ENC_ACTION(C_ISO_8859_4)},
701 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
703 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
704 ENC_ACTION(C_ISO_8859_7)},
705 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
707 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
708 ENC_ACTION(C_ISO_8859_8)},
709 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
710 ENC_ACTION(C_WINDOWS_1255)},
711 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
713 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
714 ENC_ACTION(C_ISO_8859_6)},
715 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
716 ENC_ACTION(C_CP1256)},
717 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
719 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
720 ENC_ACTION(C_ISO_8859_9)},
721 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
723 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
724 ENC_ACTION(C_ISO_8859_5)},
725 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
726 ENC_ACTION(C_KOI8_R)},
727 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
728 ENC_ACTION(C_KOI8_U)},
729 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
730 ENC_ACTION(C_WINDOWS_1251)},
731 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
733 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
734 ENC_ACTION(C_ISO_2022_JP)},
735 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
737 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
738 ENC_ACTION(C_GB2312)},
739 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
741 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
743 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
744 ENC_ACTION(C_EUC_TW)},
745 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
747 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
748 ENC_ACTION(C_EUC_KR)},
749 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
751 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
752 ENC_ACTION(C_TIS_620)},
753 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
754 ENC_ACTION(C_WINDOWS_874)},
756 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
757 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
758 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
759 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
760 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
761 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
762 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
765 static GtkTargetEntry compose_mime_types[] =
767 {"text/uri-list", 0, 0},
768 {"UTF8_STRING", 0, 0},
772 static gboolean compose_put_existing_to_front(MsgInfo *info)
774 GList *compose_list = compose_get_compose_list();
778 for (elem = compose_list; elem != NULL && elem->data != NULL;
780 Compose *c = (Compose*)elem->data;
782 if (!c->targetinfo || !c->targetinfo->msgid ||
786 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
787 gtkut_window_popup(c->window);
795 static GdkColor quote_color1 =
796 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
797 static GdkColor quote_color2 =
798 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
799 static GdkColor quote_color3 =
800 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
802 static GdkColor quote_bgcolor1 =
803 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
804 static GdkColor quote_bgcolor2 =
805 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
806 static GdkColor quote_bgcolor3 =
807 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
809 static GdkColor signature_color = {
816 static GdkColor uri_color = {
823 static void compose_create_tags(GtkTextView *text, Compose *compose)
825 GtkTextBuffer *buffer;
826 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
832 buffer = gtk_text_view_get_buffer(text);
834 if (prefs_common.enable_color) {
835 /* grab the quote colors, converting from an int to a GdkColor */
836 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
838 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
840 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
842 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
844 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
846 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
848 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
850 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
853 signature_color = quote_color1 = quote_color2 = quote_color3 =
854 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
857 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
858 gtk_text_buffer_create_tag(buffer, "quote0",
859 "foreground-gdk", "e_color1,
860 "paragraph-background-gdk", "e_bgcolor1,
862 gtk_text_buffer_create_tag(buffer, "quote1",
863 "foreground-gdk", "e_color2,
864 "paragraph-background-gdk", "e_bgcolor2,
866 gtk_text_buffer_create_tag(buffer, "quote2",
867 "foreground-gdk", "e_color3,
868 "paragraph-background-gdk", "e_bgcolor3,
871 gtk_text_buffer_create_tag(buffer, "quote0",
872 "foreground-gdk", "e_color1,
874 gtk_text_buffer_create_tag(buffer, "quote1",
875 "foreground-gdk", "e_color2,
877 gtk_text_buffer_create_tag(buffer, "quote2",
878 "foreground-gdk", "e_color3,
882 gtk_text_buffer_create_tag(buffer, "signature",
883 "foreground-gdk", &signature_color,
885 gtk_text_buffer_create_tag(buffer, "link",
886 "foreground-gdk", &uri_color,
888 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
889 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
891 color[0] = quote_color1;
892 color[1] = quote_color2;
893 color[2] = quote_color3;
894 color[3] = quote_bgcolor1;
895 color[4] = quote_bgcolor2;
896 color[5] = quote_bgcolor3;
897 color[6] = signature_color;
898 color[7] = uri_color;
899 cmap = gdk_drawable_get_colormap(compose->window->window);
900 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
902 for (i = 0; i < 8; i++) {
903 if (success[i] == FALSE) {
906 g_warning("Compose: color allocation failed.\n");
907 style = gtk_widget_get_style(GTK_WIDGET(text));
908 quote_color1 = quote_color2 = quote_color3 =
909 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
910 signature_color = uri_color = black;
915 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
916 GPtrArray *attach_files)
918 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
921 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
923 return compose_generic_new(account, NULL, item, NULL, NULL);
926 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
928 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
931 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
932 GPtrArray *attach_files, GList *listAddress )
935 GtkTextView *textview;
936 GtkTextBuffer *textbuf;
938 GtkItemFactory *ifactory;
940 if (item && item->prefs && item->prefs->enable_default_account)
941 account = account_find_from_id(item->prefs->default_account);
943 if (!account) account = cur_account;
944 g_return_val_if_fail(account != NULL, NULL);
946 compose = compose_create(account, COMPOSE_NEW, FALSE);
948 ifactory = gtk_item_factory_from_widget(compose->menubar);
950 compose->replyinfo = NULL;
951 compose->fwdinfo = NULL;
953 textview = GTK_TEXT_VIEW(compose->text);
954 textbuf = gtk_text_view_get_buffer(textview);
955 compose_create_tags(textview, compose);
957 undo_block(compose->undostruct);
959 if (item && item->prefs && item->prefs->enable_default_dictionary &&
961 gtkaspell_change_dict(compose->gtkaspell,
962 item->prefs->default_dictionary);
963 compose_spell_menu_changed(compose);
966 if (account->auto_sig)
967 compose_insert_sig(compose, FALSE);
968 gtk_text_buffer_get_start_iter(textbuf, &iter);
969 gtk_text_buffer_place_cursor(textbuf, &iter);
971 if (account->protocol != A_NNTP) {
972 if (mailto && *mailto != '\0') {
973 compose_entries_set(compose, mailto);
975 } else if (item && item->prefs->enable_default_to) {
976 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
977 compose_entry_mark_default_to(compose, item->prefs->default_to);
979 if (item && item->ret_rcpt) {
980 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
984 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
986 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
989 * CLAWS: just don't allow return receipt request, even if the user
990 * may want to send an email. simple but foolproof.
992 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
994 compose_add_field_list( compose, listAddress );
1000 for (i = 0; i < attach_files->len; i++) {
1001 file = g_ptr_array_index(attach_files, i);
1002 compose_attach_append(compose, file, file, NULL);
1006 compose_show_first_last_header(compose, TRUE);
1008 /* Set save folder */
1009 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1010 gchar *folderidentifier;
1012 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1013 folderidentifier = folder_item_get_identifier(item);
1014 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1015 g_free(folderidentifier);
1018 gtk_widget_grab_focus(compose->header_last->entry);
1020 undo_unblock(compose->undostruct);
1022 if (prefs_common.auto_exteditor)
1023 compose_exec_ext_editor(compose);
1025 compose->modified = FALSE;
1026 compose_set_title(compose);
1030 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1031 gboolean override_pref)
1033 gchar *privacy = NULL;
1035 g_return_if_fail(compose != NULL);
1036 g_return_if_fail(account != NULL);
1038 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1041 if (account->default_privacy_system
1042 && strlen(account->default_privacy_system)) {
1043 privacy = account->default_privacy_system;
1045 GSList *privacy_avail = privacy_get_system_ids();
1046 if (privacy_avail && g_slist_length(privacy_avail)) {
1047 privacy = (gchar *)(privacy_avail->data);
1050 if (privacy != NULL) {
1051 compose->privacy_system = g_strdup(privacy);
1052 compose_update_privacy_system_menu_item(compose, FALSE);
1053 compose_use_encryption(compose, TRUE);
1057 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1059 gchar *privacy = NULL;
1061 if (account->default_privacy_system
1062 && strlen(account->default_privacy_system)) {
1063 privacy = account->default_privacy_system;
1065 GSList *privacy_avail = privacy_get_system_ids();
1066 if (privacy_avail && g_slist_length(privacy_avail)) {
1067 privacy = (gchar *)(privacy_avail->data);
1070 if (privacy != NULL) {
1071 compose->privacy_system = g_strdup(privacy);
1072 compose_update_privacy_system_menu_item(compose, FALSE);
1073 compose_use_signing(compose, TRUE);
1077 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1081 Compose *compose = NULL;
1082 g_return_val_if_fail(msginfo_list != NULL, NULL);
1084 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1085 g_return_val_if_fail(msginfo != NULL, NULL);
1087 list_len = g_slist_length(msginfo_list);
1091 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1092 FALSE, prefs_common.default_reply_list, FALSE, body);
1094 case COMPOSE_REPLY_WITH_QUOTE:
1095 compose = compose_reply(msginfo, TRUE,
1096 FALSE, prefs_common.default_reply_list, FALSE, body);
1098 case COMPOSE_REPLY_WITHOUT_QUOTE:
1099 compose = compose_reply(msginfo, FALSE,
1100 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1102 case COMPOSE_REPLY_TO_SENDER:
1103 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1104 FALSE, FALSE, TRUE, body);
1106 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1107 compose = compose_followup_and_reply_to(msginfo,
1108 prefs_common.reply_with_quote,
1109 FALSE, FALSE, body);
1111 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1112 compose = compose_reply(msginfo, TRUE,
1113 FALSE, FALSE, TRUE, body);
1115 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1116 compose = compose_reply(msginfo, FALSE,
1117 FALSE, FALSE, TRUE, NULL);
1119 case COMPOSE_REPLY_TO_ALL:
1120 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1121 TRUE, FALSE, FALSE, body);
1123 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1124 compose = compose_reply(msginfo, TRUE,
1125 TRUE, FALSE, FALSE, body);
1127 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1128 compose = compose_reply(msginfo, FALSE,
1129 TRUE, FALSE, FALSE, NULL);
1131 case COMPOSE_REPLY_TO_LIST:
1132 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1133 FALSE, TRUE, FALSE, body);
1135 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1136 compose = compose_reply(msginfo, TRUE,
1137 FALSE, TRUE, FALSE, body);
1139 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1140 compose = compose_reply(msginfo, FALSE,
1141 FALSE, TRUE, FALSE, NULL);
1143 case COMPOSE_FORWARD:
1144 if (prefs_common.forward_as_attachment) {
1145 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1148 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1152 case COMPOSE_FORWARD_INLINE:
1153 /* check if we reply to more than one Message */
1154 if (list_len == 1) {
1155 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1158 /* more messages FALL THROUGH */
1159 case COMPOSE_FORWARD_AS_ATTACH:
1160 compose = compose_forward_multiple(NULL, msginfo_list);
1162 case COMPOSE_REDIRECT:
1163 compose = compose_redirect(NULL, msginfo, FALSE);
1166 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1171 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1172 gboolean to_ml, gboolean to_sender,
1175 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1176 to_sender, FALSE, body);
1179 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1184 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1185 to_sender, TRUE, body);
1188 static void compose_extract_original_charset(Compose *compose)
1190 MsgInfo *info = NULL;
1191 if (compose->replyinfo) {
1192 info = compose->replyinfo;
1193 } else if (compose->fwdinfo) {
1194 info = compose->fwdinfo;
1195 } else if (compose->targetinfo) {
1196 info = compose->targetinfo;
1199 MimeInfo *mimeinfo = procmime_scan_message(info);
1200 MimeInfo *partinfo = mimeinfo;
1201 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1202 partinfo = procmime_mimeinfo_next(partinfo);
1204 compose->orig_charset =
1205 g_strdup(procmime_mimeinfo_get_parameter(
1206 partinfo, "charset"));
1208 procmime_mimeinfo_free_all(mimeinfo);
1212 #define SIGNAL_BLOCK(buffer) { \
1213 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1214 G_CALLBACK(compose_changed_cb), \
1216 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1217 G_CALLBACK(text_inserted), \
1221 #define SIGNAL_UNBLOCK(buffer) { \
1222 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1223 G_CALLBACK(compose_changed_cb), \
1225 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1226 G_CALLBACK(text_inserted), \
1230 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1231 gboolean to_all, gboolean to_ml,
1233 gboolean followup_and_reply_to,
1236 GtkItemFactory *ifactory;
1238 PrefsAccount *account = NULL;
1239 PrefsAccount *reply_account;
1240 GtkTextView *textview;
1241 GtkTextBuffer *textbuf;
1243 g_return_val_if_fail(msginfo != NULL, NULL);
1244 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1246 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1248 g_return_val_if_fail(account != NULL, NULL);
1250 if (to_sender && account->protocol == A_NNTP &&
1251 !followup_and_reply_to) {
1253 account_find_from_address(account->address);
1255 reply_account = compose_current_mail_account();
1259 reply_account = account;
1261 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1263 compose->updating = TRUE;
1265 ifactory = gtk_item_factory_from_widget(compose->menubar);
1267 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1268 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1270 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1271 if (!compose->replyinfo)
1272 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1274 compose_extract_original_charset(compose);
1276 if (msginfo->folder && msginfo->folder->ret_rcpt)
1277 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1279 /* Set save folder */
1280 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1281 gchar *folderidentifier;
1283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1284 folderidentifier = folder_item_get_identifier(msginfo->folder);
1285 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1286 g_free(folderidentifier);
1289 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1290 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1291 to_sender, followup_and_reply_to);
1292 compose_show_first_last_header(compose, TRUE);
1294 textview = (GTK_TEXT_VIEW(compose->text));
1295 textbuf = gtk_text_view_get_buffer(textview);
1296 compose_create_tags(textview, compose);
1298 undo_block(compose->undostruct);
1300 if (msginfo->folder && msginfo->folder->prefs &&
1301 msginfo->folder->prefs &&
1302 msginfo->folder->prefs->enable_default_dictionary &&
1304 gtkaspell_change_dict(compose->gtkaspell,
1305 msginfo->folder->prefs->default_dictionary);
1311 if (prefs_common.quotemark && *prefs_common.quotemark)
1312 qmark = prefs_common.quotemark;
1316 compose_quote_fmt(compose, compose->replyinfo,
1317 prefs_common.quotefmt,
1318 qmark, body, FALSE);
1319 quote_fmt_reset_vartable();
1321 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1322 compose_force_encryption(compose, account, FALSE);
1325 SIGNAL_BLOCK(textbuf);
1327 if (account->auto_sig)
1328 compose_insert_sig(compose, FALSE);
1330 compose_wrap_all(compose);
1332 SIGNAL_UNBLOCK(textbuf);
1334 gtk_widget_grab_focus(compose->text);
1336 undo_unblock(compose->undostruct);
1338 if (prefs_common.auto_exteditor)
1339 compose_exec_ext_editor(compose);
1341 compose->modified = FALSE;
1342 compose_set_title(compose);
1344 compose->updating = FALSE;
1346 if (compose->deferred_destroy) {
1347 compose_destroy(compose);
1354 #define INSERT_FW_HEADER(var, hdr) \
1355 if (msginfo->var && *msginfo->var) { \
1356 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1357 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1358 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1361 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1362 gboolean as_attach, const gchar *body,
1363 gboolean no_extedit,
1367 GtkTextView *textview;
1368 GtkTextBuffer *textbuf;
1371 g_return_val_if_fail(msginfo != NULL, NULL);
1372 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1375 !(account = compose_guess_forward_account_from_msginfo
1377 account = cur_account;
1379 compose = compose_create(account, COMPOSE_FORWARD, batch);
1381 compose->updating = TRUE;
1382 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1383 if (!compose->fwdinfo)
1384 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1386 compose_extract_original_charset(compose);
1388 if (msginfo->subject && *msginfo->subject) {
1389 gchar *buf, *buf2, *p;
1391 buf = p = g_strdup(msginfo->subject);
1392 p += subject_get_prefix_length(p);
1393 memmove(buf, p, strlen(p) + 1);
1395 buf2 = g_strdup_printf("Fw: %s", buf);
1396 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1402 textview = GTK_TEXT_VIEW(compose->text);
1403 textbuf = gtk_text_view_get_buffer(textview);
1404 compose_create_tags(textview, compose);
1406 undo_block(compose->undostruct);
1410 msgfile = procmsg_get_message_file_path(msginfo);
1411 if (!is_file_exist(msgfile))
1412 g_warning("%s: file not exist\n", msgfile);
1414 compose_attach_append(compose, msgfile, msgfile,
1420 MsgInfo *full_msginfo;
1422 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1424 full_msginfo = procmsg_msginfo_copy(msginfo);
1426 if (prefs_common.fw_quotemark &&
1427 *prefs_common.fw_quotemark)
1428 qmark = prefs_common.fw_quotemark;
1432 compose_quote_fmt(compose, full_msginfo,
1433 prefs_common.fw_quotefmt,
1434 qmark, body, FALSE);
1435 quote_fmt_reset_vartable();
1436 compose_attach_parts(compose, msginfo);
1438 procmsg_msginfo_free(full_msginfo);
1441 SIGNAL_BLOCK(textbuf);
1443 if (account->auto_sig)
1444 compose_insert_sig(compose, FALSE);
1446 compose_wrap_all(compose);
1448 SIGNAL_UNBLOCK(textbuf);
1450 gtk_text_buffer_get_start_iter(textbuf, &iter);
1451 gtk_text_buffer_place_cursor(textbuf, &iter);
1453 gtk_widget_grab_focus(compose->header_last->entry);
1455 if (!no_extedit && prefs_common.auto_exteditor)
1456 compose_exec_ext_editor(compose);
1459 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1460 gchar *folderidentifier;
1462 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1463 folderidentifier = folder_item_get_identifier(msginfo->folder);
1464 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1465 g_free(folderidentifier);
1468 undo_unblock(compose->undostruct);
1470 compose->modified = FALSE;
1471 compose_set_title(compose);
1473 compose->updating = FALSE;
1475 if (compose->deferred_destroy) {
1476 compose_destroy(compose);
1483 #undef INSERT_FW_HEADER
1485 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1488 GtkTextView *textview;
1489 GtkTextBuffer *textbuf;
1493 gboolean single_mail = TRUE;
1495 g_return_val_if_fail(msginfo_list != NULL, NULL);
1497 if (g_slist_length(msginfo_list) > 1)
1498 single_mail = FALSE;
1500 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1501 if (((MsgInfo *)msginfo->data)->folder == NULL)
1504 /* guess account from first selected message */
1506 !(account = compose_guess_forward_account_from_msginfo
1507 (msginfo_list->data)))
1508 account = cur_account;
1510 g_return_val_if_fail(account != NULL, NULL);
1512 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1513 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1514 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1517 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1519 compose->updating = TRUE;
1521 textview = GTK_TEXT_VIEW(compose->text);
1522 textbuf = gtk_text_view_get_buffer(textview);
1523 compose_create_tags(textview, compose);
1525 undo_block(compose->undostruct);
1526 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1527 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1529 if (!is_file_exist(msgfile))
1530 g_warning("%s: file not exist\n", msgfile);
1532 compose_attach_append(compose, msgfile, msgfile,
1538 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1539 if (info->subject && *info->subject) {
1540 gchar *buf, *buf2, *p;
1542 buf = p = g_strdup(info->subject);
1543 p += subject_get_prefix_length(p);
1544 memmove(buf, p, strlen(p) + 1);
1546 buf2 = g_strdup_printf("Fw: %s", buf);
1547 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1553 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1554 _("Fw: multiple emails"));
1557 SIGNAL_BLOCK(textbuf);
1559 if (account->auto_sig)
1560 compose_insert_sig(compose, FALSE);
1562 compose_wrap_all(compose);
1564 SIGNAL_UNBLOCK(textbuf);
1566 gtk_text_buffer_get_start_iter(textbuf, &iter);
1567 gtk_text_buffer_place_cursor(textbuf, &iter);
1569 gtk_widget_grab_focus(compose->header_last->entry);
1570 undo_unblock(compose->undostruct);
1571 compose->modified = FALSE;
1572 compose_set_title(compose);
1574 compose->updating = FALSE;
1576 if (compose->deferred_destroy) {
1577 compose_destroy(compose);
1584 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1586 GtkTextIter start = *iter;
1587 GtkTextIter end_iter;
1588 int start_pos = gtk_text_iter_get_offset(&start);
1590 if (!compose->account->sig_sep)
1593 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1594 start_pos+strlen(compose->account->sig_sep));
1596 /* check sig separator */
1597 str = gtk_text_iter_get_text(&start, &end_iter);
1598 if (!strcmp(str, compose->account->sig_sep)) {
1600 /* check end of line (\n) */
1601 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1602 start_pos+strlen(compose->account->sig_sep));
1603 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1604 start_pos+strlen(compose->account->sig_sep)+1);
1605 tmp = gtk_text_iter_get_text(&start, &end_iter);
1606 if (!strcmp(tmp,"\n")) {
1618 static void compose_colorize_signature(Compose *compose)
1620 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1622 GtkTextIter end_iter;
1623 gtk_text_buffer_get_start_iter(buffer, &iter);
1624 while (gtk_text_iter_forward_line(&iter))
1625 if (compose_is_sig_separator(compose, buffer, &iter)) {
1626 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1627 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1631 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1633 Compose *compose = NULL;
1634 PrefsAccount *account = NULL;
1635 GtkTextView *textview;
1636 GtkTextBuffer *textbuf;
1640 gchar buf[BUFFSIZE];
1641 gboolean use_signing = FALSE;
1642 gboolean use_encryption = FALSE;
1643 gchar *privacy_system = NULL;
1644 int priority = PRIORITY_NORMAL;
1646 g_return_val_if_fail(msginfo != NULL, NULL);
1647 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1649 if (compose_put_existing_to_front(msginfo)) {
1653 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1654 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1655 gchar queueheader_buf[BUFFSIZE];
1658 /* Select Account from queue headers */
1659 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1660 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1661 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1662 account = account_find_from_id(id);
1664 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1665 sizeof(queueheader_buf), "NAID:")) {
1666 id = atoi(&queueheader_buf[strlen("NAID:")]);
1667 account = account_find_from_id(id);
1669 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1670 sizeof(queueheader_buf), "MAID:")) {
1671 id = atoi(&queueheader_buf[strlen("MAID:")]);
1672 account = account_find_from_id(id);
1674 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1675 sizeof(queueheader_buf), "S:")) {
1676 account = account_find_from_address(queueheader_buf);
1678 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1679 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1680 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1681 use_signing = param;
1684 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1685 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1686 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1687 use_encryption = param;
1689 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1690 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1691 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1693 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1694 sizeof(queueheader_buf), "X-Priority: ")) {
1695 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1699 account = msginfo->folder->folder->account;
1702 if (!account && prefs_common.reedit_account_autosel) {
1703 gchar from[BUFFSIZE];
1704 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1705 extract_address(from);
1706 account = account_find_from_address(from);
1710 account = cur_account;
1712 g_return_val_if_fail(account != NULL, NULL);
1714 compose = compose_create(account, COMPOSE_REEDIT, batch);
1716 compose->updating = TRUE;
1717 compose->priority = priority;
1719 if (privacy_system != NULL) {
1720 compose->privacy_system = privacy_system;
1721 compose_use_signing(compose, use_signing);
1722 compose_use_encryption(compose, use_encryption);
1723 compose_update_privacy_system_menu_item(compose, FALSE);
1725 activate_privacy_system(compose, account, FALSE);
1728 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1730 compose_extract_original_charset(compose);
1732 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1733 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1734 gchar queueheader_buf[BUFFSIZE];
1736 /* Set message save folder */
1737 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1740 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1741 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1742 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1744 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1745 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1747 GtkItemFactory *ifactory;
1748 ifactory = gtk_item_factory_from_widget(compose->menubar);
1749 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1754 if (compose_parse_header(compose, msginfo) < 0) {
1755 compose->updating = FALSE;
1756 compose_destroy(compose);
1759 compose_reedit_set_entry(compose, msginfo);
1761 textview = GTK_TEXT_VIEW(compose->text);
1762 textbuf = gtk_text_view_get_buffer(textview);
1763 compose_create_tags(textview, compose);
1765 mark = gtk_text_buffer_get_insert(textbuf);
1766 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1768 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1769 G_CALLBACK(compose_changed_cb),
1772 if (procmime_msginfo_is_encrypted(msginfo)) {
1773 fp = procmime_get_first_encrypted_text_content(msginfo);
1775 compose_force_encryption(compose, account, TRUE);
1778 fp = procmime_get_first_text_content(msginfo);
1781 g_warning("Can't get text part\n");
1785 gboolean prev_autowrap = compose->autowrap;
1787 compose->autowrap = FALSE;
1788 while (fgets(buf, sizeof(buf), fp) != NULL) {
1790 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1792 compose_wrap_all_full(compose, FALSE);
1793 compose->autowrap = prev_autowrap;
1797 compose_attach_parts(compose, msginfo);
1799 compose_colorize_signature(compose);
1801 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1802 G_CALLBACK(compose_changed_cb),
1805 gtk_widget_grab_focus(compose->text);
1807 if (prefs_common.auto_exteditor) {
1808 compose_exec_ext_editor(compose);
1810 compose->modified = FALSE;
1811 compose_set_title(compose);
1813 compose->updating = FALSE;
1815 if (compose->deferred_destroy) {
1816 compose_destroy(compose);
1820 compose->sig_str = compose_get_signature_str(compose);
1825 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1830 GtkItemFactory *ifactory;
1833 g_return_val_if_fail(msginfo != NULL, NULL);
1836 account = account_get_reply_account(msginfo,
1837 prefs_common.reply_account_autosel);
1838 g_return_val_if_fail(account != NULL, NULL);
1840 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1842 compose->updating = TRUE;
1844 ifactory = gtk_item_factory_from_widget(compose->menubar);
1845 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1846 compose->replyinfo = NULL;
1847 compose->fwdinfo = NULL;
1849 compose_show_first_last_header(compose, TRUE);
1851 gtk_widget_grab_focus(compose->header_last->entry);
1853 filename = procmsg_get_message_file_path(msginfo);
1855 if (filename == NULL) {
1856 compose->updating = FALSE;
1857 compose_destroy(compose);
1862 compose->redirect_filename = filename;
1864 /* Set save folder */
1865 item = msginfo->folder;
1866 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1867 gchar *folderidentifier;
1869 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1870 folderidentifier = folder_item_get_identifier(item);
1871 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1872 g_free(folderidentifier);
1875 compose_attach_parts(compose, msginfo);
1877 if (msginfo->subject)
1878 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1880 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1882 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1883 quote_fmt_reset_vartable();
1884 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1886 compose_colorize_signature(compose);
1888 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1889 menu_set_sensitive(ifactory, "/Add...", FALSE);
1890 menu_set_sensitive(ifactory, "/Remove", FALSE);
1891 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1893 ifactory = gtk_item_factory_from_widget(compose->menubar);
1894 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1895 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1896 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1897 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1898 menu_set_sensitive(ifactory, "/Edit", FALSE);
1899 menu_set_sensitive(ifactory, "/Options", FALSE);
1900 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1901 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1903 if (compose->toolbar->draft_btn)
1904 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1905 if (compose->toolbar->insert_btn)
1906 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1907 if (compose->toolbar->attach_btn)
1908 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1909 if (compose->toolbar->sig_btn)
1910 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1911 if (compose->toolbar->exteditor_btn)
1912 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1913 if (compose->toolbar->linewrap_current_btn)
1914 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1915 if (compose->toolbar->linewrap_all_btn)
1916 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1918 compose->modified = FALSE;
1919 compose_set_title(compose);
1920 compose->updating = FALSE;
1922 if (compose->deferred_destroy) {
1923 compose_destroy(compose);
1930 GList *compose_get_compose_list(void)
1932 return compose_list;
1935 void compose_entry_append(Compose *compose, const gchar *address,
1936 ComposeEntryType type)
1940 gboolean in_quote = FALSE;
1941 if (!address || *address == '\0') return;
1948 header = N_("Bcc:");
1950 case COMPOSE_REPLYTO:
1951 header = N_("Reply-To:");
1953 case COMPOSE_NEWSGROUPS:
1954 header = N_("Newsgroups:");
1956 case COMPOSE_FOLLOWUPTO:
1957 header = N_( "Followup-To:");
1964 header = prefs_common.trans_hdr ? gettext(header) : header;
1966 cur = begin = (gchar *)address;
1968 /* we separate the line by commas, but not if we're inside a quoted
1970 while (*cur != '\0') {
1972 in_quote = !in_quote;
1973 if (*cur == ',' && !in_quote) {
1974 gchar *tmp = g_strdup(begin);
1976 tmp[cur-begin]='\0';
1979 while (*tmp == ' ' || *tmp == '\t')
1981 compose_add_header_entry(compose, header, tmp);
1988 gchar *tmp = g_strdup(begin);
1990 tmp[cur-begin]='\0';
1993 while (*tmp == ' ' || *tmp == '\t')
1995 compose_add_header_entry(compose, header, tmp);
2000 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
2002 static GdkColor yellow;
2003 static GdkColor black;
2004 static gboolean yellow_initialised = FALSE;
2008 if (!yellow_initialised) {
2009 gdk_color_parse("#f5f6be", &yellow);
2010 gdk_color_parse("#000000", &black);
2011 yellow_initialised = gdk_colormap_alloc_color(
2012 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2013 yellow_initialised &= gdk_colormap_alloc_color(
2014 gdk_colormap_get_system(), &black, FALSE, TRUE);
2017 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2018 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2019 if (gtk_entry_get_text(entry) &&
2020 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2021 if (yellow_initialised) {
2022 gtk_widget_modify_base(
2023 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2024 GTK_STATE_NORMAL, &yellow);
2025 gtk_widget_modify_text(
2026 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2027 GTK_STATE_NORMAL, &black);
2033 void compose_toolbar_cb(gint action, gpointer data)
2035 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2036 Compose *compose = (Compose*)toolbar_item->parent;
2038 g_return_if_fail(compose != NULL);
2042 compose_send_cb(compose, 0, NULL);
2045 compose_send_later_cb(compose, 0, NULL);
2048 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2051 compose_insert_file_cb(compose, 0, NULL);
2054 compose_attach_cb(compose, 0, NULL);
2057 compose_insert_sig(compose, FALSE);
2060 compose_ext_editor_cb(compose, 0, NULL);
2062 case A_LINEWRAP_CURRENT:
2063 compose_beautify_paragraph(compose, NULL, TRUE);
2065 case A_LINEWRAP_ALL:
2066 compose_wrap_all_full(compose, TRUE);
2069 compose_address_cb(compose, 0, NULL);
2072 case A_CHECK_SPELLING:
2073 compose_check_all(compose);
2081 static void compose_entries_set(Compose *compose, const gchar *mailto)
2085 gchar *subject = NULL;
2090 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2093 compose_entry_append(compose, to, COMPOSE_TO);
2095 compose_entry_append(compose, cc, COMPOSE_CC);
2097 if (!g_utf8_validate (subject, -1, NULL)) {
2098 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2099 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2102 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2106 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2107 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2110 gboolean prev_autowrap = compose->autowrap;
2112 compose->autowrap = FALSE;
2114 mark = gtk_text_buffer_get_insert(buffer);
2115 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2117 if (!g_utf8_validate (body, -1, NULL)) {
2118 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2119 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2122 gtk_text_buffer_insert(buffer, &iter, body, -1);
2124 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2126 compose->autowrap = prev_autowrap;
2127 if (compose->autowrap)
2128 compose_wrap_all(compose);
2137 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2139 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2140 {"Cc:", NULL, TRUE},
2141 {"References:", NULL, FALSE},
2142 {"Bcc:", NULL, TRUE},
2143 {"Newsgroups:", NULL, TRUE},
2144 {"Followup-To:", NULL, TRUE},
2145 {"List-Post:", NULL, FALSE},
2146 {"X-Priority:", NULL, FALSE},
2147 {NULL, NULL, FALSE}};
2163 g_return_val_if_fail(msginfo != NULL, -1);
2165 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2166 procheader_get_header_fields(fp, hentry);
2169 if (hentry[H_REPLY_TO].body != NULL) {
2170 if (hentry[H_REPLY_TO].body[0] != '\0') {
2172 conv_unmime_header(hentry[H_REPLY_TO].body,
2175 g_free(hentry[H_REPLY_TO].body);
2176 hentry[H_REPLY_TO].body = NULL;
2178 if (hentry[H_CC].body != NULL) {
2179 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2180 g_free(hentry[H_CC].body);
2181 hentry[H_CC].body = NULL;
2183 if (hentry[H_REFERENCES].body != NULL) {
2184 if (compose->mode == COMPOSE_REEDIT)
2185 compose->references = hentry[H_REFERENCES].body;
2187 compose->references = compose_parse_references
2188 (hentry[H_REFERENCES].body, msginfo->msgid);
2189 g_free(hentry[H_REFERENCES].body);
2191 hentry[H_REFERENCES].body = NULL;
2193 if (hentry[H_BCC].body != NULL) {
2194 if (compose->mode == COMPOSE_REEDIT)
2196 conv_unmime_header(hentry[H_BCC].body, NULL);
2197 g_free(hentry[H_BCC].body);
2198 hentry[H_BCC].body = NULL;
2200 if (hentry[H_NEWSGROUPS].body != NULL) {
2201 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2202 hentry[H_NEWSGROUPS].body = NULL;
2204 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2205 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2206 compose->followup_to =
2207 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2210 g_free(hentry[H_FOLLOWUP_TO].body);
2211 hentry[H_FOLLOWUP_TO].body = NULL;
2213 if (hentry[H_LIST_POST].body != NULL) {
2216 extract_address(hentry[H_LIST_POST].body);
2217 if (hentry[H_LIST_POST].body[0] != '\0') {
2218 scan_mailto_url(hentry[H_LIST_POST].body,
2219 &to, NULL, NULL, NULL, NULL);
2221 g_free(compose->ml_post);
2222 compose->ml_post = to;
2225 g_free(hentry[H_LIST_POST].body);
2226 hentry[H_LIST_POST].body = NULL;
2229 /* CLAWS - X-Priority */
2230 if (compose->mode == COMPOSE_REEDIT)
2231 if (hentry[H_X_PRIORITY].body != NULL) {
2234 priority = atoi(hentry[H_X_PRIORITY].body);
2235 g_free(hentry[H_X_PRIORITY].body);
2237 hentry[H_X_PRIORITY].body = NULL;
2239 if (priority < PRIORITY_HIGHEST ||
2240 priority > PRIORITY_LOWEST)
2241 priority = PRIORITY_NORMAL;
2243 compose->priority = priority;
2246 if (compose->mode == COMPOSE_REEDIT) {
2247 if (msginfo->inreplyto && *msginfo->inreplyto)
2248 compose->inreplyto = g_strdup(msginfo->inreplyto);
2252 if (msginfo->msgid && *msginfo->msgid)
2253 compose->inreplyto = g_strdup(msginfo->msgid);
2255 if (!compose->references) {
2256 if (msginfo->msgid && *msginfo->msgid) {
2257 if (msginfo->inreplyto && *msginfo->inreplyto)
2258 compose->references =
2259 g_strdup_printf("<%s>\n\t<%s>",
2263 compose->references =
2264 g_strconcat("<", msginfo->msgid, ">",
2266 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2267 compose->references =
2268 g_strconcat("<", msginfo->inreplyto, ">",
2276 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2278 GSList *ref_id_list, *cur;
2282 ref_id_list = references_list_append(NULL, ref);
2283 if (!ref_id_list) return NULL;
2284 if (msgid && *msgid)
2285 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2290 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2291 /* "<" + Message-ID + ">" + CR+LF+TAB */
2292 len += strlen((gchar *)cur->data) + 5;
2294 if (len > MAX_REFERENCES_LEN) {
2295 /* remove second message-ID */
2296 if (ref_id_list && ref_id_list->next &&
2297 ref_id_list->next->next) {
2298 g_free(ref_id_list->next->data);
2299 ref_id_list = g_slist_remove
2300 (ref_id_list, ref_id_list->next->data);
2302 slist_free_strings(ref_id_list);
2303 g_slist_free(ref_id_list);
2310 new_ref = g_string_new("");
2311 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2312 if (new_ref->len > 0)
2313 g_string_append(new_ref, "\n\t");
2314 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2317 slist_free_strings(ref_id_list);
2318 g_slist_free(ref_id_list);
2320 new_ref_str = new_ref->str;
2321 g_string_free(new_ref, FALSE);
2326 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2327 const gchar *fmt, const gchar *qmark,
2328 const gchar *body, gboolean rewrap)
2330 static MsgInfo dummyinfo;
2331 gchar *quote_str = NULL;
2333 gboolean prev_autowrap;
2334 const gchar *trimmed_body = body;
2335 gint cursor_pos = -1;
2336 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2337 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2342 SIGNAL_BLOCK(buffer);
2345 msginfo = &dummyinfo;
2347 if (qmark != NULL) {
2348 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2349 quote_fmt_scan_string(qmark);
2352 buf = quote_fmt_get_buffer();
2354 alertpanel_error(_("Quote mark format error."));
2356 Xstrdup_a(quote_str, buf, goto error)
2359 if (fmt && *fmt != '\0') {
2360 while (trimmed_body && strlen(trimmed_body) > 1
2361 && trimmed_body[0]=='\n')
2364 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2365 quote_fmt_scan_string(fmt);
2368 buf = quote_fmt_get_buffer();
2370 alertpanel_error(_("Message reply/forward format error."));
2376 prev_autowrap = compose->autowrap;
2377 compose->autowrap = FALSE;
2379 mark = gtk_text_buffer_get_insert(buffer);
2380 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2381 if (g_utf8_validate(buf, -1, NULL)) {
2382 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2384 gchar *tmpout = NULL;
2385 tmpout = conv_codeset_strdup
2386 (buf, conv_get_locale_charset_str_no_utf8(),
2388 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2390 tmpout = g_malloc(strlen(buf)*2+1);
2391 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2393 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2397 cursor_pos = quote_fmt_get_cursor_pos();
2398 compose->set_cursor_pos = cursor_pos;
2399 if (cursor_pos == -1) {
2402 gtk_text_buffer_get_start_iter(buffer, &iter);
2403 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2404 gtk_text_buffer_place_cursor(buffer, &iter);
2406 compose->autowrap = prev_autowrap;
2407 if (compose->autowrap && rewrap)
2408 compose_wrap_all(compose);
2415 SIGNAL_UNBLOCK(buffer);
2421 /* if ml_post is of type addr@host and from is of type
2422 * addr-anything@host, return TRUE
2424 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2426 gchar *left_ml = NULL;
2427 gchar *right_ml = NULL;
2428 gchar *left_from = NULL;
2429 gchar *right_from = NULL;
2430 gboolean result = FALSE;
2432 if (!ml_post || !from)
2435 left_ml = g_strdup(ml_post);
2436 if (strstr(left_ml, "@")) {
2437 right_ml = strstr(left_ml, "@")+1;
2438 *(strstr(left_ml, "@")) = '\0';
2441 left_from = g_strdup(from);
2442 if (strstr(left_from, "@")) {
2443 right_from = strstr(left_from, "@")+1;
2444 *(strstr(left_from, "@")) = '\0';
2447 if (left_ml && left_from && right_ml && right_from
2448 && !strncmp(left_from, left_ml, strlen(left_ml))
2449 && !strcmp(right_from, right_ml)) {
2458 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2460 gchar *my_addr1, *my_addr2;
2462 if (!addr1 || !addr2)
2465 Xstrdup_a(my_addr1, addr1, return FALSE);
2466 Xstrdup_a(my_addr2, addr2, return FALSE);
2468 extract_address(my_addr1);
2469 extract_address(my_addr2);
2471 return !strcmp(my_addr1, my_addr2);
2474 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2475 gboolean to_all, gboolean to_ml,
2477 gboolean followup_and_reply_to)
2479 GSList *cc_list = NULL;
2482 gchar *replyto = NULL;
2483 GHashTable *to_table;
2485 gboolean reply_to_ml = FALSE;
2486 gboolean default_reply_to = FALSE;
2488 g_return_if_fail(compose->account != NULL);
2489 g_return_if_fail(msginfo != NULL);
2491 reply_to_ml = to_ml && compose->ml_post;
2493 default_reply_to = msginfo->folder &&
2494 msginfo->folder->prefs->enable_default_reply_to;
2496 if (compose->account->protocol != A_NNTP) {
2497 if (reply_to_ml && !default_reply_to) {
2499 gboolean is_subscr = is_subscription(compose->ml_post,
2502 /* normal answer to ml post with a reply-to */
2503 compose_entry_append(compose,
2506 if (compose->replyto
2507 && !same_address(compose->ml_post, compose->replyto))
2508 compose_entry_append(compose,
2512 /* answer to subscription confirmation */
2513 if (compose->replyto)
2514 compose_entry_append(compose,
2517 else if (msginfo->from)
2518 compose_entry_append(compose,
2523 else if (!(to_all || to_sender) && default_reply_to) {
2524 compose_entry_append(compose,
2525 msginfo->folder->prefs->default_reply_to,
2527 compose_entry_mark_default_to(compose,
2528 msginfo->folder->prefs->default_reply_to);
2533 Xstrdup_a(tmp1, msginfo->from, return);
2534 extract_address(tmp1);
2535 if (to_all || to_sender ||
2536 !account_find_from_address(tmp1))
2537 compose_entry_append(compose,
2538 (compose->replyto && !to_sender)
2539 ? compose->replyto :
2540 msginfo->from ? msginfo->from : "",
2542 else if (!to_all && !to_sender) {
2543 /* reply to the last list of recipients */
2544 compose_entry_append(compose,
2545 msginfo->to ? msginfo->to : "",
2547 compose_entry_append(compose,
2548 msginfo->cc ? msginfo->cc : "",
2553 if (to_sender || (compose->followup_to &&
2554 !strncmp(compose->followup_to, "poster", 6)))
2555 compose_entry_append
2557 (compose->replyto ? compose->replyto :
2558 msginfo->from ? msginfo->from : ""),
2561 else if (followup_and_reply_to || to_all) {
2562 compose_entry_append
2564 (compose->replyto ? compose->replyto :
2565 msginfo->from ? msginfo->from : ""),
2568 compose_entry_append
2570 compose->followup_to ? compose->followup_to :
2571 compose->newsgroups ? compose->newsgroups : "",
2572 COMPOSE_NEWSGROUPS);
2575 compose_entry_append
2577 compose->followup_to ? compose->followup_to :
2578 compose->newsgroups ? compose->newsgroups : "",
2579 COMPOSE_NEWSGROUPS);
2582 if (msginfo->subject && *msginfo->subject) {
2586 buf = p = g_strdup(msginfo->subject);
2587 p += subject_get_prefix_length(p);
2588 memmove(buf, p, strlen(p) + 1);
2590 buf2 = g_strdup_printf("Re: %s", buf);
2591 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2596 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2598 if (to_ml && compose->ml_post) return;
2599 if (!to_all || compose->account->protocol == A_NNTP) return;
2601 if (compose->replyto) {
2602 Xstrdup_a(replyto, compose->replyto, return);
2603 extract_address(replyto);
2605 if (msginfo->from) {
2606 Xstrdup_a(from, msginfo->from, return);
2607 extract_address(from);
2610 if (replyto && from)
2611 cc_list = address_list_append_with_comments(cc_list, from);
2612 if (to_all && msginfo->folder &&
2613 msginfo->folder->prefs->enable_default_reply_to)
2614 cc_list = address_list_append_with_comments(cc_list,
2615 msginfo->folder->prefs->default_reply_to);
2616 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2617 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2619 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2621 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2622 if (compose->account)
2623 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2624 GINT_TO_POINTER(1));
2626 /* remove address on To: and that of current account */
2627 for (cur = cc_list; cur != NULL; ) {
2628 GSList *next = cur->next;
2631 addr = g_strdup(cur->data);
2632 extract_address(addr);
2634 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2635 cc_list = g_slist_remove(cc_list, cur->data);
2637 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2641 hash_free_strings(to_table);
2642 g_hash_table_destroy(to_table);
2645 for (cur = cc_list; cur != NULL; cur = cur->next)
2646 compose_entry_append(compose, (gchar *)cur->data,
2648 slist_free_strings(cc_list);
2649 g_slist_free(cc_list);
2654 #define SET_ENTRY(entry, str) \
2657 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2660 #define SET_ADDRESS(type, str) \
2663 compose_entry_append(compose, str, type); \
2666 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2668 g_return_if_fail(msginfo != NULL);
2670 SET_ENTRY(subject_entry, msginfo->subject);
2671 SET_ENTRY(from_name, msginfo->from);
2672 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2673 SET_ADDRESS(COMPOSE_CC, compose->cc);
2674 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2675 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2676 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2677 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2679 compose_update_priority_menu_item(compose);
2680 compose_update_privacy_system_menu_item(compose, FALSE);
2681 compose_show_first_last_header(compose, TRUE);
2687 static void compose_insert_sig(Compose *compose, gboolean replace)
2689 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2690 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2692 GtkTextIter iter, iter_end;
2694 gchar *search = NULL;
2695 gboolean prev_autowrap;
2696 gboolean found = FALSE, shift = FALSE;
2699 g_return_if_fail(compose->account != NULL);
2701 prev_autowrap = compose->autowrap;
2702 compose->autowrap = FALSE;
2704 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2705 G_CALLBACK(compose_changed_cb),
2708 mark = gtk_text_buffer_get_insert(buffer);
2709 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2710 cur_pos = gtk_text_iter_get_offset (&iter);
2712 gtk_text_buffer_get_end_iter(buffer, &iter);
2714 search = compose->sig_str;
2716 if (replace && search) {
2717 GtkTextIter first_iter, start_iter, end_iter;
2719 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2721 if (compose->sig_str[0] == '\0')
2724 found = gtk_text_iter_forward_search(&first_iter,
2726 GTK_TEXT_SEARCH_TEXT_ONLY,
2727 &start_iter, &end_iter,
2731 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2735 if (replace && !found && search && strlen(search) > 2
2736 && search[0] == '\n' && search[1] == '\n') {
2742 g_free(compose->sig_str);
2743 compose->sig_str = compose_get_signature_str(compose);
2744 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2745 compose->sig_str = g_strdup("");
2747 cur_pos = gtk_text_iter_get_offset(&iter);
2749 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2751 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2753 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2754 gtk_text_iter_forward_char(&iter);
2755 gtk_text_iter_forward_char(&iter);
2756 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2757 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2759 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2760 cur_pos = gtk_text_buffer_get_char_count (buffer);
2762 /* put the cursor where it should be
2763 * either where the quote_fmt says, either before the signature */
2764 if (compose->set_cursor_pos < 0)
2765 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2767 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2768 compose->set_cursor_pos);
2770 gtk_text_buffer_place_cursor(buffer, &iter);
2771 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2772 G_CALLBACK(compose_changed_cb),
2775 compose->autowrap = prev_autowrap;
2776 if (compose->autowrap)
2777 compose_wrap_all(compose);
2780 static gchar *compose_get_signature_str(Compose *compose)
2782 gchar *sig_body = NULL;
2783 gchar *sig_str = NULL;
2784 gchar *utf8_sig_str = NULL;
2786 g_return_val_if_fail(compose->account != NULL, NULL);
2788 if (!compose->account->sig_path)
2791 if (compose->account->sig_type == SIG_FILE) {
2792 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2793 g_warning("can't open signature file: %s\n",
2794 compose->account->sig_path);
2799 if (compose->account->sig_type == SIG_COMMAND)
2800 sig_body = get_command_output(compose->account->sig_path);
2804 tmp = file_read_to_str(compose->account->sig_path);
2807 sig_body = normalize_newlines(tmp);
2811 if (compose->account->sig_sep) {
2812 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2816 sig_str = g_strconcat("\n\n", sig_body, NULL);
2819 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2820 utf8_sig_str = sig_str;
2822 utf8_sig_str = conv_codeset_strdup
2823 (sig_str, conv_get_locale_charset_str_no_utf8(),
2829 return utf8_sig_str;
2832 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2835 GtkTextBuffer *buffer;
2838 const gchar *cur_encoding;
2839 gchar buf[BUFFSIZE];
2842 gboolean prev_autowrap;
2843 gboolean badtxt = FALSE;
2845 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2847 if ((fp = g_fopen(file, "rb")) == NULL) {
2848 FILE_OP_ERROR(file, "fopen");
2849 return COMPOSE_INSERT_READ_ERROR;
2852 prev_autowrap = compose->autowrap;
2853 compose->autowrap = FALSE;
2855 text = GTK_TEXT_VIEW(compose->text);
2856 buffer = gtk_text_view_get_buffer(text);
2857 mark = gtk_text_buffer_get_insert(buffer);
2858 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2860 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2861 G_CALLBACK(text_inserted),
2864 cur_encoding = conv_get_locale_charset_str_no_utf8();
2866 while (fgets(buf, sizeof(buf), fp) != NULL) {
2869 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2870 str = g_strdup(buf);
2872 str = conv_codeset_strdup
2873 (buf, cur_encoding, CS_INTERNAL);
2876 /* strip <CR> if DOS/Windows file,
2877 replace <CR> with <LF> if Macintosh file. */
2880 if (len > 0 && str[len - 1] != '\n') {
2882 if (str[len] == '\r') str[len] = '\n';
2885 gtk_text_buffer_insert(buffer, &iter, str, -1);
2889 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2890 G_CALLBACK(text_inserted),
2892 compose->autowrap = prev_autowrap;
2893 if (compose->autowrap)
2894 compose_wrap_all(compose);
2899 return COMPOSE_INSERT_INVALID_CHARACTER;
2901 return COMPOSE_INSERT_SUCCESS;
2904 static void compose_attach_append(Compose *compose, const gchar *file,
2905 const gchar *filename,
2906 const gchar *content_type)
2914 GtkListStore *store;
2916 gboolean has_binary = FALSE;
2918 if (!is_file_exist(file)) {
2919 g_warning("File %s doesn't exist\n", filename);
2922 if ((size = get_file_size(file)) < 0) {
2923 g_warning("Can't get file size of %s\n", filename);
2927 alertpanel_notice(_("File %s is empty."), filename);
2930 if ((fp = g_fopen(file, "rb")) == NULL) {
2931 alertpanel_error(_("Can't read %s."), filename);
2936 ainfo = g_new0(AttachInfo, 1);
2937 auto_ainfo = g_auto_pointer_new_with_free
2938 (ainfo, (GFreeFunc) compose_attach_info_free);
2939 ainfo->file = g_strdup(file);
2942 ainfo->content_type = g_strdup(content_type);
2943 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2945 MsgFlags flags = {0, 0};
2947 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2948 ainfo->encoding = ENC_7BIT;
2950 ainfo->encoding = ENC_8BIT;
2952 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2953 if (msginfo && msginfo->subject)
2954 name = g_strdup(msginfo->subject);
2956 name = g_path_get_basename(filename ? filename : file);
2958 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2960 procmsg_msginfo_free(msginfo);
2962 if (!g_ascii_strncasecmp(content_type, "text", 4))
2963 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2965 ainfo->encoding = ENC_BASE64;
2966 name = g_path_get_basename(filename ? filename : file);
2967 ainfo->name = g_strdup(name);
2971 ainfo->content_type = procmime_get_mime_type(file);
2972 if (!ainfo->content_type) {
2973 ainfo->content_type =
2974 g_strdup("application/octet-stream");
2975 ainfo->encoding = ENC_BASE64;
2976 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2978 procmime_get_encoding_for_text_file(file, &has_binary);
2980 ainfo->encoding = ENC_BASE64;
2981 name = g_path_get_basename(filename ? filename : file);
2982 ainfo->name = g_strdup(name);
2986 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2987 g_free(ainfo->content_type);
2988 ainfo->content_type = g_strdup("application/octet-stream");
2992 size_text = to_human_readable(size);
2994 store = GTK_LIST_STORE(gtk_tree_view_get_model
2995 (GTK_TREE_VIEW(compose->attach_clist)));
2997 gtk_list_store_append(store, &iter);
2998 gtk_list_store_set(store, &iter,
2999 COL_MIMETYPE, ainfo->content_type,
3000 COL_SIZE, size_text,
3001 COL_NAME, ainfo->name,
3003 COL_AUTODATA, auto_ainfo,
3006 g_auto_pointer_free(auto_ainfo);
3009 static void compose_use_signing(Compose *compose, gboolean use_signing)
3011 GtkItemFactory *ifactory;
3012 GtkWidget *menuitem = NULL;
3014 compose->use_signing = use_signing;
3015 ifactory = gtk_item_factory_from_widget(compose->menubar);
3016 menuitem = gtk_item_factory_get_item
3017 (ifactory, "/Options/Sign");
3018 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3022 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3024 GtkItemFactory *ifactory;
3025 GtkWidget *menuitem = NULL;
3027 compose->use_encryption = use_encryption;
3028 ifactory = gtk_item_factory_from_widget(compose->menubar);
3029 menuitem = gtk_item_factory_get_item
3030 (ifactory, "/Options/Encrypt");
3032 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3036 #define NEXT_PART_NOT_CHILD(info) \
3038 node = info->node; \
3039 while (node->children) \
3040 node = g_node_last_child(node); \
3041 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3044 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3048 MimeInfo *firsttext = NULL;
3049 MimeInfo *encrypted = NULL;
3052 const gchar *partname = NULL;
3054 mimeinfo = procmime_scan_message(msginfo);
3055 if (!mimeinfo) return;
3057 if (mimeinfo->node->children == NULL) {
3058 procmime_mimeinfo_free_all(mimeinfo);
3062 /* find first content part */
3063 child = (MimeInfo *) mimeinfo->node->children->data;
3064 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3065 child = (MimeInfo *)child->node->children->data;
3067 if (child->type == MIMETYPE_TEXT) {
3069 debug_print("First text part found\n");
3070 } else if (compose->mode == COMPOSE_REEDIT &&
3071 child->type == MIMETYPE_APPLICATION &&
3072 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3073 encrypted = (MimeInfo *)child->node->parent->data;
3076 child = (MimeInfo *) mimeinfo->node->children->data;
3077 while (child != NULL) {
3078 if (child == encrypted) {
3079 /* skip this part of tree */
3080 NEXT_PART_NOT_CHILD(child);
3084 if (child->type == MIMETYPE_MULTIPART) {
3085 /* get the actual content */
3086 child = procmime_mimeinfo_next(child);
3090 if (child == firsttext) {
3091 child = procmime_mimeinfo_next(child);
3095 outfile = procmime_get_tmp_file_name(child);
3096 if (procmime_get_part(outfile, child) < 0)
3097 g_warning("Can't get the part of multipart message.");
3099 gchar *content_type;
3101 content_type = procmime_get_content_type_str(child->type, child->subtype);
3103 /* if we meet a pgp signature, we don't attach it, but
3104 * we force signing. */
3105 if (strcmp(content_type, "application/pgp-signature")) {
3106 partname = procmime_mimeinfo_get_parameter(child, "filename");
3107 if (partname == NULL)
3108 partname = procmime_mimeinfo_get_parameter(child, "name");
3109 if (partname == NULL)
3111 compose_attach_append(compose, outfile,
3112 partname, content_type);
3114 compose_force_signing(compose, compose->account);
3116 g_free(content_type);
3119 NEXT_PART_NOT_CHILD(child);
3121 procmime_mimeinfo_free_all(mimeinfo);
3124 #undef NEXT_PART_NOT_CHILD
3129 WAIT_FOR_INDENT_CHAR,
3130 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3133 /* return indent length, we allow:
3134 indent characters followed by indent characters or spaces/tabs,
3135 alphabets and numbers immediately followed by indent characters,
3136 and the repeating sequences of the above
3137 If quote ends with multiple spaces, only the first one is included. */
3138 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3139 const GtkTextIter *start, gint *len)
3141 GtkTextIter iter = *start;
3145 IndentState state = WAIT_FOR_INDENT_CHAR;
3148 gint alnum_count = 0;
3149 gint space_count = 0;
3152 if (prefs_common.quote_chars == NULL) {
3156 while (!gtk_text_iter_ends_line(&iter)) {
3157 wc = gtk_text_iter_get_char(&iter);
3158 if (g_unichar_iswide(wc))
3160 clen = g_unichar_to_utf8(wc, ch);
3164 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3165 is_space = g_unichar_isspace(wc);
3167 if (state == WAIT_FOR_INDENT_CHAR) {
3168 if (!is_indent && !g_unichar_isalnum(wc))
3171 quote_len += alnum_count + space_count + 1;
3172 alnum_count = space_count = 0;
3173 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3176 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3177 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3181 else if (is_indent) {
3182 quote_len += alnum_count + space_count + 1;
3183 alnum_count = space_count = 0;
3186 state = WAIT_FOR_INDENT_CHAR;
3190 gtk_text_iter_forward_char(&iter);
3193 if (quote_len > 0 && space_count > 0)
3199 if (quote_len > 0) {
3201 gtk_text_iter_forward_chars(&iter, quote_len);
3202 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3208 /* return TRUE if the line is itemized */
3209 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3210 const GtkTextIter *start)
3212 GtkTextIter iter = *start;
3217 if (gtk_text_iter_ends_line(&iter))
3221 wc = gtk_text_iter_get_char(&iter);
3222 if (!g_unichar_isspace(wc))
3224 gtk_text_iter_forward_char(&iter);
3225 if (gtk_text_iter_ends_line(&iter))
3229 clen = g_unichar_to_utf8(wc, ch);
3233 if (!strchr("*-+", ch[0]))
3236 gtk_text_iter_forward_char(&iter);
3237 if (gtk_text_iter_ends_line(&iter))
3239 wc = gtk_text_iter_get_char(&iter);
3240 if (g_unichar_isspace(wc))
3246 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3247 const GtkTextIter *start,
3248 GtkTextIter *break_pos,
3252 GtkTextIter iter = *start, line_end = *start;
3253 PangoLogAttr *attrs;
3260 gboolean can_break = FALSE;
3261 gboolean do_break = FALSE;
3262 gboolean was_white = FALSE;
3263 gboolean prev_dont_break = FALSE;
3265 gtk_text_iter_forward_to_line_end(&line_end);
3266 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3267 len = g_utf8_strlen(str, -1);
3268 /* g_print("breaking line: %d: %s (len = %d)\n",
3269 gtk_text_iter_get_line(&iter), str, len); */
3270 attrs = g_new(PangoLogAttr, len + 1);
3272 pango_default_break(str, -1, NULL, attrs, len + 1);
3276 /* skip quote and leading spaces */
3277 for (i = 0; *p != '\0' && i < len; i++) {
3280 wc = g_utf8_get_char(p);
3281 if (i >= quote_len && !g_unichar_isspace(wc))
3283 if (g_unichar_iswide(wc))
3285 else if (*p == '\t')
3289 p = g_utf8_next_char(p);
3292 for (; *p != '\0' && i < len; i++) {
3293 PangoLogAttr *attr = attrs + i;
3297 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3300 was_white = attr->is_white;
3302 /* don't wrap URI */
3303 if ((uri_len = get_uri_len(p)) > 0) {
3305 if (pos > 0 && col > max_col) {
3315 wc = g_utf8_get_char(p);
3316 if (g_unichar_iswide(wc)) {
3318 if (prev_dont_break && can_break && attr->is_line_break)
3320 } else if (*p == '\t')
3324 if (pos > 0 && col > max_col) {
3329 if (*p == '-' || *p == '/')
3330 prev_dont_break = TRUE;
3332 prev_dont_break = FALSE;
3334 p = g_utf8_next_char(p);
3338 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3343 *break_pos = *start;
3344 gtk_text_iter_set_line_offset(break_pos, pos);
3349 static gboolean compose_join_next_line(Compose *compose,
3350 GtkTextBuffer *buffer,
3352 const gchar *quote_str)
3354 GtkTextIter iter_ = *iter, cur, prev, next, end;
3355 PangoLogAttr attrs[3];
3357 gchar *next_quote_str;
3360 gboolean keep_cursor = FALSE;
3362 if (!gtk_text_iter_forward_line(&iter_) ||
3363 gtk_text_iter_ends_line(&iter_))
3366 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3368 if ((quote_str || next_quote_str) &&
3369 strcmp2(quote_str, next_quote_str) != 0) {
3370 g_free(next_quote_str);
3373 g_free(next_quote_str);
3376 if (quote_len > 0) {
3377 gtk_text_iter_forward_chars(&end, quote_len);
3378 if (gtk_text_iter_ends_line(&end))
3382 /* don't join itemized lines */
3383 if (compose_is_itemized(buffer, &end))
3386 /* don't join signature separator */
3387 if (compose_is_sig_separator(compose, buffer, &iter_))
3390 /* delete quote str */
3392 gtk_text_buffer_delete(buffer, &iter_, &end);
3394 /* don't join line breaks put by the user */
3396 gtk_text_iter_backward_char(&cur);
3397 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3398 gtk_text_iter_forward_char(&cur);
3402 gtk_text_iter_forward_char(&cur);
3403 /* delete linebreak and extra spaces */
3404 while (gtk_text_iter_backward_char(&cur)) {
3405 wc1 = gtk_text_iter_get_char(&cur);
3406 if (!g_unichar_isspace(wc1))
3411 while (!gtk_text_iter_ends_line(&cur)) {
3412 wc1 = gtk_text_iter_get_char(&cur);
3413 if (!g_unichar_isspace(wc1))
3415 gtk_text_iter_forward_char(&cur);
3418 if (!gtk_text_iter_equal(&prev, &next)) {
3421 mark = gtk_text_buffer_get_insert(buffer);
3422 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3423 if (gtk_text_iter_equal(&prev, &cur))
3425 gtk_text_buffer_delete(buffer, &prev, &next);
3429 /* insert space if required */
3430 gtk_text_iter_backward_char(&prev);
3431 wc1 = gtk_text_iter_get_char(&prev);
3432 wc2 = gtk_text_iter_get_char(&next);
3433 gtk_text_iter_forward_char(&next);
3434 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3435 pango_default_break(str, -1, NULL, attrs, 3);
3436 if (!attrs[1].is_line_break ||
3437 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3438 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3440 gtk_text_iter_backward_char(&iter_);
3441 gtk_text_buffer_place_cursor(buffer, &iter_);
3450 #define ADD_TXT_POS(bp_, ep_, pti_) \
3451 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3452 last = last->next; \
3453 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3454 last->next = NULL; \
3456 g_warning("alloc error scanning URIs\n"); \
3459 static gboolean automatic_break = FALSE;
3460 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3462 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3463 GtkTextBuffer *buffer;
3464 GtkTextIter iter, break_pos, end_of_line;
3465 gchar *quote_str = NULL;
3467 gboolean wrap_quote = prefs_common.linewrap_quote;
3468 gboolean prev_autowrap = compose->autowrap;
3469 gint startq_offset = -1, noq_offset = -1;
3470 gint uri_start = -1, uri_stop = -1;
3471 gint nouri_start = -1, nouri_stop = -1;
3472 gint num_blocks = 0;
3473 gint quotelevel = -1;
3475 compose->autowrap = FALSE;
3477 buffer = gtk_text_view_get_buffer(text);
3478 undo_wrapping(compose->undostruct, TRUE);
3483 mark = gtk_text_buffer_get_insert(buffer);
3484 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3487 /* move to paragraph start */
3488 gtk_text_iter_set_line_offset(&iter, 0);
3489 if (gtk_text_iter_ends_line(&iter)) {
3490 while (gtk_text_iter_ends_line(&iter) &&
3491 gtk_text_iter_forward_line(&iter))
3494 while (gtk_text_iter_backward_line(&iter)) {
3495 if (gtk_text_iter_ends_line(&iter)) {
3496 gtk_text_iter_forward_line(&iter);
3502 /* go until paragraph end (empty line) */
3504 while (!gtk_text_iter_ends_line(&iter)) {
3505 gchar *scanpos = NULL;
3506 /* parse table - in order of priority */
3508 const gchar *needle; /* token */
3510 /* token search function */
3511 gchar *(*search) (const gchar *haystack,
3512 const gchar *needle);
3513 /* part parsing function */
3514 gboolean (*parse) (const gchar *start,
3515 const gchar *scanpos,
3519 /* part to URI function */
3520 gchar *(*build_uri) (const gchar *bp,
3524 static struct table parser[] = {
3525 {"http://", strcasestr, get_uri_part, make_uri_string},
3526 {"https://", strcasestr, get_uri_part, make_uri_string},
3527 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3528 {"sftp://", strcasestr, get_uri_part, make_uri_string},
3529 {"www.", strcasestr, get_uri_part, make_http_string},
3530 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3531 {"@", strcasestr, get_email_part, make_email_string}
3533 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3534 gint last_index = PARSE_ELEMS;
3536 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3539 if (!prev_autowrap && num_blocks == 0) {
3541 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3542 G_CALLBACK(text_inserted),
3545 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3548 uri_start = uri_stop = -1;
3550 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3554 if (startq_offset == -1) {
3555 startq_offset = gtk_text_iter_get_offset(&iter);
3559 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3560 if (startq_offset == -1)
3561 startq_offset = gtk_text_iter_get_offset(&iter);
3562 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3563 if (quotelevel > 2) {
3564 /* recycle colors */
3565 if (prefs_common.recycle_quote_colors)
3571 if (startq_offset == -1)
3572 noq_offset = gtk_text_iter_get_offset(&iter);
3576 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3579 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3580 prefs_common.linewrap_len,
3582 GtkTextIter prev, next, cur;
3584 if (prev_autowrap != FALSE || force) {
3585 automatic_break = TRUE;
3586 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3587 automatic_break = FALSE;
3588 } else if (quote_str && wrap_quote) {
3589 automatic_break = TRUE;
3590 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3591 automatic_break = FALSE;
3594 /* remove trailing spaces */
3596 gtk_text_iter_backward_char(&cur);
3598 while (!gtk_text_iter_starts_line(&cur)) {
3601 gtk_text_iter_backward_char(&cur);
3602 wc = gtk_text_iter_get_char(&cur);
3603 if (!g_unichar_isspace(wc))
3607 if (!gtk_text_iter_equal(&prev, &next)) {
3608 gtk_text_buffer_delete(buffer, &prev, &next);
3610 gtk_text_iter_forward_char(&break_pos);
3614 gtk_text_buffer_insert(buffer, &break_pos,
3618 compose_join_next_line(compose, buffer, &iter, quote_str);
3620 /* move iter to current line start */
3621 gtk_text_iter_set_line_offset(&iter, 0);
3628 /* move iter to next line start */
3633 if (!prev_autowrap && num_blocks > 0) {
3635 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3636 G_CALLBACK(text_inserted),
3640 while (!gtk_text_iter_ends_line(&end_of_line)) {
3641 gtk_text_iter_forward_char(&end_of_line);
3643 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3645 nouri_start = gtk_text_iter_get_offset(&iter);
3646 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3648 walk_pos = gtk_text_iter_get_offset(&iter);
3649 /* FIXME: this looks phony. scanning for anything in the parse table */
3650 for (n = 0; n < PARSE_ELEMS; n++) {
3653 tmp = parser[n].search(walk, parser[n].needle);
3655 if (scanpos == NULL || tmp < scanpos) {
3664 /* check if URI can be parsed */
3665 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3666 (const gchar **)&ep, FALSE)
3667 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3671 strlen(parser[last_index].needle);
3674 uri_start = walk_pos + (bp - o_walk);
3675 uri_stop = walk_pos + (ep - o_walk);
3679 gtk_text_iter_forward_line(&iter);
3682 if (startq_offset != -1) {
3683 GtkTextIter startquote, endquote;
3684 gtk_text_buffer_get_iter_at_offset(
3685 buffer, &startquote, startq_offset);
3687 switch (quotelevel) {
3688 case 0: gtk_text_buffer_apply_tag_by_name(
3689 buffer, "quote0", &startquote, &endquote);
3691 case 1: gtk_text_buffer_apply_tag_by_name(
3692 buffer, "quote1", &startquote, &endquote);
3694 case 2: gtk_text_buffer_apply_tag_by_name(
3695 buffer, "quote2", &startquote, &endquote);
3699 } else if (noq_offset != -1) {
3700 GtkTextIter startnoquote, endnoquote;
3701 gtk_text_buffer_get_iter_at_offset(
3702 buffer, &startnoquote, noq_offset);
3704 gtk_text_buffer_remove_tag_by_name(
3705 buffer, "quote0", &startnoquote, &endnoquote);
3706 gtk_text_buffer_remove_tag_by_name(
3707 buffer, "quote1", &startnoquote, &endnoquote);
3708 gtk_text_buffer_remove_tag_by_name(
3709 buffer, "quote2", &startnoquote, &endnoquote);
3714 GtkTextIter nouri_start_iter, nouri_end_iter;
3715 gtk_text_buffer_get_iter_at_offset(
3716 buffer, &nouri_start_iter, nouri_start);
3717 gtk_text_buffer_get_iter_at_offset(
3718 buffer, &nouri_end_iter, nouri_stop);
3719 gtk_text_buffer_remove_tag_by_name(
3720 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3722 if (uri_start > 0 && uri_stop > 0) {
3723 GtkTextIter uri_start_iter, uri_end_iter;
3724 gtk_text_buffer_get_iter_at_offset(
3725 buffer, &uri_start_iter, uri_start);
3726 gtk_text_buffer_get_iter_at_offset(
3727 buffer, &uri_end_iter, uri_stop);
3728 gtk_text_buffer_apply_tag_by_name(
3729 buffer, "link", &uri_start_iter, &uri_end_iter);
3735 undo_wrapping(compose->undostruct, FALSE);
3736 compose->autowrap = prev_autowrap;
3739 void compose_action_cb(void *data)
3741 Compose *compose = (Compose *)data;
3742 compose_wrap_all(compose);
3745 static void compose_wrap_all(Compose *compose)
3747 compose_wrap_all_full(compose, FALSE);
3750 static void compose_wrap_all_full(Compose *compose, gboolean force)
3752 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3753 GtkTextBuffer *buffer;
3756 buffer = gtk_text_view_get_buffer(text);
3758 gtk_text_buffer_get_start_iter(buffer, &iter);
3759 while (!gtk_text_iter_is_end(&iter))
3760 compose_beautify_paragraph(compose, &iter, force);
3764 static void compose_set_title(Compose *compose)
3770 edited = compose->modified ? _(" [Edited]") : "";
3772 subject = gtk_editable_get_chars(
3773 GTK_EDITABLE(compose->subject_entry), 0, -1);
3775 if (subject && strlen(subject))
3776 str = g_strdup_printf(_("%s - Compose message%s"),
3779 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3780 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3786 * compose_current_mail_account:
3788 * Find a current mail account (the currently selected account, or the
3789 * default account, if a news account is currently selected). If a
3790 * mail account cannot be found, display an error message.
3792 * Return value: Mail account, or NULL if not found.
3794 static PrefsAccount *
3795 compose_current_mail_account(void)
3799 if (cur_account && cur_account->protocol != A_NNTP)
3802 ac = account_get_default();
3803 if (!ac || ac->protocol == A_NNTP) {
3804 alertpanel_error(_("Account for sending mail is not specified.\n"
3805 "Please select a mail account before sending."));
3812 #define QUOTE_IF_REQUIRED(out, str) \
3814 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3818 len = strlen(str) + 3; \
3819 if ((__tmp = alloca(len)) == NULL) { \
3820 g_warning("can't allocate memory\n"); \
3821 g_string_free(header, TRUE); \
3824 g_snprintf(__tmp, len, "\"%s\"", str); \
3829 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3830 g_warning("can't allocate memory\n"); \
3831 g_string_free(header, TRUE); \
3834 strcpy(__tmp, str); \
3840 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
3842 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3846 len = strlen(str) + 3; \
3847 if ((__tmp = alloca(len)) == NULL) { \
3848 g_warning("can't allocate memory\n"); \
3851 g_snprintf(__tmp, len, "\"%s\"", str); \
3856 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3857 g_warning("can't allocate memory\n"); \
3860 strcpy(__tmp, str); \
3866 static void compose_select_account(Compose *compose, PrefsAccount *account,
3869 GtkItemFactory *ifactory;
3872 g_return_if_fail(account != NULL);
3874 compose->account = account;
3876 if (account->name && *account->name) {
3878 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
3879 from = g_strdup_printf("%s <%s>",
3880 buf, account->address);
3881 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3883 from = g_strdup_printf("<%s>",
3885 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3890 compose_set_title(compose);
3892 ifactory = gtk_item_factory_from_widget(compose->menubar);
3894 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3895 menu_set_active(ifactory, "/Options/Sign", TRUE);
3897 menu_set_active(ifactory, "/Options/Sign", FALSE);
3898 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3899 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3901 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3903 activate_privacy_system(compose, account, FALSE);
3905 if (!init && compose->mode != COMPOSE_REDIRECT) {
3906 undo_block(compose->undostruct);
3907 compose_insert_sig(compose, TRUE);
3908 undo_unblock(compose->undostruct);
3912 gboolean compose_check_for_valid_recipient(Compose *compose) {
3913 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3914 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3915 gboolean recipient_found = FALSE;
3919 /* free to and newsgroup list */
3920 slist_free_strings(compose->to_list);
3921 g_slist_free(compose->to_list);
3922 compose->to_list = NULL;
3924 slist_free_strings(compose->newsgroup_list);
3925 g_slist_free(compose->newsgroup_list);
3926 compose->newsgroup_list = NULL;
3928 /* search header entries for to and newsgroup entries */
3929 for (list = compose->header_list; list; list = list->next) {
3932 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3933 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3935 if (entry[0] != '\0') {
3936 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3937 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3938 compose->to_list = address_list_append(compose->to_list, entry);
3939 recipient_found = TRUE;
3942 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3943 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3944 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3945 recipient_found = TRUE;
3952 return recipient_found;
3955 static gboolean compose_check_for_set_recipients(Compose *compose)
3957 if (compose->account->set_autocc && compose->account->auto_cc) {
3958 gboolean found_other = FALSE;
3960 /* search header entries for to and newsgroup entries */
3961 for (list = compose->header_list; list; list = list->next) {
3964 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3965 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3967 if (strcmp(entry, compose->account->auto_cc)
3968 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3978 if (compose->batch) {
3979 gtk_widget_show_all(compose->window);
3981 aval = alertpanel(_("Send"),
3982 _("The only recipient is the default CC address. Send anyway?"),
3983 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3984 if (aval != G_ALERTALTERNATE)
3988 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3989 gboolean found_other = FALSE;
3991 /* search header entries for to and newsgroup entries */
3992 for (list = compose->header_list; list; list = list->next) {
3995 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3996 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3998 if (strcmp(entry, compose->account->auto_cc)
3999 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
4009 if (compose->batch) {
4010 gtk_widget_show_all(compose->window);
4012 aval = alertpanel(_("Send"),
4013 _("The only recipient is the default BCC address. Send anyway?"),
4014 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4015 if (aval != G_ALERTALTERNATE)
4022 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
4026 if (compose_check_for_valid_recipient(compose) == FALSE) {
4027 if (compose->batch) {
4028 gtk_widget_show_all(compose->window);
4030 alertpanel_error(_("Recipient is not specified."));
4034 if (compose_check_for_set_recipients(compose) == FALSE) {
4038 if (!compose->batch) {
4039 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4040 if (*str == '\0' && check_subject == TRUE) {
4043 aval = alertpanel(_("Send"),
4044 _("Subject is empty. Send it anyway?"),
4045 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4046 if (aval != G_ALERTALTERNATE)
4054 gint compose_send(Compose *compose)
4057 FolderItem *folder = NULL;
4059 gchar *msgpath = NULL;
4060 gboolean discard_window = FALSE;
4061 gchar *errstr = NULL;
4062 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4063 || compose->batch == TRUE)
4064 discard_window = TRUE;
4066 compose_allow_user_actions (compose, FALSE);
4067 compose->sending = TRUE;
4069 if (compose_check_entries(compose, TRUE) == FALSE) {
4070 if (compose->batch) {
4071 gtk_widget_show_all(compose->window);
4076 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
4079 if (compose->batch) {
4080 gtk_widget_show_all(compose->window);
4083 alertpanel_error(_("Could not queue message for sending:\n\n"
4084 "Charset conversion failed."));
4085 } else if (val == -3) {
4086 if (privacy_peek_error())
4087 alertpanel_error(_("Could not queue message for sending:\n\n"
4088 "Signature failed: %s"), privacy_get_error());
4089 } else if (val == -2 && errno != 0) {
4090 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4092 alertpanel_error(_("Could not queue message for sending."));
4097 if (discard_window) {
4098 compose->sending = FALSE;
4099 compose_close(compose);
4100 /* No more compose access in the normal codepath
4101 * after this point! */
4106 alertpanel_error(_("The message was queued but could not be "
4107 "sent.\nUse \"Send queued messages\" from "
4108 "the main window to retry."));
4109 if (!discard_window) {
4115 if (msgpath == NULL) {
4116 msgpath = folder_item_fetch_msg(folder, msgnum);
4117 val = procmsg_send_message_queue(msgpath, &errstr);
4120 val = procmsg_send_message_queue(msgpath, &errstr);
4124 if (!discard_window) {
4125 compose->sending = FALSE;
4126 compose_allow_user_actions (compose, TRUE);
4128 folder_item_remove_msg(folder, msgnum);
4129 folder_item_scan(folder);
4134 folder_item_remove_msg(folder, msgnum);
4135 folder_item_scan(folder);
4136 if (!discard_window)
4137 compose_close(compose);
4140 gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
4141 "the main window to retry."), errstr);
4143 alertpanel_error_log(tmp);
4146 alertpanel_error_log(_("The message was queued but could not be "
4147 "sent.\nUse \"Send queued messages\" from "
4148 "the main window to retry."));
4150 if (!discard_window) {
4156 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4160 compose_allow_user_actions (compose, TRUE);
4161 compose->sending = FALSE;
4162 compose->modified = TRUE;
4163 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4168 static gboolean compose_use_attach(Compose *compose)
4170 GtkTreeModel *model = gtk_tree_view_get_model
4171 (GTK_TREE_VIEW(compose->attach_clist));
4172 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4175 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4178 gchar buf[BUFFSIZE];
4180 gboolean first_to_address;
4181 gboolean first_cc_address;
4183 ComposeHeaderEntry *headerentry;
4184 const gchar *headerentryname;
4188 debug_print("Writing redirect header\n");
4190 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4191 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4193 first_to_address = TRUE;
4194 for (list = compose->header_list; list; list = list->next) {
4195 headerentry = ((ComposeHeaderEntry *)list->data);
4196 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4198 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4199 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4200 Xstrdup_a(str, entstr, return -1);
4202 if (str[0] != '\0') {
4203 compose_convert_header
4204 (compose, buf, sizeof(buf), str,
4205 strlen("Resent-To") + 2, TRUE);
4207 if (first_to_address) {
4208 fprintf(fp, "Resent-To: ");
4209 first_to_address = FALSE;
4213 fprintf(fp, "%s", buf);
4217 if (!first_to_address) {
4221 first_cc_address = TRUE;
4222 for (list = compose->header_list; list; list = list->next) {
4223 headerentry = ((ComposeHeaderEntry *)list->data);
4224 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4226 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4227 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4228 Xstrdup_a(str, strg, return -1);
4230 if (str[0] != '\0') {
4231 compose_convert_header
4232 (compose, buf, sizeof(buf), str,
4233 strlen("Resent-Cc") + 2, TRUE);
4235 if (first_cc_address) {
4236 fprintf(fp, "Resent-Cc: ");
4237 first_cc_address = FALSE;
4241 fprintf(fp, "%s", buf);
4245 if (!first_cc_address) {
4252 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4254 gchar buf[BUFFSIZE];
4256 const gchar *entstr;
4257 /* struct utsname utsbuf; */
4259 g_return_val_if_fail(fp != NULL, -1);
4260 g_return_val_if_fail(compose->account != NULL, -1);
4261 g_return_val_if_fail(compose->account->address != NULL, -1);
4264 get_rfc822_date(buf, sizeof(buf));
4265 fprintf(fp, "Resent-Date: %s\n", buf);
4268 if (compose->account->name && *compose->account->name) {
4269 compose_convert_header
4270 (compose, buf, sizeof(buf), compose->account->name,
4271 strlen("From: "), TRUE);
4272 fprintf(fp, "Resent-From: %s <%s>\n",
4273 buf, compose->account->address);
4275 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4278 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4279 if (*entstr != '\0') {
4280 Xstrdup_a(str, entstr, return -1);
4283 compose_convert_header(compose, buf, sizeof(buf), str,
4284 strlen("Subject: "), FALSE);
4285 fprintf(fp, "Subject: %s\n", buf);
4289 /* Resent-Message-ID */
4290 if (compose->account->gen_msgid) {
4291 generate_msgid(buf, sizeof(buf));
4292 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4293 compose->msgid = g_strdup(buf);
4296 compose_redirect_write_headers_from_headerlist(compose, fp);
4298 /* separator between header and body */
4304 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4308 gchar buf[BUFFSIZE];
4310 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4311 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4315 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4316 /* should filter returnpath, delivered-to */
4317 if (g_ascii_strncasecmp(buf, "Return-Path:",
4318 strlen("Return-Path:")) == 0 ||
4319 g_ascii_strncasecmp(buf, "Delivered-To:",
4320 strlen("Delivered-To:")) == 0 ||
4321 g_ascii_strncasecmp(buf, "Received:",
4322 strlen("Received:")) == 0 ||
4323 g_ascii_strncasecmp(buf, "Subject:",
4324 strlen("Subject:")) == 0 ||
4325 g_ascii_strncasecmp(buf, "X-UIDL:",
4326 strlen("X-UIDL:")) == 0)
4329 if (fputs(buf, fdest) == -1)
4332 if (!prefs_common.redirect_keep_from) {
4333 if (g_ascii_strncasecmp(buf, "From:",
4334 strlen("From:")) == 0) {
4335 fputs(" (by way of ", fdest);
4336 if (compose->account->name
4337 && *compose->account->name) {
4338 compose_convert_header
4339 (compose, buf, sizeof(buf),
4340 compose->account->name,
4343 fprintf(fdest, "%s <%s>",
4345 compose->account->address);
4347 fprintf(fdest, "%s",
4348 compose->account->address);
4353 if (fputs("\n", fdest) == -1)
4357 compose_redirect_write_headers(compose, fdest);
4359 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4360 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4373 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
4375 GtkTextBuffer *buffer;
4376 GtkTextIter start, end;
4379 const gchar *out_codeset;
4380 EncodingType encoding;
4381 MimeInfo *mimemsg, *mimetext;
4384 if (action == COMPOSE_WRITE_FOR_SEND)
4385 attach_parts = TRUE;
4387 /* create message MimeInfo */
4388 mimemsg = procmime_mimeinfo_new();
4389 mimemsg->type = MIMETYPE_MESSAGE;
4390 mimemsg->subtype = g_strdup("rfc822");
4391 mimemsg->content = MIMECONTENT_MEM;
4392 mimemsg->tmp = TRUE; /* must free content later */
4393 mimemsg->data.mem = compose_get_header(compose);
4395 /* Create text part MimeInfo */
4396 /* get all composed text */
4397 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4398 gtk_text_buffer_get_start_iter(buffer, &start);
4399 gtk_text_buffer_get_end_iter(buffer, &end);
4400 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4401 if (is_ascii_str(chars)) {
4404 out_codeset = CS_US_ASCII;
4405 encoding = ENC_7BIT;
4407 const gchar *src_codeset = CS_INTERNAL;
4409 out_codeset = conv_get_charset_str(compose->out_encoding);
4412 gchar *test_conv_global_out = NULL;
4413 gchar *test_conv_reply = NULL;
4415 /* automatic mode. be automatic. */
4416 codeconv_set_strict(TRUE);
4418 out_codeset = conv_get_outgoing_charset_str();
4420 debug_print("trying to convert to %s\n", out_codeset);
4421 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4424 if (!test_conv_global_out && compose->orig_charset
4425 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4426 out_codeset = compose->orig_charset;
4427 debug_print("failure; trying to convert to %s\n", out_codeset);
4428 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4431 if (!test_conv_global_out && !test_conv_reply) {
4433 out_codeset = CS_INTERNAL;
4434 debug_print("failure; finally using %s\n", out_codeset);
4436 g_free(test_conv_global_out);
4437 g_free(test_conv_reply);
4438 codeconv_set_strict(FALSE);
4441 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4442 out_codeset = CS_ISO_8859_1;
4444 if (prefs_common.encoding_method == CTE_BASE64)
4445 encoding = ENC_BASE64;
4446 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4447 encoding = ENC_QUOTED_PRINTABLE;
4448 else if (prefs_common.encoding_method == CTE_8BIT)
4449 encoding = ENC_8BIT;
4451 encoding = procmime_get_encoding_for_charset(out_codeset);
4453 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4454 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4456 if (action == COMPOSE_WRITE_FOR_SEND) {
4457 codeconv_set_strict(TRUE);
4458 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4459 codeconv_set_strict(FALSE);
4465 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4466 "to the specified %s charset.\n"
4467 "Send it as %s?"), out_codeset, src_codeset);
4468 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4469 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4472 if (aval != G_ALERTALTERNATE) {
4477 out_codeset = src_codeset;
4483 out_codeset = src_codeset;
4489 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4490 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4491 strstr(buf, "\nFrom ") != NULL) {
4492 encoding = ENC_QUOTED_PRINTABLE;
4496 mimetext = procmime_mimeinfo_new();
4497 mimetext->content = MIMECONTENT_MEM;
4498 mimetext->tmp = TRUE; /* must free content later */
4499 mimetext->data.mem = buf;
4500 mimetext->type = MIMETYPE_TEXT;
4501 mimetext->subtype = g_strdup("plain");
4502 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4503 g_strdup(out_codeset));
4505 /* protect trailing spaces when signing message */
4506 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4507 privacy_system_can_sign(compose->privacy_system)) {
4508 encoding = ENC_QUOTED_PRINTABLE;
4511 debug_print("main text: %d bytes encoded as %s in %d\n",
4512 strlen(buf), out_codeset, encoding);
4514 /* check for line length limit */
4515 if (action == COMPOSE_WRITE_FOR_SEND &&
4516 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4517 check_line_length(buf, 1000, &line) < 0) {
4521 msg = g_strdup_printf
4522 (_("Line %d exceeds the line length limit (998 bytes).\n"
4523 "The contents of the message might be broken on the way to the delivery.\n"
4525 "Send it anyway?"), line + 1);
4526 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4528 if (aval != G_ALERTALTERNATE) {
4533 if (encoding != ENC_UNKNOWN)
4534 procmime_encode_content(mimetext, encoding);
4536 /* append attachment parts */
4537 if (compose_use_attach(compose) && attach_parts) {
4538 MimeInfo *mimempart;
4539 gchar *boundary = NULL;
4540 mimempart = procmime_mimeinfo_new();
4541 mimempart->content = MIMECONTENT_EMPTY;
4542 mimempart->type = MIMETYPE_MULTIPART;
4543 mimempart->subtype = g_strdup("mixed");
4547 boundary = generate_mime_boundary(NULL);
4548 } while (strstr(buf, boundary) != NULL);
4550 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4553 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4555 g_node_append(mimempart->node, mimetext->node);
4556 g_node_append(mimemsg->node, mimempart->node);
4558 compose_add_attachments(compose, mimempart);
4560 g_node_append(mimemsg->node, mimetext->node);
4562 /* sign message if sending */
4563 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4564 privacy_system_can_sign(compose->privacy_system))
4565 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4568 procmime_write_mimeinfo(mimemsg, fp);
4570 procmime_mimeinfo_free_all(mimemsg);
4575 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4577 GtkTextBuffer *buffer;
4578 GtkTextIter start, end;
4583 if ((fp = g_fopen(file, "wb")) == NULL) {
4584 FILE_OP_ERROR(file, "fopen");
4588 /* chmod for security */
4589 if (change_file_mode_rw(fp, file) < 0) {
4590 FILE_OP_ERROR(file, "chmod");
4591 g_warning("can't change file mode\n");
4594 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4595 gtk_text_buffer_get_start_iter(buffer, &start);
4596 gtk_text_buffer_get_end_iter(buffer, &end);
4597 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4599 chars = conv_codeset_strdup
4600 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4603 if (!chars) return -1;
4606 len = strlen(chars);
4607 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4608 FILE_OP_ERROR(file, "fwrite");
4617 if (fclose(fp) == EOF) {
4618 FILE_OP_ERROR(file, "fclose");
4625 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4628 MsgInfo *msginfo = compose->targetinfo;
4630 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4631 if (!msginfo) return -1;
4633 if (!force && MSG_IS_LOCKED(msginfo->flags))
4636 item = msginfo->folder;
4637 g_return_val_if_fail(item != NULL, -1);
4639 if (procmsg_msg_exist(msginfo) &&
4640 (folder_has_parent_of_type(item, F_QUEUE) ||
4641 folder_has_parent_of_type(item, F_DRAFT)
4642 || msginfo == compose->autosaved_draft)) {
4643 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4644 g_warning("can't remove the old message\n");
4652 void compose_remove_draft(Compose *compose)
4655 MsgInfo *msginfo = compose->targetinfo;
4656 drafts = account_get_special_folder(compose->account, F_DRAFT);
4658 if (procmsg_msg_exist(msginfo)) {
4659 folder_item_remove_msg(drafts, msginfo->msgnum);
4664 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
4665 gboolean remove_reedit_target)
4667 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
4669 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
4670 gchar **msgpath, gboolean check_subject,
4671 gboolean remove_reedit_target)
4678 static gboolean lock = FALSE;
4679 PrefsAccount *mailac = NULL, *newsac = NULL;
4681 debug_print("queueing message...\n");
4682 g_return_val_if_fail(compose->account != NULL, -1);
4686 if (compose_check_entries(compose, check_subject) == FALSE) {
4688 if (compose->batch) {
4689 gtk_widget_show_all(compose->window);
4694 if (!compose->to_list && !compose->newsgroup_list) {
4695 g_warning("can't get recipient list.");
4700 if (compose->to_list) {
4701 if (compose->account->protocol != A_NNTP)
4702 mailac = compose->account;
4703 else if (cur_account && cur_account->protocol != A_NNTP)
4704 mailac = cur_account;
4705 else if (!(mailac = compose_current_mail_account())) {
4707 alertpanel_error(_("No account for sending mails available!"));
4712 if (compose->newsgroup_list) {
4713 if (compose->account->protocol == A_NNTP)
4714 newsac = compose->account;
4715 else if (!newsac->protocol != A_NNTP) {
4717 alertpanel_error(_("No account for posting news available!"));
4722 /* write queue header */
4723 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4724 G_DIR_SEPARATOR, compose);
4725 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4726 FILE_OP_ERROR(tmp, "fopen");
4732 if (change_file_mode_rw(fp, tmp) < 0) {
4733 FILE_OP_ERROR(tmp, "chmod");
4734 g_warning("can't change file mode\n");
4737 /* queueing variables */
4738 fprintf(fp, "AF:\n");
4739 fprintf(fp, "NF:0\n");
4740 fprintf(fp, "PS:10\n");
4741 fprintf(fp, "SRH:1\n");
4742 fprintf(fp, "SFN:\n");
4743 fprintf(fp, "DSR:\n");
4745 fprintf(fp, "MID:<%s>\n", compose->msgid);
4747 fprintf(fp, "MID:\n");
4748 fprintf(fp, "CFG:\n");
4749 fprintf(fp, "PT:0\n");
4750 fprintf(fp, "S:%s\n", compose->account->address);
4751 fprintf(fp, "RQ:\n");
4753 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4755 fprintf(fp, "SSV:\n");
4757 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4759 fprintf(fp, "NSV:\n");
4760 fprintf(fp, "SSH:\n");
4761 /* write recepient list */
4762 if (compose->to_list) {
4763 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4764 for (cur = compose->to_list->next; cur != NULL;
4766 fprintf(fp, ",<%s>", (gchar *)cur->data);
4769 /* write newsgroup list */
4770 if (compose->newsgroup_list) {
4772 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4773 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4774 fprintf(fp, ",%s", (gchar *)cur->data);
4777 /* Sylpheed account IDs */
4779 fprintf(fp, "MAID:%d\n", mailac->account_id);
4781 fprintf(fp, "NAID:%d\n", newsac->account_id);
4784 if (compose->privacy_system != NULL) {
4785 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4786 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4787 if (compose->use_encryption) {
4789 if (mailac && mailac->encrypt_to_self) {
4790 GSList *tmp_list = g_slist_copy(compose->to_list);
4791 tmp_list = g_slist_append(tmp_list, compose->account->address);
4792 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
4793 g_slist_free(tmp_list);
4795 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4797 if (encdata != NULL) {
4798 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4799 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4800 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4802 } /* else we finally dont want to encrypt */
4804 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4805 /* and if encdata was null, it means there's been a problem in
4812 /* Save copy folder */
4813 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4814 gchar *savefolderid;
4816 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4817 fprintf(fp, "SCF:%s\n", savefolderid);
4818 g_free(savefolderid);
4820 /* Save copy folder */
4821 if (compose->return_receipt) {
4822 fprintf(fp, "RRCPT:1\n");
4824 /* Message-ID of message replying to */
4825 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4828 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4829 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4832 /* Message-ID of message forwarding to */
4833 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4836 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4837 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4841 /* end of headers */
4842 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
4844 if (compose->redirect_filename != NULL) {
4845 if (compose_redirect_write_to_file(compose, fp) < 0) {
4854 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
4859 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4863 if (fclose(fp) == EOF) {
4864 FILE_OP_ERROR(tmp, "fclose");
4871 if (item && *item) {
4874 queue = account_get_special_folder(compose->account, F_QUEUE);
4877 g_warning("can't find queue folder\n");
4883 folder_item_scan(queue);
4884 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4885 g_warning("can't queue the message\n");
4892 if (msgpath == NULL) {
4898 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
4899 compose_remove_reedit_target(compose, FALSE);
4902 if ((msgnum != NULL) && (item != NULL)) {
4910 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4913 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4915 struct stat statbuf;
4916 gchar *type, *subtype;
4917 GtkTreeModel *model;
4920 model = gtk_tree_view_get_model(tree_view);
4922 if (!gtk_tree_model_get_iter_first(model, &iter))
4925 gtk_tree_model_get(model, &iter,
4929 mimepart = procmime_mimeinfo_new();
4930 mimepart->content = MIMECONTENT_FILE;
4931 mimepart->data.filename = g_strdup(ainfo->file);
4932 mimepart->tmp = FALSE; /* or we destroy our attachment */
4933 mimepart->offset = 0;
4935 stat(ainfo->file, &statbuf);
4936 mimepart->length = statbuf.st_size;
4938 type = g_strdup(ainfo->content_type);
4940 if (!strchr(type, '/')) {
4942 type = g_strdup("application/octet-stream");
4945 subtype = strchr(type, '/') + 1;
4946 *(subtype - 1) = '\0';
4947 mimepart->type = procmime_get_media_type(type);
4948 mimepart->subtype = g_strdup(subtype);
4951 if (mimepart->type == MIMETYPE_MESSAGE &&
4952 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4953 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4955 g_hash_table_insert(mimepart->typeparameters,
4956 g_strdup("name"), g_strdup(ainfo->name));
4957 g_hash_table_insert(mimepart->dispositionparameters,
4958 g_strdup("filename"), g_strdup(ainfo->name));
4959 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4962 if (compose->use_signing) {
4963 if (ainfo->encoding == ENC_7BIT)
4964 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4965 else if (ainfo->encoding == ENC_8BIT)
4966 ainfo->encoding = ENC_BASE64;
4969 procmime_encode_content(mimepart, ainfo->encoding);
4971 g_node_append(parent->node, mimepart->node);
4972 } while (gtk_tree_model_iter_next(model, &iter));
4975 #define IS_IN_CUSTOM_HEADER(header) \
4976 (compose->account->add_customhdr && \
4977 custom_header_find(compose->account->customhdr_list, header) != NULL)
4979 static void compose_add_headerfield_from_headerlist(Compose *compose,
4981 const gchar *fieldname,
4982 const gchar *seperator)
4984 gchar *str, *fieldname_w_colon, *trans_fieldname;
4985 gboolean add_field = FALSE;
4987 ComposeHeaderEntry *headerentry;
4988 const gchar * headerentryname;
4991 if (IS_IN_CUSTOM_HEADER(fieldname))
4994 debug_print("Adding %s-fields\n", fieldname);
4996 fieldstr = g_string_sized_new(64);
4998 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4999 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
5001 for (list = compose->header_list; list; list = list->next) {
5002 headerentry = ((ComposeHeaderEntry *)list->data);
5003 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
5005 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
5006 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
5008 if (str[0] != '\0') {
5010 g_string_append(fieldstr, seperator);
5011 g_string_append(fieldstr, str);
5020 buf = g_new0(gchar, fieldstr->len * 4 + 256);
5021 compose_convert_header
5022 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
5023 strlen(fieldname) + 2, TRUE);
5024 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
5028 g_free(fieldname_w_colon);
5029 g_string_free(fieldstr, TRUE);
5034 static gchar *compose_get_header(Compose *compose)
5036 gchar buf[BUFFSIZE];
5037 const gchar *entry_str;
5041 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5043 gchar *from_name = NULL, *from_address = NULL;
5046 g_return_val_if_fail(compose->account != NULL, NULL);
5047 g_return_val_if_fail(compose->account->address != NULL, NULL);
5049 header = g_string_sized_new(64);
5052 get_rfc822_date(buf, sizeof(buf));
5053 g_string_append_printf(header, "Date: %s\n", buf);
5057 if (compose->account->name && *compose->account->name) {
5059 QUOTE_IF_REQUIRED(buf, compose->account->name);
5060 tmp = g_strdup_printf("%s <%s>",
5061 buf, compose->account->address);
5063 tmp = g_strdup_printf("%s",
5064 compose->account->address);
5066 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5067 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5069 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5070 from_address = g_strdup(compose->account->address);
5072 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5073 /* extract name and address */
5074 if (strstr(spec, " <") && strstr(spec, ">")) {
5075 from_address = g_strdup(strrchr(spec, '<')+1);
5076 *(strrchr(from_address, '>')) = '\0';
5077 from_name = g_strdup(spec);
5078 *(strrchr(from_name, '<')) = '\0';
5081 from_address = g_strdup(spec);
5088 if (from_name && *from_name) {
5089 compose_convert_header
5090 (compose, buf, sizeof(buf), from_name,
5091 strlen("From: "), TRUE);
5092 QUOTE_IF_REQUIRED(name, buf);
5094 g_string_append_printf(header, "From: %s <%s>\n",
5095 name, from_address);
5097 g_string_append_printf(header, "From: %s\n", from_address);
5100 g_free(from_address);
5103 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5106 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5109 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5112 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5115 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5117 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5120 compose_convert_header(compose, buf, sizeof(buf), str,
5121 strlen("Subject: "), FALSE);
5122 g_string_append_printf(header, "Subject: %s\n", buf);
5128 if (compose->account->gen_msgid) {
5129 generate_msgid(buf, sizeof(buf));
5130 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5131 compose->msgid = g_strdup(buf);
5134 if (compose->remove_references == FALSE) {
5136 if (compose->inreplyto && compose->to_list)
5137 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5140 if (compose->references)
5141 g_string_append_printf(header, "References: %s\n", compose->references);
5145 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5148 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5151 if (compose->account->organization &&
5152 strlen(compose->account->organization) &&
5153 !IS_IN_CUSTOM_HEADER("Organization")) {
5154 compose_convert_header(compose, buf, sizeof(buf),
5155 compose->account->organization,
5156 strlen("Organization: "), FALSE);
5157 g_string_append_printf(header, "Organization: %s\n", buf);
5160 /* Program version and system info */
5161 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5162 !compose->newsgroup_list) {
5163 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5165 gtk_major_version, gtk_minor_version, gtk_micro_version,
5168 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5169 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5171 gtk_major_version, gtk_minor_version, gtk_micro_version,
5175 /* custom headers */
5176 if (compose->account->add_customhdr) {
5179 for (cur = compose->account->customhdr_list; cur != NULL;
5181 CustomHeader *chdr = (CustomHeader *)cur->data;
5183 if (custom_header_is_allowed(chdr->name)) {
5184 compose_convert_header
5185 (compose, buf, sizeof(buf),
5186 chdr->value ? chdr->value : "",
5187 strlen(chdr->name) + 2, FALSE);
5188 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5194 switch (compose->priority) {
5195 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5196 "X-Priority: 1 (Highest)\n");
5198 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5199 "X-Priority: 2 (High)\n");
5201 case PRIORITY_NORMAL: break;
5202 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5203 "X-Priority: 4 (Low)\n");
5205 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5206 "X-Priority: 5 (Lowest)\n");
5208 default: debug_print("compose: priority unknown : %d\n",
5212 /* Request Return Receipt */
5213 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5214 if (compose->return_receipt) {
5215 if (compose->account->name
5216 && *compose->account->name) {
5217 compose_convert_header(compose, buf, sizeof(buf),
5218 compose->account->name,
5219 strlen("Disposition-Notification-To: "),
5221 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5223 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5227 /* get special headers */
5228 for (list = compose->header_list; list; list = list->next) {
5229 ComposeHeaderEntry *headerentry;
5232 gchar *headername_wcolon;
5233 gchar *headername_trans;
5236 gboolean standard_header = FALSE;
5238 headerentry = ((ComposeHeaderEntry *)list->data);
5240 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5241 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5246 if (!strstr(tmp, ":")) {
5247 headername_wcolon = g_strconcat(tmp, ":", NULL);
5248 headername = g_strdup(tmp);
5250 headername_wcolon = g_strdup(tmp);
5251 headername = g_strdup(strtok(tmp, ":"));
5255 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5256 Xstrdup_a(headervalue, entry_str, return NULL);
5257 subst_char(headervalue, '\r', ' ');
5258 subst_char(headervalue, '\n', ' ');
5259 string = std_headers;
5260 while (*string != NULL) {
5261 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5262 if (!strcmp(headername_trans,headername_wcolon))
5263 standard_header = TRUE;
5266 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5267 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5270 g_free(headername_wcolon);
5274 g_string_free(header, FALSE);
5279 #undef IS_IN_CUSTOM_HEADER
5281 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5282 gint header_len, gboolean addr_field)
5284 gchar *tmpstr = NULL;
5285 const gchar *out_codeset = NULL;
5287 g_return_if_fail(src != NULL);
5288 g_return_if_fail(dest != NULL);
5290 if (len < 1) return;
5292 tmpstr = g_strdup(src);
5294 subst_char(tmpstr, '\n', ' ');
5295 subst_char(tmpstr, '\r', ' ');
5298 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5299 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5300 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5305 codeconv_set_strict(TRUE);
5306 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5307 conv_get_charset_str(compose->out_encoding));
5308 codeconv_set_strict(FALSE);
5310 if (!dest || *dest == '\0') {
5311 gchar *test_conv_global_out = NULL;
5312 gchar *test_conv_reply = NULL;
5314 /* automatic mode. be automatic. */
5315 codeconv_set_strict(TRUE);
5317 out_codeset = conv_get_outgoing_charset_str();
5319 debug_print("trying to convert to %s\n", out_codeset);
5320 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5323 if (!test_conv_global_out && compose->orig_charset
5324 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5325 out_codeset = compose->orig_charset;
5326 debug_print("failure; trying to convert to %s\n", out_codeset);
5327 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5330 if (!test_conv_global_out && !test_conv_reply) {
5332 out_codeset = CS_INTERNAL;
5333 debug_print("finally using %s\n", out_codeset);
5335 g_free(test_conv_global_out);
5336 g_free(test_conv_reply);
5337 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5339 codeconv_set_strict(FALSE);
5344 static void compose_create_header_entry(Compose *compose)
5346 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5350 GList *combo_list = NULL;
5352 const gchar *header = NULL;
5353 ComposeHeaderEntry *headerentry;
5354 gboolean standard_header = FALSE;
5356 headerentry = g_new0(ComposeHeaderEntry, 1);
5359 combo = gtk_combo_new();
5361 while(*string != NULL) {
5362 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5365 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5366 g_list_free(combo_list);
5367 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5368 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5369 G_CALLBACK(compose_grab_focus_cb), compose);
5370 gtk_widget_show(combo);
5371 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5372 if (compose->header_last) {
5373 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5375 while (*string != NULL) {
5376 if (!strcmp(*string, last_header_entry))
5377 standard_header = TRUE;
5380 if (standard_header)
5381 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5383 if (!compose->header_last || !standard_header) {
5384 switch(compose->account->protocol) {
5386 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5389 header = prefs_common.trans_hdr ? _("To:") : "To:";
5394 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5396 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5397 G_CALLBACK(compose_grab_focus_cb), compose);
5400 entry = gtk_entry_new();
5401 gtk_widget_show(entry);
5402 gtk_tooltips_set_tip(compose->tooltips, entry,
5403 _("Use <tab> to autocomplete from addressbook"), NULL);
5404 gtk_table_attach(GTK_TABLE(compose->header_table), entry, 1, 2, compose->header_nextrow, compose->header_nextrow+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
5406 g_signal_connect(G_OBJECT(entry), "key-press-event",
5407 G_CALLBACK(compose_headerentry_key_press_event_cb),
5409 g_signal_connect(G_OBJECT(entry), "changed",
5410 G_CALLBACK(compose_headerentry_changed_cb),
5412 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5413 G_CALLBACK(compose_grab_focus_cb), compose);
5416 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5417 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5418 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5419 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5420 G_CALLBACK(compose_header_drag_received_cb),
5422 g_signal_connect(G_OBJECT(entry), "drag-drop",
5423 G_CALLBACK(compose_drag_drop),
5426 address_completion_register_entry(GTK_ENTRY(entry));
5428 headerentry->compose = compose;
5429 headerentry->combo = combo;
5430 headerentry->entry = entry;
5431 headerentry->headernum = compose->header_nextrow;
5433 compose->header_nextrow++;
5434 compose->header_last = headerentry;
5437 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5439 ComposeHeaderEntry *last_header;
5441 last_header = compose->header_last;
5443 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5444 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5447 static GtkWidget *compose_create_header(Compose *compose)
5449 GtkWidget *from_optmenu_hbox;
5450 GtkWidget *header_scrolledwin;
5451 GtkWidget *header_table;
5455 /* header labels and entries */
5456 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5457 gtk_widget_show(header_scrolledwin);
5458 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5460 header_table = gtk_table_new(2, 2, FALSE);
5461 gtk_widget_show(header_table);
5462 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5463 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5464 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5467 /* option menu for selecting accounts */
5468 from_optmenu_hbox = compose_account_option_menu_create(compose);
5469 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5470 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5473 compose->header_table = header_table;
5474 compose->header_list = NULL;
5475 compose->header_nextrow = count;
5477 compose_create_header_entry(compose);
5479 compose->table = NULL;
5481 return header_scrolledwin ;
5484 GtkWidget *compose_create_attach(Compose *compose)
5486 GtkWidget *attach_scrwin;
5487 GtkWidget *attach_clist;
5489 GtkListStore *store;
5490 GtkCellRenderer *renderer;
5491 GtkTreeViewColumn *column;
5492 GtkTreeSelection *selection;
5494 /* attachment list */
5495 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5496 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5497 GTK_POLICY_AUTOMATIC,
5498 GTK_POLICY_AUTOMATIC);
5499 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5501 store = gtk_list_store_new(N_ATTACH_COLS,
5506 G_TYPE_AUTO_POINTER,
5508 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5509 (GTK_TREE_MODEL(store)));
5510 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5511 g_object_unref(store);
5513 renderer = gtk_cell_renderer_text_new();
5514 column = gtk_tree_view_column_new_with_attributes
5515 (_("Mime type"), renderer, "text",
5516 COL_MIMETYPE, NULL);
5517 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5519 renderer = gtk_cell_renderer_text_new();
5520 column = gtk_tree_view_column_new_with_attributes
5521 (_("Size"), renderer, "text",
5523 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5525 renderer = gtk_cell_renderer_text_new();
5526 column = gtk_tree_view_column_new_with_attributes
5527 (_("Name"), renderer, "text",
5529 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5531 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5532 prefs_common.enable_rules_hint);
5533 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5534 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5536 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5537 G_CALLBACK(attach_selected), compose);
5538 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5539 G_CALLBACK(attach_button_pressed), compose);
5540 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5541 G_CALLBACK(attach_key_pressed), compose);
5544 gtk_drag_dest_set(attach_clist,
5545 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5546 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5547 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5548 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5549 G_CALLBACK(compose_attach_drag_received_cb),
5551 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5552 G_CALLBACK(compose_drag_drop),
5555 compose->attach_scrwin = attach_scrwin;
5556 compose->attach_clist = attach_clist;
5558 return attach_scrwin;
5561 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5562 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5564 static GtkWidget *compose_create_others(Compose *compose)
5567 GtkWidget *savemsg_checkbtn;
5568 GtkWidget *savemsg_entry;
5569 GtkWidget *savemsg_select;
5572 gchar *folderidentifier;
5574 /* Table for settings */
5575 table = gtk_table_new(3, 1, FALSE);
5576 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5577 gtk_widget_show(table);
5578 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5581 /* Save Message to folder */
5582 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5583 gtk_widget_show(savemsg_checkbtn);
5584 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5585 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5586 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5588 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5589 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5591 savemsg_entry = gtk_entry_new();
5592 gtk_widget_show(savemsg_entry);
5593 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5594 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5595 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5596 G_CALLBACK(compose_grab_focus_cb), compose);
5597 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5598 folderidentifier = folder_item_get_identifier(account_get_special_folder
5599 (compose->account, F_OUTBOX));
5600 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5601 g_free(folderidentifier);
5604 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5605 gtk_widget_show(savemsg_select);
5606 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5607 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5608 G_CALLBACK(compose_savemsg_select_cb),
5613 compose->savemsg_checkbtn = savemsg_checkbtn;
5614 compose->savemsg_entry = savemsg_entry;
5619 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5621 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5622 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5625 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5630 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5633 path = folder_item_get_identifier(dest);
5635 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5639 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5640 GdkAtom clip, GtkTextIter *insert_place);
5642 #define BLOCK_WRAP() { \
5643 prev_autowrap = compose->autowrap; \
5644 buffer = gtk_text_view_get_buffer( \
5645 GTK_TEXT_VIEW(compose->text)); \
5646 compose->autowrap = FALSE; \
5648 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5649 G_CALLBACK(compose_changed_cb), \
5651 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5652 G_CALLBACK(text_inserted), \
5655 #define UNBLOCK_WRAP() { \
5656 compose->autowrap = prev_autowrap; \
5657 if (compose->autowrap) \
5658 compose_wrap_all(compose); \
5660 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5661 G_CALLBACK(compose_changed_cb), \
5663 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5664 G_CALLBACK(text_inserted), \
5669 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5673 GtkTextBuffer *buffer;
5675 if (event->button == 3) {
5677 GtkTextIter sel_start, sel_end;
5678 gboolean stuff_selected;
5680 /* move the cursor to allow GtkAspell to check the word
5681 * under the mouse */
5682 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5683 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5685 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5688 stuff_selected = gtk_text_buffer_get_selection_bounds(
5689 GTK_TEXT_VIEW(text)->buffer,
5690 &sel_start, &sel_end);
5692 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5693 /* reselect stuff */
5695 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5696 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5697 &sel_start, &sel_end);
5699 return FALSE; /* pass the event so that the right-click goes through */
5702 if (event->button == 2) {
5707 /* get the middle-click position to paste at the correct place */
5708 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5709 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5711 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5714 entry_paste_clipboard(compose, text,
5715 prefs_common.linewrap_pastes,
5716 GDK_SELECTION_PRIMARY, &iter);
5724 static void compose_spell_menu_changed(void *data)
5726 Compose *compose = (Compose *)data;
5728 GtkWidget *menuitem;
5729 GtkWidget *parent_item;
5730 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5731 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5734 if (compose->gtkaspell == NULL)
5737 parent_item = gtk_item_factory_get_item(ifactory,
5738 "/Spelling/Options");
5740 /* setting the submenu removes /Spelling/Options from the factory
5741 * so we need to save it */
5743 if (parent_item == NULL) {
5744 parent_item = compose->aspell_options_menu;
5745 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5747 compose->aspell_options_menu = parent_item;
5749 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5751 spell_menu = g_slist_reverse(spell_menu);
5752 for (items = spell_menu;
5753 items; items = items->next) {
5754 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
5755 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5756 gtk_widget_show(GTK_WIDGET(menuitem));
5758 g_slist_free(spell_menu);
5760 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
5765 static gboolean compose_force_window_origin = TRUE;
5766 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5773 GtkWidget *handlebox;
5775 GtkWidget *notebook;
5780 GtkWidget *subject_hbox;
5781 GtkWidget *subject_frame;
5782 GtkWidget *subject_entry;
5786 GtkWidget *edit_vbox;
5787 GtkWidget *ruler_hbox;
5789 GtkWidget *scrolledwin;
5791 GtkTextBuffer *buffer;
5792 GtkClipboard *clipboard;
5794 UndoMain *undostruct;
5796 gchar *titles[N_ATTACH_COLS];
5797 guint n_menu_entries;
5798 GtkWidget *popupmenu;
5799 GtkItemFactory *popupfactory;
5800 GtkItemFactory *ifactory;
5801 GtkWidget *tmpl_menu;
5803 GtkWidget *menuitem;
5806 GtkAspell * gtkaspell = NULL;
5809 static GdkGeometry geometry;
5811 g_return_val_if_fail(account != NULL, NULL);
5813 debug_print("Creating compose window...\n");
5814 compose = g_new0(Compose, 1);
5816 titles[COL_MIMETYPE] = _("MIME type");
5817 titles[COL_SIZE] = _("Size");
5818 titles[COL_NAME] = _("Name");
5820 compose->batch = batch;
5821 compose->account = account;
5823 compose->mutex = g_mutex_new();
5824 compose->set_cursor_pos = -1;
5826 compose->tooltips = gtk_tooltips_new();
5828 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5829 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5830 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5832 if (!geometry.max_width) {
5833 geometry.max_width = gdk_screen_width();
5834 geometry.max_height = gdk_screen_height();
5837 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5838 &geometry, GDK_HINT_MAX_SIZE);
5839 if (!geometry.min_width) {
5840 geometry.min_width = 600;
5841 geometry.min_height = 480;
5843 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5844 &geometry, GDK_HINT_MIN_SIZE);
5846 if (compose_force_window_origin)
5847 gtk_widget_set_uposition(window, prefs_common.compose_x,
5848 prefs_common.compose_y);
5850 g_signal_connect(G_OBJECT(window), "delete_event",
5851 G_CALLBACK(compose_delete_cb), compose);
5852 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5853 gtk_widget_realize(window);
5855 gtkut_widget_set_composer_icon(window);
5857 vbox = gtk_vbox_new(FALSE, 0);
5858 gtk_container_add(GTK_CONTAINER(window), vbox);
5860 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5861 menubar = menubar_create(window, compose_entries,
5862 n_menu_entries, "<Compose>", compose);
5863 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5865 if (prefs_common.toolbar_detachable) {
5866 handlebox = gtk_handle_box_new();
5868 handlebox = gtk_hbox_new(FALSE, 0);
5870 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5872 gtk_widget_realize(handlebox);
5873 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5876 vbox2 = gtk_vbox_new(FALSE, 2);
5877 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5878 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5881 notebook = gtk_notebook_new();
5882 gtk_widget_set_size_request(notebook, -1, 130);
5883 gtk_widget_show(notebook);
5885 /* header labels and entries */
5886 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5887 compose_create_header(compose),
5888 gtk_label_new_with_mnemonic(_("Hea_der")));
5889 /* attachment list */
5890 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5891 compose_create_attach(compose),
5892 gtk_label_new_with_mnemonic(_("_Attachments")));
5894 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5895 compose_create_others(compose),
5896 gtk_label_new_with_mnemonic(_("Othe_rs")));
5899 subject_hbox = gtk_hbox_new(FALSE, 0);
5900 gtk_widget_show(subject_hbox);
5902 subject_frame = gtk_frame_new(NULL);
5903 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5904 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5905 gtk_widget_show(subject_frame);
5907 subject = gtk_hbox_new(FALSE, 0);
5908 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5909 gtk_widget_show(subject);
5911 label = gtk_label_new(_("Subject:"));
5912 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5913 gtk_widget_show(label);
5915 subject_entry = gtk_entry_new();
5916 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5917 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5918 G_CALLBACK(compose_grab_focus_cb), compose);
5919 gtk_widget_show(subject_entry);
5920 compose->subject_entry = subject_entry;
5921 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5923 edit_vbox = gtk_vbox_new(FALSE, 0);
5925 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5928 ruler_hbox = gtk_hbox_new(FALSE, 0);
5929 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5931 ruler = gtk_shruler_new();
5932 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5933 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5937 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5938 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5939 GTK_POLICY_AUTOMATIC,
5940 GTK_POLICY_AUTOMATIC);
5941 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5943 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5944 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5946 text = gtk_text_view_new();
5947 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5948 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5949 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5950 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5951 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5953 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5955 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5956 G_CALLBACK(compose_edit_size_alloc),
5958 g_signal_connect(G_OBJECT(buffer), "changed",
5959 G_CALLBACK(compose_changed_cb), compose);
5960 g_signal_connect(G_OBJECT(text), "grab_focus",
5961 G_CALLBACK(compose_grab_focus_cb), compose);
5962 g_signal_connect(G_OBJECT(buffer), "insert_text",
5963 G_CALLBACK(text_inserted), compose);
5964 g_signal_connect(G_OBJECT(text), "button_press_event",
5965 G_CALLBACK(text_clicked), compose);
5966 g_signal_connect(G_OBJECT(subject_entry), "changed",
5967 G_CALLBACK(compose_changed_cb), compose);
5970 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5971 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5972 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5973 g_signal_connect(G_OBJECT(text), "drag_data_received",
5974 G_CALLBACK(compose_insert_drag_received_cb),
5976 g_signal_connect(G_OBJECT(text), "drag-drop",
5977 G_CALLBACK(compose_drag_drop),
5979 gtk_widget_show_all(vbox);
5981 /* pane between attach clist and text */
5982 paned = gtk_vpaned_new();
5983 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5984 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5985 gtk_paned_add1(GTK_PANED(paned), notebook);
5986 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5987 gtk_widget_show_all(paned);
5990 if (prefs_common.textfont) {
5991 PangoFontDescription *font_desc;
5993 font_desc = pango_font_description_from_string
5994 (prefs_common.textfont);
5996 gtk_widget_modify_font(text, font_desc);
5997 pango_font_description_free(font_desc);
6001 n_entries = sizeof(compose_popup_entries) /
6002 sizeof(compose_popup_entries[0]);
6003 popupmenu = menu_create_items(compose_popup_entries, n_entries,
6004 "<Compose>", &popupfactory,
6007 ifactory = gtk_item_factory_from_widget(menubar);
6008 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6009 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6010 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
6012 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6014 undostruct = undo_init(text);
6015 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
6018 address_completion_start(window);
6020 compose->window = window;
6021 compose->vbox = vbox;
6022 compose->menubar = menubar;
6023 compose->handlebox = handlebox;
6025 compose->vbox2 = vbox2;
6027 compose->paned = paned;
6029 compose->edit_vbox = edit_vbox;
6030 compose->ruler_hbox = ruler_hbox;
6031 compose->ruler = ruler;
6032 compose->scrolledwin = scrolledwin;
6033 compose->text = text;
6035 compose->focused_editable = NULL;
6037 compose->popupmenu = popupmenu;
6038 compose->popupfactory = popupfactory;
6040 compose->tmpl_menu = tmpl_menu;
6042 compose->mode = mode;
6044 compose->targetinfo = NULL;
6045 compose->replyinfo = NULL;
6046 compose->fwdinfo = NULL;
6048 compose->replyto = NULL;
6050 compose->bcc = NULL;
6051 compose->followup_to = NULL;
6053 compose->ml_post = NULL;
6055 compose->inreplyto = NULL;
6056 compose->references = NULL;
6057 compose->msgid = NULL;
6058 compose->boundary = NULL;
6060 compose->autowrap = prefs_common.autowrap;
6062 compose->use_signing = FALSE;
6063 compose->use_encryption = FALSE;
6064 compose->privacy_system = NULL;
6066 compose->modified = FALSE;
6068 compose->return_receipt = FALSE;
6070 compose->to_list = NULL;
6071 compose->newsgroup_list = NULL;
6073 compose->undostruct = undostruct;
6075 compose->sig_str = NULL;
6077 compose->exteditor_file = NULL;
6078 compose->exteditor_pid = -1;
6079 compose->exteditor_tag = -1;
6080 compose->draft_timeout_tag = -1;
6083 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6084 if (mode != COMPOSE_REDIRECT) {
6085 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6086 strcmp(prefs_common.dictionary, "")) {
6087 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6088 prefs_common.dictionary,
6089 conv_get_locale_charset_str(),
6090 prefs_common.misspelled_col,
6091 prefs_common.check_while_typing,
6092 prefs_common.recheck_when_changing_dict,
6093 prefs_common.use_alternate,
6094 GTK_TEXT_VIEW(text),
6095 GTK_WINDOW(compose->window),
6096 compose_spell_menu_changed,
6099 alertpanel_error(_("Spell checker could not "
6101 gtkaspell_checkers_strerror());
6102 gtkaspell_checkers_reset_error();
6104 if (!gtkaspell_set_sug_mode(gtkaspell,
6105 prefs_common.aspell_sugmode)) {
6106 debug_print("Aspell: could not set "
6107 "suggestion mode %s\n",
6108 gtkaspell_checkers_strerror());
6109 gtkaspell_checkers_reset_error();
6112 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6116 compose->gtkaspell = gtkaspell;
6117 compose_spell_menu_changed(compose);
6120 compose_select_account(compose, account, TRUE);
6122 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6123 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6124 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6126 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6127 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6129 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6130 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6133 if (account->protocol != A_NNTP)
6134 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6136 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6138 addressbook_set_target_compose(compose);
6140 if (mode != COMPOSE_REDIRECT)
6141 compose_set_template_menu(compose);
6143 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6144 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6147 compose_list = g_list_append(compose_list, compose);
6149 if (!prefs_common.show_ruler)
6150 gtk_widget_hide(ruler_hbox);
6152 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6153 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6154 prefs_common.show_ruler);
6157 compose->priority = PRIORITY_NORMAL;
6158 compose_update_priority_menu_item(compose);
6160 compose_set_out_encoding(compose);
6163 compose_update_actions_menu(compose);
6165 /* Privacy Systems menu */
6166 compose_update_privacy_systems_menu(compose);
6168 activate_privacy_system(compose, account, TRUE);
6169 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6171 gtk_widget_realize(window);
6173 gtk_widget_show(window);
6179 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6184 GtkWidget *optmenubox;
6187 GtkWidget *from_name = NULL;
6189 gint num = 0, def_menu = 0;
6191 accounts = account_get_list();
6192 g_return_val_if_fail(accounts != NULL, NULL);
6194 optmenubox = gtk_event_box_new();
6195 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
6196 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
6198 hbox = gtk_hbox_new(FALSE, 6);
6199 from_name = gtk_entry_new();
6201 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6202 G_CALLBACK(compose_grab_focus_cb), compose);
6204 for (; accounts != NULL; accounts = accounts->next, num++) {
6205 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6206 gchar *name, *from = NULL;
6208 if (ac == compose->account) def_menu = num;
6210 name = g_markup_printf_escaped(_("From: <i>%s</i>"),
6213 if (ac == compose->account) {
6214 if (ac->name && *ac->name) {
6216 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6217 from = g_strdup_printf("%s <%s>",
6219 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6221 from = g_strdup_printf("%s",
6223 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6226 COMBOBOX_ADD(menu, name, ac->account_id);
6231 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
6233 g_signal_connect(G_OBJECT(optmenu), "changed",
6234 G_CALLBACK(account_activated),
6237 gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
6238 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6240 gtk_tooltips_set_tip(compose->tooltips, optmenubox,
6241 _("Account to use for this email"), NULL);
6242 gtk_tooltips_set_tip(compose->tooltips, from_name,
6243 _("Sender address to be used"), NULL);
6245 compose->from_name = from_name;
6250 static void compose_set_priority_cb(gpointer data,
6254 Compose *compose = (Compose *) data;
6255 compose->priority = action;
6258 static void compose_update_priority_menu_item(Compose * compose)
6260 GtkItemFactory *ifactory;
6261 GtkWidget *menuitem = NULL;
6263 ifactory = gtk_item_factory_from_widget(compose->menubar);
6265 switch (compose->priority) {
6266 case PRIORITY_HIGHEST:
6267 menuitem = gtk_item_factory_get_item
6268 (ifactory, "/Options/Priority/Highest");
6271 menuitem = gtk_item_factory_get_item
6272 (ifactory, "/Options/Priority/High");
6274 case PRIORITY_NORMAL:
6275 menuitem = gtk_item_factory_get_item
6276 (ifactory, "/Options/Priority/Normal");
6279 menuitem = gtk_item_factory_get_item
6280 (ifactory, "/Options/Priority/Low");
6282 case PRIORITY_LOWEST:
6283 menuitem = gtk_item_factory_get_item
6284 (ifactory, "/Options/Priority/Lowest");
6287 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6290 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6292 Compose *compose = (Compose *) data;
6294 GtkItemFactory *ifactory;
6295 gboolean can_sign = FALSE, can_encrypt = FALSE;
6297 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6299 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6302 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6303 g_free(compose->privacy_system);
6304 compose->privacy_system = NULL;
6305 if (systemid != NULL) {
6306 compose->privacy_system = g_strdup(systemid);
6308 can_sign = privacy_system_can_sign(systemid);
6309 can_encrypt = privacy_system_can_encrypt(systemid);
6312 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6314 ifactory = gtk_item_factory_from_widget(compose->menubar);
6315 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6316 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6319 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6321 static gchar *branch_path = "/Options/Privacy System";
6322 GtkItemFactory *ifactory;
6323 GtkWidget *menuitem = NULL;
6325 gboolean can_sign = FALSE, can_encrypt = FALSE;
6326 gboolean found = FALSE;
6328 ifactory = gtk_item_factory_from_widget(compose->menubar);
6330 if (compose->privacy_system != NULL) {
6333 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6334 g_return_if_fail(menuitem != NULL);
6336 amenu = GTK_MENU_SHELL(menuitem)->children;
6338 while (amenu != NULL) {
6339 GList *alist = amenu->next;
6341 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6342 if (systemid != NULL) {
6343 if (strcmp(systemid, compose->privacy_system) == 0) {
6344 menuitem = GTK_WIDGET(amenu->data);
6346 can_sign = privacy_system_can_sign(systemid);
6347 can_encrypt = privacy_system_can_encrypt(systemid);
6351 } else if (strlen(compose->privacy_system) == 0) {
6352 menuitem = GTK_WIDGET(amenu->data);
6355 can_encrypt = FALSE;
6362 if (menuitem != NULL)
6363 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6365 if (warn && !found && strlen(compose->privacy_system)) {
6366 gchar *tmp = g_strdup_printf(
6367 _("The privacy system '%s' cannot be loaded. You "
6368 "will not be able to sign or encrypt this message."),
6369 compose->privacy_system);
6370 alertpanel_warning(tmp);
6375 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6376 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6379 static void compose_set_out_encoding(Compose *compose)
6381 GtkItemFactoryEntry *entry;
6382 GtkItemFactory *ifactory;
6383 CharSet out_encoding;
6384 gchar *path, *p, *q;
6387 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6388 ifactory = gtk_item_factory_from_widget(compose->menubar);
6390 for (entry = compose_entries; entry->callback != compose_address_cb;
6392 if (entry->callback == compose_set_encoding_cb &&
6393 (CharSet)entry->callback_action == out_encoding) {
6394 p = q = path = g_strdup(entry->path);
6406 item = gtk_item_factory_get_item(ifactory, path);
6407 gtk_widget_activate(item);
6414 static void compose_set_template_menu(Compose *compose)
6416 GSList *tmpl_list, *cur;
6420 tmpl_list = template_get_config();
6422 menu = gtk_menu_new();
6424 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6425 Template *tmpl = (Template *)cur->data;
6427 item = gtk_menu_item_new_with_label(tmpl->name);
6428 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6429 g_signal_connect(G_OBJECT(item), "activate",
6430 G_CALLBACK(compose_template_activate_cb),
6432 g_object_set_data(G_OBJECT(item), "template", tmpl);
6433 gtk_widget_show(item);
6436 gtk_widget_show(menu);
6437 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6440 void compose_update_actions_menu(Compose *compose)
6442 GtkItemFactory *ifactory;
6444 ifactory = gtk_item_factory_from_widget(compose->menubar);
6445 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6448 void compose_update_privacy_systems_menu(Compose *compose)
6450 static gchar *branch_path = "/Options/Privacy System";
6451 GtkItemFactory *ifactory;
6452 GtkWidget *menuitem;
6453 GSList *systems, *cur;
6456 GtkWidget *system_none;
6459 ifactory = gtk_item_factory_from_widget(compose->menubar);
6461 /* remove old entries */
6462 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6463 g_return_if_fail(menuitem != NULL);
6465 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6466 while (amenu != NULL) {
6467 GList *alist = amenu->next;
6468 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6472 system_none = gtk_item_factory_get_widget(ifactory,
6473 "/Options/Privacy System/None");
6475 g_signal_connect(G_OBJECT(system_none), "activate",
6476 G_CALLBACK(compose_set_privacy_system_cb), compose);
6478 systems = privacy_get_system_ids();
6479 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6480 gchar *systemid = cur->data;
6482 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6483 widget = gtk_radio_menu_item_new_with_label(group,
6484 privacy_system_get_name(systemid));
6485 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6486 g_strdup(systemid), g_free);
6487 g_signal_connect(G_OBJECT(widget), "activate",
6488 G_CALLBACK(compose_set_privacy_system_cb), compose);
6490 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6491 gtk_widget_show(widget);
6494 g_slist_free(systems);
6497 void compose_reflect_prefs_all(void)
6502 for (cur = compose_list; cur != NULL; cur = cur->next) {
6503 compose = (Compose *)cur->data;
6504 compose_set_template_menu(compose);
6508 void compose_reflect_prefs_pixmap_theme(void)
6513 for (cur = compose_list; cur != NULL; cur = cur->next) {
6514 compose = (Compose *)cur->data;
6515 toolbar_update(TOOLBAR_COMPOSE, compose);
6519 static void compose_template_apply(Compose *compose, Template *tmpl,
6523 GtkTextBuffer *buffer;
6527 gchar *parsed_str = NULL;
6528 gint cursor_pos = 0;
6531 /* process the body */
6533 text = GTK_TEXT_VIEW(compose->text);
6534 buffer = gtk_text_view_get_buffer(text);
6537 gtk_text_buffer_set_text(buffer, "", -1);
6539 mark = gtk_text_buffer_get_insert(buffer);
6540 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6543 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6544 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6547 if (prefs_common.quotemark && *prefs_common.quotemark)
6548 qmark = prefs_common.quotemark;
6552 if (compose->replyinfo != NULL)
6553 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6554 tmpl->value, qmark, NULL, FALSE);
6555 else if (compose->fwdinfo != NULL)
6556 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6557 tmpl->value, qmark, NULL, FALSE);
6562 if (replace && parsed_str && compose->account->auto_sig)
6563 compose_insert_sig(compose, FALSE);
6565 if (replace && parsed_str) {
6566 gtk_text_buffer_get_start_iter(buffer, &iter);
6567 gtk_text_buffer_place_cursor(buffer, &iter);
6571 cursor_pos = quote_fmt_get_cursor_pos();
6572 compose->set_cursor_pos = cursor_pos;
6573 if (cursor_pos == -1)
6575 gtk_text_buffer_get_start_iter(buffer, &iter);
6576 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6577 gtk_text_buffer_place_cursor(buffer, &iter);
6580 /* process the other fields */
6581 compose_template_apply_fields(compose, tmpl);
6582 quote_fmt_reset_vartable();
6583 compose_changed_cb(NULL, compose);
6586 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6588 static MsgInfo dummyinfo;
6589 MsgInfo *msginfo = NULL;
6592 if (compose->replyinfo != NULL)
6593 msginfo = compose->replyinfo;
6594 else if (compose->fwdinfo != NULL)
6595 msginfo = compose->fwdinfo;
6597 msginfo = &dummyinfo;
6599 if (tmpl->to && *tmpl->to != '\0') {
6600 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6601 quote_fmt_scan_string(tmpl->to);
6604 buf = quote_fmt_get_buffer();
6606 alertpanel_error(_("Message To format error."));
6608 compose_entry_append(compose, buf, COMPOSE_TO);
6612 if (tmpl->cc && *tmpl->cc != '\0') {
6613 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6614 quote_fmt_scan_string(tmpl->cc);
6617 buf = quote_fmt_get_buffer();
6619 alertpanel_error(_("Message Cc format error."));
6621 compose_entry_append(compose, buf, COMPOSE_CC);
6625 if (tmpl->bcc && *tmpl->bcc != '\0') {
6626 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6627 quote_fmt_scan_string(tmpl->bcc);
6630 buf = quote_fmt_get_buffer();
6632 alertpanel_error(_("Message Bcc format error."));
6634 compose_entry_append(compose, buf, COMPOSE_BCC);
6638 /* process the subject */
6639 if (tmpl->subject && *tmpl->subject != '\0') {
6640 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6641 quote_fmt_scan_string(tmpl->subject);
6644 buf = quote_fmt_get_buffer();
6646 alertpanel_error(_("Message subject format error."));
6648 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6653 static void compose_destroy(Compose *compose)
6655 compose_list = g_list_remove(compose_list, compose);
6657 if (compose->updating) {
6658 debug_print("danger, not destroying anything now\n");
6659 compose->deferred_destroy = TRUE;
6662 /* NOTE: address_completion_end() does nothing with the window
6663 * however this may change. */
6664 address_completion_end(compose->window);
6666 slist_free_strings(compose->to_list);
6667 g_slist_free(compose->to_list);
6668 slist_free_strings(compose->newsgroup_list);
6669 g_slist_free(compose->newsgroup_list);
6670 slist_free_strings(compose->header_list);
6671 g_slist_free(compose->header_list);
6673 procmsg_msginfo_free(compose->targetinfo);
6674 procmsg_msginfo_free(compose->replyinfo);
6675 procmsg_msginfo_free(compose->fwdinfo);
6677 g_free(compose->replyto);
6678 g_free(compose->cc);
6679 g_free(compose->bcc);
6680 g_free(compose->newsgroups);
6681 g_free(compose->followup_to);
6683 g_free(compose->ml_post);
6685 g_free(compose->inreplyto);
6686 g_free(compose->references);
6687 g_free(compose->msgid);
6688 g_free(compose->boundary);
6690 g_free(compose->redirect_filename);
6691 if (compose->undostruct)
6692 undo_destroy(compose->undostruct);
6694 g_free(compose->sig_str);
6696 g_free(compose->exteditor_file);
6698 g_free(compose->orig_charset);
6700 g_free(compose->privacy_system);
6702 if (addressbook_get_target_compose() == compose)
6703 addressbook_set_target_compose(NULL);
6706 if (compose->gtkaspell) {
6707 gtkaspell_delete(compose->gtkaspell);
6708 compose->gtkaspell = NULL;
6712 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6713 prefs_common.compose_height = compose->window->allocation.height;
6715 if (!gtk_widget_get_parent(compose->paned))
6716 gtk_widget_destroy(compose->paned);
6717 gtk_widget_destroy(compose->popupmenu);
6719 gtk_widget_destroy(compose->window);
6720 toolbar_destroy(compose->toolbar);
6721 g_free(compose->toolbar);
6722 g_mutex_free(compose->mutex);
6726 static void compose_attach_info_free(AttachInfo *ainfo)
6728 g_free(ainfo->file);
6729 g_free(ainfo->content_type);
6730 g_free(ainfo->name);
6734 static void compose_attach_remove_selected(Compose *compose)
6736 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6737 GtkTreeSelection *selection;
6739 GtkTreeModel *model;
6741 selection = gtk_tree_view_get_selection(tree_view);
6742 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6747 for (cur = sel; cur != NULL; cur = cur->next) {
6748 GtkTreePath *path = cur->data;
6749 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6752 gtk_tree_path_free(path);
6755 for (cur = sel; cur != NULL; cur = cur->next) {
6756 GtkTreeRowReference *ref = cur->data;
6757 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6760 if (gtk_tree_model_get_iter(model, &iter, path))
6761 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6763 gtk_tree_path_free(path);
6764 gtk_tree_row_reference_free(ref);
6770 static struct _AttachProperty
6773 GtkWidget *mimetype_entry;
6774 GtkWidget *encoding_optmenu;
6775 GtkWidget *path_entry;
6776 GtkWidget *filename_entry;
6778 GtkWidget *cancel_btn;
6781 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6783 gtk_tree_path_free((GtkTreePath *)ptr);
6786 static void compose_attach_property(Compose *compose)
6788 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6790 GtkComboBox *optmenu;
6791 GtkTreeSelection *selection;
6793 GtkTreeModel *model;
6796 static gboolean cancelled;
6798 /* only if one selected */
6799 selection = gtk_tree_view_get_selection(tree_view);
6800 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6803 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6807 path = (GtkTreePath *) sel->data;
6808 gtk_tree_model_get_iter(model, &iter, path);
6809 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6812 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6818 if (!attach_prop.window)
6819 compose_attach_property_create(&cancelled);
6820 gtk_widget_grab_focus(attach_prop.ok_btn);
6821 gtk_widget_show(attach_prop.window);
6822 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6824 optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
6825 if (ainfo->encoding == ENC_UNKNOWN)
6826 combobox_select_by_data(optmenu, ENC_BASE64);
6828 combobox_select_by_data(optmenu, ainfo->encoding);
6830 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6831 ainfo->content_type ? ainfo->content_type : "");
6832 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6833 ainfo->file ? ainfo->file : "");
6834 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6835 ainfo->name ? ainfo->name : "");
6838 const gchar *entry_text;
6840 gchar *cnttype = NULL;
6847 gtk_widget_hide(attach_prop.window);
6852 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6853 if (*entry_text != '\0') {
6856 text = g_strstrip(g_strdup(entry_text));
6857 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6858 cnttype = g_strdup(text);
6861 alertpanel_error(_("Invalid MIME type."));
6867 ainfo->encoding = combobox_get_active_data(optmenu);
6869 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6870 if (*entry_text != '\0') {
6871 if (is_file_exist(entry_text) &&
6872 (size = get_file_size(entry_text)) > 0)
6873 file = g_strdup(entry_text);
6876 (_("File doesn't exist or is empty."));
6882 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6883 if (*entry_text != '\0') {
6884 g_free(ainfo->name);
6885 ainfo->name = g_strdup(entry_text);
6889 g_free(ainfo->content_type);
6890 ainfo->content_type = cnttype;
6893 g_free(ainfo->file);
6899 /* update tree store */
6900 text = to_human_readable(ainfo->size);
6901 gtk_tree_model_get_iter(model, &iter, path);
6902 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6903 COL_MIMETYPE, ainfo->content_type,
6905 COL_NAME, ainfo->name,
6911 gtk_tree_path_free(path);
6914 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6916 label = gtk_label_new(str); \
6917 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6918 GTK_FILL, 0, 0, 0); \
6919 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6921 entry = gtk_entry_new(); \
6922 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6923 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6926 static void compose_attach_property_create(gboolean *cancelled)
6932 GtkWidget *mimetype_entry;
6935 GtkListStore *optmenu_menu;
6936 GtkWidget *path_entry;
6937 GtkWidget *filename_entry;
6940 GtkWidget *cancel_btn;
6941 GList *mime_type_list, *strlist;
6944 debug_print("Creating attach_property window...\n");
6946 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6947 gtk_widget_set_size_request(window, 480, -1);
6948 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6949 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6950 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6951 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6952 g_signal_connect(G_OBJECT(window), "delete_event",
6953 G_CALLBACK(attach_property_delete_event),
6955 g_signal_connect(G_OBJECT(window), "key_press_event",
6956 G_CALLBACK(attach_property_key_pressed),
6959 vbox = gtk_vbox_new(FALSE, 8);
6960 gtk_container_add(GTK_CONTAINER(window), vbox);
6962 table = gtk_table_new(4, 2, FALSE);
6963 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6964 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6965 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6967 label = gtk_label_new(_("MIME type"));
6968 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6970 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6971 mimetype_entry = gtk_combo_new();
6972 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6973 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6975 /* stuff with list */
6976 mime_type_list = procmime_get_mime_type_list();
6978 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6979 MimeType *type = (MimeType *) mime_type_list->data;
6982 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6984 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6987 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6988 (GCompareFunc)strcmp2);
6991 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6993 for (mime_type_list = strlist; mime_type_list != NULL;
6994 mime_type_list = mime_type_list->next)
6995 g_free(mime_type_list->data);
6996 g_list_free(strlist);
6998 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
7000 label = gtk_label_new(_("Encoding"));
7001 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
7003 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7005 hbox = gtk_hbox_new(FALSE, 0);
7006 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
7007 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7009 optmenu = gtkut_sc_combobox_create(NULL, TRUE);
7010 optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
7012 COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
7013 COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
7014 COMBOBOX_ADD(optmenu_menu, "quoted-printable", ENC_QUOTED_PRINTABLE);
7015 COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
7016 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
7018 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
7020 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
7021 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
7023 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
7024 &ok_btn, GTK_STOCK_OK,
7026 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
7027 gtk_widget_grab_default(ok_btn);
7029 g_signal_connect(G_OBJECT(ok_btn), "clicked",
7030 G_CALLBACK(attach_property_ok),
7032 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
7033 G_CALLBACK(attach_property_cancel),
7036 gtk_widget_show_all(vbox);
7038 attach_prop.window = window;
7039 attach_prop.mimetype_entry = mimetype_entry;
7040 attach_prop.encoding_optmenu = optmenu;
7041 attach_prop.path_entry = path_entry;
7042 attach_prop.filename_entry = filename_entry;
7043 attach_prop.ok_btn = ok_btn;
7044 attach_prop.cancel_btn = cancel_btn;
7047 #undef SET_LABEL_AND_ENTRY
7049 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7055 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7061 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7062 gboolean *cancelled)
7070 static gboolean attach_property_key_pressed(GtkWidget *widget,
7072 gboolean *cancelled)
7074 if (event && event->keyval == GDK_Escape) {
7081 static void compose_exec_ext_editor(Compose *compose)
7088 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7089 G_DIR_SEPARATOR, compose);
7091 if (pipe(pipe_fds) < 0) {
7097 if ((pid = fork()) < 0) {
7104 /* close the write side of the pipe */
7107 compose->exteditor_file = g_strdup(tmp);
7108 compose->exteditor_pid = pid;
7110 compose_set_ext_editor_sensitive(compose, FALSE);
7112 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7113 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7117 } else { /* process-monitoring process */
7123 /* close the read side of the pipe */
7126 if (compose_write_body_to_file(compose, tmp) < 0) {
7127 fd_write_all(pipe_fds[1], "2\n", 2);
7131 pid_ed = compose_exec_ext_editor_real(tmp);
7133 fd_write_all(pipe_fds[1], "1\n", 2);
7137 /* wait until editor is terminated */
7138 waitpid(pid_ed, NULL, 0);
7140 fd_write_all(pipe_fds[1], "0\n", 2);
7147 #endif /* G_OS_UNIX */
7151 static gint compose_exec_ext_editor_real(const gchar *file)
7158 g_return_val_if_fail(file != NULL, -1);
7160 if ((pid = fork()) < 0) {
7165 if (pid != 0) return pid;
7167 /* grandchild process */
7169 if (setpgid(0, getppid()))
7172 if (prefs_common.ext_editor_cmd &&
7173 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7174 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7175 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7177 if (prefs_common.ext_editor_cmd)
7178 g_warning("External editor command line is invalid: '%s'\n",
7179 prefs_common.ext_editor_cmd);
7180 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7183 cmdline = strsplit_with_quote(buf, " ", 1024);
7184 execvp(cmdline[0], cmdline);
7187 g_strfreev(cmdline);
7192 static gboolean compose_ext_editor_kill(Compose *compose)
7194 pid_t pgid = compose->exteditor_pid * -1;
7197 ret = kill(pgid, 0);
7199 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7203 msg = g_strdup_printf
7204 (_("The external editor is still working.\n"
7205 "Force terminating the process?\n"
7206 "process group id: %d"), -pgid);
7207 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7208 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7212 if (val == G_ALERTALTERNATE) {
7213 g_source_remove(compose->exteditor_tag);
7214 g_io_channel_shutdown(compose->exteditor_ch,
7216 g_io_channel_unref(compose->exteditor_ch);
7218 if (kill(pgid, SIGTERM) < 0) perror("kill");
7219 waitpid(compose->exteditor_pid, NULL, 0);
7221 g_warning("Terminated process group id: %d", -pgid);
7222 g_warning("Temporary file: %s",
7223 compose->exteditor_file);
7225 compose_set_ext_editor_sensitive(compose, TRUE);
7227 g_free(compose->exteditor_file);
7228 compose->exteditor_file = NULL;
7229 compose->exteditor_pid = -1;
7230 compose->exteditor_ch = NULL;
7231 compose->exteditor_tag = -1;
7239 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7243 Compose *compose = (Compose *)data;
7246 debug_print(_("Compose: input from monitoring process\n"));
7248 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7250 g_io_channel_shutdown(source, FALSE, NULL);
7251 g_io_channel_unref(source);
7253 waitpid(compose->exteditor_pid, NULL, 0);
7255 if (buf[0] == '0') { /* success */
7256 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7257 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7259 gtk_text_buffer_set_text(buffer, "", -1);
7260 compose_insert_file(compose, compose->exteditor_file);
7261 compose_changed_cb(NULL, compose);
7263 if (g_unlink(compose->exteditor_file) < 0)
7264 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7265 } else if (buf[0] == '1') { /* failed */
7266 g_warning("Couldn't exec external editor\n");
7267 if (g_unlink(compose->exteditor_file) < 0)
7268 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7269 } else if (buf[0] == '2') {
7270 g_warning("Couldn't write to file\n");
7271 } else if (buf[0] == '3') {
7272 g_warning("Pipe read failed\n");
7275 compose_set_ext_editor_sensitive(compose, TRUE);
7277 g_free(compose->exteditor_file);
7278 compose->exteditor_file = NULL;
7279 compose->exteditor_pid = -1;
7280 compose->exteditor_ch = NULL;
7281 compose->exteditor_tag = -1;
7286 static void compose_set_ext_editor_sensitive(Compose *compose,
7289 GtkItemFactory *ifactory;
7291 ifactory = gtk_item_factory_from_widget(compose->menubar);
7293 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7294 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7295 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7296 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7297 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7298 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7299 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7302 gtk_widget_set_sensitive(compose->text, sensitive);
7303 if (compose->toolbar->send_btn)
7304 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7305 if (compose->toolbar->sendl_btn)
7306 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7307 if (compose->toolbar->draft_btn)
7308 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7309 if (compose->toolbar->insert_btn)
7310 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7311 if (compose->toolbar->sig_btn)
7312 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7313 if (compose->toolbar->exteditor_btn)
7314 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7315 if (compose->toolbar->linewrap_current_btn)
7316 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7317 if (compose->toolbar->linewrap_all_btn)
7318 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7320 #endif /* G_OS_UNIX */
7323 * compose_undo_state_changed:
7325 * Change the sensivity of the menuentries undo and redo
7327 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7328 gint redo_state, gpointer data)
7330 GtkWidget *widget = GTK_WIDGET(data);
7331 GtkItemFactory *ifactory;
7333 g_return_if_fail(widget != NULL);
7335 ifactory = gtk_item_factory_from_widget(widget);
7337 switch (undo_state) {
7338 case UNDO_STATE_TRUE:
7339 if (!undostruct->undo_state) {
7340 undostruct->undo_state = TRUE;
7341 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7344 case UNDO_STATE_FALSE:
7345 if (undostruct->undo_state) {
7346 undostruct->undo_state = FALSE;
7347 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7350 case UNDO_STATE_UNCHANGED:
7352 case UNDO_STATE_REFRESH:
7353 menu_set_sensitive(ifactory, "/Edit/Undo",
7354 undostruct->undo_state);
7357 g_warning("Undo state not recognized");
7361 switch (redo_state) {
7362 case UNDO_STATE_TRUE:
7363 if (!undostruct->redo_state) {
7364 undostruct->redo_state = TRUE;
7365 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7368 case UNDO_STATE_FALSE:
7369 if (undostruct->redo_state) {
7370 undostruct->redo_state = FALSE;
7371 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7374 case UNDO_STATE_UNCHANGED:
7376 case UNDO_STATE_REFRESH:
7377 menu_set_sensitive(ifactory, "/Edit/Redo",
7378 undostruct->redo_state);
7381 g_warning("Redo state not recognized");
7386 /* callback functions */
7388 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7389 * includes "non-client" (windows-izm) in calculation, so this calculation
7390 * may not be accurate.
7392 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7393 GtkAllocation *allocation,
7394 GtkSHRuler *shruler)
7396 if (prefs_common.show_ruler) {
7397 gint char_width = 0, char_height = 0;
7398 gint line_width_in_chars;
7400 gtkut_get_font_size(GTK_WIDGET(widget),
7401 &char_width, &char_height);
7402 line_width_in_chars =
7403 (allocation->width - allocation->x) / char_width;
7405 /* got the maximum */
7406 gtk_ruler_set_range(GTK_RULER(shruler),
7407 0.0, line_width_in_chars, 0,
7408 /*line_width_in_chars*/ char_width);
7414 static void account_activated(GtkComboBox *optmenu, gpointer data)
7416 Compose *compose = (Compose *)data;
7419 gchar *folderidentifier;
7420 gint account_id = 0;
7424 /* Get ID of active account in the combo box */
7425 menu = gtk_combo_box_get_model(optmenu);
7426 gtk_combo_box_get_active_iter(optmenu, &iter);
7427 gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
7429 ac = account_find_from_id(account_id);
7430 g_return_if_fail(ac != NULL);
7432 if (ac != compose->account)
7433 compose_select_account(compose, ac, FALSE);
7435 /* Set message save folder */
7436 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7437 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7439 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7440 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7442 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7443 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7444 folderidentifier = folder_item_get_identifier(account_get_special_folder
7445 (compose->account, F_OUTBOX));
7446 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7447 g_free(folderidentifier);
7451 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7452 GtkTreeViewColumn *column, Compose *compose)
7454 compose_attach_property(compose);
7457 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7460 Compose *compose = (Compose *)data;
7461 GtkTreeSelection *attach_selection;
7462 gint attach_nr_selected;
7463 GtkItemFactory *ifactory;
7465 if (!event) return FALSE;
7467 if (event->button == 3) {
7468 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7469 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7470 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7472 if (attach_nr_selected > 0)
7474 menu_set_sensitive(ifactory, "/Remove", TRUE);
7475 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7477 menu_set_sensitive(ifactory, "/Remove", FALSE);
7478 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7481 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7482 NULL, NULL, event->button, event->time);
7489 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7492 Compose *compose = (Compose *)data;
7494 if (!event) return FALSE;
7496 switch (event->keyval) {
7498 compose_attach_remove_selected(compose);
7504 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7506 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7507 toolbar_comp_set_sensitive(compose, allow);
7508 menu_set_sensitive(ifactory, "/Message", allow);
7509 menu_set_sensitive(ifactory, "/Edit", allow);
7511 menu_set_sensitive(ifactory, "/Spelling", allow);
7513 menu_set_sensitive(ifactory, "/Options", allow);
7514 menu_set_sensitive(ifactory, "/Tools", allow);
7515 menu_set_sensitive(ifactory, "/Help", allow);
7517 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7521 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7523 Compose *compose = (Compose *)data;
7525 if (prefs_common.work_offline &&
7526 !inc_offline_should_override(
7527 _("Sylpheed-Claws needs network access in order "
7528 "to send this email.")))
7531 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7532 gtk_timeout_remove(compose->draft_timeout_tag);
7533 compose->draft_timeout_tag = -1;
7536 compose_send(compose);
7539 static void compose_send_later_cb(gpointer data, guint action,
7542 Compose *compose = (Compose *)data;
7545 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
7547 compose_close(compose);
7548 } else if (val == -1) {
7549 alertpanel_error(_("Could not queue message."));
7550 } else if (val == -2) {
7551 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7552 } else if (val == -3) {
7553 if (privacy_peek_error())
7554 alertpanel_error(_("Could not queue message for sending:\n\n"
7555 "Signature failed: %s"), privacy_get_error());
7556 } else if (val == -4) {
7557 alertpanel_error(_("Could not queue message for sending:\n\n"
7558 "Charset conversion failed."));
7560 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
7563 void compose_draft (gpointer data)
7565 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7568 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7570 Compose *compose = (Compose *)data;
7574 MsgFlags flag = {0, 0};
7575 static gboolean lock = FALSE;
7576 MsgInfo *newmsginfo;
7578 gboolean target_locked = FALSE;
7582 draft = account_get_special_folder(compose->account, F_DRAFT);
7583 g_return_if_fail(draft != NULL);
7585 if (!g_mutex_trylock(compose->mutex)) {
7586 /* we don't want to lock the mutex once it's available,
7587 * because as the only other part of compose.c locking
7588 * it is compose_close - which means once unlocked,
7589 * the compose struct will be freed */
7590 debug_print("couldn't lock mutex, probably sending\n");
7596 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7597 G_DIR_SEPARATOR, compose);
7598 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7599 FILE_OP_ERROR(tmp, "fopen");
7603 /* chmod for security */
7604 if (change_file_mode_rw(fp, tmp) < 0) {
7605 FILE_OP_ERROR(tmp, "chmod");
7606 g_warning("can't change file mode\n");
7609 /* Save draft infos */
7610 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7611 fprintf(fp, "S:%s\n", compose->account->address);
7613 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7614 gchar *savefolderid;
7616 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7617 fprintf(fp, "SCF:%s\n", savefolderid);
7618 g_free(savefolderid);
7620 if (compose->return_receipt) {
7621 fprintf(fp, "RRCPT:1\n");
7623 if (compose->privacy_system) {
7624 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7625 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7626 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7629 /* Message-ID of message replying to */
7630 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
7633 folderid = folder_item_get_identifier(compose->replyinfo->folder);
7634 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
7637 /* Message-ID of message forwarding to */
7638 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
7641 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
7642 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
7646 /* end of headers */
7647 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
7649 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
7657 if (compose->targetinfo) {
7658 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7659 flag.perm_flags = target_locked?MSG_LOCKED:0;
7661 flag.tmp_flags = MSG_DRAFT;
7663 folder_item_scan(draft);
7664 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7667 if (action != COMPOSE_AUTO_SAVE)
7668 alertpanel_error(_("Could not save draft."));
7673 if (compose->mode == COMPOSE_REEDIT) {
7674 compose_remove_reedit_target(compose, TRUE);
7677 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7679 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7681 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7683 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7684 if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
7685 procmsg_msginfo_set_flags(newmsginfo, 0,
7686 MSG_HAS_ATTACHMENT);
7688 procmsg_msginfo_free(newmsginfo);
7691 folder_item_scan(draft);
7693 if (action == COMPOSE_QUIT_EDITING) {
7695 g_mutex_unlock(compose->mutex); /* must be done before closing */
7696 compose_close(compose);
7702 path = folder_item_fetch_msg(draft, msgnum);
7704 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7707 if (g_stat(path, &s) < 0) {
7708 FILE_OP_ERROR(path, "stat");
7714 procmsg_msginfo_free(compose->targetinfo);
7715 compose->targetinfo = procmsg_msginfo_new();
7716 compose->targetinfo->msgnum = msgnum;
7717 compose->targetinfo->size = s.st_size;
7718 compose->targetinfo->mtime = s.st_mtime;
7719 compose->targetinfo->folder = draft;
7721 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7722 compose->mode = COMPOSE_REEDIT;
7724 if (action == COMPOSE_AUTO_SAVE) {
7725 compose->autosaved_draft = compose->targetinfo;
7727 compose->modified = FALSE;
7728 compose_set_title(compose);
7732 g_mutex_unlock(compose->mutex);
7735 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7737 Compose *compose = (Compose *)data;
7740 if (compose->redirect_filename != NULL)
7743 file_list = filesel_select_multiple_files_open(_("Select file"));
7748 for ( tmp = file_list; tmp; tmp = tmp->next) {
7749 gchar *file = (gchar *) tmp->data;
7750 gchar *utf8_filename = conv_filename_to_utf8(file);
7751 compose_attach_append(compose, file, utf8_filename, NULL);
7752 compose_changed_cb(NULL, compose);
7754 g_free(utf8_filename);
7756 g_list_free(file_list);
7760 static void compose_insert_file_cb(gpointer data, guint action,
7763 Compose *compose = (Compose *)data;
7766 file_list = filesel_select_multiple_files_open(_("Select file"));
7771 for ( tmp = file_list; tmp; tmp = tmp->next) {
7772 gchar *file = (gchar *) tmp->data;
7773 gchar *filedup = g_strdup(file);
7774 gchar *shortfile = g_path_get_basename(filedup);
7775 ComposeInsertResult res;
7777 res = compose_insert_file(compose, file);
7778 if (res == COMPOSE_INSERT_READ_ERROR) {
7779 alertpanel_error(_("File '%s' could not be read."), shortfile);
7780 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7781 alertpanel_error(_("File '%s' contained invalid characters\n"
7782 "for the current encoding, insertion may be incorrect."), shortfile);
7788 g_list_free(file_list);
7792 static void compose_insert_sig_cb(gpointer data, guint action,
7795 Compose *compose = (Compose *)data;
7797 compose_insert_sig(compose, FALSE);
7800 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7804 Compose *compose = (Compose *)data;
7806 gtkut_widget_get_uposition(widget, &x, &y);
7807 prefs_common.compose_x = x;
7808 prefs_common.compose_y = y;
7810 if (compose->sending || compose->updating)
7812 compose_close_cb(compose, 0, NULL);
7816 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7818 Compose *compose = (Compose *)data;
7822 if (compose->exteditor_tag != -1) {
7823 if (!compose_ext_editor_kill(compose))
7828 if (compose->modified) {
7829 val = alertpanel(_("Discard message"),
7830 _("This message has been modified. Discard it?"),
7831 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7834 case G_ALERTDEFAULT:
7835 if (prefs_common.autosave)
7836 compose_remove_draft(compose);
7838 case G_ALERTALTERNATE:
7839 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7846 compose_close(compose);
7849 static void compose_set_encoding_cb(gpointer data, guint action,
7852 Compose *compose = (Compose *)data;
7854 if (GTK_CHECK_MENU_ITEM(widget)->active)
7855 compose->out_encoding = (CharSet)action;
7858 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7860 Compose *compose = (Compose *)data;
7862 addressbook_open(compose);
7865 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7867 Compose *compose = (Compose *)data;
7872 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7873 g_return_if_fail(tmpl != NULL);
7875 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7877 val = alertpanel(_("Apply template"), msg,
7878 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7881 if (val == G_ALERTDEFAULT)
7882 compose_template_apply(compose, tmpl, TRUE);
7883 else if (val == G_ALERTALTERNATE)
7884 compose_template_apply(compose, tmpl, FALSE);
7887 static void compose_ext_editor_cb(gpointer data, guint action,
7890 Compose *compose = (Compose *)data;
7892 compose_exec_ext_editor(compose);
7895 static void compose_undo_cb(Compose *compose)
7897 gboolean prev_autowrap = compose->autowrap;
7899 compose->autowrap = FALSE;
7900 undo_undo(compose->undostruct);
7901 compose->autowrap = prev_autowrap;
7904 static void compose_redo_cb(Compose *compose)
7906 gboolean prev_autowrap = compose->autowrap;
7908 compose->autowrap = FALSE;
7909 undo_redo(compose->undostruct);
7910 compose->autowrap = prev_autowrap;
7913 static void entry_cut_clipboard(GtkWidget *entry)
7915 if (GTK_IS_EDITABLE(entry))
7916 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7917 else if (GTK_IS_TEXT_VIEW(entry))
7918 gtk_text_buffer_cut_clipboard(
7919 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7920 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7924 static void entry_copy_clipboard(GtkWidget *entry)
7926 if (GTK_IS_EDITABLE(entry))
7927 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7928 else if (GTK_IS_TEXT_VIEW(entry))
7929 gtk_text_buffer_copy_clipboard(
7930 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7931 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7934 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7935 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
7937 if (GTK_IS_TEXT_VIEW(entry)) {
7938 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7939 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7940 GtkTextIter start_iter, end_iter;
7942 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7944 if (contents == NULL)
7947 undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);
7949 /* we shouldn't delete the selection when middle-click-pasting, or we
7950 * can't mid-click-paste our own selection */
7951 if (clip != GDK_SELECTION_PRIMARY) {
7952 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7955 if (insert_place == NULL) {
7956 /* if insert_place isn't specified, insert at the cursor.
7957 * used for Ctrl-V pasting */
7958 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7959 start = gtk_text_iter_get_offset(&start_iter);
7960 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7962 /* if insert_place is specified, paste here.
7963 * used for mid-click-pasting */
7964 start = gtk_text_iter_get_offset(insert_place);
7965 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
7969 /* paste unwrapped: mark the paste so it's not wrapped later */
7970 end = start + strlen(contents);
7971 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7972 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7973 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7974 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7975 /* rewrap paragraph now (after a mid-click-paste) */
7976 mark_start = gtk_text_buffer_get_insert(buffer);
7977 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7978 gtk_text_iter_backward_char(&start_iter);
7979 compose_beautify_paragraph(compose, &start_iter, TRUE);
7981 } else if (GTK_IS_EDITABLE(entry))
7982 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7986 static void entry_allsel(GtkWidget *entry)
7988 if (GTK_IS_EDITABLE(entry))
7989 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7990 else if (GTK_IS_TEXT_VIEW(entry)) {
7991 GtkTextIter startiter, enditer;
7992 GtkTextBuffer *textbuf;
7994 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7995 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7996 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7998 gtk_text_buffer_move_mark_by_name(textbuf,
7999 "selection_bound", &startiter);
8000 gtk_text_buffer_move_mark_by_name(textbuf,
8001 "insert", &enditer);
8005 static void compose_cut_cb(Compose *compose)
8007 if (compose->focused_editable &&
8008 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8009 entry_cut_clipboard(compose->focused_editable);
8012 static void compose_copy_cb(Compose *compose)
8014 if (compose->focused_editable &&
8015 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8016 entry_copy_clipboard(compose->focused_editable);
8019 static void compose_paste_cb(Compose *compose)
8022 GtkTextBuffer *buffer;
8024 if (compose->focused_editable &&
8025 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8026 entry_paste_clipboard(compose, compose->focused_editable,
8027 prefs_common.linewrap_pastes,
8028 GDK_SELECTION_CLIPBOARD, NULL);
8032 static void compose_paste_as_quote_cb(Compose *compose)
8034 gint wrap_quote = prefs_common.linewrap_quote;
8035 if (compose->focused_editable &&
8036 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
8037 /* let text_insert() (called directly or at a later time
8038 * after the gtk_editable_paste_clipboard) know that
8039 * text is to be inserted as a quotation. implemented
8040 * by using a simple refcount... */
8041 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
8042 G_OBJECT(compose->focused_editable),
8043 "paste_as_quotation"));
8044 g_object_set_data(G_OBJECT(compose->focused_editable),
8045 "paste_as_quotation",
8046 GINT_TO_POINTER(paste_as_quotation + 1));
8047 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
8048 entry_paste_clipboard(compose, compose->focused_editable,
8049 prefs_common.linewrap_pastes,
8050 GDK_SELECTION_CLIPBOARD, NULL);
8051 prefs_common.linewrap_quote = wrap_quote;
8055 static void compose_paste_no_wrap_cb(Compose *compose)
8058 GtkTextBuffer *buffer;
8060 if (compose->focused_editable &&
8061 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8062 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
8063 GDK_SELECTION_CLIPBOARD, NULL);
8067 static void compose_paste_wrap_cb(Compose *compose)
8070 GtkTextBuffer *buffer;
8072 if (compose->focused_editable &&
8073 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8074 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
8075 GDK_SELECTION_CLIPBOARD, NULL);
8079 static void compose_allsel_cb(Compose *compose)
8081 if (compose->focused_editable &&
8082 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8083 entry_allsel(compose->focused_editable);
8086 static void textview_move_beginning_of_line (GtkTextView *text)
8088 GtkTextBuffer *buffer;
8092 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8094 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8095 mark = gtk_text_buffer_get_insert(buffer);
8096 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8097 gtk_text_iter_set_line_offset(&ins, 0);
8098 gtk_text_buffer_place_cursor(buffer, &ins);
8101 static void textview_move_forward_character (GtkTextView *text)
8103 GtkTextBuffer *buffer;
8107 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8109 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8110 mark = gtk_text_buffer_get_insert(buffer);
8111 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8112 if (gtk_text_iter_forward_cursor_position(&ins))
8113 gtk_text_buffer_place_cursor(buffer, &ins);
8116 static void textview_move_backward_character (GtkTextView *text)
8118 GtkTextBuffer *buffer;
8122 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8124 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8125 mark = gtk_text_buffer_get_insert(buffer);
8126 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8127 if (gtk_text_iter_backward_cursor_position(&ins))
8128 gtk_text_buffer_place_cursor(buffer, &ins);
8131 static void textview_move_forward_word (GtkTextView *text)
8133 GtkTextBuffer *buffer;
8138 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8140 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8141 mark = gtk_text_buffer_get_insert(buffer);
8142 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8143 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8144 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8145 gtk_text_iter_backward_word_start(&ins);
8146 gtk_text_buffer_place_cursor(buffer, &ins);
8150 static void textview_move_backward_word (GtkTextView *text)
8152 GtkTextBuffer *buffer;
8157 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8159 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8160 mark = gtk_text_buffer_get_insert(buffer);
8161 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8162 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8163 if (gtk_text_iter_backward_word_starts(&ins, 1))
8164 gtk_text_buffer_place_cursor(buffer, &ins);
8167 static void textview_move_end_of_line (GtkTextView *text)
8169 GtkTextBuffer *buffer;
8173 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8175 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8176 mark = gtk_text_buffer_get_insert(buffer);
8177 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8178 if (gtk_text_iter_forward_to_line_end(&ins))
8179 gtk_text_buffer_place_cursor(buffer, &ins);
8182 static void textview_move_next_line (GtkTextView *text)
8184 GtkTextBuffer *buffer;
8189 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8191 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8192 mark = gtk_text_buffer_get_insert(buffer);
8193 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8194 offset = gtk_text_iter_get_line_offset(&ins);
8195 if (gtk_text_iter_forward_line(&ins)) {
8196 gtk_text_iter_set_line_offset(&ins, offset);
8197 gtk_text_buffer_place_cursor(buffer, &ins);
8201 static void textview_move_previous_line (GtkTextView *text)
8203 GtkTextBuffer *buffer;
8208 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8210 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8211 mark = gtk_text_buffer_get_insert(buffer);
8212 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8213 offset = gtk_text_iter_get_line_offset(&ins);
8214 if (gtk_text_iter_backward_line(&ins)) {
8215 gtk_text_iter_set_line_offset(&ins, offset);
8216 gtk_text_buffer_place_cursor(buffer, &ins);
8220 static void textview_delete_forward_character (GtkTextView *text)
8222 GtkTextBuffer *buffer;
8224 GtkTextIter ins, end_iter;
8226 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8228 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8229 mark = gtk_text_buffer_get_insert(buffer);
8230 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8232 if (gtk_text_iter_forward_char(&end_iter)) {
8233 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8237 static void textview_delete_backward_character (GtkTextView *text)
8239 GtkTextBuffer *buffer;
8241 GtkTextIter ins, end_iter;
8243 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8245 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8246 mark = gtk_text_buffer_get_insert(buffer);
8247 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8249 if (gtk_text_iter_backward_char(&end_iter)) {
8250 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8254 static void textview_delete_forward_word (GtkTextView *text)
8256 GtkTextBuffer *buffer;
8258 GtkTextIter ins, end_iter;
8260 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8262 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8263 mark = gtk_text_buffer_get_insert(buffer);
8264 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8266 if (gtk_text_iter_forward_word_end(&end_iter)) {
8267 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8271 static void textview_delete_backward_word (GtkTextView *text)
8273 GtkTextBuffer *buffer;
8275 GtkTextIter ins, end_iter;
8277 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8279 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8280 mark = gtk_text_buffer_get_insert(buffer);
8281 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8283 if (gtk_text_iter_backward_word_start(&end_iter)) {
8284 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8288 static void textview_delete_line (GtkTextView *text)
8290 GtkTextBuffer *buffer;
8292 GtkTextIter ins, start_iter, end_iter;
8295 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8297 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8298 mark = gtk_text_buffer_get_insert(buffer);
8299 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8302 gtk_text_iter_set_line_offset(&start_iter, 0);
8305 if (gtk_text_iter_ends_line(&end_iter))
8306 found = gtk_text_iter_forward_char(&end_iter);
8308 found = gtk_text_iter_forward_to_line_end(&end_iter);
8311 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8314 static void textview_delete_to_line_end (GtkTextView *text)
8316 GtkTextBuffer *buffer;
8318 GtkTextIter ins, end_iter;
8321 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8323 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8324 mark = gtk_text_buffer_get_insert(buffer);
8325 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8327 if (gtk_text_iter_ends_line(&end_iter))
8328 found = gtk_text_iter_forward_char(&end_iter);
8330 found = gtk_text_iter_forward_to_line_end(&end_iter);
8332 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8335 static void compose_advanced_action_cb(Compose *compose,
8336 ComposeCallAdvancedAction action)
8338 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8340 void (*do_action) (GtkTextView *text);
8341 } action_table[] = {
8342 {textview_move_beginning_of_line},
8343 {textview_move_forward_character},
8344 {textview_move_backward_character},
8345 {textview_move_forward_word},
8346 {textview_move_backward_word},
8347 {textview_move_end_of_line},
8348 {textview_move_next_line},
8349 {textview_move_previous_line},
8350 {textview_delete_forward_character},
8351 {textview_delete_backward_character},
8352 {textview_delete_forward_word},
8353 {textview_delete_backward_word},
8354 {textview_delete_line},
8355 {NULL}, /* gtk_stext_delete_line_n */
8356 {textview_delete_to_line_end}
8359 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8361 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8362 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8363 if (action_table[action].do_action)
8364 action_table[action].do_action(text);
8366 g_warning("Not implemented yet.");
8370 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8374 if (GTK_IS_EDITABLE(widget)) {
8375 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8376 gtk_editable_set_position(GTK_EDITABLE(widget),
8379 if (widget->parent && widget->parent->parent
8380 && widget->parent->parent->parent) {
8381 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8382 gint y = widget->allocation.y;
8383 gint height = widget->allocation.height;
8384 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8385 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8387 if (y < (int)shown->value) {
8388 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8390 if (y + height > (int)shown->value + (int)shown->page_size) {
8391 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8392 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8393 y + height - (int)shown->page_size - 1);
8395 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8396 (int)shown->upper - (int)shown->page_size - 1);
8403 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8404 compose->focused_editable = widget;
8407 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8409 compose->modified = TRUE;
8410 compose_set_title(compose);
8413 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8415 Compose *compose = (Compose *)data;
8418 compose_wrap_all_full(compose, TRUE);
8420 compose_beautify_paragraph(compose, NULL, TRUE);
8423 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8425 Compose *compose = (Compose *)data;
8427 message_search_compose(compose);
8430 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8433 Compose *compose = (Compose *)data;
8434 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8435 if (compose->autowrap)
8436 compose_wrap_all_full(compose, TRUE);
8437 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8440 static void compose_toggle_sign_cb(gpointer data, guint action,
8443 Compose *compose = (Compose *)data;
8445 if (GTK_CHECK_MENU_ITEM(widget)->active)
8446 compose->use_signing = TRUE;
8448 compose->use_signing = FALSE;
8451 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8454 Compose *compose = (Compose *)data;
8456 if (GTK_CHECK_MENU_ITEM(widget)->active)
8457 compose->use_encryption = TRUE;
8459 compose->use_encryption = FALSE;
8462 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8464 g_free(compose->privacy_system);
8466 compose->privacy_system = g_strdup(account->default_privacy_system);
8467 compose_update_privacy_system_menu_item(compose, warn);
8470 static void compose_toggle_ruler_cb(gpointer data, guint action,
8473 Compose *compose = (Compose *)data;
8475 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8476 gtk_widget_show(compose->ruler_hbox);
8477 prefs_common.show_ruler = TRUE;
8479 gtk_widget_hide(compose->ruler_hbox);
8480 gtk_widget_queue_resize(compose->edit_vbox);
8481 prefs_common.show_ruler = FALSE;
8485 static void compose_attach_drag_received_cb (GtkWidget *widget,
8486 GdkDragContext *context,
8489 GtkSelectionData *data,
8494 Compose *compose = (Compose *)user_data;
8497 if (gdk_atom_name(data->type) &&
8498 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8499 && gtk_drag_get_source_widget(context) !=
8500 mainwindow_get_mainwindow()->summaryview->ctree) {
8501 list = uri_list_extract_filenames((const gchar *)data->data);
8502 for (tmp = list; tmp != NULL; tmp = tmp->next)
8503 compose_attach_append
8504 (compose, (const gchar *)tmp->data,
8505 (const gchar *)tmp->data, NULL);
8506 if (list) compose_changed_cb(NULL, compose);
8507 list_free_strings(list);
8509 } else if (gtk_drag_get_source_widget(context)
8510 == mainwindow_get_mainwindow()->summaryview->ctree) {
8511 /* comes from our summaryview */
8512 SummaryView * summaryview = NULL;
8513 GSList * list = NULL, *cur = NULL;
8515 if (mainwindow_get_mainwindow())
8516 summaryview = mainwindow_get_mainwindow()->summaryview;
8519 list = summary_get_selected_msg_list(summaryview);
8521 for (cur = list; cur; cur = cur->next) {
8522 MsgInfo *msginfo = (MsgInfo *)cur->data;
8525 file = procmsg_get_message_file_full(msginfo,
8528 compose_attach_append(compose, (const gchar *)file,
8529 (const gchar *)file, "message/rfc822");
8537 static gboolean compose_drag_drop(GtkWidget *widget,
8538 GdkDragContext *drag_context,
8540 guint time, gpointer user_data)
8542 /* not handling this signal makes compose_insert_drag_received_cb
8547 static void compose_insert_drag_received_cb (GtkWidget *widget,
8548 GdkDragContext *drag_context,
8551 GtkSelectionData *data,
8556 Compose *compose = (Compose *)user_data;
8559 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8561 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8562 AlertValue val = G_ALERTDEFAULT;
8564 switch (prefs_common.compose_dnd_mode) {
8565 case COMPOSE_DND_ASK:
8566 val = alertpanel_full(_("Insert or attach?"),
8567 _("Do you want to insert the contents of the file(s) "
8568 "into the message body, or attach it to the email?"),
8569 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
8570 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
8572 case COMPOSE_DND_INSERT:
8573 val = G_ALERTALTERNATE;
8575 case COMPOSE_DND_ATTACH:
8579 /* unexpected case */
8580 g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
8583 if (val & G_ALERTDISABLE) {
8584 val &= ~G_ALERTDISABLE;
8585 /* remember what action to perform by default, only if we don't click Cancel */
8586 if (val == G_ALERTALTERNATE)
8587 prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
8588 else if (val == G_ALERTOTHER)
8589 prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
8592 if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
8593 gtk_drag_finish(drag_context, FALSE, FALSE, time);
8595 } else if (val == G_ALERTOTHER) {
8596 compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
8599 list = uri_list_extract_filenames((const gchar *)data->data);
8600 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8601 compose_insert_file(compose, (const gchar *)tmp->data);
8603 list_free_strings(list);
8605 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8608 #if GTK_CHECK_VERSION(2, 8, 0)
8609 /* do nothing, handled by GTK */
8611 gchar *tmpfile = get_tmp_file();
8612 str_write_to_file((const gchar *)data->data, tmpfile);
8613 compose_insert_file(compose, tmpfile);
8616 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8620 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8623 static void compose_header_drag_received_cb (GtkWidget *widget,
8624 GdkDragContext *drag_context,
8627 GtkSelectionData *data,
8632 GtkEditable *entry = (GtkEditable *)user_data;
8633 gchar *email = (gchar *)data->data;
8635 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8638 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8639 gchar *decoded=g_new(gchar, strlen(email));
8642 email += strlen("mailto:");
8643 decode_uri(decoded, email); /* will fit */
8644 gtk_editable_delete_text(entry, 0, -1);
8645 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8646 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8650 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8653 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8656 Compose *compose = (Compose *)data;
8658 if (GTK_CHECK_MENU_ITEM(widget)->active)
8659 compose->return_receipt = TRUE;
8661 compose->return_receipt = FALSE;
8664 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8667 Compose *compose = (Compose *)data;
8669 if (GTK_CHECK_MENU_ITEM(widget)->active)
8670 compose->remove_references = TRUE;
8672 compose->remove_references = FALSE;
8675 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8677 ComposeHeaderEntry *headerentry)
8679 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8680 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8681 !(event->state & GDK_MODIFIER_MASK) &&
8682 (event->keyval == GDK_BackSpace) &&
8683 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8684 gtk_container_remove
8685 (GTK_CONTAINER(headerentry->compose->header_table),
8686 headerentry->combo);
8687 gtk_container_remove
8688 (GTK_CONTAINER(headerentry->compose->header_table),
8689 headerentry->entry);
8690 headerentry->compose->header_list =
8691 g_slist_remove(headerentry->compose->header_list,
8693 g_free(headerentry);
8694 } else if (event->keyval == GDK_Tab) {
8695 if (headerentry->compose->header_last == headerentry) {
8696 /* Override default next focus, and give it to subject_entry
8697 * instead of notebook tabs
8699 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8700 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8707 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8708 ComposeHeaderEntry *headerentry)
8710 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8711 headerentry->compose->header_list =
8712 g_slist_append(headerentry->compose->header_list,
8715 compose_create_header_entry(headerentry->compose);
8716 g_signal_handlers_disconnect_matched
8717 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8718 0, 0, NULL, NULL, headerentry);
8720 /* Automatically scroll down */
8721 compose_show_first_last_header(headerentry->compose, FALSE);
8727 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8729 GtkAdjustment *vadj;
8731 g_return_if_fail(compose);
8732 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8733 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8735 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8736 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8739 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8740 const gchar *text, gint len, Compose *compose)
8742 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8743 (G_OBJECT(compose->text), "paste_as_quotation"));
8746 g_return_if_fail(text != NULL);
8748 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8749 G_CALLBACK(text_inserted),
8751 if (paste_as_quotation) {
8758 new_text = g_strndup(text, len);
8759 if (prefs_common.quotemark && *prefs_common.quotemark)
8760 qmark = prefs_common.quotemark;
8764 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8765 gtk_text_buffer_place_cursor(buffer, iter);
8767 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8768 quote_fmt_reset_vartable();
8770 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8771 GINT_TO_POINTER(paste_as_quotation - 1));
8773 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8774 gtk_text_buffer_place_cursor(buffer, iter);
8776 if (strcmp(text, "\n") || automatic_break
8777 || gtk_text_iter_starts_line(iter))
8778 gtk_text_buffer_insert(buffer, iter, text, len);
8780 debug_print("insert nowrap \\n\n");
8781 gtk_text_buffer_insert_with_tags_by_name(buffer,
8782 iter, text, len, "no_join", NULL);
8786 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8788 compose_beautify_paragraph(compose, iter, FALSE);
8790 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8791 gtk_text_buffer_delete_mark(buffer, mark);
8793 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8794 G_CALLBACK(text_inserted),
8796 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8798 if (prefs_common.autosave &&
8799 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8800 compose->draft_timeout_tag = gtk_timeout_add
8801 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8803 static gint compose_defer_auto_save_draft(Compose *compose)
8805 compose->draft_timeout_tag = -1;
8806 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8811 static void compose_check_all(Compose *compose)
8813 if (compose->gtkaspell)
8814 gtkaspell_check_all(compose->gtkaspell);
8817 static void compose_highlight_all(Compose *compose)
8819 if (compose->gtkaspell)
8820 gtkaspell_highlight_all(compose->gtkaspell);
8823 static void compose_check_backwards(Compose *compose)
8825 if (compose->gtkaspell)
8826 gtkaspell_check_backwards(compose->gtkaspell);
8828 GtkItemFactory *ifactory;
8829 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8830 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8831 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8835 static void compose_check_forwards_go(Compose *compose)
8837 if (compose->gtkaspell)
8838 gtkaspell_check_forwards_go(compose->gtkaspell);
8840 GtkItemFactory *ifactory;
8841 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8842 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8843 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8849 *\brief Guess originating forward account from MsgInfo and several
8850 * "common preference" settings. Return NULL if no guess.
8852 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8854 PrefsAccount *account = NULL;
8856 g_return_val_if_fail(msginfo, NULL);
8857 g_return_val_if_fail(msginfo->folder, NULL);
8858 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8860 if (msginfo->folder->prefs->enable_default_account)
8861 account = account_find_from_id(msginfo->folder->prefs->default_account);
8864 account = msginfo->folder->folder->account;
8866 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8868 Xstrdup_a(to, msginfo->to, return NULL);
8869 extract_address(to);
8870 account = account_find_from_address(to);
8873 if (!account && prefs_common.forward_account_autosel) {
8875 if (!procheader_get_header_from_msginfo
8876 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8877 extract_address(cc);
8878 account = account_find_from_address(cc);
8885 gboolean compose_close(Compose *compose)
8889 if (!g_mutex_trylock(compose->mutex)) {
8890 /* we have to wait for the (possibly deferred by auto-save)
8891 * drafting to be done, before destroying the compose under
8893 debug_print("waiting for drafting to finish...\n");
8894 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8897 g_return_val_if_fail(compose, FALSE);
8898 gtkut_widget_get_uposition(compose->window, &x, &y);
8899 prefs_common.compose_x = x;
8900 prefs_common.compose_y = y;
8901 g_mutex_unlock(compose->mutex);
8902 compose_destroy(compose);
8907 * Add entry field for each address in list.
8908 * \param compose E-Mail composition object.
8909 * \param listAddress List of (formatted) E-Mail addresses.
8911 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8916 addr = ( gchar * ) node->data;
8917 compose_entry_append( compose, addr, COMPOSE_TO );
8918 node = g_list_next( node );
8922 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
8923 guint action, gboolean opening_multiple)
8926 GSList *new_msglist = NULL;
8927 MsgInfo *tmp_msginfo = NULL;
8928 gboolean originally_enc = FALSE;
8929 Compose *compose = NULL;
8931 g_return_if_fail(msgview != NULL);
8933 g_return_if_fail(msginfo_list != NULL);
8935 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
8936 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8937 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8939 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8940 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8941 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8942 orig_msginfo, mimeinfo);
8943 if (tmp_msginfo != NULL) {
8944 new_msglist = g_slist_append(NULL, tmp_msginfo);
8945 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8946 originally_enc = TRUE;
8952 if (!opening_multiple)
8953 body = messageview_get_selection(msgview);
8956 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8957 procmsg_msginfo_free(tmp_msginfo);
8958 g_slist_free(new_msglist);
8960 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8962 if (originally_enc) {
8963 compose_force_encryption(compose, compose->account, FALSE);
8969 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8972 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
8973 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
8974 GSList *cur = msginfo_list;
8975 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
8976 "messages. Opening the windows "
8977 "could take some time. Do you "
8978 "want to continue?"),
8979 g_slist_length(msginfo_list));
8980 if (g_slist_length(msginfo_list) > 9
8981 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
8982 != G_ALERTALTERNATE) {
8987 /* We'll open multiple compose windows */
8988 /* let the WM place the next windows */
8989 compose_force_window_origin = FALSE;
8990 for (; cur; cur = cur->next) {
8992 tmplist.data = cur->data;
8993 tmplist.next = NULL;
8994 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
8996 compose_force_window_origin = TRUE;
8998 /* forwarding multiple mails as attachments is done via a
8999 * single compose window */
9000 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
9004 void compose_set_position(Compose *compose, gint pos)
9006 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9008 gtkut_text_view_set_position(text, pos);
9011 gboolean compose_search_string(Compose *compose,
9012 const gchar *str, gboolean case_sens)
9014 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9016 return gtkut_text_view_search_string(text, str, case_sens);
9019 gboolean compose_search_string_backward(Compose *compose,
9020 const gchar *str, gboolean case_sens)
9022 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9024 return gtkut_text_view_search_string_backward(text, str, case_sens);