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);
1044 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account);
1045 quote_fmt_scan_string(tmp);
1048 buf = quote_fmt_get_buffer();
1050 alertpanel_error(_("New message subject format error."));
1052 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
1053 quote_fmt_reset_vartable();
1059 if ( prefs_common.compose_body_format
1060 && *prefs_common.compose_body_format != '\0' )
1063 GtkTextBuffer *buffer;
1064 GtkTextIter start, end;
1067 if ( dummyinfo == NULL )
1068 dummyinfo = compose_msginfo_new_from_compose(compose);
1070 text = GTK_TEXT_VIEW(compose->text);
1071 buffer = gtk_text_view_get_buffer(text);
1072 gtk_text_buffer_get_start_iter(buffer, &start);
1073 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
1074 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
1076 compose_quote_fmt(compose, dummyinfo,
1077 prefs_common.compose_body_format,
1078 NULL, tmp, FALSE, TRUE,
1079 _("New message body format error."));
1080 quote_fmt_reset_vartable();
1085 procmsg_msginfo_free( dummyinfo );
1092 for (i = 0; i < attach_files->len; i++) {
1093 file = g_ptr_array_index(attach_files, i);
1094 compose_attach_append(compose, file, file, NULL);
1098 compose_show_first_last_header(compose, TRUE);
1100 /* Set save folder */
1101 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1102 gchar *folderidentifier;
1104 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1105 folderidentifier = folder_item_get_identifier(item);
1106 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1107 g_free(folderidentifier);
1110 gtk_widget_grab_focus(compose->header_last->entry);
1112 undo_unblock(compose->undostruct);
1114 if (prefs_common.auto_exteditor)
1115 compose_exec_ext_editor(compose);
1117 compose->modified = FALSE;
1118 compose_set_title(compose);
1122 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1123 gboolean override_pref)
1125 gchar *privacy = NULL;
1127 g_return_if_fail(compose != NULL);
1128 g_return_if_fail(account != NULL);
1130 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1133 if (account->default_privacy_system
1134 && strlen(account->default_privacy_system)) {
1135 privacy = account->default_privacy_system;
1137 GSList *privacy_avail = privacy_get_system_ids();
1138 if (privacy_avail && g_slist_length(privacy_avail)) {
1139 privacy = (gchar *)(privacy_avail->data);
1142 if (privacy != NULL) {
1143 if (compose->privacy_system == NULL)
1144 compose->privacy_system = g_strdup(privacy);
1145 compose_update_privacy_system_menu_item(compose, FALSE);
1146 compose_use_encryption(compose, TRUE);
1150 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1152 gchar *privacy = NULL;
1154 if (account->default_privacy_system
1155 && strlen(account->default_privacy_system)) {
1156 privacy = account->default_privacy_system;
1158 GSList *privacy_avail = privacy_get_system_ids();
1159 if (privacy_avail && g_slist_length(privacy_avail)) {
1160 privacy = (gchar *)(privacy_avail->data);
1163 if (privacy != NULL) {
1164 if (compose->privacy_system == NULL)
1165 compose->privacy_system = g_strdup(privacy);
1166 compose_update_privacy_system_menu_item(compose, FALSE);
1167 compose_use_signing(compose, TRUE);
1171 static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1175 Compose *compose = NULL;
1176 GtkItemFactory *ifactory = NULL;
1178 g_return_val_if_fail(msginfo_list != NULL, NULL);
1180 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1181 g_return_val_if_fail(msginfo != NULL, NULL);
1183 list_len = g_slist_length(msginfo_list);
1187 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1188 FALSE, prefs_common.default_reply_list, FALSE, body);
1190 case COMPOSE_REPLY_WITH_QUOTE:
1191 compose = compose_reply(msginfo, TRUE,
1192 FALSE, prefs_common.default_reply_list, FALSE, body);
1194 case COMPOSE_REPLY_WITHOUT_QUOTE:
1195 compose = compose_reply(msginfo, FALSE,
1196 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1198 case COMPOSE_REPLY_TO_SENDER:
1199 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1200 FALSE, FALSE, TRUE, body);
1202 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1203 compose = compose_followup_and_reply_to(msginfo,
1204 prefs_common.reply_with_quote,
1205 FALSE, FALSE, body);
1207 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1208 compose = compose_reply(msginfo, TRUE,
1209 FALSE, FALSE, TRUE, body);
1211 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1212 compose = compose_reply(msginfo, FALSE,
1213 FALSE, FALSE, TRUE, NULL);
1215 case COMPOSE_REPLY_TO_ALL:
1216 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1217 TRUE, FALSE, FALSE, body);
1219 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1220 compose = compose_reply(msginfo, TRUE,
1221 TRUE, FALSE, FALSE, body);
1223 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1224 compose = compose_reply(msginfo, FALSE,
1225 TRUE, FALSE, FALSE, NULL);
1227 case COMPOSE_REPLY_TO_LIST:
1228 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1229 FALSE, TRUE, FALSE, body);
1231 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1232 compose = compose_reply(msginfo, TRUE,
1233 FALSE, TRUE, FALSE, body);
1235 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1236 compose = compose_reply(msginfo, FALSE,
1237 FALSE, TRUE, FALSE, NULL);
1239 case COMPOSE_FORWARD:
1240 if (prefs_common.forward_as_attachment) {
1241 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1244 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1248 case COMPOSE_FORWARD_INLINE:
1249 /* check if we reply to more than one Message */
1250 if (list_len == 1) {
1251 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1254 /* more messages FALL THROUGH */
1255 case COMPOSE_FORWARD_AS_ATTACH:
1256 compose = compose_forward_multiple(NULL, msginfo_list);
1258 case COMPOSE_REDIRECT:
1259 compose = compose_redirect(NULL, msginfo, FALSE);
1262 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1265 ifactory = gtk_item_factory_from_widget(compose->menubar);
1267 compose->rmode = mode;
1268 switch (compose->rmode) {
1270 case COMPOSE_REPLY_WITH_QUOTE:
1271 case COMPOSE_REPLY_WITHOUT_QUOTE:
1272 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1273 debug_print("reply mode Normal\n");
1274 menu_set_active(ifactory, "/Options/Reply mode/Normal", TRUE);
1275 compose_reply_change_mode(compose, COMPOSE_REPLY, NULL); /* force update */
1277 case COMPOSE_REPLY_TO_SENDER:
1278 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1279 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1280 debug_print("reply mode Sender\n");
1281 menu_set_active(ifactory, "/Options/Reply mode/Sender", TRUE);
1283 case COMPOSE_REPLY_TO_ALL:
1284 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1285 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1286 debug_print("reply mode All\n");
1287 menu_set_active(ifactory, "/Options/Reply mode/All", TRUE);
1289 case COMPOSE_REPLY_TO_LIST:
1290 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1291 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1292 debug_print("reply mode List\n");
1293 menu_set_active(ifactory, "/Options/Reply mode/Mailing-list", TRUE);
1301 static Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1302 gboolean to_ml, gboolean to_sender,
1305 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1306 to_sender, FALSE, body);
1309 static Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1314 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1315 to_sender, TRUE, body);
1318 static void compose_extract_original_charset(Compose *compose)
1320 MsgInfo *info = NULL;
1321 if (compose->replyinfo) {
1322 info = compose->replyinfo;
1323 } else if (compose->fwdinfo) {
1324 info = compose->fwdinfo;
1325 } else if (compose->targetinfo) {
1326 info = compose->targetinfo;
1329 MimeInfo *mimeinfo = procmime_scan_message(info);
1330 MimeInfo *partinfo = mimeinfo;
1331 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1332 partinfo = procmime_mimeinfo_next(partinfo);
1334 compose->orig_charset =
1335 g_strdup(procmime_mimeinfo_get_parameter(
1336 partinfo, "charset"));
1338 procmime_mimeinfo_free_all(mimeinfo);
1342 #define SIGNAL_BLOCK(buffer) { \
1343 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1344 G_CALLBACK(compose_changed_cb), \
1346 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1347 G_CALLBACK(text_inserted), \
1351 #define SIGNAL_UNBLOCK(buffer) { \
1352 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1353 G_CALLBACK(compose_changed_cb), \
1355 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1356 G_CALLBACK(text_inserted), \
1360 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1361 gboolean to_all, gboolean to_ml,
1363 gboolean followup_and_reply_to,
1366 GtkItemFactory *ifactory;
1368 PrefsAccount *account = NULL;
1369 PrefsAccount *reply_account;
1370 GtkTextView *textview;
1371 GtkTextBuffer *textbuf;
1373 g_return_val_if_fail(msginfo != NULL, NULL);
1374 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1376 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1378 g_return_val_if_fail(account != NULL, NULL);
1380 if (to_sender && account->protocol == A_NNTP &&
1381 !followup_and_reply_to) {
1383 account_find_from_address(account->address);
1385 reply_account = compose_current_mail_account();
1389 reply_account = account;
1391 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1393 compose->updating = TRUE;
1395 ifactory = gtk_item_factory_from_widget(compose->menubar);
1397 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1398 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1400 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1401 if (!compose->replyinfo)
1402 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1404 compose_extract_original_charset(compose);
1406 if (msginfo->folder && msginfo->folder->ret_rcpt)
1407 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1409 /* Set save folder */
1410 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1411 gchar *folderidentifier;
1413 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1414 folderidentifier = folder_item_get_identifier(msginfo->folder);
1415 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1416 g_free(folderidentifier);
1419 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1421 textview = (GTK_TEXT_VIEW(compose->text));
1422 textbuf = gtk_text_view_get_buffer(textview);
1423 compose_create_tags(textview, compose);
1425 undo_block(compose->undostruct);
1427 compose_set_dictionaries_from_folder_prefs(compose, msginfo->folder);
1433 if (prefs_common.quotemark && *prefs_common.quotemark)
1434 qmark = prefs_common.quotemark;
1438 compose_quote_fmt(compose, compose->replyinfo,
1439 prefs_common.quotefmt,
1440 qmark, body, FALSE, TRUE,
1441 _("Message reply format error."));
1442 quote_fmt_reset_vartable();
1444 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1445 compose_force_encryption(compose, account, FALSE);
1448 SIGNAL_BLOCK(textbuf);
1450 if (account->auto_sig)
1451 compose_insert_sig(compose, FALSE);
1453 compose_wrap_all(compose);
1455 SIGNAL_UNBLOCK(textbuf);
1457 gtk_widget_grab_focus(compose->text);
1459 undo_unblock(compose->undostruct);
1461 if (prefs_common.auto_exteditor)
1462 compose_exec_ext_editor(compose);
1464 compose->modified = FALSE;
1465 compose_set_title(compose);
1467 compose->updating = FALSE;
1469 if (compose->deferred_destroy) {
1470 compose_destroy(compose);
1477 #define INSERT_FW_HEADER(var, hdr) \
1478 if (msginfo->var && *msginfo->var) { \
1479 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1480 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1481 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1484 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1485 gboolean as_attach, const gchar *body,
1486 gboolean no_extedit,
1490 GtkTextView *textview;
1491 GtkTextBuffer *textbuf;
1494 g_return_val_if_fail(msginfo != NULL, NULL);
1495 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1498 !(account = compose_guess_forward_account_from_msginfo
1500 account = cur_account;
1502 compose = compose_create(account, COMPOSE_FORWARD, batch);
1504 compose->updating = TRUE;
1505 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1506 if (!compose->fwdinfo)
1507 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1509 compose_extract_original_charset(compose);
1511 if (msginfo->subject && *msginfo->subject) {
1512 gchar *buf, *buf2, *p;
1514 buf = p = g_strdup(msginfo->subject);
1515 p += subject_get_prefix_length(p);
1516 memmove(buf, p, strlen(p) + 1);
1518 buf2 = g_strdup_printf("Fw: %s", buf);
1519 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1525 textview = GTK_TEXT_VIEW(compose->text);
1526 textbuf = gtk_text_view_get_buffer(textview);
1527 compose_create_tags(textview, compose);
1529 undo_block(compose->undostruct);
1533 msgfile = procmsg_get_message_file_path(msginfo);
1534 if (!is_file_exist(msgfile))
1535 g_warning("%s: file not exist\n", msgfile);
1537 compose_attach_append(compose, msgfile, msgfile,
1543 MsgInfo *full_msginfo;
1545 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1547 full_msginfo = procmsg_msginfo_copy(msginfo);
1549 if (prefs_common.fw_quotemark &&
1550 *prefs_common.fw_quotemark)
1551 qmark = prefs_common.fw_quotemark;
1555 compose_quote_fmt(compose, full_msginfo,
1556 prefs_common.fw_quotefmt,
1557 qmark, body, FALSE, TRUE,
1558 _("Message forward format error."));
1559 quote_fmt_reset_vartable();
1560 compose_attach_parts(compose, msginfo);
1562 procmsg_msginfo_free(full_msginfo);
1565 SIGNAL_BLOCK(textbuf);
1567 if (account->auto_sig)
1568 compose_insert_sig(compose, FALSE);
1570 compose_wrap_all(compose);
1572 SIGNAL_UNBLOCK(textbuf);
1574 gtk_text_buffer_get_start_iter(textbuf, &iter);
1575 gtk_text_buffer_place_cursor(textbuf, &iter);
1577 gtk_widget_grab_focus(compose->header_last->entry);
1579 if (!no_extedit && prefs_common.auto_exteditor)
1580 compose_exec_ext_editor(compose);
1583 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1584 gchar *folderidentifier;
1586 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1587 folderidentifier = folder_item_get_identifier(msginfo->folder);
1588 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1589 g_free(folderidentifier);
1592 undo_unblock(compose->undostruct);
1594 compose->modified = FALSE;
1595 compose_set_title(compose);
1597 compose->updating = FALSE;
1599 if (compose->deferred_destroy) {
1600 compose_destroy(compose);
1607 #undef INSERT_FW_HEADER
1609 static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1612 GtkTextView *textview;
1613 GtkTextBuffer *textbuf;
1617 gboolean single_mail = TRUE;
1619 g_return_val_if_fail(msginfo_list != NULL, NULL);
1621 if (g_slist_length(msginfo_list) > 1)
1622 single_mail = FALSE;
1624 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1625 if (((MsgInfo *)msginfo->data)->folder == NULL)
1628 /* guess account from first selected message */
1630 !(account = compose_guess_forward_account_from_msginfo
1631 (msginfo_list->data)))
1632 account = cur_account;
1634 g_return_val_if_fail(account != NULL, NULL);
1636 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1637 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1638 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1641 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1643 compose->updating = TRUE;
1645 textview = GTK_TEXT_VIEW(compose->text);
1646 textbuf = gtk_text_view_get_buffer(textview);
1647 compose_create_tags(textview, compose);
1649 undo_block(compose->undostruct);
1650 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1651 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1653 if (!is_file_exist(msgfile))
1654 g_warning("%s: file not exist\n", msgfile);
1656 compose_attach_append(compose, msgfile, msgfile,
1662 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1663 if (info->subject && *info->subject) {
1664 gchar *buf, *buf2, *p;
1666 buf = p = g_strdup(info->subject);
1667 p += subject_get_prefix_length(p);
1668 memmove(buf, p, strlen(p) + 1);
1670 buf2 = g_strdup_printf("Fw: %s", buf);
1671 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1677 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1678 _("Fw: multiple emails"));
1681 SIGNAL_BLOCK(textbuf);
1683 if (account->auto_sig)
1684 compose_insert_sig(compose, FALSE);
1686 compose_wrap_all(compose);
1688 SIGNAL_UNBLOCK(textbuf);
1690 gtk_text_buffer_get_start_iter(textbuf, &iter);
1691 gtk_text_buffer_place_cursor(textbuf, &iter);
1693 gtk_widget_grab_focus(compose->header_last->entry);
1694 undo_unblock(compose->undostruct);
1695 compose->modified = FALSE;
1696 compose_set_title(compose);
1698 compose->updating = FALSE;
1700 if (compose->deferred_destroy) {
1701 compose_destroy(compose);
1708 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1710 GtkTextIter start = *iter;
1711 GtkTextIter end_iter;
1712 int start_pos = gtk_text_iter_get_offset(&start);
1714 if (!compose->account->sig_sep)
1717 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1718 start_pos+strlen(compose->account->sig_sep));
1720 /* check sig separator */
1721 str = gtk_text_iter_get_text(&start, &end_iter);
1722 if (!strcmp(str, compose->account->sig_sep)) {
1724 /* check end of line (\n) */
1725 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1726 start_pos+strlen(compose->account->sig_sep));
1727 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1728 start_pos+strlen(compose->account->sig_sep)+1);
1729 tmp = gtk_text_iter_get_text(&start, &end_iter);
1730 if (!strcmp(tmp,"\n")) {
1742 static void compose_colorize_signature(Compose *compose)
1744 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1746 GtkTextIter end_iter;
1747 gtk_text_buffer_get_start_iter(buffer, &iter);
1748 while (gtk_text_iter_forward_line(&iter))
1749 if (compose_is_sig_separator(compose, buffer, &iter)) {
1750 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1751 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1755 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1757 Compose *compose = NULL;
1758 PrefsAccount *account = NULL;
1759 GtkTextView *textview;
1760 GtkTextBuffer *textbuf;
1764 gchar buf[BUFFSIZE];
1765 gboolean use_signing = FALSE;
1766 gboolean use_encryption = FALSE;
1767 gchar *privacy_system = NULL;
1768 int priority = PRIORITY_NORMAL;
1769 MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
1771 g_return_val_if_fail(msginfo != NULL, NULL);
1772 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1774 if (compose_put_existing_to_front(msginfo)) {
1778 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1779 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1780 gchar queueheader_buf[BUFFSIZE];
1783 /* Select Account from queue headers */
1784 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1785 sizeof(queueheader_buf), "X-Claws-Account-Id:")) {
1786 id = atoi(&queueheader_buf[strlen("X-Claws-Account-Id:")]);
1787 account = account_find_from_id(id);
1789 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1790 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1791 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1792 account = account_find_from_id(id);
1794 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1795 sizeof(queueheader_buf), "NAID:")) {
1796 id = atoi(&queueheader_buf[strlen("NAID:")]);
1797 account = account_find_from_id(id);
1799 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1800 sizeof(queueheader_buf), "MAID:")) {
1801 id = atoi(&queueheader_buf[strlen("MAID:")]);
1802 account = account_find_from_id(id);
1804 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1805 sizeof(queueheader_buf), "S:")) {
1806 account = account_find_from_address(queueheader_buf);
1808 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1809 sizeof(queueheader_buf), "X-Claws-Sign:")) {
1810 param = atoi(&queueheader_buf[strlen("X-Claws-Sign:")]);
1811 use_signing = param;
1814 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1815 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1816 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1817 use_signing = param;
1820 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1821 sizeof(queueheader_buf), "X-Claws-Encrypt:")) {
1822 param = atoi(&queueheader_buf[strlen("X-Claws-Encrypt:")]);
1823 use_encryption = param;
1825 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1826 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1827 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1828 use_encryption = param;
1830 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1831 sizeof(queueheader_buf), "X-Claws-Privacy-System:")) {
1832 privacy_system = g_strdup(&queueheader_buf[strlen("X-Claws-Privacy-System:")]);
1834 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1835 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1836 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1838 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1839 sizeof(queueheader_buf), "X-Priority: ")) {
1840 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1843 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1844 sizeof(queueheader_buf), "RMID:")) {
1845 gchar **tokens = g_strsplit(&queueheader_buf[strlen("RMID:")], "\t", 0);
1846 if (tokens[0] && tokens[1] && tokens[2]) {
1847 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1848 if (orig_item != NULL) {
1849 replyinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1854 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1855 sizeof(queueheader_buf), "FMID:")) {
1856 gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0);
1857 if (tokens[0] && tokens[1] && tokens[2]) {
1858 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1859 if (orig_item != NULL) {
1860 fwdinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1866 account = msginfo->folder->folder->account;
1869 if (!account && prefs_common.reedit_account_autosel) {
1870 gchar from[BUFFSIZE];
1871 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1872 extract_address(from);
1873 account = account_find_from_address(from);
1877 account = cur_account;
1879 g_return_val_if_fail(account != NULL, NULL);
1881 compose = compose_create(account, COMPOSE_REEDIT, batch);
1883 compose->replyinfo = replyinfo;
1884 compose->fwdinfo = fwdinfo;
1886 compose->updating = TRUE;
1887 compose->priority = priority;
1889 if (privacy_system != NULL) {
1890 compose->privacy_system = privacy_system;
1891 compose_use_signing(compose, use_signing);
1892 compose_use_encryption(compose, use_encryption);
1893 compose_update_privacy_system_menu_item(compose, FALSE);
1895 activate_privacy_system(compose, account, FALSE);
1898 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1900 compose_extract_original_charset(compose);
1902 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1903 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1904 gchar queueheader_buf[BUFFSIZE];
1906 /* Set message save folder */
1907 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1910 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1911 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1912 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1914 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1915 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1917 GtkItemFactory *ifactory;
1918 ifactory = gtk_item_factory_from_widget(compose->menubar);
1919 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1924 if (compose_parse_header(compose, msginfo) < 0) {
1925 compose->updating = FALSE;
1926 compose_destroy(compose);
1929 compose_reedit_set_entry(compose, msginfo);
1931 textview = GTK_TEXT_VIEW(compose->text);
1932 textbuf = gtk_text_view_get_buffer(textview);
1933 compose_create_tags(textview, compose);
1935 mark = gtk_text_buffer_get_insert(textbuf);
1936 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1938 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1939 G_CALLBACK(compose_changed_cb),
1942 if (procmime_msginfo_is_encrypted(msginfo)) {
1943 fp = procmime_get_first_encrypted_text_content(msginfo);
1945 compose_force_encryption(compose, account, TRUE);
1948 fp = procmime_get_first_text_content(msginfo);
1951 g_warning("Can't get text part\n");
1955 gboolean prev_autowrap = compose->autowrap;
1957 compose->autowrap = FALSE;
1958 while (fgets(buf, sizeof(buf), fp) != NULL) {
1960 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1962 compose_wrap_all_full(compose, FALSE);
1963 compose->autowrap = prev_autowrap;
1967 compose_attach_parts(compose, msginfo);
1969 compose_colorize_signature(compose);
1971 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1972 G_CALLBACK(compose_changed_cb),
1975 gtk_widget_grab_focus(compose->text);
1977 if (prefs_common.auto_exteditor) {
1978 compose_exec_ext_editor(compose);
1980 compose->modified = FALSE;
1981 compose_set_title(compose);
1983 compose->updating = FALSE;
1985 if (compose->deferred_destroy) {
1986 compose_destroy(compose);
1990 compose->sig_str = compose_get_signature_str(compose);
1995 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
2000 GtkItemFactory *ifactory;
2003 g_return_val_if_fail(msginfo != NULL, NULL);
2006 account = account_get_reply_account(msginfo,
2007 prefs_common.reply_account_autosel);
2008 g_return_val_if_fail(account != NULL, NULL);
2010 compose = compose_create(account, COMPOSE_REDIRECT, batch);
2012 compose->updating = TRUE;
2014 ifactory = gtk_item_factory_from_widget(compose->menubar);
2015 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
2016 compose->replyinfo = NULL;
2017 compose->fwdinfo = NULL;
2019 compose_show_first_last_header(compose, TRUE);
2021 gtk_widget_grab_focus(compose->header_last->entry);
2023 filename = procmsg_get_message_file_path(msginfo);
2025 if (filename == NULL) {
2026 compose->updating = FALSE;
2027 compose_destroy(compose);
2032 compose->redirect_filename = filename;
2034 /* Set save folder */
2035 item = msginfo->folder;
2036 if (item && item->prefs && item->prefs->save_copy_to_folder) {
2037 gchar *folderidentifier;
2039 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
2040 folderidentifier = folder_item_get_identifier(item);
2041 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
2042 g_free(folderidentifier);
2045 compose_attach_parts(compose, msginfo);
2047 if (msginfo->subject)
2048 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
2050 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
2052 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE, FALSE,
2053 _("Message redirect format error."));
2054 quote_fmt_reset_vartable();
2055 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
2057 compose_colorize_signature(compose);
2059 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
2060 menu_set_sensitive(ifactory, "/Add...", FALSE);
2061 menu_set_sensitive(ifactory, "/Remove", FALSE);
2062 menu_set_sensitive(ifactory, "/Properties...", FALSE);
2064 ifactory = gtk_item_factory_from_widget(compose->menubar);
2065 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
2066 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
2067 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
2068 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
2069 menu_set_sensitive(ifactory, "/Edit", FALSE);
2070 menu_set_sensitive(ifactory, "/Options", FALSE);
2071 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
2072 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
2074 if (compose->toolbar->draft_btn)
2075 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
2076 if (compose->toolbar->insert_btn)
2077 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
2078 if (compose->toolbar->attach_btn)
2079 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
2080 if (compose->toolbar->sig_btn)
2081 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
2082 if (compose->toolbar->exteditor_btn)
2083 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
2084 if (compose->toolbar->linewrap_current_btn)
2085 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
2086 if (compose->toolbar->linewrap_all_btn)
2087 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
2089 compose->modified = FALSE;
2090 compose_set_title(compose);
2091 compose->updating = FALSE;
2093 if (compose->deferred_destroy) {
2094 compose_destroy(compose);
2101 GList *compose_get_compose_list(void)
2103 return compose_list;
2106 void compose_entry_append(Compose *compose, const gchar *address,
2107 ComposeEntryType type)
2109 const gchar *header;
2111 gboolean in_quote = FALSE;
2112 if (!address || *address == '\0') return;
2119 header = N_("Bcc:");
2121 case COMPOSE_REPLYTO:
2122 header = N_("Reply-To:");
2124 case COMPOSE_NEWSGROUPS:
2125 header = N_("Newsgroups:");
2127 case COMPOSE_FOLLOWUPTO:
2128 header = N_( "Followup-To:");
2135 header = prefs_common_translated_header_name(header);
2137 cur = begin = (gchar *)address;
2139 /* we separate the line by commas, but not if we're inside a quoted
2141 while (*cur != '\0') {
2143 in_quote = !in_quote;
2144 if (*cur == ',' && !in_quote) {
2145 gchar *tmp = g_strdup(begin);
2147 tmp[cur-begin]='\0';
2150 while (*tmp == ' ' || *tmp == '\t')
2152 compose_add_header_entry(compose, header, tmp);
2159 gchar *tmp = g_strdup(begin);
2161 tmp[cur-begin]='\0';
2164 while (*tmp == ' ' || *tmp == '\t')
2166 compose_add_header_entry(compose, header, tmp);
2171 static void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
2173 static GdkColor yellow;
2174 static GdkColor black;
2175 static gboolean yellow_initialised = FALSE;
2179 if (!yellow_initialised) {
2180 gdk_color_parse("#f5f6be", &yellow);
2181 gdk_color_parse("#000000", &black);
2182 yellow_initialised = gdk_colormap_alloc_color(
2183 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2184 yellow_initialised &= gdk_colormap_alloc_color(
2185 gdk_colormap_get_system(), &black, FALSE, TRUE);
2188 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2189 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2190 if (gtk_entry_get_text(entry) &&
2191 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2192 if (yellow_initialised) {
2193 gtk_widget_modify_base(
2194 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2195 GTK_STATE_NORMAL, &yellow);
2196 gtk_widget_modify_text(
2197 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2198 GTK_STATE_NORMAL, &black);
2204 void compose_toolbar_cb(gint action, gpointer data)
2206 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2207 Compose *compose = (Compose*)toolbar_item->parent;
2209 g_return_if_fail(compose != NULL);
2213 compose_send_cb(compose, 0, NULL);
2216 compose_send_later_cb(compose, 0, NULL);
2219 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2222 compose_insert_file_cb(compose, 0, NULL);
2225 compose_attach_cb(compose, 0, NULL);
2228 compose_insert_sig(compose, FALSE);
2231 compose_ext_editor_cb(compose, 0, NULL);
2233 case A_LINEWRAP_CURRENT:
2234 compose_beautify_paragraph(compose, NULL, TRUE);
2236 case A_LINEWRAP_ALL:
2237 compose_wrap_all_full(compose, TRUE);
2240 compose_address_cb(compose, 0, NULL);
2243 case A_CHECK_SPELLING:
2244 compose_check_all(compose);
2252 static void compose_entries_set(Compose *compose, const gchar *mailto)
2256 gchar *subject = NULL;
2260 gchar *attach = NULL;
2262 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body, &attach);
2265 compose_entry_append(compose, to, COMPOSE_TO);
2267 compose_entry_append(compose, cc, COMPOSE_CC);
2269 if (!g_utf8_validate (subject, -1, NULL)) {
2270 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2271 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2274 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2278 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2279 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2282 gboolean prev_autowrap = compose->autowrap;
2284 compose->autowrap = FALSE;
2286 mark = gtk_text_buffer_get_insert(buffer);
2287 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2289 if (!g_utf8_validate (body, -1, NULL)) {
2290 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2291 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2294 gtk_text_buffer_insert(buffer, &iter, body, -1);
2296 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2298 compose->autowrap = prev_autowrap;
2299 if (compose->autowrap)
2300 compose_wrap_all(compose);
2304 gchar *utf8_filename = conv_filename_to_utf8(attach);
2305 if (utf8_filename) {
2306 if (compose_attach_append(compose, attach, utf8_filename, NULL)) {
2307 alertpanel_notice(_("The file '%s' has been attached."), attach);
2309 g_free(utf8_filename);
2311 alertpanel_error(_("Couldn't attach a file (charset conversion failed)."));
2321 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2323 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2324 {"Cc:", NULL, TRUE},
2325 {"References:", NULL, FALSE},
2326 {"Bcc:", NULL, TRUE},
2327 {"Newsgroups:", NULL, TRUE},
2328 {"Followup-To:", NULL, TRUE},
2329 {"List-Post:", NULL, FALSE},
2330 {"X-Priority:", NULL, FALSE},
2331 {NULL, NULL, FALSE}};
2347 g_return_val_if_fail(msginfo != NULL, -1);
2349 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2350 procheader_get_header_fields(fp, hentry);
2353 if (hentry[H_REPLY_TO].body != NULL) {
2354 if (hentry[H_REPLY_TO].body[0] != '\0') {
2356 conv_unmime_header(hentry[H_REPLY_TO].body,
2359 g_free(hentry[H_REPLY_TO].body);
2360 hentry[H_REPLY_TO].body = NULL;
2362 if (hentry[H_CC].body != NULL) {
2363 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2364 g_free(hentry[H_CC].body);
2365 hentry[H_CC].body = NULL;
2367 if (hentry[H_REFERENCES].body != NULL) {
2368 if (compose->mode == COMPOSE_REEDIT)
2369 compose->references = hentry[H_REFERENCES].body;
2371 compose->references = compose_parse_references
2372 (hentry[H_REFERENCES].body, msginfo->msgid);
2373 g_free(hentry[H_REFERENCES].body);
2375 hentry[H_REFERENCES].body = NULL;
2377 if (hentry[H_BCC].body != NULL) {
2378 if (compose->mode == COMPOSE_REEDIT)
2380 conv_unmime_header(hentry[H_BCC].body, NULL);
2381 g_free(hentry[H_BCC].body);
2382 hentry[H_BCC].body = NULL;
2384 if (hentry[H_NEWSGROUPS].body != NULL) {
2385 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2386 hentry[H_NEWSGROUPS].body = NULL;
2388 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2389 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2390 compose->followup_to =
2391 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2394 g_free(hentry[H_FOLLOWUP_TO].body);
2395 hentry[H_FOLLOWUP_TO].body = NULL;
2397 if (hentry[H_LIST_POST].body != NULL) {
2400 extract_address(hentry[H_LIST_POST].body);
2401 if (hentry[H_LIST_POST].body[0] != '\0') {
2402 scan_mailto_url(hentry[H_LIST_POST].body,
2403 &to, NULL, NULL, NULL, NULL, NULL);
2405 g_free(compose->ml_post);
2406 compose->ml_post = to;
2409 g_free(hentry[H_LIST_POST].body);
2410 hentry[H_LIST_POST].body = NULL;
2413 /* CLAWS - X-Priority */
2414 if (compose->mode == COMPOSE_REEDIT)
2415 if (hentry[H_X_PRIORITY].body != NULL) {
2418 priority = atoi(hentry[H_X_PRIORITY].body);
2419 g_free(hentry[H_X_PRIORITY].body);
2421 hentry[H_X_PRIORITY].body = NULL;
2423 if (priority < PRIORITY_HIGHEST ||
2424 priority > PRIORITY_LOWEST)
2425 priority = PRIORITY_NORMAL;
2427 compose->priority = priority;
2430 if (compose->mode == COMPOSE_REEDIT) {
2431 if (msginfo->inreplyto && *msginfo->inreplyto)
2432 compose->inreplyto = g_strdup(msginfo->inreplyto);
2436 if (msginfo->msgid && *msginfo->msgid)
2437 compose->inreplyto = g_strdup(msginfo->msgid);
2439 if (!compose->references) {
2440 if (msginfo->msgid && *msginfo->msgid) {
2441 if (msginfo->inreplyto && *msginfo->inreplyto)
2442 compose->references =
2443 g_strdup_printf("<%s>\n\t<%s>",
2447 compose->references =
2448 g_strconcat("<", msginfo->msgid, ">",
2450 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2451 compose->references =
2452 g_strconcat("<", msginfo->inreplyto, ">",
2460 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2462 GSList *ref_id_list, *cur;
2466 ref_id_list = references_list_append(NULL, ref);
2467 if (!ref_id_list) return NULL;
2468 if (msgid && *msgid)
2469 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2474 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2475 /* "<" + Message-ID + ">" + CR+LF+TAB */
2476 len += strlen((gchar *)cur->data) + 5;
2478 if (len > MAX_REFERENCES_LEN) {
2479 /* remove second message-ID */
2480 if (ref_id_list && ref_id_list->next &&
2481 ref_id_list->next->next) {
2482 g_free(ref_id_list->next->data);
2483 ref_id_list = g_slist_remove
2484 (ref_id_list, ref_id_list->next->data);
2486 slist_free_strings(ref_id_list);
2487 g_slist_free(ref_id_list);
2494 new_ref = g_string_new("");
2495 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2496 if (new_ref->len > 0)
2497 g_string_append(new_ref, "\n\t");
2498 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2501 slist_free_strings(ref_id_list);
2502 g_slist_free(ref_id_list);
2504 new_ref_str = new_ref->str;
2505 g_string_free(new_ref, FALSE);
2510 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2511 const gchar *fmt, const gchar *qmark,
2512 const gchar *body, gboolean rewrap,
2513 gboolean need_unescape,
2514 const gchar *err_msg)
2516 MsgInfo* dummyinfo = NULL;
2517 gchar *quote_str = NULL;
2519 gboolean prev_autowrap;
2520 const gchar *trimmed_body = body;
2521 gint cursor_pos = -1;
2522 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2523 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2528 SIGNAL_BLOCK(buffer);
2531 dummyinfo = compose_msginfo_new_from_compose(compose);
2532 msginfo = dummyinfo;
2535 if (qmark != NULL) {
2536 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
2537 quote_fmt_scan_string(qmark);
2540 buf = quote_fmt_get_buffer();
2542 alertpanel_error(_("Quote mark format error."));
2544 Xstrdup_a(quote_str, buf, goto error)
2547 if (fmt && *fmt != '\0') {
2550 while (*trimmed_body == '\n')
2553 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account);
2554 if (need_unescape) {
2557 /* decode \-escape sequences in the internal representation of the quote format */
2558 tmp = malloc(strlen(fmt)+1);
2559 pref_get_unescaped_pref(tmp, fmt);
2560 quote_fmt_scan_string(tmp);
2564 quote_fmt_scan_string(fmt);
2568 buf = quote_fmt_get_buffer();
2570 alertpanel_error(err_msg);
2576 prev_autowrap = compose->autowrap;
2577 compose->autowrap = FALSE;
2579 mark = gtk_text_buffer_get_insert(buffer);
2580 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2581 if (g_utf8_validate(buf, -1, NULL)) {
2582 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2584 gchar *tmpout = NULL;
2585 tmpout = conv_codeset_strdup
2586 (buf, conv_get_locale_charset_str_no_utf8(),
2588 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2590 tmpout = g_malloc(strlen(buf)*2+1);
2591 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2593 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2597 cursor_pos = quote_fmt_get_cursor_pos();
2598 compose->set_cursor_pos = cursor_pos;
2599 if (cursor_pos == -1) {
2602 gtk_text_buffer_get_start_iter(buffer, &iter);
2603 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2604 gtk_text_buffer_place_cursor(buffer, &iter);
2606 compose->autowrap = prev_autowrap;
2607 if (compose->autowrap && rewrap)
2608 compose_wrap_all(compose);
2615 SIGNAL_UNBLOCK(buffer);
2617 procmsg_msginfo_free( dummyinfo );
2622 /* if ml_post is of type addr@host and from is of type
2623 * addr-anything@host, return TRUE
2625 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2627 gchar *left_ml = NULL;
2628 gchar *right_ml = NULL;
2629 gchar *left_from = NULL;
2630 gchar *right_from = NULL;
2631 gboolean result = FALSE;
2633 if (!ml_post || !from)
2636 left_ml = g_strdup(ml_post);
2637 if (strstr(left_ml, "@")) {
2638 right_ml = strstr(left_ml, "@")+1;
2639 *(strstr(left_ml, "@")) = '\0';
2642 left_from = g_strdup(from);
2643 if (strstr(left_from, "@")) {
2644 right_from = strstr(left_from, "@")+1;
2645 *(strstr(left_from, "@")) = '\0';
2648 if (left_ml && left_from && right_ml && right_from
2649 && !strncmp(left_from, left_ml, strlen(left_ml))
2650 && !strcmp(right_from, right_ml)) {
2659 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2661 gchar *my_addr1, *my_addr2;
2663 if (!addr1 || !addr2)
2666 Xstrdup_a(my_addr1, addr1, return FALSE);
2667 Xstrdup_a(my_addr2, addr2, return FALSE);
2669 extract_address(my_addr1);
2670 extract_address(my_addr2);
2672 return !strcasecmp(my_addr1, my_addr2);
2675 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2676 gboolean to_all, gboolean to_ml,
2678 gboolean followup_and_reply_to)
2680 GSList *cc_list = NULL;
2683 gchar *replyto = NULL;
2684 GHashTable *to_table;
2686 gboolean reply_to_ml = FALSE;
2687 gboolean default_reply_to = FALSE;
2689 g_return_if_fail(compose->account != NULL);
2690 g_return_if_fail(msginfo != NULL);
2692 reply_to_ml = to_ml && compose->ml_post;
2694 default_reply_to = msginfo->folder &&
2695 msginfo->folder->prefs->enable_default_reply_to;
2697 if (compose->account->protocol != A_NNTP) {
2698 if (reply_to_ml && !default_reply_to) {
2700 gboolean is_subscr = is_subscription(compose->ml_post,
2703 /* normal answer to ml post with a reply-to */
2704 compose_entry_append(compose,
2707 if (compose->replyto
2708 && !same_address(compose->ml_post, compose->replyto))
2709 compose_entry_append(compose,
2713 /* answer to subscription confirmation */
2714 if (compose->replyto)
2715 compose_entry_append(compose,
2718 else if (msginfo->from)
2719 compose_entry_append(compose,
2724 else if (!(to_all || to_sender) && default_reply_to) {
2725 compose_entry_append(compose,
2726 msginfo->folder->prefs->default_reply_to,
2728 compose_entry_mark_default_to(compose,
2729 msginfo->folder->prefs->default_reply_to);
2734 Xstrdup_a(tmp1, msginfo->from, return);
2735 extract_address(tmp1);
2736 if (to_all || to_sender ||
2737 !account_find_from_address(tmp1))
2738 compose_entry_append(compose,
2739 (compose->replyto && !to_sender)
2740 ? compose->replyto :
2741 msginfo->from ? msginfo->from : "",
2743 else if (!to_all && !to_sender) {
2744 if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
2745 !folder_has_parent_of_type(msginfo->folder, F_OUTBOX) &&
2746 !folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
2747 compose_entry_append(compose,
2748 msginfo->from ? msginfo->from : "",
2751 /* replying to own mail, use original recp */
2752 compose_entry_append(compose,
2753 msginfo->to ? msginfo->to : "",
2755 compose_entry_append(compose,
2756 msginfo->cc ? msginfo->cc : "",
2762 if (to_sender || (compose->followup_to &&
2763 !strncmp(compose->followup_to, "poster", 6)))
2764 compose_entry_append
2766 (compose->replyto ? compose->replyto :
2767 msginfo->from ? msginfo->from : ""),
2770 else if (followup_and_reply_to || to_all) {
2771 compose_entry_append
2773 (compose->replyto ? compose->replyto :
2774 msginfo->from ? msginfo->from : ""),
2777 compose_entry_append
2779 compose->followup_to ? compose->followup_to :
2780 compose->newsgroups ? compose->newsgroups : "",
2781 COMPOSE_NEWSGROUPS);
2784 compose_entry_append
2786 compose->followup_to ? compose->followup_to :
2787 compose->newsgroups ? compose->newsgroups : "",
2788 COMPOSE_NEWSGROUPS);
2791 if (msginfo->subject && *msginfo->subject) {
2795 buf = p = g_strdup(msginfo->subject);
2796 p += subject_get_prefix_length(p);
2797 memmove(buf, p, strlen(p) + 1);
2799 buf2 = g_strdup_printf("Re: %s", buf);
2800 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2805 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2807 if (to_ml && compose->ml_post) return;
2808 if (!to_all || compose->account->protocol == A_NNTP) return;
2810 if (compose->replyto) {
2811 Xstrdup_a(replyto, compose->replyto, return);
2812 extract_address(replyto);
2814 if (msginfo->from) {
2815 Xstrdup_a(from, msginfo->from, return);
2816 extract_address(from);
2819 if (replyto && from)
2820 cc_list = address_list_append_with_comments(cc_list, from);
2821 if (to_all && msginfo->folder &&
2822 msginfo->folder->prefs->enable_default_reply_to)
2823 cc_list = address_list_append_with_comments(cc_list,
2824 msginfo->folder->prefs->default_reply_to);
2825 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2826 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2828 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2830 g_hash_table_insert(to_table, g_utf8_strdown(replyto, -1), GINT_TO_POINTER(1));
2831 if (compose->account) {
2832 g_hash_table_insert(to_table, g_utf8_strdown(compose->account->address, -1),
2833 GINT_TO_POINTER(1));
2835 /* remove address on To: and that of current account */
2836 for (cur = cc_list; cur != NULL; ) {
2837 GSList *next = cur->next;
2840 addr = g_utf8_strdown(cur->data, -1);
2841 extract_address(addr);
2843 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2844 cc_list = g_slist_remove(cc_list, cur->data);
2846 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2850 hash_free_strings(to_table);
2851 g_hash_table_destroy(to_table);
2854 for (cur = cc_list; cur != NULL; cur = cur->next)
2855 compose_entry_append(compose, (gchar *)cur->data,
2857 slist_free_strings(cc_list);
2858 g_slist_free(cc_list);
2863 #define SET_ENTRY(entry, str) \
2866 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2869 #define SET_ADDRESS(type, str) \
2872 compose_entry_append(compose, str, type); \
2875 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2877 g_return_if_fail(msginfo != NULL);
2879 SET_ENTRY(subject_entry, msginfo->subject);
2880 SET_ENTRY(from_name, msginfo->from);
2881 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2882 SET_ADDRESS(COMPOSE_CC, compose->cc);
2883 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2884 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2885 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2886 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2888 compose_update_priority_menu_item(compose);
2889 compose_update_privacy_system_menu_item(compose, FALSE);
2890 compose_show_first_last_header(compose, TRUE);
2896 static void compose_insert_sig(Compose *compose, gboolean replace)
2898 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2899 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2901 GtkTextIter iter, iter_end;
2903 gchar *search = NULL;
2904 gboolean prev_autowrap;
2905 gboolean found = FALSE, shift = FALSE;
2908 g_return_if_fail(compose->account != NULL);
2910 prev_autowrap = compose->autowrap;
2911 compose->autowrap = FALSE;
2913 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2914 G_CALLBACK(compose_changed_cb),
2917 mark = gtk_text_buffer_get_insert(buffer);
2918 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2919 cur_pos = gtk_text_iter_get_offset (&iter);
2921 gtk_text_buffer_get_end_iter(buffer, &iter);
2923 search = compose->sig_str;
2925 if (replace && search) {
2926 GtkTextIter first_iter, start_iter, end_iter;
2928 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2930 if (compose->sig_str[0] == '\0')
2933 found = gtk_text_iter_forward_search(&first_iter,
2935 GTK_TEXT_SEARCH_TEXT_ONLY,
2936 &start_iter, &end_iter,
2940 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2944 if (replace && !found && search && strlen(search) > 2
2945 && search[0] == '\n' && search[1] == '\n') {
2951 g_free(compose->sig_str);
2952 compose->sig_str = compose_get_signature_str(compose);
2953 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2954 compose->sig_str = g_strdup("");
2956 cur_pos = gtk_text_iter_get_offset(&iter);
2958 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2960 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2962 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2963 gtk_text_iter_forward_char(&iter);
2964 gtk_text_iter_forward_char(&iter);
2965 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2966 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2968 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2969 cur_pos = gtk_text_buffer_get_char_count (buffer);
2971 /* put the cursor where it should be
2972 * either where the quote_fmt says, either before the signature */
2973 if (compose->set_cursor_pos < 0)
2974 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2976 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2977 compose->set_cursor_pos);
2979 gtk_text_buffer_place_cursor(buffer, &iter);
2980 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2981 G_CALLBACK(compose_changed_cb),
2984 compose->autowrap = prev_autowrap;
2985 if (compose->autowrap)
2986 compose_wrap_all(compose);
2989 static gchar *compose_get_signature_str(Compose *compose)
2991 gchar *sig_body = NULL;
2992 gchar *sig_str = NULL;
2993 gchar *utf8_sig_str = NULL;
2995 g_return_val_if_fail(compose->account != NULL, NULL);
2997 if (!compose->account->sig_path)
3000 if (compose->account->sig_type == SIG_FILE) {
3001 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
3002 g_warning("can't open signature file: %s\n",
3003 compose->account->sig_path);
3008 if (compose->account->sig_type == SIG_COMMAND)
3009 sig_body = get_command_output(compose->account->sig_path);
3013 tmp = file_read_to_str(compose->account->sig_path);
3016 sig_body = normalize_newlines(tmp);
3020 if (compose->account->sig_sep) {
3021 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
3025 sig_str = g_strconcat("\n\n", sig_body, NULL);
3028 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
3029 utf8_sig_str = sig_str;
3031 utf8_sig_str = conv_codeset_strdup
3032 (sig_str, conv_get_locale_charset_str_no_utf8(),
3038 return utf8_sig_str;
3041 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
3044 GtkTextBuffer *buffer;
3047 const gchar *cur_encoding;
3048 gchar buf[BUFFSIZE];
3051 gboolean prev_autowrap;
3052 gboolean badtxt = FALSE;
3054 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
3056 if ((fp = g_fopen(file, "rb")) == NULL) {
3057 FILE_OP_ERROR(file, "fopen");
3058 return COMPOSE_INSERT_READ_ERROR;
3061 prev_autowrap = compose->autowrap;
3062 compose->autowrap = FALSE;
3064 text = GTK_TEXT_VIEW(compose->text);
3065 buffer = gtk_text_view_get_buffer(text);
3066 mark = gtk_text_buffer_get_insert(buffer);
3067 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3069 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3070 G_CALLBACK(text_inserted),
3073 cur_encoding = conv_get_locale_charset_str_no_utf8();
3075 while (fgets(buf, sizeof(buf), fp) != NULL) {
3078 if (g_utf8_validate(buf, -1, NULL) == TRUE)
3079 str = g_strdup(buf);
3081 str = conv_codeset_strdup
3082 (buf, cur_encoding, CS_INTERNAL);
3085 /* strip <CR> if DOS/Windows file,
3086 replace <CR> with <LF> if Macintosh file. */
3089 if (len > 0 && str[len - 1] != '\n') {
3091 if (str[len] == '\r') str[len] = '\n';
3094 gtk_text_buffer_insert(buffer, &iter, str, -1);
3098 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3099 G_CALLBACK(text_inserted),
3101 compose->autowrap = prev_autowrap;
3102 if (compose->autowrap)
3103 compose_wrap_all(compose);
3108 return COMPOSE_INSERT_INVALID_CHARACTER;
3110 return COMPOSE_INSERT_SUCCESS;
3113 static gboolean compose_attach_append(Compose *compose, const gchar *file,
3114 const gchar *filename,
3115 const gchar *content_type)
3123 GtkListStore *store;
3125 gboolean has_binary = FALSE;
3127 if (!is_file_exist(file)) {
3128 gchar *file_from_uri = g_filename_from_uri(file, NULL, NULL);
3129 gboolean result = FALSE;
3130 if (file_from_uri && is_file_exist(file_from_uri)) {
3131 result = compose_attach_append(
3132 compose, file_from_uri,
3136 g_free(file_from_uri);
3139 alertpanel_error("File %s doesn't exist\n", filename);
3142 if ((size = get_file_size(file)) < 0) {
3143 alertpanel_error("Can't get file size of %s\n", filename);
3147 alertpanel_error(_("File %s is empty."), filename);
3150 if ((fp = g_fopen(file, "rb")) == NULL) {
3151 alertpanel_error(_("Can't read %s."), filename);
3156 ainfo = g_new0(AttachInfo, 1);
3157 auto_ainfo = g_auto_pointer_new_with_free
3158 (ainfo, (GFreeFunc) compose_attach_info_free);
3159 ainfo->file = g_strdup(file);
3162 ainfo->content_type = g_strdup(content_type);
3163 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
3165 MsgFlags flags = {0, 0};
3167 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
3168 ainfo->encoding = ENC_7BIT;
3170 ainfo->encoding = ENC_8BIT;
3172 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
3173 if (msginfo && msginfo->subject)
3174 name = g_strdup(msginfo->subject);
3176 name = g_path_get_basename(filename ? filename : file);
3178 ainfo->name = g_strdup_printf(_("Message: %s"), name);
3180 procmsg_msginfo_free(msginfo);
3182 if (!g_ascii_strncasecmp(content_type, "text", 4))
3183 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
3185 ainfo->encoding = ENC_BASE64;
3186 name = g_path_get_basename(filename ? filename : file);
3187 ainfo->name = g_strdup(name);
3191 ainfo->content_type = procmime_get_mime_type(file);
3192 if (!ainfo->content_type) {
3193 ainfo->content_type =
3194 g_strdup("application/octet-stream");
3195 ainfo->encoding = ENC_BASE64;
3196 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
3198 procmime_get_encoding_for_text_file(file, &has_binary);