2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
123 #include "combobox.h"
136 #define N_ATTACH_COLS (N_COL_COLUMNS)
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
154 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
155 } ComposeCallAdvancedAction;
159 PRIORITY_HIGHEST = 1,
168 COMPOSE_INSERT_SUCCESS,
169 COMPOSE_INSERT_READ_ERROR,
170 COMPOSE_INSERT_INVALID_CHARACTER,
171 COMPOSE_INSERT_NO_FILE
172 } ComposeInsertResult;
176 COMPOSE_QUIT_EDITING,
177 COMPOSE_KEEP_EDITING,
179 } ComposeDraftAction;
183 COMPOSE_WRITE_FOR_SEND,
184 COMPOSE_WRITE_FOR_STORE
187 #define B64_LINE_SIZE 57
188 #define B64_BUFFSIZE 77
190 #define MAX_REFERENCES_LEN 999
192 static GList *compose_list = NULL;
194 Compose *compose_generic_new (PrefsAccount *account,
197 GPtrArray *attach_files,
198 GList *listAddress );
200 static Compose *compose_create (PrefsAccount *account,
204 static GtkWidget *compose_account_option_menu_create
206 static void compose_set_out_encoding (Compose *compose);
207 static void compose_set_template_menu (Compose *compose);
208 static void compose_template_apply (Compose *compose,
211 static void compose_destroy (Compose *compose);
213 static void compose_entries_set (Compose *compose,
214 const gchar *mailto);
215 static gint compose_parse_header (Compose *compose,
217 static gchar *compose_parse_references (const gchar *ref,
220 static gchar *compose_quote_fmt (Compose *compose,
226 const gchar *err_msg);
228 static void compose_reply_set_entry (Compose *compose,
234 followup_and_reply_to);
235 static void compose_reedit_set_entry (Compose *compose,
238 static void compose_insert_sig (Compose *compose,
240 static gchar *compose_get_signature_str (Compose *compose);
241 static ComposeInsertResult compose_insert_file (Compose *compose,
244 static gboolean compose_attach_append (Compose *compose,
247 const gchar *content_type);
248 static void compose_attach_parts (Compose *compose,
251 static void compose_beautify_paragraph (Compose *compose,
252 GtkTextIter *par_iter,
254 static void compose_wrap_all (Compose *compose);
255 static void compose_wrap_all_full (Compose *compose,
258 static void compose_set_title (Compose *compose);
259 static void compose_select_account (Compose *compose,
260 PrefsAccount *account,
263 static PrefsAccount *compose_current_mail_account(void);
264 /* static gint compose_send (Compose *compose); */
265 static gboolean compose_check_for_valid_recipient
267 static gboolean compose_check_entries (Compose *compose,
268 gboolean check_subject);
269 static gint compose_write_to_file (Compose *compose,
272 gboolean attach_parts);
273 static gint compose_write_body_to_file (Compose *compose,
275 static gint compose_remove_reedit_target (Compose *compose,
277 void compose_remove_draft (Compose *compose);
278 static gint compose_queue_sub (Compose *compose,
282 gboolean check_subject,
283 gboolean remove_reedit_target);
284 static void compose_add_attachments (Compose *compose,
286 static gchar *compose_get_header (Compose *compose);
288 static void compose_convert_header (Compose *compose,
293 gboolean addr_field);
295 static void compose_attach_info_free (AttachInfo *ainfo);
296 static void compose_attach_remove_selected (Compose *compose);
298 static void compose_attach_property (Compose *compose);
299 static void compose_attach_property_create (gboolean *cancelled);
300 static void attach_property_ok (GtkWidget *widget,
301 gboolean *cancelled);
302 static void attach_property_cancel (GtkWidget *widget,
303 gboolean *cancelled);
304 static gint attach_property_delete_event (GtkWidget *widget,
306 gboolean *cancelled);
307 static gboolean attach_property_key_pressed (GtkWidget *widget,
309 gboolean *cancelled);
311 static void compose_exec_ext_editor (Compose *compose);
313 static gint compose_exec_ext_editor_real (const gchar *file);
314 static gboolean compose_ext_editor_kill (Compose *compose);
315 static gboolean compose_input_cb (GIOChannel *source,
316 GIOCondition condition,
318 static void compose_set_ext_editor_sensitive (Compose *compose,
320 #endif /* G_OS_UNIX */
322 static void compose_undo_state_changed (UndoMain *undostruct,
327 static void compose_create_header_entry (Compose *compose);
328 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
329 static void compose_remove_header_entries(Compose *compose);
331 static void compose_update_priority_menu_item(Compose * compose);
333 static void compose_spell_menu_changed (void *data);
335 static void compose_add_field_list ( Compose *compose,
336 GList *listAddress );
338 /* callback functions */
340 static gboolean compose_edit_size_alloc (GtkEditable *widget,
341 GtkAllocation *allocation,
342 GtkSHRuler *shruler);
343 static void account_activated (GtkComboBox *optmenu,
345 static void attach_selected (GtkTreeView *tree_view,
346 GtkTreePath *tree_path,
347 GtkTreeViewColumn *column,
349 static gboolean attach_button_pressed (GtkWidget *widget,
350 GdkEventButton *event,
352 static gboolean attach_key_pressed (GtkWidget *widget,
356 static void compose_send_cb (gpointer data,
359 static void compose_send_later_cb (gpointer data,
363 static void compose_draft_cb (gpointer data,
367 static void compose_attach_cb (gpointer data,
370 static void compose_insert_file_cb (gpointer data,
373 static void compose_insert_sig_cb (gpointer data,
377 static void compose_close_cb (gpointer data,
381 static void compose_set_encoding_cb (gpointer data,
385 static void compose_address_cb (gpointer data,
388 static void compose_template_activate_cb(GtkWidget *widget,
391 static void compose_ext_editor_cb (gpointer data,
395 static gint compose_delete_cb (GtkWidget *widget,
399 static void compose_undo_cb (Compose *compose);
400 static void compose_redo_cb (Compose *compose);
401 static void compose_cut_cb (Compose *compose);
402 static void compose_copy_cb (Compose *compose);
403 static void compose_paste_cb (Compose *compose);
404 static void compose_paste_as_quote_cb (Compose *compose);
405 static void compose_paste_no_wrap_cb (Compose *compose);
406 static void compose_paste_wrap_cb (Compose *compose);
407 static void compose_allsel_cb (Compose *compose);
409 static void compose_advanced_action_cb (Compose *compose,
410 ComposeCallAdvancedAction action);
412 static void compose_grab_focus_cb (GtkWidget *widget,
415 static void compose_changed_cb (GtkTextBuffer *textbuf,
418 static void compose_wrap_cb (gpointer data,
421 static void compose_find_cb (gpointer data,
424 static void compose_toggle_autowrap_cb (gpointer data,
428 static void compose_toggle_ruler_cb (gpointer data,
431 static void compose_toggle_sign_cb (gpointer data,
434 static void compose_toggle_encrypt_cb (gpointer data,
437 static void compose_set_privacy_system_cb(GtkWidget *widget,
439 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
440 static void activate_privacy_system (Compose *compose,
441 PrefsAccount *account,
443 static void compose_use_signing(Compose *compose, gboolean use_signing);
444 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
445 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
447 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
449 static void compose_set_priority_cb (gpointer data,
452 static void compose_reply_change_mode (gpointer data,
456 static void compose_attach_drag_received_cb (GtkWidget *widget,
457 GdkDragContext *drag_context,
460 GtkSelectionData *data,
464 static void compose_insert_drag_received_cb (GtkWidget *widget,
465 GdkDragContext *drag_context,
468 GtkSelectionData *data,
472 static void compose_header_drag_received_cb (GtkWidget *widget,
473 GdkDragContext *drag_context,
476 GtkSelectionData *data,
481 static gboolean compose_drag_drop (GtkWidget *widget,
482 GdkDragContext *drag_context,
484 guint time, gpointer user_data);
486 static void text_inserted (GtkTextBuffer *buffer,
491 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
492 gboolean to_all, gboolean to_ml,
494 gboolean followup_and_reply_to,
497 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
498 ComposeHeaderEntry *headerentry);
499 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
501 ComposeHeaderEntry *headerentry);
503 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
505 static void compose_allow_user_actions (Compose *compose, gboolean allow);
508 static void compose_check_all (Compose *compose);
509 static void compose_highlight_all (Compose *compose);
510 static void compose_check_backwards (Compose *compose);
511 static void compose_check_forwards_go (Compose *compose);
514 static gint compose_defer_auto_save_draft (Compose *compose);
515 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
517 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
519 static GtkItemFactoryEntry compose_popup_entries[] =
521 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
522 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
523 {N_("/---"), NULL, NULL, 0, "<Separator>"},
524 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
527 static GtkItemFactoryEntry compose_entries[] =
529 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
530 {N_("/_Message/_Send"), "<control>Return",
531 compose_send_cb, 0, NULL},
532 {N_("/_Message/Send _later"), "<shift><control>S",
533 compose_send_later_cb, 0, NULL},
534 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
535 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
536 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
537 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
538 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
539 {N_("/_Message/_Save"),
540 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
541 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
542 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
544 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
545 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
546 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
547 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
548 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
549 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
550 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
551 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
552 {N_("/_Edit/Special paste/as _quotation"),
553 NULL, compose_paste_as_quote_cb, 0, NULL},
554 {N_("/_Edit/Special paste/_wrapped"),
555 NULL, compose_paste_wrap_cb, 0, NULL},
556 {N_("/_Edit/Special paste/_unwrapped"),
557 NULL, compose_paste_no_wrap_cb, 0, NULL},
558 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
559 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
560 {N_("/_Edit/A_dvanced/Move a character backward"),
562 compose_advanced_action_cb,
563 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
565 {N_("/_Edit/A_dvanced/Move a character forward"),
567 compose_advanced_action_cb,
568 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
570 {N_("/_Edit/A_dvanced/Move a word backward"),
572 compose_advanced_action_cb,
573 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
575 {N_("/_Edit/A_dvanced/Move a word forward"),
577 compose_advanced_action_cb,
578 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
580 {N_("/_Edit/A_dvanced/Move to beginning of line"),
581 NULL, /* "<control>A" */
582 compose_advanced_action_cb,
583 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
585 {N_("/_Edit/A_dvanced/Move to end of line"),
587 compose_advanced_action_cb,
588 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
590 {N_("/_Edit/A_dvanced/Move to previous line"),
592 compose_advanced_action_cb,
593 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
595 {N_("/_Edit/A_dvanced/Move to next line"),
597 compose_advanced_action_cb,
598 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
600 {N_("/_Edit/A_dvanced/Delete a character backward"),
602 compose_advanced_action_cb,
603 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
605 {N_("/_Edit/A_dvanced/Delete a character forward"),
607 compose_advanced_action_cb,
608 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
610 {N_("/_Edit/A_dvanced/Delete a word backward"),
611 NULL, /* "<control>W" */
612 compose_advanced_action_cb,
613 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
615 {N_("/_Edit/A_dvanced/Delete a word forward"),
616 NULL, /* "<alt>D", */
617 compose_advanced_action_cb,
618 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
620 {N_("/_Edit/A_dvanced/Delete line"),
622 compose_advanced_action_cb,
623 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
625 {N_("/_Edit/A_dvanced/Delete entire line"),
627 compose_advanced_action_cb,
628 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
630 {N_("/_Edit/A_dvanced/Delete to end of line"),
632 compose_advanced_action_cb,
633 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
635 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
637 "<control>F", compose_find_cb, 0, NULL},
638 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
639 {N_("/_Edit/_Wrap current paragraph"),
640 "<control>L", compose_wrap_cb, 0, NULL},
641 {N_("/_Edit/Wrap all long _lines"),
642 "<control><alt>L", compose_wrap_cb, 1, NULL},
643 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
644 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Edit/Edit with e_xternal editor"),
646 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
648 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
649 {N_("/_Spelling/_Check all or check selection"),
650 NULL, compose_check_all, 0, NULL},
651 {N_("/_Spelling/_Highlight all misspelled words"),
652 NULL, compose_highlight_all, 0, NULL},
653 {N_("/_Spelling/Check _backwards misspelled word"),
654 NULL, compose_check_backwards , 0, NULL},
655 {N_("/_Spelling/_Forward to next misspelled word"),
656 NULL, compose_check_forwards_go, 0, NULL},
657 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Spelling/Options"),
659 NULL, NULL, 0, "<Branch>"},
661 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
662 {N_("/_Options/Reply _mode"), NULL, NULL, 0, "<Branch>"},
663 {N_("/_Options/Reply _mode/_Normal"), NULL, compose_reply_change_mode, COMPOSE_REPLY, "<RadioItem>"},
664 {N_("/_Options/Reply _mode/_All"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_ALL, "/Options/Reply mode/Normal"},
665 {N_("/_Options/Reply _mode/_Sender"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_SENDER, "/Options/Reply mode/Normal"},
666 {N_("/_Options/Reply _mode/_Mailing-list"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_LIST, "/Options/Reply mode/Normal"},
667 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
668 {N_("/_Options/Privacy _System"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Options/Privacy _System/None"), NULL, NULL, 0, "<RadioItem>"},
670 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
671 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
672 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
673 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
674 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
675 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
676 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
677 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
678 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
679 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
680 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
681 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
682 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
683 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
685 #define ENC_ACTION(action) \
686 NULL, compose_set_encoding_cb, action, \
687 "/Options/Character encoding/Automatic"
689 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
690 {N_("/_Options/Character _encoding/_Automatic"),
691 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
692 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
694 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
695 ENC_ACTION(C_US_ASCII)},
696 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
697 ENC_ACTION(C_UTF_8)},
698 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
700 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
701 ENC_ACTION(C_ISO_8859_1)},
702 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
703 ENC_ACTION(C_ISO_8859_15)},
704 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
705 ENC_ACTION(C_WINDOWS_1252)},
706 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
708 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
709 ENC_ACTION(C_ISO_8859_2)},
710 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
712 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
713 ENC_ACTION(C_ISO_8859_13)},
714 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
715 ENC_ACTION(C_ISO_8859_4)},
716 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
718 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
719 ENC_ACTION(C_ISO_8859_7)},
720 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
722 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
723 ENC_ACTION(C_ISO_8859_8)},
724 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
725 ENC_ACTION(C_WINDOWS_1255)},
726 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
728 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
729 ENC_ACTION(C_ISO_8859_6)},
730 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
731 ENC_ACTION(C_CP1256)},
732 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
735 ENC_ACTION(C_ISO_8859_9)},
736 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
738 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
739 ENC_ACTION(C_ISO_8859_5)},
740 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
741 ENC_ACTION(C_KOI8_R)},
742 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
743 ENC_ACTION(C_KOI8_U)},
744 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
745 ENC_ACTION(C_WINDOWS_1251)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
749 ENC_ACTION(C_ISO_2022_JP)},
750 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
752 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
753 ENC_ACTION(C_GB2312)},
754 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
756 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
758 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
759 ENC_ACTION(C_EUC_TW)},
760 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
762 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
763 ENC_ACTION(C_EUC_KR)},
764 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
766 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
767 ENC_ACTION(C_TIS_620)},
768 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
769 ENC_ACTION(C_WINDOWS_874)},
771 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
772 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
773 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
774 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
775 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
776 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
777 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
780 static GtkTargetEntry compose_mime_types[] =
782 {"text/uri-list", 0, 0},
783 {"UTF8_STRING", 0, 0},
787 static gboolean compose_put_existing_to_front(MsgInfo *info)
789 GList *compose_list = compose_get_compose_list();
793 for (elem = compose_list; elem != NULL && elem->data != NULL;
795 Compose *c = (Compose*)elem->data;
797 if (!c->targetinfo || !c->targetinfo->msgid ||
801 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
802 gtkut_window_popup(c->window);
810 static GdkColor quote_color1 =
811 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
812 static GdkColor quote_color2 =
813 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
814 static GdkColor quote_color3 =
815 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
817 static GdkColor quote_bgcolor1 =
818 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
819 static GdkColor quote_bgcolor2 =
820 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
821 static GdkColor quote_bgcolor3 =
822 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
824 static GdkColor signature_color = {
831 static GdkColor uri_color = {
838 static void compose_create_tags(GtkTextView *text, Compose *compose)
840 GtkTextBuffer *buffer;
841 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
847 buffer = gtk_text_view_get_buffer(text);
849 if (prefs_common.enable_color) {
850 /* grab the quote colors, converting from an int to a GdkColor */
851 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
853 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
855 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
857 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
859 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
861 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
863 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
865 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
868 signature_color = quote_color1 = quote_color2 = quote_color3 =
869 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
872 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
873 gtk_text_buffer_create_tag(buffer, "quote0",
874 "foreground-gdk", "e_color1,
875 "paragraph-background-gdk", "e_bgcolor1,
877 gtk_text_buffer_create_tag(buffer, "quote1",
878 "foreground-gdk", "e_color2,
879 "paragraph-background-gdk", "e_bgcolor2,
881 gtk_text_buffer_create_tag(buffer, "quote2",
882 "foreground-gdk", "e_color3,
883 "paragraph-background-gdk", "e_bgcolor3,
886 gtk_text_buffer_create_tag(buffer, "quote0",
887 "foreground-gdk", "e_color1,
889 gtk_text_buffer_create_tag(buffer, "quote1",
890 "foreground-gdk", "e_color2,
892 gtk_text_buffer_create_tag(buffer, "quote2",
893 "foreground-gdk", "e_color3,
897 gtk_text_buffer_create_tag(buffer, "signature",
898 "foreground-gdk", &signature_color,
900 gtk_text_buffer_create_tag(buffer, "link",
901 "foreground-gdk", &uri_color,
903 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
904 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
906 color[0] = quote_color1;
907 color[1] = quote_color2;
908 color[2] = quote_color3;
909 color[3] = quote_bgcolor1;
910 color[4] = quote_bgcolor2;
911 color[5] = quote_bgcolor3;
912 color[6] = signature_color;
913 color[7] = uri_color;
914 cmap = gdk_drawable_get_colormap(compose->window->window);
915 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
917 for (i = 0; i < 8; i++) {
918 if (success[i] == FALSE) {
921 g_warning("Compose: color allocation failed.\n");
922 style = gtk_widget_get_style(GTK_WIDGET(text));
923 quote_color1 = quote_color2 = quote_color3 =
924 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
925 signature_color = uri_color = black;
930 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
931 GPtrArray *attach_files)
933 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
936 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item, const gchar *mailto)
938 return compose_generic_new(account, mailto, item, NULL, NULL);
941 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
943 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
946 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
947 GPtrArray *attach_files, GList *listAddress )
950 GtkTextView *textview;
951 GtkTextBuffer *textbuf;
953 GtkItemFactory *ifactory;
955 if (item && item->prefs && item->prefs->enable_default_account)
956 account = account_find_from_id(item->prefs->default_account);
958 if (!account) account = cur_account;
959 g_return_val_if_fail(account != NULL, NULL);
961 compose = compose_create(account, COMPOSE_NEW, FALSE);
963 ifactory = gtk_item_factory_from_widget(compose->menubar);
965 compose->replyinfo = NULL;
966 compose->fwdinfo = NULL;
968 textview = GTK_TEXT_VIEW(compose->text);
969 textbuf = gtk_text_view_get_buffer(textview);
970 compose_create_tags(textview, compose);
972 undo_block(compose->undostruct);
974 if (item && item->prefs && item->prefs->enable_default_dictionary &&
976 gtkaspell_change_dict(compose->gtkaspell,
977 item->prefs->default_dictionary);
978 compose_spell_menu_changed(compose);
981 if (account->auto_sig)
982 compose_insert_sig(compose, FALSE);
983 gtk_text_buffer_get_start_iter(textbuf, &iter);
984 gtk_text_buffer_place_cursor(textbuf, &iter);
986 if (account->protocol != A_NNTP) {
987 if (mailto && *mailto != '\0') {
988 compose_entries_set(compose, mailto);
990 } else if (item && item->prefs->enable_default_to) {
991 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
992 compose_entry_mark_default_to(compose, item->prefs->default_to);
994 if (item && item->ret_rcpt) {
995 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
999 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
1000 } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
1001 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
1004 * CLAWS: just don't allow return receipt request, even if the user
1005 * may want to send an email. simple but foolproof.
1007 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1009 compose_add_field_list( compose, listAddress );
1011 if (prefs_common.compose_with_format) {
1012 MsgInfo* dummyinfo = NULL;
1014 if ( prefs_common.compose_subject_format
1015 && *prefs_common.compose_subject_format != '\0' )
1017 gchar *subject = NULL;
1021 dummyinfo = compose_msginfo_new_from_compose(compose);
1023 /* decode \-escape sequences in the internal representation of the quote format */
1024 tmp = malloc(strlen(prefs_common.compose_subject_format)+1);
1025 pref_get_unescaped_pref(tmp, prefs_common.compose_subject_format);
1027 subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
1028 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account);
1029 quote_fmt_scan_string(tmp);
1032 buf = quote_fmt_get_buffer();
1034 alertpanel_error(_("New message subject format error."));
1036 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
1037 quote_fmt_reset_vartable();
1043 if ( prefs_common.compose_body_format
1044 && *prefs_common.compose_body_format != '\0' )
1047 GtkTextBuffer *buffer;
1048 GtkTextIter start, end;
1051 if ( dummyinfo == NULL )
1052 dummyinfo = compose_msginfo_new_from_compose(compose);
1054 text = GTK_TEXT_VIEW(compose->text);
1055 buffer = gtk_text_view_get_buffer(text);
1056 gtk_text_buffer_get_start_iter(buffer, &start);
1057 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
1058 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
1060 compose_quote_fmt(compose, dummyinfo,
1061 prefs_common.compose_body_format,
1063 _("New message body format error."));
1064 quote_fmt_reset_vartable();
1069 procmsg_msginfo_free( dummyinfo );
1076 for (i = 0; i < attach_files->len; i++) {
1077 file = g_ptr_array_index(attach_files, i);
1078 compose_attach_append(compose, file, file, NULL);
1082 compose_show_first_last_header(compose, TRUE);
1084 /* Set save folder */
1085 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1086 gchar *folderidentifier;
1088 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1089 folderidentifier = folder_item_get_identifier(item);
1090 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1091 g_free(folderidentifier);
1094 gtk_widget_grab_focus(compose->header_last->entry);
1096 undo_unblock(compose->undostruct);
1098 if (prefs_common.auto_exteditor)
1099 compose_exec_ext_editor(compose);
1101 compose->modified = FALSE;
1102 compose_set_title(compose);
1106 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1107 gboolean override_pref)
1109 gchar *privacy = NULL;
1111 g_return_if_fail(compose != NULL);
1112 g_return_if_fail(account != NULL);
1114 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1117 if (account->default_privacy_system
1118 && strlen(account->default_privacy_system)) {
1119 privacy = account->default_privacy_system;
1121 GSList *privacy_avail = privacy_get_system_ids();
1122 if (privacy_avail && g_slist_length(privacy_avail)) {
1123 privacy = (gchar *)(privacy_avail->data);
1126 if (privacy != NULL) {
1127 compose->privacy_system = g_strdup(privacy);
1128 compose_update_privacy_system_menu_item(compose, FALSE);
1129 compose_use_encryption(compose, TRUE);
1133 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1135 gchar *privacy = NULL;
1137 if (account->default_privacy_system
1138 && strlen(account->default_privacy_system)) {
1139 privacy = account->default_privacy_system;
1141 GSList *privacy_avail = privacy_get_system_ids();
1142 if (privacy_avail && g_slist_length(privacy_avail)) {
1143 privacy = (gchar *)(privacy_avail->data);
1146 if (privacy != NULL) {
1147 compose->privacy_system = g_strdup(privacy);
1148 compose_update_privacy_system_menu_item(compose, FALSE);
1149 compose_use_signing(compose, TRUE);
1153 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1157 Compose *compose = NULL;
1158 GtkItemFactory *ifactory = NULL;
1160 g_return_val_if_fail(msginfo_list != NULL, NULL);
1162 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1163 g_return_val_if_fail(msginfo != NULL, NULL);
1165 list_len = g_slist_length(msginfo_list);
1169 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1170 FALSE, prefs_common.default_reply_list, FALSE, body);
1172 case COMPOSE_REPLY_WITH_QUOTE:
1173 compose = compose_reply(msginfo, TRUE,
1174 FALSE, prefs_common.default_reply_list, FALSE, body);
1176 case COMPOSE_REPLY_WITHOUT_QUOTE:
1177 compose = compose_reply(msginfo, FALSE,
1178 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1180 case COMPOSE_REPLY_TO_SENDER:
1181 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1182 FALSE, FALSE, TRUE, body);
1184 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1185 compose = compose_followup_and_reply_to(msginfo,
1186 prefs_common.reply_with_quote,
1187 FALSE, FALSE, body);
1189 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1190 compose = compose_reply(msginfo, TRUE,
1191 FALSE, FALSE, TRUE, body);
1193 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1194 compose = compose_reply(msginfo, FALSE,
1195 FALSE, FALSE, TRUE, NULL);
1197 case COMPOSE_REPLY_TO_ALL:
1198 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1199 TRUE, FALSE, FALSE, body);
1201 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1202 compose = compose_reply(msginfo, TRUE,
1203 TRUE, FALSE, FALSE, body);
1205 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1206 compose = compose_reply(msginfo, FALSE,
1207 TRUE, FALSE, FALSE, NULL);
1209 case COMPOSE_REPLY_TO_LIST:
1210 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1211 FALSE, TRUE, FALSE, body);
1213 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1214 compose = compose_reply(msginfo, TRUE,
1215 FALSE, TRUE, FALSE, body);
1217 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1218 compose = compose_reply(msginfo, FALSE,
1219 FALSE, TRUE, FALSE, NULL);
1221 case COMPOSE_FORWARD:
1222 if (prefs_common.forward_as_attachment) {
1223 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1226 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1230 case COMPOSE_FORWARD_INLINE:
1231 /* check if we reply to more than one Message */
1232 if (list_len == 1) {
1233 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1236 /* more messages FALL THROUGH */
1237 case COMPOSE_FORWARD_AS_ATTACH:
1238 compose = compose_forward_multiple(NULL, msginfo_list);
1240 case COMPOSE_REDIRECT:
1241 compose = compose_redirect(NULL, msginfo, FALSE);
1244 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1247 ifactory = gtk_item_factory_from_widget(compose->menubar);
1249 compose->rmode = mode;
1250 switch (compose->rmode) {
1252 case COMPOSE_REPLY_WITH_QUOTE:
1253 case COMPOSE_REPLY_WITHOUT_QUOTE:
1254 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1255 debug_print("reply mode Normal\n");
1256 menu_set_active(ifactory, "/Options/Reply mode/Normal", TRUE);
1257 compose_reply_change_mode(compose, COMPOSE_REPLY, NULL); /* force update */
1259 case COMPOSE_REPLY_TO_SENDER:
1260 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1261 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1262 debug_print("reply mode Sender\n");
1263 menu_set_active(ifactory, "/Options/Reply mode/Sender", TRUE);
1265 case COMPOSE_REPLY_TO_ALL:
1266 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1267 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1268 debug_print("reply mode All\n");
1269 menu_set_active(ifactory, "/Options/Reply mode/All", TRUE);
1271 case COMPOSE_REPLY_TO_LIST:
1272 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1273 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1274 debug_print("reply mode List\n");
1275 menu_set_active(ifactory, "/Options/Reply mode/Mailing-list", TRUE);
1283 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1284 gboolean to_ml, gboolean to_sender,
1287 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1288 to_sender, FALSE, body);
1291 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1296 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1297 to_sender, TRUE, body);
1300 static void compose_extract_original_charset(Compose *compose)
1302 MsgInfo *info = NULL;
1303 if (compose->replyinfo) {
1304 info = compose->replyinfo;
1305 } else if (compose->fwdinfo) {
1306 info = compose->fwdinfo;
1307 } else if (compose->targetinfo) {
1308 info = compose->targetinfo;
1311 MimeInfo *mimeinfo = procmime_scan_message(info);
1312 MimeInfo *partinfo = mimeinfo;
1313 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1314 partinfo = procmime_mimeinfo_next(partinfo);
1316 compose->orig_charset =
1317 g_strdup(procmime_mimeinfo_get_parameter(
1318 partinfo, "charset"));
1320 procmime_mimeinfo_free_all(mimeinfo);
1324 #define SIGNAL_BLOCK(buffer) { \
1325 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1326 G_CALLBACK(compose_changed_cb), \
1328 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1329 G_CALLBACK(text_inserted), \
1333 #define SIGNAL_UNBLOCK(buffer) { \
1334 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1335 G_CALLBACK(compose_changed_cb), \
1337 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1338 G_CALLBACK(text_inserted), \
1342 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1343 gboolean to_all, gboolean to_ml,
1345 gboolean followup_and_reply_to,
1348 GtkItemFactory *ifactory;
1350 PrefsAccount *account = NULL;
1351 PrefsAccount *reply_account;
1352 GtkTextView *textview;
1353 GtkTextBuffer *textbuf;
1355 g_return_val_if_fail(msginfo != NULL, NULL);
1356 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1358 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1360 g_return_val_if_fail(account != NULL, NULL);
1362 if (to_sender && account->protocol == A_NNTP &&
1363 !followup_and_reply_to) {
1365 account_find_from_address(account->address);
1367 reply_account = compose_current_mail_account();
1371 reply_account = account;
1373 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1375 compose->updating = TRUE;
1377 ifactory = gtk_item_factory_from_widget(compose->menubar);
1379 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1380 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1382 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1383 if (!compose->replyinfo)
1384 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1386 compose_extract_original_charset(compose);
1388 if (msginfo->folder && msginfo->folder->ret_rcpt)
1389 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1391 /* Set save folder */
1392 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1393 gchar *folderidentifier;
1395 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1396 folderidentifier = folder_item_get_identifier(msginfo->folder);
1397 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1398 g_free(folderidentifier);
1401 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1403 textview = (GTK_TEXT_VIEW(compose->text));
1404 textbuf = gtk_text_view_get_buffer(textview);
1405 compose_create_tags(textview, compose);
1407 undo_block(compose->undostruct);
1409 if (msginfo->folder && msginfo->folder->prefs &&
1410 msginfo->folder->prefs &&
1411 msginfo->folder->prefs->enable_default_dictionary &&
1413 gtkaspell_change_dict(compose->gtkaspell,
1414 msginfo->folder->prefs->default_dictionary);
1420 if (prefs_common.quotemark && *prefs_common.quotemark)
1421 qmark = prefs_common.quotemark;
1425 compose_quote_fmt(compose, compose->replyinfo,
1426 prefs_common.quotefmt,
1428 _("Message reply format error."));
1429 quote_fmt_reset_vartable();
1431 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1432 compose_force_encryption(compose, account, FALSE);
1435 SIGNAL_BLOCK(textbuf);
1437 if (account->auto_sig)
1438 compose_insert_sig(compose, FALSE);
1440 compose_wrap_all(compose);
1442 SIGNAL_UNBLOCK(textbuf);
1444 gtk_widget_grab_focus(compose->text);
1446 undo_unblock(compose->undostruct);
1448 if (prefs_common.auto_exteditor)
1449 compose_exec_ext_editor(compose);
1451 compose->modified = FALSE;
1452 compose_set_title(compose);
1454 compose->updating = FALSE;
1456 if (compose->deferred_destroy) {
1457 compose_destroy(compose);
1464 #define INSERT_FW_HEADER(var, hdr) \
1465 if (msginfo->var && *msginfo->var) { \
1466 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1467 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1468 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1471 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1472 gboolean as_attach, const gchar *body,
1473 gboolean no_extedit,
1477 GtkTextView *textview;
1478 GtkTextBuffer *textbuf;
1481 g_return_val_if_fail(msginfo != NULL, NULL);
1482 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1485 !(account = compose_guess_forward_account_from_msginfo
1487 account = cur_account;
1489 compose = compose_create(account, COMPOSE_FORWARD, batch);
1491 compose->updating = TRUE;
1492 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1493 if (!compose->fwdinfo)
1494 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1496 compose_extract_original_charset(compose);
1498 if (msginfo->subject && *msginfo->subject) {
1499 gchar *buf, *buf2, *p;
1501 buf = p = g_strdup(msginfo->subject);
1502 p += subject_get_prefix_length(p);
1503 memmove(buf, p, strlen(p) + 1);
1505 buf2 = g_strdup_printf("Fw: %s", buf);
1506 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1512 textview = GTK_TEXT_VIEW(compose->text);
1513 textbuf = gtk_text_view_get_buffer(textview);
1514 compose_create_tags(textview, compose);
1516 undo_block(compose->undostruct);
1520 msgfile = procmsg_get_message_file_path(msginfo);
1521 if (!is_file_exist(msgfile))
1522 g_warning("%s: file not exist\n", msgfile);
1524 compose_attach_append(compose, msgfile, msgfile,
1530 MsgInfo *full_msginfo;
1532 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1534 full_msginfo = procmsg_msginfo_copy(msginfo);
1536 if (prefs_common.fw_quotemark &&
1537 *prefs_common.fw_quotemark)
1538 qmark = prefs_common.fw_quotemark;
1542 compose_quote_fmt(compose, full_msginfo,
1543 prefs_common.fw_quotefmt,
1545 _("Message forward format error."));
1546 quote_fmt_reset_vartable();
1547 compose_attach_parts(compose, msginfo);
1549 procmsg_msginfo_free(full_msginfo);
1552 SIGNAL_BLOCK(textbuf);
1554 if (account->auto_sig)
1555 compose_insert_sig(compose, FALSE);
1557 compose_wrap_all(compose);
1559 SIGNAL_UNBLOCK(textbuf);
1561 gtk_text_buffer_get_start_iter(textbuf, &iter);
1562 gtk_text_buffer_place_cursor(textbuf, &iter);
1564 gtk_widget_grab_focus(compose->header_last->entry);
1566 if (!no_extedit && prefs_common.auto_exteditor)
1567 compose_exec_ext_editor(compose);
1570 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1571 gchar *folderidentifier;
1573 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1574 folderidentifier = folder_item_get_identifier(msginfo->folder);
1575 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1576 g_free(folderidentifier);
1579 undo_unblock(compose->undostruct);
1581 compose->modified = FALSE;
1582 compose_set_title(compose);
1584 compose->updating = FALSE;
1586 if (compose->deferred_destroy) {
1587 compose_destroy(compose);
1594 #undef INSERT_FW_HEADER
1596 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1599 GtkTextView *textview;
1600 GtkTextBuffer *textbuf;
1604 gboolean single_mail = TRUE;
1606 g_return_val_if_fail(msginfo_list != NULL, NULL);
1608 if (g_slist_length(msginfo_list) > 1)
1609 single_mail = FALSE;
1611 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1612 if (((MsgInfo *)msginfo->data)->folder == NULL)
1615 /* guess account from first selected message */
1617 !(account = compose_guess_forward_account_from_msginfo
1618 (msginfo_list->data)))
1619 account = cur_account;
1621 g_return_val_if_fail(account != NULL, NULL);
1623 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1624 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1625 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1628 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1630 compose->updating = TRUE;
1632 textview = GTK_TEXT_VIEW(compose->text);
1633 textbuf = gtk_text_view_get_buffer(textview);
1634 compose_create_tags(textview, compose);
1636 undo_block(compose->undostruct);
1637 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1638 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1640 if (!is_file_exist(msgfile))
1641 g_warning("%s: file not exist\n", msgfile);
1643 compose_attach_append(compose, msgfile, msgfile,
1649 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1650 if (info->subject && *info->subject) {
1651 gchar *buf, *buf2, *p;
1653 buf = p = g_strdup(info->subject);
1654 p += subject_get_prefix_length(p);
1655 memmove(buf, p, strlen(p) + 1);
1657 buf2 = g_strdup_printf("Fw: %s", buf);
1658 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1664 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1665 _("Fw: multiple emails"));
1668 SIGNAL_BLOCK(textbuf);
1670 if (account->auto_sig)
1671 compose_insert_sig(compose, FALSE);
1673 compose_wrap_all(compose);
1675 SIGNAL_UNBLOCK(textbuf);
1677 gtk_text_buffer_get_start_iter(textbuf, &iter);
1678 gtk_text_buffer_place_cursor(textbuf, &iter);
1680 gtk_widget_grab_focus(compose->header_last->entry);
1681 undo_unblock(compose->undostruct);
1682 compose->modified = FALSE;
1683 compose_set_title(compose);
1685 compose->updating = FALSE;
1687 if (compose->deferred_destroy) {
1688 compose_destroy(compose);
1695 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1697 GtkTextIter start = *iter;
1698 GtkTextIter end_iter;
1699 int start_pos = gtk_text_iter_get_offset(&start);
1701 if (!compose->account->sig_sep)
1704 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1705 start_pos+strlen(compose->account->sig_sep));
1707 /* check sig separator */
1708 str = gtk_text_iter_get_text(&start, &end_iter);
1709 if (!strcmp(str, compose->account->sig_sep)) {
1711 /* check end of line (\n) */
1712 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1713 start_pos+strlen(compose->account->sig_sep));
1714 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1715 start_pos+strlen(compose->account->sig_sep)+1);
1716 tmp = gtk_text_iter_get_text(&start, &end_iter);
1717 if (!strcmp(tmp,"\n")) {
1729 static void compose_colorize_signature(Compose *compose)
1731 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1733 GtkTextIter end_iter;
1734 gtk_text_buffer_get_start_iter(buffer, &iter);
1735 while (gtk_text_iter_forward_line(&iter))
1736 if (compose_is_sig_separator(compose, buffer, &iter)) {
1737 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1738 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1742 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1744 Compose *compose = NULL;
1745 PrefsAccount *account = NULL;
1746 GtkTextView *textview;
1747 GtkTextBuffer *textbuf;
1751 gchar buf[BUFFSIZE];
1752 gboolean use_signing = FALSE;
1753 gboolean use_encryption = FALSE;
1754 gchar *privacy_system = NULL;
1755 int priority = PRIORITY_NORMAL;
1756 MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
1758 g_return_val_if_fail(msginfo != NULL, NULL);
1759 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1761 if (compose_put_existing_to_front(msginfo)) {
1765 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1766 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1767 gchar queueheader_buf[BUFFSIZE];
1770 /* Select Account from queue headers */
1771 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1772 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1773 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1774 account = account_find_from_id(id);
1776 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1777 sizeof(queueheader_buf), "NAID:")) {
1778 id = atoi(&queueheader_buf[strlen("NAID:")]);
1779 account = account_find_from_id(id);
1781 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1782 sizeof(queueheader_buf), "MAID:")) {
1783 id = atoi(&queueheader_buf[strlen("MAID:")]);
1784 account = account_find_from_id(id);
1786 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1787 sizeof(queueheader_buf), "S:")) {
1788 account = account_find_from_address(queueheader_buf);
1790 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1791 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1792 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1793 use_signing = param;
1796 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1797 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1798 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1799 use_encryption = param;
1801 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1802 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1803 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1805 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1806 sizeof(queueheader_buf), "X-Priority: ")) {
1807 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1810 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1811 sizeof(queueheader_buf), "RMID:")) {
1812 gchar **tokens = g_strsplit(&queueheader_buf[strlen("RMID:")], "\t", 0);
1813 if (tokens[0] && tokens[1] && tokens[2]) {
1814 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1815 if (orig_item != NULL) {
1816 replyinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1821 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1822 sizeof(queueheader_buf), "FMID:")) {
1823 gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0);
1824 if (tokens[0] && tokens[1] && tokens[2]) {
1825 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1826 if (orig_item != NULL) {
1827 fwdinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1833 account = msginfo->folder->folder->account;
1836 if (!account && prefs_common.reedit_account_autosel) {
1837 gchar from[BUFFSIZE];
1838 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1839 extract_address(from);
1840 account = account_find_from_address(from);
1844 account = cur_account;
1846 g_return_val_if_fail(account != NULL, NULL);
1848 compose = compose_create(account, COMPOSE_REEDIT, batch);
1850 compose->replyinfo = replyinfo;
1851 compose->fwdinfo = fwdinfo;
1853 compose->updating = TRUE;
1854 compose->priority = priority;
1856 if (privacy_system != NULL) {
1857 compose->privacy_system = privacy_system;
1858 compose_use_signing(compose, use_signing);
1859 compose_use_encryption(compose, use_encryption);
1860 compose_update_privacy_system_menu_item(compose, FALSE);
1862 activate_privacy_system(compose, account, FALSE);
1865 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1867 compose_extract_original_charset(compose);
1869 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1870 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1871 gchar queueheader_buf[BUFFSIZE];
1873 /* Set message save folder */
1874 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1877 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1878 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1879 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1881 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1882 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1884 GtkItemFactory *ifactory;
1885 ifactory = gtk_item_factory_from_widget(compose->menubar);
1886 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1891 if (compose_parse_header(compose, msginfo) < 0) {
1892 compose->updating = FALSE;
1893 compose_destroy(compose);
1896 compose_reedit_set_entry(compose, msginfo);
1898 textview = GTK_TEXT_VIEW(compose->text);
1899 textbuf = gtk_text_view_get_buffer(textview);
1900 compose_create_tags(textview, compose);
1902 mark = gtk_text_buffer_get_insert(textbuf);
1903 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1905 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1906 G_CALLBACK(compose_changed_cb),
1909 if (procmime_msginfo_is_encrypted(msginfo)) {
1910 fp = procmime_get_first_encrypted_text_content(msginfo);
1912 compose_force_encryption(compose, account, TRUE);
1915 fp = procmime_get_first_text_content(msginfo);
1918 g_warning("Can't get text part\n");
1922 gboolean prev_autowrap = compose->autowrap;
1924 compose->autowrap = FALSE;
1925 while (fgets(buf, sizeof(buf), fp) != NULL) {
1927 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1929 compose_wrap_all_full(compose, FALSE);
1930 compose->autowrap = prev_autowrap;
1934 compose_attach_parts(compose, msginfo);
1936 compose_colorize_signature(compose);
1938 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1939 G_CALLBACK(compose_changed_cb),
1942 gtk_widget_grab_focus(compose->text);
1944 if (prefs_common.auto_exteditor) {
1945 compose_exec_ext_editor(compose);
1947 compose->modified = FALSE;
1948 compose_set_title(compose);
1950 compose->updating = FALSE;
1952 if (compose->deferred_destroy) {
1953 compose_destroy(compose);
1957 compose->sig_str = compose_get_signature_str(compose);
1962 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1967 GtkItemFactory *ifactory;
1970 g_return_val_if_fail(msginfo != NULL, NULL);
1973 account = account_get_reply_account(msginfo,
1974 prefs_common.reply_account_autosel);
1975 g_return_val_if_fail(account != NULL, NULL);
1977 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1979 compose->updating = TRUE;
1981 ifactory = gtk_item_factory_from_widget(compose->menubar);
1982 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1983 compose->replyinfo = NULL;
1984 compose->fwdinfo = NULL;
1986 compose_show_first_last_header(compose, TRUE);
1988 gtk_widget_grab_focus(compose->header_last->entry);
1990 filename = procmsg_get_message_file_path(msginfo);
1992 if (filename == NULL) {
1993 compose->updating = FALSE;
1994 compose_destroy(compose);
1999 compose->redirect_filename = filename;
2001 /* Set save folder */
2002 item = msginfo->folder;
2003 if (item && item->prefs && item->prefs->save_copy_to_folder) {
2004 gchar *folderidentifier;
2006 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
2007 folderidentifier = folder_item_get_identifier(item);
2008 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
2009 g_free(folderidentifier);
2012 compose_attach_parts(compose, msginfo);
2014 if (msginfo->subject)
2015 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
2017 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
2019 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE,
2020 _("Message redirect format error."));
2021 quote_fmt_reset_vartable();
2022 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
2024 compose_colorize_signature(compose);
2026 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
2027 menu_set_sensitive(ifactory, "/Add...", FALSE);
2028 menu_set_sensitive(ifactory, "/Remove", FALSE);
2029 menu_set_sensitive(ifactory, "/Properties...", FALSE);
2031 ifactory = gtk_item_factory_from_widget(compose->menubar);
2032 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
2033 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
2034 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
2035 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
2036 menu_set_sensitive(ifactory, "/Edit", FALSE);
2037 menu_set_sensitive(ifactory, "/Options", FALSE);
2038 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
2039 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
2041 if (compose->toolbar->draft_btn)
2042 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
2043 if (compose->toolbar->insert_btn)
2044 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
2045 if (compose->toolbar->attach_btn)
2046 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
2047 if (compose->toolbar->sig_btn)
2048 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
2049 if (compose->toolbar->exteditor_btn)
2050 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
2051 if (compose->toolbar->linewrap_current_btn)
2052 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
2053 if (compose->toolbar->linewrap_all_btn)
2054 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
2056 compose->modified = FALSE;
2057 compose_set_title(compose);
2058 compose->updating = FALSE;
2060 if (compose->deferred_destroy) {
2061 compose_destroy(compose);
2068 GList *compose_get_compose_list(void)
2070 return compose_list;
2073 void compose_entry_append(Compose *compose, const gchar *address,
2074 ComposeEntryType type)
2078 gboolean in_quote = FALSE;
2079 if (!address || *address == '\0') return;
2086 header = N_("Bcc:");
2088 case COMPOSE_REPLYTO:
2089 header = N_("Reply-To:");
2091 case COMPOSE_NEWSGROUPS:
2092 header = N_("Newsgroups:");
2094 case COMPOSE_FOLLOWUPTO:
2095 header = N_( "Followup-To:");
2102 header = prefs_common.trans_hdr ? gettext(header) : header;
2104 cur = begin = (gchar *)address;
2106 /* we separate the line by commas, but not if we're inside a quoted
2108 while (*cur != '\0') {
2110 in_quote = !in_quote;
2111 if (*cur == ',' && !in_quote) {
2112 gchar *tmp = g_strdup(begin);
2114 tmp[cur-begin]='\0';
2117 while (*tmp == ' ' || *tmp == '\t')
2119 compose_add_header_entry(compose, header, tmp);
2126 gchar *tmp = g_strdup(begin);
2128 tmp[cur-begin]='\0';
2131 while (*tmp == ' ' || *tmp == '\t')
2133 compose_add_header_entry(compose, header, tmp);
2138 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
2140 static GdkColor yellow;
2141 static GdkColor black;
2142 static gboolean yellow_initialised = FALSE;
2146 if (!yellow_initialised) {
2147 gdk_color_parse("#f5f6be", &yellow);
2148 gdk_color_parse("#000000", &black);
2149 yellow_initialised = gdk_colormap_alloc_color(
2150 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2151 yellow_initialised &= gdk_colormap_alloc_color(
2152 gdk_colormap_get_system(), &black, FALSE, TRUE);
2155 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2156 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2157 if (gtk_entry_get_text(entry) &&
2158 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2159 if (yellow_initialised) {
2160 gtk_widget_modify_base(
2161 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2162 GTK_STATE_NORMAL, &yellow);
2163 gtk_widget_modify_text(
2164 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2165 GTK_STATE_NORMAL, &black);
2171 void compose_toolbar_cb(gint action, gpointer data)
2173 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2174 Compose *compose = (Compose*)toolbar_item->parent;
2176 g_return_if_fail(compose != NULL);
2180 compose_send_cb(compose, 0, NULL);
2183 compose_send_later_cb(compose, 0, NULL);
2186 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2189 compose_insert_file_cb(compose, 0, NULL);
2192 compose_attach_cb(compose, 0, NULL);
2195 compose_insert_sig(compose, FALSE);
2198 compose_ext_editor_cb(compose, 0, NULL);
2200 case A_LINEWRAP_CURRENT:
2201 compose_beautify_paragraph(compose, NULL, TRUE);
2203 case A_LINEWRAP_ALL:
2204 compose_wrap_all_full(compose, TRUE);
2207 compose_address_cb(compose, 0, NULL);
2210 case A_CHECK_SPELLING:
2211 compose_check_all(compose);
2219 static void compose_entries_set(Compose *compose, const gchar *mailto)
2223 gchar *subject = NULL;
2227 gchar *attach = NULL;
2229 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body, &attach);
2232 compose_entry_append(compose, to, COMPOSE_TO);
2234 compose_entry_append(compose, cc, COMPOSE_CC);
2236 if (!g_utf8_validate (subject, -1, NULL)) {
2237 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2238 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2241 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2245 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2246 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2249 gboolean prev_autowrap = compose->autowrap;
2251 compose->autowrap = FALSE;
2253 mark = gtk_text_buffer_get_insert(buffer);
2254 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2256 if (!g_utf8_validate (body, -1, NULL)) {
2257 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2258 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2261 gtk_text_buffer_insert(buffer, &iter, body, -1);
2263 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2265 compose->autowrap = prev_autowrap;
2266 if (compose->autowrap)
2267 compose_wrap_all(compose);
2271 gchar *utf8_filename = conv_filename_to_utf8(attach);
2272 if (utf8_filename) {
2273 if (compose_attach_append(compose, attach, utf8_filename, NULL)) {
2274 alertpanel_notice(_("The file '%s' has been attached."), attach);
2276 g_free(utf8_filename);
2278 alertpanel_error(_("Couldn't attach a file (charset conversion failed)."));
2288 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2290 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2291 {"Cc:", NULL, TRUE},
2292 {"References:", NULL, FALSE},
2293 {"Bcc:", NULL, TRUE},
2294 {"Newsgroups:", NULL, TRUE},
2295 {"Followup-To:", NULL, TRUE},
2296 {"List-Post:", NULL, FALSE},
2297 {"X-Priority:", NULL, FALSE},
2298 {NULL, NULL, FALSE}};
2314 g_return_val_if_fail(msginfo != NULL, -1);
2316 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2317 procheader_get_header_fields(fp, hentry);
2320 if (hentry[H_REPLY_TO].body != NULL) {
2321 if (hentry[H_REPLY_TO].body[0] != '\0') {
2323 conv_unmime_header(hentry[H_REPLY_TO].body,
2326 g_free(hentry[H_REPLY_TO].body);
2327 hentry[H_REPLY_TO].body = NULL;
2329 if (hentry[H_CC].body != NULL) {
2330 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2331 g_free(hentry[H_CC].body);
2332 hentry[H_CC].body = NULL;
2334 if (hentry[H_REFERENCES].body != NULL) {
2335 if (compose->mode == COMPOSE_REEDIT)
2336 compose->references = hentry[H_REFERENCES].body;
2338 compose->references = compose_parse_references
2339 (hentry[H_REFERENCES].body, msginfo->msgid);
2340 g_free(hentry[H_REFERENCES].body);
2342 hentry[H_REFERENCES].body = NULL;
2344 if (hentry[H_BCC].body != NULL) {
2345 if (compose->mode == COMPOSE_REEDIT)
2347 conv_unmime_header(hentry[H_BCC].body, NULL);
2348 g_free(hentry[H_BCC].body);
2349 hentry[H_BCC].body = NULL;
2351 if (hentry[H_NEWSGROUPS].body != NULL) {
2352 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2353 hentry[H_NEWSGROUPS].body = NULL;
2355 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2356 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2357 compose->followup_to =
2358 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2361 g_free(hentry[H_FOLLOWUP_TO].body);
2362 hentry[H_FOLLOWUP_TO].body = NULL;
2364 if (hentry[H_LIST_POST].body != NULL) {
2367 extract_address(hentry[H_LIST_POST].body);
2368 if (hentry[H_LIST_POST].body[0] != '\0') {
2369 scan_mailto_url(hentry[H_LIST_POST].body,
2370 &to, NULL, NULL, NULL, NULL, NULL);
2372 g_free(compose->ml_post);
2373 compose->ml_post = to;
2376 g_free(hentry[H_LIST_POST].body);
2377 hentry[H_LIST_POST].body = NULL;
2380 /* CLAWS - X-Priority */
2381 if (compose->mode == COMPOSE_REEDIT)
2382 if (hentry[H_X_PRIORITY].body != NULL) {
2385 priority = atoi(hentry[H_X_PRIORITY].body);
2386 g_free(hentry[H_X_PRIORITY].body);
2388 hentry[H_X_PRIORITY].body = NULL;
2390 if (priority < PRIORITY_HIGHEST ||
2391 priority > PRIORITY_LOWEST)
2392 priority = PRIORITY_NORMAL;
2394 compose->priority = priority;
2397 if (compose->mode == COMPOSE_REEDIT) {
2398 if (msginfo->inreplyto && *msginfo->inreplyto)
2399 compose->inreplyto = g_strdup(msginfo->inreplyto);
2403 if (msginfo->msgid && *msginfo->msgid)
2404 compose->inreplyto = g_strdup(msginfo->msgid);
2406 if (!compose->references) {
2407 if (msginfo->msgid && *msginfo->msgid) {
2408 if (msginfo->inreplyto && *msginfo->inreplyto)
2409 compose->references =
2410 g_strdup_printf("<%s>\n\t<%s>",
2414 compose->references =
2415 g_strconcat("<", msginfo->msgid, ">",
2417 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2418 compose->references =
2419 g_strconcat("<", msginfo->inreplyto, ">",
2427 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2429 GSList *ref_id_list, *cur;
2433 ref_id_list = references_list_append(NULL, ref);
2434 if (!ref_id_list) return NULL;
2435 if (msgid && *msgid)
2436 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2441 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2442 /* "<" + Message-ID + ">" + CR+LF+TAB */
2443 len += strlen((gchar *)cur->data) + 5;
2445 if (len > MAX_REFERENCES_LEN) {
2446 /* remove second message-ID */
2447 if (ref_id_list && ref_id_list->next &&
2448 ref_id_list->next->next) {
2449 g_free(ref_id_list->next->data);
2450 ref_id_list = g_slist_remove
2451 (ref_id_list, ref_id_list->next->data);
2453 slist_free_strings(ref_id_list);
2454 g_slist_free(ref_id_list);
2461 new_ref = g_string_new("");
2462 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2463 if (new_ref->len > 0)
2464 g_string_append(new_ref, "\n\t");
2465 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2468 slist_free_strings(ref_id_list);
2469 g_slist_free(ref_id_list);
2471 new_ref_str = new_ref->str;
2472 g_string_free(new_ref, FALSE);
2477 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2478 const gchar *fmt, const gchar *qmark,
2479 const gchar *body, gboolean rewrap,
2480 const gchar *err_msg)
2482 MsgInfo* dummyinfo = NULL;
2483 gchar *quote_str = NULL;
2485 gboolean prev_autowrap;
2486 const gchar *trimmed_body = body;
2487 gint cursor_pos = -1;
2488 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2489 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2494 SIGNAL_BLOCK(buffer);
2497 dummyinfo = compose_msginfo_new_from_compose(compose);
2498 msginfo = dummyinfo;
2501 if (qmark != NULL) {
2502 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
2503 quote_fmt_scan_string(qmark);
2506 buf = quote_fmt_get_buffer();
2508 alertpanel_error(_("Quote mark format error."));
2510 Xstrdup_a(quote_str, buf, goto error)
2513 if (fmt && *fmt != '\0') {
2517 while (*trimmed_body == '\n')
2520 /* decode \-escape sequences in the internal representation of the quote format */
2521 tmp = malloc(strlen(fmt)+1);
2522 pref_get_unescaped_pref(tmp, fmt);
2524 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account);
2525 quote_fmt_scan_string(tmp);
2529 buf = quote_fmt_get_buffer();
2531 alertpanel_error(err_msg);
2537 prev_autowrap = compose->autowrap;
2538 compose->autowrap = FALSE;
2540 mark = gtk_text_buffer_get_insert(buffer);
2541 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2542 if (g_utf8_validate(buf, -1, NULL)) {
2543 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2545 gchar *tmpout = NULL;
2546 tmpout = conv_codeset_strdup
2547 (buf, conv_get_locale_charset_str_no_utf8(),
2549 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2551 tmpout = g_malloc(strlen(buf)*2+1);
2552 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2554 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2558 cursor_pos = quote_fmt_get_cursor_pos();
2559 compose->set_cursor_pos = cursor_pos;
2560 if (cursor_pos == -1) {
2563 gtk_text_buffer_get_start_iter(buffer, &iter);
2564 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2565 gtk_text_buffer_place_cursor(buffer, &iter);
2567 compose->autowrap = prev_autowrap;
2568 if (compose->autowrap && rewrap)
2569 compose_wrap_all(compose);
2576 SIGNAL_UNBLOCK(buffer);
2578 procmsg_msginfo_free( dummyinfo );
2583 /* if ml_post is of type addr@host and from is of type
2584 * addr-anything@host, return TRUE
2586 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2588 gchar *left_ml = NULL;
2589 gchar *right_ml = NULL;
2590 gchar *left_from = NULL;
2591 gchar *right_from = NULL;
2592 gboolean result = FALSE;
2594 if (!ml_post || !from)
2597 left_ml = g_strdup(ml_post);
2598 if (strstr(left_ml, "@")) {
2599 right_ml = strstr(left_ml, "@")+1;
2600 *(strstr(left_ml, "@")) = '\0';
2603 left_from = g_strdup(from);
2604 if (strstr(left_from, "@")) {
2605 right_from = strstr(left_from, "@")+1;
2606 *(strstr(left_from, "@")) = '\0';
2609 if (left_ml && left_from && right_ml && right_from
2610 && !strncmp(left_from, left_ml, strlen(left_ml))
2611 && !strcmp(right_from, right_ml)) {
2620 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2622 gchar *my_addr1, *my_addr2;
2624 if (!addr1 || !addr2)
2627 Xstrdup_a(my_addr1, addr1, return FALSE);
2628 Xstrdup_a(my_addr2, addr2, return FALSE);
2630 extract_address(my_addr1);
2631 extract_address(my_addr2);
2633 return !strcasecmp(my_addr1, my_addr2);
2636 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2637 gboolean to_all, gboolean to_ml,
2639 gboolean followup_and_reply_to)
2641 GSList *cc_list = NULL;
2644 gchar *replyto = NULL;
2645 GHashTable *to_table;
2647 gboolean reply_to_ml = FALSE;
2648 gboolean default_reply_to = FALSE;
2650 g_return_if_fail(compose->account != NULL);
2651 g_return_if_fail(msginfo != NULL);
2653 reply_to_ml = to_ml && compose->ml_post;
2655 default_reply_to = msginfo->folder &&
2656 msginfo->folder->prefs->enable_default_reply_to;
2658 if (compose->account->protocol != A_NNTP) {
2659 if (reply_to_ml && !default_reply_to) {
2661 gboolean is_subscr = is_subscription(compose->ml_post,
2664 /* normal answer to ml post with a reply-to */
2665 compose_entry_append(compose,
2668 if (compose->replyto
2669 && !same_address(compose->ml_post, compose->replyto))
2670 compose_entry_append(compose,
2674 /* answer to subscription confirmation */
2675 if (compose->replyto)
2676 compose_entry_append(compose,
2679 else if (msginfo->from)
2680 compose_entry_append(compose,
2685 else if (!(to_all || to_sender) && default_reply_to) {
2686 compose_entry_append(compose,
2687 msginfo->folder->prefs->default_reply_to,
2689 compose_entry_mark_default_to(compose,
2690 msginfo->folder->prefs->default_reply_to);
2695 Xstrdup_a(tmp1, msginfo->from, return);
2696 extract_address(tmp1);
2697 if (to_all || to_sender ||
2698 !account_find_from_address(tmp1))
2699 compose_entry_append(compose,
2700 (compose->replyto && !to_sender)
2701 ? compose->replyto :
2702 msginfo->from ? msginfo->from : "",
2704 else if (!to_all && !to_sender) {
2705 /* reply to the last list of recipients */
2706 compose_entry_append(compose,
2707 msginfo->to ? msginfo->to : "",
2709 compose_entry_append(compose,
2710 msginfo->cc ? msginfo->cc : "",
2715 if (to_sender || (compose->followup_to &&
2716 !strncmp(compose->followup_to, "poster", 6)))
2717 compose_entry_append
2719 (compose->replyto ? compose->replyto :
2720 msginfo->from ? msginfo->from : ""),
2723 else if (followup_and_reply_to || to_all) {
2724 compose_entry_append
2726 (compose->replyto ? compose->replyto :
2727 msginfo->from ? msginfo->from : ""),
2730 compose_entry_append
2732 compose->followup_to ? compose->followup_to :
2733 compose->newsgroups ? compose->newsgroups : "",
2734 COMPOSE_NEWSGROUPS);
2737 compose_entry_append
2739 compose->followup_to ? compose->followup_to :
2740 compose->newsgroups ? compose->newsgroups : "",
2741 COMPOSE_NEWSGROUPS);
2744 if (msginfo->subject && *msginfo->subject) {
2748 buf = p = g_strdup(msginfo->subject);
2749 p += subject_get_prefix_length(p);
2750 memmove(buf, p, strlen(p) + 1);
2752 buf2 = g_strdup_printf("Re: %s", buf);
2753 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2758 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2760 if (to_ml && compose->ml_post) return;
2761 if (!to_all || compose->account->protocol == A_NNTP) return;
2763 if (compose->replyto) {
2764 Xstrdup_a(replyto, compose->replyto, return);
2765 extract_address(replyto);
2767 if (msginfo->from) {
2768 Xstrdup_a(from, msginfo->from, return);
2769 extract_address(from);
2772 if (replyto && from)
2773 cc_list = address_list_append_with_comments(cc_list, from);
2774 if (to_all && msginfo->folder &&
2775 msginfo->folder->prefs->enable_default_reply_to)
2776 cc_list = address_list_append_with_comments(cc_list,
2777 msginfo->folder->prefs->default_reply_to);
2778 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2779 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2781 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2783 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2784 if (compose->account)
2785 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2786 GINT_TO_POINTER(1));
2788 /* remove address on To: and that of current account */
2789 for (cur = cc_list; cur != NULL; ) {
2790 GSList *next = cur->next;
2793 addr = g_strdup(cur->data);
2794 extract_address(addr);
2796 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2797 cc_list = g_slist_remove(cc_list, cur->data);
2799 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2803 hash_free_strings(to_table);
2804 g_hash_table_destroy(to_table);
2807 for (cur = cc_list; cur != NULL; cur = cur->next)
2808 compose_entry_append(compose, (gchar *)cur->data,
2810 slist_free_strings(cc_list);
2811 g_slist_free(cc_list);
2816 #define SET_ENTRY(entry, str) \
2819 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2822 #define SET_ADDRESS(type, str) \
2825 compose_entry_append(compose, str, type); \
2828 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2830 g_return_if_fail(msginfo != NULL);
2832 SET_ENTRY(subject_entry, msginfo->subject);
2833 SET_ENTRY(from_name, msginfo->from);
2834 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2835 SET_ADDRESS(COMPOSE_CC, compose->cc);
2836 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2837 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2838 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2839 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2841 compose_update_priority_menu_item(compose);
2842 compose_update_privacy_system_menu_item(compose, FALSE);
2843 compose_show_first_last_header(compose, TRUE);
2849 static void compose_insert_sig(Compose *compose, gboolean replace)
2851 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2852 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2854 GtkTextIter iter, iter_end;
2856 gchar *search = NULL;
2857 gboolean prev_autowrap;
2858 gboolean found = FALSE, shift = FALSE;
2861 g_return_if_fail(compose->account != NULL);
2863 prev_autowrap = compose->autowrap;
2864 compose->autowrap = FALSE;
2866 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2867 G_CALLBACK(compose_changed_cb),
2870 mark = gtk_text_buffer_get_insert(buffer);
2871 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2872 cur_pos = gtk_text_iter_get_offset (&iter);
2874 gtk_text_buffer_get_end_iter(buffer, &iter);
2876 search = compose->sig_str;
2878 if (replace && search) {
2879 GtkTextIter first_iter, start_iter, end_iter;
2881 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2883 if (compose->sig_str[0] == '\0')
2886 found = gtk_text_iter_forward_search(&first_iter,
2888 GTK_TEXT_SEARCH_TEXT_ONLY,
2889 &start_iter, &end_iter,
2893 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2897 if (replace && !found && search && strlen(search) > 2
2898 && search[0] == '\n' && search[1] == '\n') {
2904 g_free(compose->sig_str);
2905 compose->sig_str = compose_get_signature_str(compose);
2906 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2907 compose->sig_str = g_strdup("");
2909 cur_pos = gtk_text_iter_get_offset(&iter);
2911 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2913 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2915 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2916 gtk_text_iter_forward_char(&iter);
2917 gtk_text_iter_forward_char(&iter);
2918 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2919 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2921 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2922 cur_pos = gtk_text_buffer_get_char_count (buffer);
2924 /* put the cursor where it should be
2925 * either where the quote_fmt says, either before the signature */
2926 if (compose->set_cursor_pos < 0)
2927 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2929 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2930 compose->set_cursor_pos);
2932 gtk_text_buffer_place_cursor(buffer, &iter);
2933 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2934 G_CALLBACK(compose_changed_cb),
2937 compose->autowrap = prev_autowrap;
2938 if (compose->autowrap)
2939 compose_wrap_all(compose);
2942 static gchar *compose_get_signature_str(Compose *compose)
2944 gchar *sig_body = NULL;
2945 gchar *sig_str = NULL;
2946 gchar *utf8_sig_str = NULL;
2948 g_return_val_if_fail(compose->account != NULL, NULL);
2950 if (!compose->account->sig_path)
2953 if (compose->account->sig_type == SIG_FILE) {
2954 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2955 g_warning("can't open signature file: %s\n",
2956 compose->account->sig_path);
2961 if (compose->account->sig_type == SIG_COMMAND)
2962 sig_body = get_command_output(compose->account->sig_path);
2966 tmp = file_read_to_str(compose->account->sig_path);
2969 sig_body = normalize_newlines(tmp);
2973 if (compose->account->sig_sep) {
2974 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2978 sig_str = g_strconcat("\n\n", sig_body, NULL);
2981 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2982 utf8_sig_str = sig_str;
2984 utf8_sig_str = conv_codeset_strdup
2985 (sig_str, conv_get_locale_charset_str_no_utf8(),
2991 return utf8_sig_str;
2994 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2997 GtkTextBuffer *buffer;
3000 const gchar *cur_encoding;
3001 gchar buf[BUFFSIZE];
3004 gboolean prev_autowrap;
3005 gboolean badtxt = FALSE;
3007 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
3009 if ((fp = g_fopen(file, "rb")) == NULL) {
3010 FILE_OP_ERROR(file, "fopen");
3011 return COMPOSE_INSERT_READ_ERROR;
3014 prev_autowrap = compose->autowrap;
3015 compose->autowrap = FALSE;
3017 text = GTK_TEXT_VIEW(compose->text);
3018 buffer = gtk_text_view_get_buffer(text);
3019 mark = gtk_text_buffer_get_insert(buffer);
3020 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3022 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3023 G_CALLBACK(text_inserted),
3026 cur_encoding = conv_get_locale_charset_str_no_utf8();
3028 while (fgets(buf, sizeof(buf), fp) != NULL) {
3031 if (g_utf8_validate(buf, -1, NULL) == TRUE)
3032 str = g_strdup(buf);
3034 str = conv_codeset_strdup
3035 (buf, cur_encoding, CS_INTERNAL);
3038 /* strip <CR> if DOS/Windows file,
3039 replace <CR> with <LF> if Macintosh file. */
3042 if (len > 0 && str[len - 1] != '\n') {
3044 if (str[len] == '\r') str[len] = '\n';
3047 gtk_text_buffer_insert(buffer, &iter, str, -1);
3051 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3052 G_CALLBACK(text_inserted),
3054 compose->autowrap = prev_autowrap;
3055 if (compose->autowrap)
3056 compose_wrap_all(compose);
3061 return COMPOSE_INSERT_INVALID_CHARACTER;
3063 return COMPOSE_INSERT_SUCCESS;
3066 static gboolean compose_attach_append(Compose *compose, const gchar *file,
3067 const gchar *filename,
3068 const gchar *content_type)
3076 GtkListStore *store;
3078 gboolean has_binary = FALSE;
3080 if (!is_file_exist(file)) {
3081 alertpanel_error("File %s doesn't exist\n", filename);
3084 if ((size = get_file_size(file)) < 0) {
3085 alertpanel_error("Can't get file size of %s\n", filename);
3089 alertpanel_error(_("File %s is empty."), filename);
3092 if ((fp = g_fopen(file, "rb")) == NULL) {
3093 alertpanel_error(_("Can't read %s."), filename);
3098 ainfo = g_new0(AttachInfo, 1);
3099 auto_ainfo = g_auto_pointer_new_with_free
3100 (ainfo, (GFreeFunc) compose_attach_info_free);
3101 ainfo->file = g_strdup(file);
3104 ainfo->content_type = g_strdup(content_type);
3105 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
3107 MsgFlags flags = {0, 0};
3109 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
3110 ainfo->encoding = ENC_7BIT;
3112 ainfo->encoding = ENC_8BIT;
3114 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
3115 if (msginfo && msginfo->subject)
3116 name = g_strdup(msginfo->subject);
3118 name = g_path_get_basename(filename ? filename : file);
3120 ainfo->name = g_strdup_printf(_("Message: %s"), name);
3122 procmsg_msginfo_free(msginfo);
3124 if (!g_ascii_strncasecmp(content_type, "text", 4))
3125 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
3127 ainfo->encoding = ENC_BASE64;
3128 name = g_path_get_basename(filename ? filename : file);
3129 ainfo->name = g_strdup(name);
3133 ainfo->content_type = procmime_get_mime_type(file);
3134 if (!ainfo->content_type) {
3135 ainfo->content_type =
3136 g_strdup("application/octet-stream");
3137 ainfo->encoding = ENC_BASE64;
3138 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
3140 procmime_get_encoding_for_text_file(file, &has_binary);
3142 ainfo->encoding = ENC_BASE64;
3143 name = g_path_get_basename(filename ? filename : file);
3144 ainfo->name = g_strdup(name);
3148 if (ainfo->name != NULL
3149 && !strcmp(ainfo->name, ".")) {
3150 g_free(ainfo->name);
3154 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
3155 g_free(ainfo->content_type);
3156 ainfo->content_type = g_strdup("application/octet-stream");
3160 size_text = to_human_readable(size);
3162 store = GTK_LIST_STORE(gtk_tree_view_get_model
3163 (GTK_TREE_VIEW(compose->attach_clist)));
3165 gtk_list_store_append(store, &iter);
3166 gtk_list_store_set(store, &iter,
3167 COL_MIMETYPE, ainfo->content_type,
3168 COL_SIZE, size_text,
3169 COL_NAME, ainfo->name,
3171 COL_AUTODATA, auto_ainfo,
3174 g_auto_pointer_free(auto_ainfo);
3178 static void compose_use_signing(Compose *compose, gboolean use_signing)
3180 GtkItemFactory *ifactory;
3181 GtkWidget *menuitem = NULL;
3183 compose->use_signing = use_signing;
3184 ifactory = gtk_item_factory_from_widget(compose->menubar);
3185 menuitem = gtk_item_factory_get_item
3186 (ifactory, "/Options/Sign");
3187 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3191 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3193 GtkItemFactory *ifactory;
3194 GtkWidget *menuitem = NULL;
3196 compose->use_encryption = use_encryption;
3197 ifactory = gtk_item_factory_from_widget(compose->menubar);
3198 menuitem = gtk_item_factory_get_item
3199 (ifactory, "/Options/Encrypt");
3201 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3205 #define NEXT_PART_NOT_CHILD(info) \
3207 node = info->node; \
3208 while (node->children) \
3209 node = g_node_last_child(node); \
3210 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3213 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3217 MimeInfo *firsttext = NULL;
3218 MimeInfo *encrypted = NULL;
3221 const gchar *partname = NULL;
3223 mimeinfo = procmime_scan_message(msginfo);
3224 if (!mimeinfo) return;
3226 if (mimeinfo->node->children == NULL) {
3227 procmime_mimeinfo_free_all(mimeinfo);
3231 /* find first content part */
3232 child = (MimeInfo *) mimeinfo->node->children->data;
3233 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3234 child = (MimeInfo *)child->node->children->data;
3236 if (child->type == MIMETYPE_TEXT) {
3238 debug_print("First text part found\n");
3239 } else if (compose->mode == COMPOSE_REEDIT &&
3240 child->type == MIMETYPE_APPLICATION &&
3241 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3242 encrypted = (MimeInfo *)child->node->parent->data;
3245 child = (MimeInfo *) mimeinfo->node->children->data;
3246 while (child != NULL) {
3247 if (child == encrypted) {
3248 /* skip this part of tree */
3249 NEXT_PART_NOT_CHILD(child);
3253 if (child->type == MIMETYPE_MULTIPART) {
3254 /* get the actual content */
3255 child = procmime_mimeinfo_next(child);
3259 if (child == firsttext) {
3260 child = procmime_mimeinfo_next(child);
3264 outfile = procmime_get_tmp_file_name(child);
3265 if (procmime_get_part(outfile, child) < 0)
3266 g_warning("Can't get the part of multipart message.");
3268 gchar *content_type;
3270 content_type = procmime_get_content_type_str(child->type, child->subtype);
3272 /* if we meet a pgp signature, we don't attach it, but
3273 * we force signing. */
3274 if (strcmp(content_type, "application/pgp-signature")) {
3275 partname = procmime_mimeinfo_get_parameter(child, "filename");
3276 if (partname == NULL)
3277 partname = procmime_mimeinfo_get_parameter(child, "name");
3278 if (partname == NULL)
3280 compose_attach_append(compose, outfile,
3281 partname, content_type);
3283 compose_force_signing(compose, compose->account);
3285 g_free(content_type);
3288 NEXT_PART_NOT_CHILD(child);
3290 procmime_mimeinfo_free_all(mimeinfo);
3293 #undef NEXT_PART_NOT_CHILD
3298 WAIT_FOR_INDENT_CHAR,
3299 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3302 /* return indent length, we allow:
3303 indent characters followed by indent characters or spaces/tabs,
3304 alphabets and numbers immediately followed by indent characters,
3305 and the repeating sequences of the above
3306 If quote ends with multiple spaces, only the first one is included. */
3307 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3308 const GtkTextIter *start, gint *len)
3310 GtkTextIter iter = *start;
3314 IndentState state = WAIT_FOR_INDENT_CHAR;
3317 gint alnum_count = 0;
3318 gint space_count = 0;
3321 if (prefs_common.quote_chars == NULL) {
3325 while (!gtk_text_iter_ends_line(&iter)) {
3326 wc = gtk_text_iter_get_char(&iter);
3327 if (g_unichar_iswide(wc))
3329 clen = g_unichar_to_utf8(wc, ch);
3333 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3334 is_space = g_unichar_isspace(wc);
3336 if (state == WAIT_FOR_INDENT_CHAR) {
3337 if (!is_indent && !g_unichar_isalnum(wc))
3340 quote_len += alnum_count + space_count + 1;
3341 alnum_count = space_count = 0;
3342 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3345 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3346 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3350 else if (is_indent) {
3351 quote_len += alnum_count + space_count + 1;
3352 alnum_count = space_count = 0;
3355 state = WAIT_FOR_INDENT_CHAR;
3359 gtk_text_iter_forward_char(&iter);
3362 if (quote_len > 0 && space_count > 0)
3368 if (quote_len > 0) {
3370 gtk_text_iter_forward_chars(&iter, quote_len);
3371 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3377 /* return TRUE if the line is itemized */
3378 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3379 const GtkTextIter *start)
3381 GtkTextIter iter = *start;
3386 if (gtk_text_iter_ends_line(&iter))
3390 wc = gtk_text_iter_get_char(&iter);
3391 if (!g_unichar_isspace(wc))
3393 gtk_text_iter_forward_char(&iter);
3394 if (gtk_text_iter_ends_line(&iter))
3398 clen = g_unichar_to_utf8(wc, ch);
3402 if (!strchr("*-+", ch[0]))
3405 gtk_text_iter_forward_char(&iter);
3406 if (gtk_text_iter_ends_line(&iter))
3408 wc = gtk_text_iter_get_char(&iter);
3409 if (g_unichar_isspace(wc))
3415 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3416 const GtkTextIter *start,
3417 GtkTextIter *break_pos,
3421 GtkTextIter iter = *start, line_end = *start;
3422 PangoLogAttr *attrs;
3429 gboolean can_break = FALSE;
3430 gboolean do_break = FALSE;
3431 gboolean was_white = FALSE;
3432 gboolean prev_dont_break = FALSE;
3434 gtk_text_iter_forward_to_line_end(&line_end);
3435 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3436 len = g_utf8_strlen(str, -1);
3437 /* g_print("breaking line: %d: %s (len = %d)\n",
3438 gtk_text_iter_get_line(&iter), str, len); */
3439 attrs = g_new(PangoLogAttr, len + 1);
3441 pango_default_break(str, -1, NULL, attrs, len + 1);
3445 /* skip quote and leading spaces */
3446 for (i = 0; *p != '\0' && i < len; i++) {
3449 wc = g_utf8_get_char(p);
3450 if (i >= quote_len && !g_unichar_isspace(wc))
3452 if (g_unichar_iswide(wc))
3454 else if (*p == '\t')
3458 p = g_utf8_next_char(p);
3461 for (; *p != '\0' && i < len; i++) {
3462 PangoLogAttr *attr = attrs + i;
3466 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3469 was_white = attr->is_white;
3471 /* don't wrap URI */
3472 if ((uri_len = get_uri_len(p)) > 0) {
3474 if (pos > 0 && col > max_col) {
3484 wc = g_utf8_get_char(p);
3485 if (g_unichar_iswide(wc)) {
3487 if (prev_dont_break && can_break && attr->is_line_break)
3489 } else if (*p == '\t')
3493 if (pos > 0 && col > max_col) {
3498 if (*p == '-' || *p == '/')
3499 prev_dont_break = TRUE;
3501 prev_dont_break = FALSE;
3503 p = g_utf8_next_char(p);
3507 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3512 *break_pos = *start;
3513 gtk_text_iter_set_line_offset(break_pos, pos);
3518 static gboolean compose_join_next_line(Compose *compose,
3519 GtkTextBuffer *buffer,
3521 const gchar *quote_str)
3523 GtkTextIter iter_ = *iter, cur, prev, next, end;
3524 PangoLogAttr attrs[3];
3526 gchar *next_quote_str;
3529 gboolean keep_cursor = FALSE;
3531 if (!gtk_text_iter_forward_line(&iter_) ||
3532 gtk_text_iter_ends_line(&iter_))
3535 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3537 if ((quote_str || next_quote_str) &&
3538 strcmp2(quote_str, next_quote_str) != 0) {
3539 g_free(next_quote_str);
3542 g_free(next_quote_str);
3545 if (quote_len > 0) {
3546 gtk_text_iter_forward_chars(&end, quote_len);
3547 if (gtk_text_iter_ends_line(&end))
3551 /* don't join itemized lines */
3552 if (compose_is_itemized(buffer, &end))
3555 /* don't join signature separator */
3556 if (compose_is_sig_separator(compose, buffer, &iter_))
3559 /* delete quote str */
3561 gtk_text_buffer_delete(buffer, &iter_, &end);
3563 /* don't join line breaks put by the user */
3565 gtk_text_iter_backward_char(&cur);
3566 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3567 gtk_text_iter_forward_char(&cur);
3571 gtk_text_iter_forward_char(&cur);
3572 /* delete linebreak and extra spaces */
3573 while (gtk_text_iter_backward_char(&cur)) {
3574 wc1 = gtk_text_iter_get_char(&cur);
3575 if (!g_unichar_isspace(wc1))
3580 while (!gtk_text_iter_ends_line(&cur)) {
3581 wc1 = gtk_text_iter_get_char(&cur);
3582 if (!g_unichar_isspace(wc1))
3584 gtk_text_iter_forward_char(&cur);
3587 if (!gtk_text_iter_equal(&prev, &next)) {
3590 mark = gtk_text_buffer_get_insert(buffer);
3591 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3592 if (gtk_text_iter_equal(&prev, &cur))
3594 gtk_text_buffer_delete(buffer, &prev, &next);
3598 /* insert space if required */
3599 gtk_text_iter_backward_char(&prev);
3600 wc1 = gtk_text_iter_get_char(&prev);
3601 wc2 = gtk_text_iter_get_char(&next);
3602 gtk_text_iter_forward_char(&next);
3603 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3604 pango_default_break(str, -1, NULL, attrs, 3);
3605 if (!attrs[1].is_line_break ||
3606 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3607 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3609 gtk_text_iter_backward_char(&iter_);
3610 gtk_text_buffer_place_cursor(buffer, &iter_);
3619 #define ADD_TXT_POS(bp_, ep_, pti_) \
3620 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3621 last = last->next; \
3622 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3623 last->next = NULL; \
3625 g_warning("alloc error scanning URIs\n"); \
3628 static gboolean automatic_break = FALSE;
3629 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3631 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3632 GtkTextBuffer *buffer;
3633 GtkTextIter iter, break_pos, end_of_line;
3634 gchar *quote_str = NULL;
3636 gboolean wrap_quote = prefs_common.linewrap_quote;
3637 gboolean prev_autowrap = compose->autowrap;
3638 gint startq_offset = -1, noq_offset = -1;
3639 gint uri_start = -1, uri_stop = -1;
3640 gint nouri_start = -1, nouri_stop = -1;
3641 gint num_blocks = 0;
3642 gint quotelevel = -1;
3644 compose->autowrap = FALSE;
3646 buffer = gtk_text_view_get_buffer(text);
3647 undo_wrapping(compose->undostruct, TRUE);
3652 mark = gtk_text_buffer_get_insert(buffer);
3653 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3656 /* move to paragraph start */
3657 gtk_text_iter_set_line_offset(&iter, 0);
3658 if (gtk_text_iter_ends_line(&iter)) {
3659 while (gtk_text_iter_ends_line(&iter) &&
3660 gtk_text_iter_forward_line(&iter))
3663 while (gtk_text_iter_backward_line(&iter)) {
3664 if (gtk_text_iter_ends_line(&iter)) {
3665 gtk_text_iter_forward_line(&iter);
3671 /* go until paragraph end (empty line) */
3673 while (!gtk_text_iter_ends_line(&iter)) {
3674 gchar *scanpos = NULL;
3675 /* parse table - in order of priority */
3677 const gchar *needle; /* token */
3679 /* token search function */
3680 gchar *(*search) (const gchar *haystack,
3681 const gchar *needle);
3682 /* part parsing function */
3683 gboolean (*parse) (const gchar *start,
3684 const gchar *scanpos,
3688 /* part to URI function */
3689 gchar *(*build_uri) (const gchar *bp,
3693 static struct table parser[] = {
3694 {"http://", strcasestr, get_uri_part, make_uri_string},
3695 {"https://", strcasestr, get_uri_part, make_uri_string},
3696 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3697 {"sftp://", strcasestr, get_uri_part, make_uri_string},
3698 {"www.", strcasestr, get_uri_part, make_http_string},
3699 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3700 {"@", strcasestr, get_email_part, make_email_string}
3702 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3703 gint last_index = PARSE_ELEMS;
3705 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3708 if (!prev_autowrap && num_blocks == 0) {
3710 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3711 G_CALLBACK(text_inserted),
3714 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3717 uri_start = uri_stop = -1;
3719 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3723 if (startq_offset == -1) {
3724 startq_offset = gtk_text_iter_get_offset(&iter);
3728 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3729 if (startq_offset == -1)
3730 startq_offset = gtk_text_iter_get_offset(&iter);
3731 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3732 if (quotelevel > 2) {
3733 /* recycle colors */
3734 if (prefs_common.recycle_quote_colors)
3740 if (startq_offset == -1)
3741 noq_offset = gtk_text_iter_get_offset(&iter);
3745 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3748 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3749 prefs_common.linewrap_len,
3751 GtkTextIter prev, next, cur;
3753 if (prev_autowrap != FALSE || force) {
3754 automatic_break = TRUE;
3755 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3756 automatic_break = FALSE;
3757 } else if (quote_str && wrap_quote) {
3758 automatic_break = TRUE;
3759 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3760 automatic_break = FALSE;
3763 /* remove trailing spaces */
3765 gtk_text_iter_backward_char(&cur);
3767 while (!gtk_text_iter_starts_line(&cur)) {
3770 gtk_text_iter_backward_char(&cur);
3771 wc = gtk_text_iter_get_char(&cur);
3772 if (!g_unichar_isspace(wc))
3776 if (!gtk_text_iter_equal(&prev, &next)) {
3777 gtk_text_buffer_delete(buffer, &prev, &next);
3779 gtk_text_iter_forward_char(&break_pos);
3783 gtk_text_buffer_insert(buffer, &break_pos,
3787 compose_join_next_line(compose, buffer, &iter, quote_str);
3789 /* move iter to current line start */
3790 gtk_text_iter_set_line_offset(&iter, 0);
3797 /* move iter to next line start */
3802 if (!prev_autowrap && num_blocks > 0) {
3804 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3805 G_CALLBACK(text_inserted),
3809 while (!gtk_text_iter_ends_line(&end_of_line)) {
3810 gtk_text_iter_forward_char(&end_of_line);
3812 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3814 nouri_start = gtk_text_iter_get_offset(&iter);
3815 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3817 walk_pos = gtk_text_iter_get_offset(&iter);
3818 /* FIXME: this looks phony. scanning for anything in the parse table */
3819 for (n = 0; n < PARSE_ELEMS; n++) {
3822 tmp = parser[n].search(walk, parser[n].needle);
3824 if (scanpos == NULL || tmp < scanpos) {
3833 /* check if URI can be parsed */
3834 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3835 (const gchar **)&ep, FALSE)
3836 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3840 strlen(parser[last_index].needle);
3843 uri_start = walk_pos + (bp - o_walk);
3844 uri_stop = walk_pos + (ep - o_walk);
3848 gtk_text_iter_forward_line(&iter);
3851 if (startq_offset != -1) {
3852 GtkTextIter startquote, endquote;
3853 gtk_text_buffer_get_iter_at_offset(
3854 buffer, &startquote, startq_offset);
3856 switch (quotelevel) {
3857 case 0: gtk_text_buffer_apply_tag_by_name(
3858 buffer, "quote0", &startquote, &endquote);
3860 case 1: gtk_text_buffer_apply_tag_by_name(
3861 buffer, "quote1", &startquote, &endquote);
3863 case 2: gtk_text_buffer_apply_tag_by_name(
3864 buffer, "quote2", &startquote, &endquote);
3868 } else if (noq_offset != -1) {
3869 GtkTextIter startnoquote, endnoquote;
3870 gtk_text_buffer_get_iter_at_offset(
3871 buffer, &startnoquote, noq_offset);
3873 gtk_text_buffer_remove_tag_by_name(
3874 buffer, "quote0", &startnoquote, &endnoquote);
3875 gtk_text_buffer_remove_tag_by_name(
3876 buffer, "quote1", &startnoquote, &endnoquote);
3877 gtk_text_buffer_remove_tag_by_name(
3878 buffer, "quote2", &startnoquote, &endnoquote);
3883 GtkTextIter nouri_start_iter, nouri_end_iter;
3884 gtk_text_buffer_get_iter_at_offset(
3885 buffer, &nouri_start_iter, nouri_start);
3886 gtk_text_buffer_get_iter_at_offset(
3887 buffer, &nouri_end_iter, nouri_stop);
3888 gtk_text_buffer_remove_tag_by_name(
3889 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3891 if (uri_start > 0 && uri_stop > 0) {
3892 GtkTextIter uri_start_iter, uri_end_iter;
3893 gtk_text_buffer_get_iter_at_offset(
3894 buffer, &uri_start_iter, uri_start);
3895 gtk_text_buffer_get_iter_at_offset(
3896 buffer, &uri_end_iter, uri_stop);
3897 gtk_text_buffer_apply_tag_by_name(
3898 buffer, "link", &uri_start_iter, &uri_end_iter);
3904 undo_wrapping(compose->undostruct, FALSE);
3905 compose->autowrap = prev_autowrap;
3908 void compose_action_cb(void *data)
3910 Compose *compose = (Compose *)data;
3911 compose_wrap_all(compose);
3914 static void compose_wrap_all(Compose *compose)
3916 compose_wrap_all_full(compose, FALSE);
3919 static void compose_wrap_all_full(Compose *compose, gboolean force)
3921 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3922 GtkTextBuffer *buffer;
3925 buffer = gtk_text_view_get_buffer(text);
3927 gtk_text_buffer_get_start_iter(buffer, &iter);
3928 while (!gtk_text_iter_is_end(&iter))
3929 compose_beautify_paragraph(compose, &iter, force);
3933 static void compose_set_title(Compose *compose)
3939 edited = compose->modified ? _(" [Edited]") : "";
3941 subject = gtk_editable_get_chars(
3942 GTK_EDITABLE(compose->subject_entry), 0, -1);
3944 if (subject && strlen(subject))
3945 str = g_strdup_printf(_("%s - Compose message%s"),
3948 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3949 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3955 * compose_current_mail_account:
3957 * Find a current mail account (the currently selected account, or the
3958 * default account, if a news account is currently selected). If a
3959 * mail account cannot be found, display an error message.
3961 * Return value: Mail account, or NULL if not found.
3963 static PrefsAccount *
3964 compose_current_mail_account(void)
3968 if (cur_account && cur_account->protocol != A_NNTP)
3971 ac = account_get_default();
3972 if (!ac || ac->protocol == A_NNTP) {
3973 alertpanel_error(_("Account for sending mail is not specified.\n"
3974 "Please select a mail account before sending."));
3981 #define QUOTE_IF_REQUIRED(out, str) \
3983 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3987 len = strlen(str) + 3; \
3988 if ((__tmp = alloca(len)) == NULL) { \
3989 g_warning("can't allocate memory\n"); \
3990 g_string_free(header, TRUE); \
3993 g_snprintf(__tmp, len, "\"%s\"", str); \
3998 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3999 g_warning("can't allocate memory\n"); \
4000 g_string_free(header, TRUE); \
4003 strcpy(__tmp, str); \
4009 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
4011 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4015 len = strlen(str) + 3; \
4016 if ((__tmp = alloca(len)) == NULL) { \
4017 g_warning("can't allocate memory\n"); \
4020 g_snprintf(__tmp, len, "\"%s\"", str); \
4025 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4026 g_warning("can't allocate memory\n"); \
4029 strcpy(__tmp, str); \
4035 static void compose_select_account(Compose *compose, PrefsAccount *account,
4038 GtkItemFactory *ifactory;
4041 g_return_if_fail(account != NULL);
4043 compose->account = account;
4045 if (account->name && *account->name) {
4047 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
4048 from = g_strdup_printf("%s <%s>",
4049 buf, account->address);
4050 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
4052 from = g_strdup_printf("<%s>",
4054 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
4059 compose_set_title(compose);
4061 ifactory = gtk_item_factory_from_widget(compose->menubar);
4063 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
4064 menu_set_active(ifactory, "/Options/Sign", TRUE);
4066 menu_set_active(ifactory, "/Options/Sign", FALSE);
4067 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
4068 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
4070 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
4072 activate_privacy_system(compose, account, FALSE);
4074 if (!init && compose->mode != COMPOSE_REDIRECT) {
4075 undo_block(compose->undostruct);
4076 compose_insert_sig(compose, TRUE);
4077 undo_unblock(compose->undostruct);
4081 gboolean compose_check_for_valid_recipient(Compose *compose) {
4082 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
4083 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
4084 gboolean recipient_found = FALSE;
4088 /* free to and newsgroup list */
4089 slist_free_strings(compose->to_list);
4090 g_slist_free(compose->to_list);
4091 compose->to_list = NULL;
4093 slist_free_strings(compose->newsgroup_list);
4094 g_slist_free(compose->newsgroup_list);
4095 compose->newsgroup_list = NULL;
4097 /* search header entries for to and newsgroup entries */
4098 for (list = compose->header_list; list; list = list->next) {
4101 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4102 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4104 if (entry[0] != '\0') {
4105 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
4106 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
4107 compose->to_list = address_list_append(compose->to_list, entry);
4108 recipient_found = TRUE;
4111 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
4112 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
4113 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
4114 recipient_found = TRUE;
4121 return recipient_found;
4124 static gboolean compose_check_for_set_recipients(Compose *compose)
4126 if (compose->account->set_autocc && compose->account->auto_cc) {
4127 gboolean found_other = FALSE;
4129 /* search header entries for to and newsgroup entries */
4130 for (list = compose->header_list; list; list = list->next) {
4133 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4134 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4136 if (strcmp(entry, compose->account->auto_cc)
4137 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
4147 if (compose->batch) {
4148 gtk_widget_show_all(compose->window);
4150 aval = alertpanel(_("Send"),
4151 _("The only recipient is the default CC address. Send anyway?"),
4152 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4153 if (aval != G_ALERTALTERNATE)
4157 if (compose->account->set_autobcc && compose->account->auto_bcc) {
4158 gboolean found_other = FALSE;
4160 /* search header entries for to and newsgroup entries */
4161 for (list = compose->header_list; list; list = list->next) {
4164 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4165 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4167 if (strcmp(entry, compose->account->auto_bcc)
4168 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
4178 if (compose->batch) {
4179 gtk_widget_show_all(compose->window);
4181 aval = alertpanel(_("Send"),
4182 _("The only recipient is the default BCC address. Send anyway?"),
4183 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4184 if (aval != G_ALERTALTERNATE)
4191 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
4195 if (compose_check_for_valid_recipient(compose) == FALSE) {
4196 if (compose->batch) {
4197 gtk_widget_show_all(compose->window);
4199 alertpanel_error(_("Recipient is not specified."));
4203 if (compose_check_for_set_recipients(compose) == FALSE) {
4207 if (!compose->batch) {
4208 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4209 if (*str == '\0' && check_subject == TRUE) {
4212 aval = alertpanel(_("Send"),
4213 _("Subject is empty. Send it anyway?"),
4214 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4215 if (aval != G_ALERTALTERNATE)
4220 if (hooks_invoke(COMPOSE_CHECK_BEFORE_SEND_HOOKLIST, compose))
4226 gint compose_send(Compose *compose)
4229 FolderItem *folder = NULL;
4231 gchar *msgpath = NULL;
4232 gboolean discard_window = FALSE;
4233 gchar *errstr = NULL;
4234 gchar *tmsgid = NULL;
4235 MainWindow *mainwin = mainwindow_get_mainwindow();
4237 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4238 || compose->batch == TRUE)
4239 discard_window = TRUE;
4241 compose_allow_user_actions (compose, FALSE);
4242 compose->sending = TRUE;
4244 if (compose_check_entries(compose, TRUE) == FALSE) {
4245 if (compose->batch) {
4246 gtk_widget_show_all(compose->window);
4252 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
4255 if (compose->batch) {
4256 gtk_widget_show_all(compose->window);
4259 alertpanel_error(_("Could not queue message for sending:\n\n"
4260 "Charset conversion failed."));
4261 } else if (val == -5) {
4262 alertpanel_error(_("Could not queue message for sending:\n\n"
4263 "Couldn't get recipient encryption key."));
4264 } else if (val == -3) {
4265 if (privacy_peek_error())
4266 alertpanel_error(_("Could not queue message for sending:\n\n"
4267 "Signature failed: %s"), privacy_get_error());
4268 } else if (val == -2 && errno != 0) {
4269 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4271 alertpanel_error(_("Could not queue message for sending."));
4276 tmsgid = g_strdup(compose->msgid);
4277 if (discard_window) {
4278 compose->sending = FALSE;
4279 compose_close(compose);
4280 /* No more compose access in the normal codepath
4281 * after this point! */
4286 alertpanel_error(_("The message was queued but could not be "
4287 "sent.\nUse \"Send queued messages\" from "
4288 "the main window to retry."));
4289 if (!discard_window) {
4296 if (msgpath == NULL) {
4297 msgpath = folder_item_fetch_msg(folder, msgnum);
4298 val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum);
4301 val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum);
4305 if (!discard_window) {
4306 compose->sending = FALSE;
4307 compose_allow_user_actions (compose, TRUE);
4309 folder_item_remove_msg(folder, msgnum);
4310 folder_item_scan(folder);
4312 /* make sure we delete that */
4313 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
4315 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
4316 folder_item_remove_msg(folder, tmp->msgnum);
4317 procmsg_msginfo_free(tmp);
4324 folder_item_remove_msg(folder, msgnum);
4325 folder_item_scan(folder);
4327 /* make sure we delete that */
4328 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
4330 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
4331 folder_item_remove_msg(folder, tmp->msgnum);
4332 procmsg_msginfo_free(tmp);
4335 if (!discard_window)
4336 compose_close(compose);
4339 gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
4340 "the main window to retry."), errstr);
4342 alertpanel_error_log(tmp);
4345 alertpanel_error_log(_("The message was queued but could not be "
4346 "sent.\nUse \"Send queued messages\" from "
4347 "the main window to retry."));
4349 if (!discard_window) {
4358 toolbar_main_set_sensitive(mainwin);
4359 main_window_set_menu_sensitive(mainwin);
4365 compose_allow_user_actions (compose, TRUE);
4366 compose->sending = FALSE;
4367 compose->modified = TRUE;
4368 toolbar_main_set_sensitive(mainwin);
4369 main_window_set_menu_sensitive(mainwin);
4374 static gboolean compose_use_attach(Compose *compose)
4376 GtkTreeModel *model = gtk_tree_view_get_model
4377 (GTK_TREE_VIEW(compose->attach_clist));
4378 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4381 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4384 gchar buf[BUFFSIZE];
4386 gboolean first_to_address;
4387 gboolean first_cc_address;
4389 ComposeHeaderEntry *headerentry;
4390 const gchar *headerentryname;
4394 debug_print("Writing redirect header\n");
4396 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4397 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4399 first_to_address = TRUE;
4400 for (list = compose->header_list; list; list = list->next) {
4401 headerentry = ((ComposeHeaderEntry *)list->data);
4402 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4404 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4405 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4406 Xstrdup_a(str, entstr, return -1);
4408 if (str[0] != '\0') {
4409 compose_convert_header
4410 (compose, buf, sizeof(buf), str,
4411 strlen("Resent-To") + 2, TRUE);
4413 if (first_to_address) {
4414 fprintf(fp, "Resent-To: ");
4415 first_to_address = FALSE;
4419 fprintf(fp, "%s", buf);
4423 if (!first_to_address) {
4427 first_cc_address = TRUE;
4428 for (list = compose->header_list; list; list = list->next) {
4429 headerentry = ((ComposeHeaderEntry *)list->data);
4430 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4432 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4433 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4434 Xstrdup_a(str, strg, return -1);
4436 if (str[0] != '\0') {
4437 compose_convert_header
4438 (compose, buf, sizeof(buf), str,
4439 strlen("Resent-Cc") + 2, TRUE);
4441 if (first_cc_address) {
4442 fprintf(fp, "Resent-Cc: ");
4443 first_cc_address = FALSE;
4447 fprintf(fp, "%s", buf);
4451 if (!first_cc_address) {
4458 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4460 gchar buf[BUFFSIZE];
4462 const gchar *entstr;
4463 /* struct utsname utsbuf; */
4465 g_return_val_if_fail(fp != NULL, -1);
4466 g_return_val_if_fail(compose->account != NULL, -1);
4467 g_return_val_if_fail(compose->account->address != NULL, -1);
4470 get_rfc822_date(buf, sizeof(buf));
4471 fprintf(fp, "Resent-Date: %s\n", buf);
4474 if (compose->account->name && *compose->account->name) {
4475 compose_convert_header
4476 (compose, buf, sizeof(buf), compose->account->name,
4477 strlen("From: "), TRUE);
4478 fprintf(fp, "Resent-From: %s <%s>\n",
4479 buf, compose->account->address);
4481 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4484 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4485 if (*entstr != '\0') {
4486 Xstrdup_a(str, entstr, return -1);
4489 compose_convert_header(compose, buf, sizeof(buf), str,
4490 strlen("Subject: "), FALSE);
4491 fprintf(fp, "Subject: %s\n", buf);
4495 /* Resent-Message-ID */
4496 if (compose->account->gen_msgid) {
4497 generate_msgid(buf, sizeof(buf));
4498 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4499 compose->msgid = g_strdup(buf);
4502 compose_redirect_write_headers_from_headerlist(compose, fp);
4504 /* separator between header and body */
4510 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4514 gchar buf[BUFFSIZE];
4516 gboolean skip = FALSE;
4517 gchar *not_included[]={
4518 "Return-Path:", "Delivered-To:", "Received:",
4519 "Subject:", "X-UIDL:", "AF:",
4520 "NF:", "PS:", "SRH:",
4521 "SFN:", "DSR:", "MID:",
4522 "CFG:", "PT:", "S:",
4523 "RQ:", "SSV:", "NSV:",
4524 "SSH:", "R:", "MAID:",
4525 "NAID:", "RMID:", "FMID:",
4526 "SCF:", "RRCPT:", "NG:",
4527 "X-Sylpheed-Privacy", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt",
4528 "X-Sylpheed-End-Special-Headers:",
4531 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4532 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4536 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4538 for (i = 0; not_included[i] != NULL; i++) {
4539 if (g_ascii_strncasecmp(buf, not_included[i],
4540 strlen(not_included[i])) == 0) {
4547 if (fputs(buf, fdest) == -1)
4550 if (!prefs_common.redirect_keep_from) {
4551 if (g_ascii_strncasecmp(buf, "From:",
4552 strlen("From:")) == 0) {
4553 fputs(" (by way of ", fdest);
4554 if (compose->account->name
4555 && *compose->account->name) {
4556 compose_convert_header
4557 (compose, buf, sizeof(buf),
4558 compose->account->name,
4561 fprintf(fdest, "%s <%s>",
4563 compose->account->address);
4565 fprintf(fdest, "%s",
4566 compose->account->address);
4571 if (fputs("\n", fdest) == -1)
4575 compose_redirect_write_headers(compose, fdest);
4577 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4578 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4591 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
4593 GtkTextBuffer *buffer;
4594 GtkTextIter start, end;
4597 const gchar *out_codeset;
4598 EncodingType encoding;
4599 MimeInfo *mimemsg, *mimetext;
4602 if (action == COMPOSE_WRITE_FOR_SEND)
4603 attach_parts = TRUE;
4605 /* create message MimeInfo */
4606 mimemsg = procmime_mimeinfo_new();
4607 mimemsg->type = MIMETYPE_MESSAGE;
4608 mimemsg->subtype = g_strdup("rfc822");
4609 mimemsg->content = MIMECONTENT_MEM;
4610 mimemsg->tmp = TRUE; /* must free content later */
4611 mimemsg->data.mem = compose_get_header(compose);
4613 /* Create text part MimeInfo */
4614 /* get all composed text */
4615 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4616 gtk_text_buffer_get_start_iter(buffer, &start);
4617 gtk_text_buffer_get_end_iter(buffer, &end);
4618 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4619 if (is_ascii_str(chars)) {
4622 out_codeset = CS_US_ASCII;
4623 encoding = ENC_7BIT;
4625 const gchar *src_codeset = CS_INTERNAL;
4627 out_codeset = conv_get_charset_str(compose->out_encoding);
4630 gchar *test_conv_global_out = NULL;
4631 gchar *test_conv_reply = NULL;
4633 /* automatic mode. be automatic. */
4634 codeconv_set_strict(TRUE);
4636 out_codeset = conv_get_outgoing_charset_str();
4638 debug_print("trying to convert to %s\n", out_codeset);
4639 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4642 if (!test_conv_global_out && compose->orig_charset
4643 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4644 out_codeset = compose->orig_charset;
4645 debug_print("failure; trying to convert to %s\n", out_codeset);
4646 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4649 if (!test_conv_global_out && !test_conv_reply) {
4651 out_codeset = CS_INTERNAL;
4652 debug_print("failure; finally using %s\n", out_codeset);
4654 g_free(test_conv_global_out);
4655 g_free(test_conv_reply);
4656 codeconv_set_strict(FALSE);
4659 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4660 out_codeset = CS_ISO_8859_1;
4662 if (prefs_common.encoding_method == CTE_BASE64)
4663 encoding = ENC_BASE64;
4664 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4665 encoding = ENC_QUOTED_PRINTABLE;
4666 else if (prefs_common.encoding_method == CTE_8BIT)
4667 encoding = ENC_8BIT;
4669 encoding = procmime_get_encoding_for_charset(out_codeset);
4671 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4672 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4674 if (action == COMPOSE_WRITE_FOR_SEND) {
4675 codeconv_set_strict(TRUE);
4676 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4677 codeconv_set_strict(FALSE);
4683 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4684 "to the specified %s charset.\n"
4685 "Send it as %s?"), out_codeset, src_codeset);
4686 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4687 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4690 if (aval != G_ALERTALTERNATE) {
4695 out_codeset = src_codeset;
4701 out_codeset = src_codeset;
4707 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4708 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4709 strstr(buf, "\nFrom ") != NULL) {
4710 encoding = ENC_QUOTED_PRINTABLE;
4714 mimetext = procmime_mimeinfo_new();
4715 mimetext->content = MIMECONTENT_MEM;
4716 mimetext->tmp = TRUE; /* must free content later */
4717 /* dup'ed because procmime_encode_content can turn it into a tmpfile
4718 * and free the data, which we need later. */
4719 mimetext->data.mem = g_strdup(buf);
4720 mimetext->type = MIMETYPE_TEXT;
4721 mimetext->subtype = g_strdup("plain");
4722 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4723 g_strdup(out_codeset));
4725 /* protect trailing spaces when signing message */
4726 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4727 privacy_system_can_sign(compose->privacy_system)) {
4728 encoding = ENC_QUOTED_PRINTABLE;
4731 debug_print("main text: %d bytes encoded as %s in %d\n",
4732 strlen(buf), out_codeset, encoding);
4734 /* check for line length limit */
4735 if (action == COMPOSE_WRITE_FOR_SEND &&
4736 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4737 check_line_length(buf, 1000, &line) < 0) {
4741 msg = g_strdup_printf
4742 (_("Line %d exceeds the line length limit (998 bytes).\n"
4743 "The contents of the message might be broken on the way to the delivery.\n"
4745 "Send it anyway?"), line + 1);
4746 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4748 if (aval != G_ALERTALTERNATE) {
4754 if (encoding != ENC_UNKNOWN)
4755 procmime_encode_content(mimetext, encoding);
4757 /* append attachment parts */
4758 if (compose_use_attach(compose) && attach_parts) {
4759 MimeInfo *mimempart;
4760 gchar *boundary = NULL;
4761 mimempart = procmime_mimeinfo_new();
4762 mimempart->content = MIMECONTENT_EMPTY;
4763 mimempart->type = MIMETYPE_MULTIPART;
4764 mimempart->subtype = g_strdup("mixed");
4768 boundary = generate_mime_boundary(NULL);
4769 } while (strstr(buf, boundary) != NULL);
4771 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4774 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4776 g_node_append(mimempart->node, mimetext->node);
4777 g_node_append(mimemsg->node, mimempart->node);
4779 compose_add_attachments(compose, mimempart);
4781 g_node_append(mimemsg->node, mimetext->node);
4785 /* sign message if sending */
4786 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4787 privacy_system_can_sign(compose->privacy_system))
4788 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4791 procmime_write_mimeinfo(mimemsg, fp);
4793 procmime_mimeinfo_free_all(mimemsg);
4798 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4800 GtkTextBuffer *buffer;
4801 GtkTextIter start, end;
4806 if ((fp = g_fopen(file, "wb")) == NULL) {
4807 FILE_OP_ERROR(file, "fopen");
4811 /* chmod for security */
4812 if (change_file_mode_rw(fp, file) < 0) {
4813 FILE_OP_ERROR(file, "chmod");
4814 g_warning("can't change file mode\n");
4817 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4818 gtk_text_buffer_get_start_iter(buffer, &start);
4819 gtk_text_buffer_get_end_iter(buffer, &end);
4820 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4822 chars = conv_codeset_strdup
4823 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4826 if (!chars) return -1;
4829 len = strlen(chars);
4830 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4831 FILE_OP_ERROR(file, "fwrite");
4840 if (fclose(fp) == EOF) {
4841 FILE_OP_ERROR(file, "fclose");
4848 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4851 MsgInfo *msginfo = compose->targetinfo;
4853 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4854 if (!msginfo) return -1;
4856 if (!force && MSG_IS_LOCKED(msginfo->flags))
4859 item = msginfo->folder;
4860 g_return_val_if_fail(item != NULL, -1);
4862 if (procmsg_msg_exist(msginfo) &&
4863 (folder_has_parent_of_type(item, F_QUEUE) ||
4864 folder_has_parent_of_type(item, F_DRAFT)
4865 || msginfo == compose->autosaved_draft)) {
4866 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4867 g_warning("can't remove the old message\n");
4875 void compose_remove_draft(Compose *compose)
4878 MsgInfo *msginfo = compose->targetinfo;
4879 drafts = account_get_special_folder(compose->account, F_DRAFT);
4881 if (procmsg_msg_exist(msginfo)) {
4882 folder_item_remove_msg(drafts, msginfo->msgnum);
4887 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
4888 gboolean remove_reedit_target)
4890 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
4892 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
4893 gchar **msgpath, gboolean check_subject,
4894 gboolean remove_reedit_target)
4901 static gboolean lock = FALSE;
4902 PrefsAccount *mailac = NULL, *newsac = NULL;
4904 debug_print("queueing message...\n");
4905 g_return_val_if_fail(compose->account != NULL, -1);
4909 if (compose_check_entries(compose, check_subject) == FALSE) {
4911 if (compose->batch) {
4912 gtk_widget_show_all(compose->window);
4917 if (!compose->to_list && !compose->newsgroup_list) {
4918 g_warning("can't get recipient list.");
4923 if (compose->to_list) {
4924 if (compose->account->protocol != A_NNTP)
4925 mailac = compose->account;
4926 else if (cur_account && cur_account->protocol != A_NNTP)
4927 mailac = cur_account;
4928 else if (!(mailac = compose_current_mail_account())) {
4930 alertpanel_error(_("No account for sending mails available!"));
4935 if (compose->newsgroup_list) {
4936 if (compose->account->protocol == A_NNTP)
4937 newsac = compose->account;
4938 else if (!newsac->protocol != A_NNTP) {
4940 alertpanel_error(_("No account for posting news available!"));
4945 /* write queue header */
4946 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4947 G_DIR_SEPARATOR, compose);
4948 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4949 FILE_OP_ERROR(tmp, "fopen");
4955 if (change_file_mode_rw(fp, tmp) < 0) {
4956 FILE_OP_ERROR(tmp, "chmod");
4957 g_warning("can't change file mode\n");
4960 /* queueing variables */
4961 fprintf(fp, "AF:\n");
4962 fprintf(fp, "NF:0\n");
4963 fprintf(fp, "PS:10\n");
4964 fprintf(fp, "SRH:1\n");
4965 fprintf(fp, "SFN:\n");
4966 fprintf(fp, "DSR:\n");
4968 fprintf(fp, "MID:<%s>\n", compose->msgid);
4970 fprintf(fp, "MID:\n");
4971 fprintf(fp, "CFG:\n");
4972 fprintf(fp, "PT:0\n");
4973 fprintf(fp, "S:%s\n", compose->account->address);
4974 fprintf(fp, "RQ:\n");
4976 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4978 fprintf(fp, "SSV:\n");
4980 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4982 fprintf(fp, "NSV:\n");
4983 fprintf(fp, "SSH:\n");
4984 /* write recepient list */
4985 if (compose->to_list) {
4986 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4987 for (cur = compose->to_list->next; cur != NULL;
4989 fprintf(fp, ",<%s>", (gchar *)cur->data);
4992 /* write newsgroup list */
4993 if (compose->newsgroup_list) {
4995 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4996 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4997 fprintf(fp, ",%s", (gchar *)cur->data);
5000 /* Sylpheed account IDs */
5002 fprintf(fp, "MAID:%d\n", mailac->account_id);
5004 fprintf(fp, "NAID:%d\n", newsac->account_id);
5007 if (compose->privacy_system != NULL) {
5008 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
5009 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
5010 if (compose->use_encryption) {
5012 if (mailac && mailac->encrypt_to_self) {
5013 GSList *tmp_list = g_slist_copy(compose->to_list);
5014 tmp_list = g_slist_append(tmp_list, compose->account->address);
5015 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
5016 g_slist_free(tmp_list);
5018 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
5020 if (encdata != NULL) {
5021 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
5022 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
5023 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
5025 } /* else we finally dont want to encrypt */
5027 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
5028 /* and if encdata was null, it means there's been a problem in
5040 /* Save copy folder */
5041 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
5042 gchar *savefolderid;
5044 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
5045 fprintf(fp, "SCF:%s\n", savefolderid);
5046 g_free(savefolderid);
5048 /* Save copy folder */
5049 if (compose->return_receipt) {
5050 fprintf(fp, "RRCPT:1\n");
5052 /* Message-ID of message replying to */
5053 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
5056 folderid = folder_item_get_identifier(compose->replyinfo->folder);
5057 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
5060 /* Message-ID of message forwarding to */
5061 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
5064 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
5065 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
5069 /* end of headers */
5070 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
5072 if (compose->redirect_filename != NULL) {
5073 if (compose_redirect_write_to_file(compose, fp) < 0) {
5082 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
5087 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
5091 if (fclose(fp) == EOF) {
5092 FILE_OP_ERROR(tmp, "fclose");
5099 if (item && *item) {
5102 queue = account_get_special_folder(compose->account, F_QUEUE);
5105 g_warning("can't find queue folder\n");
5111 folder_item_scan(queue);
5112 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
5113 g_warning("can't queue the message\n");
5120 if (msgpath == NULL) {
5126 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
5127 compose_remove_reedit_target(compose, FALSE);
5130 if ((msgnum != NULL) && (item != NULL)) {
5138 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
5141 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5143 struct stat statbuf;
5144 gchar *type, *subtype;
5145 GtkTreeModel *model;
5148 model = gtk_tree_view_get_model(tree_view);
5150 if (!gtk_tree_model_get_iter_first(model, &iter))
5153 gtk_tree_model_get(model, &iter,
5157 mimepart = procmime_mimeinfo_new();
5158 mimepart->content = MIMECONTENT_FILE;
5159 mimepart->data.filename = g_strdup(ainfo->file);
5160 mimepart->tmp = FALSE; /* or we destroy our attachment */
5161 mimepart->offset = 0;
5163 stat(ainfo->file, &statbuf);
5164 mimepart->length = statbuf.st_size;
5166 type = g_strdup(ainfo->content_type);
5168 if (!strchr(type, '/')) {
5170 type = g_strdup("application/octet-stream");
5173 subtype = strchr(type, '/') + 1;
5174 *(subtype - 1) = '\0';
5175 mimepart->type = procmime_get_media_type(type);
5176 mimepart->subtype = g_strdup(subtype);
5179 if (mimepart->type == MIMETYPE_MESSAGE &&
5180 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
5181 mimepart->disposition = DISPOSITIONTYPE_INLINE;
5184 g_hash_table_insert(mimepart->typeparameters,
5185 g_strdup("name"), g_strdup(ainfo->name));
5186 g_hash_table_insert(mimepart->dispositionparameters,
5187 g_strdup("filename"), g_strdup(ainfo->name));
5188 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
5192 if (compose->use_signing) {
5193 if (ainfo->encoding == ENC_7BIT)
5194 ainfo->encoding = ENC_QUOTED_PRINTABLE;
5195 else if (ainfo->encoding == ENC_8BIT)
5196 ainfo->encoding = ENC_BASE64;
5199 procmime_encode_content(mimepart, ainfo->encoding);
5201 g_node_append(parent->node, mimepart->node);
5202 } while (gtk_tree_model_iter_next(model, &iter));
5205 #define IS_IN_CUSTOM_HEADER(header) \
5206 (compose->account->add_customhdr && \
5207 custom_header_find(compose->account->customhdr_list, header) != NULL)
5209 static void compose_add_headerfield_from_headerlist(Compose *compose,
5211 const gchar *fieldname,
5212 const gchar *seperator)
5214 gchar *str, *fieldname_w_colon, *trans_fieldname;
5215 gboolean add_field = FALSE;
5217 ComposeHeaderEntry *headerentry;
5218 const gchar * headerentryname;
5221 if (IS_IN_CUSTOM_HEADER(fieldname))
5224 debug_print("Adding %s-fields\n", fieldname);
5226 fieldstr = g_string_sized_new(64);
5228 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
5229 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
5231 for (list = compose->header_list; list; list = list->next) {
5232 headerentry = ((ComposeHeaderEntry *)list->data);
5233 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
5235 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
5236 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
5238 if (str[0] != '\0') {
5240 g_string_append(fieldstr, seperator);
5241 g_string_append(fieldstr, str);
5250 buf = g_new0(gchar, fieldstr->len * 4 + 256);
5251 compose_convert_header
5252 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
5253 strlen(fieldname) + 2, TRUE);
5254 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
5258 g_free(fieldname_w_colon);
5259 g_string_free(fieldstr, TRUE);
5264 static gchar *compose_get_header(Compose *compose)
5266 gchar buf[BUFFSIZE];
5267 const gchar *entry_str;
5271 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5273 gchar *from_name = NULL, *from_address = NULL;
5276 g_return_val_if_fail(compose->account != NULL, NULL);
5277 g_return_val_if_fail(compose->account->address != NULL, NULL);
5279 header = g_string_sized_new(64);
5282 get_rfc822_date(buf, sizeof(buf));
5283 g_string_append_printf(header, "Date: %s\n", buf);
5287 if (compose->account->name && *compose->account->name) {
5289 QUOTE_IF_REQUIRED(buf, compose->account->name);
5290 tmp = g_strdup_printf("%s <%s>",
5291 buf, compose->account->address);
5293 tmp = g_strdup_printf("%s",
5294 compose->account->address);
5296 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5297 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5299 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5300 from_address = g_strdup(compose->account->address);
5302 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5303 /* extract name and address */
5304 if (strstr(spec, " <") && strstr(spec, ">")) {
5305 from_address = g_strdup(strrchr(spec, '<')+1);
5306 *(strrchr(from_address, '>')) = '\0';
5307 from_name = g_strdup(spec);
5308 *(strrchr(from_name, '<')) = '\0';
5311 from_address = g_strdup(spec);
5318 if (from_name && *from_name) {
5319 compose_convert_header
5320 (compose, buf, sizeof(buf), from_name,
5321 strlen("From: "), TRUE);
5322 QUOTE_IF_REQUIRED(name, buf);
5324 g_string_append_printf(header, "From: %s <%s>\n",
5325 name, from_address);
5327 g_string_append_printf(header, "From: %s\n", from_address);
5330 g_free(from_address);
5333 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5336 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5339 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5342 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5345 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5347 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5350 compose_convert_header(compose, buf, sizeof(buf), str,
5351 strlen("Subject: "), FALSE);
5352 g_string_append_printf(header, "Subject: %s\n", buf);
5358 if (compose->account->gen_msgid) {
5359 generate_msgid(buf, sizeof(buf));
5360 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5361 compose->msgid = g_strdup(buf);
5364 if (compose->remove_references == FALSE) {
5366 if (compose->inreplyto && compose->to_list)
5367 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5370 if (compose->references)
5371 g_string_append_printf(header, "References: %s\n", compose->references);
5375 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5378 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5381 if (compose->account->organization &&
5382 strlen(compose->account->organization) &&
5383 !IS_IN_CUSTOM_HEADER("Organization")) {
5384 compose_convert_header(compose, buf, sizeof(buf),
5385 compose->account->organization,
5386 strlen("Organization: "), FALSE);
5387 g_string_append_printf(header, "Organization: %s\n", buf);
5390 /* Program version and system info */
5391 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5392 !compose->newsgroup_list) {
5393 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5395 gtk_major_version, gtk_minor_version, gtk_micro_version,
5398 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5399 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5401 gtk_major_version, gtk_minor_version, gtk_micro_version,
5405 /* custom headers */
5406 if (compose->account->add_customhdr) {
5409 for (cur = compose->account->customhdr_list; cur != NULL;
5411 CustomHeader *chdr = (CustomHeader *)cur->data;
5413 if (custom_header_is_allowed(chdr->name)) {
5414 compose_convert_header
5415 (compose, buf, sizeof(buf),
5416 chdr->value ? chdr->value : "",
5417 strlen(chdr->name) + 2, FALSE);
5418 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5424 switch (compose->priority) {
5425 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5426 "X-Priority: 1 (Highest)\n");
5428 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5429 "X-Priority: 2 (High)\n");
5431 case PRIORITY_NORMAL: break;
5432 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5433 "X-Priority: 4 (Low)\n");
5435 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5436 "X-Priority: 5 (Lowest)\n");
5438 default: debug_print("compose: priority unknown : %d\n",
5442 /* Request Return Receipt */
5443 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5444 if (compose->return_receipt) {
5445 if (compose->account->name
5446 && *compose->account->name) {
5447 compose_convert_header(compose, buf, sizeof(buf),
5448 compose->account->name,
5449 strlen("Disposition-Notification-To: "),
5451 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5453 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5457 /* get special headers */
5458 for (list = compose->header_list; list; list = list->next) {
5459 ComposeHeaderEntry *headerentry;
5462 gchar *headername_wcolon;
5463 gchar *headername_trans;
5466 gboolean standard_header = FALSE;
5468 headerentry = ((ComposeHeaderEntry *)list->data);
5470 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5471 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5476 if (!strstr(tmp, ":")) {
5477 headername_wcolon = g_strconcat(tmp, ":", NULL);
5478 headername = g_strdup(tmp);
5480 headername_wcolon = g_strdup(tmp);
5481 headername = g_strdup(strtok(tmp, ":"));
5485 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5486 Xstrdup_a(headervalue, entry_str, return NULL);
5487 subst_char(headervalue, '\r', ' ');
5488 subst_char(headervalue, '\n', ' ');
5489 string = std_headers;
5490 while (*string != NULL) {
5491 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5492 if (!strcmp(headername_trans,headername_wcolon))
5493 standard_header = TRUE;
5496 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5497 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5500 g_free(headername_wcolon);
5504 g_string_free(header, FALSE);
5509 #undef IS_IN_CUSTOM_HEADER
5511 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5512 gint header_len, gboolean addr_field)
5514 gchar *tmpstr = NULL;
5515 const gchar *out_codeset = NULL;
5517 g_return_if_fail(src != NULL);
5518 g_return_if_fail(dest != NULL);
5520 if (len < 1) return;
5522 tmpstr = g_strdup(src);
5524 subst_char(tmpstr, '\n', ' ');
5525 subst_char(tmpstr, '\r', ' ');
5528 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5529 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5530 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5535 codeconv_set_strict(TRUE);
5536 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5537 conv_get_charset_str(compose->out_encoding));
5538 codeconv_set_strict(FALSE);
5540 if (!dest || *dest == '\0') {
5541 gchar *test_conv_global_out = NULL;
5542 gchar *test_conv_reply = NULL;
5544 /* automatic mode. be automatic. */
5545 codeconv_set_strict(TRUE);
5547 out_codeset = conv_get_outgoing_charset_str();
5549 debug_print("trying to convert to %s\n", out_codeset);
5550 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5553 if (!test_conv_global_out && compose->orig_charset
5554 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5555 out_codeset = compose->orig_charset;
5556 debug_print("failure; trying to convert to %s\n", out_codeset);
5557 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5560 if (!test_conv_global_out && !test_conv_reply) {
5562 out_codeset = CS_INTERNAL;
5563 debug_print("finally using %s\n", out_codeset);
5565 g_free(test_conv_global_out);
5566 g_free(test_conv_reply);
5567 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5569 codeconv_set_strict(FALSE);
5574 static void compose_create_header_entry(Compose *compose)
5576 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5580 GList *combo_list = NULL;
5582 const gchar *header = NULL;
5583 ComposeHeaderEntry *headerentry;
5584 gboolean standard_header = FALSE;
5586 headerentry = g_new0(ComposeHeaderEntry, 1);
5589 combo = gtk_combo_new();
5591 while(*string != NULL) {
5592 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5595 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5596 g_list_free(combo_list);
5597 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5598 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5599 G_CALLBACK(compose_grab_focus_cb), compose);
5600 gtk_widget_show(combo);
5601 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5602 if (compose->header_last) {
5603 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5605 while (*string != NULL) {
5606 if (!strcmp(*string, last_header_entry))
5607 standard_header = TRUE;
5610 if (standard_header)
5611 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5613 if (!compose->header_last || !standard_header) {
5614 switch(compose->account->protocol) {
5616 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5619 header = prefs_common.trans_hdr ? _("To:") : "To:";
5624 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5626 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5627 G_CALLBACK(compose_grab_focus_cb), compose);
5630 entry = gtk_entry_new();
5631 gtk_widget_show(entry);
5632 gtk_tooltips_set_tip(compose->tooltips, entry,
5633 _("Use <tab> to autocomplete from addressbook"), NULL);
5634 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);
5636 g_signal_connect(G_OBJECT(entry), "key-press-event",
5637 G_CALLBACK(compose_headerentry_key_press_event_cb),
5639 g_signal_connect(G_OBJECT(entry), "changed",
5640 G_CALLBACK(compose_headerentry_changed_cb),
5642 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5643 G_CALLBACK(compose_grab_focus_cb), compose);
5646 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5647 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5648 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5649 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5650 G_CALLBACK(compose_header_drag_received_cb),
5652 g_signal_connect(G_OBJECT(entry), "drag-drop",
5653 G_CALLBACK(compose_drag_drop),
5656 address_completion_register_entry(GTK_ENTRY(entry), TRUE);
5658 headerentry->compose = compose;
5659 headerentry->combo = combo;
5660 headerentry->entry = entry;
5661 headerentry->headernum = compose->header_nextrow;
5663 compose->header_nextrow++;
5664 compose->header_last = headerentry;
5667 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5669 ComposeHeaderEntry *last_header;
5671 last_header = compose->header_last;
5673 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5674 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5677 static void compose_remove_header_entries(Compose *compose)
5680 for (list = compose->header_list; list; list = list->next) {
5681 ComposeHeaderEntry *headerentry =
5682 (ComposeHeaderEntry *)list->data;
5683 gtk_widget_destroy(headerentry->combo);
5684 gtk_widget_destroy(headerentry->entry);
5685 g_free(headerentry);
5687 g_slist_free(compose->header_list);
5688 compose->header_list = NULL;
5689 compose->header_nextrow = 1;
5690 compose_create_header_entry(compose);
5693 static GtkWidget *compose_create_header(Compose *compose)
5695 GtkWidget *from_optmenu_hbox;
5696 GtkWidget *header_scrolledwin;
5697 GtkWidget *header_table;
5701 /* header labels and entries */
5702 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5703 gtk_widget_show(header_scrolledwin);
5704 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5706 header_table = gtk_table_new(2, 2, FALSE);
5707 gtk_widget_show(header_table);
5708 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5709 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5710 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5713 /* option menu for selecting accounts */
5714 from_optmenu_hbox = compose_account_option_menu_create(compose);
5715 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5716 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5719 compose->header_table = header_table;
5720 compose->header_list = NULL;
5721 compose->header_nextrow = count;
5723 compose_create_header_entry(compose);
5725 compose->table = NULL;
5727 return header_scrolledwin ;
5730 GtkWidget *compose_create_attach(Compose *compose)
5732 GtkWidget *attach_scrwin;
5733 GtkWidget *attach_clist;
5735 GtkListStore *store;
5736 GtkCellRenderer *renderer;
5737 GtkTreeViewColumn *column;
5738 GtkTreeSelection *selection;
5740 /* attachment list */
5741 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5742 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5743 GTK_POLICY_AUTOMATIC,
5744 GTK_POLICY_AUTOMATIC);
5745 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5747 store = gtk_list_store_new(N_ATTACH_COLS,
5752 G_TYPE_AUTO_POINTER,
5754 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5755 (GTK_TREE_MODEL(store)));
5756 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5757 g_object_unref(store);
5759 renderer = gtk_cell_renderer_text_new();
5760 column = gtk_tree_view_column_new_with_attributes
5761 (_("Mime type"), renderer, "text",
5762 COL_MIMETYPE, NULL);
5763 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5765 renderer = gtk_cell_renderer_text_new();
5766 column = gtk_tree_view_column_new_with_attributes
5767 (_("Size"), renderer, "text",
5769 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5771 renderer = gtk_cell_renderer_text_new();
5772 column = gtk_tree_view_column_new_with_attributes
5773 (_("Name"), renderer, "text",
5775 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5777 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5778 prefs_common.use_stripes_everywhere);
5779 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5780 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5782 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5783 G_CALLBACK(attach_selected), compose);
5784 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5785 G_CALLBACK(attach_button_pressed), compose);
5786 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5787 G_CALLBACK(attach_key_pressed), compose);
5790 gtk_drag_dest_set(attach_clist,
5791 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5792 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5793 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5794 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5795 G_CALLBACK(compose_attach_drag_received_cb),
5797 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5798 G_CALLBACK(compose_drag_drop),
5801 compose->attach_scrwin = attach_scrwin;
5802 compose->attach_clist = attach_clist;
5804 return attach_scrwin;
5807 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5808 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5810 static GtkWidget *compose_create_others(Compose *compose)
5813 GtkWidget *savemsg_checkbtn;
5814 GtkWidget *savemsg_entry;
5815 GtkWidget *savemsg_select;
5818 gchar *folderidentifier;
5820 /* Table for settings */
5821 table = gtk_table_new(3, 1, FALSE);
5822 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5823 gtk_widget_show(table);
5824 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5827 /* Save Message to folder */
5828 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5829 gtk_widget_show(savemsg_checkbtn);
5830 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5831 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5832 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5834 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5835 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5837 savemsg_entry = gtk_entry_new();
5838 gtk_widget_show(savemsg_entry);
5839 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5840 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5841 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5842 G_CALLBACK(compose_grab_focus_cb), compose);
5843 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5844 folderidentifier = folder_item_get_identifier(account_get_special_folder
5845 (compose->account, F_OUTBOX));
5846 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5847 g_free(folderidentifier);
5850 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5851 gtk_widget_show(savemsg_select);
5852 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5853 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5854 G_CALLBACK(compose_savemsg_select_cb),
5859 compose->savemsg_checkbtn = savemsg_checkbtn;
5860 compose->savemsg_entry = savemsg_entry;
5865 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5867 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5868 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5871 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5876 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5879 path = folder_item_get_identifier(dest);
5881 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5885 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5886 GdkAtom clip, GtkTextIter *insert_place);
5888 #define BLOCK_WRAP() { \
5889 prev_autowrap = compose->autowrap; \
5890 buffer = gtk_text_view_get_buffer( \
5891 GTK_TEXT_VIEW(compose->text)); \
5892 compose->autowrap = FALSE; \
5894 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5895 G_CALLBACK(compose_changed_cb), \
5897 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5898 G_CALLBACK(text_inserted), \
5901 #define UNBLOCK_WRAP() { \
5902 compose->autowrap = prev_autowrap; \
5903 if (compose->autowrap) \
5904 compose_wrap_all(compose); \
5906 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5907 G_CALLBACK(compose_changed_cb), \
5909 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5910 G_CALLBACK(text_inserted), \
5915 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5919 GtkTextBuffer *buffer;
5921 if (event->button == 3) {
5923 GtkTextIter sel_start, sel_end;
5924 gboolean stuff_selected;
5926 /* move the cursor to allow GtkAspell to check the word
5927 * under the mouse */
5928 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5929 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5931 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5934 stuff_selected = gtk_text_buffer_get_selection_bounds(
5935 GTK_TEXT_VIEW(text)->buffer,
5936 &sel_start, &sel_end);
5938 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5939 /* reselect stuff */
5941 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5942 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5943 &sel_start, &sel_end);
5945 return FALSE; /* pass the event so that the right-click goes through */
5948 if (event->button == 2) {
5953 /* get the middle-click position to paste at the correct place */
5954 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5955 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5957 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5960 entry_paste_clipboard(compose, text,
5961 prefs_common.linewrap_pastes,
5962 GDK_SELECTION_PRIMARY, &iter);
5970 static void compose_spell_menu_changed(void *data)
5972 Compose *compose = (Compose *)data;
5974 GtkWidget *menuitem;
5975 GtkWidget *parent_item;
5976 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5977 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5980 if (compose->gtkaspell == NULL)
5983 parent_item = gtk_item_factory_get_item(ifactory,
5984 "/Spelling/Options");
5986 /* setting the submenu removes /Spelling/Options from the factory
5987 * so we need to save it */
5989 if (parent_item == NULL) {
5990 parent_item = compose->aspell_options_menu;
5991 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5993 compose->aspell_options_menu = parent_item;
5995 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5997 spell_menu = g_slist_reverse(spell_menu);
5998 for (items = spell_menu;
5999 items; items = items->next) {
6000 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
6001 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
6002 gtk_widget_show(GTK_WIDGET(menuitem));
6004 g_slist_free(spell_menu);
6006 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
6011 static gboolean compose_force_window_origin = TRUE;
6012 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
6019 GtkWidget *handlebox;
6021 GtkWidget *notebook;
6026 GtkWidget *subject_hbox;
6027 GtkWidget *subject_frame;
6028 GtkWidget *subject_entry;
6032 GtkWidget *edit_vbox;
6033 GtkWidget *ruler_hbox;
6035 GtkWidget *scrolledwin;
6037 GtkTextBuffer *buffer;
6038 GtkClipboard *clipboard;
6040 UndoMain *undostruct;
6042 gchar *titles[N_ATTACH_COLS];
6043 guint n_menu_entries;
6044 GtkWidget *popupmenu;
6045 GtkItemFactory *popupfactory;
6046 GtkItemFactory *ifactory;
6047 GtkWidget *tmpl_menu;
6049 GtkWidget *menuitem;
6052 GtkAspell * gtkaspell = NULL;
6055 static GdkGeometry geometry;
6057 g_return_val_if_fail(account != NULL, NULL);
6059 debug_print("Creating compose window...\n");
6060 compose = g_new0(Compose, 1);
6062 titles[COL_MIMETYPE] = _("MIME type");
6063 titles[COL_SIZE] = _("Size");
6064 titles[COL_NAME] = _("Name");
6066 compose->batch = batch;
6067 compose->account = account;
6069 compose->mutex = g_mutex_new();
6070 compose->set_cursor_pos = -1;
6072 compose->tooltips = gtk_tooltips_new();
6074 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6075 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
6076 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
6078 if (!geometry.max_width) {
6079 geometry.max_width = gdk_screen_width();
6080 geometry.max_height = gdk_screen_height();
6083 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
6084 &geometry, GDK_HINT_MAX_SIZE);
6085 if (!geometry.min_width) {
6086 geometry.min_width = 600;
6087 geometry.min_height = 480;
6089 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
6090 &geometry, GDK_HINT_MIN_SIZE);
6092 if (compose_force_window_origin)
6093 gtk_widget_set_uposition(window, prefs_common.compose_x,
6094 prefs_common.compose_y);
6096 g_signal_connect(G_OBJECT(window), "delete_event",
6097 G_CALLBACK(compose_delete_cb), compose);
6098 MANAGE_WINDOW_SIGNALS_CONNECT(window);
6099 gtk_widget_realize(window);
6101 gtkut_widget_set_composer_icon(window);
6103 vbox = gtk_vbox_new(FALSE, 0);
6104 gtk_container_add(GTK_CONTAINER(window), vbox);
6106 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
6107 menubar = menubar_create(window, compose_entries,
6108 n_menu_entries, "<Compose>", compose);
6109 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
6111 if (prefs_common.toolbar_detachable) {
6112 handlebox = gtk_handle_box_new();
6114 handlebox = gtk_hbox_new(FALSE, 0);
6116 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
6118 gtk_widget_realize(handlebox);
6119 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
6122 vbox2 = gtk_vbox_new(FALSE, 2);
6123 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
6124 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
6127 notebook = gtk_notebook_new();
6128 gtk_widget_set_size_request(notebook, -1, 130);
6129 gtk_widget_show(notebook);
6131 /* header labels and entries */
6132 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6133 compose_create_header(compose),
6134 gtk_label_new_with_mnemonic(_("Hea_der")));
6135 /* attachment list */
6136 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6137 compose_create_attach(compose),
6138 gtk_label_new_with_mnemonic(_("_Attachments")));
6140 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6141 compose_create_others(compose),
6142 gtk_label_new_with_mnemonic(_("Othe_rs")));
6145 subject_hbox = gtk_hbox_new(FALSE, 0);
6146 gtk_widget_show(subject_hbox);
6148 subject_frame = gtk_frame_new(NULL);
6149 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
6150 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
6151 gtk_widget_show(subject_frame);
6153 subject = gtk_hbox_new(FALSE, 0);
6154 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
6155 gtk_widget_show(subject);
6157 label = gtk_label_new(_("Subject:"));
6158 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
6159 gtk_widget_show(label);
6161 subject_entry = gtk_entry_new();
6162 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
6163 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
6164 G_CALLBACK(compose_grab_focus_cb), compose);
6165 gtk_widget_show(subject_entry);
6166 compose->subject_entry = subject_entry;
6167 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
6169 edit_vbox = gtk_vbox_new(FALSE, 0);
6171 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
6174 ruler_hbox = gtk_hbox_new(FALSE, 0);
6175 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
6177 ruler = gtk_shruler_new();
6178 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
6179 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
6183 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
6184 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
6185 GTK_POLICY_AUTOMATIC,
6186 GTK_POLICY_AUTOMATIC);
6187 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
6189 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
6190 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
6192 text = gtk_text_view_new();
6193 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6194 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
6195 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
6196 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
6197 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
6199 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
6201 g_signal_connect_after(G_OBJECT(text), "size_allocate",
6202 G_CALLBACK(compose_edit_size_alloc),
6204 g_signal_connect(G_OBJECT(buffer), "changed",
6205 G_CALLBACK(compose_changed_cb), compose);
6206 g_signal_connect(G_OBJECT(text), "grab_focus",
6207 G_CALLBACK(compose_grab_focus_cb), compose);
6208 g_signal_connect(G_OBJECT(buffer), "insert_text",
6209 G_CALLBACK(text_inserted), compose);
6210 g_signal_connect(G_OBJECT(text), "button_press_event",
6211 G_CALLBACK(text_clicked), compose);
6212 g_signal_connect(G_OBJECT(subject_entry), "changed",
6213 G_CALLBACK(compose_changed_cb), compose);
6216 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
6217 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
6218 GDK_ACTION_COPY | GDK_ACTION_MOVE);
6219 g_signal_connect(G_OBJECT(text), "drag_data_received",
6220 G_CALLBACK(compose_insert_drag_received_cb),
6222 g_signal_connect(G_OBJECT(text), "drag-drop",
6223 G_CALLBACK(compose_drag_drop),
6225 gtk_widget_show_all(vbox);
6227 /* pane between attach clist and text */
6228 paned = gtk_vpaned_new();
6229 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
6230 gtk_container_add(GTK_CONTAINER(vbox2), paned);
6231 gtk_paned_add1(GTK_PANED(paned), notebook);
6232 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
6233 gtk_widget_show_all(paned);
6236 if (prefs_common.textfont) {
6237 PangoFontDescription *font_desc;
6239 font_desc = pango_font_description_from_string
6240 (prefs_common.textfont);
6242 gtk_widget_modify_font(text, font_desc);
6243 pango_font_description_free(font_desc);
6247 n_entries = sizeof(compose_popup_entries) /
6248 sizeof(compose_popup_entries[0]);
6249 popupmenu = menu_create_items(compose_popup_entries, n_entries,
6250 "<Compose>", &popupfactory,
6253 ifactory = gtk_item_factory_from_widget(menubar);
6254 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6255 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6256 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
6258 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6260 undostruct = undo_init(text);
6261 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
6264 address_completion_start(window);
6266 compose->window = window;
6267 compose->vbox = vbox;
6268 compose->menubar = menubar;
6269 compose->handlebox = handlebox;
6271 compose->vbox2 = vbox2;
6273 compose->paned = paned;
6275 compose->edit_vbox = edit_vbox;
6276 compose->ruler_hbox = ruler_hbox;
6277 compose->ruler = ruler;
6278 compose->scrolledwin = scrolledwin;
6279 compose->text = text;
6281 compose->focused_editable = NULL;
6283 compose->popupmenu = popupmenu;
6284 compose->popupfactory = popupfactory;
6286 compose->tmpl_menu = tmpl_menu;
6288 compose->mode = mode;
6289 compose->rmode = mode;
6291 compose->targetinfo = NULL;
6292 compose->replyinfo = NULL;
6293 compose->fwdinfo = NULL;
6295 compose->replyto = NULL;
6297 compose->bcc = NULL;
6298 compose->followup_to = NULL;
6300 compose->ml_post = NULL;
6302 compose->inreplyto = NULL;
6303 compose->references = NULL;
6304 compose->msgid = NULL;
6305 compose->boundary = NULL;
6307 compose->autowrap = prefs_common.autowrap;
6309 compose->use_signing = FALSE;
6310 compose->use_encryption = FALSE;
6311 compose->privacy_system = NULL;
6313 compose->modified = FALSE;
6315 compose->return_receipt = FALSE;
6317 compose->to_list = NULL;
6318 compose->newsgroup_list = NULL;
6320 compose->undostruct = undostruct;
6322 compose->sig_str = NULL;
6324 compose->exteditor_file = NULL;
6325 compose->exteditor_pid = -1;
6326 compose->exteditor_tag = -1;
6327 compose->draft_timeout_tag = -1;
6330 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6331 if (mode != COMPOSE_REDIRECT) {
6332 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6333 strcmp(prefs_common.dictionary, "")) {
6334 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6335 prefs_common.dictionary,
6336 conv_get_locale_charset_str(),
6337 prefs_common.misspelled_col,
6338 prefs_common.check_while_typing,
6339 prefs_common.recheck_when_changing_dict,
6340 prefs_common.use_alternate,
6341 GTK_TEXT_VIEW(text),
6342 GTK_WINDOW(compose->window),
6343 compose_spell_menu_changed,
6346 alertpanel_error(_("Spell checker could not "
6348 gtkaspell_checkers_strerror());
6349 gtkaspell_checkers_reset_error();
6351 if (!gtkaspell_set_sug_mode(gtkaspell,
6352 prefs_common.aspell_sugmode)) {
6353 debug_print("Aspell: could not set "
6354 "suggestion mode %s\n",
6355 gtkaspell_checkers_strerror());
6356 gtkaspell_checkers_reset_error();
6359 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6363 compose->gtkaspell = gtkaspell;
6364 compose_spell_menu_changed(compose);
6367 compose_select_account(compose, account, TRUE);
6369 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6370 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6371 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6373 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6374 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6376 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6377 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6379 menu_set_sensitive(ifactory, "/Options/Reply mode", compose->mode == COMPOSE_REPLY);
6381 if (account->protocol != A_NNTP)
6382 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6384 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6386 addressbook_set_target_compose(compose);
6388 if (mode != COMPOSE_REDIRECT)
6389 compose_set_template_menu(compose);
6391 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6392 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6395 compose_list = g_list_append(compose_list, compose);
6397 if (!prefs_common.show_ruler)
6398 gtk_widget_hide(ruler_hbox);
6400 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6401 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6402 prefs_common.show_ruler);
6405 compose->priority = PRIORITY_NORMAL;
6406 compose_update_priority_menu_item(compose);
6408 compose_set_out_encoding(compose);
6411 compose_update_actions_menu(compose);
6413 /* Privacy Systems menu */
6414 compose_update_privacy_systems_menu(compose);
6416 activate_privacy_system(compose, account, TRUE);
6417 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6419 gtk_widget_realize(window);
6421 gtk_widget_show(window);
6427 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6432 GtkWidget *optmenubox;
6435 GtkWidget *from_name = NULL;
6437 gint num = 0, def_menu = 0;
6439 accounts = account_get_list();
6440 g_return_val_if_fail(accounts != NULL, NULL);
6442 optmenubox = gtk_event_box_new();
6443 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
6444 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
6446 hbox = gtk_hbox_new(FALSE, 6);
6447 from_name = gtk_entry_new();
6449 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6450 G_CALLBACK(compose_grab_focus_cb), compose);
6452 for (; accounts != NULL; accounts = accounts->next, num++) {
6453 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6454 gchar *name, *from = NULL;
6456 if (ac == compose->account) def_menu = num;
6458 name = g_markup_printf_escaped(_("From: <i>%s</i>"),
6461 if (ac == compose->account) {
6462 if (ac->name && *ac->name) {
6464 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6465 from = g_strdup_printf("%s <%s>",
6467 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6469 from = g_strdup_printf("%s",
6471 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6474 COMBOBOX_ADD(menu, name, ac->account_id);
6479 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
6481 g_signal_connect(G_OBJECT(optmenu), "changed",
6482 G_CALLBACK(account_activated),
6485 gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
6486 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6488 gtk_tooltips_set_tip(compose->tooltips, optmenubox,
6489 _("Account to use for this email"), NULL);
6490 gtk_tooltips_set_tip(compose->tooltips, from_name,
6491 _("Sender address to be used"), NULL);
6493 compose->from_name = from_name;
6498 static void compose_set_priority_cb(gpointer data,
6502 Compose *compose = (Compose *) data;
6503 compose->priority = action;
6506 static void compose_reply_change_mode(gpointer data,
6510 Compose *compose = (Compose *) data;
6511 gboolean was_modified = compose->modified;
6513 gboolean all = FALSE, ml = FALSE, sender = FALSE, followup = FALSE;
6514 if (compose->mode != COMPOSE_REPLY)
6516 g_return_if_fail(compose->replyinfo != NULL);
6518 if (action == COMPOSE_REPLY && prefs_common.default_reply_list)
6520 if (action == COMPOSE_REPLY && compose->rmode == COMPOSE_FOLLOWUP_AND_REPLY_TO)
6522 if (action == COMPOSE_REPLY_TO_ALL)
6524 if (action == COMPOSE_REPLY_TO_SENDER)
6526 if (action == COMPOSE_REPLY_TO_LIST)
6529 compose_remove_header_entries(compose);
6530 compose_reply_set_entry(compose, compose->replyinfo, all, ml, sender, followup);
6531 compose_show_first_last_header(compose, TRUE);
6532 compose->modified = was_modified;
6533 compose_set_title(compose);
6536 static void compose_update_priority_menu_item(Compose * compose)
6538 GtkItemFactory *ifactory;
6539 GtkWidget *menuitem = NULL;
6541 ifactory = gtk_item_factory_from_widget(compose->menubar);
6543 switch (compose->priority) {
6544 case PRIORITY_HIGHEST:
6545 menuitem = gtk_item_factory_get_item
6546 (ifactory, "/Options/Priority/Highest");
6549 menuitem = gtk_item_factory_get_item
6550 (ifactory, "/Options/Priority/High");
6552 case PRIORITY_NORMAL:
6553 menuitem = gtk_item_factory_get_item
6554 (ifactory, "/Options/Priority/Normal");
6557 menuitem = gtk_item_factory_get_item
6558 (ifactory, "/Options/Priority/Low");
6560 case PRIORITY_LOWEST:
6561 menuitem = gtk_item_factory_get_item
6562 (ifactory, "/Options/Priority/Lowest");
6565 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6568 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6570 Compose *compose = (Compose *) data;
6572 GtkItemFactory *ifactory;
6573 gboolean can_sign = FALSE, can_encrypt = FALSE;
6575 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6577 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6580 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6581 g_free(compose->privacy_system);
6582 compose->privacy_system = NULL;
6583 if (systemid != NULL) {
6584 compose->privacy_system = g_strdup(systemid);
6586 can_sign = privacy_system_can_sign(systemid);
6587 can_encrypt = privacy_system_can_encrypt(systemid);
6590 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6592 ifactory = gtk_item_factory_from_widget(compose->menubar);
6593 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6594 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6597 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6599 static gchar *branch_path = "/Options/Privacy System";
6600 GtkItemFactory *ifactory;
6601 GtkWidget *menuitem = NULL;
6603 gboolean can_sign = FALSE, can_encrypt = FALSE;
6604 gboolean found = FALSE;
6606 ifactory = gtk_item_factory_from_widget(compose->menubar);
6608 if (compose->privacy_system != NULL) {
6611 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6612 g_return_if_fail(menuitem != NULL);
6614 amenu = GTK_MENU_SHELL(menuitem)->children;
6616 while (amenu != NULL) {
6617 GList *alist = amenu->next;
6619 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6620 if (systemid != NULL) {
6621 if (strcmp(systemid, compose->privacy_system) == 0) {
6622 menuitem = GTK_WIDGET(amenu->data);
6624 can_sign = privacy_system_can_sign(systemid);
6625 can_encrypt = privacy_system_can_encrypt(systemid);
6629 } else if (strlen(compose->privacy_system) == 0) {
6630 menuitem = GTK_WIDGET(amenu->data);
6633 can_encrypt = FALSE;
6640 if (menuitem != NULL)
6641 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6643 if (warn && !found && strlen(compose->privacy_system)) {
6644 gchar *tmp = g_strdup_printf(
6645 _("The privacy system '%s' cannot be loaded. You "
6646 "will not be able to sign or encrypt this message."),
6647 compose->privacy_system);
6648 alertpanel_warning(tmp);
6653 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6654 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6657 static void compose_set_out_encoding(Compose *compose)
6659 GtkItemFactoryEntry *entry;
6660 GtkItemFactory *ifactory;
6661 CharSet out_encoding;
6662 gchar *path, *p, *q;
6665 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6666 ifactory = gtk_item_factory_from_widget(compose->menubar);
6668 for (entry = compose_entries; entry->callback != compose_address_cb;
6670 if (entry->callback == compose_set_encoding_cb &&
6671 (CharSet)entry->callback_action == out_encoding) {
6672 p = q = path = g_strdup(entry->path);
6684 item = gtk_item_factory_get_item(ifactory, path);
6685 gtk_widget_activate(item);
6692 static void compose_set_template_menu(Compose *compose)
6694 GSList *tmpl_list, *cur;
6698 tmpl_list = template_get_config();
6700 menu = gtk_menu_new();
6702 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6703 Template *tmpl = (Template *)cur->data;
6705 item = gtk_menu_item_new_with_label(tmpl->name);
6706 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6707 g_signal_connect(G_OBJECT(item), "activate",
6708 G_CALLBACK(compose_template_activate_cb),
6710 g_object_set_data(G_OBJECT(item), "template", tmpl);
6711 gtk_widget_show(item);
6714 gtk_widget_show(menu);
6715 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6718 void compose_update_actions_menu(Compose *compose)
6720 GtkItemFactory *ifactory;
6722 ifactory = gtk_item_factory_from_widget(compose->menubar);
6723 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6726 void compose_update_privacy_systems_menu(Compose *compose)
6728 static gchar *branch_path = "/Options/Privacy System";
6729 GtkItemFactory *ifactory;
6730 GtkWidget *menuitem;
6731 GSList *systems, *cur;
6734 GtkWidget *system_none;
6737 ifactory = gtk_item_factory_from_widget(compose->menubar);
6739 /* remove old entries */
6740 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6741 g_return_if_fail(menuitem != NULL);
6743 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6744 while (amenu != NULL) {
6745 GList *alist = amenu->next;
6746 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6750 system_none = gtk_item_factory_get_widget(ifactory,
6751 "/Options/Privacy System/None");
6753 g_signal_connect(G_OBJECT(system_none), "activate",
6754 G_CALLBACK(compose_set_privacy_system_cb), compose);
6756 systems = privacy_get_system_ids();
6757 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6758 gchar *systemid = cur->data;
6760 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6761 widget = gtk_radio_menu_item_new_with_label(group,
6762 privacy_system_get_name(systemid));
6763 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6764 g_strdup(systemid), g_free);
6765 g_signal_connect(G_OBJECT(widget), "activate",
6766 G_CALLBACK(compose_set_privacy_system_cb), compose);
6768 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6769 gtk_widget_show(widget);
6772 g_slist_free(systems);
6775 void compose_reflect_prefs_all(void)
6780 for (cur = compose_list; cur != NULL; cur = cur->next) {
6781 compose = (Compose *)cur->data;
6782 compose_set_template_menu(compose);
6786 void compose_reflect_prefs_pixmap_theme(void)
6791 for (cur = compose_list; cur != NULL; cur = cur->next) {
6792 compose = (Compose *)cur->data;
6793 toolbar_update(TOOLBAR_COMPOSE, compose);
6797 static void compose_template_apply(Compose *compose, Template *tmpl,
6801 GtkTextBuffer *buffer;
6805 gchar *parsed_str = NULL;
6806 gint cursor_pos = 0;
6807 const gchar *err_msg = _("Template body format error.");
6810 /* process the body */
6812 text = GTK_TEXT_VIEW(compose->text);
6813 buffer = gtk_text_view_get_buffer(text);
6816 if (prefs_common.quotemark && *prefs_common.quotemark)
6817 qmark = prefs_common.quotemark;
6821 if (compose->replyinfo != NULL) {
6824 gtk_text_buffer_set_text(buffer, "", -1);
6825 mark = gtk_text_buffer_get_insert(buffer);
6826 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6828 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6829 tmpl->value, qmark, NULL, FALSE, err_msg);
6831 } else if (compose->fwdinfo != NULL) {
6834 gtk_text_buffer_set_text(buffer, "", -1);
6835 mark = gtk_text_buffer_get_insert(buffer);
6836 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6838 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6839 tmpl->value, qmark, NULL, FALSE, err_msg);
6842 MsgInfo* dummyinfo = compose_msginfo_new_from_compose(compose);
6844 GtkTextIter start, end;
6847 gtk_text_buffer_get_start_iter(buffer, &start);
6848 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
6849 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
6851 /* clear the buffer now */
6853 gtk_text_buffer_set_text(buffer, "", -1);
6855 parsed_str = compose_quote_fmt(compose, dummyinfo,
6856 tmpl->value, qmark, tmp, FALSE, err_msg);
6857 procmsg_msginfo_free( dummyinfo );
6863 gtk_text_buffer_set_text(buffer, "", -1);
6864 mark = gtk_text_buffer_get_insert(buffer);
6865 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6868 if (replace && parsed_str && compose->account->auto_sig)
6869 compose_insert_sig(compose, FALSE);
6871 if (replace && parsed_str) {
6872 gtk_text_buffer_get_start_iter(buffer, &iter);
6873 gtk_text_buffer_place_cursor(buffer, &iter);
6877 cursor_pos = quote_fmt_get_cursor_pos();
6878 compose->set_cursor_pos = cursor_pos;
6879 if (cursor_pos == -1)
6881 gtk_text_buffer_get_start_iter(buffer, &iter);
6882 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6883 gtk_text_buffer_place_cursor(buffer, &iter);
6886 /* process the other fields */
6888 compose_template_apply_fields(compose, tmpl);
6889 quote_fmt_reset_vartable();
6890 compose_changed_cb(NULL, compose);
6893 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6895 MsgInfo* dummyinfo = NULL;
6896 MsgInfo *msginfo = NULL;
6899 if (compose->replyinfo != NULL)
6900 msginfo = compose->replyinfo;
6901 else if (compose->fwdinfo != NULL)
6902 msginfo = compose->fwdinfo;
6904 dummyinfo = compose_msginfo_new_from_compose(compose);
6905 msginfo = dummyinfo;
6908 if (tmpl->to && *tmpl->to != '\0') {
6909 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6910 quote_fmt_scan_string(tmpl->to);
6913 buf = quote_fmt_get_buffer();
6915 alertpanel_error(_("Message To format error."));
6917 compose_entry_append(compose, buf, COMPOSE_TO);
6921 if (tmpl->cc && *tmpl->cc != '\0') {
6922 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6923 quote_fmt_scan_string(tmpl->cc);
6926 buf = quote_fmt_get_buffer();
6928 alertpanel_error(_("Message Cc format error."));
6930 compose_entry_append(compose, buf, COMPOSE_CC);
6934 if (tmpl->bcc && *tmpl->bcc != '\0') {
6935 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6936 quote_fmt_scan_string(tmpl->bcc);
6939 buf = quote_fmt_get_buffer();
6941 alertpanel_error(_("Message Bcc format error."));
6943 compose_entry_append(compose, buf, COMPOSE_BCC);
6947 /* process the subject */
6948 if (tmpl->subject && *tmpl->subject != '\0') {
6949 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6950 quote_fmt_scan_string(tmpl->subject);
6953 buf = quote_fmt_get_buffer();
6955 alertpanel_error(_("Message subject format error."));
6957 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6961 procmsg_msginfo_free( dummyinfo );
6964 static void compose_destroy(Compose *compose)
6966 GtkTextBuffer *buffer;
6967 GtkClipboard *clipboard;
6969 compose_list = g_list_remove(compose_list, compose);
6971 if (compose->updating) {
6972 debug_print("danger, not destroying anything now\n");
6973 compose->deferred_destroy = TRUE;
6976 /* NOTE: address_completion_end() does nothing with the window
6977 * however this may change. */
6978 address_completion_end(compose->window);
6980 slist_free_strings(compose->to_list);
6981 g_slist_free(compose->to_list);
6982 slist_free_strings(compose->newsgroup_list);
6983 g_slist_free(compose->newsgroup_list);
6984 slist_free_strings(compose->header_list);
6985 g_slist_free(compose->header_list);
6987 procmsg_msginfo_free(compose->targetinfo);
6988 procmsg_msginfo_free(compose->replyinfo);
6989 procmsg_msginfo_free(compose->fwdinfo);
6991 g_free(compose->replyto);
6992 g_free(compose->cc);
6993 g_free(compose->bcc);
6994 g_free(compose->newsgroups);
6995 g_free(compose->followup_to);
6997 g_free(compose->ml_post);
6999 g_free(compose->inreplyto);
7000 g_free(compose->references);
7001 g_free(compose->msgid);
7002 g_free(compose->boundary);
7004 g_free(compose->redirect_filename);
7005 if (compose->undostruct)
7006 undo_destroy(compose->undostruct);
7008 g_free(compose->sig_str);
7010 g_free(compose->exteditor_file);
7012 g_free(compose->orig_charset);
7014 g_free(compose->privacy_system);
7016 if (addressbook_get_target_compose() == compose)
7017 addressbook_set_target_compose(NULL);
7020 if (compose->gtkaspell) {
7021 gtkaspell_delete(compose->gtkaspell);
7022 compose->gtkaspell = NULL;
7026 prefs_common.compose_width = compose->scrolledwin->allocation.width;
7027 prefs_common.compose_height = compose->window->allocation.height;
7029 if (!gtk_widget_get_parent(compose->paned))
7030 gtk_widget_destroy(compose->paned);
7031 gtk_widget_destroy(compose->popupmenu);
7033 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
7034 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
7035 gtk_text_buffer_remove_selection_clipboard(buffer, clipboard);
7037 gtk_widget_destroy(compose->window);
7038 toolbar_destroy(compose->toolbar);
7039 g_free(compose->toolbar);
7040 g_mutex_free(compose->mutex);
7044 static void compose_attach_info_free(AttachInfo *ainfo)
7046 g_free(ainfo->file);
7047 g_free(ainfo->content_type);
7048 g_free(ainfo->name);
7052 static void compose_attach_remove_selected(Compose *compose)
7054 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
7055 GtkTreeSelection *selection;
7057 GtkTreeModel *model;
7059 selection = gtk_tree_view_get_selection(tree_view);
7060 sel = gtk_tree_selection_get_selected_rows(selection, &model);
7065 for (cur = sel; cur != NULL; cur = cur->next) {
7066 GtkTreePath *path = cur->data;
7067 GtkTreeRowReference *ref = gtk_tree_row_reference_new
7070 gtk_tree_path_free(path);
7073 for (cur = sel; cur != NULL; cur = cur->next) {
7074 GtkTreeRowReference *ref = cur->data;
7075 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
7078 if (gtk_tree_model_get_iter(model, &iter, path))
7079 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
7081 gtk_tree_path_free(path);
7082 gtk_tree_row_reference_free(ref);
7088 static struct _AttachProperty
7091 GtkWidget *mimetype_entry;
7092 GtkWidget *encoding_optmenu;
7093 GtkWidget *path_entry;
7094 GtkWidget *filename_entry;
7096 GtkWidget *cancel_btn;
7099 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
7101 gtk_tree_path_free((GtkTreePath *)ptr);
7104 static void compose_attach_property(Compose *compose)
7106 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
7108 GtkComboBox *optmenu;
7109 GtkTreeSelection *selection;
7111 GtkTreeModel *model;
7114 static gboolean cancelled;
7116 /* only if one selected */
7117 selection = gtk_tree_view_get_selection(tree_view);
7118 if (gtk_tree_selection_count_selected_rows(selection) != 1)
7121 sel = gtk_tree_selection_get_selected_rows(selection, &model);
7125 path = (GtkTreePath *) sel->data;
7126 gtk_tree_model_get_iter(model, &iter, path);
7127 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
7130 g_list_foreach(sel, gtk_tree_path_free_, NULL);
7136 if (!attach_prop.window)
7137 compose_attach_property_create(&cancelled);
7138 gtk_widget_grab_focus(attach_prop.ok_btn);
7139 gtk_widget_show(attach_prop.window);
7140 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
7142 optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
7143 if (ainfo->encoding == ENC_UNKNOWN)
7144 combobox_select_by_data(optmenu, ENC_BASE64);
7146 combobox_select_by_data(optmenu, ainfo->encoding);
7148 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
7149 ainfo->content_type ? ainfo->content_type : "");
7150 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
7151 ainfo->file ? ainfo->file : "");
7152 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
7153 ainfo->name ? ainfo->name : "");
7156 const gchar *entry_text;
7158 gchar *cnttype = NULL;
7165 gtk_widget_hide(attach_prop.window);
7170 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
7171 if (*entry_text != '\0') {
7174 text = g_strstrip(g_strdup(entry_text));
7175 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
7176 cnttype = g_strdup(text);
7179 alertpanel_error(_("Invalid MIME type."));
7185 ainfo->encoding = combobox_get_active_data(optmenu);
7187 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
7188 if (*entry_text != '\0') {
7189 if (is_file_exist(entry_text) &&
7190 (size = get_file_size(entry_text)) > 0)
7191 file = g_strdup(entry_text);
7194 (_("File doesn't exist or is empty."));
7200 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
7201 if (*entry_text != '\0') {
7202 g_free(ainfo->name);
7203 ainfo->name = g_strdup(entry_text);
7207 g_free(ainfo->content_type);
7208 ainfo->content_type = cnttype;
7211 g_free(ainfo->file);
7217 /* update tree store */
7218 text = to_human_readable(ainfo->size);
7219 gtk_tree_model_get_iter(model, &iter, path);
7220 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
7221 COL_MIMETYPE, ainfo->content_type,
7223 COL_NAME, ainfo->name,
7229 gtk_tree_path_free(path);
7232 #define SET_LABEL_AND_ENTRY(str, entry, top) \
7234 label = gtk_label_new(str); \
7235 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
7236 GTK_FILL, 0, 0, 0); \
7237 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
7239 entry = gtk_entry_new(); \
7240 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
7241 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
7244 static void compose_attach_property_create(gboolean *cancelled)
7250 GtkWidget *mimetype_entry;
7253 GtkListStore *optmenu_menu;
7254 GtkWidget *path_entry;
7255 GtkWidget *filename_entry;
7258 GtkWidget *cancel_btn;
7259 GList *mime_type_list, *strlist;
7262 debug_print("Creating attach_property window...\n");
7264 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
7265 gtk_widget_set_size_request(window, 480, -1);
7266 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
7267 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
7268 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
7269 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
7270 g_signal_connect(G_OBJECT(window), "delete_event",
7271 G_CALLBACK(attach_property_delete_event),
7273 g_signal_connect(G_OBJECT(window), "key_press_event",
7274 G_CALLBACK(attach_property_key_pressed),
7277 vbox = gtk_vbox_new(FALSE, 8);
7278 gtk_container_add(GTK_CONTAINER(window), vbox);
7280 table = gtk_table_new(4, 2, FALSE);
7281 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
7282 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
7283 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
7285 label = gtk_label_new(_("MIME type"));
7286 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
7288 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7289 mimetype_entry = gtk_combo_new();
7290 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
7291 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7293 /* stuff with list */
7294 mime_type_list = procmime_get_mime_type_list();
7296 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
7297 MimeType *type = (MimeType *) mime_type_list->data;
7300 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
7302 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
7305 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
7306 (GCompareFunc)strcmp2);
7309 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
7311 for (mime_type_list = strlist; mime_type_list != NULL;
7312 mime_type_list = mime_type_list->next)
7313 g_free(mime_type_list->data);
7314 g_list_free(strlist);
7316 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
7318 label = gtk_label_new(_("Encoding"));
7319 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
7321 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7323 hbox = gtk_hbox_new(FALSE, 0);
7324 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
7325 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7327 optmenu = gtkut_sc_combobox_create(NULL, TRUE);
7328 optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
7330 COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
7331 COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
7332 COMBOBOX_ADD(optmenu_menu, "quoted-printable", ENC_QUOTED_PRINTABLE);
7333 COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
7334 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
7336 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
7338 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
7339 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
7341 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
7342 &ok_btn, GTK_STOCK_OK,
7344 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
7345 gtk_widget_grab_default(ok_btn);
7347 g_signal_connect(G_OBJECT(ok_btn), "clicked",
7348 G_CALLBACK(attach_property_ok),
7350 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
7351 G_CALLBACK(attach_property_cancel),
7354 gtk_widget_show_all(vbox);
7356 attach_prop.window = window;
7357 attach_prop.mimetype_entry = mimetype_entry;
7358 attach_prop.encoding_optmenu = optmenu;
7359 attach_prop.path_entry = path_entry;
7360 attach_prop.filename_entry = filename_entry;
7361 attach_prop.ok_btn = ok_btn;
7362 attach_prop.cancel_btn = cancel_btn;
7365 #undef SET_LABEL_AND_ENTRY
7367 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7373 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7379 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7380 gboolean *cancelled)
7388 static gboolean attach_property_key_pressed(GtkWidget *widget,
7390 gboolean *cancelled)
7392 if (event && event->keyval == GDK_Escape) {
7399 static void compose_exec_ext_editor(Compose *compose)
7406 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7407 G_DIR_SEPARATOR, compose);
7409 if (pipe(pipe_fds) < 0) {
7415 if ((pid = fork()) < 0) {
7422 /* close the write side of the pipe */
7425 compose->exteditor_file = g_strdup(tmp);
7426 compose->exteditor_pid = pid;
7428 compose_set_ext_editor_sensitive(compose, FALSE);
7430 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7431 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7435 } else { /* process-monitoring process */
7441 /* close the read side of the pipe */
7444 if (compose_write_body_to_file(compose, tmp) < 0) {
7445 fd_write_all(pipe_fds[1], "2\n", 2);
7449 pid_ed = compose_exec_ext_editor_real(tmp);
7451 fd_write_all(pipe_fds[1], "1\n", 2);
7455 /* wait until editor is terminated */
7456 waitpid(pid_ed, NULL, 0);
7458 fd_write_all(pipe_fds[1], "0\n", 2);
7465 #endif /* G_OS_UNIX */
7469 static gint compose_exec_ext_editor_real(const gchar *file)
7476 g_return_val_if_fail(file != NULL, -1);
7478 if ((pid = fork()) < 0) {
7483 if (pid != 0) return pid;
7485 /* grandchild process */
7487 if (setpgid(0, getppid()))
7490 if (prefs_common.ext_editor_cmd &&
7491 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7492 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7493 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7495 if (prefs_common.ext_editor_cmd)
7496 g_warning("External editor command line is invalid: '%s'\n",
7497 prefs_common.ext_editor_cmd);
7498 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7501 cmdline = strsplit_with_quote(buf, " ", 1024);
7502 execvp(cmdline[0], cmdline);
7505 g_strfreev(cmdline);
7510 static gboolean compose_ext_editor_kill(Compose *compose)
7512 pid_t pgid = compose->exteditor_pid * -1;
7515 ret = kill(pgid, 0);
7517 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7521 msg = g_strdup_printf
7522 (_("The external editor is still working.\n"
7523 "Force terminating the process?\n"
7524 "process group id: %d"), -pgid);
7525 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7526 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7530 if (val == G_ALERTALTERNATE) {
7531 g_source_remove(compose->exteditor_tag);
7532 g_io_channel_shutdown(compose->exteditor_ch,
7534 g_io_channel_unref(compose->exteditor_ch);
7536 if (kill(pgid, SIGTERM) < 0) perror("kill");
7537 waitpid(compose->exteditor_pid, NULL, 0);
7539 g_warning("Terminated process group id: %d", -pgid);
7540 g_warning("Temporary file: %s",
7541 compose->exteditor_file);
7543 compose_set_ext_editor_sensitive(compose, TRUE);
7545 g_free(compose->exteditor_file);
7546 compose->exteditor_file = NULL;
7547 compose->exteditor_pid = -1;
7548 compose->exteditor_ch = NULL;
7549 compose->exteditor_tag = -1;
7557 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7561 Compose *compose = (Compose *)data;
7564 debug_print(_("Compose: input from monitoring process\n"));
7566 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7568 g_io_channel_shutdown(source, FALSE, NULL);
7569 g_io_channel_unref(source);
7571 waitpid(compose->exteditor_pid, NULL, 0);
7573 if (buf[0] == '0') { /* success */
7574 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7575 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7577 gtk_text_buffer_set_text(buffer, "", -1);
7578 compose_insert_file(compose, compose->exteditor_file);
7579 compose_changed_cb(NULL, compose);
7581 if (g_unlink(compose->exteditor_file) < 0)
7582 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7583 } else if (buf[0] == '1') { /* failed */
7584 g_warning("Couldn't exec external editor\n");
7585 if (g_unlink(compose->exteditor_file) < 0)
7586 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7587 } else if (buf[0] == '2') {
7588 g_warning("Couldn't write to file\n");
7589 } else if (buf[0] == '3') {
7590 g_warning("Pipe read failed\n");
7593 compose_set_ext_editor_sensitive(compose, TRUE);
7595 g_free(compose->exteditor_file);
7596 compose->exteditor_file = NULL;
7597 compose->exteditor_pid = -1;
7598 compose->exteditor_ch = NULL;
7599 compose->exteditor_tag = -1;
7604 static void compose_set_ext_editor_sensitive(Compose *compose,
7607 GtkItemFactory *ifactory;
7609 ifactory = gtk_item_factory_from_widget(compose->menubar);
7611 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7612 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7613 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7614 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7615 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7616 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7617 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7620 gtk_widget_set_sensitive(compose->text, sensitive);
7621 if (compose->toolbar->send_btn)
7622 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7623 if (compose->toolbar->sendl_btn)
7624 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7625 if (compose->toolbar->draft_btn)
7626 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7627 if (compose->toolbar->insert_btn)
7628 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7629 if (compose->toolbar->sig_btn)
7630 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7631 if (compose->toolbar->exteditor_btn)
7632 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7633 if (compose->toolbar->linewrap_current_btn)
7634 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7635 if (compose->toolbar->linewrap_all_btn)
7636 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7638 #endif /* G_OS_UNIX */
7641 * compose_undo_state_changed:
7643 * Change the sensivity of the menuentries undo and redo
7645 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7646 gint redo_state, gpointer data)
7648 GtkWidget *widget = GTK_WIDGET(data);
7649 GtkItemFactory *ifactory;
7651 g_return_if_fail(widget != NULL);
7653 ifactory = gtk_item_factory_from_widget(widget);
7655 switch (undo_state) {
7656 case UNDO_STATE_TRUE:
7657 if (!undostruct->undo_state) {
7658 undostruct->undo_state = TRUE;
7659 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7662 case UNDO_STATE_FALSE:
7663 if (undostruct->undo_state) {
7664 undostruct->undo_state = FALSE;
7665 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7668 case UNDO_STATE_UNCHANGED:
7670 case UNDO_STATE_REFRESH:
7671 menu_set_sensitive(ifactory, "/Edit/Undo",
7672 undostruct->undo_state);
7675 g_warning("Undo state not recognized");
7679 switch (redo_state) {
7680 case UNDO_STATE_TRUE:
7681 if (!undostruct->redo_state) {
7682 undostruct->redo_state = TRUE;
7683 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7686 case UNDO_STATE_FALSE:
7687 if (undostruct->redo_state) {
7688 undostruct->redo_state = FALSE;
7689 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7692 case UNDO_STATE_UNCHANGED:
7694 case UNDO_STATE_REFRESH:
7695 menu_set_sensitive(ifactory, "/Edit/Redo",
7696 undostruct->redo_state);
7699 g_warning("Redo state not recognized");
7704 /* callback functions */
7706 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7707 * includes "non-client" (windows-izm) in calculation, so this calculation
7708 * may not be accurate.
7710 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7711 GtkAllocation *allocation,
7712 GtkSHRuler *shruler)
7714 if (prefs_common.show_ruler) {
7715 gint char_width = 0, char_height = 0;
7716 gint line_width_in_chars;
7718 gtkut_get_font_size(GTK_WIDGET(widget),
7719 &char_width, &char_height);
7720 line_width_in_chars =
7721 (allocation->width - allocation->x) / char_width;
7723 /* got the maximum */
7724 gtk_ruler_set_range(GTK_RULER(shruler),
7725 0.0, line_width_in_chars, 0,
7726 /*line_width_in_chars*/ char_width);
7732 static void account_activated(GtkComboBox *optmenu, gpointer data)
7734 Compose *compose = (Compose *)data;
7737 gchar *folderidentifier;
7738 gint account_id = 0;
7742 /* Get ID of active account in the combo box */
7743 menu = gtk_combo_box_get_model(optmenu);
7744 gtk_combo_box_get_active_iter(optmenu, &iter);
7745 gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
7747 ac = account_find_from_id(account_id);
7748 g_return_if_fail(ac != NULL);
7750 if (ac != compose->account)
7751 compose_select_account(compose, ac, FALSE);
7753 /* Set message save folder */
7754 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7755 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7757 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7758 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7760 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7761 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7762 folderidentifier = folder_item_get_identifier(account_get_special_folder
7763 (compose->account, F_OUTBOX));
7764 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7765 g_free(folderidentifier);
7769 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7770 GtkTreeViewColumn *column, Compose *compose)
7772 compose_attach_property(compose);
7775 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7778 Compose *compose = (Compose *)data;
7779 GtkTreeSelection *attach_selection;
7780 gint attach_nr_selected;
7781 GtkItemFactory *ifactory;
7783 if (!event) return FALSE;
7785 if (event->button == 3) {
7786 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7787 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7788 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7790 if (attach_nr_selected > 0)
7792 menu_set_sensitive(ifactory, "/Remove", TRUE);
7793 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7795 menu_set_sensitive(ifactory, "/Remove", FALSE);
7796 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7799 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7800 NULL, NULL, event->button, event->time);
7807 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7810 Compose *compose = (Compose *)data;
7812 if (!event) return FALSE;
7814 switch (event->keyval) {
7816 compose_attach_remove_selected(compose);
7822 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7824 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7825 toolbar_comp_set_sensitive(compose, allow);
7826 menu_set_sensitive(ifactory, "/Message", allow);
7827 menu_set_sensitive(ifactory, "/Edit", allow);
7829 menu_set_sensitive(ifactory, "/Spelling", allow);
7831 menu_set_sensitive(ifactory, "/Options", allow);
7832 menu_set_sensitive(ifactory, "/Tools", allow);
7833 menu_set_sensitive(ifactory, "/Help", allow);
7835 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7839 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7841 Compose *compose = (Compose *)data;
7843 if (prefs_common.work_offline &&
7844 !inc_offline_should_override(
7845 _("Claws Mail needs network access in order "
7846 "to send this email.")))
7849 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7850 gtk_timeout_remove(compose->draft_timeout_tag);
7851 compose->draft_timeout_tag = -1;
7854 compose_send(compose);
7857 static void compose_send_later_cb(gpointer data, guint action,
7860 Compose *compose = (Compose *)data;
7864 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
7868 compose_close(compose);
7869 } else if (val == -1) {
7870 alertpanel_error(_("Could not queue message."));
7871 } else if (val == -2) {
7872 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7873 } else if (val == -3) {
7874 if (privacy_peek_error())
7875 alertpanel_error(_("Could not queue message for sending:\n\n"
7876 "Signature failed: %s"), privacy_get_error());
7877 } else if (val == -4) {
7878 alertpanel_error(_("Could not queue message for sending:\n\n"
7879 "Charset conversion failed."));
7880 } else if (val == -5) {
7881 alertpanel_error(_("Could not queue message for sending:\n\n"
7882 "Couldn't get recipient encryption key."));
7884 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
7887 void compose_draft (gpointer data)
7889 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7892 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7894 Compose *compose = (Compose *)data;
7898 MsgFlags flag = {0, 0};
7899 static gboolean lock = FALSE;
7900 MsgInfo *newmsginfo;
7902 gboolean target_locked = FALSE;
7906 draft = account_get_special_folder(compose->account, F_DRAFT);
7907 g_return_if_fail(draft != NULL);
7909 if (!g_mutex_trylock(compose->mutex)) {
7910 /* we don't want to lock the mutex once it's available,
7911 * because as the only other part of compose.c locking
7912 * it is compose_close - which means once unlocked,
7913 * the compose struct will be freed */
7914 debug_print("couldn't lock mutex, probably sending\n");
7920 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7921 G_DIR_SEPARATOR, compose);
7922 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7923 FILE_OP_ERROR(tmp, "fopen");
7927 /* chmod for security */
7928 if (change_file_mode_rw(fp, tmp) < 0) {
7929 FILE_OP_ERROR(tmp, "chmod");
7930 g_warning("can't change file mode\n");
7933 /* Save draft infos */
7934 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7935 fprintf(fp, "S:%s\n", compose->account->address);
7937 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7938 gchar *savefolderid;
7940 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7941 fprintf(fp, "SCF:%s\n", savefolderid);
7942 g_free(savefolderid);
7944 if (compose->return_receipt) {
7945 fprintf(fp, "RRCPT:1\n");
7947 if (compose->privacy_system) {
7948 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7949 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7950 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7953 /* Message-ID of message replying to */
7954 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
7957 folderid = folder_item_get_identifier(compose->replyinfo->folder);
7958 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
7961 /* Message-ID of message forwarding to */
7962 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
7965 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
7966 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
7970 /* end of headers */
7971 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
7973 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
7981 if (compose->targetinfo) {
7982 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7983 flag.perm_flags = target_locked?MSG_LOCKED:0;
7985 flag.tmp_flags = MSG_DRAFT;
7987 folder_item_scan(draft);
7988 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7991 if (action != COMPOSE_AUTO_SAVE)
7992 alertpanel_error(_("Could not save draft."));
7997 if (compose->mode == COMPOSE_REEDIT) {
7998 compose_remove_reedit_target(compose, TRUE);
8001 newmsginfo = folder_item_get_msginfo(draft, msgnum);
8003 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
8005 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
8007 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
8008 if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
8009 procmsg_msginfo_set_flags(newmsginfo, 0,
8010 MSG_HAS_ATTACHMENT);
8012 procmsg_msginfo_free(newmsginfo);
8015 folder_item_scan(draft);
8017 if (action == COMPOSE_QUIT_EDITING) {
8019 g_mutex_unlock(compose->mutex); /* must be done before closing */
8020 compose_close(compose);
8026 path = folder_item_fetch_msg(draft, msgnum);
8028 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
8031 if (g_stat(path, &s) < 0) {
8032 FILE_OP_ERROR(path, "stat");
8038 procmsg_msginfo_free(compose->targetinfo);
8039 compose->targetinfo = procmsg_msginfo_new();
8040 compose->targetinfo->msgnum = msgnum;
8041 compose->targetinfo->size = s.st_size;
8042 compose->targetinfo->mtime = s.st_mtime;
8043 compose->targetinfo->folder = draft;
8045 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
8046 compose->mode = COMPOSE_REEDIT;
8048 if (action == COMPOSE_AUTO_SAVE) {
8049 compose->autosaved_draft = compose->targetinfo;
8051 compose->modified = FALSE;
8052 compose_set_title(compose);
8056 g_mutex_unlock(compose->mutex);
8059 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
8061 Compose *compose = (Compose *)data;
8064 if (compose->redirect_filename != NULL)
8067 file_list = filesel_select_multiple_files_open(_("Select file"));
8072 for ( tmp = file_list; tmp; tmp = tmp->next) {
8073 gchar *file = (gchar *) tmp->data;
8074 gchar *utf8_filename = conv_filename_to_utf8(file);
8075 compose_attach_append(compose, file, utf8_filename, NULL);
8076 compose_changed_cb(NULL, compose);
8078 g_free(utf8_filename);
8080 g_list_free(file_list);
8084 static void compose_insert_file_cb(gpointer data, guint action,
8087 Compose *compose = (Compose *)data;
8090 file_list = filesel_select_multiple_files_open(_("Select file"));
8095 for ( tmp = file_list; tmp; tmp = tmp->next) {
8096 gchar *file = (gchar *) tmp->data;
8097 gchar *filedup = g_strdup(file);
8098 gchar *shortfile = g_path_get_basename(filedup);
8099 ComposeInsertResult res;
8101 res = compose_insert_file(compose, file);
8102 if (res == COMPOSE_INSERT_READ_ERROR) {
8103 alertpanel_error(_("File '%s' could not be read."), shortfile);
8104 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
8105 alertpanel_error(_("File '%s' contained invalid characters\n"
8106 "for the current encoding, insertion may be incorrect."), shortfile);
8112 g_list_free(file_list);
8116 static void compose_insert_sig_cb(gpointer data, guint action,
8119 Compose *compose = (Compose *)data;
8121 compose_insert_sig(compose, FALSE);
8124 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
8128 Compose *compose = (Compose *)data;
8130 gtkut_widget_get_uposition(widget, &x, &y);
8131 prefs_common.compose_x = x;
8132 prefs_common.compose_y = y;
8134 if (compose->sending || compose->updating)
8136 compose_close_cb(compose, 0, NULL);
8140 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
8142 Compose *compose = (Compose *)data;
8146 if (compose->exteditor_tag != -1) {
8147 if (!compose_ext_editor_kill(compose))
8152 if (compose->modified) {
8153 val = alertpanel(_("Discard message"),
8154 _("This message has been modified. Discard it?"),
8155 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
8158 case G_ALERTDEFAULT:
8159 if (prefs_common.autosave)
8160 compose_remove_draft(compose);
8162 case G_ALERTALTERNATE:
8163 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
8170 compose_close(compose);
8173 static void compose_set_encoding_cb(gpointer data, guint action,
8176 Compose *compose = (Compose *)data;
8178 if (GTK_CHECK_MENU_ITEM(widget)->active)
8179 compose->out_encoding = (CharSet)action;
8182 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
8184 Compose *compose = (Compose *)data;
8186 addressbook_open(compose);
8189 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
8191 Compose *compose = (Compose *)data;
8196 tmpl = g_object_get_data(G_OBJECT(widget), "template");
8197 g_return_if_fail(tmpl != NULL);
8199 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
8201 val = alertpanel(_("Apply template"), msg,
8202 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
8205 if (val == G_ALERTDEFAULT)
8206 compose_template_apply(compose, tmpl, TRUE);
8207 else if (val == G_ALERTALTERNATE)
8208 compose_template_apply(compose, tmpl, FALSE);
8211 static void compose_ext_editor_cb(gpointer data, guint action,
8214 Compose *compose = (Compose *)data;
8216 compose_exec_ext_editor(compose);
8219 static void compose_undo_cb(Compose *compose)
8221 gboolean prev_autowrap = compose->autowrap;
8223 compose->autowrap = FALSE;
8224 undo_undo(compose->undostruct);
8225 compose->autowrap = prev_autowrap;
8228 static void compose_redo_cb(Compose *compose)
8230 gboolean prev_autowrap = compose->autowrap;
8232 compose->autowrap = FALSE;
8233 undo_redo(compose->undostruct);
8234 compose->autowrap = prev_autowrap;
8237 static void entry_cut_clipboard(GtkWidget *entry)
8239 if (GTK_IS_EDITABLE(entry))
8240 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
8241 else if (GTK_IS_TEXT_VIEW(entry))
8242 gtk_text_buffer_cut_clipboard(
8243 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
8244 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
8248 static void entry_copy_clipboard(GtkWidget *entry)
8250 if (GTK_IS_EDITABLE(entry))
8251 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
8252 else if (GTK_IS_TEXT_VIEW(entry))
8253 gtk_text_buffer_copy_clipboard(
8254 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
8255 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
8258 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
8259 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
8261 if (GTK_IS_TEXT_VIEW(entry)) {
8262 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
8263 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
8264 GtkTextIter start_iter, end_iter;
8266 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
8268 if (contents == NULL)
8271 undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);
8273 /* we shouldn't delete the selection when middle-click-pasting, or we
8274 * can't mid-click-paste our own selection */
8275 if (clip != GDK_SELECTION_PRIMARY) {
8276 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
8279 if (insert_place == NULL) {
8280 /* if insert_place isn't specified, insert at the cursor.
8281 * used for Ctrl-V pasting */
8282 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
8283 start = gtk_text_iter_get_offset(&start_iter);
8284 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
8286 /* if insert_place is specified, paste here.
8287 * used for mid-click-pasting */
8288 start = gtk_text_iter_get_offset(insert_place);
8289 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
8293 /* paste unwrapped: mark the paste so it's not wrapped later */
8294 end = start + strlen(contents);
8295 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
8296 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
8297 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
8298 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
8299 /* rewrap paragraph now (after a mid-click-paste) */
8300 mark_start = gtk_text_buffer_get_insert(buffer);
8301 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
8302 gtk_text_iter_backward_char(&start_iter);
8303 compose_beautify_paragraph(compose, &start_iter, TRUE);
8305 } else if (GTK_IS_EDITABLE(entry))
8306 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
8310 static void entry_allsel(GtkWidget *entry)
8312 if (GTK_IS_EDITABLE(entry))
8313 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
8314 else if (GTK_IS_TEXT_VIEW(entry)) {
8315 GtkTextIter startiter, enditer;
8316 GtkTextBuffer *textbuf;
8318 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
8319 gtk_text_buffer_get_start_iter(textbuf, &startiter);
8320 gtk_text_buffer_get_end_iter(textbuf, &enditer);
8322 gtk_text_buffer_move_mark_by_name(textbuf,
8323 "selection_bound", &startiter);
8324 gtk_text_buffer_move_mark_by_name(textbuf,
8325 "insert", &enditer);
8329 static void compose_cut_cb(Compose *compose)
8331 if (compose->focused_editable &&
8332 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8333 entry_cut_clipboard(compose->focused_editable);
8336 static void compose_copy_cb(Compose *compose)
8338 if (compose->focused_editable &&
8339 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8340 entry_copy_clipboard(compose->focused_editable);
8343 static void compose_paste_cb(Compose *compose)
8346 GtkTextBuffer *buffer;
8348 if (compose->focused_editable &&
8349 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8350 entry_paste_clipboard(compose, compose->focused_editable,
8351 prefs_common.linewrap_pastes,
8352 GDK_SELECTION_CLIPBOARD, NULL);
8356 static void compose_paste_as_quote_cb(Compose *compose)
8358 gint wrap_quote = prefs_common.linewrap_quote;
8359 if (compose->focused_editable &&
8360 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
8361 /* let text_insert() (called directly or at a later time
8362 * after the gtk_editable_paste_clipboard) know that
8363 * text is to be inserted as a quotation. implemented
8364 * by using a simple refcount... */
8365 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
8366 G_OBJECT(compose->focused_editable),
8367 "paste_as_quotation"));
8368 g_object_set_data(G_OBJECT(compose->focused_editable),
8369 "paste_as_quotation",
8370 GINT_TO_POINTER(paste_as_quotation + 1));
8371 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
8372 entry_paste_clipboard(compose, compose->focused_editable,
8373 prefs_common.linewrap_pastes,
8374 GDK_SELECTION_CLIPBOARD, NULL);
8375 prefs_common.linewrap_quote = wrap_quote;
8379 static void compose_paste_no_wrap_cb(Compose *compose)
8382 GtkTextBuffer *buffer;
8384 if (compose->focused_editable &&
8385 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8386 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
8387 GDK_SELECTION_CLIPBOARD, NULL);
8391 static void compose_paste_wrap_cb(Compose *compose)
8394 GtkTextBuffer *buffer;
8396 if (compose->focused_editable &&
8397 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8398 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
8399 GDK_SELECTION_CLIPBOARD, NULL);
8403 static void compose_allsel_cb(Compose *compose)
8405 if (compose->focused_editable &&
8406 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8407 entry_allsel(compose->focused_editable);
8410 static void textview_move_beginning_of_line (GtkTextView *text)
8412 GtkTextBuffer *buffer;
8416 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8418 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8419 mark = gtk_text_buffer_get_insert(buffer);
8420 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8421 gtk_text_iter_set_line_offset(&ins, 0);
8422 gtk_text_buffer_place_cursor(buffer, &ins);
8425 static void textview_move_forward_character (GtkTextView *text)
8427 GtkTextBuffer *buffer;
8431 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8433 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8434 mark = gtk_text_buffer_get_insert(buffer);
8435 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8436 if (gtk_text_iter_forward_cursor_position(&ins))
8437 gtk_text_buffer_place_cursor(buffer, &ins);
8440 static void textview_move_backward_character (GtkTextView *text)
8442 GtkTextBuffer *buffer;
8446 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8448 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8449 mark = gtk_text_buffer_get_insert(buffer);
8450 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8451 if (gtk_text_iter_backward_cursor_position(&ins))
8452 gtk_text_buffer_place_cursor(buffer, &ins);
8455 static void textview_move_forward_word (GtkTextView *text)
8457 GtkTextBuffer *buffer;
8462 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8464 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8465 mark = gtk_text_buffer_get_insert(buffer);
8466 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8467 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8468 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8469 gtk_text_iter_backward_word_start(&ins);
8470 gtk_text_buffer_place_cursor(buffer, &ins);
8474 static void textview_move_backward_word (GtkTextView *text)
8476 GtkTextBuffer *buffer;
8481 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8483 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8484 mark = gtk_text_buffer_get_insert(buffer);
8485 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8486 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8487 if (gtk_text_iter_backward_word_starts(&ins, 1))
8488 gtk_text_buffer_place_cursor(buffer, &ins);
8491 static void textview_move_end_of_line (GtkTextView *text)
8493 GtkTextBuffer *buffer;
8497 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8499 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8500 mark = gtk_text_buffer_get_insert(buffer);
8501 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8502 if (gtk_text_iter_forward_to_line_end(&ins))
8503 gtk_text_buffer_place_cursor(buffer, &ins);
8506 static void textview_move_next_line (GtkTextView *text)
8508 GtkTextBuffer *buffer;
8513 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8515 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8516 mark = gtk_text_buffer_get_insert(buffer);
8517 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8518 offset = gtk_text_iter_get_line_offset(&ins);
8519 if (gtk_text_iter_forward_line(&ins)) {
8520 gtk_text_iter_set_line_offset(&ins, offset);
8521 gtk_text_buffer_place_cursor(buffer, &ins);
8525 static void textview_move_previous_line (GtkTextView *text)
8527 GtkTextBuffer *buffer;
8532 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8534 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8535 mark = gtk_text_buffer_get_insert(buffer);
8536 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8537 offset = gtk_text_iter_get_line_offset(&ins);
8538 if (gtk_text_iter_backward_line(&ins)) {
8539 gtk_text_iter_set_line_offset(&ins, offset);
8540 gtk_text_buffer_place_cursor(buffer, &ins);
8544 static void textview_delete_forward_character (GtkTextView *text)
8546 GtkTextBuffer *buffer;
8548 GtkTextIter ins, end_iter;
8550 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8552 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8553 mark = gtk_text_buffer_get_insert(buffer);
8554 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8556 if (gtk_text_iter_forward_char(&end_iter)) {
8557 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8561 static void textview_delete_backward_character (GtkTextView *text)
8563 GtkTextBuffer *buffer;
8565 GtkTextIter ins, end_iter;
8567 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8569 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8570 mark = gtk_text_buffer_get_insert(buffer);
8571 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8573 if (gtk_text_iter_backward_char(&end_iter)) {
8574 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8578 static void textview_delete_forward_word (GtkTextView *text)
8580 GtkTextBuffer *buffer;
8582 GtkTextIter ins, end_iter;
8584 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8586 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8587 mark = gtk_text_buffer_get_insert(buffer);
8588 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8590 if (gtk_text_iter_forward_word_end(&end_iter)) {
8591 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8595 static void textview_delete_backward_word (GtkTextView *text)
8597 GtkTextBuffer *buffer;
8599 GtkTextIter ins, end_iter;
8601 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8603 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8604 mark = gtk_text_buffer_get_insert(buffer);
8605 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8607 if (gtk_text_iter_backward_word_start(&end_iter)) {
8608 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8612 static void textview_delete_line (GtkTextView *text)
8614 GtkTextBuffer *buffer;
8616 GtkTextIter ins, start_iter, end_iter;
8619 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8621 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8622 mark = gtk_text_buffer_get_insert(buffer);
8623 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8626 gtk_text_iter_set_line_offset(&start_iter, 0);
8629 if (gtk_text_iter_ends_line(&end_iter))
8630 found = gtk_text_iter_forward_char(&end_iter);
8632 found = gtk_text_iter_forward_to_line_end(&end_iter);
8635 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8638 static void textview_delete_to_line_end (GtkTextView *text)
8640 GtkTextBuffer *buffer;
8642 GtkTextIter ins, end_iter;
8645 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8647 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8648 mark = gtk_text_buffer_get_insert(buffer);
8649 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8651 if (gtk_text_iter_ends_line(&end_iter))
8652 found = gtk_text_iter_forward_char(&end_iter);
8654 found = gtk_text_iter_forward_to_line_end(&end_iter);
8656 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8659 static void compose_advanced_action_cb(Compose *compose,
8660 ComposeCallAdvancedAction action)
8662 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8664 void (*do_action) (GtkTextView *text);
8665 } action_table[] = {
8666 {textview_move_beginning_of_line},
8667 {textview_move_forward_character},
8668 {textview_move_backward_character},
8669 {textview_move_forward_word},
8670 {textview_move_backward_word},
8671 {textview_move_end_of_line},
8672 {textview_move_next_line},
8673 {textview_move_previous_line},
8674 {textview_delete_forward_character},
8675 {textview_delete_backward_character},
8676 {textview_delete_forward_word},
8677 {textview_delete_backward_word},
8678 {textview_delete_line},
8679 {NULL}, /* gtk_stext_delete_line_n */
8680 {textview_delete_to_line_end}
8683 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8685 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8686 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8687 if (action_table[action].do_action)
8688 action_table[action].do_action(text);
8690 g_warning("Not implemented yet.");
8694 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8698 if (GTK_IS_EDITABLE(widget)) {
8699 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8700 gtk_editable_set_position(GTK_EDITABLE(widget),
8703 if (widget->parent && widget->parent->parent
8704 && widget->parent->parent->parent) {
8705 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8706 gint y = widget->allocation.y;
8707 gint height = widget->allocation.height;
8708 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8709 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8711 if (y < (int)shown->value) {
8712 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8714 if (y + height > (int)shown->value + (int)shown->page_size) {
8715 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8716 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8717 y + height - (int)shown->page_size - 1);
8719 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8720 (int)shown->upper - (int)shown->page_size - 1);
8727 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8728 compose->focused_editable = widget;
8731 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8733 compose->modified = TRUE;
8734 compose_set_title(compose);
8737 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8739 Compose *compose = (Compose *)data;
8742 compose_wrap_all_full(compose, TRUE);
8744 compose_beautify_paragraph(compose, NULL, TRUE);
8747 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8749 Compose *compose = (Compose *)data;
8751 message_search_compose(compose);
8754 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8757 Compose *compose = (Compose *)data;
8758 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8759 if (compose->autowrap)
8760 compose_wrap_all_full(compose, TRUE);
8761 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8764 static void compose_toggle_sign_cb(gpointer data, guint action,
8767 Compose *compose = (Compose *)data;
8769 if (GTK_CHECK_MENU_ITEM(widget)->active)
8770 compose->use_signing = TRUE;
8772 compose->use_signing = FALSE;
8775 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8778 Compose *compose = (Compose *)data;
8780 if (GTK_CHECK_MENU_ITEM(widget)->active)
8781 compose->use_encryption = TRUE;
8783 compose->use_encryption = FALSE;
8786 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8788 g_free(compose->privacy_system);
8790 compose->privacy_system = g_strdup(account->default_privacy_system);
8791 compose_update_privacy_system_menu_item(compose, warn);
8794 static void compose_toggle_ruler_cb(gpointer data, guint action,
8797 Compose *compose = (Compose *)data;
8799 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8800 gtk_widget_show(compose->ruler_hbox);
8801 prefs_common.show_ruler = TRUE;
8803 gtk_widget_hide(compose->ruler_hbox);
8804 gtk_widget_queue_resize(compose->edit_vbox);
8805 prefs_common.show_ruler = FALSE;
8809 static void compose_attach_drag_received_cb (GtkWidget *widget,
8810 GdkDragContext *context,
8813 GtkSelectionData *data,
8818 Compose *compose = (Compose *)user_data;
8821 if (gdk_atom_name(data->type) &&
8822 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8823 && gtk_drag_get_source_widget(context) !=
8824 summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
8825 list = uri_list_extract_filenames((const gchar *)data->data);
8826 for (tmp = list; tmp != NULL; tmp = tmp->next)
8827 compose_attach_append
8828 (compose, (const gchar *)tmp->data,
8829 (const gchar *)tmp->data, NULL);
8830 if (list) compose_changed_cb(NULL, compose);
8831 list_free_strings(list);
8833 } else if (gtk_drag_get_source_widget(context)
8834 == summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
8835 /* comes from our summaryview */
8836 SummaryView * summaryview = NULL;
8837 GSList * list = NULL, *cur = NULL;
8839 if (mainwindow_get_mainwindow())
8840 summaryview = mainwindow_get_mainwindow()->summaryview;
8843 list = summary_get_selected_msg_list(summaryview);
8845 for (cur = list; cur; cur = cur->next) {
8846 MsgInfo *msginfo = (MsgInfo *)cur->data;
8849 file = procmsg_get_message_file_full(msginfo,
8852 compose_attach_append(compose, (const gchar *)file,
8853 (const gchar *)file, "message/rfc822");
8861 static gboolean compose_drag_drop(GtkWidget *widget,
8862 GdkDragContext *drag_context,
8864 guint time, gpointer user_data)
8866 /* not handling this signal makes compose_insert_drag_received_cb
8871 static void compose_insert_drag_received_cb (GtkWidget *widget,
8872 GdkDragContext *drag_context,
8875 GtkSelectionData *data,
8880 Compose *compose = (Compose *)user_data;
8883 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8885 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8886 AlertValue val = G_ALERTDEFAULT;
8888 switch (prefs_common.compose_dnd_mode) {
8889 case COMPOSE_DND_ASK:
8890 val = alertpanel_full(_("Insert or attach?"),
8891 _("Do you want to insert the contents of the file(s) "
8892 "into the message body, or attach it to the email?"),
8893 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
8894 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
8896 case COMPOSE_DND_INSERT:
8897 val = G_ALERTALTERNATE;
8899 case COMPOSE_DND_ATTACH:
8903 /* unexpected case */
8904 g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
8907 if (val & G_ALERTDISABLE) {
8908 val &= ~G_ALERTDISABLE;
8909 /* remember what action to perform by default, only if we don't click Cancel */
8910 if (val == G_ALERTALTERNATE)
8911 prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
8912 else if (val == G_ALERTOTHER)
8913 prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
8916 if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
8917 gtk_drag_finish(drag_context, FALSE, FALSE, time);
8919 } else if (val == G_ALERTOTHER) {
8920 compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
8923 list = uri_list_extract_filenames((const gchar *)data->data);
8924 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8925 compose_insert_file(compose, (const gchar *)tmp->data);
8927 list_free_strings(list);
8929 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8932 #if GTK_CHECK_VERSION(2, 8, 0)
8933 /* do nothing, handled by GTK */
8935 gchar *tmpfile = get_tmp_file();
8936 str_write_to_file((const gchar *)data->data, tmpfile);
8937 compose_insert_file(compose, tmpfile);
8940 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8944 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8947 static void compose_header_drag_received_cb (GtkWidget *widget,
8948 GdkDragContext *drag_context,
8951 GtkSelectionData *data,
8956 GtkEditable *entry = (GtkEditable *)user_data;
8957 gchar *email = (gchar *)data->data;
8959 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8962 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8963 gchar *decoded=g_new(gchar, strlen(email));
8966 email += strlen("mailto:");
8967 decode_uri(decoded, email); /* will fit */
8968 gtk_editable_delete_text(entry, 0, -1);
8969 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8970 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8974 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8977 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8980 Compose *compose = (Compose *)data;
8982 if (GTK_CHECK_MENU_ITEM(widget)->active)
8983 compose->return_receipt = TRUE;
8985 compose->return_receipt = FALSE;
8988 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8991 Compose *compose = (Compose *)data;
8993 if (GTK_CHECK_MENU_ITEM(widget)->active)
8994 compose->remove_references = TRUE;
8996 compose->remove_references = FALSE;
8999 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
9001 ComposeHeaderEntry *headerentry)
9003 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
9004 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
9005 !(event->state & GDK_MODIFIER_MASK) &&
9006 (event->keyval == GDK_BackSpace) &&
9007 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
9008 gtk_container_remove
9009 (GTK_CONTAINER(headerentry->compose->header_table),
9010 headerentry->combo);
9011 gtk_container_remove
9012 (GTK_CONTAINER(headerentry->compose->header_table),
9013 headerentry->entry);
9014 headerentry->compose->header_list =
9015 g_slist_remove(headerentry->compose->header_list,
9017 g_free(headerentry);
9018 } else if (event->keyval == GDK_Tab) {
9019 if (headerentry->compose->header_last == headerentry) {
9020 /* Override default next focus, and give it to subject_entry
9021 * instead of notebook tabs
9023 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
9024 gtk_widget_grab_focus(headerentry->compose->subject_entry);
9031 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
9032 ComposeHeaderEntry *headerentry)
9034 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
9035 headerentry->compose->header_list =
9036 g_slist_append(headerentry->compose->header_list,
9039 compose_create_header_entry(headerentry->compose);
9040 g_signal_handlers_disconnect_matched
9041 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
9042 0, 0, NULL, NULL, headerentry);
9044 /* Automatically scroll down */
9045 compose_show_first_last_header(headerentry->compose, FALSE);
9051 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
9053 GtkAdjustment *vadj;
9055 g_return_if_fail(compose);
9056 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
9057 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
9059 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
9060 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
9063 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
9064 const gchar *text, gint len, Compose *compose)
9066 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
9067 (G_OBJECT(compose->text), "paste_as_quotation"));
9070 g_return_if_fail(text != NULL);
9072 g_signal_handlers_block_by_func(G_OBJECT(buffer),
9073 G_CALLBACK(text_inserted),
9075 if (paste_as_quotation) {
9082 new_text = g_strndup(text, len);
9083 if (prefs_common.quotemark && *prefs_common.quotemark)
9084 qmark = prefs_common.quotemark;
9088 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
9089 gtk_text_buffer_place_cursor(buffer, iter);
9091 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE,
9092 _("Quote format error."));
9093 quote_fmt_reset_vartable();
9095 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
9096 GINT_TO_POINTER(paste_as_quotation - 1));
9098 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
9099 gtk_text_buffer_place_cursor(buffer, iter);
9101 if (strcmp(text, "\n") || automatic_break
9102 || gtk_text_iter_starts_line(iter))
9103 gtk_text_buffer_insert(buffer, iter, text, len);
9105 debug_print("insert nowrap \\n\n");
9106 gtk_text_buffer_insert_with_tags_by_name(buffer,
9107 iter, text, len, "no_join", NULL);
9111 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
9113 compose_beautify_paragraph(compose, iter, FALSE);
9115 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
9116 gtk_text_buffer_delete_mark(buffer, mark);
9118 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
9119 G_CALLBACK(text_inserted),
9121 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
9123 if (prefs_common.autosave &&
9124 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
9125 compose->draft_timeout_tag = gtk_timeout_add
9126 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
9128 static gint compose_defer_auto_save_draft(Compose *compose)
9130 compose->draft_timeout_tag = -1;
9131 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
9136 static void compose_check_all(Compose *compose)
9138 if (compose->gtkaspell)
9139 gtkaspell_check_all(compose->gtkaspell);
9142 static void compose_highlight_all(Compose *compose)
9144 if (compose->gtkaspell)
9145 gtkaspell_highlight_all(compose->gtkaspell);
9148 static void compose_check_backwards(Compose *compose)
9150 if (compose->gtkaspell)
9151 gtkaspell_check_backwards(compose->gtkaspell);
9153 GtkItemFactory *ifactory;
9154 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
9155 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
9156 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
9160 static void compose_check_forwards_go(Compose *compose)
9162 if (compose->gtkaspell)
9163 gtkaspell_check_forwards_go(compose->gtkaspell);
9165 GtkItemFactory *ifactory;
9166 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
9167 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
9168 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
9174 *\brief Guess originating forward account from MsgInfo and several
9175 * "common preference" settings. Return NULL if no guess.
9177 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
9179 PrefsAccount *account = NULL;
9181 g_return_val_if_fail(msginfo, NULL);
9182 g_return_val_if_fail(msginfo->folder, NULL);
9183 g_return_val_if_fail(msginfo->folder->prefs, NULL);
9185 if (msginfo->folder->prefs->enable_default_account)
9186 account = account_find_from_id(msginfo->folder->prefs->default_account);
9189 account = msginfo->folder->folder->account;
9191 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
9193 Xstrdup_a(to, msginfo->to, return NULL);
9194 extract_address(to);
9195 account = account_find_from_address(to);
9198 if (!account && prefs_common.forward_account_autosel) {
9200 if (!procheader_get_header_from_msginfo
9201 (msginfo, cc,sizeof cc , "Cc:")) {
9202 gchar *buf = cc + strlen("Cc:");
9203 extract_address(buf);
9204 account = account_find_from_address(buf);
9208 if (!account && prefs_common.forward_account_autosel) {
9209 gchar deliveredto[BUFFSIZE];
9210 if (!procheader_get_header_from_msginfo
9211 (msginfo, deliveredto,sizeof deliveredto , "Delivered-To:")) {
9212 gchar *buf = deliveredto + strlen("Delivered-To:");
9213 extract_address(buf);
9214 account = account_find_from_address(buf);
9221 gboolean compose_close(Compose *compose)
9225 if (!g_mutex_trylock(compose->mutex)) {
9226 /* we have to wait for the (possibly deferred by auto-save)
9227 * drafting to be done, before destroying the compose under
9229 debug_print("waiting for drafting to finish...\n");
9230 g_timeout_add (500, (GSourceFunc) compose_close, compose);
9233 g_return_val_if_fail(compose, FALSE);
9234 gtkut_widget_get_uposition(compose->window, &x, &y);
9235 prefs_common.compose_x = x;
9236 prefs_common.compose_y = y;
9237 g_mutex_unlock(compose->mutex);
9238 compose_destroy(compose);
9243 * Add entry field for each address in list.
9244 * \param compose E-Mail composition object.
9245 * \param listAddress List of (formatted) E-Mail addresses.
9247 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
9252 addr = ( gchar * ) node->data;
9253 compose_entry_append( compose, addr, COMPOSE_TO );
9254 node = g_list_next( node );
9258 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
9259 guint action, gboolean opening_multiple)
9262 GSList *new_msglist = NULL;
9263 MsgInfo *tmp_msginfo = NULL;
9264 gboolean originally_enc = FALSE;
9265 Compose *compose = NULL;
9267 g_return_if_fail(msgview != NULL);
9269 g_return_if_fail(msginfo_list != NULL);
9271 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
9272 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
9273 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
9275 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
9276 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
9277 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
9278 orig_msginfo, mimeinfo);
9279 if (tmp_msginfo != NULL) {
9280 new_msglist = g_slist_append(NULL, tmp_msginfo);
9281 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
9282 originally_enc = TRUE;
9288 if (!opening_multiple)
9289 body = messageview_get_selection(msgview);
9292 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
9293 procmsg_msginfo_free(tmp_msginfo);
9294 g_slist_free(new_msglist);
9296 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
9298 if (originally_enc) {
9299 compose_force_encryption(compose, compose->account, FALSE);
9305 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
9308 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
9309 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
9310 GSList *cur = msginfo_list;
9311 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
9312 "messages. Opening the windows "
9313 "could take some time. Do you "
9314 "want to continue?"),
9315 g_slist_length(msginfo_list));
9316 if (g_slist_length(msginfo_list) > 9
9317 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
9318 != G_ALERTALTERNATE) {
9323 /* We'll open multiple compose windows */
9324 /* let the WM place the next windows */
9325 compose_force_window_origin = FALSE;
9326 for (; cur; cur = cur->next) {
9328 tmplist.data = cur->data;
9329 tmplist.next = NULL;
9330 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
9332 compose_force_window_origin = TRUE;
9334 /* forwarding multiple mails as attachments is done via a
9335 * single compose window */
9336 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
9340 void compose_set_position(Compose *compose, gint pos)
9342 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9344 gtkut_text_view_set_position(text, pos);
9347 gboolean compose_search_string(Compose *compose,
9348 const gchar *str, gboolean case_sens)
9350 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9352 return gtkut_text_view_search_string(text, str, case_sens);
9355 gboolean compose_search_string_backward(Compose *compose,
9356 const gchar *str, gboolean case_sens)
9358 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9360 return gtkut_text_view_search_string_backward(text, str, case_sens);
9363 /* allocate a msginfo structure and populate its data from a compose data structure */
9364 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
9366 MsgInfo *newmsginfo;
9368 gchar buf[BUFFSIZE];
9370 g_return_val_if_fail( compose != NULL, NULL );
9372 newmsginfo = procmsg_msginfo_new();
9375 get_rfc822_date(buf, sizeof(buf));
9376 newmsginfo->date = g_strdup(buf);
9379 if (compose->from_name) {
9380 newmsginfo->from = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
9381 newmsginfo->fromname = procheader_get_fromname(newmsginfo->from);
9385 if (compose->subject_entry)
9386 newmsginfo->subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
9388 /* to, cc, reply-to, newsgroups */
9389 for (list = compose->header_list; list; list = list->next) {
9390 gchar *header = gtk_editable_get_chars(
9392 GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
9393 gchar *entry = gtk_editable_get_chars(
9394 GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
9396 if ( strcasecmp(header, (prefs_common.trans_hdr ? gettext("To:") : "To:")) == 0 ) {
9397 if ( newmsginfo->to == NULL ) {
9398 newmsginfo->to = g_strdup(entry);
9400 gchar *tmp = g_strconcat(newmsginfo->to, ", ", entry, NULL);
9401 g_free(newmsginfo->to);
9402 newmsginfo->to = tmp;
9405 if ( strcasecmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:")) == 0 ) {
9406 if ( newmsginfo->cc == NULL ) {
9407 newmsginfo->cc = g_strdup(entry);
9409 gchar *tmp = g_strconcat(newmsginfo->cc, ", ", entry, NULL);
9410 g_free(newmsginfo->cc);
9411 newmsginfo->cc = tmp;
9414 if ( strcasecmp(header,
9415 (prefs_common.trans_hdr ? gettext("Newsgroups:") : "Newsgroups:")) == 0 ) {
9416 if ( newmsginfo->newsgroups == NULL ) {
9417 newmsginfo->newsgroups = g_strdup(entry);
9419 gchar *tmp = g_strconcat(newmsginfo->newsgroups, ", ", entry, NULL);
9420 g_free(newmsginfo->newsgroups);
9421 newmsginfo->newsgroups = tmp;
9429 /* other data is unset */