2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
123 #include "combobox.h"
137 #define N_ATTACH_COLS (N_COL_COLUMNS)
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
148 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
154 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
155 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
156 } ComposeCallAdvancedAction;
160 PRIORITY_HIGHEST = 1,
169 COMPOSE_INSERT_SUCCESS,
170 COMPOSE_INSERT_READ_ERROR,
171 COMPOSE_INSERT_INVALID_CHARACTER,
172 COMPOSE_INSERT_NO_FILE
173 } ComposeInsertResult;
177 COMPOSE_WRITE_FOR_SEND,
178 COMPOSE_WRITE_FOR_STORE
181 #define B64_LINE_SIZE 57
182 #define B64_BUFFSIZE 77
184 #define MAX_REFERENCES_LEN 999
186 static GList *compose_list = NULL;
188 static Compose *compose_generic_new (PrefsAccount *account,
191 GPtrArray *attach_files,
192 GList *listAddress );
194 static Compose *compose_create (PrefsAccount *account,
198 static void compose_entry_mark_default_to (Compose *compose,
199 const gchar *address);
200 static Compose *compose_followup_and_reply_to (MsgInfo *msginfo,
205 static Compose *compose_forward_multiple (PrefsAccount *account,
206 GSList *msginfo_list);
207 static Compose *compose_reply (MsgInfo *msginfo,
213 static Compose *compose_reply_mode (ComposeMode mode,
214 GSList *msginfo_list,
216 static void compose_template_apply_fields(Compose *compose, Template *tmpl);
217 static void compose_update_privacy_systems_menu(Compose *compose);
219 static GtkWidget *compose_account_option_menu_create
221 static void compose_set_out_encoding (Compose *compose);
222 static void compose_set_template_menu (Compose *compose);
223 static void compose_template_apply (Compose *compose,
226 static void compose_destroy (Compose *compose);
228 static void compose_entries_set (Compose *compose,
229 const gchar *mailto);
230 static gint compose_parse_header (Compose *compose,
232 static gchar *compose_parse_references (const gchar *ref,
235 static gchar *compose_quote_fmt (Compose *compose,
241 gboolean need_unescape,
242 const gchar *err_msg);
244 static void compose_reply_set_entry (Compose *compose,
250 followup_and_reply_to);
251 static void compose_reedit_set_entry (Compose *compose,
254 static void compose_insert_sig (Compose *compose,
256 static gchar *compose_get_signature_str (Compose *compose);
257 static ComposeInsertResult compose_insert_file (Compose *compose,
260 static gboolean compose_attach_append (Compose *compose,
263 const gchar *content_type);
264 static void compose_attach_parts (Compose *compose,
267 static void compose_beautify_paragraph (Compose *compose,
268 GtkTextIter *par_iter,
270 static void compose_wrap_all (Compose *compose);
271 static void compose_wrap_all_full (Compose *compose,
274 static void compose_set_title (Compose *compose);
275 static void compose_select_account (Compose *compose,
276 PrefsAccount *account,
279 static PrefsAccount *compose_current_mail_account(void);
280 /* static gint compose_send (Compose *compose); */
281 static gboolean compose_check_for_valid_recipient
283 static gboolean compose_check_entries (Compose *compose,
284 gboolean check_everything);
285 static gint compose_write_to_file (Compose *compose,
288 gboolean attach_parts);
289 static gint compose_write_body_to_file (Compose *compose,
291 static gint compose_remove_reedit_target (Compose *compose,
293 static void compose_remove_draft (Compose *compose);
294 static gint compose_queue_sub (Compose *compose,
298 gboolean check_subject,
299 gboolean remove_reedit_target);
300 static void compose_add_attachments (Compose *compose,
302 static gchar *compose_get_header (Compose *compose);
304 static void compose_convert_header (Compose *compose,
309 gboolean addr_field);
311 static void compose_attach_info_free (AttachInfo *ainfo);
312 static void compose_attach_remove_selected (Compose *compose);
314 static void compose_attach_property (Compose *compose);
315 static void compose_attach_property_create (gboolean *cancelled);
316 static void attach_property_ok (GtkWidget *widget,
317 gboolean *cancelled);
318 static void attach_property_cancel (GtkWidget *widget,
319 gboolean *cancelled);
320 static gint attach_property_delete_event (GtkWidget *widget,
322 gboolean *cancelled);
323 static gboolean attach_property_key_pressed (GtkWidget *widget,
325 gboolean *cancelled);
327 static void compose_exec_ext_editor (Compose *compose);
329 static gint compose_exec_ext_editor_real (const gchar *file);
330 static gboolean compose_ext_editor_kill (Compose *compose);
331 static gboolean compose_input_cb (GIOChannel *source,
332 GIOCondition condition,
334 static void compose_set_ext_editor_sensitive (Compose *compose,
336 #endif /* G_OS_UNIX */
338 static void compose_undo_state_changed (UndoMain *undostruct,
343 static void compose_create_header_entry (Compose *compose);
344 static void compose_add_header_entry (Compose *compose, const gchar *header, gchar *text);
345 static void compose_remove_header_entries(Compose *compose);
347 static void compose_update_priority_menu_item(Compose * compose);
349 static void compose_spell_menu_changed (void *data);
351 static void compose_add_field_list ( Compose *compose,
352 GList *listAddress );
354 /* callback functions */
356 static gboolean compose_edit_size_alloc (GtkEditable *widget,
357 GtkAllocation *allocation,
358 GtkSHRuler *shruler);
359 static void account_activated (GtkComboBox *optmenu,
361 static void attach_selected (GtkTreeView *tree_view,
362 GtkTreePath *tree_path,
363 GtkTreeViewColumn *column,
365 static gboolean attach_button_pressed (GtkWidget *widget,
366 GdkEventButton *event,
368 static gboolean attach_key_pressed (GtkWidget *widget,
371 static void compose_send_cb (gpointer data,
374 static void compose_send_later_cb (gpointer data,
378 static void compose_draft_cb (gpointer data,
382 static void compose_attach_cb (gpointer data,
385 static void compose_insert_file_cb (gpointer data,
388 static void compose_insert_sig_cb (gpointer data,
392 static void compose_close_cb (gpointer data,
396 static void compose_set_encoding_cb (gpointer data,
400 static void compose_address_cb (gpointer data,
403 static void compose_template_activate_cb(GtkWidget *widget,
406 static void compose_ext_editor_cb (gpointer data,
410 static gint compose_delete_cb (GtkWidget *widget,
414 static void compose_undo_cb (Compose *compose);
415 static void compose_redo_cb (Compose *compose);
416 static void compose_cut_cb (Compose *compose);
417 static void compose_copy_cb (Compose *compose);
418 static void compose_paste_cb (Compose *compose);
419 static void compose_paste_as_quote_cb (Compose *compose);
420 static void compose_paste_no_wrap_cb (Compose *compose);
421 static void compose_paste_wrap_cb (Compose *compose);
422 static void compose_allsel_cb (Compose *compose);
424 static void compose_advanced_action_cb (Compose *compose,
425 ComposeCallAdvancedAction action);
427 static void compose_grab_focus_cb (GtkWidget *widget,
430 static void compose_changed_cb (GtkTextBuffer *textbuf,
433 static void compose_wrap_cb (gpointer data,
436 static void compose_find_cb (gpointer data,
439 static void compose_toggle_autowrap_cb (gpointer data,
443 static void compose_toggle_ruler_cb (gpointer data,
446 static void compose_toggle_sign_cb (gpointer data,
449 static void compose_toggle_encrypt_cb (gpointer data,
452 static void compose_set_privacy_system_cb(GtkWidget *widget,
454 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
455 static void activate_privacy_system (Compose *compose,
456 PrefsAccount *account,
458 static void compose_use_signing(Compose *compose, gboolean use_signing);
459 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
460 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
462 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
464 static void compose_set_priority_cb (gpointer data,
467 static void compose_reply_change_mode (gpointer data,
471 static void compose_attach_drag_received_cb (GtkWidget *widget,
472 GdkDragContext *drag_context,
475 GtkSelectionData *data,
479 static void compose_insert_drag_received_cb (GtkWidget *widget,
480 GdkDragContext *drag_context,
483 GtkSelectionData *data,
487 static void compose_header_drag_received_cb (GtkWidget *widget,
488 GdkDragContext *drag_context,
491 GtkSelectionData *data,
496 static gboolean compose_drag_drop (GtkWidget *widget,
497 GdkDragContext *drag_context,
499 guint time, gpointer user_data);
501 static void text_inserted (GtkTextBuffer *buffer,
506 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
507 gboolean to_all, gboolean to_ml,
509 gboolean followup_and_reply_to,
512 static gboolean compose_headerentry_changed_cb (GtkWidget *entry,
513 ComposeHeaderEntry *headerentry);
514 static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
516 ComposeHeaderEntry *headerentry);
518 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
520 static void compose_allow_user_actions (Compose *compose, gboolean allow);
523 static void compose_check_all (Compose *compose);
524 static void compose_highlight_all (Compose *compose);
525 static void compose_check_backwards (Compose *compose);
526 static void compose_check_forwards_go (Compose *compose);
529 static gint compose_defer_auto_save_draft (Compose *compose);
530 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
532 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
535 static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
536 FolderItem *folder_item);
539 static GtkItemFactoryEntry compose_popup_entries[] =
541 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
542 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
543 {"/---", NULL, NULL, 0, "<Separator>"},
544 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
547 static GtkItemFactoryEntry compose_entries[] =
549 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
550 {N_("/_Message/S_end"), "<control>Return",
551 compose_send_cb, 0, NULL},
552 {N_("/_Message/Send _later"), "<shift><control>S",
553 compose_send_later_cb, 0, NULL},
554 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
555 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
556 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
557 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
558 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
559 {N_("/_Message/_Save"),
560 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
561 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
562 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
564 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
565 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
566 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
567 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
568 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
569 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
570 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
571 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
572 {N_("/_Edit/Special paste/as _quotation"),
573 NULL, compose_paste_as_quote_cb, 0, NULL},
574 {N_("/_Edit/Special paste/_wrapped"),
575 NULL, compose_paste_wrap_cb, 0, NULL},
576 {N_("/_Edit/Special paste/_unwrapped"),
577 NULL, compose_paste_no_wrap_cb, 0, NULL},
578 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
579 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
580 {N_("/_Edit/A_dvanced/Move a character backward"),
582 compose_advanced_action_cb,
583 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
585 {N_("/_Edit/A_dvanced/Move a character forward"),
587 compose_advanced_action_cb,
588 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
590 {N_("/_Edit/A_dvanced/Move a word backward"),
592 compose_advanced_action_cb,
593 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
595 {N_("/_Edit/A_dvanced/Move a word forward"),
597 compose_advanced_action_cb,
598 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
600 {N_("/_Edit/A_dvanced/Move to beginning of line"),
601 NULL, /* "<control>A" */
602 compose_advanced_action_cb,
603 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
605 {N_("/_Edit/A_dvanced/Move to end of line"),
607 compose_advanced_action_cb,
608 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
610 {N_("/_Edit/A_dvanced/Move to previous line"),
612 compose_advanced_action_cb,
613 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
615 {N_("/_Edit/A_dvanced/Move to next line"),
617 compose_advanced_action_cb,
618 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
620 {N_("/_Edit/A_dvanced/Delete a character backward"),
622 compose_advanced_action_cb,
623 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
625 {N_("/_Edit/A_dvanced/Delete a character forward"),
627 compose_advanced_action_cb,
628 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
630 {N_("/_Edit/A_dvanced/Delete a word backward"),
631 NULL, /* "<control>W" */
632 compose_advanced_action_cb,
633 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
635 {N_("/_Edit/A_dvanced/Delete a word forward"),
636 NULL, /* "<alt>D", */
637 compose_advanced_action_cb,
638 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
640 {N_("/_Edit/A_dvanced/Delete line"),
642 compose_advanced_action_cb,
643 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
645 {N_("/_Edit/A_dvanced/Delete entire line"),
647 compose_advanced_action_cb,
648 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
650 {N_("/_Edit/A_dvanced/Delete to end of line"),
652 compose_advanced_action_cb,
653 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
655 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
657 "<control>F", compose_find_cb, 0, NULL},
658 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Edit/_Wrap current paragraph"),
660 "<control>L", compose_wrap_cb, 0, NULL},
661 {N_("/_Edit/Wrap all long _lines"),
662 "<control><alt>L", compose_wrap_cb, 1, NULL},
663 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
664 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
665 {N_("/_Edit/Edit with e_xternal editor"),
666 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
668 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Spelling/_Check all or check selection"),
670 NULL, compose_check_all, 0, NULL},
671 {N_("/_Spelling/_Highlight all misspelled words"),
672 NULL, compose_highlight_all, 0, NULL},
673 {N_("/_Spelling/Check _backwards misspelled word"),
674 NULL, compose_check_backwards , 0, NULL},
675 {N_("/_Spelling/_Forward to next misspelled word"),
676 NULL, compose_check_forwards_go, 0, NULL},
677 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
678 {N_("/_Spelling/Options"),
679 NULL, NULL, 0, "<Branch>"},
681 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
682 {N_("/_Options/Reply _mode"), NULL, NULL, 0, "<Branch>"},
683 {N_("/_Options/Reply _mode/_Normal"), NULL, compose_reply_change_mode, COMPOSE_REPLY, "<RadioItem>"},
684 {N_("/_Options/Reply _mode/_All"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_ALL, "/Options/Reply mode/Normal"},
685 {N_("/_Options/Reply _mode/_Sender"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_SENDER, "/Options/Reply mode/Normal"},
686 {N_("/_Options/Reply _mode/_Mailing-list"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_LIST, "/Options/Reply mode/Normal"},
687 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
688 {N_("/_Options/Privacy _System"), NULL, NULL, 0, "<Branch>"},
689 {N_("/_Options/Privacy _System/None"), NULL, NULL, 0, "<RadioItem>"},
690 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
691 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
692 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
693 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
694 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
695 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
696 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
697 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
698 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
699 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
700 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
701 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
702 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
703 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
705 #define ENC_ACTION(action) \
706 NULL, compose_set_encoding_cb, action, \
707 "/Options/Character encoding/Automatic"
709 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
710 {N_("/_Options/Character _encoding/_Automatic"),
711 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
712 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
714 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
715 ENC_ACTION(C_US_ASCII)},
716 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
717 ENC_ACTION(C_UTF_8)},
718 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
720 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
721 ENC_ACTION(C_ISO_8859_1)},
722 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
723 ENC_ACTION(C_ISO_8859_15)},
724 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
725 ENC_ACTION(C_WINDOWS_1252)},
726 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
728 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
729 ENC_ACTION(C_ISO_8859_2)},
730 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
732 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
733 ENC_ACTION(C_ISO_8859_13)},
734 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
735 ENC_ACTION(C_ISO_8859_4)},
736 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
738 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
739 ENC_ACTION(C_ISO_8859_7)},
740 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
742 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
743 ENC_ACTION(C_ISO_8859_8)},
744 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
745 ENC_ACTION(C_WINDOWS_1255)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
749 ENC_ACTION(C_ISO_8859_6)},
750 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
751 ENC_ACTION(C_CP1256)},
752 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
754 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
755 ENC_ACTION(C_ISO_8859_9)},
756 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
758 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
759 ENC_ACTION(C_ISO_8859_5)},
760 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
761 ENC_ACTION(C_KOI8_R)},
762 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
763 ENC_ACTION(C_KOI8_U)},
764 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
765 ENC_ACTION(C_WINDOWS_1251)},
766 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
768 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
769 ENC_ACTION(C_ISO_2022_JP)},
770 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
772 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
773 ENC_ACTION(C_GB2312)},
774 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
776 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
778 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
779 ENC_ACTION(C_EUC_TW)},
780 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
782 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
783 ENC_ACTION(C_EUC_KR)},
784 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
786 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
787 ENC_ACTION(C_TIS_620)},
788 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
789 ENC_ACTION(C_WINDOWS_874)},
791 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
792 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
793 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
794 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
795 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
796 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
797 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
800 static GtkTargetEntry compose_mime_types[] =
802 {"text/uri-list", 0, 0},
803 {"UTF8_STRING", 0, 0},
807 static gboolean compose_put_existing_to_front(MsgInfo *info)
809 GList *compose_list = compose_get_compose_list();
813 for (elem = compose_list; elem != NULL && elem->data != NULL;
815 Compose *c = (Compose*)elem->data;
817 if (!c->targetinfo || !c->targetinfo->msgid ||
821 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
822 gtkut_window_popup(c->window);
830 static GdkColor quote_color1 =
831 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
832 static GdkColor quote_color2 =
833 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
834 static GdkColor quote_color3 =
835 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
837 static GdkColor quote_bgcolor1 =
838 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
839 static GdkColor quote_bgcolor2 =
840 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
841 static GdkColor quote_bgcolor3 =
842 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
844 static GdkColor signature_color = {
851 static GdkColor uri_color = {
858 static void compose_create_tags(GtkTextView *text, Compose *compose)
860 GtkTextBuffer *buffer;
861 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
867 buffer = gtk_text_view_get_buffer(text);
869 if (prefs_common.enable_color) {
870 /* grab the quote colors, converting from an int to a GdkColor */
871 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
873 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
875 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
877 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
879 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
881 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
883 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
885 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
888 signature_color = quote_color1 = quote_color2 = quote_color3 =
889 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
892 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
893 gtk_text_buffer_create_tag(buffer, "quote0",
894 "foreground-gdk", "e_color1,
895 "paragraph-background-gdk", "e_bgcolor1,
897 gtk_text_buffer_create_tag(buffer, "quote1",
898 "foreground-gdk", "e_color2,
899 "paragraph-background-gdk", "e_bgcolor2,
901 gtk_text_buffer_create_tag(buffer, "quote2",
902 "foreground-gdk", "e_color3,
903 "paragraph-background-gdk", "e_bgcolor3,
906 gtk_text_buffer_create_tag(buffer, "quote0",
907 "foreground-gdk", "e_color1,
909 gtk_text_buffer_create_tag(buffer, "quote1",
910 "foreground-gdk", "e_color2,
912 gtk_text_buffer_create_tag(buffer, "quote2",
913 "foreground-gdk", "e_color3,
917 gtk_text_buffer_create_tag(buffer, "signature",
918 "foreground-gdk", &signature_color,
920 gtk_text_buffer_create_tag(buffer, "link",
921 "foreground-gdk", &uri_color,
923 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
924 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
926 color[0] = quote_color1;
927 color[1] = quote_color2;
928 color[2] = quote_color3;
929 color[3] = quote_bgcolor1;
930 color[4] = quote_bgcolor2;
931 color[5] = quote_bgcolor3;
932 color[6] = signature_color;
933 color[7] = uri_color;
934 cmap = gdk_drawable_get_colormap(compose->window->window);
935 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
937 for (i = 0; i < 8; i++) {
938 if (success[i] == FALSE) {
941 g_warning("Compose: color allocation failed.\n");
942 style = gtk_widget_get_style(GTK_WIDGET(text));
943 quote_color1 = quote_color2 = quote_color3 =
944 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
945 signature_color = uri_color = black;
950 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
951 GPtrArray *attach_files)
953 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
956 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item, const gchar *mailto)
958 return compose_generic_new(account, mailto, item, NULL, NULL);
961 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
963 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
966 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
967 GPtrArray *attach_files, GList *listAddress )
970 GtkTextView *textview;
971 GtkTextBuffer *textbuf;
973 GtkItemFactory *ifactory;
975 if (item && item->prefs && item->prefs->enable_default_account)
976 account = account_find_from_id(item->prefs->default_account);
978 if (!account) account = cur_account;
979 g_return_val_if_fail(account != NULL, NULL);
981 compose = compose_create(account, COMPOSE_NEW, FALSE);
983 ifactory = gtk_item_factory_from_widget(compose->menubar);
985 compose->replyinfo = NULL;
986 compose->fwdinfo = NULL;
988 textview = GTK_TEXT_VIEW(compose->text);
989 textbuf = gtk_text_view_get_buffer(textview);
990 compose_create_tags(textview, compose);
992 undo_block(compose->undostruct);
994 compose_set_dictionaries_from_folder_prefs(compose, item);
997 if (account->auto_sig)
998 compose_insert_sig(compose, FALSE);
999 gtk_text_buffer_get_start_iter(textbuf, &iter);
1000 gtk_text_buffer_place_cursor(textbuf, &iter);
1002 if (account->protocol != A_NNTP) {
1003 if (mailto && *mailto != '\0') {
1004 compose_entries_set(compose, mailto);
1006 } else if (item && item->prefs->enable_default_to) {
1007 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
1008 compose_entry_mark_default_to(compose, item->prefs->default_to);
1010 if (item && item->ret_rcpt) {
1011 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1015 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
1016 } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
1017 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
1020 * CLAWS: just don't allow return receipt request, even if the user
1021 * may want to send an email. simple but foolproof.
1023 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1025 compose_add_field_list( compose, listAddress );
1027 if (prefs_common.compose_with_format) {
1028 MsgInfo* dummyinfo = NULL;
1030 if ( prefs_common.compose_subject_format
1031 && *prefs_common.compose_subject_format != '\0' )
1033 gchar *subject = NULL;
1037 dummyinfo = compose_msginfo_new_from_compose(compose);
1039 /* decode \-escape sequences in the internal representation of the quote format */
1040 tmp = malloc(strlen(prefs_common.compose_subject_format)+1);
1041 pref_get_unescaped_pref(tmp, prefs_common.compose_subject_format);
1043 subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
1045 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account,
1046 compose->gtkaspell);
1048 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account);
1050 quote_fmt_scan_string(tmp);
1053 buf = quote_fmt_get_buffer();
1055 alertpanel_error(_("New message subject format error."));
1057 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
1058 quote_fmt_reset_vartable();
1064 if ( prefs_common.compose_body_format
1065 && *prefs_common.compose_body_format != '\0' )
1068 GtkTextBuffer *buffer;
1069 GtkTextIter start, end;
1072 if ( dummyinfo == NULL )
1073 dummyinfo = compose_msginfo_new_from_compose(compose);
1075 text = GTK_TEXT_VIEW(compose->text);
1076 buffer = gtk_text_view_get_buffer(text);
1077 gtk_text_buffer_get_start_iter(buffer, &start);
1078 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
1079 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
1081 compose_quote_fmt(compose, dummyinfo,
1082 prefs_common.compose_body_format,
1083 NULL, tmp, FALSE, TRUE,
1084 _("New message body format error."));
1085 quote_fmt_reset_vartable();
1090 procmsg_msginfo_free( dummyinfo );
1097 for (i = 0; i < attach_files->len; i++) {
1098 file = g_ptr_array_index(attach_files, i);
1099 compose_attach_append(compose, file, file, NULL);
1103 compose_show_first_last_header(compose, TRUE);
1105 /* Set save folder */
1106 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1107 gchar *folderidentifier;
1109 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1110 folderidentifier = folder_item_get_identifier(item);
1111 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1112 g_free(folderidentifier);
1115 gtk_widget_grab_focus(compose->header_last->entry);
1117 undo_unblock(compose->undostruct);
1119 if (prefs_common.auto_exteditor)
1120 compose_exec_ext_editor(compose);
1122 compose->modified = FALSE;
1123 compose_set_title(compose);
1127 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1128 gboolean override_pref)
1130 gchar *privacy = NULL;
1132 g_return_if_fail(compose != NULL);
1133 g_return_if_fail(account != NULL);
1135 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1138 if (account->default_privacy_system
1139 && strlen(account->default_privacy_system)) {
1140 privacy = account->default_privacy_system;
1142 GSList *privacy_avail = privacy_get_system_ids();
1143 if (privacy_avail && g_slist_length(privacy_avail)) {
1144 privacy = (gchar *)(privacy_avail->data);
1147 if (privacy != NULL) {
1148 if (compose->privacy_system == NULL)
1149 compose->privacy_system = g_strdup(privacy);
1150 compose_update_privacy_system_menu_item(compose, FALSE);
1151 compose_use_encryption(compose, TRUE);
1155 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1157 gchar *privacy = NULL;
1159 if (account->default_privacy_system
1160 && strlen(account->default_privacy_system)) {
1161 privacy = account->default_privacy_system;
1163 GSList *privacy_avail = privacy_get_system_ids();
1164 if (privacy_avail && g_slist_length(privacy_avail)) {
1165 privacy = (gchar *)(privacy_avail->data);
1168 if (privacy != NULL) {
1169 if (compose->privacy_system == NULL)
1170 compose->privacy_system = g_strdup(privacy);
1171 compose_update_privacy_system_menu_item(compose, FALSE);
1172 compose_use_signing(compose, TRUE);
1176 static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1180 Compose *compose = NULL;
1181 GtkItemFactory *ifactory = NULL;
1183 g_return_val_if_fail(msginfo_list != NULL, NULL);
1185 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1186 g_return_val_if_fail(msginfo != NULL, NULL);
1188 list_len = g_slist_length(msginfo_list);
1192 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1193 FALSE, prefs_common.default_reply_list, FALSE, body);
1195 case COMPOSE_REPLY_WITH_QUOTE:
1196 compose = compose_reply(msginfo, TRUE,
1197 FALSE, prefs_common.default_reply_list, FALSE, body);
1199 case COMPOSE_REPLY_WITHOUT_QUOTE:
1200 compose = compose_reply(msginfo, FALSE,
1201 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1203 case COMPOSE_REPLY_TO_SENDER:
1204 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1205 FALSE, FALSE, TRUE, body);
1207 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1208 compose = compose_followup_and_reply_to(msginfo,
1209 prefs_common.reply_with_quote,
1210 FALSE, FALSE, body);
1212 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1213 compose = compose_reply(msginfo, TRUE,
1214 FALSE, FALSE, TRUE, body);
1216 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1217 compose = compose_reply(msginfo, FALSE,
1218 FALSE, FALSE, TRUE, NULL);
1220 case COMPOSE_REPLY_TO_ALL:
1221 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1222 TRUE, FALSE, FALSE, body);
1224 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1225 compose = compose_reply(msginfo, TRUE,
1226 TRUE, FALSE, FALSE, body);
1228 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1229 compose = compose_reply(msginfo, FALSE,
1230 TRUE, FALSE, FALSE, NULL);
1232 case COMPOSE_REPLY_TO_LIST:
1233 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1234 FALSE, TRUE, FALSE, body);
1236 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1237 compose = compose_reply(msginfo, TRUE,
1238 FALSE, TRUE, FALSE, body);
1240 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1241 compose = compose_reply(msginfo, FALSE,
1242 FALSE, TRUE, FALSE, NULL);
1244 case COMPOSE_FORWARD:
1245 if (prefs_common.forward_as_attachment) {
1246 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1249 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1253 case COMPOSE_FORWARD_INLINE:
1254 /* check if we reply to more than one Message */
1255 if (list_len == 1) {
1256 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1259 /* more messages FALL THROUGH */
1260 case COMPOSE_FORWARD_AS_ATTACH:
1261 compose = compose_forward_multiple(NULL, msginfo_list);
1263 case COMPOSE_REDIRECT:
1264 compose = compose_redirect(NULL, msginfo, FALSE);
1267 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1270 ifactory = gtk_item_factory_from_widget(compose->menubar);
1272 compose->rmode = mode;
1273 switch (compose->rmode) {
1275 case COMPOSE_REPLY_WITH_QUOTE:
1276 case COMPOSE_REPLY_WITHOUT_QUOTE:
1277 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1278 debug_print("reply mode Normal\n");
1279 menu_set_active(ifactory, "/Options/Reply mode/Normal", TRUE);
1280 compose_reply_change_mode(compose, COMPOSE_REPLY, NULL); /* force update */
1282 case COMPOSE_REPLY_TO_SENDER:
1283 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1284 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1285 debug_print("reply mode Sender\n");
1286 menu_set_active(ifactory, "/Options/Reply mode/Sender", TRUE);
1288 case COMPOSE_REPLY_TO_ALL:
1289 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1290 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1291 debug_print("reply mode All\n");
1292 menu_set_active(ifactory, "/Options/Reply mode/All", TRUE);
1294 case COMPOSE_REPLY_TO_LIST:
1295 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1296 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1297 debug_print("reply mode List\n");
1298 menu_set_active(ifactory, "/Options/Reply mode/Mailing-list", TRUE);
1306 static Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1307 gboolean to_ml, gboolean to_sender,
1310 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1311 to_sender, FALSE, body);
1314 static Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1319 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1320 to_sender, TRUE, body);
1323 static void compose_extract_original_charset(Compose *compose)
1325 MsgInfo *info = NULL;
1326 if (compose->replyinfo) {
1327 info = compose->replyinfo;
1328 } else if (compose->fwdinfo) {
1329 info = compose->fwdinfo;
1330 } else if (compose->targetinfo) {
1331 info = compose->targetinfo;
1334 MimeInfo *mimeinfo = procmime_scan_message(info);
1335 MimeInfo *partinfo = mimeinfo;
1336 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1337 partinfo = procmime_mimeinfo_next(partinfo);
1339 compose->orig_charset =
1340 g_strdup(procmime_mimeinfo_get_parameter(
1341 partinfo, "charset"));
1343 procmime_mimeinfo_free_all(mimeinfo);
1347 #define SIGNAL_BLOCK(buffer) { \
1348 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1349 G_CALLBACK(compose_changed_cb), \
1351 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1352 G_CALLBACK(text_inserted), \
1356 #define SIGNAL_UNBLOCK(buffer) { \
1357 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1358 G_CALLBACK(compose_changed_cb), \
1360 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1361 G_CALLBACK(text_inserted), \
1365 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1366 gboolean to_all, gboolean to_ml,
1368 gboolean followup_and_reply_to,
1371 GtkItemFactory *ifactory;
1373 PrefsAccount *account = NULL;
1374 PrefsAccount *reply_account;
1375 GtkTextView *textview;
1376 GtkTextBuffer *textbuf;
1378 g_return_val_if_fail(msginfo != NULL, NULL);
1379 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1381 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1383 g_return_val_if_fail(account != NULL, NULL);
1385 if (to_sender && account->protocol == A_NNTP &&
1386 !followup_and_reply_to) {
1388 account_find_from_address(account->address);
1390 reply_account = compose_current_mail_account();
1394 reply_account = account;
1396 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1398 compose->updating = TRUE;
1400 ifactory = gtk_item_factory_from_widget(compose->menubar);
1402 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1403 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1405 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1406 if (!compose->replyinfo)
1407 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1409 compose_extract_original_charset(compose);
1411 if (msginfo->folder && msginfo->folder->ret_rcpt)
1412 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1414 /* Set save folder */
1415 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1416 gchar *folderidentifier;
1418 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1419 folderidentifier = folder_item_get_identifier(msginfo->folder);
1420 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1421 g_free(folderidentifier);
1424 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1426 textview = (GTK_TEXT_VIEW(compose->text));
1427 textbuf = gtk_text_view_get_buffer(textview);
1428 compose_create_tags(textview, compose);
1430 undo_block(compose->undostruct);
1432 compose_set_dictionaries_from_folder_prefs(compose, msginfo->folder);
1438 if (prefs_common.quotemark && *prefs_common.quotemark)
1439 qmark = prefs_common.quotemark;
1443 compose_quote_fmt(compose, compose->replyinfo,
1444 prefs_common.quotefmt,
1445 qmark, body, FALSE, TRUE,
1446 _("Message reply format error."));
1447 quote_fmt_reset_vartable();
1449 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1450 compose_force_encryption(compose, account, FALSE);
1453 SIGNAL_BLOCK(textbuf);
1455 if (account->auto_sig)
1456 compose_insert_sig(compose, FALSE);
1458 compose_wrap_all(compose);
1460 SIGNAL_UNBLOCK(textbuf);
1462 gtk_widget_grab_focus(compose->text);
1464 undo_unblock(compose->undostruct);
1466 if (prefs_common.auto_exteditor)
1467 compose_exec_ext_editor(compose);
1469 compose->modified = FALSE;
1470 compose_set_title(compose);
1472 compose->updating = FALSE;
1474 if (compose->deferred_destroy) {
1475 compose_destroy(compose);
1482 #define INSERT_FW_HEADER(var, hdr) \
1483 if (msginfo->var && *msginfo->var) { \
1484 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1485 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1486 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1489 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1490 gboolean as_attach, const gchar *body,
1491 gboolean no_extedit,
1495 GtkTextView *textview;
1496 GtkTextBuffer *textbuf;
1499 g_return_val_if_fail(msginfo != NULL, NULL);
1500 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1503 !(account = compose_guess_forward_account_from_msginfo
1505 account = cur_account;
1507 compose = compose_create(account, COMPOSE_FORWARD, batch);
1509 compose->updating = TRUE;
1510 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1511 if (!compose->fwdinfo)
1512 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1514 compose_extract_original_charset(compose);
1516 if (msginfo->subject && *msginfo->subject) {
1517 gchar *buf, *buf2, *p;
1519 buf = p = g_strdup(msginfo->subject);
1520 p += subject_get_prefix_length(p);
1521 memmove(buf, p, strlen(p) + 1);
1523 buf2 = g_strdup_printf("Fw: %s", buf);
1524 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1530 textview = GTK_TEXT_VIEW(compose->text);
1531 textbuf = gtk_text_view_get_buffer(textview);
1532 compose_create_tags(textview, compose);
1534 undo_block(compose->undostruct);
1538 msgfile = procmsg_get_message_file_path(msginfo);
1539 if (!is_file_exist(msgfile))
1540 g_warning("%s: file not exist\n", msgfile);
1542 compose_attach_append(compose, msgfile, msgfile,
1548 MsgInfo *full_msginfo;
1550 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1552 full_msginfo = procmsg_msginfo_copy(msginfo);
1554 if (prefs_common.fw_quotemark &&
1555 *prefs_common.fw_quotemark)
1556 qmark = prefs_common.fw_quotemark;
1560 compose_quote_fmt(compose, full_msginfo,
1561 prefs_common.fw_quotefmt,
1562 qmark, body, FALSE, TRUE,
1563 _("Message forward format error."));
1564 quote_fmt_reset_vartable();
1565 compose_attach_parts(compose, msginfo);
1567 procmsg_msginfo_free(full_msginfo);
1570 SIGNAL_BLOCK(textbuf);
1572 if (account->auto_sig)
1573 compose_insert_sig(compose, FALSE);
1575 compose_wrap_all(compose);
1577 SIGNAL_UNBLOCK(textbuf);
1579 gtk_text_buffer_get_start_iter(textbuf, &iter);
1580 gtk_text_buffer_place_cursor(textbuf, &iter);
1582 gtk_widget_grab_focus(compose->header_last->entry);
1584 if (!no_extedit && prefs_common.auto_exteditor)
1585 compose_exec_ext_editor(compose);
1588 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1589 gchar *folderidentifier;
1591 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1592 folderidentifier = folder_item_get_identifier(msginfo->folder);
1593 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1594 g_free(folderidentifier);
1597 undo_unblock(compose->undostruct);
1599 compose->modified = FALSE;
1600 compose_set_title(compose);
1602 compose->updating = FALSE;
1604 if (compose->deferred_destroy) {
1605 compose_destroy(compose);
1612 #undef INSERT_FW_HEADER
1614 static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1617 GtkTextView *textview;
1618 GtkTextBuffer *textbuf;
1622 gboolean single_mail = TRUE;
1624 g_return_val_if_fail(msginfo_list != NULL, NULL);
1626 if (g_slist_length(msginfo_list) > 1)
1627 single_mail = FALSE;
1629 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1630 if (((MsgInfo *)msginfo->data)->folder == NULL)
1633 /* guess account from first selected message */
1635 !(account = compose_guess_forward_account_from_msginfo
1636 (msginfo_list->data)))
1637 account = cur_account;
1639 g_return_val_if_fail(account != NULL, NULL);
1641 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1642 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1643 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1646 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1648 compose->updating = TRUE;
1650 textview = GTK_TEXT_VIEW(compose->text);
1651 textbuf = gtk_text_view_get_buffer(textview);
1652 compose_create_tags(textview, compose);
1654 undo_block(compose->undostruct);
1655 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1656 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1658 if (!is_file_exist(msgfile))
1659 g_warning("%s: file not exist\n", msgfile);
1661 compose_attach_append(compose, msgfile, msgfile,
1667 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1668 if (info->subject && *info->subject) {
1669 gchar *buf, *buf2, *p;
1671 buf = p = g_strdup(info->subject);
1672 p += subject_get_prefix_length(p);
1673 memmove(buf, p, strlen(p) + 1);
1675 buf2 = g_strdup_printf("Fw: %s", buf);
1676 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1682 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1683 _("Fw: multiple emails"));
1686 SIGNAL_BLOCK(textbuf);
1688 if (account->auto_sig)
1689 compose_insert_sig(compose, FALSE);
1691 compose_wrap_all(compose);
1693 SIGNAL_UNBLOCK(textbuf);
1695 gtk_text_buffer_get_start_iter(textbuf, &iter);
1696 gtk_text_buffer_place_cursor(textbuf, &iter);
1698 gtk_widget_grab_focus(compose->header_last->entry);
1699 undo_unblock(compose->undostruct);
1700 compose->modified = FALSE;
1701 compose_set_title(compose);
1703 compose->updating = FALSE;
1705 if (compose->deferred_destroy) {
1706 compose_destroy(compose);
1713 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1715 GtkTextIter start = *iter;
1716 GtkTextIter end_iter;
1717 int start_pos = gtk_text_iter_get_offset(&start);
1719 if (!compose->account->sig_sep)
1722 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1723 start_pos+strlen(compose->account->sig_sep));
1725 /* check sig separator */
1726 str = gtk_text_iter_get_text(&start, &end_iter);
1727 if (!strcmp(str, compose->account->sig_sep)) {
1729 /* check end of line (\n) */
1730 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1731 start_pos+strlen(compose->account->sig_sep));
1732 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1733 start_pos+strlen(compose->account->sig_sep)+1);
1734 tmp = gtk_text_iter_get_text(&start, &end_iter);
1735 if (!strcmp(tmp,"\n")) {
1747 static void compose_colorize_signature(Compose *compose)
1749 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1751 GtkTextIter end_iter;
1752 gtk_text_buffer_get_start_iter(buffer, &iter);
1753 while (gtk_text_iter_forward_line(&iter))
1754 if (compose_is_sig_separator(compose, buffer, &iter)) {
1755 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1756 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1760 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1762 Compose *compose = NULL;
1763 PrefsAccount *account = NULL;
1764 GtkTextView *textview;
1765 GtkTextBuffer *textbuf;
1769 gchar buf[BUFFSIZE];
1770 gboolean use_signing = FALSE;
1771 gboolean use_encryption = FALSE;
1772 gchar *privacy_system = NULL;
1773 int priority = PRIORITY_NORMAL;
1774 MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
1776 g_return_val_if_fail(msginfo != NULL, NULL);
1777 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1779 if (compose_put_existing_to_front(msginfo)) {
1783 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1784 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1785 gchar queueheader_buf[BUFFSIZE];
1788 /* Select Account from queue headers */
1789 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1790 sizeof(queueheader_buf), "X-Claws-Account-Id:")) {
1791 id = atoi(&queueheader_buf[strlen("X-Claws-Account-Id:")]);
1792 account = account_find_from_id(id);
1794 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1795 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1796 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1797 account = account_find_from_id(id);
1799 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1800 sizeof(queueheader_buf), "NAID:")) {
1801 id = atoi(&queueheader_buf[strlen("NAID:")]);
1802 account = account_find_from_id(id);
1804 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1805 sizeof(queueheader_buf), "MAID:")) {
1806 id = atoi(&queueheader_buf[strlen("MAID:")]);
1807 account = account_find_from_id(id);
1809 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1810 sizeof(queueheader_buf), "S:")) {
1811 account = account_find_from_address(queueheader_buf);
1813 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1814 sizeof(queueheader_buf), "X-Claws-Sign:")) {
1815 param = atoi(&queueheader_buf[strlen("X-Claws-Sign:")]);
1816 use_signing = param;
1819 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1820 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1821 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1822 use_signing = param;
1825 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1826 sizeof(queueheader_buf), "X-Claws-Encrypt:")) {
1827 param = atoi(&queueheader_buf[strlen("X-Claws-Encrypt:")]);
1828 use_encryption = param;
1830 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1831 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1832 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1833 use_encryption = param;
1835 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1836 sizeof(queueheader_buf), "X-Claws-Privacy-System:")) {
1837 privacy_system = g_strdup(&queueheader_buf[strlen("X-Claws-Privacy-System:")]);
1839 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1840 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1841 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1843 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1844 sizeof(queueheader_buf), "X-Priority: ")) {
1845 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1848 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1849 sizeof(queueheader_buf), "RMID:")) {
1850 gchar **tokens = g_strsplit(&queueheader_buf[strlen("RMID:")], "\t", 0);
1851 if (tokens[0] && tokens[1] && tokens[2]) {
1852 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1853 if (orig_item != NULL) {
1854 replyinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1859 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1860 sizeof(queueheader_buf), "FMID:")) {
1861 gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0);
1862 if (tokens[0] && tokens[1] && tokens[2]) {
1863 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1864 if (orig_item != NULL) {
1865 fwdinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1871 account = msginfo->folder->folder->account;
1874 if (!account && prefs_common.reedit_account_autosel) {
1875 gchar from[BUFFSIZE];
1876 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1877 extract_address(from);
1878 account = account_find_from_address(from);
1882 account = cur_account;
1884 g_return_val_if_fail(account != NULL, NULL);
1886 compose = compose_create(account, COMPOSE_REEDIT, batch);
1888 compose->replyinfo = replyinfo;
1889 compose->fwdinfo = fwdinfo;
1891 compose->updating = TRUE;
1892 compose->priority = priority;
1894 if (privacy_system != NULL) {
1895 compose->privacy_system = privacy_system;
1896 compose_use_signing(compose, use_signing);
1897 compose_use_encryption(compose, use_encryption);
1898 compose_update_privacy_system_menu_item(compose, FALSE);
1900 activate_privacy_system(compose, account, FALSE);
1903 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1905 compose_extract_original_charset(compose);
1907 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1908 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1909 gchar queueheader_buf[BUFFSIZE];
1911 /* Set message save folder */
1912 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1915 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1916 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1917 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1919 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1920 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1922 GtkItemFactory *ifactory;
1923 ifactory = gtk_item_factory_from_widget(compose->menubar);
1924 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1929 if (compose_parse_header(compose, msginfo) < 0) {
1930 compose->updating = FALSE;
1931 compose_destroy(compose);
1934 compose_reedit_set_entry(compose, msginfo);
1936 textview = GTK_TEXT_VIEW(compose->text);
1937 textbuf = gtk_text_view_get_buffer(textview);
1938 compose_create_tags(textview, compose);
1940 mark = gtk_text_buffer_get_insert(textbuf);
1941 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1943 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1944 G_CALLBACK(compose_changed_cb),
1947 if (procmime_msginfo_is_encrypted(msginfo)) {
1948 fp = procmime_get_first_encrypted_text_content(msginfo);
1950 compose_force_encryption(compose, account, TRUE);
1953 fp = procmime_get_first_text_content(msginfo);
1956 g_warning("Can't get text part\n");
1960 gboolean prev_autowrap = compose->autowrap;
1962 compose->autowrap = FALSE;
1963 while (fgets(buf, sizeof(buf), fp) != NULL) {
1965 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1967 compose_wrap_all_full(compose, FALSE);
1968 compose->autowrap = prev_autowrap;
1972 compose_attach_parts(compose, msginfo);
1974 compose_colorize_signature(compose);
1976 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1977 G_CALLBACK(compose_changed_cb),
1980 gtk_widget_grab_focus(compose->text);
1982 if (prefs_common.auto_exteditor) {
1983 compose_exec_ext_editor(compose);
1985 compose->modified = FALSE;
1986 compose_set_title(compose);
1988 compose->updating = FALSE;
1990 if (compose->deferred_destroy) {
1991 compose_destroy(compose);
1995 compose->sig_str = compose_get_signature_str(compose);
2000 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
2005 GtkItemFactory *ifactory;
2008 g_return_val_if_fail(msginfo != NULL, NULL);
2011 account = account_get_reply_account(msginfo,
2012 prefs_common.reply_account_autosel);
2013 g_return_val_if_fail(account != NULL, NULL);
2015 compose = compose_create(account, COMPOSE_REDIRECT, batch);
2017 compose->updating = TRUE;
2019 ifactory = gtk_item_factory_from_widget(compose->menubar);
2020 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
2021 compose->replyinfo = NULL;
2022 compose->fwdinfo = NULL;
2024 compose_show_first_last_header(compose, TRUE);
2026 gtk_widget_grab_focus(compose->header_last->entry);
2028 filename = procmsg_get_message_file_path(msginfo);
2030 if (filename == NULL) {
2031 compose->updating = FALSE;
2032 compose_destroy(compose);
2037 compose->redirect_filename = filename;
2039 /* Set save folder */
2040 item = msginfo->folder;
2041 if (item && item->prefs && item->prefs->save_copy_to_folder) {
2042 gchar *folderidentifier;
2044 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
2045 folderidentifier = folder_item_get_identifier(item);
2046 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
2047 g_free(folderidentifier);
2050 compose_attach_parts(compose, msginfo);
2052 if (msginfo->subject)
2053 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
2055 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
2057 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE, FALSE,
2058 _("Message redirect format error."));
2059 quote_fmt_reset_vartable();
2060 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
2062 compose_colorize_signature(compose);
2064 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
2065 menu_set_sensitive(ifactory, "/Add...", FALSE);
2066 menu_set_sensitive(ifactory, "/Remove", FALSE);
2067 menu_set_sensitive(ifactory, "/Properties...", FALSE);
2069 ifactory = gtk_item_factory_from_widget(compose->menubar);
2070 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
2071 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
2072 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
2073 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
2074 menu_set_sensitive(ifactory, "/Edit", FALSE);
2075 menu_set_sensitive(ifactory, "/Options", FALSE);
2076 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
2077 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
2079 if (compose->toolbar->draft_btn)
2080 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
2081 if (compose->toolbar->insert_btn)
2082 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
2083 if (compose->toolbar->attach_btn)
2084 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
2085 if (compose->toolbar->sig_btn)
2086 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
2087 if (compose->toolbar->exteditor_btn)
2088 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
2089 if (compose->toolbar->linewrap_current_btn)
2090 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
2091 if (compose->toolbar->linewrap_all_btn)
2092 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
2094 compose->modified = FALSE;
2095 compose_set_title(compose);
2096 compose->updating = FALSE;
2098 if (compose->deferred_destroy) {
2099 compose_destroy(compose);
2106 GList *compose_get_compose_list(void)
2108 return compose_list;
2111 void compose_entry_append(Compose *compose, const gchar *address,
2112 ComposeEntryType type)
2114 const gchar *header;
2116 gboolean in_quote = FALSE;
2117 if (!address || *address == '\0') return;
2124 header = N_("Bcc:");
2126 case COMPOSE_REPLYTO:
2127 header = N_("Reply-To:");
2129 case COMPOSE_NEWSGROUPS:
2130 header = N_("Newsgroups:");
2132 case COMPOSE_FOLLOWUPTO:
2133 header = N_( "Followup-To:");
2140 header = prefs_common_translated_header_name(header);
2142 cur = begin = (gchar *)address;
2144 /* we separate the line by commas, but not if we're inside a quoted
2146 while (*cur != '\0') {
2148 in_quote = !in_quote;
2149 if (*cur == ',' && !in_quote) {
2150 gchar *tmp = g_strdup(begin);
2152 tmp[cur-begin]='\0';
2155 while (*tmp == ' ' || *tmp == '\t')
2157 compose_add_header_entry(compose, header, tmp);
2164 gchar *tmp = g_strdup(begin);
2166 tmp[cur-begin]='\0';
2169 while (*tmp == ' ' || *tmp == '\t')
2171 compose_add_header_entry(compose, header, tmp);
2176 static void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
2178 static GdkColor yellow;
2179 static GdkColor black;
2180 static gboolean yellow_initialised = FALSE;
2184 if (!yellow_initialised) {
2185 gdk_color_parse("#f5f6be", &yellow);
2186 gdk_color_parse("#000000", &black);
2187 yellow_initialised = gdk_colormap_alloc_color(
2188 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2189 yellow_initialised &= gdk_colormap_alloc_color(
2190 gdk_colormap_get_system(), &black, FALSE, TRUE);
2193 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2194 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2195 if (gtk_entry_get_text(entry) &&
2196 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2197 if (yellow_initialised) {
2198 gtk_widget_modify_base(
2199 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2200 GTK_STATE_NORMAL, &yellow);
2201 gtk_widget_modify_text(
2202 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2203 GTK_STATE_NORMAL, &black);
2209 void compose_toolbar_cb(gint action, gpointer data)
2211 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2212 Compose *compose = (Compose*)toolbar_item->parent;
2214 g_return_if_fail(compose != NULL);
2218 compose_send_cb(compose, 0, NULL);
2221 compose_send_later_cb(compose, 0, NULL);
2224 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2227 compose_insert_file_cb(compose, 0, NULL);
2230 compose_attach_cb(compose, 0, NULL);
2233 compose_insert_sig(compose, FALSE);
2236 compose_ext_editor_cb(compose, 0, NULL);
2238 case A_LINEWRAP_CURRENT:
2239 compose_beautify_paragraph(compose, NULL, TRUE);
2241 case A_LINEWRAP_ALL:
2242 compose_wrap_all_full(compose, TRUE);
2245 compose_address_cb(compose, 0, NULL);
2248 case A_CHECK_SPELLING:
2249 compose_check_all(compose);
2257 static void compose_entries_set(Compose *compose, const gchar *mailto)
2261 gchar *subject = NULL;
2265 gchar *attach = NULL;
2267 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body, &attach);
2270 compose_entry_append(compose, to, COMPOSE_TO);
2272 compose_entry_append(compose, cc, COMPOSE_CC);
2274 if (!g_utf8_validate (subject, -1, NULL)) {
2275 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2276 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2279 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2283 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2284 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2287 gboolean prev_autowrap = compose->autowrap;
2289 compose->autowrap = FALSE;
2291 mark = gtk_text_buffer_get_insert(buffer);
2292 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2294 if (!g_utf8_validate (body, -1, NULL)) {
2295 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2296 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2299 gtk_text_buffer_insert(buffer, &iter, body, -1);
2301 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2303 compose->autowrap = prev_autowrap;
2304 if (compose->autowrap)
2305 compose_wrap_all(compose);
2309 gchar *utf8_filename = conv_filename_to_utf8(attach);
2310 if (utf8_filename) {
2311 if (compose_attach_append(compose, attach, utf8_filename, NULL)) {
2312 alertpanel_notice(_("The file '%s' has been attached."), attach);
2314 g_free(utf8_filename);
2316 alertpanel_error(_("Couldn't attach a file (charset conversion failed)."));
2326 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2328 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2329 {"Cc:", NULL, TRUE},
2330 {"References:", NULL, FALSE},
2331 {"Bcc:", NULL, TRUE},
2332 {"Newsgroups:", NULL, TRUE},
2333 {"Followup-To:", NULL, TRUE},
2334 {"List-Post:", NULL, FALSE},
2335 {"X-Priority:", NULL, FALSE},
2336 {NULL, NULL, FALSE}};
2352 g_return_val_if_fail(msginfo != NULL, -1);
2354 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2355 procheader_get_header_fields(fp, hentry);
2358 if (hentry[H_REPLY_TO].body != NULL) {
2359 if (hentry[H_REPLY_TO].body[0] != '\0') {
2361 conv_unmime_header(hentry[H_REPLY_TO].body,
2364 g_free(hentry[H_REPLY_TO].body);
2365 hentry[H_REPLY_TO].body = NULL;
2367 if (hentry[H_CC].body != NULL) {
2368 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2369 g_free(hentry[H_CC].body);
2370 hentry[H_CC].body = NULL;
2372 if (hentry[H_REFERENCES].body != NULL) {
2373 if (compose->mode == COMPOSE_REEDIT)
2374 compose->references = hentry[H_REFERENCES].body;
2376 compose->references = compose_parse_references
2377 (hentry[H_REFERENCES].body, msginfo->msgid);
2378 g_free(hentry[H_REFERENCES].body);
2380 hentry[H_REFERENCES].body = NULL;
2382 if (hentry[H_BCC].body != NULL) {
2383 if (compose->mode == COMPOSE_REEDIT)
2385 conv_unmime_header(hentry[H_BCC].body, NULL);
2386 g_free(hentry[H_BCC].body);
2387 hentry[H_BCC].body = NULL;
2389 if (hentry[H_NEWSGROUPS].body != NULL) {
2390 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2391 hentry[H_NEWSGROUPS].body = NULL;
2393 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2394 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2395 compose->followup_to =
2396 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2399 g_free(hentry[H_FOLLOWUP_TO].body);
2400 hentry[H_FOLLOWUP_TO].body = NULL;
2402 if (hentry[H_LIST_POST].body != NULL) {
2405 extract_address(hentry[H_LIST_POST].body);
2406 if (hentry[H_LIST_POST].body[0] != '\0') {
2407 scan_mailto_url(hentry[H_LIST_POST].body,
2408 &to, NULL, NULL, NULL, NULL, NULL);
2410 g_free(compose->ml_post);
2411 compose->ml_post = to;
2414 g_free(hentry[H_LIST_POST].body);
2415 hentry[H_LIST_POST].body = NULL;
2418 /* CLAWS - X-Priority */
2419 if (compose->mode == COMPOSE_REEDIT)
2420 if (hentry[H_X_PRIORITY].body != NULL) {
2423 priority = atoi(hentry[H_X_PRIORITY].body);
2424 g_free(hentry[H_X_PRIORITY].body);
2426 hentry[H_X_PRIORITY].body = NULL;
2428 if (priority < PRIORITY_HIGHEST ||
2429 priority > PRIORITY_LOWEST)
2430 priority = PRIORITY_NORMAL;
2432 compose->priority = priority;
2435 if (compose->mode == COMPOSE_REEDIT) {
2436 if (msginfo->inreplyto && *msginfo->inreplyto)
2437 compose->inreplyto = g_strdup(msginfo->inreplyto);
2441 if (msginfo->msgid && *msginfo->msgid)
2442 compose->inreplyto = g_strdup(msginfo->msgid);
2444 if (!compose->references) {
2445 if (msginfo->msgid && *msginfo->msgid) {
2446 if (msginfo->inreplyto && *msginfo->inreplyto)
2447 compose->references =
2448 g_strdup_printf("<%s>\n\t<%s>",
2452 compose->references =
2453 g_strconcat("<", msginfo->msgid, ">",
2455 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2456 compose->references =
2457 g_strconcat("<", msginfo->inreplyto, ">",
2465 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2467 GSList *ref_id_list, *cur;
2471 ref_id_list = references_list_append(NULL, ref);
2472 if (!ref_id_list) return NULL;
2473 if (msgid && *msgid)
2474 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2479 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2480 /* "<" + Message-ID + ">" + CR+LF+TAB */
2481 len += strlen((gchar *)cur->data) + 5;
2483 if (len > MAX_REFERENCES_LEN) {
2484 /* remove second message-ID */
2485 if (ref_id_list && ref_id_list->next &&
2486 ref_id_list->next->next) {
2487 g_free(ref_id_list->next->data);
2488 ref_id_list = g_slist_remove
2489 (ref_id_list, ref_id_list->next->data);
2491 slist_free_strings(ref_id_list);
2492 g_slist_free(ref_id_list);
2499 new_ref = g_string_new("");
2500 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2501 if (new_ref->len > 0)
2502 g_string_append(new_ref, "\n\t");
2503 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2506 slist_free_strings(ref_id_list);
2507 g_slist_free(ref_id_list);
2509 new_ref_str = new_ref->str;
2510 g_string_free(new_ref, FALSE);
2515 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2516 const gchar *fmt, const gchar *qmark,
2517 const gchar *body, gboolean rewrap,
2518 gboolean need_unescape,
2519 const gchar *err_msg)
2521 MsgInfo* dummyinfo = NULL;
2522 gchar *quote_str = NULL;
2524 gboolean prev_autowrap;
2525 const gchar *trimmed_body = body;
2526 gint cursor_pos = -1;
2527 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2528 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2533 SIGNAL_BLOCK(buffer);
2536 dummyinfo = compose_msginfo_new_from_compose(compose);
2537 msginfo = dummyinfo;
2540 if (qmark != NULL) {
2542 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
2543 compose->gtkaspell);
2545 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
2547 quote_fmt_scan_string(qmark);
2550 buf = quote_fmt_get_buffer();
2552 alertpanel_error(_("Quote mark format error."));
2554 Xstrdup_a(quote_str, buf, goto error)
2557 if (fmt && *fmt != '\0') {
2560 while (*trimmed_body == '\n')
2564 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account,
2565 compose->gtkaspell);
2567 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account);
2569 if (need_unescape) {
2572 /* decode \-escape sequences in the internal representation of the quote format */
2573 tmp = malloc(strlen(fmt)+1);
2574 pref_get_unescaped_pref(tmp, fmt);
2575 quote_fmt_scan_string(tmp);
2579 quote_fmt_scan_string(fmt);
2583 buf = quote_fmt_get_buffer();
2585 alertpanel_error(err_msg);
2591 prev_autowrap = compose->autowrap;
2592 compose->autowrap = FALSE;
2594 mark = gtk_text_buffer_get_insert(buffer);
2595 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2596 if (g_utf8_validate(buf, -1, NULL)) {
2597 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2599 gchar *tmpout = NULL;
2600 tmpout = conv_codeset_strdup
2601 (buf, conv_get_locale_charset_str_no_utf8(),
2603 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2605 tmpout = g_malloc(strlen(buf)*2+1);
2606 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2608 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2612 cursor_pos = quote_fmt_get_cursor_pos();
2613 compose->set_cursor_pos = cursor_pos;
2614 if (cursor_pos == -1) {
2617 gtk_text_buffer_get_start_iter(buffer, &iter);
2618 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2619 gtk_text_buffer_place_cursor(buffer, &iter);
2621 compose->autowrap = prev_autowrap;
2622 if (compose->autowrap && rewrap)
2623 compose_wrap_all(compose);
2630 SIGNAL_UNBLOCK(buffer);
2632 procmsg_msginfo_free( dummyinfo );
2637 /* if ml_post is of type addr@host and from is of type
2638 * addr-anything@host, return TRUE
2640 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2642 gchar *left_ml = NULL;
2643 gchar *right_ml = NULL;
2644 gchar *left_from = NULL;
2645 gchar *right_from = NULL;
2646 gboolean result = FALSE;
2648 if (!ml_post || !from)
2651 left_ml = g_strdup(ml_post);
2652 if (strstr(left_ml, "@")) {
2653 right_ml = strstr(left_ml, "@")+1;
2654 *(strstr(left_ml, "@")) = '\0';
2657 left_from = g_strdup(from);
2658 if (strstr(left_from, "@")) {
2659 right_from = strstr(left_from, "@")+1;
2660 *(strstr(left_from, "@")) = '\0';
2663 if (left_ml && left_from && right_ml && right_from
2664 && !strncmp(left_from, left_ml, strlen(left_ml))
2665 && !strcmp(right_from, right_ml)) {
2674 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2676 gchar *my_addr1, *my_addr2;
2678 if (!addr1 || !addr2)
2681 Xstrdup_a(my_addr1, addr1, return FALSE);
2682 Xstrdup_a(my_addr2, addr2, return FALSE);
2684 extract_address(my_addr1);
2685 extract_address(my_addr2);
2687 return !strcasecmp(my_addr1, my_addr2);
2690 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2691 gboolean to_all, gboolean to_ml,
2693 gboolean followup_and_reply_to)
2695 GSList *cc_list = NULL;
2698 gchar *replyto = NULL;
2699 GHashTable *to_table;
2701 gboolean reply_to_ml = FALSE;
2702 gboolean default_reply_to = FALSE;
2704 g_return_if_fail(compose->account != NULL);
2705 g_return_if_fail(msginfo != NULL);
2707 reply_to_ml = to_ml && compose->ml_post;
2709 default_reply_to = msginfo->folder &&
2710 msginfo->folder->prefs->enable_default_reply_to;
2712 if (compose->account->protocol != A_NNTP) {
2713 if (reply_to_ml && !default_reply_to) {
2715 gboolean is_subscr = is_subscription(compose->ml_post,
2718 /* normal answer to ml post with a reply-to */
2719 compose_entry_append(compose,
2722 if (compose->replyto
2723 && !same_address(compose->ml_post, compose->replyto))
2724 compose_entry_append(compose,
2728 /* answer to subscription confirmation */
2729 if (compose->replyto)
2730 compose_entry_append(compose,
2733 else if (msginfo->from)
2734 compose_entry_append(compose,
2739 else if (!(to_all || to_sender) && default_reply_to) {
2740 compose_entry_append(compose,
2741 msginfo->folder->prefs->default_reply_to,
2743 compose_entry_mark_default_to(compose,
2744 msginfo->folder->prefs->default_reply_to);
2749 Xstrdup_a(tmp1, msginfo->from, return);
2750 extract_address(tmp1);
2751 if (to_all || to_sender ||
2752 !account_find_from_address(tmp1))
2753 compose_entry_append(compose,
2754 (compose->replyto && !to_sender)
2755 ? compose->replyto :
2756 msginfo->from ? msginfo->from : "",
2758 else if (!to_all && !to_sender) {
2759 if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
2760 !folder_has_parent_of_type(msginfo->folder, F_OUTBOX) &&
2761 !folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
2762 compose_entry_append(compose,
2763 msginfo->from ? msginfo->from : "",
2766 /* replying to own mail, use original recp */
2767 compose_entry_append(compose,
2768 msginfo->to ? msginfo->to : "",
2770 compose_entry_append(compose,
2771 msginfo->cc ? msginfo->cc : "",
2777 if (to_sender || (compose->followup_to &&
2778 !strncmp(compose->followup_to, "poster", 6)))
2779 compose_entry_append
2781 (compose->replyto ? compose->replyto :
2782 msginfo->from ? msginfo->from : ""),
2785 else if (followup_and_reply_to || to_all) {
2786 compose_entry_append
2788 (compose->replyto ? compose->replyto :
2789 msginfo->from ? msginfo->from : ""),
2792 compose_entry_append
2794 compose->followup_to ? compose->followup_to :
2795 compose->newsgroups ? compose->newsgroups : "",
2796 COMPOSE_NEWSGROUPS);
2799 compose_entry_append
2801 compose->followup_to ? compose->followup_to :
2802 compose->newsgroups ? compose->newsgroups : "",
2803 COMPOSE_NEWSGROUPS);
2806 if (msginfo->subject && *msginfo->subject) {
2810 buf = p = g_strdup(msginfo->subject);
2811 p += subject_get_prefix_length(p);
2812 memmove(buf, p, strlen(p) + 1);
2814 buf2 = g_strdup_printf("Re: %s", buf);
2815 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2820 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2822 if (to_ml && compose->ml_post) return;
2823 if (!to_all || compose->account->protocol == A_NNTP) return;
2825 if (compose->replyto) {
2826 Xstrdup_a(replyto, compose->replyto, return);
2827 extract_address(replyto);
2829 if (msginfo->from) {
2830 Xstrdup_a(from, msginfo->from, return);
2831 extract_address(from);
2834 if (replyto && from)
2835 cc_list = address_list_append_with_comments(cc_list, from);
2836 if (to_all && msginfo->folder &&
2837 msginfo->folder->prefs->enable_default_reply_to)
2838 cc_list = address_list_append_with_comments(cc_list,
2839 msginfo->folder->prefs->default_reply_to);
2840 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2841 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2843 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2845 g_hash_table_insert(to_table, g_utf8_strdown(replyto, -1), GINT_TO_POINTER(1));
2846 if (compose->account) {
2847 g_hash_table_insert(to_table, g_utf8_strdown(compose->account->address, -1),
2848 GINT_TO_POINTER(1));
2850 /* remove address on To: and that of current account */
2851 for (cur = cc_list; cur != NULL; ) {
2852 GSList *next = cur->next;
2855 addr = g_utf8_strdown(cur->data, -1);
2856 extract_address(addr);
2858 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2859 cc_list = g_slist_remove(cc_list, cur->data);
2861 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2865 hash_free_strings(to_table);
2866 g_hash_table_destroy(to_table);
2869 for (cur = cc_list; cur != NULL; cur = cur->next)
2870 compose_entry_append(compose, (gchar *)cur->data,
2872 slist_free_strings(cc_list);
2873 g_slist_free(cc_list);
2878 #define SET_ENTRY(entry, str) \
2881 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2884 #define SET_ADDRESS(type, str) \
2887 compose_entry_append(compose, str, type); \
2890 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2892 g_return_if_fail(msginfo != NULL);
2894 SET_ENTRY(subject_entry, msginfo->subject);
2895 SET_ENTRY(from_name, msginfo->from);
2896 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2897 SET_ADDRESS(COMPOSE_CC, compose->cc);
2898 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2899 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2900 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2901 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2903 compose_update_priority_menu_item(compose);
2904 compose_update_privacy_system_menu_item(compose, FALSE);
2905 compose_show_first_last_header(compose, TRUE);
2911 static void compose_insert_sig(Compose *compose, gboolean replace)
2913 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2914 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2916 GtkTextIter iter, iter_end;
2918 gchar *search = NULL;
2919 gboolean prev_autowrap;
2920 gboolean found = FALSE, shift = FALSE;
2923 g_return_if_fail(compose->account != NULL);
2925 prev_autowrap = compose->autowrap;
2926 compose->autowrap = FALSE;
2928 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2929 G_CALLBACK(compose_changed_cb),
2932 mark = gtk_text_buffer_get_insert(buffer);
2933 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2934 cur_pos = gtk_text_iter_get_offset (&iter);
2936 gtk_text_buffer_get_end_iter(buffer, &iter);
2938 search = compose->sig_str;
2940 if (replace && search) {
2941 GtkTextIter first_iter, start_iter, end_iter;
2943 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2945 if (compose->sig_str[0] == '\0')
2948 found = gtk_text_iter_forward_search(&first_iter,
2950 GTK_TEXT_SEARCH_TEXT_ONLY,
2951 &start_iter, &end_iter,
2955 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2959 if (replace && !found && search && strlen(search) > 2
2960 && search[0] == '\n' && search[1] == '\n') {
2966 g_free(compose->sig_str);
2967 compose->sig_str = compose_get_signature_str(compose);
2968 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2969 compose->sig_str = g_strdup("");
2971 cur_pos = gtk_text_iter_get_offset(&iter);
2973 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2975 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2977 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2978 gtk_text_iter_forward_char(&iter);
2979 gtk_text_iter_forward_char(&iter);
2980 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2981 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2983 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2984 cur_pos = gtk_text_buffer_get_char_count (buffer);
2986 /* put the cursor where it should be
2987 * either where the quote_fmt says, either before the signature */
2988 if (compose->set_cursor_pos < 0)
2989 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2991 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2992 compose->set_cursor_pos);
2994 gtk_text_buffer_place_cursor(buffer, &iter);
2995 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2996 G_CALLBACK(compose_changed_cb),
2999 compose->autowrap = prev_autowrap;
3000 if (compose->autowrap)
3001 compose_wrap_all(compose);
3004 static gchar *compose_get_signature_str(Compose *compose)
3006 gchar *sig_body = NULL;
3007 gchar *sig_str = NULL;
3008 gchar *utf8_sig_str = NULL;
3010 g_return_val_if_fail(compose->account != NULL, NULL);
3012 if (!compose->account->sig_path)
3015 if (compose->account->sig_type == SIG_FILE) {
3016 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
3017 g_warning("can't open signature file: %s\n",
3018 compose->account->sig_path);
3023 if (compose->account->sig_type == SIG_COMMAND)
3024 sig_body = get_command_output(compose->account->sig_path);
3028 tmp = file_read_to_str(compose->account->sig_path);
3031 sig_body = normalize_newlines(tmp);
3035 if (compose->account->sig_sep) {
3036 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
3040 sig_str = g_strconcat("\n\n", sig_body, NULL);
3043 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
3044 utf8_sig_str = sig_str;
3046 utf8_sig_str = conv_codeset_strdup
3047 (sig_str, conv_get_locale_charset_str_no_utf8(),
3053 return utf8_sig_str;
3056 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
3059 GtkTextBuffer *buffer;
3062 const gchar *cur_encoding;
3063 gchar buf[BUFFSIZE];
3066 gboolean prev_autowrap;
3067 gboolean badtxt = FALSE;
3069 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
3071 if ((fp = g_fopen(file, "rb")) == NULL) {
3072 FILE_OP_ERROR(file, "fopen");
3073 return COMPOSE_INSERT_READ_ERROR;
3076 prev_autowrap = compose->autowrap;
3077 compose->autowrap = FALSE;
3079 text = GTK_TEXT_VIEW(compose->text);
3080 buffer = gtk_text_view_get_buffer(text);
3081 mark = gtk_text_buffer_get_insert(buffer);
3082 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3084 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3085 G_CALLBACK(text_inserted),
3088 cur_encoding = conv_get_locale_charset_str_no_utf8();
3090 while (fgets(buf, sizeof(buf), fp) != NULL) {
3093 if (g_utf8_validate(buf, -1, NULL) == TRUE)
3094 str = g_strdup(buf);
3096 str = conv_codeset_strdup
3097 (buf, cur_encoding, CS_INTERNAL);
3100 /* strip <CR> if DOS/Windows file,
3101 replace <CR> with <LF> if Macintosh file. */
3104 if (len > 0 && str[len - 1] != '\n') {
3106 if (str[len] == '\r') str[len] = '\n';
3109 gtk_text_buffer_insert(buffer, &iter, str, -1);
3113 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3114 G_CALLBACK(text_inserted),
3116 compose->autowrap = prev_autowrap;
3117 if (compose->autowrap)
3118 compose_wrap_all(compose);
3123 return COMPOSE_INSERT_INVALID_CHARACTER;
3125 return COMPOSE_INSERT_SUCCESS;
3128 static gboolean compose_attach_append(Compose *compose, const gchar *file,
3129 const gchar *filename,
3130 const gchar *content_type)
3138 GtkListStore *store;
3140 gboolean has_binary = FALSE;
3142 if (!is_file_exist(file)) {
3143 gchar *file_from_uri = g_filename_from_uri(file, NULL, NULL);
3144 gboolean result = FALSE;
3145 if (file_from_uri && is_file_exist(file_from_uri)) {
3146 result = compose_attach_append(
3147 compose, file_from_uri,
3151 g_free(file_from_uri);
3154 alertpanel_error("File %s doesn't exist\n", filename);
3157 if ((size = get_file_size(file)) < 0) {
3158 alertpanel_error("Can't get file size of %s\n", filename);
3162 alertpanel_error(_("File %s is empty."), filename);
3165 if ((fp = g_fopen(file, "rb")) == NULL) {
3166 alertpanel_error(_("Can't read %s."), filename);
3171 ainfo = g_new0(AttachInfo, 1);
3172 auto_ainfo = g_auto_pointer_new_with_free
3173 (ainfo, (GFreeFunc) compose_attach_info_free);
3174 ainfo->file = g_strdup(file);
3177 ainfo->content_type = g_strdup(content_type);
3178 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
3180 MsgFlags flags = {0, 0};
3182 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
3183 ainfo->encoding = ENC_7BIT;
3185 ainfo->encoding = ENC_8BIT;
3187 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
3188 if (msginfo && msginfo->subject)
3189 name = g_strdup(msginfo->subject);
3191 name = g_path_get_basename(filename ? filename : file);
3193 ainfo->name = g_strdup_printf(_("Message: %s"), name);
3195 procmsg_msginfo_free(msginfo);
3197 if (!g_ascii_strncasecmp(content_type, "text", 4))
3198 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
3200 ainfo->encoding = ENC_BASE64;
3201 name = g_path_get_basename(filename ? filename : file);
3202 ainfo->name = g_strdup(name);
3206 ainfo->content_type = procmime_get_mime_type(file);
3207 if (!ainfo->content_type) {
3208 ainfo->content_type =
3209 g_strdup("application/octet-stream");
3210 ainfo->encoding = ENC_BASE64;
3211 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
3213 procmime_get_encoding_for_text_file(file, &has_binary);
3215 ainfo->encoding = ENC_BASE64;
3216 name = g_path_get_basename(filename ? filename : file);
3217 ainfo->name = g_strdup(name);
3221 if (ainfo->name != NULL
3222 && !strcmp(ainfo->name, ".")) {
3223 g_free(ainfo->name);
3227 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
3228 g_free(ainfo->content_type);
3229 ainfo->content_type = g_strdup("application/octet-stream");
3233 size_text = to_human_readable(size);
3235 store = GTK_LIST_STORE(gtk_tree_view_get_model
3236 (GTK_TREE_VIEW(compose->attach_clist)));
3238 gtk_list_store_append(store, &iter);
3239 gtk_list_store_set(store, &iter,
3240 COL_MIMETYPE, ainfo->content_type,
3241 COL_SIZE, size_text,
3242 COL_NAME, ainfo->name,
3244 COL_AUTODATA, auto_ainfo,
3247 g_auto_pointer_free(auto_ainfo);
3251 static void compose_use_signing(Compose *compose, gboolean use_signing)
3253 GtkItemFactory *ifactory;
3254 GtkWidget *menuitem = NULL;
3256 compose->use_signing = use_signing;
3257 ifactory = gtk_item_factory_from_widget(compose->menubar);
3258 menuitem = gtk_item_factory_get_item
3259 (ifactory, "/Options/Sign");
3260 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3264 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3266 GtkItemFactory *ifactory;
3267 GtkWidget *menuitem = NULL;
3269 compose->use_encryption = use_encryption;
3270 ifactory = gtk_item_factory_from_widget(compose->menubar);
3271 menuitem = gtk_item_factory_get_item
3272 (ifactory, "/Options/Encrypt");
3274 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3278 #define NEXT_PART_NOT_CHILD(info) \
3280 node = info->node; \
3281 while (node->children) \
3282 node = g_node_last_child(node); \
3283 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3286 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3290 MimeInfo *firsttext = NULL;
3291 MimeInfo *encrypted = NULL;
3294 const gchar *partname = NULL;
3296 mimeinfo = procmime_scan_message(msginfo);
3297 if (!mimeinfo) return;
3299 if (mimeinfo->node->children == NULL) {
3300 procmime_mimeinfo_free_all(mimeinfo);
3304 /* find first content part */
3305 child = (MimeInfo *) mimeinfo->node->children->data;
3306 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3307 child = (MimeInfo *)child->node->children->data;
3309 if (child->type == MIMETYPE_TEXT) {
3311 debug_print("First text part found\n");
3312 } else if (compose->mode == COMPOSE_REEDIT &&
3313 child->type == MIMETYPE_APPLICATION &&
3314 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3315 encrypted = (MimeInfo *)child->node->parent->data;
3318 child = (MimeInfo *) mimeinfo->node->children->data;
3319 while (child != NULL) {
3322 if (child == encrypted) {
3323 /* skip this part of tree */
3324 NEXT_PART_NOT_CHILD(child);
3328 if (child->type == MIMETYPE_MULTIPART) {
3329 /* get the actual content */
3330 child = procmime_mimeinfo_next(child);
3334 if (child == firsttext) {
3335 child = procmime_mimeinfo_next(child);
3339 outfile = procmime_get_tmp_file_name(child);
3340 if ((err = procmime_get_part(outfile, child)) < 0)
3341 g_warning("Can't get the part of multipart message. (%s)", strerror(-err));
3343 gchar *content_type;
3345 content_type = procmime_get_content_type_str(child->type, child->subtype);
3347 /* if we meet a pgp signature, we don't attach it, but
3348 * we force signing. */
3349 if (strcmp(content_type, "application/pgp-signature") &&
3350 strcmp(content_type, "application/pkcs7-signature") &&
3351 strcmp(content_type, "application/x-pkcs7-signature")) {
3352 partname = procmime_mimeinfo_get_parameter(child, "filename");
3353 if (partname == NULL)
3354 partname = procmime_mimeinfo_get_parameter(child, "name");
3355 if (partname == NULL)
3357 compose_attach_append(compose, outfile,
3358 partname, content_type);
3360 compose_force_signing(compose, compose->account);
3362 g_free(content_type);
3365 NEXT_PART_NOT_CHILD(child);
3367 procmime_mimeinfo_free_all(mimeinfo);
3370 #undef NEXT_PART_NOT_CHILD
3375 WAIT_FOR_INDENT_CHAR,
3376 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3379 /* return indent length, we allow:
3380 indent characters followed by indent characters or spaces/tabs,
3381 alphabets and numbers immediately followed by indent characters,
3382 and the repeating sequences of the above
3383 If quote ends with multiple spaces, only the first one is included. */
3384 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3385 const GtkTextIter *start, gint *len)
3387 GtkTextIter iter = *start;
3391 IndentState state = WAIT_FOR_INDENT_CHAR;
3394 gint alnum_count = 0;
3395 gint space_count = 0;
3398 if (prefs_common.quote_chars == NULL) {
3402 while (!gtk_text_iter_ends_line(&iter)) {
3403 wc = gtk_text_iter_get_char(&iter);
3404 if (g_unichar_iswide(wc))
3406 clen = g_unichar_to_utf8(wc, ch);
3410 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3411 is_space = g_unichar_isspace(wc);
3413 if (state == WAIT_FOR_INDENT_CHAR) {
3414 if (!is_indent && !g_unichar_isalnum(wc))
3417 quote_len += alnum_count + space_count + 1;
3418 alnum_count = space_count = 0;
3419 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3422 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3423 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3427 else if (is_indent) {
3428 quote_len += alnum_count + space_count + 1;
3429 alnum_count = space_count = 0;
3432 state = WAIT_FOR_INDENT_CHAR;
3436 gtk_text_iter_forward_char(&iter);
3439 if (quote_len > 0 && space_count > 0)
3445 if (quote_len > 0) {
3447 gtk_text_iter_forward_chars(&iter, quote_len);
3448 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3454 /* return TRUE if the line is itemized */
3455 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3456 const GtkTextIter *start)
3458 GtkTextIter iter = *start;
3463 if (gtk_text_iter_ends_line(&iter))
3467 wc = gtk_text_iter_get_char(&iter);
3468 if (!g_unichar_isspace(wc))
3470 gtk_text_iter_forward_char(&iter);
3471 if (gtk_text_iter_ends_line(&iter))
3475 clen = g_unichar_to_utf8(wc, ch);
3479 if (!strchr("*-+", ch[0]))
3482 gtk_text_iter_forward_char(&iter);
3483 if (gtk_text_iter_ends_line(&iter))
3485 wc = gtk_text_iter_get_char(&iter);
3486 if (g_unichar_isspace(wc))
3492 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3493 const GtkTextIter *start,
3494 GtkTextIter *break_pos,
3498 GtkTextIter iter = *start, line_end = *start;
3499 PangoLogAttr *attrs;
3506 gboolean can_break = FALSE;
3507 gboolean do_break = FALSE;
3508 gboolean was_white = FALSE;
3509 gboolean prev_dont_break = FALSE;
3511 gtk_text_iter_forward_to_line_end(&line_end);
3512 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3513 len = g_utf8_strlen(str, -1);
3514 /* g_print("breaking line: %d: %s (len = %d)\n",
3515 gtk_text_iter_get_line(&iter), str, len); */
3516 attrs = g_new(PangoLogAttr, len + 1);
3518 pango_default_break(str, -1, NULL, attrs, len + 1);
3522 /* skip quote and leading spaces */
3523 for (i = 0; *p != '\0' && i < len; i++) {
3526 wc = g_utf8_get_char(p);
3527 if (i >= quote_len && !g_unichar_isspace(wc))
3529 if (g_unichar_iswide(wc))
3531 else if (*p == '\t')
3535 p = g_utf8_next_char(p);
3538 for (; *p != '\0' && i < len; i++) {
3539 PangoLogAttr *attr = attrs + i;
3543 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3546 was_white = attr->is_white;
3548 /* don't wrap URI */
3549 if ((uri_len = get_uri_len(p)) > 0) {
3551 if (pos > 0 && col > max_col) {
3561 wc = g_utf8_get_char(p);
3562 if (g_unichar_iswide(wc)) {
3564 if (prev_dont_break && can_break && attr->is_line_break)
3566 } else if (*p == '\t')
3570 if (pos > 0 && col > max_col) {
3575 if (*p == '-' || *p == '/')
3576 prev_dont_break = TRUE;
3578 prev_dont_break = FALSE;
3580 p = g_utf8_next_char(p);
3584 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3589 *break_pos = *start;
3590 gtk_text_iter_set_line_offset(break_pos, pos);
3595 static gboolean compose_join_next_line(Compose *compose,
3596 GtkTextBuffer *buffer,
3598 const gchar *quote_str)
3600 GtkTextIter iter_ = *iter, cur, prev, next, end;
3601 PangoLogAttr attrs[3];
3603 gchar *next_quote_str;
3606 gboolean keep_cursor = FALSE;
3608 if (!gtk_text_iter_forward_line(&iter_) ||
3609 gtk_text_iter_ends_line(&iter_))
3612 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3614 if ((quote_str || next_quote_str) &&
3615 strcmp2(quote_str, next_quote_str) != 0) {
3616 g_free(next_quote_str);
3619 g_free(next_quote_str);
3622 if (quote_len > 0) {
3623 gtk_text_iter_forward_chars(&end, quote_len);
3624 if (gtk_text_iter_ends_line(&end))
3628 /* don't join itemized lines */
3629 if (compose_is_itemized(buffer, &end))
3632 /* don't join signature separator */
3633 if (compose_is_sig_separator(compose, buffer, &iter_))
3636 /* delete quote str */
3638 gtk_text_buffer_delete(buffer, &iter_, &end);
3640 /* don't join line breaks put by the user */
3642 gtk_text_iter_backward_char(&cur);
3643 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3644 gtk_text_iter_forward_char(&cur);
3648 gtk_text_iter_forward_char(&cur);
3649 /* delete linebreak and extra spaces */
3650 while (gtk_text_iter_backward_char(&cur)) {
3651 wc1 = gtk_text_iter_get_char(&cur);
3652 if (!g_unichar_isspace(wc1))
3657 while (!gtk_text_iter_ends_line(&cur)) {
3658 wc1 = gtk_text_iter_get_char(&cur);
3659 if (!g_unichar_isspace(wc1))
3661 gtk_text_iter_forward_char(&cur);
3664 if (!gtk_text_iter_equal(&prev, &next)) {
3667 mark = gtk_text_buffer_get_insert(buffer);
3668 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3669 if (gtk_text_iter_equal(&prev, &cur))
3671 gtk_text_buffer_delete(buffer, &prev, &next);
3675 /* insert space if required */
3676 gtk_text_iter_backward_char(&prev);
3677 wc1 = gtk_text_iter_get_char(&prev);
3678 wc2 = gtk_text_iter_get_char(&next);
3679 gtk_text_iter_forward_char(&next);
3680 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3681 pango_default_break(str, -1, NULL, attrs, 3);
3682 if (!attrs[1].is_line_break ||
3683 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3684 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3686 gtk_text_iter_backward_char(&iter_);
3687 gtk_text_buffer_place_cursor(buffer, &iter_);
3696 #define ADD_TXT_POS(bp_, ep_, pti_) \
3697 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3698 last = last->next; \
3699 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3700 last->next = NULL; \
3702 g_warning("alloc error scanning URIs\n"); \
3705 static gboolean automatic_break = FALSE;
3706 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3708 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3709 GtkTextBuffer *buffer;
3710 GtkTextIter iter, break_pos, end_of_line;
3711 gchar *quote_str = NULL;
3713 gboolean wrap_quote = prefs_common.linewrap_quote;
3714 gboolean prev_autowrap = compose->autowrap;
3715 gint startq_offset = -1, noq_offset = -1;
3716 gint uri_start = -1, uri_stop = -1;
3717 gint nouri_start = -1, nouri_stop = -1;
3718 gint num_blocks = 0;
3719 gint quotelevel = -1;
3721 compose->autowrap = FALSE;
3723 buffer = gtk_text_view_get_buffer(text);
3724 undo_wrapping(compose->undostruct, TRUE);
3729 mark = gtk_text_buffer_get_insert(buffer);
3730 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3733 /* move to paragraph start */
3734 gtk_text_iter_set_line_offset(&iter, 0);
3735 if (gtk_text_iter_ends_line(&iter)) {
3736 while (gtk_text_iter_ends_line(&iter) &&
3737 gtk_text_iter_forward_line(&iter))
3740 while (gtk_text_iter_backward_line(&iter)) {
3741 if (gtk_text_iter_ends_line(&iter)) {
3742 gtk_text_iter_forward_line(&iter);
3748 /* go until paragraph end (empty line) */
3750 while (!gtk_text_iter_ends_line(&iter)) {
3751 gchar *scanpos = NULL;
3752 /* parse table - in order of priority */
3754 const gchar *needle; /* token */
3756 /* token search function */
3757 gchar *(*search) (const gchar *haystack,
3758 const gchar *needle);
3759 /* part parsing function */
3760 gboolean (*parse) (const gchar *start,
3761 const gchar *scanpos,
3765 /* part to URI function */
3766 gchar *(*build_uri) (const gchar *bp,
3770 static struct table parser[] = {
3771 {"http://", strcasestr, get_uri_part, make_uri_string},
3772 {"https://", strcasestr, get_uri_part, make_uri_string},
3773 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3774 {"sftp://", strcasestr, get_uri_part, make_uri_string},
3775 {"www.", strcasestr, get_uri_part, make_http_string},
3776 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3777 {"@", strcasestr, get_email_part, make_email_string}
3779 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3780 gint last_index = PARSE_ELEMS;
3782 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3785 if (!prev_autowrap && num_blocks == 0) {
3787 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3788 G_CALLBACK(text_inserted),
3791 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3794 uri_start = uri_stop = -1;
3796 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3799 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3800 if (startq_offset == -1)
3801 startq_offset = gtk_text_iter_get_offset(&iter);
3802 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3803 if (quotelevel > 2) {
3804 /* recycle colors */
3805 if (prefs_common.recycle_quote_colors)
3814 if (startq_offset == -1)
3815 noq_offset = gtk_text_iter_get_offset(&iter);
3819 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3822 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3823 prefs_common.linewrap_len,
3825 GtkTextIter prev, next, cur;
3827 if (prev_autowrap != FALSE || force) {
3828 automatic_break = TRUE;
3829 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3830 automatic_break = FALSE;
3831 } else if (quote_str && wrap_quote) {
3832 automatic_break = TRUE;
3833 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3834 automatic_break = FALSE;
3837 /* remove trailing spaces */
3839 gtk_text_iter_backward_char(&cur);
3841 while (!gtk_text_iter_starts_line(&cur)) {
3844 gtk_text_iter_backward_char(&cur);
3845 wc = gtk_text_iter_get_char(&cur);
3846 if (!g_unichar_isspace(wc))
3850 if (!gtk_text_iter_equal(&prev, &next)) {
3851 gtk_text_buffer_delete(buffer, &prev, &next);
3853 gtk_text_iter_forward_char(&break_pos);
3857 gtk_text_buffer_insert(buffer, &break_pos,
3861 compose_join_next_line(compose, buffer, &iter, quote_str);
3863 /* move iter to current line start */
3864 gtk_text_iter_set_line_offset(&iter, 0);
3871 /* move iter to next line start */
3876 if (!prev_autowrap && num_blocks > 0) {
3878 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3879 G_CALLBACK(text_inserted),
3883 while (!gtk_text_iter_ends_line(&end_of_line)) {
3884 gtk_text_iter_forward_char(&end_of_line);
3886 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3888 nouri_start = gtk_text_iter_get_offset(&iter);
3889 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3891 walk_pos = gtk_text_iter_get_offset(&iter);
3892 /* FIXME: this looks phony. scanning for anything in the parse table */
3893 for (n = 0; n < PARSE_ELEMS; n++) {
3896 tmp = parser[n].search(walk, parser[n].needle);
3898 if (scanpos == NULL || tmp < scanpos) {
3907 /* check if URI can be parsed */
3908 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3909 (const gchar **)&ep, FALSE)
3910 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3914 strlen(parser[last_index].needle);
3917 uri_start = walk_pos + (bp - o_walk);
3918 uri_stop = walk_pos + (ep - o_walk);
3922 gtk_text_iter_forward_line(&iter);
3925 if (startq_offset != -1) {
3926 GtkTextIter startquote, endquote;
3927 gtk_text_buffer_get_iter_at_offset(
3928 buffer, &startquote, startq_offset);
3931 switch (quotelevel) {
3932 case 0: gtk_text_buffer_apply_tag_by_name(
3933 buffer, "quote0", &startquote, &endquote);
3935 case 1: gtk_text_buffer_apply_tag_by_name(
3936 buffer, "quote1", &startquote, &endquote);
3938 case 2: gtk_text_buffer_apply_tag_by_name(
3939 buffer, "quote2", &startquote, &endquote);
3943 } else if (noq_offset != -1) {
3944 GtkTextIter startnoquote, endnoquote;
3945 gtk_text_buffer_get_iter_at_offset(
3946 buffer, &startnoquote, noq_offset);
3948 gtk_text_buffer_remove_tag_by_name(
3949 buffer, "quote0", &startnoquote, &endnoquote);
3950 gtk_text_buffer_remove_tag_by_name(
3951 buffer, "quote1", &startnoquote, &endnoquote);
3952 gtk_text_buffer_remove_tag_by_name(
3953 buffer, "quote2", &startnoquote, &endnoquote);
3958 GtkTextIter nouri_start_iter, nouri_end_iter;
3959 gtk_text_buffer_get_iter_at_offset(
3960 buffer, &nouri_start_iter, nouri_start);
3961 gtk_text_buffer_get_iter_at_offset(
3962 buffer, &nouri_end_iter, nouri_stop);
3963 gtk_text_buffer_remove_tag_by_name(
3964 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3966 if (uri_start > 0 && uri_stop > 0) {
3967 GtkTextIter uri_start_iter, uri_end_iter;
3968 gtk_text_buffer_get_iter_at_offset(
3969 buffer, &uri_start_iter, uri_start);
3970 gtk_text_buffer_get_iter_at_offset(
3971 buffer, &uri_end_iter, uri_stop);
3972 gtk_text_buffer_apply_tag_by_name(
3973 buffer, "link", &uri_start_iter, &uri_end_iter);
3979 undo_wrapping(compose->undostruct, FALSE);
3980 compose->autowrap = prev_autowrap;
3983 void compose_action_cb(void *data)
3985 Compose *compose = (Compose *)data;
3986 compose_wrap_all(compose);
3989 static void compose_wrap_all(Compose *compose)
3991 compose_wrap_all_full(compose, FALSE);
3994 static void compose_wrap_all_full(Compose *compose, gboolean force)
3996 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3997 GtkTextBuffer *buffer;
4000 buffer = gtk_text_view_get_buffer(text);
4002 gtk_text_buffer_get_start_iter(buffer, &iter);
4003 while (!gtk_text_iter_is_end(&iter))
4004 compose_beautify_paragraph(compose, &iter, force);
4008 static void compose_set_title(Compose *compose)
4014 edited = compose->modified ? _(" [Edited]") : "";
4016 subject = gtk_editable_get_chars(
4017 GTK_EDITABLE(compose->subject_entry), 0, -1);
4020 if (subject && strlen(subject))
4021 str = g_strdup_printf(_("%s - Compose message%s"),
4024 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
4026 str = g_strdup(_("Compose message"));
4029 gtk_window_set_title(GTK_WINDOW(compose->window), str);
4035 * compose_current_mail_account:
4037 * Find a current mail account (the currently selected account, or the
4038 * default account, if a news account is currently selected). If a
4039 * mail account cannot be found, display an error message.
4041 * Return value: Mail account, or NULL if not found.
4043 static PrefsAccount *
4044 compose_current_mail_account(void)
4048 if (cur_account && cur_account->protocol != A_NNTP)
4051 ac = account_get_default();
4052 if (!ac || ac->protocol == A_NNTP) {
4053 alertpanel_error(_("Account for sending mail is not specified.\n"
4054 "Please select a mail account before sending."));
4061 #define QUOTE_IF_REQUIRED(out, str) \
4063 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4067 len = strlen(str) + 3; \
4068 if ((__tmp = alloca(len)) == NULL) { \
4069 g_warning("can't allocate memory\n"); \
4070 g_string_free(header, TRUE); \
4073 g_snprintf(__tmp, len, "\"%s\"", str); \
4078 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4079 g_warning("can't allocate memory\n"); \
4080 g_string_free(header, TRUE); \
4083 strcpy(__tmp, str); \
4089 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
4091 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4095 len = strlen(str) + 3; \
4096 if ((__tmp = alloca(len)) == NULL) { \
4097 g_warning("can't allocate memory\n"); \
4100 g_snprintf(__tmp, len, "\"%s\"", str); \
4105 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4106 g_warning("can't allocate memory\n"); \
4109 strcpy(__tmp, str); \
4115 static void compose_select_account(Compose *compose, PrefsAccount *account,
4118 GtkItemFactory *ifactory;
4121 g_return_if_fail(account != NULL);
4123 compose->account = account;
4125 if (account->name && *account->name) {
4127 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
4128 from = g_strdup_printf("%s <%s>",
4129 buf, account->address);
4130 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
4132 from = g_strdup_printf("<%s>",
4134 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
4139 compose_set_title(compose);
4141 ifactory = gtk_item_factory_from_widget(compose->menubar);
4143 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
4144 menu_set_active(ifactory, "/Options/Sign", TRUE);
4146 menu_set_active(ifactory, "/Options/Sign", FALSE);
4147 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
4148 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
4150 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
4152 activate_privacy_system(compose, account, FALSE);
4154 if (!init && compose->mode != COMPOSE_REDIRECT) {
4155 undo_block(compose->undostruct);
4156 compose_insert_sig(compose, TRUE);
4157 undo_unblock(compose->undostruct);
4161 /* use account's dict info if set */
4162 if (compose->gtkaspell) {
4163 if (account->enable_default_dictionary)
4164 gtkaspell_change_dict(compose->gtkaspell,
4165 account->default_dictionary, FALSE);
4166 if (account->enable_default_alt_dictionary)
4167 gtkaspell_change_alt_dict(compose->gtkaspell,
4168 account->default_alt_dictionary);
4169 if (account->enable_default_dictionary
4170 || account->enable_default_alt_dictionary)
4171 compose_spell_menu_changed(compose);
4176 gboolean compose_check_for_valid_recipient(Compose *compose) {
4177 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
4178 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
4179 gboolean recipient_found = FALSE;
4183 /* free to and newsgroup list */
4184 slist_free_strings(compose->to_list);
4185 g_slist_free(compose->to_list);
4186 compose->to_list = NULL;
4188 slist_free_strings(compose->newsgroup_list);
4189 g_slist_free(compose->newsgroup_list);
4190 compose->newsgroup_list = NULL;
4192 /* search header entries for to and newsgroup entries */
4193 for (list = compose->header_list; list; list = list->next) {
4196 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4197 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4200 if (entry[0] != '\0') {
4201 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
4202 if (!strcmp(header, prefs_common_translated_header_name(*strptr))) {
4203 compose->to_list = address_list_append(compose->to_list, entry);
4204 recipient_found = TRUE;
4207 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
4208 if (!strcmp(header, prefs_common_translated_header_name(*strptr))) {
4209 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
4210 recipient_found = TRUE;
4217 return recipient_found;
4220 static gboolean compose_check_for_set_recipients(Compose *compose)
4222 if (compose->account->set_autocc && compose->account->auto_cc) {
4223 gboolean found_other = FALSE;
4225 /* search header entries for to and newsgroup entries */
4226 for (list = compose->header_list; list; list = list->next) {
4229 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4230 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4232 if (strcmp(entry, compose->account->auto_cc)
4233 || strcmp(header, prefs_common_translated_header_name("Cc:"))) {
4243 if (compose->batch) {
4244 gtk_widget_show_all(compose->window);
4246 aval = alertpanel(_("Send"),
4247 _("The only recipient is the default CC address. Send anyway?"),
4248 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4249 if (aval != G_ALERTALTERNATE)
4253 if (compose->account->set_autobcc && compose->account->auto_bcc) {
4254 gboolean found_other = FALSE;
4256 /* search header entries for to and newsgroup entries */
4257 for (list = compose->header_list; list; list = list->next) {
4260 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4261 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4263 if (strcmp(entry, compose->account->auto_bcc)
4264 || strcmp(header, prefs_common_translated_header_name("Bcc:"))) {
4274 if (compose->batch) {
4275 gtk_widget_show_all(compose->window);
4277 aval = alertpanel(_("Send"),
4278 _("The only recipient is the default BCC address. Send anyway?"),
4279 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4280 if (aval != G_ALERTALTERNATE)
4287 static gboolean compose_check_entries(Compose *compose, gboolean check_everything)
4291 if (compose_check_for_valid_recipient(compose) == FALSE) {
4292 if (compose->batch) {
4293 gtk_widget_show_all(compose->window);
4295 alertpanel_error(_("Recipient is not specified."));
4299 if (compose_check_for_set_recipients(compose) == FALSE) {
4303 if (!compose->batch) {
4304 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4305 if (*str == '\0' && check_everything == TRUE &&
4306 compose->mode != COMPOSE_REDIRECT) {
4309 aval = alertpanel(_("Send"),
4310 _("Subject is empty. Send it anyway?"),
4311 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4312 if (aval != G_ALERTALTERNATE)
4317 if (check_everything && hooks_invoke(COMPOSE_CHECK_BEFORE_SEND_HOOKLIST, compose))
4323 gint compose_send(Compose *compose)
4326 FolderItem *folder = NULL;
4328 gchar *msgpath = NULL;
4329 gboolean discard_window = FALSE;
4330 gchar *errstr = NULL;
4331 gchar *tmsgid = NULL;
4332 MainWindow *mainwin = mainwindow_get_mainwindow();
4333 gboolean queued_removed = FALSE;
4335 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4336 || compose->batch == TRUE)
4337 discard_window = TRUE;
4339 compose_allow_user_actions (compose, FALSE);
4340 compose->sending = TRUE;
4342 if (compose_check_entries(compose, TRUE) == FALSE) {
4343 if (compose->batch) {
4344 gtk_widget_show_all(compose->window);
4350 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
4353 if (compose->batch) {
4354 gtk_widget_show_all(compose->window);
4357 alertpanel_error(_("Could not queue message for sending:\n\n"
4358 "Charset conversion failed."));
4359 } else if (val == -5) {
4360 alertpanel_error(_("Could not queue message for sending:\n\n"
4361 "Couldn't get recipient encryption key."));
4362 } else if (val == -6) {
4364 } else if (val == -3) {
4365 if (privacy_peek_error())
4366 alertpanel_error(_("Could not queue message for sending:\n\n"
4367 "Signature failed: %s"), privacy_get_error());
4368 } else if (val == -2 && errno != 0) {
4369 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4371 alertpanel_error(_("Could not queue message for sending."));
4376 tmsgid = g_strdup(compose->msgid);
4377 if (discard_window) {
4378 compose->sending = FALSE;
4379 compose_close(compose);
4380 /* No more compose access in the normal codepath
4381 * after this point! */
4386 alertpanel_error(_("The message was queued but could not be "
4387 "sent.\nUse \"Send queued messages\" from "
4388 "the main window to retry."));
4389 if (!discard_window) {
4396 if (msgpath == NULL) {
4397 msgpath = folder_item_fetch_msg(folder, msgnum);
4398 val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum, &queued_removed);
4401 val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum, &queued_removed);
4405 if (!discard_window) {
4406 compose->sending = FALSE;
4407 compose_allow_user_actions (compose, TRUE);
4409 if (!queued_removed)
4410 folder_item_remove_msg(folder, msgnum);
4411 folder_item_scan(folder);
4413 /* make sure we delete that */
4414 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
4416 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
4417 folder_item_remove_msg(folder, tmp->msgnum);
4418 procmsg_msginfo_free(tmp);
4425 if (!queued_removed)
4426 folder_item_remove_msg(folder, msgnum);
4427 folder_item_scan(folder);
4429 /* make sure we delete that */
4430 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
4432 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
4433 folder_item_remove_msg(folder, tmp->msgnum);
4434 procmsg_msginfo_free(tmp);
4437 if (!discard_window)
4438 compose_close(compose);
4441 gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
4442 "the main window to retry."), errstr);
4444 alertpanel_error_log(tmp);
4447 alertpanel_error_log(_("The message was queued but could not be "
4448 "sent.\nUse \"Send queued messages\" from "
4449 "the main window to retry."));
4451 if (!discard_window) {
4460 toolbar_main_set_sensitive(mainwin);
4461 main_window_set_menu_sensitive(mainwin);
4467 compose_allow_user_actions (compose, TRUE);
4468 compose->sending = FALSE;
4469 compose->modified = TRUE;
4470 toolbar_main_set_sensitive(mainwin);
4471 main_window_set_menu_sensitive(mainwin);
4476 static gboolean compose_use_attach(Compose *compose)
4478 GtkTreeModel *model = gtk_tree_view_get_model
4479 (GTK_TREE_VIEW(compose->attach_clist));
4480 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4483 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4486 gchar buf[BUFFSIZE];
4488 gboolean first_to_address;
4489 gboolean first_cc_address;
4491 ComposeHeaderEntry *headerentry;
4492 const gchar *headerentryname;
4493 const gchar *cc_hdr;
4494 const gchar *to_hdr;
4496 debug_print("Writing redirect header\n");
4498 cc_hdr = prefs_common_translated_header_name("Cc:");
4499 to_hdr = prefs_common_translated_header_name("To:");
4501 first_to_address = TRUE;
4502 for (list = compose->header_list; list; list = list->next) {
4503 headerentry = ((ComposeHeaderEntry *)list->data);
4504 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4506 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4507 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4508 Xstrdup_a(str, entstr, return -1);
4510 if (str[0] != '\0') {
4511 compose_convert_header
4512 (compose, buf, sizeof(buf), str,
4513 strlen("Resent-To") + 2, TRUE);
4515 if (first_to_address) {
4516 fprintf(fp, "Resent-To: ");
4517 first_to_address = FALSE;
4521 fprintf(fp, "%s", buf);
4525 if (!first_to_address) {
4529 first_cc_address = TRUE;
4530 for (list = compose->header_list; list; list = list->next) {
4531 headerentry = ((ComposeHeaderEntry *)list->data);
4532 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4534 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4535 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4536 Xstrdup_a(str, strg, return -1);
4538 if (str[0] != '\0') {
4539 compose_convert_header
4540 (compose, buf, sizeof(buf), str,
4541 strlen("Resent-Cc") + 2, TRUE);
4543 if (first_cc_address) {
4544 fprintf(fp, "Resent-Cc: ");
4545 first_cc_address = FALSE;
4549 fprintf(fp, "%s", buf);
4553 if (!first_cc_address) {
4560 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4562 gchar buf[BUFFSIZE];
4564 const gchar *entstr;
4565 /* struct utsname utsbuf; */
4567 g_return_val_if_fail(fp != NULL, -1);
4568 g_return_val_if_fail(compose->account != NULL, -1);
4569 g_return_val_if_fail(compose->account->address != NULL, -1);
4572 get_rfc822_date(buf, sizeof(buf));
4573 fprintf(fp, "Resent-Date: %s\n", buf);
4576 if (compose->account->name && *compose->account->name) {
4577 compose_convert_header
4578 (compose, buf, sizeof(buf), compose->account->name,
4579 strlen("From: "), TRUE);
4580 fprintf(fp, "Resent-From: %s <%s>\n",
4581 buf, compose->account->address);
4583 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4586 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4587 if (*entstr != '\0') {
4588 Xstrdup_a(str, entstr, return -1);
4591 compose_convert_header(compose, buf, sizeof(buf), str,
4592 strlen("Subject: "), FALSE);
4593 fprintf(fp, "Subject: %s\n", buf);
4597 /* Resent-Message-ID */
4598 if (compose->account->gen_msgid) {
4599 generate_msgid(buf, sizeof(buf));
4600 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4601 compose->msgid = g_strdup(buf);
4604 compose_redirect_write_headers_from_headerlist(compose, fp);
4606 /* separator between header and body */
4612 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4616 gchar buf[BUFFSIZE];
4618 gboolean skip = FALSE;
4619 gchar *not_included[]={
4620 "Return-Path:", "Delivered-To:", "Received:",
4621 "Subject:", "X-UIDL:", "AF:",
4622 "NF:", "PS:", "SRH:",
4623 "SFN:", "DSR:", "MID:",
4624 "CFG:", "PT:", "S:",
4625 "RQ:", "SSV:", "NSV:",
4626 "SSH:", "R:", "MAID:",
4627 "NAID:", "RMID:", "FMID:",
4628 "SCF:", "RRCPT:", "NG:",
4629 "X-Claws-Privacy", "X-Claws-Sign:", "X-Claws-Encrypt",
4630 "X-Claws-End-Special-Headers:", "X-Claws-Account-Id:",
4631 "X-Sylpheed-Privacy", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt",
4632 "X-Sylpheed-End-Special-Headers:", "X-Sylpheed-Account-Id:",
4635 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4636 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4640 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4642 for (i = 0; not_included[i] != NULL; i++) {
4643 if (g_ascii_strncasecmp(buf, not_included[i],
4644 strlen(not_included[i])) == 0) {
4651 if (fputs(buf, fdest) == -1)
4654 if (!prefs_common.redirect_keep_from) {
4655 if (g_ascii_strncasecmp(buf, "From:",
4656 strlen("From:")) == 0) {
4657 fputs(" (by way of ", fdest);
4658 if (compose->account->name
4659 && *compose->account->name) {
4660 compose_convert_header
4661 (compose, buf, sizeof(buf),
4662 compose->account->name,
4665 fprintf(fdest, "%s <%s>",
4667 compose->account->address);
4669 fprintf(fdest, "%s",
4670 compose->account->address);
4675 if (fputs("\n", fdest) == -1)
4679 compose_redirect_write_headers(compose, fdest);
4681 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4682 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4695 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
4697 GtkTextBuffer *buffer;
4698 GtkTextIter start, end;
4701 const gchar *out_codeset;
4702 EncodingType encoding;
4703 MimeInfo *mimemsg, *mimetext;
4706 if (action == COMPOSE_WRITE_FOR_SEND)
4707 attach_parts = TRUE;
4709 /* create message MimeInfo */
4710 mimemsg = procmime_mimeinfo_new();
4711 mimemsg->type = MIMETYPE_MESSAGE;
4712 mimemsg->subtype = g_strdup("rfc822");
4713 mimemsg->content = MIMECONTENT_MEM;
4714 mimemsg->tmp = TRUE; /* must free content later */
4715 mimemsg->data.mem = compose_get_header(compose);
4717 /* Create text part MimeInfo */
4718 /* get all composed text */
4719 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4720 gtk_text_buffer_get_start_iter(buffer, &start);
4721 gtk_text_buffer_get_end_iter(buffer, &end);
4722 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4723 if (is_ascii_str(chars)) {
4726 out_codeset = CS_US_ASCII;
4727 encoding = ENC_7BIT;
4729 const gchar *src_codeset = CS_INTERNAL;
4731 out_codeset = conv_get_charset_str(compose->out_encoding);
4734 gchar *test_conv_global_out = NULL;
4735 gchar *test_conv_reply = NULL;
4737 /* automatic mode. be automatic. */
4738 codeconv_set_strict(TRUE);
4740 out_codeset = conv_get_outgoing_charset_str();
4742 debug_print("trying to convert to %s\n", out_codeset);
4743 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4746 if (!test_conv_global_out && compose->orig_charset
4747 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4748 out_codeset = compose->orig_charset;
4749 debug_print("failure; trying to convert to %s\n", out_codeset);
4750 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4753 if (!test_conv_global_out && !test_conv_reply) {
4755 out_codeset = CS_INTERNAL;
4756 debug_print("failure; finally using %s\n", out_codeset);
4758 g_free(test_conv_global_out);
4759 g_free(test_conv_reply);
4760 codeconv_set_strict(FALSE);
4763 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4764 out_codeset = CS_ISO_8859_1;
4766 if (prefs_common.encoding_method == CTE_BASE64)
4767 encoding = ENC_BASE64;
4768 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4769 encoding = ENC_QUOTED_PRINTABLE;
4770 else if (prefs_common.encoding_method == CTE_8BIT)
4771 encoding = ENC_8BIT;
4773 encoding = procmime_get_encoding_for_charset(out_codeset);
4775 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4776 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4778 if (action == COMPOSE_WRITE_FOR_SEND) {
4779 codeconv_set_strict(TRUE);
4780 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4781 codeconv_set_strict(FALSE);
4787 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4788 "to the specified %s charset.\n"
4789 "Send it as %s?"), out_codeset, src_codeset);
4790 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4791 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4794 if (aval != G_ALERTALTERNATE) {
4799 out_codeset = src_codeset;
4805 out_codeset = src_codeset;
4811 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4812 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4813 strstr(buf, "\nFrom ") != NULL) {
4814 encoding = ENC_QUOTED_PRINTABLE;
4818 mimetext = procmime_mimeinfo_new();
4819 mimetext->content = MIMECONTENT_MEM;
4820 mimetext->tmp = TRUE; /* must free content later */
4821 /* dup'ed because procmime_encode_content can turn it into a tmpfile
4822 * and free the data, which we need later. */
4823 mimetext->data.mem = g_strdup(buf);
4824 mimetext->type = MIMETYPE_TEXT;
4825 mimetext->subtype = g_strdup("plain");
4826 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4827 g_strdup(out_codeset));
4829 /* protect trailing spaces when signing message */
4830 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4831 privacy_system_can_sign(compose->privacy_system)) {
4832 encoding = ENC_QUOTED_PRINTABLE;
4835 debug_print("main text: %d bytes encoded as %s in %d\n",
4836 strlen(buf), out_codeset, encoding);
4838 /* check for line length limit */
4839 if (action == COMPOSE_WRITE_FOR_SEND &&
4840 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4841 check_line_length(buf, 1000, &line) < 0) {
4845 msg = g_strdup_printf
4846 (_("Line %d exceeds the line length limit (998 bytes).\n"
4847 "The contents of the message might be broken on the way to the delivery.\n"
4849 "Send it anyway?"), line + 1);
4850 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4852 if (aval != G_ALERTALTERNATE) {
4858 if (encoding != ENC_UNKNOWN)
4859 procmime_encode_content(mimetext, encoding);
4861 /* append attachment parts */
4862 if (compose_use_attach(compose) && attach_parts) {
4863 MimeInfo *mimempart;
4864 gchar *boundary = NULL;
4865 mimempart = procmime_mimeinfo_new();
4866 mimempart->content = MIMECONTENT_EMPTY;
4867 mimempart->type = MIMETYPE_MULTIPART;
4868 mimempart->subtype = g_strdup("mixed");
4872 boundary = generate_mime_boundary(NULL);
4873 } while (strstr(buf, boundary) != NULL);
4875 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4878 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4880 g_node_append(mimempart->node, mimetext->node);
4881 g_node_append(mimemsg->node, mimempart->node);
4883 compose_add_attachments(compose, mimempart);
4885 g_node_append(mimemsg->node, mimetext->node);
4889 /* sign message if sending */
4890 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4891 privacy_system_can_sign(compose->privacy_system))
4892 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4895 procmime_write_mimeinfo(mimemsg, fp);
4897 procmime_mimeinfo_free_all(mimemsg);
4902 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4904 GtkTextBuffer *buffer;
4905 GtkTextIter start, end;
4910 if ((fp = g_fopen(file, "wb")) == NULL) {
4911 FILE_OP_ERROR(file, "fopen");
4915 /* chmod for security */
4916 if (change_file_mode_rw(fp, file) < 0) {
4917 FILE_OP_ERROR(file, "chmod");
4918 g_warning("can't change file mode\n");
4921 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4922 gtk_text_buffer_get_start_iter(buffer, &start);
4923 gtk_text_buffer_get_end_iter(buffer, &end);
4924 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4926 chars = conv_codeset_strdup
4927 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4930 if (!chars) return -1;
4933 len = strlen(chars);
4934 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4935 FILE_OP_ERROR(file, "fwrite");
4944 if (fclose(fp) == EOF) {
4945 FILE_OP_ERROR(file, "fclose");
4952 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4955 MsgInfo *msginfo = compose->targetinfo;
4957 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4958 if (!msginfo) return -1;
4960 if (!force && MSG_IS_LOCKED(msginfo->flags))
4963 item = msginfo->folder;
4964 g_return_val_if_fail(item != NULL, -1);
4966 if (procmsg_msg_exist(msginfo) &&
4967 (folder_has_parent_of_type(item, F_QUEUE) ||
4968 folder_has_parent_of_type(item, F_DRAFT)
4969 || msginfo == compose->autosaved_draft)) {
4970 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4971 g_warning("can't remove the old message\n");
4979 static void compose_remove_draft(Compose *compose)
4982 MsgInfo *msginfo = compose->targetinfo;
4983 drafts = account_get_special_folder(compose->account, F_DRAFT);
4985 if (procmsg_msg_exist(msginfo)) {
4986 folder_item_remove_msg(drafts, msginfo->msgnum);
4991 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
4992 gboolean remove_reedit_target)
4994 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
4997 static gboolean compose_warn_encryption(Compose *compose)
4999 const gchar *warning = privacy_get_encrypt_warning(compose->privacy_system);
5000 AlertValue val = G_ALERTALTERNATE;
5002 if (warning == NULL)
5005 val = alertpanel_full(_("Encryption warning"), warning,
5006 GTK_STOCK_CANCEL, _("+C_ontinue"), NULL,
5007 TRUE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
5008 if (val & G_ALERTDISABLE) {
5009 val &= ~G_ALERTDISABLE;
5010 if (val == G_ALERTALTERNATE)
5011 privacy_inhibit_encrypt_warning(compose->privacy_system,
5015 if (val == G_ALERTALTERNATE) {
5022 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
5023 gchar **msgpath, gboolean check_subject,
5024 gboolean remove_reedit_target)
5031 static gboolean lock = FALSE;
5032 PrefsAccount *mailac = NULL, *newsac = NULL;
5034 debug_print("queueing message...\n");
5035 g_return_val_if_fail(compose->account != NULL, -1);
5039 if (compose_check_entries(compose, check_subject) == FALSE) {
5041 if (compose->batch) {
5042 gtk_widget_show_all(compose->window);
5047 if (!compose->to_list && !compose->newsgroup_list) {
5048 g_warning("can't get recipient list.");
5053 if (compose->to_list) {
5054 if (compose->account->protocol != A_NNTP)
5055 mailac = compose->account;
5056 else if (cur_account && cur_account->protocol != A_NNTP)
5057 mailac = cur_account;
5058 else if (!(mailac = compose_current_mail_account())) {
5060 alertpanel_error(_("No account for sending mails available!"));
5065 if (compose->newsgroup_list) {
5066 if (compose->account->protocol == A_NNTP)
5067 newsac = compose->account;
5068 else if (!newsac->protocol != A_NNTP) {
5070 alertpanel_error(_("No account for posting news available!"));
5075 /* write queue header */
5076 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
5077 G_DIR_SEPARATOR, compose);
5078 if ((fp = g_fopen(tmp, "wb")) == NULL) {
5079 FILE_OP_ERROR(tmp, "fopen");
5085 if (change_file_mode_rw(fp, tmp) < 0) {
5086 FILE_OP_ERROR(tmp, "chmod");
5087 g_warning("can't change file mode\n");
5090 /* queueing variables */
5091 fprintf(fp, "AF:\n");
5092 fprintf(fp, "NF:0\n");
5093 fprintf(fp, "PS:10\n");
5094 fprintf(fp, "SRH:1\n");
5095 fprintf(fp, "SFN:\n");
5096 fprintf(fp, "DSR:\n");
5098 fprintf(fp, "MID:<%s>\n", compose->msgid);
5100 fprintf(fp, "MID:\n");
5101 fprintf(fp, "CFG:\n");
5102 fprintf(fp, "PT:0\n");
5103 fprintf(fp, "S:%s\n", compose->account->address);
5104 fprintf(fp, "RQ:\n");
5106 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
5108 fprintf(fp, "SSV:\n");
5110 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
5112 fprintf(fp, "NSV:\n");
5113 fprintf(fp, "SSH:\n");
5114 /* write recepient list */
5115 if (compose->to_list) {
5116 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
5117 for (cur = compose->to_list->next; cur != NULL;
5119 fprintf(fp, ",<%s>", (gchar *)cur->data);
5122 /* write newsgroup list */
5123 if (compose->newsgroup_list) {
5125 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
5126 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
5127 fprintf(fp, ",%s", (gchar *)cur->data);
5130 /* Sylpheed account IDs */
5132 fprintf(fp, "MAID:%d\n", mailac->account_id);
5134 fprintf(fp, "NAID:%d\n", newsac->account_id);
5137 if (compose->privacy_system != NULL) {
5138 fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system);
5139 fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing);
5140 if (compose->use_encryption) {
5142 if (!compose_warn_encryption(compose)) {
5149 if (mailac && mailac->encrypt_to_self) {
5150 GSList *tmp_list = g_slist_copy(compose->to_list);
5151 tmp_list = g_slist_append(tmp_list, compose->account->address);
5152 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
5153 g_slist_free(tmp_list);
5155 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
5157 if (encdata != NULL) {
5158 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
5159 fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
5160 fprintf(fp, "X-Claws-Encrypt-Data:%s\n",
5162 } /* else we finally dont want to encrypt */
5164 fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
5165 /* and if encdata was null, it means there's been a problem in
5177 /* Save copy folder */
5178 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
5179 gchar *savefolderid;
5181 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
5182 fprintf(fp, "SCF:%s\n", savefolderid);
5183 g_free(savefolderid);
5185 /* Save copy folder */
5186 if (compose->return_receipt) {
5187 fprintf(fp, "RRCPT:1\n");
5189 /* Message-ID of message replying to */
5190 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
5193 folderid = folder_item_get_identifier(compose->replyinfo->folder);
5194 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
5197 /* Message-ID of message forwarding to */
5198 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
5201 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
5202 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
5206 /* end of headers */
5207 fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
5209 if (compose->redirect_filename != NULL) {
5210 if (compose_redirect_write_to_file(compose, fp) < 0) {
5219 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
5224 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
5228 if (fclose(fp) == EOF) {
5229 FILE_OP_ERROR(tmp, "fclose");
5236 if (item && *item) {
5239 queue = account_get_special_folder(compose->account, F_QUEUE);
5242 g_warning("can't find queue folder\n");
5248 folder_item_scan(queue);
5249 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
5250 g_warning("can't queue the message\n");
5257 if (msgpath == NULL) {
5263 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
5264 compose_remove_reedit_target(compose, FALSE);
5267 if ((msgnum != NULL) && (item != NULL)) {
5275 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
5278 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5280 struct stat statbuf;
5281 gchar *type, *subtype;
5282 GtkTreeModel *model;
5285 model = gtk_tree_view_get_model(tree_view);
5287 if (!gtk_tree_model_get_iter_first(model, &iter))
5290 gtk_tree_model_get(model, &iter,
5294 mimepart = procmime_mimeinfo_new();
5295 mimepart->content = MIMECONTENT_FILE;
5296 mimepart->data.filename = g_strdup(ainfo->file);
5297 mimepart->tmp = FALSE; /* or we destroy our attachment */
5298 mimepart->offset = 0;
5300 stat(ainfo->file, &statbuf);
5301 mimepart->length = statbuf.st_size;
5303 type = g_strdup(ainfo->content_type);
5305 if (!strchr(type, '/')) {
5307 type = g_strdup("application/octet-stream");
5310 subtype = strchr(type, '/') + 1;
5311 *(subtype - 1) = '\0';
5312 mimepart->type = procmime_get_media_type(type);
5313 mimepart->subtype = g_strdup(subtype);
5316 if (mimepart->type == MIMETYPE_MESSAGE &&
5317 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
5318 mimepart->disposition = DISPOSITIONTYPE_INLINE;
5321 g_hash_table_insert(mimepart->typeparameters,
5322 g_strdup("name"), g_strdup(ainfo->name));
5323 g_hash_table_insert(mimepart->dispositionparameters,
5324 g_strdup("filename"), g_strdup(ainfo->name));
5325 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
5329 if (compose->use_signing) {
5330 if (ainfo->encoding == ENC_7BIT)
5331 ainfo->encoding = ENC_QUOTED_PRINTABLE;
5332 else if (ainfo->encoding == ENC_8BIT)
5333 ainfo->encoding = ENC_BASE64;
5336 procmime_encode_content(mimepart, ainfo->encoding);
5338 g_node_append(parent->node, mimepart->node);
5339 } while (gtk_tree_model_iter_next(model, &iter));
5342 #define IS_IN_CUSTOM_HEADER(header) \
5343 (compose->account->add_customhdr && \
5344 custom_header_find(compose->account->customhdr_list, header) != NULL)
5346 static void compose_add_headerfield_from_headerlist(Compose *compose,
5348 const gchar *fieldname,
5349 const gchar *seperator)
5351 gchar *str, *fieldname_w_colon;
5352 gboolean add_field = FALSE;
5354 ComposeHeaderEntry *headerentry;
5355 const gchar *headerentryname;
5356 const gchar *trans_fieldname;
5359 if (IS_IN_CUSTOM_HEADER(fieldname))
5362 debug_print("Adding %s-fields\n", fieldname);
5364 fieldstr = g_string_sized_new(64);
5366 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
5367 trans_fieldname = prefs_common_translated_header_name(fieldname_w_colon);
5369 for (list = compose->header_list; list; list = list->next) {
5370 headerentry = ((ComposeHeaderEntry *)list->data);
5371 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
5373 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
5374 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
5376 if (str[0] != '\0') {
5378 g_string_append(fieldstr, seperator);
5379 g_string_append(fieldstr, str);
5388 buf = g_new0(gchar, fieldstr->len * 4 + 256);
5389 compose_convert_header
5390 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
5391 strlen(fieldname) + 2, TRUE);
5392 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
5396 g_free(fieldname_w_colon);
5397 g_string_free(fieldstr, TRUE);
5402 static gchar *compose_get_header(Compose *compose)
5404 gchar buf[BUFFSIZE];
5405 const gchar *entry_str;
5409 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5411 gchar *from_name = NULL, *from_address = NULL;
5414 g_return_val_if_fail(compose->account != NULL, NULL);
5415 g_return_val_if_fail(compose->account->address != NULL, NULL);
5417 header = g_string_sized_new(64);
5420 get_rfc822_date(buf, sizeof(buf));
5421 g_string_append_printf(header, "Date: %s\n", buf);
5425 if (compose->account->name && *compose->account->name) {
5427 QUOTE_IF_REQUIRED(buf, compose->account->name);
5428 tmp = g_strdup_printf("%s <%s>",
5429 buf, compose->account->address);
5431 tmp = g_strdup_printf("%s",
5432 compose->account->address);
5434 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5435 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5437 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5438 from_address = g_strdup(compose->account->address);
5440 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5441 /* extract name and address */
5442 if (strstr(spec, " <") && strstr(spec, ">")) {
5443 from_address = g_strdup(strrchr(spec, '<')+1);
5444 *(strrchr(from_address, '>')) = '\0';
5445 from_name = g_strdup(spec);
5446 *(strrchr(from_name, '<')) = '\0';
5449 from_address = g_strdup(spec);
5456 if (from_name && *from_name) {
5457 compose_convert_header
5458 (compose, buf, sizeof(buf), from_name,
5459 strlen("From: "), TRUE);
5460 QUOTE_IF_REQUIRED(name, buf);
5462 g_string_append_printf(header, "From: %s <%s>\n",
5463 name, from_address);
5465 g_string_append_printf(header, "From: %s\n", from_address);
5468 g_free(from_address);
5471 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5474 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5477 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5480 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5483 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5485 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5488 compose_convert_header(compose, buf, sizeof(buf), str,
5489 strlen("Subject: "), FALSE);
5490 g_string_append_printf(header, "Subject: %s\n", buf);
5496 if (compose->account->gen_msgid) {
5497 generate_msgid(buf, sizeof(buf));
5498 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5499 compose->msgid = g_strdup(buf);
5502 if (compose->remove_references == FALSE) {
5504 if (compose->inreplyto && compose->to_list)
5505 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5508 if (compose->references)
5509 g_string_append_printf(header, "References: %s\n", compose->references);
5513 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5516 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5519 if (compose->account->organization &&
5520 strlen(compose->account->organization) &&
5521 !IS_IN_CUSTOM_HEADER("Organization")) {
5522 compose_convert_header(compose, buf, sizeof(buf),
5523 compose->account->organization,
5524 strlen("Organization: "), FALSE);
5525 g_string_append_printf(header, "Organization: %s\n", buf);
5528 /* Program version and system info */
5529 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5530 !compose->newsgroup_list) {
5531 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5533 gtk_major_version, gtk_minor_version, gtk_micro_version,
5536 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5537 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5539 gtk_major_version, gtk_minor_version, gtk_micro_version,
5543 /* custom headers */
5544 if (compose->account->add_customhdr) {
5547 for (cur = compose->account->customhdr_list; cur != NULL;
5549 CustomHeader *chdr = (CustomHeader *)cur->data;
5551 if (custom_header_is_allowed(chdr->name)) {
5552 compose_convert_header
5553 (compose, buf, sizeof(buf),
5554 chdr->value ? chdr->value : "",
5555 strlen(chdr->name) + 2, FALSE);
5556 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5562 switch (compose->priority) {
5563 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5564 "X-Priority: 1 (Highest)\n");
5566 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5567 "X-Priority: 2 (High)\n");
5569 case PRIORITY_NORMAL: break;
5570 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5571 "X-Priority: 4 (Low)\n");
5573 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5574 "X-Priority: 5 (Lowest)\n");
5576 default: debug_print("compose: priority unknown : %d\n",
5580 /* Request Return Receipt */
5581 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5582 if (compose->return_receipt) {
5583 if (compose->account->name
5584 && *compose->account->name) {
5585 compose_convert_header(compose, buf, sizeof(buf),
5586 compose->account->name,
5587 strlen("Disposition-Notification-To: "),
5589 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5591 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5595 /* get special headers */
5596 for (list = compose->header_list; list; list = list->next) {
5597 ComposeHeaderEntry *headerentry;
5600 gchar *headername_wcolon;
5601 const gchar *headername_trans;
5604 gboolean standard_header = FALSE;
5606 headerentry = ((ComposeHeaderEntry *)list->data);
5608 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5609 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5614 if (!strstr(tmp, ":")) {
5615 headername_wcolon = g_strconcat(tmp, ":", NULL);
5616 headername = g_strdup(tmp);
5618 headername_wcolon = g_strdup(tmp);
5619 headername = g_strdup(strtok(tmp, ":"));
5623 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5624 Xstrdup_a(headervalue, entry_str, return NULL);
5625 subst_char(headervalue, '\r', ' ');
5626 subst_char(headervalue, '\n', ' ');
5627 string = std_headers;
5628 while (*string != NULL) {
5629 headername_trans = prefs_common_translated_header_name(*string);
5630 if (!strcmp(headername_trans, headername_wcolon))
5631 standard_header = TRUE;
5634 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5635 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5638 g_free(headername_wcolon);
5642 g_string_free(header, FALSE);
5647 #undef IS_IN_CUSTOM_HEADER
5649 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5650 gint header_len, gboolean addr_field)
5652 gchar *tmpstr = NULL;
5653 const gchar *out_codeset = NULL;
5655 g_return_if_fail(src != NULL);
5656 g_return_if_fail(dest != NULL);
5658 if (len < 1) return;
5660 tmpstr = g_strdup(src);
5662 subst_char(tmpstr, '\n', ' ');
5663 subst_char(tmpstr, '\r', ' ');
5666 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5667 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5668 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5673 codeconv_set_strict(TRUE);
5674 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5675 conv_get_charset_str(compose->out_encoding));
5676 codeconv_set_strict(FALSE);
5678 if (!dest || *dest == '\0') {
5679 gchar *test_conv_global_out = NULL;
5680 gchar *test_conv_reply = NULL;
5682 /* automatic mode. be automatic. */
5683 codeconv_set_strict(TRUE);
5685 out_codeset = conv_get_outgoing_charset_str();
5687 debug_print("trying to convert to %s\n", out_codeset);
5688 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5691 if (!test_conv_global_out && compose->orig_charset
5692 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5693 out_codeset = compose->orig_charset;
5694 debug_print("failure; trying to convert to %s\n", out_codeset);
5695 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5698 if (!test_conv_global_out && !test_conv_reply) {
5700 out_codeset = CS_INTERNAL;
5701 debug_print("finally using %s\n", out_codeset);
5703 g_free(test_conv_global_out);
5704 g_free(test_conv_reply);
5705 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5707 codeconv_set_strict(FALSE);
5712 static void compose_add_to_addressbook_cb(GtkMenuItem *menuitem, gpointer user_data)
5716 g_return_if_fail(user_data != NULL);
5718 address = g_strdup(gtk_entry_get_text(GTK_ENTRY(user_data)));
5719 g_strstrip(address);
5720 if (*address != '\0') {
5721 gchar *name = procheader_get_fromname(address);
5722 extract_address(address);
5723 addressbook_add_contact(name, address, NULL);
5728 static void compose_entry_popup_extend(GtkEntry *entry, GtkMenu *menu, gpointer user_data)
5730 GtkWidget *menuitem;
5733 g_return_if_fail(menu != NULL);
5734 g_return_if_fail(GTK_IS_MENU_SHELL(menu));
5736 menuitem = gtk_separator_menu_item_new();
5737 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem);
5738 gtk_widget_show(menuitem);
5740 menuitem = gtk_menu_item_new_with_mnemonic(_("Add to address _book"));
5741 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem);
5743 address = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
5744 g_strstrip(address);
5745 if (*address == '\0') {
5746 gtk_widget_set_sensitive(GTK_WIDGET(menuitem), FALSE);
5749 g_signal_connect(G_OBJECT(menuitem), "activate",
5750 G_CALLBACK(compose_add_to_addressbook_cb), entry);
5751 gtk_widget_show(menuitem);
5754 static void compose_create_header_entry(Compose *compose)
5756 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5760 GList *combo_list = NULL;
5762 const gchar *header = NULL;
5763 ComposeHeaderEntry *headerentry;
5764 gboolean standard_header = FALSE;
5766 headerentry = g_new0(ComposeHeaderEntry, 1);
5769 combo = gtk_combo_new();
5771 while(*string != NULL) {
5772 combo_list = g_list_append(combo_list, (gchar*)prefs_common_translated_header_name(*string));
5775 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5776 g_list_free(combo_list);
5777 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5778 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5779 G_CALLBACK(compose_grab_focus_cb), compose);
5780 gtk_widget_show(combo);
5781 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1,
5782 compose->header_nextrow, compose->header_nextrow+1,
5783 GTK_SHRINK, GTK_FILL, 0, 0);
5784 if (compose->header_last) {
5785 const gchar *last_header_entry = gtk_entry_get_text(
5786 GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5788 while (*string != NULL) {
5789 if (!strcmp(*string, last_header_entry))
5790 standard_header = TRUE;
5793 if (standard_header)
5794 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5796 if (!compose->header_last || !standard_header) {
5797 switch(compose->account->protocol) {
5799 header = prefs_common_translated_header_name("Newsgroups:");
5802 header = prefs_common_translated_header_name("To:");
5807 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5809 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5810 G_CALLBACK(compose_grab_focus_cb), compose);
5813 entry = gtk_entry_new();
5814 gtk_widget_show(entry);
5815 gtk_tooltips_set_tip(compose->tooltips, entry,
5816 _("Use <tab> to autocomplete from addressbook"), NULL);
5817 gtk_table_attach(GTK_TABLE(compose->header_table), entry, 1, 2,
5818 compose->header_nextrow, compose->header_nextrow+1,
5819 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
5821 g_signal_connect(G_OBJECT(entry), "key-press-event",
5822 G_CALLBACK(compose_headerentry_key_press_event_cb),
5824 g_signal_connect(G_OBJECT(entry), "changed",
5825 G_CALLBACK(compose_headerentry_changed_cb),
5827 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5828 G_CALLBACK(compose_grab_focus_cb), compose);
5831 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5832 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5833 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5834 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5835 G_CALLBACK(compose_header_drag_received_cb),
5837 g_signal_connect(G_OBJECT(entry), "drag-drop",
5838 G_CALLBACK(compose_drag_drop),
5840 g_signal_connect(G_OBJECT(entry), "populate-popup",
5841 G_CALLBACK(compose_entry_popup_extend),
5844 address_completion_register_entry(GTK_ENTRY(entry), TRUE);
5846 headerentry->compose = compose;
5847 headerentry->combo = combo;
5848 headerentry->entry = entry;
5849 headerentry->headernum = compose->header_nextrow;
5851 compose->header_nextrow++;
5852 compose->header_last = headerentry;
5853 compose->header_list =
5854 g_slist_append(compose->header_list,
5858 static void compose_add_header_entry(Compose *compose, const gchar *header, gchar *text)
5860 ComposeHeaderEntry *last_header;
5862 last_header = compose->header_last;
5864 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5865 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5868 static void compose_remove_header_entries(Compose *compose)
5871 for (list = compose->header_list; list; list = list->next) {
5872 ComposeHeaderEntry *headerentry =
5873 (ComposeHeaderEntry *)list->data;
5874 gtk_widget_destroy(headerentry->combo);
5875 gtk_widget_destroy(headerentry->entry);
5876 g_free(headerentry);
5878 compose->header_last = NULL;
5879 g_slist_free(compose->header_list);
5880 compose->header_list = NULL;
5881 compose->header_nextrow = 1;
5882 compose_create_header_entry(compose);
5885 static GtkWidget *compose_create_header(Compose *compose)
5887 GtkWidget *from_optmenu_hbox;
5888 GtkWidget *header_scrolledwin;
5889 GtkWidget *header_table;
5893 /* header labels and entries */
5894 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5895 gtk_widget_show(header_scrolledwin);
5896 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5898 header_table = gtk_table_new(2, 2, FALSE);
5899 gtk_widget_show(header_table);
5900 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5901 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5902 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5905 /* option menu for selecting accounts */
5906 from_optmenu_hbox = compose_account_option_menu_create(compose);
5907 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5908 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5911 compose->header_table = header_table;
5912 compose->header_list = NULL;
5913 compose->header_nextrow = count;
5915 compose_create_header_entry(compose);
5917 compose->table = NULL;
5919 return header_scrolledwin ;
5922 static gboolean popup_attach_button_pressed(GtkWidget *widget, gpointer data)
5924 Compose *compose = (Compose *)data;
5925 GdkEventButton event;
5928 event.time = gtk_get_current_event_time();
5930 return attach_button_pressed(compose->attach_clist, &event, compose);
5933 static GtkWidget *compose_create_attach(Compose *compose)
5935 GtkWidget *attach_scrwin;
5936 GtkWidget *attach_clist;
5938 GtkListStore *store;
5939 GtkCellRenderer *renderer;
5940 GtkTreeViewColumn *column;
5941 GtkTreeSelection *selection;
5943 /* attachment list */
5944 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5945 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5946 GTK_POLICY_AUTOMATIC,
5947 GTK_POLICY_AUTOMATIC);
5948 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5950 store = gtk_list_store_new(N_ATTACH_COLS,
5955 G_TYPE_AUTO_POINTER,
5957 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5958 (GTK_TREE_MODEL(store)));
5959 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5960 g_object_unref(store);
5962 renderer = gtk_cell_renderer_text_new();
5963 column = gtk_tree_view_column_new_with_attributes
5964 (_("Mime type"), renderer, "text",
5965 COL_MIMETYPE, NULL);
5966 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5968 renderer = gtk_cell_renderer_text_new();
5969 column = gtk_tree_view_column_new_with_attributes
5970 (_("Size"), renderer, "text",
5972 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5974 renderer = gtk_cell_renderer_text_new();
5975 column = gtk_tree_view_column_new_with_attributes
5976 (_("Name"), renderer, "text",
5978 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5980 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5981 prefs_common.use_stripes_everywhere);
5982 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5983 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5985 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5986 G_CALLBACK(attach_selected), compose);
5987 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5988 G_CALLBACK(attach_button_pressed), compose);
5990 g_signal_connect(G_OBJECT(attach_clist), "popup-menu",
5991 G_CALLBACK(popup_attach_button_pressed), compose);
5993 gtk_widget_tap_and_hold_setup(GTK_WIDGET(attach_clist), NULL, NULL,
5994 GTK_TAP_AND_HOLD_NONE | GTK_TAP_AND_HOLD_NO_INTERNALS);
5995 g_signal_connect(G_OBJECT(attach_clist), "tap-and-hold",
5996 G_CALLBACK(popup_attach_button_pressed), compose);
5998 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5999 G_CALLBACK(attach_key_pressed), compose);
6002 gtk_drag_dest_set(attach_clist,
6003 GTK_DEST_DEFAULT_ALL, compose_mime_types,
6004 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
6005 GDK_ACTION_COPY | GDK_ACTION_MOVE);
6006 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
6007 G_CALLBACK(compose_attach_drag_received_cb),
6009 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
6010 G_CALLBACK(compose_drag_drop),
6013 compose->attach_scrwin = attach_scrwin;
6014 compose->attach_clist = attach_clist;
6016 return attach_scrwin;
6019 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
6020 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
6022 static GtkWidget *compose_create_others(Compose *compose)
6025 GtkWidget *savemsg_checkbtn;
6026 GtkWidget *savemsg_entry;
6027 GtkWidget *savemsg_select;
6030 gchar *folderidentifier;
6032 /* Table for settings */
6033 table = gtk_table_new(3, 1, FALSE);
6034 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
6035 gtk_widget_show(table);
6036 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
6039 /* Save Message to folder */
6040 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
6041 gtk_widget_show(savemsg_checkbtn);
6042 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
6043 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6044 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
6046 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
6047 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6049 savemsg_entry = gtk_entry_new();
6050 gtk_widget_show(savemsg_entry);
6051 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
6052 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
6053 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
6054 G_CALLBACK(compose_grab_focus_cb), compose);
6055 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6056 folderidentifier = folder_item_get_identifier(account_get_special_folder
6057 (compose->account, F_OUTBOX));
6058 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
6059 g_free(folderidentifier);
6062 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
6063 gtk_widget_show(savemsg_select);
6064 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
6065 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
6066 G_CALLBACK(compose_savemsg_select_cb),
6071 compose->savemsg_checkbtn = savemsg_checkbtn;
6072 compose->savemsg_entry = savemsg_entry;
6077 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
6079 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
6080 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
6083 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
6088 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
6091 path = folder_item_get_identifier(dest);
6093 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
6097 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
6098 GdkAtom clip, GtkTextIter *insert_place);
6100 #define BLOCK_WRAP() { \
6101 prev_autowrap = compose->autowrap; \
6102 buffer = gtk_text_view_get_buffer( \
6103 GTK_TEXT_VIEW(compose->text)); \
6104 compose->autowrap = FALSE; \
6106 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
6107 G_CALLBACK(compose_changed_cb), \
6109 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
6110 G_CALLBACK(text_inserted), \
6113 #define UNBLOCK_WRAP() { \
6114 compose->autowrap = prev_autowrap; \
6115 if (compose->autowrap) \
6116 compose_wrap_all(compose); \
6118 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
6119 G_CALLBACK(compose_changed_cb), \
6121 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
6122 G_CALLBACK(text_inserted), \
6127 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
6131 GtkTextBuffer *buffer;
6133 if (event->button == 3) {
6135 GtkTextIter sel_start, sel_end;
6136 gboolean stuff_selected;
6138 /* move the cursor to allow GtkAspell to check the word
6139 * under the mouse */
6140 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
6141 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
6143 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
6146 stuff_selected = gtk_text_buffer_get_selection_bounds(
6147 GTK_TEXT_VIEW(text)->buffer,
6148 &sel_start, &sel_end);
6150 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
6151 /* reselect stuff */
6153 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
6154 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
6155 &sel_start, &sel_end);
6157 return FALSE; /* pass the event so that the right-click goes through */
6160 if (event->button == 2) {
6165 /* get the middle-click position to paste at the correct place */
6166 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
6167 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
6169 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
6172 entry_paste_clipboard(compose, text,
6173 prefs_common.linewrap_pastes,
6174 GDK_SELECTION_PRIMARY, &iter);
6182 static void compose_spell_menu_changed(void *data)
6184 Compose *compose = (Compose *)data;
6186 GtkWidget *menuitem;
6187 GtkWidget *parent_item;
6188 GtkMenu *menu = GTK_MENU(gtk_menu_new());
6189 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6192 if (compose->gtkaspell == NULL)
6195 parent_item = gtk_item_factory_get_item(ifactory,
6196 "/Spelling/Options");
6198 /* setting the submenu removes /Spelling/Options from the factory
6199 * so we need to save it */
6201 if (parent_item == NULL) {
6202 parent_item = compose->aspell_options_menu;
6203 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
6205 compose->aspell_options_menu = parent_item;
6207 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
6209 spell_menu = g_slist_reverse(spell_menu);
6210 for (items = spell_menu;
6211 items; items = items->next) {
6212 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
6213 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
6214 gtk_widget_show(GTK_WIDGET(menuitem));
6216 g_slist_free(spell_menu);
6218 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
6223 static gboolean compose_popup_menu(GtkWidget *widget, gpointer data)
6225 Compose *compose = (Compose *)data;
6226 GdkEventButton event;
6229 event.time = gtk_get_current_event_time();
6231 return text_clicked(compose->text, &event, compose);
6234 static gboolean compose_force_window_origin = TRUE;
6235 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
6242 GtkWidget *handlebox;
6244 GtkWidget *notebook;
6249 GtkWidget *subject_hbox;
6250 GtkWidget *subject_frame;
6251 GtkWidget *subject_entry;
6255 GtkWidget *edit_vbox;
6256 GtkWidget *ruler_hbox;
6258 GtkWidget *scrolledwin;
6260 GtkTextBuffer *buffer;
6261 GtkClipboard *clipboard;
6263 UndoMain *undostruct;
6265 gchar *titles[N_ATTACH_COLS];
6266 guint n_menu_entries;
6267 GtkWidget *popupmenu;
6268 GtkItemFactory *popupfactory;
6269 GtkItemFactory *ifactory;
6270 GtkWidget *tmpl_menu;
6272 GtkWidget *menuitem;
6275 GtkAspell * gtkaspell = NULL;
6278 static GdkGeometry geometry;
6280 g_return_val_if_fail(account != NULL, NULL);
6282 debug_print("Creating compose window...\n");
6283 compose = g_new0(Compose, 1);
6285 titles[COL_MIMETYPE] = _("MIME type");
6286 titles[COL_SIZE] = _("Size");
6287 titles[COL_NAME] = _("Name");
6289 compose->batch = batch;
6290 compose->account = account;
6292 compose->mutex = g_mutex_new();
6293 compose->set_cursor_pos = -1;
6295 compose->tooltips = gtk_tooltips_new();
6297 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose");
6299 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
6300 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
6302 if (!geometry.max_width) {
6303 geometry.max_width = gdk_screen_width();
6304 geometry.max_height = gdk_screen_height();
6307 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
6308 &geometry, GDK_HINT_MAX_SIZE);
6309 if (!geometry.min_width) {
6310 geometry.min_width = 600;
6311 geometry.min_height = 480;
6313 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
6314 &geometry, GDK_HINT_MIN_SIZE);
6317 if (compose_force_window_origin)
6318 gtk_widget_set_uposition(window, prefs_common.compose_x,
6319 prefs_common.compose_y);
6321 g_signal_connect(G_OBJECT(window), "delete_event",
6322 G_CALLBACK(compose_delete_cb), compose);
6323 MANAGE_WINDOW_SIGNALS_CONNECT(window);
6324 gtk_widget_realize(window);
6326 gtkut_widget_set_composer_icon(window);
6328 vbox = gtk_vbox_new(FALSE, 0);
6329 gtk_container_add(GTK_CONTAINER(window), vbox);
6331 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
6332 menubar = menubar_create(window, compose_entries,
6333 n_menu_entries, "<Compose>", compose);
6334 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
6336 if (prefs_common.toolbar_detachable) {
6337 handlebox = gtk_handle_box_new();
6339 handlebox = gtk_hbox_new(FALSE, 0);
6341 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
6343 gtk_widget_realize(handlebox);
6344 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
6347 vbox2 = gtk_vbox_new(FALSE, 2);
6348 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
6349 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
6352 notebook = gtk_notebook_new();
6353 gtk_widget_set_size_request(notebook, -1, 130);
6354 gtk_widget_show(notebook);
6356 /* header labels and entries */
6357 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6358 compose_create_header(compose),
6359 gtk_label_new_with_mnemonic(_("Hea_der")));
6360 /* attachment list */
6361 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6362 compose_create_attach(compose),
6363 gtk_label_new_with_mnemonic(_("_Attachments")));
6365 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6366 compose_create_others(compose),
6367 gtk_label_new_with_mnemonic(_("Othe_rs")));
6370 subject_hbox = gtk_hbox_new(FALSE, 0);
6371 gtk_widget_show(subject_hbox);
6373 subject_frame = gtk_frame_new(NULL);
6374 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
6375 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
6376 gtk_widget_show(subject_frame);
6378 subject = gtk_hbox_new(FALSE, HSPACING_NARROW);
6379 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
6380 gtk_widget_show(subject);
6382 label = gtk_label_new(_("Subject:"));
6383 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
6384 gtk_widget_show(label);
6386 subject_entry = gtk_entry_new();
6387 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
6388 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
6389 G_CALLBACK(compose_grab_focus_cb), compose);
6390 gtk_widget_show(subject_entry);
6391 compose->subject_entry = subject_entry;
6392 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
6394 edit_vbox = gtk_vbox_new(FALSE, 0);
6396 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
6399 ruler_hbox = gtk_hbox_new(FALSE, 0);
6400 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
6402 ruler = gtk_shruler_new();
6403 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
6404 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
6408 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
6409 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
6410 GTK_POLICY_AUTOMATIC,
6411 GTK_POLICY_AUTOMATIC);
6412 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
6414 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
6415 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
6417 text = gtk_text_view_new();
6418 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6419 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
6420 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
6421 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
6422 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
6424 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
6426 g_signal_connect_after(G_OBJECT(text), "size_allocate",
6427 G_CALLBACK(compose_edit_size_alloc),
6429 g_signal_connect(G_OBJECT(buffer), "changed",
6430 G_CALLBACK(compose_changed_cb), compose);
6431 g_signal_connect(G_OBJECT(text), "grab_focus",
6432 G_CALLBACK(compose_grab_focus_cb), compose);
6433 g_signal_connect(G_OBJECT(buffer), "insert_text",
6434 G_CALLBACK(text_inserted), compose);
6435 g_signal_connect(G_OBJECT(text), "button_press_event",
6436 G_CALLBACK(text_clicked), compose);
6438 g_signal_connect(G_OBJECT(text), "popup-menu",
6439 G_CALLBACK(compose_popup_menu), compose);
6441 gtk_widget_tap_and_hold_setup(GTK_WIDGET(text), NULL, NULL,
6442 GTK_TAP_AND_HOLD_NONE | GTK_TAP_AND_HOLD_NO_INTERNALS);
6443 g_signal_connect(G_OBJECT(text), "tap-and-hold",
6444 G_CALLBACK(compose_popup_menu), compose);
6446 g_signal_connect(G_OBJECT(subject_entry), "changed",
6447 G_CALLBACK(compose_changed_cb), compose);
6450 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
6451 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
6452 GDK_ACTION_COPY | GDK_ACTION_MOVE);
6453 g_signal_connect(G_OBJECT(text), "drag_data_received",
6454 G_CALLBACK(compose_insert_drag_received_cb),
6456 g_signal_connect(G_OBJECT(text), "drag-drop",
6457 G_CALLBACK(compose_drag_drop),
6459 gtk_widget_show_all(vbox);
6461 /* pane between attach clist and text */
6462 paned = gtk_vpaned_new();
6463 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
6464 gtk_container_add(GTK_CONTAINER(vbox2), paned);
6466 if( maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window) )
6467 gtk_widget_set_size_request(edit_vbox, -1, mode == COMPOSE_NEW ? 300 : 280);
6469 gtk_widget_set_size_request(edit_vbox, -1, mode == COMPOSE_NEW ? 250 : 230);
6471 gtk_paned_add1(GTK_PANED(paned), notebook);
6472 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
6473 gtk_widget_show_all(paned);
6476 if (prefs_common.textfont) {
6477 PangoFontDescription *font_desc;
6479 font_desc = pango_font_description_from_string
6480 (prefs_common.textfont);
6482 gtk_widget_modify_font(text, font_desc);
6483 pango_font_description_free(font_desc);
6487 n_entries = sizeof(compose_popup_entries) /
6488 sizeof(compose_popup_entries[0]);
6489 popupmenu = menu_create_items(compose_popup_entries, n_entries,
6490 "<Compose>", &popupfactory,
6493 ifactory = gtk_item_factory_from_widget(menubar);
6494 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6495 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6496 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
6498 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6500 undostruct = undo_init(text);
6501 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
6504 address_completion_start(window);
6506 compose->window = window;
6507 compose->vbox = vbox;
6508 compose->menubar = menubar;
6509 compose->handlebox = handlebox;
6511 compose->vbox2 = vbox2;
6513 compose->paned = paned;
6515 compose->notebook = notebook;
6516 compose->edit_vbox = edit_vbox;
6517 compose->ruler_hbox = ruler_hbox;
6518 compose->ruler = ruler;
6519 compose->scrolledwin = scrolledwin;
6520 compose->text = text;
6522 compose->focused_editable = NULL;
6524 compose->popupmenu = popupmenu;
6525 compose->popupfactory = popupfactory;
6527 compose->tmpl_menu = tmpl_menu;
6529 compose->mode = mode;
6530 compose->rmode = mode;
6532 compose->targetinfo = NULL;
6533 compose->replyinfo = NULL;
6534 compose->fwdinfo = NULL;
6536 compose->replyto = NULL;
6538 compose->bcc = NULL;
6539 compose->followup_to = NULL;
6541 compose->ml_post = NULL;
6543 compose->inreplyto = NULL;
6544 compose->references = NULL;
6545 compose->msgid = NULL;
6546 compose->boundary = NULL;
6548 compose->autowrap = prefs_common.autowrap;
6550 compose->use_signing = FALSE;
6551 compose->use_encryption = FALSE;
6552 compose->privacy_system = NULL;
6554 compose->modified = FALSE;
6556 compose->return_receipt = FALSE;
6558 compose->to_list = NULL;
6559 compose->newsgroup_list = NULL;
6561 compose->undostruct = undostruct;
6563 compose->sig_str = NULL;
6565 compose->exteditor_file = NULL;
6566 compose->exteditor_pid = -1;
6567 compose->exteditor_tag = -1;
6568 compose->draft_timeout_tag = -1;
6571 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6572 if (mode != COMPOSE_REDIRECT) {
6573 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6574 strcmp(prefs_common.dictionary, "")) {
6575 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6576 prefs_common.dictionary,
6577 prefs_common.alt_dictionary,
6578 conv_get_locale_charset_str(),
6579 prefs_common.misspelled_col,
6580 prefs_common.check_while_typing,
6581 prefs_common.recheck_when_changing_dict,
6582 prefs_common.use_alternate,
6583 prefs_common.use_both_dicts,
6584 GTK_TEXT_VIEW(text),
6585 GTK_WINDOW(compose->window),
6586 compose_spell_menu_changed,
6589 alertpanel_error(_("Spell checker could not "
6591 gtkaspell_checkers_strerror());
6592 gtkaspell_checkers_reset_error();
6594 if (!gtkaspell_set_sug_mode(gtkaspell,
6595 prefs_common.aspell_sugmode)) {
6596 debug_print("Aspell: could not set "
6597 "suggestion mode %s\n",
6598 gtkaspell_checkers_strerror());
6599 gtkaspell_checkers_reset_error();
6602 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6606 compose->gtkaspell = gtkaspell;
6607 compose_spell_menu_changed(compose);
6610 compose_select_account(compose, account, TRUE);
6612 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6613 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6614 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6616 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6617 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6619 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6620 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6622 menu_set_sensitive(ifactory, "/Options/Reply mode", compose->mode == COMPOSE_REPLY);
6624 if (account->protocol != A_NNTP)
6625 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry),
6626 prefs_common_translated_header_name("To:"));
6628 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry),
6629 prefs_common_translated_header_name("Newsgroups:"));
6631 addressbook_set_target_compose(compose);
6633 if (mode != COMPOSE_REDIRECT)
6634 compose_set_template_menu(compose);
6636 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6637 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6640 compose_list = g_list_append(compose_list, compose);
6642 if (!prefs_common.show_ruler)
6643 gtk_widget_hide(ruler_hbox);
6645 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6646 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6647 prefs_common.show_ruler);
6650 compose->priority = PRIORITY_NORMAL;
6651 compose_update_priority_menu_item(compose);
6653 compose_set_out_encoding(compose);
6656 compose_update_actions_menu(compose);
6658 /* Privacy Systems menu */
6659 compose_update_privacy_systems_menu(compose);
6661 activate_privacy_system(compose, account, TRUE);
6662 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6664 gtk_widget_realize(window);
6666 gtk_widget_show(window);
6668 maemo_window_full_screen_if_needed(GTK_WINDOW(window));
6669 maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
6676 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6681 GtkWidget *optmenubox;
6684 GtkWidget *from_name = NULL;
6686 gint num = 0, def_menu = 0;
6688 accounts = account_get_list();
6689 g_return_val_if_fail(accounts != NULL, NULL);
6691 optmenubox = gtk_event_box_new();
6692 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
6693 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
6695 hbox = gtk_hbox_new(FALSE, 6);
6696 from_name = gtk_entry_new();
6698 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6699 G_CALLBACK(compose_grab_focus_cb), compose);
6701 for (; accounts != NULL; accounts = accounts->next, num++) {
6702 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6703 gchar *name, *from = NULL;
6705 if (ac == compose->account) def_menu = num;
6707 name = g_markup_printf_escaped(_("From: <i>%s</i>"),
6710 if (ac == compose->account) {
6711 if (ac->name && *ac->name) {
6713 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6714 from = g_strdup_printf("%s <%s>",
6716 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6718 from = g_strdup_printf("%s",
6720 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6723 COMBOBOX_ADD(menu, name, ac->account_id);
6728 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
6730 g_signal_connect(G_OBJECT(optmenu), "changed",
6731 G_CALLBACK(account_activated),
6733 g_signal_connect(G_OBJECT(from_name), "populate-popup",
6734 G_CALLBACK(compose_entry_popup_extend),
6737 gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
6738 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6740 gtk_tooltips_set_tip(compose->tooltips, optmenubox,
6741 _("Account to use for this email"), NULL);
6742 gtk_tooltips_set_tip(compose->tooltips, from_name,
6743 _("Sender address to be used"), NULL);
6745 compose->from_name = from_name;
6750 static void compose_set_priority_cb(gpointer data,
6754 Compose *compose = (Compose *) data;
6755 compose->priority = action;
6758 static void compose_reply_change_mode(gpointer data,
6762 Compose *compose = (Compose *) data;
6763 gboolean was_modified = compose->modified;
6765 gboolean all = FALSE, ml = FALSE, sender = FALSE, followup = FALSE;
6767 g_return_if_fail(compose->replyinfo != NULL);
6769 if (action == COMPOSE_REPLY && prefs_common.default_reply_list)
6771 if (action == COMPOSE_REPLY && compose->rmode == COMPOSE_FOLLOWUP_AND_REPLY_TO)
6773 if (action == COMPOSE_REPLY_TO_ALL)
6775 if (action == COMPOSE_REPLY_TO_SENDER)
6777 if (action == COMPOSE_REPLY_TO_LIST)
6780 compose_remove_header_entries(compose);
6781 compose_reply_set_entry(compose, compose->replyinfo, all, ml, sender, followup);
6782 if (compose->account->set_autocc && compose->account->auto_cc)
6783 compose_entry_append(compose, compose->account->auto_cc, COMPOSE_CC);
6785 if (compose->account->set_autobcc && compose->account->auto_bcc)
6786 compose_entry_append(compose, compose->account->auto_bcc, COMPOSE_BCC);
6788 if (compose->account->set_autoreplyto && compose->account->auto_replyto)
6789 compose_entry_append(compose, compose->account->auto_replyto, COMPOSE_REPLYTO);
6790 compose_show_first_last_header(compose, TRUE);
6791 compose->modified = was_modified;
6792 compose_set_title(compose);
6795 static void compose_update_priority_menu_item(Compose * compose)
6797 GtkItemFactory *ifactory;
6798 GtkWidget *menuitem = NULL;
6800 ifactory = gtk_item_factory_from_widget(compose->menubar);
6802 switch (compose->priority) {
6803 case PRIORITY_HIGHEST:
6804 menuitem = gtk_item_factory_get_item
6805 (ifactory, "/Options/Priority/Highest");
6808 menuitem = gtk_item_factory_get_item
6809 (ifactory, "/Options/Priority/High");
6811 case PRIORITY_NORMAL:
6812 menuitem = gtk_item_factory_get_item
6813 (ifactory, "/Options/Priority/Normal");
6816 menuitem = gtk_item_factory_get_item
6817 (ifactory, "/Options/Priority/Low");
6819 case PRIORITY_LOWEST:
6820 menuitem = gtk_item_factory_get_item
6821 (ifactory, "/Options/Priority/Lowest");
6824 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6827 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6829 Compose *compose = (Compose *) data;
6831 GtkItemFactory *ifactory;
6832 gboolean can_sign = FALSE, can_encrypt = FALSE;
6834 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6836 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6839 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6840 g_free(compose->privacy_system);
6841 compose->privacy_system = NULL;
6842 if (systemid != NULL) {
6843 compose->privacy_system = g_strdup(systemid);
6845 can_sign = privacy_system_can_sign(systemid);
6846 can_encrypt = privacy_system_can_encrypt(systemid);
6849 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6851 ifactory = gtk_item_factory_from_widget(compose->menubar);
6852 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6853 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6856 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6858 static gchar *branch_path = "/Options/Privacy System";
6859 GtkItemFactory *ifactory;
6860 GtkWidget *menuitem = NULL;
6862 gboolean can_sign = FALSE, can_encrypt = FALSE;
6863 gboolean found = FALSE;
6865 ifactory = gtk_item_factory_from_widget(compose->menubar);
6867 if (compose->privacy_system != NULL) {
6870 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6871 g_return_if_fail(menuitem != NULL);
6873 amenu = GTK_MENU_SHELL(menuitem)->children;
6875 while (amenu != NULL) {
6876 GList *alist = amenu->next;
6878 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6879 if (systemid != NULL) {
6880 if (strcmp(systemid, compose->privacy_system) == 0) {
6881 menuitem = GTK_WIDGET(amenu->data);
6883 can_sign = privacy_system_can_sign(systemid);
6884 can_encrypt = privacy_system_can_encrypt(systemid);
6888 } else if (strlen(compose->privacy_system) == 0) {
6889 menuitem = GTK_WIDGET(amenu->data);
6892 can_encrypt = FALSE;
6899 if (menuitem != NULL)
6900 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6902 if (warn && !found && strlen(compose->privacy_system)) {
6903 gchar *tmp = g_strdup_printf(
6904 _("The privacy system '%s' cannot be loaded. You "
6905 "will not be able to sign or encrypt this message."),
6906 compose->privacy_system);
6907 alertpanel_warning(tmp);
6912 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6913 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6916 static void compose_set_out_encoding(Compose *compose)
6918 GtkItemFactoryEntry *entry;
6919 GtkItemFactory *ifactory;
6920 CharSet out_encoding;
6921 gchar *path, *p, *q;
6924 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6925 ifactory = gtk_item_factory_from_widget(compose->menubar);
6927 for (entry = compose_entries; entry->callback != compose_address_cb;
6929 if (entry->callback == compose_set_encoding_cb &&
6930 (CharSet)entry->callback_action == out_encoding) {
6931 p = q = path = g_strdup(entry->path);
6943 item = gtk_item_factory_get_item(ifactory, path);
6944 gtk_widget_activate(item);
6951 static void compose_set_template_menu(Compose *compose)
6953 GSList *tmpl_list, *cur;
6957 tmpl_list = template_get_config();
6959 menu = gtk_menu_new();
6961 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6962 Template *tmpl = (Template *)cur->data;
6964 item = gtk_menu_item_new_with_label(tmpl->name);
6965 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6966 g_signal_connect(G_OBJECT(item), "activate",
6967 G_CALLBACK(compose_template_activate_cb),
6969 g_object_set_data(G_OBJECT(item), "template", tmpl);
6970 gtk_widget_show(item);
6973 gtk_widget_show(menu);
6974 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6977 void compose_update_actions_menu(Compose *compose)
6979 GtkItemFactory *ifactory;
6981 ifactory = gtk_item_factory_from_widget(compose->menubar);
6982 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6985 static void compose_update_privacy_systems_menu(Compose *compose)
6987 static gchar *branch_path = "/Options/Privacy System";
6988 GtkItemFactory *ifactory;
6989 GtkWidget *menuitem;
6990 GSList *systems, *cur;
6993 GtkWidget *system_none;
6996 ifactory = gtk_item_factory_from_widget(compose->menubar);
6998 /* remove old entries */
6999 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
7000 g_return_if_fail(menuitem != NULL);
7002 amenu = GTK_MENU_SHELL(menuitem)->children->next;
7003 while (amenu != NULL) {
7004 GList *alist = amenu->next;
7005 gtk_widget_destroy(GTK_WIDGET(amenu->data));
7009 system_none = gtk_item_factory_get_widget(ifactory,
7010 "/Options/Privacy System/None");
7012 g_signal_connect(G_OBJECT(system_none), "activate",
7013 G_CALLBACK(compose_set_privacy_system_cb), compose);
7015 systems = privacy_get_system_ids();
7016 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
7017 gchar *systemid = cur->data;
7019 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
7020 widget = gtk_radio_menu_item_new_with_label(group,
7021 privacy_system_get_name(systemid));
7022 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
7023 g_strdup(systemid), g_free);
7024 g_signal_connect(G_OBJECT(widget), "activate",
7025 G_CALLBACK(compose_set_privacy_system_cb), compose);
7027 gtk_menu_append(GTK_MENU(system_none->parent), widget);
7028 gtk_widget_show(widget);
7031 g_slist_free(systems);
7034 void compose_reflect_prefs_all(void)
7039 for (cur = compose_list; cur != NULL; cur = cur->next) {
7040 compose = (Compose *)cur->data;
7041 compose_set_template_menu(compose);
7045 void compose_reflect_prefs_pixmap_theme(void)
7050 for (cur = compose_list; cur != NULL; cur = cur->next) {
7051 compose = (Compose *)cur->data;
7052 toolbar_update(TOOLBAR_COMPOSE, compose);
7056 static void compose_template_apply(Compose *compose, Template *tmpl,
7060 GtkTextBuffer *buffer;
7064 gchar *parsed_str = NULL;
7065 gint cursor_pos = 0;
7066 const gchar *err_msg = _("Template body format error.");
7069 /* process the body */
7071 text = GTK_TEXT_VIEW(compose->text);
7072 buffer = gtk_text_view_get_buffer(text);
7075 if (prefs_common.quotemark && *prefs_common.quotemark)
7076 qmark = prefs_common.quotemark;
7080 if (compose->replyinfo != NULL) {
7083 gtk_text_buffer_set_text(buffer, "", -1);
7084 mark = gtk_text_buffer_get_insert(buffer);
7085 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
7087 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
7088 tmpl->value, qmark, NULL, FALSE, FALSE, err_msg);
7090 } else if (compose->fwdinfo != NULL) {
7093 gtk_text_buffer_set_text(buffer, "", -1);
7094 mark = gtk_text_buffer_get_insert(buffer);
7095 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
7097 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
7098 tmpl->value, qmark, NULL, FALSE, FALSE, err_msg);
7101 MsgInfo* dummyinfo = compose_msginfo_new_from_compose(compose);
7103 GtkTextIter start, end;
7106 gtk_text_buffer_get_start_iter(buffer, &start);
7107 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
7108 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
7110 /* clear the buffer now */
7112 gtk_text_buffer_set_text(buffer, "", -1);
7114 parsed_str = compose_quote_fmt(compose, dummyinfo,
7115 tmpl->value, qmark, tmp, FALSE, FALSE, err_msg);
7116 procmsg_msginfo_free( dummyinfo );
7122 gtk_text_buffer_set_text(buffer, "", -1);
7123 mark = gtk_text_buffer_get_insert(buffer);
7124 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
7127 if (replace && parsed_str && compose->account->auto_sig)
7128 compose_insert_sig(compose, FALSE);
7130 if (replace && parsed_str) {
7131 gtk_text_buffer_get_start_iter(buffer, &iter);
7132 gtk_text_buffer_place_cursor(buffer, &iter);
7136 cursor_pos = quote_fmt_get_cursor_pos();
7137 compose->set_cursor_pos = cursor_pos;
7138 if (cursor_pos == -1)
7140 gtk_text_buffer_get_start_iter(buffer, &iter);
7141 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
7142 gtk_text_buffer_place_cursor(buffer, &iter);
7145 /* process the other fields */
7147 compose_template_apply_fields(compose, tmpl);
7148 quote_fmt_reset_vartable();
7149 compose_changed_cb(NULL, compose);
7152 static void compose_template_apply_fields(Compose *compose, Template *tmpl)
7154 MsgInfo* dummyinfo = NULL;
7155 MsgInfo *msginfo = NULL;
7158 if (compose->replyinfo != NULL)
7159 msginfo = compose->replyinfo;
7160 else if (compose->fwdinfo != NULL)
7161 msginfo = compose->fwdinfo;
7163 dummyinfo = compose_msginfo_new_from_compose(compose);
7164 msginfo = dummyinfo;
7167 if (tmpl->to && *tmpl->to != '\0') {
7169 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
7170 compose->gtkaspell);
7172 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
7174 quote_fmt_scan_string(tmpl->to);
7177 buf = quote_fmt_get_buffer();
7179 alertpanel_error(_("Template To format error."));
7181 compose_entry_append(compose, buf, COMPOSE_TO);
7185 if (tmpl->cc && *tmpl->cc != '\0') {
7187 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
7188 compose->gtkaspell);
7190 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
7192 quote_fmt_scan_string(tmpl->cc);
7195 buf = quote_fmt_get_buffer();
7197 alertpanel_error(_("Template Cc format error."));
7199 compose_entry_append(compose, buf, COMPOSE_CC);
7203 if (tmpl->bcc && *tmpl->bcc != '\0') {
7205 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
7206 compose->gtkaspell);
7208 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
7210 quote_fmt_scan_string(tmpl->bcc);
7213 buf = quote_fmt_get_buffer();
7215 alertpanel_error(_("Template Bcc format error."));
7217 compose_entry_append(compose, buf, COMPOSE_BCC);
7221 /* process the subject */
7222 if (tmpl->subject && *tmpl->subject != '\0') {
7224 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
7225 compose->gtkaspell);
7227 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
7229 quote_fmt_scan_string(tmpl->subject);
7232 buf = quote_fmt_get_buffer();
7234 alertpanel_error(_("Template subject format error."));
7236 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
7240 procmsg_msginfo_free( dummyinfo );
7243 static void compose_destroy(Compose *compose)
7245 GtkTextBuffer *buffer;
7246 GtkClipboard *clipboard;
7248 compose_list = g_list_remove(compose_list, compose);
7250 if (compose->updating) {
7251 debug_print("danger, not destroying anything now\n");
7252 compose->deferred_destroy = TRUE;
7255 /* NOTE: address_completion_end() does nothing with the window
7256 * however this may change. */
7257 address_completion_end(compose->window);
7259 slist_free_strings(compose->to_list);
7260 g_slist_free(compose->to_list);
7261 slist_free_strings(compose->newsgroup_list);
7262 g_slist_free(compose->newsgroup_list);
7263 slist_free_strings(compose->header_list);
7264 g_slist_free(compose->header_list);
7266 procmsg_msginfo_free(compose->targetinfo);
7267 procmsg_msginfo_free(compose->replyinfo);
7268 procmsg_msginfo_free(compose->fwdinfo);
7270 g_free(compose->replyto);
7271 g_free(compose->cc);
7272 g_free(compose->bcc);
7273 g_free(compose->newsgroups);
7274 g_free(compose->followup_to);
7276 g_free(compose->ml_post);
7278 g_free(compose->inreplyto);
7279 g_free(compose->references);
7280 g_free(compose->msgid);
7281 g_free(compose->boundary);
7283 g_free(compose->redirect_filename);
7284 if (compose->undostruct)
7285 undo_destroy(compose->undostruct);
7287 g_free(compose->sig_str);
7289 g_free(compose->exteditor_file);
7291 g_free(compose->orig_charset);
7293 g_free(compose->privacy_system);
7295 if (addressbook_get_target_compose() == compose)
7296 addressbook_set_target_compose(NULL);
7299 if (compose->gtkaspell) {
7300 gtkaspell_delete(compose->gtkaspell);
7301 compose->gtkaspell = NULL;
7305 prefs_common.compose_width = compose->scrolledwin->allocation.width;
7306 prefs_common.compose_height = compose->window->allocation.height;
7308 if (!gtk_widget_get_parent(compose->paned))
7309 gtk_widget_destroy(compose->paned);
7310 gtk_widget_destroy(compose->popupmenu);
7312 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
7313 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
7314 gtk_text_buffer_remove_selection_clipboard(buffer, clipboard);
7316 gtk_widget_destroy(compose->window);
7317 toolbar_destroy(compose->toolbar);
7318 g_free(compose->toolbar);
7319 g_mutex_free(compose->mutex);
7323 static void compose_attach_info_free(AttachInfo *ainfo)
7325 g_free(ainfo->file);
7326 g_free(ainfo->content_type);
7327 g_free(ainfo->name);
7331 static void compose_attach_remove_selected(Compose *compose)
7333 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
7334 GtkTreeSelection *selection;
7336 GtkTreeModel *model;
7338 selection = gtk_tree_view_get_selection(tree_view);
7339 sel = gtk_tree_selection_get_selected_rows(selection, &model);
7344 for (cur = sel; cur != NULL; cur = cur->next) {
7345 GtkTreePath *path = cur->data;
7346 GtkTreeRowReference *ref = gtk_tree_row_reference_new
7349 gtk_tree_path_free(path);
7352 for (cur = sel; cur != NULL; cur = cur->next) {
7353 GtkTreeRowReference *ref = cur->data;
7354 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
7357 if (gtk_tree_model_get_iter(model, &iter, path))
7358 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
7360 gtk_tree_path_free(path);
7361 gtk_tree_row_reference_free(ref);
7367 static struct _AttachProperty
7370 GtkWidget *mimetype_entry;
7371 GtkWidget *encoding_optmenu;
7372 GtkWidget *path_entry;
7373 GtkWidget *filename_entry;
7375 GtkWidget *cancel_btn;
7378 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
7380 gtk_tree_path_free((GtkTreePath *)ptr);
7383 static void compose_attach_property(Compose *compose)
7385 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
7387 GtkComboBox *optmenu;
7388 GtkTreeSelection *selection;
7390 GtkTreeModel *model;
7393 static gboolean cancelled;
7395 /* only if one selected */
7396 selection = gtk_tree_view_get_selection(tree_view);
7397 if (gtk_tree_selection_count_selected_rows(selection) != 1)
7400 sel = gtk_tree_selection_get_selected_rows(selection, &model);
7404 path = (GtkTreePath *) sel->data;
7405 gtk_tree_model_get_iter(model, &iter, path);
7406 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
7409 g_list_foreach(sel, gtk_tree_path_free_, NULL);
7415 if (!attach_prop.window)
7416 compose_attach_property_create(&cancelled);
7417 gtk_widget_grab_focus(attach_prop.ok_btn);
7418 gtk_widget_show(attach_prop.window);
7419 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
7421 optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
7422 if (ainfo->encoding == ENC_UNKNOWN)
7423 combobox_select_by_data(optmenu, ENC_BASE64);
7425 combobox_select_by_data(optmenu, ainfo->encoding);
7427 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
7428 ainfo->content_type ? ainfo->content_type : "");
7429 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
7430 ainfo->file ? ainfo->file : "");
7431 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
7432 ainfo->name ? ainfo->name : "");
7435 const gchar *entry_text;
7437 gchar *cnttype = NULL;
7444 gtk_widget_hide(attach_prop.window);
7449 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
7450 if (*entry_text != '\0') {
7453 text = g_strstrip(g_strdup(entry_text));
7454 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
7455 cnttype = g_strdup(text);
7458 alertpanel_error(_("Invalid MIME type."));
7464 ainfo->encoding = combobox_get_active_data(optmenu);
7466 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
7467 if (*entry_text != '\0') {
7468 if (is_file_exist(entry_text) &&
7469 (size = get_file_size(entry_text)) > 0)
7470 file = g_strdup(entry_text);
7473 (_("File doesn't exist or is empty."));
7479 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
7480 if (*entry_text != '\0') {
7481 g_free(ainfo->name);
7482 ainfo->name = g_strdup(entry_text);
7486 g_free(ainfo->content_type);
7487 ainfo->content_type = cnttype;
7490 g_free(ainfo->file);
7496 /* update tree store */
7497 text = to_human_readable(ainfo->size);
7498 gtk_tree_model_get_iter(model, &iter, path);
7499 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
7500 COL_MIMETYPE, ainfo->content_type,
7502 COL_NAME, ainfo->name,
7508 gtk_tree_path_free(path);
7511 #define SET_LABEL_AND_ENTRY(str, entry, top) \
7513 label = gtk_label_new(str); \
7514 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
7515 GTK_FILL, 0, 0, 0); \
7516 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
7518 entry = gtk_entry_new(); \
7519 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
7520 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
7523 static void compose_attach_property_create(gboolean *cancelled)
7529 GtkWidget *mimetype_entry;
7532 GtkListStore *optmenu_menu;
7533 GtkWidget *path_entry;
7534 GtkWidget *filename_entry;
7537 GtkWidget *cancel_btn;
7538 GList *mime_type_list, *strlist;
7541 debug_print("Creating attach_property window...\n");
7543 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose_attach_property");
7544 gtk_widget_set_size_request(window, 480, -1);
7545 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
7546 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
7547 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
7548 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
7549 g_signal_connect(G_OBJECT(window), "delete_event",
7550 G_CALLBACK(attach_property_delete_event),
7552 g_signal_connect(G_OBJECT(window), "key_press_event",
7553 G_CALLBACK(attach_property_key_pressed),
7556 vbox = gtk_vbox_new(FALSE, 8);
7557 gtk_container_add(GTK_CONTAINER(window), vbox);
7559 table = gtk_table_new(4, 2, FALSE);
7560 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
7561 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
7562 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
7564 label = gtk_label_new(_("MIME type"));
7565 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
7567 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7568 mimetype_entry = gtk_combo_new();
7569 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
7570 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7572 /* stuff with list */
7573 mime_type_list = procmime_get_mime_type_list();
7575 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
7576 MimeType *type = (MimeType *) mime_type_list->data;
7579 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
7581 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
7584 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
7585 (GCompareFunc)strcmp2);
7588 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
7590 for (mime_type_list = strlist; mime_type_list != NULL;
7591 mime_type_list = mime_type_list->next)
7592 g_free(mime_type_list->data);
7593 g_list_free(strlist);
7595 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
7597 label = gtk_label_new(_("Encoding"));
7598 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
7600 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7602 hbox = gtk_hbox_new(FALSE, 0);
7603 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
7604 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7606 optmenu = gtkut_sc_combobox_create(NULL, TRUE);
7607 optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
7609 COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
7610 COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
7611 COMBOBOX_ADD(optmenu_menu, "quoted-printable", ENC_QUOTED_PRINTABLE);
7612 COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
7613 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
7615 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
7617 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
7618 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
7620 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
7621 &ok_btn, GTK_STOCK_OK,
7623 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
7624 gtk_widget_grab_default(ok_btn);
7626 g_signal_connect(G_OBJECT(ok_btn), "clicked",
7627 G_CALLBACK(attach_property_ok),
7629 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
7630 G_CALLBACK(attach_property_cancel),
7633 gtk_widget_show_all(vbox);
7635 attach_prop.window = window;
7636 attach_prop.mimetype_entry = mimetype_entry;
7637 attach_prop.encoding_optmenu = optmenu;
7638 attach_prop.path_entry = path_entry;
7639 attach_prop.filename_entry = filename_entry;
7640 attach_prop.ok_btn = ok_btn;
7641 attach_prop.cancel_btn = cancel_btn;
7644 #undef SET_LABEL_AND_ENTRY
7646 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7652 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7658 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7659 gboolean *cancelled)
7667 static gboolean attach_property_key_pressed(GtkWidget *widget,
7669 gboolean *cancelled)
7671 if (event && event->keyval == GDK_Escape) {
7678 static void compose_exec_ext_editor(Compose *compose)
7685 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7686 G_DIR_SEPARATOR, compose);
7688 if (pipe(pipe_fds) < 0) {
7694 if ((pid = fork()) < 0) {
7701 /* close the write side of the pipe */
7704 compose->exteditor_file = g_strdup(tmp);
7705 compose->exteditor_pid = pid;
7707 compose_set_ext_editor_sensitive(compose, FALSE);
7709 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7710 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7714 } else { /* process-monitoring process */
7720 /* close the read side of the pipe */
7723 if (compose_write_body_to_file(compose, tmp) < 0) {
7724 fd_write_all(pipe_fds[1], "2\n", 2);
7728 pid_ed = compose_exec_ext_editor_real(tmp);
7730 fd_write_all(pipe_fds[1], "1\n", 2);
7734 /* wait until editor is terminated */
7735 waitpid(pid_ed, NULL, 0);
7737 fd_write_all(pipe_fds[1], "0\n", 2);
7744 #endif /* G_OS_UNIX */
7748 static gint compose_exec_ext_editor_real(const gchar *file)
7755 g_return_val_if_fail(file != NULL, -1);
7757 if ((pid = fork()) < 0) {
7762 if (pid != 0) return pid;
7764 /* grandchild process */
7766 if (setpgid(0, getppid()))
7769 if (prefs_common.ext_editor_cmd &&
7770 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7771 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7772 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7774 if (prefs_common.ext_editor_cmd)
7775 g_warning("External editor command line is invalid: '%s'\n",
7776 prefs_common.ext_editor_cmd);
7777 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7780 cmdline = strsplit_with_quote(buf, " ", 1024);
7781 execvp(cmdline[0], cmdline);
7784 g_strfreev(cmdline);
7789 static gboolean compose_ext_editor_kill(Compose *compose)
7791 pid_t pgid = compose->exteditor_pid * -1;
7794 ret = kill(pgid, 0);
7796 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7800 msg = g_strdup_printf
7801 (_("The external editor is still working.\n"
7802 "Force terminating the process?\n"
7803 "process group id: %d"), -pgid);
7804 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7805 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7809 if (val == G_ALERTALTERNATE) {
7810 g_source_remove(compose->exteditor_tag);
7811 g_io_channel_shutdown(compose->exteditor_ch,
7813 g_io_channel_unref(compose->exteditor_ch);
7815 if (kill(pgid, SIGTERM) < 0) perror("kill");
7816 waitpid(compose->exteditor_pid, NULL, 0);
7818 g_warning("Terminated process group id: %d", -pgid);
7819 g_warning("Temporary file: %s",
7820 compose->exteditor_file);
7822 compose_set_ext_editor_sensitive(compose, TRUE);
7824 g_free(compose->exteditor_file);
7825 compose->exteditor_file = NULL;
7826 compose->exteditor_pid = -1;
7827 compose->exteditor_ch = NULL;
7828 compose->exteditor_tag = -1;
7836 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7840 Compose *compose = (Compose *)data;
7843 debug_print(_("Compose: input from monitoring process\n"));
7845 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7847 g_io_channel_shutdown(source, FALSE, NULL);
7848 g_io_channel_unref(source);
7850 waitpid(compose->exteditor_pid, NULL, 0);
7852 if (buf[0] == '0') { /* success */
7853 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7854 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7856 gtk_text_buffer_set_text(buffer, "", -1);
7857 compose_insert_file(compose, compose->exteditor_file);
7858 compose_changed_cb(NULL, compose);
7860 if (g_unlink(compose->exteditor_file) < 0)
7861 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7862 } else if (buf[0] == '1') { /* failed */
7863 g_warning("Couldn't exec external editor\n");
7864 if (g_unlink(compose->exteditor_file) < 0)
7865 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7866 } else if (buf[0] == '2') {
7867 g_warning("Couldn't write to file\n");
7868 } else if (buf[0] == '3') {
7869 g_warning("Pipe read failed\n");
7872 compose_set_ext_editor_sensitive(compose, TRUE);
7874 g_free(compose->exteditor_file);
7875 compose->exteditor_file = NULL;
7876 compose->exteditor_pid = -1;
7877 compose->exteditor_ch = NULL;
7878 compose->exteditor_tag = -1;
7883 static void compose_set_ext_editor_sensitive(Compose *compose,
7886 GtkItemFactory *ifactory;
7888 ifactory = gtk_item_factory_from_widget(compose->menubar);
7890 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7891 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7892 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7893 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7894 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7895 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7896 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7899 gtk_widget_set_sensitive(compose->text, sensitive);
7900 if (compose->toolbar->send_btn)
7901 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7902 if (compose->toolbar->sendl_btn)
7903 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7904 if (compose->toolbar->draft_btn)
7905 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7906 if (compose->toolbar->insert_btn)
7907 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7908 if (compose->toolbar->sig_btn)
7909 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7910 if (compose->toolbar->exteditor_btn)
7911 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7912 if (compose->toolbar->linewrap_current_btn)
7913 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7914 if (compose->toolbar->linewrap_all_btn)
7915 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7917 #endif /* G_OS_UNIX */
7920 * compose_undo_state_changed:
7922 * Change the sensivity of the menuentries undo and redo
7924 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7925 gint redo_state, gpointer data)
7927 GtkWidget *widget = GTK_WIDGET(data);
7928 GtkItemFactory *ifactory;
7930 g_return_if_fail(widget != NULL);
7932 ifactory = gtk_item_factory_from_widget(widget);
7934 switch (undo_state) {
7935 case UNDO_STATE_TRUE:
7936 if (!undostruct->undo_state) {
7937 undostruct->undo_state = TRUE;
7938 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7941 case UNDO_STATE_FALSE:
7942 if (undostruct->undo_state) {
7943 undostruct->undo_state = FALSE;
7944 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7947 case UNDO_STATE_UNCHANGED:
7949 case UNDO_STATE_REFRESH:
7950 menu_set_sensitive(ifactory, "/Edit/Undo",
7951 undostruct->undo_state);
7954 g_warning("Undo state not recognized");
7958 switch (redo_state) {
7959 case UNDO_STATE_TRUE:
7960 if (!undostruct->redo_state) {
7961 undostruct->redo_state = TRUE;
7962 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7965 case UNDO_STATE_FALSE:
7966 if (undostruct->redo_state) {
7967 undostruct->redo_state = FALSE;
7968 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7971 case UNDO_STATE_UNCHANGED:
7973 case UNDO_STATE_REFRESH:
7974 menu_set_sensitive(ifactory, "/Edit/Redo",
7975 undostruct->redo_state);
7978 g_warning("Redo state not recognized");
7983 /* callback functions */
7985 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7986 * includes "non-client" (windows-izm) in calculation, so this calculation
7987 * may not be accurate.
7989 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7990 GtkAllocation *allocation,
7991 GtkSHRuler *shruler)
7993 if (prefs_common.show_ruler) {
7994 gint char_width = 0, char_height = 0;
7995 gint line_width_in_chars;
7997 gtkut_get_font_size(GTK_WIDGET(widget),
7998 &char_width, &char_height);
7999 line_width_in_chars =
8000 (allocation->width - allocation->x) / char_width;
8002 /* got the maximum */
8003 gtk_ruler_set_range(GTK_RULER(shruler),
8004 0.0, line_width_in_chars, 0,
8005 /*line_width_in_chars*/ char_width);
8011 static void account_activated(GtkComboBox *optmenu, gpointer data)
8013 Compose *compose = (Compose *)data;
8016 gchar *folderidentifier;
8017 gint account_id = 0;
8021 /* Get ID of active account in the combo box */
8022 menu = gtk_combo_box_get_model(optmenu);
8023 gtk_combo_box_get_active_iter(optmenu, &iter);
8024 gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
8026 ac = account_find_from_id(account_id);
8027 g_return_if_fail(ac != NULL);
8029 if (ac != compose->account)
8030 compose_select_account(compose, ac, FALSE);
8032 /* Set message save folder */
8033 if (account_get_special_folder(compose->account, F_OUTBOX)) {
8034 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
8036 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
8037 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
8039 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
8040 if (account_get_special_folder(compose->account, F_OUTBOX)) {
8041 folderidentifier = folder_item_get_identifier(account_get_special_folder
8042 (compose->account, F_OUTBOX));
8043 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
8044 g_free(folderidentifier);
8048 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
8049 GtkTreeViewColumn *column, Compose *compose)
8051 compose_attach_property(compose);
8054 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
8057 Compose *compose = (Compose *)data;
8058 GtkTreeSelection *attach_selection;
8059 gint attach_nr_selected;
8060 GtkItemFactory *ifactory;
8062 if (!event) return FALSE;
8064 if (event->button == 3) {
8065 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
8066 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
8067 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8069 if (attach_nr_selected > 0)
8071 menu_set_sensitive(ifactory, "/Remove", TRUE);
8072 menu_set_sensitive(ifactory, "/Properties...", TRUE);
8074 menu_set_sensitive(ifactory, "/Remove", FALSE);
8075 menu_set_sensitive(ifactory, "/Properties...", FALSE);
8078 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
8079 NULL, NULL, event->button, event->time);
8086 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
8089 Compose *compose = (Compose *)data;
8091 if (!event) return FALSE;
8093 switch (event->keyval) {
8095 compose_attach_remove_selected(compose);
8101 static void compose_allow_user_actions (Compose *compose, gboolean allow)
8103 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
8104 toolbar_comp_set_sensitive(compose, allow);
8105 menu_set_sensitive(ifactory, "/Message", allow);
8106 menu_set_sensitive(ifactory, "/Edit", allow);
8108 menu_set_sensitive(ifactory, "/Spelling", allow);
8110 menu_set_sensitive(ifactory, "/Options", allow);
8111 menu_set_sensitive(ifactory, "/Tools", allow);
8112 menu_set_sensitive(ifactory, "/Help", allow);
8114 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
8118 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
8120 Compose *compose = (Compose *)data;
8122 if (prefs_common.work_offline &&
8123 !inc_offline_should_override(TRUE,
8124 _("Claws Mail needs network access in order "
8125 "to send this email.")))
8128 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
8129 g_source_remove(compose->draft_timeout_tag);
8130 compose->draft_timeout_tag = -1;
8133 compose_send(compose);
8136 static void compose_send_later_cb(gpointer data, guint action,
8139 Compose *compose = (Compose *)data;
8143 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
8147 compose_close(compose);
8148 } else if (val == -1) {
8149 alertpanel_error(_("Could not queue message."));
8150 } else if (val == -2) {
8151 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
8152 } else if (val == -3) {
8153 if (privacy_peek_error())
8154 alertpanel_error(_("Could not queue message for sending:\n\n"
8155 "Signature failed: %s"), privacy_get_error());
8156 } else if (val == -4) {
8157 alertpanel_error(_("Could not queue message for sending:\n\n"
8158 "Charset conversion failed."));
8159 } else if (val == -5) {
8160 alertpanel_error(_("Could not queue message for sending:\n\n"
8161 "Couldn't get recipient encryption key."));
8162 } else if (val == -6) {
8165 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
8168 void compose_draft (gpointer data, guint action)
8170 compose_draft_cb(data, action, NULL);
8173 #define DRAFTED_AT_EXIT "drafted_at_exit"
8174 void compose_clear_exit_drafts(void)
8176 gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
8177 DRAFTED_AT_EXIT, NULL);
8178 if (is_file_exist(filepath))
8184 static void compose_register_draft(MsgInfo *info)
8186 gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
8187 DRAFTED_AT_EXIT, NULL);
8188 FILE *fp = fopen(filepath, "ab");
8191 fprintf(fp, "%s\t%d\n", folder_item_get_identifier(info->folder),
8199 void compose_reopen_exit_drafts(void)
8201 gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
8202 DRAFTED_AT_EXIT, NULL);
8203 FILE *fp = fopen(filepath, "rb");
8207 while (fgets(buf, sizeof(buf), fp)) {
8208 gchar **parts = g_strsplit(buf, "\t", 2);
8209 const gchar *folder = parts[0];
8210 int msgnum = parts[1] ? atoi(parts[1]):-1;
8212 if (folder && *folder && msgnum > -1) {
8213 FolderItem *item = folder_find_item_from_identifier(folder);
8214 MsgInfo *info = folder_item_get_msginfo(item, msgnum);
8216 compose_reedit(info, FALSE);
8223 compose_clear_exit_drafts();
8226 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
8228 Compose *compose = (Compose *)data;
8232 MsgFlags flag = {0, 0};
8233 static gboolean lock = FALSE;
8234 MsgInfo *newmsginfo;
8236 gboolean target_locked = FALSE;
8240 draft = account_get_special_folder(compose->account, F_DRAFT);
8241 g_return_if_fail(draft != NULL);
8243 if (!g_mutex_trylock(compose->mutex)) {
8244 /* we don't want to lock the mutex once it's available,
8245 * because as the only other part of compose.c locking
8246 * it is compose_close - which means once unlocked,
8247 * the compose struct will be freed */
8248 debug_print("couldn't lock mutex, probably sending\n");
8254 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
8255 G_DIR_SEPARATOR, compose);
8256 if ((fp = g_fopen(tmp, "wb")) == NULL) {
8257 FILE_OP_ERROR(tmp, "fopen");
8261 /* chmod for security */
8262 if (change_file_mode_rw(fp, tmp) < 0) {
8263 FILE_OP_ERROR(tmp, "chmod");
8264 g_warning("can't change file mode\n");
8267 /* Save draft infos */
8268 fprintf(fp, "X-Claws-Account-Id:%d\n", compose->account->account_id);
8269 fprintf(fp, "S:%s\n", compose->account->address);
8271 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
8272 gchar *savefolderid;
8274 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
8275 fprintf(fp, "SCF:%s\n", savefolderid);
8276 g_free(savefolderid);
8278 if (compose->return_receipt) {
8279 fprintf(fp, "RRCPT:1\n");
8281 if (compose->privacy_system) {
8282 fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing);
8283 fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
8284 fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system);
8287 /* Message-ID of message replying to */
8288 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
8291 folderid = folder_item_get_identifier(compose->replyinfo->folder);
8292 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
8295 /* Message-ID of message forwarding to */
8296 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
8299 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
8300 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
8304 /* end of headers */
8305 fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
8307 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
8315 if (compose->targetinfo) {
8316 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
8317 flag.perm_flags = target_locked?MSG_LOCKED:0;
8319 flag.tmp_flags = MSG_DRAFT;
8321 folder_item_scan(draft);
8322 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
8325 if (action != COMPOSE_AUTO_SAVE)
8326 alertpanel_error(_("Could not save draft."));
8331 if (compose->mode == COMPOSE_REEDIT) {
8332 compose_remove_reedit_target(compose, TRUE);
8335 newmsginfo = folder_item_get_msginfo(draft, msgnum);
8337 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
8339 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
8341 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
8342 if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
8343 procmsg_msginfo_set_flags(newmsginfo, 0,
8344 MSG_HAS_ATTACHMENT);
8346 if (action == COMPOSE_DRAFT_FOR_EXIT) {
8347 compose_register_draft(newmsginfo);
8349 procmsg_msginfo_free(newmsginfo);
8352 folder_item_scan(draft);
8354 if (action == COMPOSE_QUIT_EDITING || action == COMPOSE_DRAFT_FOR_EXIT) {
8356 g_mutex_unlock(compose->mutex); /* must be done before closing */
8357 compose_close(compose);
8363 path = folder_item_fetch_msg(draft, msgnum);
8365 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
8368 if (g_stat(path, &s) < 0) {
8369 FILE_OP_ERROR(path, "stat");
8375 procmsg_msginfo_free(compose->targetinfo);
8376 compose->targetinfo = procmsg_msginfo_new();
8377 compose->targetinfo->msgnum = msgnum;
8378 compose->targetinfo->size = s.st_size;
8379 compose->targetinfo->mtime = s.st_mtime;
8380 compose->targetinfo->folder = draft;
8382 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
8383 compose->mode = COMPOSE_REEDIT;
8385 if (action == COMPOSE_AUTO_SAVE) {
8386 compose->autosaved_draft = compose->targetinfo;
8388 compose->modified = FALSE;
8389 compose_set_title(compose);
8393 g_mutex_unlock(compose->mutex);
8396 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
8398 Compose *compose = (Compose *)data;
8401 if (compose->redirect_filename != NULL)
8404 file_list = filesel_select_multiple_files_open(_("Select file"));
8409 for ( tmp = file_list; tmp; tmp = tmp->next) {
8410 gchar *file = (gchar *) tmp->data;
8411 gchar *utf8_filename = conv_filename_to_utf8(file);
8412 compose_attach_append(compose, file, utf8_filename, NULL);
8413 compose_changed_cb(NULL, compose);
8415 g_free(utf8_filename);
8417 g_list_free(file_list);
8421 static void compose_insert_file_cb(gpointer data, guint action,
8424 Compose *compose = (Compose *)data;
8427 file_list = filesel_select_multiple_files_open(_("Select file"));
8432 for ( tmp = file_list; tmp; tmp = tmp->next) {
8433 gchar *file = (gchar *) tmp->data;
8434 gchar *filedup = g_strdup(file);
8435 gchar *shortfile = g_path_get_basename(filedup);
8436 ComposeInsertResult res;
8438 res = compose_insert_file(compose, file);
8439 if (res == COMPOSE_INSERT_READ_ERROR) {
8440 alertpanel_error(_("File '%s' could not be read."), shortfile);
8441 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
8442 alertpanel_error(_("File '%s' contained invalid characters\n"
8443 "for the current encoding, insertion may be incorrect."), shortfile);
8449 g_list_free(file_list);
8453 static void compose_insert_sig_cb(gpointer data, guint action,
8456 Compose *compose = (Compose *)data;
8458 compose_insert_sig(compose, FALSE);
8461 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
8465 Compose *compose = (Compose *)data;
8467 gtkut_widget_get_uposition(widget, &x, &y);
8468 prefs_common.compose_x = x;
8469 prefs_common.compose_y = y;
8471 if (compose->sending || compose->updating)
8473 compose_close_cb(compose, 0, NULL);
8477 void compose_close_toolbar(Compose *compose)
8479 compose_close_cb(compose, 0, NULL);
8482 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
8484 Compose *compose = (Compose *)data;
8488 if (compose->exteditor_tag != -1) {
8489 if (!compose_ext_editor_kill(compose))
8494 if (compose->modified) {
8495 val = alertpanel(_("Discard message"),
8496 _("This message has been modified. Discard it?"),
8497 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
8500 case G_ALERTDEFAULT:
8501 if (prefs_common.autosave)
8502 compose_remove_draft(compose);
8504 case G_ALERTALTERNATE:
8505 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
8512 compose_close(compose);
8515 static void compose_set_encoding_cb(gpointer data, guint action,
8518 Compose *compose = (Compose *)data;
8520 if (GTK_CHECK_MENU_ITEM(widget)->active)
8521 compose->out_encoding = (CharSet)action;
8524 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
8526 Compose *compose = (Compose *)data;
8528 addressbook_open(compose);
8531 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
8533 Compose *compose = (Compose *)data;
8538 tmpl = g_object_get_data(G_OBJECT(widget), "template");
8539 g_return_if_fail(tmpl != NULL);
8541 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
8543 val = alertpanel(_("Apply template"), msg,
8544 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
8547 if (val == G_ALERTDEFAULT)
8548 compose_template_apply(compose, tmpl, TRUE);
8549 else if (val == G_ALERTALTERNATE)
8550 compose_template_apply(compose, tmpl, FALSE);
8553 static void compose_ext_editor_cb(gpointer data, guint action,
8556 Compose *compose = (Compose *)data;
8558 compose_exec_ext_editor(compose);
8561 static void compose_undo_cb(Compose *compose)
8563 gboolean prev_autowrap = compose->autowrap;
8565 compose->autowrap = FALSE;
8566 undo_undo(compose->undostruct);
8567 compose->autowrap = prev_autowrap;
8570 static void compose_redo_cb(Compose *compose)
8572 gboolean prev_autowrap = compose->autowrap;
8574 compose->autowrap = FALSE;
8575 undo_redo(compose->undostruct);
8576 compose->autowrap = prev_autowrap;
8579 static void entry_cut_clipboard(GtkWidget *entry)
8581 if (GTK_IS_EDITABLE(entry))
8582 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
8583 else if (GTK_IS_TEXT_VIEW(entry))
8584 gtk_text_buffer_cut_clipboard(
8585 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
8586 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
8590 static void entry_copy_clipboard(GtkWidget *entry)
8592 if (GTK_IS_EDITABLE(entry))
8593 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
8594 else if (GTK_IS_TEXT_VIEW(entry))
8595 gtk_text_buffer_copy_clipboard(
8596 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
8597 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
8600 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
8601 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
8603 if (GTK_IS_TEXT_VIEW(entry)) {
8604 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
8605 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
8606 GtkTextIter start_iter, end_iter;
8608 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
8610 if (contents == NULL)
8613 undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);
8615 /* we shouldn't delete the selection when middle-click-pasting, or we
8616 * can't mid-click-paste our own selection */
8617 if (clip != GDK_SELECTION_PRIMARY) {
8618 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
8621 if (insert_place == NULL) {
8622 /* if insert_place isn't specified, insert at the cursor.
8623 * used for Ctrl-V pasting */
8624 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
8625 start = gtk_text_iter_get_offset(&start_iter);
8626 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
8628 /* if insert_place is specified, paste here.
8629 * used for mid-click-pasting */
8630 start = gtk_text_iter_get_offset(insert_place);
8631 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
8635 /* paste unwrapped: mark the paste so it's not wrapped later */
8636 end = start + strlen(contents);
8637 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
8638 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
8639 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
8640 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
8641 /* rewrap paragraph now (after a mid-click-paste) */
8642 mark_start = gtk_text_buffer_get_insert(buffer);
8643 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
8644 gtk_text_iter_backward_char(&start_iter);
8645 compose_beautify_paragraph(compose, &start_iter, TRUE);
8647 } else if (GTK_IS_EDITABLE(entry))
8648 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
8652 static void entry_allsel(GtkWidget *entry)
8654 if (GTK_IS_EDITABLE(entry))
8655 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
8656 else if (GTK_IS_TEXT_VIEW(entry)) {
8657 GtkTextIter startiter, enditer;
8658 GtkTextBuffer *textbuf;
8660 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
8661 gtk_text_buffer_get_start_iter(textbuf, &startiter);
8662 gtk_text_buffer_get_end_iter(textbuf, &enditer);
8664 gtk_text_buffer_move_mark_by_name(textbuf,
8665 "selection_bound", &startiter);
8666 gtk_text_buffer_move_mark_by_name(textbuf,
8667 "insert", &enditer);
8671 static void compose_cut_cb(Compose *compose)
8673 if (compose->focused_editable
8675 && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
8678 entry_cut_clipboard(compose->focused_editable);
8681 static void compose_copy_cb(Compose *compose)
8683 if (compose->focused_editable
8685 && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
8688 entry_copy_clipboard(compose->focused_editable);
8691 static void compose_paste_cb(Compose *compose)
8694 GtkTextBuffer *buffer;
8696 if (compose->focused_editable &&
8697 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8698 entry_paste_clipboard(compose, compose->focused_editable,
8699 prefs_common.linewrap_pastes,
8700 GDK_SELECTION_CLIPBOARD, NULL);
8704 static void compose_paste_as_quote_cb(Compose *compose)
8706 gint wrap_quote = prefs_common.linewrap_quote;
8707 if (compose->focused_editable
8709 && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
8712 /* let text_insert() (called directly or at a later time
8713 * after the gtk_editable_paste_clipboard) know that
8714 * text is to be inserted as a quotation. implemented
8715 * by using a simple refcount... */
8716 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
8717 G_OBJECT(compose->focused_editable),
8718 "paste_as_quotation"));
8719 g_object_set_data(G_OBJECT(compose->focused_editable),
8720 "paste_as_quotation",
8721 GINT_TO_POINTER(paste_as_quotation + 1));
8722 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
8723 entry_paste_clipboard(compose, compose->focused_editable,
8724 prefs_common.linewrap_pastes,
8725 GDK_SELECTION_CLIPBOARD, NULL);
8726 prefs_common.linewrap_quote = wrap_quote;
8730 static void compose_paste_no_wrap_cb(Compose *compose)
8733 GtkTextBuffer *buffer;
8735 if (compose->focused_editable
8737 && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
8740 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
8741 GDK_SELECTION_CLIPBOARD, NULL);
8745 static void compose_paste_wrap_cb(Compose *compose)
8748 GtkTextBuffer *buffer;
8750 if (compose->focused_editable
8752 && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
8755 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
8756 GDK_SELECTION_CLIPBOARD, NULL);
8760 static void compose_allsel_cb(Compose *compose)
8762 if (compose->focused_editable
8764 && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
8767 entry_allsel(compose->focused_editable);
8770 static void textview_move_beginning_of_line (GtkTextView *text)
8772 GtkTextBuffer *buffer;
8776 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8778 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8779 mark = gtk_text_buffer_get_insert(buffer);
8780 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8781 gtk_text_iter_set_line_offset(&ins, 0);
8782 gtk_text_buffer_place_cursor(buffer, &ins);
8785 static void textview_move_forward_character (GtkTextView *text)
8787 GtkTextBuffer *buffer;
8791 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8793 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8794 mark = gtk_text_buffer_get_insert(buffer);
8795 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8796 if (gtk_text_iter_forward_cursor_position(&ins))
8797 gtk_text_buffer_place_cursor(buffer, &ins);
8800 static void textview_move_backward_character (GtkTextView *text)
8802 GtkTextBuffer *buffer;
8806 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8808 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8809 mark = gtk_text_buffer_get_insert(buffer);
8810 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8811 if (gtk_text_iter_backward_cursor_position(&ins))
8812 gtk_text_buffer_place_cursor(buffer, &ins);
8815 static void textview_move_forward_word (GtkTextView *text)
8817 GtkTextBuffer *buffer;
8822 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8824 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8825 mark = gtk_text_buffer_get_insert(buffer);
8826 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8827 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8828 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8829 gtk_text_iter_backward_word_start(&ins);
8830 gtk_text_buffer_place_cursor(buffer, &ins);
8834 static void textview_move_backward_word (GtkTextView *text)
8836 GtkTextBuffer *buffer;
8841 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8843 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8844 mark = gtk_text_buffer_get_insert(buffer);
8845 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8846 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8847 if (gtk_text_iter_backward_word_starts(&ins, 1))
8848 gtk_text_buffer_place_cursor(buffer, &ins);
8851 static void textview_move_end_of_line (GtkTextView *text)
8853 GtkTextBuffer *buffer;
8857 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8859 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8860 mark = gtk_text_buffer_get_insert(buffer);
8861 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8862 if (gtk_text_iter_forward_to_line_end(&ins))
8863 gtk_text_buffer_place_cursor(buffer, &ins);
8866 static void textview_move_next_line (GtkTextView *text)
8868 GtkTextBuffer *buffer;
8873 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8875 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8876 mark = gtk_text_buffer_get_insert(buffer);
8877 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8878 offset = gtk_text_iter_get_line_offset(&ins);
8879 if (gtk_text_iter_forward_line(&ins)) {
8880 gtk_text_iter_set_line_offset(&ins, offset);
8881 gtk_text_buffer_place_cursor(buffer, &ins);
8885 static void textview_move_previous_line (GtkTextView *text)
8887 GtkTextBuffer *buffer;
8892 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8894 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8895 mark = gtk_text_buffer_get_insert(buffer);
8896 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8897 offset = gtk_text_iter_get_line_offset(&ins);
8898 if (gtk_text_iter_backward_line(&ins)) {
8899 gtk_text_iter_set_line_offset(&ins, offset);
8900 gtk_text_buffer_place_cursor(buffer, &ins);
8904 static void textview_delete_forward_character (GtkTextView *text)
8906 GtkTextBuffer *buffer;
8908 GtkTextIter ins, end_iter;
8910 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8912 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8913 mark = gtk_text_buffer_get_insert(buffer);
8914 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8916 if (gtk_text_iter_forward_char(&end_iter)) {
8917 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8921 static void textview_delete_backward_character (GtkTextView *text)
8923 GtkTextBuffer *buffer;
8925 GtkTextIter ins, end_iter;
8927 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8929 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8930 mark = gtk_text_buffer_get_insert(buffer);
8931 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8933 if (gtk_text_iter_backward_char(&end_iter)) {
8934 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8938 static void textview_delete_forward_word (GtkTextView *text)
8940 GtkTextBuffer *buffer;
8942 GtkTextIter ins, end_iter;
8944 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8946 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8947 mark = gtk_text_buffer_get_insert(buffer);
8948 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8950 if (gtk_text_iter_forward_word_end(&end_iter)) {
8951 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8955 static void textview_delete_backward_word (GtkTextView *text)
8957 GtkTextBuffer *buffer;
8959 GtkTextIter ins, end_iter;
8961 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8963 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8964 mark = gtk_text_buffer_get_insert(buffer);
8965 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8967 if (gtk_text_iter_backward_word_start(&end_iter)) {
8968 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8972 static void textview_delete_line (GtkTextView *text)
8974 GtkTextBuffer *buffer;
8976 GtkTextIter ins, start_iter, end_iter;
8979 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8981 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8982 mark = gtk_text_buffer_get_insert(buffer);
8983 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8986 gtk_text_iter_set_line_offset(&start_iter, 0);
8989 if (gtk_text_iter_ends_line(&end_iter))
8990 found = gtk_text_iter_forward_char(&end_iter);
8992 found = gtk_text_iter_forward_to_line_end(&end_iter);
8995 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8998 static void textview_delete_to_line_end (GtkTextView *text)
9000 GtkTextBuffer *buffer;
9002 GtkTextIter ins, end_iter;
9005 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
9007 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
9008 mark = gtk_text_buffer_get_insert(buffer);
9009 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
9011 if (gtk_text_iter_ends_line(&end_iter))
9012 found = gtk_text_iter_forward_char(&end_iter);
9014 found = gtk_text_iter_forward_to_line_end(&end_iter);
9016 gtk_text_buffer_delete(buffer, &ins, &end_iter);
9019 static void compose_advanced_action_cb(Compose *compose,
9020 ComposeCallAdvancedAction action)
9022 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9024 void (*do_action) (GtkTextView *text);
9025 } action_table[] = {
9026 {textview_move_beginning_of_line},
9027 {textview_move_forward_character},
9028 {textview_move_backward_character},
9029 {textview_move_forward_word},
9030 {textview_move_backward_word},
9031 {textview_move_end_of_line},
9032 {textview_move_next_line},
9033 {textview_move_previous_line},
9034 {textview_delete_forward_character},
9035 {textview_delete_backward_character},
9036 {textview_delete_forward_word},
9037 {textview_delete_backward_word},
9038 {textview_delete_line},
9039 {NULL}, /* gtk_stext_delete_line_n */
9040 {textview_delete_to_line_end}
9043 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
9045 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
9046 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
9047 if (action_table[action].do_action)
9048 action_table[action].do_action(text);
9050 g_warning("Not implemented yet.");
9054 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
9058 if (GTK_IS_EDITABLE(widget)) {
9059 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
9060 gtk_editable_set_position(GTK_EDITABLE(widget),
9063 if (widget->parent && widget->parent->parent
9064 && widget->parent->parent->parent) {
9065 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
9066 gint y = widget->allocation.y;
9067 gint height = widget->allocation.height;
9068 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
9069 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
9071 if (y < (int)shown->value) {
9072 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
9074 if (y + height > (int)shown->value + (int)shown->page_size) {
9075 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
9076 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
9077 y + height - (int)shown->page_size - 1);
9079 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
9080 (int)shown->upper - (int)shown->page_size - 1);
9087 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
9088 compose->focused_editable = widget;
9091 if (GTK_IS_TEXT_VIEW(widget)
9092 && gtk_paned_get_child1(GTK_PANED(compose->paned)) != compose->edit_vbox) {
9093 gtk_widget_ref(compose->notebook);
9094 gtk_widget_ref(compose->edit_vbox);
9095 gtk_container_remove(GTK_CONTAINER(compose->paned), compose->notebook);
9096 gtk_container_remove(GTK_CONTAINER(compose->paned), compose->edit_vbox);
9097 gtk_paned_add1(GTK_PANED(compose->paned), compose->edit_vbox);
9098 gtk_paned_add2(GTK_PANED(compose->paned), compose->notebook);
9099 gtk_widget_unref(compose->notebook);
9100 gtk_widget_unref(compose->edit_vbox);
9101 g_signal_handlers_block_by_func(G_OBJECT(widget),
9102 G_CALLBACK(compose_grab_focus_cb),
9104 gtk_widget_grab_focus(widget);
9105 g_signal_handlers_unblock_by_func(G_OBJECT(widget),
9106 G_CALLBACK(compose_grab_focus_cb),
9108 } else if (!GTK_IS_TEXT_VIEW(widget)
9109 && gtk_paned_get_child1(GTK_PANED(compose->paned)) != compose->notebook) {
9110 gtk_widget_ref(compose->notebook);
9111 gtk_widget_ref(compose->edit_vbox);
9112 gtk_container_remove(GTK_CONTAINER(compose->paned), compose->notebook);
9113 gtk_container_remove(GTK_CONTAINER(compose->paned), compose->edit_vbox);
9114 gtk_paned_add1(GTK_PANED(compose->paned), compose->notebook);
9115 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
9116 gtk_widget_unref(compose->notebook);
9117 gtk_widget_unref(compose->edit_vbox);
9118 g_signal_handlers_block_by_func(G_OBJECT(widget),
9119 G_CALLBACK(compose_grab_focus_cb),
9121 gtk_widget_grab_focus(widget);
9122 g_signal_handlers_unblock_by_func(G_OBJECT(widget),
9123 G_CALLBACK(compose_grab_focus_cb),
9129 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
9131 compose->modified = TRUE;
9133 compose_set_title(compose);
9137 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
9139 Compose *compose = (Compose *)data;
9142 compose_wrap_all_full(compose, TRUE);
9144 compose_beautify_paragraph(compose, NULL, TRUE);
9147 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
9149 Compose *compose = (Compose *)data;
9151 message_search_compose(compose);
9154 static void compose_toggle_autowrap_cb(gpointer data, guint action,
9157 Compose *compose = (Compose *)data;
9158 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
9159 if (compose->autowrap)
9160 compose_wrap_all_full(compose, TRUE);
9161 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
9164 static void compose_toggle_sign_cb(gpointer data, guint action,
9167 Compose *compose = (Compose *)data;
9169 if (GTK_CHECK_MENU_ITEM(widget)->active)
9170 compose->use_signing = TRUE;
9172 compose->use_signing = FALSE;
9175 static void compose_toggle_encrypt_cb(gpointer data, guint action,
9178 Compose *compose = (Compose *)data;
9180 if (GTK_CHECK_MENU_ITEM(widget)->active)
9181 compose->use_encryption = TRUE;
9183 compose->use_encryption = FALSE;
9186 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
9188 g_free(compose->privacy_system);
9190 compose->privacy_system = g_strdup(account->default_privacy_system);
9191 compose_update_privacy_system_menu_item(compose, warn);
9194 static void compose_toggle_ruler_cb(gpointer data, guint action,
9197 Compose *compose = (Compose *)data;
9199 if (GTK_CHECK_MENU_ITEM(widget)->active) {
9200 gtk_widget_show(compose->ruler_hbox);
9201 prefs_common.show_ruler = TRUE;
9203 gtk_widget_hide(compose->ruler_hbox);
9204 gtk_widget_queue_resize(compose->edit_vbox);
9205 prefs_common.show_ruler = FALSE;
9209 static void compose_attach_drag_received_cb (GtkWidget *widget,
9210 GdkDragContext *context,
9213 GtkSelectionData *data,
9218 Compose *compose = (Compose *)user_data;
9221 if (gdk_atom_name(data->type) &&
9222 !strcmp(gdk_atom_name(data->type), "text/uri-list")
9223 && gtk_drag_get_source_widget(context) !=
9224 summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
9225 list = uri_list_extract_filenames((const gchar *)data->data);
9226 for (tmp = list; tmp != NULL; tmp = tmp->next) {
9227 gchar *utf8_filename = conv_filename_to_utf8((const gchar *)tmp->data);
9228 compose_attach_append
9229 (compose, (const gchar *)tmp->data,
9230 utf8_filename, NULL);
9231 g_free(utf8_filename);
9233 if (list) compose_changed_cb(NULL, compose);
9234 list_free_strings(list);
9236 } else if (gtk_drag_get_source_widget(context)
9237 == summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
9238 /* comes from our summaryview */
9239 SummaryView * summaryview = NULL;
9240 GSList * list = NULL, *cur = NULL;
9242 if (mainwindow_get_mainwindow())
9243 summaryview = mainwindow_get_mainwindow()->summaryview;
9246 list = summary_get_selected_msg_list(summaryview);
9248 for (cur = list; cur; cur = cur->next) {
9249 MsgInfo *msginfo = (MsgInfo *)cur->data;
9252 file = procmsg_get_message_file_full(msginfo,
9255 compose_attach_append(compose, (const gchar *)file,
9256 (const gchar *)file, "message/rfc822");
9264 static gboolean compose_drag_drop(GtkWidget *widget,
9265 GdkDragContext *drag_context,
9267 guint time, gpointer user_data)
9269 /* not handling this signal makes compose_insert_drag_received_cb
9274 static void compose_insert_drag_received_cb (GtkWidget *widget,
9275 GdkDragContext *drag_context,
9278 GtkSelectionData *data,
9283 Compose *compose = (Compose *)user_data;
9286 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
9288 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
9289 AlertValue val = G_ALERTDEFAULT;
9291 switch (prefs_common.compose_dnd_mode) {
9292 case COMPOSE_DND_ASK:
9293 val = alertpanel_full(_("Insert or attach?"),
9294 _("Do you want to insert the contents of the file(s) "
9295 "into the message body, or attach it to the email?"),
9296 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
9297 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
9299 case COMPOSE_DND_INSERT:
9300 val = G_ALERTALTERNATE;
9302 case COMPOSE_DND_ATTACH:
9306 /* unexpected case */
9307 g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
9310 if (val & G_ALERTDISABLE) {
9311 val &= ~G_ALERTDISABLE;
9312 /* remember what action to perform by default, only if we don't click Cancel */
9313 if (val == G_ALERTALTERNATE)
9314 prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
9315 else if (val == G_ALERTOTHER)
9316 prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
9319 if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
9320 gtk_drag_finish(drag_context, FALSE, FALSE, time);
9322 } else if (val == G_ALERTOTHER) {
9323 compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
9326 list = uri_list_extract_filenames((const gchar *)data->data);
9327 for (tmp = list; tmp != NULL; tmp = tmp->next) {
9328 compose_insert_file(compose, (const gchar *)tmp->data);
9330 list_free_strings(list);
9332 gtk_drag_finish(drag_context, TRUE, FALSE, time);
9335 #if GTK_CHECK_VERSION(2, 8, 0)
9336 /* do nothing, handled by GTK */
9338 gchar *tmpfile = get_tmp_file();
9339 str_write_to_file((const gchar *)data->data, tmpfile);
9340 compose_insert_file(compose, tmpfile);
9343 gtk_drag_finish(drag_context, TRUE, FALSE, time);
9347 gtk_drag_finish(drag_context, TRUE, FALSE, time);
9350 static void compose_header_drag_received_cb (GtkWidget *widget,
9351 GdkDragContext *drag_context,
9354 GtkSelectionData *data,
9359 GtkEditable *entry = (GtkEditable *)user_data;
9360 gchar *email = (gchar *)data->data;
9362 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
9365 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
9366 gchar *decoded=g_new(gchar, strlen(email));
9369 email += strlen("mailto:");
9370 decode_uri(decoded, email); /* will fit */
9371 gtk_editable_delete_text(entry, 0, -1);
9372 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
9373 gtk_drag_finish(drag_context, TRUE, FALSE, time);
9377 gtk_drag_finish(drag_context, TRUE, FALSE, time);
9380 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
9383 Compose *compose = (Compose *)data;
9385 if (GTK_CHECK_MENU_ITEM(widget)->active)
9386 compose->return_receipt = TRUE;
9388 compose->return_receipt = FALSE;
9391 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
9394 Compose *compose = (Compose *)data;
9396 if (GTK_CHECK_MENU_ITEM(widget)->active)
9397 compose->remove_references = TRUE;
9399 compose->remove_references = FALSE;
9402 static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
9404 ComposeHeaderEntry *headerentry)
9406 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
9407 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
9408 !(event->state & GDK_MODIFIER_MASK) &&
9409 (event->keyval == GDK_BackSpace) &&
9410 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
9411 gtk_container_remove
9412 (GTK_CONTAINER(headerentry->compose->header_table),
9413 headerentry->combo);
9414 gtk_container_remove
9415 (GTK_CONTAINER(headerentry->compose->header_table),
9416 headerentry->entry);
9417 headerentry->compose->header_list =
9418 g_slist_remove(headerentry->compose->header_list,
9420 g_free(headerentry);
9421 } else if (event->keyval == GDK_Tab) {
9422 if (headerentry->compose->header_last == headerentry) {
9423 /* Override default next focus, and give it to subject_entry
9424 * instead of notebook tabs
9426 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
9427 gtk_widget_grab_focus(headerentry->compose->subject_entry);
9434 static gboolean compose_headerentry_changed_cb(GtkWidget *entry,
9435 ComposeHeaderEntry *headerentry)
9437 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
9438 compose_create_header_entry(headerentry->compose);
9439 g_signal_handlers_disconnect_matched
9440 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
9441 0, 0, NULL, NULL, headerentry);
9443 /* Automatically scroll down */
9444 compose_show_first_last_header(headerentry->compose, FALSE);
9450 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
9452 GtkAdjustment *vadj;
9454 g_return_if_fail(compose);
9455 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
9456 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
9458 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
9459 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
9462 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
9463 const gchar *text, gint len, Compose *compose)
9465 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
9466 (G_OBJECT(compose->text), "paste_as_quotation"));
9469 g_return_if_fail(text != NULL);
9471 g_signal_handlers_block_by_func(G_OBJECT(buffer),
9472 G_CALLBACK(text_inserted),
9474 if (paste_as_quotation) {
9481 new_text = g_strndup(text, len);
9482 if (prefs_common.quotemark && *prefs_common.quotemark)
9483 qmark = prefs_common.quotemark;
9487 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
9488 gtk_text_buffer_place_cursor(buffer, iter);
9490 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE, FALSE,
9491 _("Quote format error."));
9492 quote_fmt_reset_vartable();
9494 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
9495 GINT_TO_POINTER(paste_as_quotation - 1));
9497 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
9498 gtk_text_buffer_place_cursor(buffer, iter);
9500 if (strcmp(text, "\n") || automatic_break
9501 || gtk_text_iter_starts_line(iter))
9502 gtk_text_buffer_insert(buffer, iter, text, len);
9504 debug_print("insert nowrap \\n\n");
9505 gtk_text_buffer_insert_with_tags_by_name(buffer,
9506 iter, text, len, "no_join", NULL);
9510 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
9512 compose_beautify_paragraph(compose, iter, FALSE);
9514 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
9515 gtk_text_buffer_delete_mark(buffer, mark);
9517 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
9518 G_CALLBACK(text_inserted),
9520 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
9522 if (prefs_common.autosave &&
9523 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
9524 compose->draft_timeout_tag = g_timeout_add
9525 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
9527 static gint compose_defer_auto_save_draft(Compose *compose)
9529 compose->draft_timeout_tag = -1;
9530 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
9535 static void compose_check_all(Compose *compose)
9537 if (compose->gtkaspell)
9538 gtkaspell_check_all(compose->gtkaspell);
9541 static void compose_highlight_all(Compose *compose)
9543 if (compose->gtkaspell)
9544 gtkaspell_highlight_all(compose->gtkaspell);
9547 static void compose_check_backwards(Compose *compose)
9549 if (compose->gtkaspell)
9550 gtkaspell_check_backwards(compose->gtkaspell);
9552 GtkItemFactory *ifactory;
9553 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
9554 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
9555 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
9559 static void compose_check_forwards_go(Compose *compose)
9561 if (compose->gtkaspell)
9562 gtkaspell_check_forwards_go(compose->gtkaspell);
9564 GtkItemFactory *ifactory;
9565 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
9566 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
9567 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
9573 *\brief Guess originating forward account from MsgInfo and several
9574 * "common preference" settings. Return NULL if no guess.
9576 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
9578 PrefsAccount *account = NULL;
9580 g_return_val_if_fail(msginfo, NULL);
9581 g_return_val_if_fail(msginfo->folder, NULL);
9582 g_return_val_if_fail(msginfo->folder->prefs, NULL);
9584 if (msginfo->folder->prefs->enable_default_account)
9585 account = account_find_from_id(msginfo->folder->prefs->default_account);
9588 account = msginfo->folder->folder->account;
9590 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
9592 Xstrdup_a(to, msginfo->to, return NULL);
9593 extract_address(to);
9594 account = account_find_from_address(to);
9597 if (!account && prefs_common.forward_account_autosel) {
9599 if (!procheader_get_header_from_msginfo
9600 (msginfo, cc,sizeof cc , "Cc:")) {
9601 gchar *buf = cc + strlen("Cc:");
9602 extract_address(buf);
9603 account = account_find_from_address(buf);
9607 if (!account && prefs_common.forward_account_autosel) {
9608 gchar deliveredto[BUFFSIZE];
9609 if (!procheader_get_header_from_msginfo
9610 (msginfo, deliveredto,sizeof deliveredto , "Delivered-To:")) {
9611 gchar *buf = deliveredto + strlen("Delivered-To:");
9612 extract_address(buf);
9613 account = account_find_from_address(buf);
9620 gboolean compose_close(Compose *compose)
9624 if (!g_mutex_trylock(compose->mutex)) {
9625 /* we have to wait for the (possibly deferred by auto-save)
9626 * drafting to be done, before destroying the compose under
9628 debug_print("waiting for drafting to finish...\n");
9629 g_timeout_add (500, (GSourceFunc) compose_close, compose);
9632 g_return_val_if_fail(compose, FALSE);
9633 gtkut_widget_get_uposition(compose->window, &x, &y);
9634 prefs_common.compose_x = x;
9635 prefs_common.compose_y = y;
9636 g_mutex_unlock(compose->mutex);
9637 compose_destroy(compose);
9642 * Add entry field for each address in list.
9643 * \param compose E-Mail composition object.
9644 * \param listAddress List of (formatted) E-Mail addresses.
9646 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
9651 addr = ( gchar * ) node->data;
9652 compose_entry_append( compose, addr, COMPOSE_TO );
9653 node = g_list_next( node );
9657 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
9658 guint action, gboolean opening_multiple)
9661 GSList *new_msglist = NULL;
9662 MsgInfo *tmp_msginfo = NULL;
9663 gboolean originally_enc = FALSE;
9664 Compose *compose = NULL;
9666 g_return_if_fail(msgview != NULL);
9668 g_return_if_fail(msginfo_list != NULL);
9670 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
9671 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
9672 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
9674 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
9675 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
9676 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
9677 orig_msginfo, mimeinfo);
9678 if (tmp_msginfo != NULL) {
9679 new_msglist = g_slist_append(NULL, tmp_msginfo);
9680 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
9681 originally_enc = TRUE;
9687 if (!opening_multiple)
9688 body = messageview_get_selection(msgview);
9691 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
9692 procmsg_msginfo_free(tmp_msginfo);
9693 g_slist_free(new_msglist);
9695 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
9697 if (originally_enc) {
9698 compose_force_encryption(compose, compose->account, FALSE);
9704 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
9707 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
9708 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
9709 GSList *cur = msginfo_list;
9710 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
9711 "messages. Opening the windows "
9712 "could take some time. Do you "
9713 "want to continue?"),
9714 g_slist_length(msginfo_list));
9715 if (g_slist_length(msginfo_list) > 9
9716 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
9717 != G_ALERTALTERNATE) {
9722 /* We'll open multiple compose windows */
9723 /* let the WM place the next windows */
9724 compose_force_window_origin = FALSE;
9725 for (; cur; cur = cur->next) {
9727 tmplist.data = cur->data;
9728 tmplist.next = NULL;
9729 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
9731 compose_force_window_origin = TRUE;
9733 /* forwarding multiple mails as attachments is done via a
9734 * single compose window */
9735 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
9739 void compose_set_position(Compose *compose, gint pos)
9741 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9743 gtkut_text_view_set_position(text, pos);
9746 gboolean compose_search_string(Compose *compose,
9747 const gchar *str, gboolean case_sens)
9749 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9751 return gtkut_text_view_search_string(text, str, case_sens);
9754 gboolean compose_search_string_backward(Compose *compose,
9755 const gchar *str, gboolean case_sens)
9757 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9759 return gtkut_text_view_search_string_backward(text, str, case_sens);
9762 /* allocate a msginfo structure and populate its data from a compose data structure */
9763 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
9765 MsgInfo *newmsginfo;
9767 gchar buf[BUFFSIZE];
9769 g_return_val_if_fail( compose != NULL, NULL );
9771 newmsginfo = procmsg_msginfo_new();
9774 get_rfc822_date(buf, sizeof(buf));
9775 newmsginfo->date = g_strdup(buf);
9778 if (compose->from_name) {
9779 newmsginfo->from = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
9780 newmsginfo->fromname = procheader_get_fromname(newmsginfo->from);
9784 if (compose->subject_entry)
9785 newmsginfo->subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
9787 /* to, cc, reply-to, newsgroups */
9788 for (list = compose->header_list; list; list = list->next) {
9789 gchar *header = gtk_editable_get_chars(
9791 GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
9792 gchar *entry = gtk_editable_get_chars(
9793 GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
9795 if ( strcasecmp(header, prefs_common_translated_header_name("To:")) == 0 ) {
9796 if ( newmsginfo->to == NULL ) {
9797 newmsginfo->to = g_strdup(entry);
9798 } else if (entry && *entry) {
9799 gchar *tmp = g_strconcat(newmsginfo->to, ", ", entry, NULL);
9800 g_free(newmsginfo->to);
9801 newmsginfo->to = tmp;
9804 if ( strcasecmp(header, prefs_common_translated_header_name("Cc:")) == 0 ) {
9805 if ( newmsginfo->cc == NULL ) {
9806 newmsginfo->cc = g_strdup(entry);
9807 } else if (entry && *entry) {
9808 gchar *tmp = g_strconcat(newmsginfo->cc, ", ", entry, NULL);
9809 g_free(newmsginfo->cc);
9810 newmsginfo->cc = tmp;
9813 if ( strcasecmp(header,
9814 prefs_common_translated_header_name("Newsgroups:")) == 0 ) {
9815 if ( newmsginfo->newsgroups == NULL ) {
9816 newmsginfo->newsgroups = g_strdup(entry);
9817 } else if (entry && *entry) {
9818 gchar *tmp = g_strconcat(newmsginfo->newsgroups, ", ", entry, NULL);
9819 g_free(newmsginfo->newsgroups);
9820 newmsginfo->newsgroups = tmp;
9828 /* other data is unset */
9834 /* update compose's dictionaries from folder dict settings */
9835 static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
9836 FolderItem *folder_item)
9838 g_return_if_fail(compose != NULL);
9840 if (compose->gtkaspell && folder_item && folder_item->prefs) {
9841 FolderItemPrefs *prefs = folder_item->prefs;
9843 if (prefs->enable_default_dictionary)
9844 gtkaspell_change_dict(compose->gtkaspell,
9845 prefs->default_dictionary, FALSE);
9846 if (folder_item->prefs->enable_default_alt_dictionary)
9847 gtkaspell_change_alt_dict(compose->gtkaspell,
9848 prefs->default_alt_dictionary);
9849 if (prefs->enable_default_dictionary
9850 || prefs->enable_default_alt_dictionary)
9851 compose_spell_menu_changed(compose);