2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
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"
118 #include "template.h"
120 #include "foldersel.h"
133 #define N_ATTACH_COLS (N_COL_COLUMNS)
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
152 } ComposeCallAdvancedAction;
156 PRIORITY_HIGHEST = 1,
165 COMPOSE_INSERT_SUCCESS,
166 COMPOSE_INSERT_READ_ERROR,
167 COMPOSE_INSERT_INVALID_CHARACTER,
168 COMPOSE_INSERT_NO_FILE
169 } ComposeInsertResult;
173 COMPOSE_QUIT_EDITING,
174 COMPOSE_KEEP_EDITING,
176 } ComposeDraftAction;
180 COMPOSE_WRITE_FOR_SEND,
181 COMPOSE_WRITE_FOR_STORE
184 #define B64_LINE_SIZE 57
185 #define B64_BUFFSIZE 77
187 #define MAX_REFERENCES_LEN 999
189 static GList *compose_list = NULL;
191 Compose *compose_generic_new (PrefsAccount *account,
194 GPtrArray *attach_files,
195 GList *listAddress );
197 static Compose *compose_create (PrefsAccount *account,
200 static GtkWidget *compose_account_option_menu_create
202 static void compose_set_out_encoding (Compose *compose);
203 static void compose_set_template_menu (Compose *compose);
204 static void compose_template_apply (Compose *compose,
207 static void compose_destroy (Compose *compose);
209 static void compose_entries_set (Compose *compose,
210 const gchar *mailto);
211 static gint compose_parse_header (Compose *compose,
213 static gchar *compose_parse_references (const gchar *ref,
216 static gchar *compose_quote_fmt (Compose *compose,
223 static void compose_reply_set_entry (Compose *compose,
229 followup_and_reply_to);
230 static void compose_reedit_set_entry (Compose *compose,
233 static void compose_insert_sig (Compose *compose,
235 static gchar *compose_get_signature_str (Compose *compose);
236 static ComposeInsertResult compose_insert_file (Compose *compose,
239 static void compose_attach_append (Compose *compose,
242 const gchar *content_type);
243 static void compose_attach_parts (Compose *compose,
246 static void compose_beautify_paragraph (Compose *compose,
247 GtkTextIter *par_iter,
249 static void compose_wrap_all (Compose *compose);
250 static void compose_wrap_all_full (Compose *compose,
253 static void compose_set_title (Compose *compose);
254 static void compose_select_account (Compose *compose,
255 PrefsAccount *account,
258 static PrefsAccount *compose_current_mail_account(void);
259 /* static gint compose_send (Compose *compose); */
260 static gboolean compose_check_for_valid_recipient
262 static gboolean compose_check_entries (Compose *compose,
263 gboolean check_subject);
264 static gint compose_write_to_file (Compose *compose,
267 static gint compose_write_body_to_file (Compose *compose,
269 static gint compose_remove_reedit_target (Compose *compose);
270 void compose_remove_draft (Compose *compose);
271 static gint compose_queue (Compose *compose,
274 static gint compose_queue_sub (Compose *compose,
277 gboolean check_subject);
278 static void compose_add_attachments (Compose *compose,
280 static gchar *compose_get_header (Compose *compose);
282 static void compose_convert_header (Compose *compose,
287 gboolean addr_field);
289 static void compose_attach_info_free (AttachInfo *ainfo);
290 static void compose_attach_remove_selected (Compose *compose);
292 static void compose_attach_property (Compose *compose);
293 static void compose_attach_property_create (gboolean *cancelled);
294 static void attach_property_ok (GtkWidget *widget,
295 gboolean *cancelled);
296 static void attach_property_cancel (GtkWidget *widget,
297 gboolean *cancelled);
298 static gint attach_property_delete_event (GtkWidget *widget,
300 gboolean *cancelled);
301 static gboolean attach_property_key_pressed (GtkWidget *widget,
303 gboolean *cancelled);
305 static void compose_exec_ext_editor (Compose *compose);
307 static gint compose_exec_ext_editor_real (const gchar *file);
308 static gboolean compose_ext_editor_kill (Compose *compose);
309 static gboolean compose_input_cb (GIOChannel *source,
310 GIOCondition condition,
312 static void compose_set_ext_editor_sensitive (Compose *compose,
314 #endif /* G_OS_UNIX */
316 static void compose_undo_state_changed (UndoMain *undostruct,
321 static void compose_create_header_entry (Compose *compose);
322 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
323 static void compose_update_priority_menu_item(Compose * compose);
325 static void compose_add_field_list ( Compose *compose,
326 GList *listAddress );
328 /* callback functions */
330 static gboolean compose_edit_size_alloc (GtkEditable *widget,
331 GtkAllocation *allocation,
332 GtkSHRuler *shruler);
333 static void account_activated (GtkMenuItem *menuitem,
335 static void attach_selected (GtkTreeView *tree_view,
336 GtkTreePath *tree_path,
337 GtkTreeViewColumn *column,
339 static gboolean attach_button_pressed (GtkWidget *widget,
340 GdkEventButton *event,
342 static gboolean attach_key_pressed (GtkWidget *widget,
346 static void compose_send_cb (gpointer data,
349 static void compose_send_later_cb (gpointer data,
353 static void compose_draft_cb (gpointer data,
357 static void compose_attach_cb (gpointer data,
360 static void compose_insert_file_cb (gpointer data,
363 static void compose_insert_sig_cb (gpointer data,
367 static void compose_close_cb (gpointer data,
371 static void compose_set_encoding_cb (gpointer data,
375 static void compose_address_cb (gpointer data,
378 static void compose_template_activate_cb(GtkWidget *widget,
381 static void compose_ext_editor_cb (gpointer data,
385 static gint compose_delete_cb (GtkWidget *widget,
389 static void compose_undo_cb (Compose *compose);
390 static void compose_redo_cb (Compose *compose);
391 static void compose_cut_cb (Compose *compose);
392 static void compose_copy_cb (Compose *compose);
393 static void compose_paste_cb (Compose *compose);
394 static void compose_paste_as_quote_cb (Compose *compose);
395 static void compose_paste_no_wrap_cb (Compose *compose);
396 static void compose_paste_wrap_cb (Compose *compose);
397 static void compose_allsel_cb (Compose *compose);
399 static void compose_advanced_action_cb (Compose *compose,
400 ComposeCallAdvancedAction action);
402 static void compose_grab_focus_cb (GtkWidget *widget,
405 static void compose_changed_cb (GtkTextBuffer *textbuf,
408 static void compose_wrap_cb (gpointer data,
411 static void compose_toggle_autowrap_cb (gpointer data,
415 static void compose_toggle_ruler_cb (gpointer data,
418 static void compose_toggle_sign_cb (gpointer data,
421 static void compose_toggle_encrypt_cb (gpointer data,
424 static void compose_set_privacy_system_cb(GtkWidget *widget,
426 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
427 static void activate_privacy_system (Compose *compose,
428 PrefsAccount *account,
430 static void compose_use_signing(Compose *compose, gboolean use_signing);
431 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
432 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
434 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
436 static void compose_set_priority_cb (gpointer data,
440 static void compose_attach_drag_received_cb (GtkWidget *widget,
441 GdkDragContext *drag_context,
444 GtkSelectionData *data,
448 static void compose_insert_drag_received_cb (GtkWidget *widget,
449 GdkDragContext *drag_context,
452 GtkSelectionData *data,
456 static void compose_header_drag_received_cb (GtkWidget *widget,
457 GdkDragContext *drag_context,
460 GtkSelectionData *data,
465 static gboolean compose_drag_drop (GtkWidget *widget,
466 GdkDragContext *drag_context,
468 guint time, gpointer user_data);
470 static void text_inserted (GtkTextBuffer *buffer,
475 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
476 gboolean to_all, gboolean to_ml,
478 gboolean followup_and_reply_to,
481 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
482 ComposeHeaderEntry *headerentry);
483 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
485 ComposeHeaderEntry *headerentry);
487 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
489 static void compose_allow_user_actions (Compose *compose, gboolean allow);
492 static void compose_check_all (Compose *compose);
493 static void compose_highlight_all (Compose *compose);
494 static void compose_check_backwards (Compose *compose);
495 static void compose_check_forwards_go (Compose *compose);
498 static gint compose_defer_auto_save_draft (Compose *compose);
499 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
501 static gboolean compose_close (Compose *compose);
503 static GtkItemFactoryEntry compose_popup_entries[] =
505 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
506 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
507 {N_("/---"), NULL, NULL, 0, "<Separator>"},
508 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
511 static GtkItemFactoryEntry compose_entries[] =
513 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
514 {N_("/_Message/_Send"), "<control>Return",
515 compose_send_cb, 0, NULL},
516 {N_("/_Message/Send _later"), "<shift><control>S",
517 compose_send_later_cb, 0, NULL},
518 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
519 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
520 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
521 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
522 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Message/_Save"),
524 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
525 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
528 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
529 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
530 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
531 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
532 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
533 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
534 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
535 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
536 {N_("/_Edit/Special paste/as _quotation"),
537 NULL, compose_paste_as_quote_cb, 0, NULL},
538 {N_("/_Edit/Special paste/_wrapped"),
539 NULL, compose_paste_wrap_cb, 0, NULL},
540 {N_("/_Edit/Special paste/_unwrapped"),
541 NULL, compose_paste_no_wrap_cb, 0, NULL},
542 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
543 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
544 {N_("/_Edit/A_dvanced/Move a character backward"),
546 compose_advanced_action_cb,
547 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
549 {N_("/_Edit/A_dvanced/Move a character forward"),
551 compose_advanced_action_cb,
552 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
554 {N_("/_Edit/A_dvanced/Move a word backward"),
556 compose_advanced_action_cb,
557 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
559 {N_("/_Edit/A_dvanced/Move a word forward"),
561 compose_advanced_action_cb,
562 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
564 {N_("/_Edit/A_dvanced/Move to beginning of line"),
565 NULL, /* "<control>A" */
566 compose_advanced_action_cb,
567 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
569 {N_("/_Edit/A_dvanced/Move to end of line"),
571 compose_advanced_action_cb,
572 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
574 {N_("/_Edit/A_dvanced/Move to previous line"),
576 compose_advanced_action_cb,
577 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
579 {N_("/_Edit/A_dvanced/Move to next line"),
581 compose_advanced_action_cb,
582 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
584 {N_("/_Edit/A_dvanced/Delete a character backward"),
586 compose_advanced_action_cb,
587 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
589 {N_("/_Edit/A_dvanced/Delete a character forward"),
591 compose_advanced_action_cb,
592 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
594 {N_("/_Edit/A_dvanced/Delete a word backward"),
595 NULL, /* "<control>W" */
596 compose_advanced_action_cb,
597 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
599 {N_("/_Edit/A_dvanced/Delete a word forward"),
600 NULL, /* "<alt>D", */
601 compose_advanced_action_cb,
602 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
604 {N_("/_Edit/A_dvanced/Delete line"),
606 compose_advanced_action_cb,
607 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
609 {N_("/_Edit/A_dvanced/Delete entire line"),
611 compose_advanced_action_cb,
612 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
614 {N_("/_Edit/A_dvanced/Delete to end of line"),
616 compose_advanced_action_cb,
617 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
619 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
620 {N_("/_Edit/_Wrap current paragraph"),
621 "<control>L", compose_wrap_cb, 0, NULL},
622 {N_("/_Edit/Wrap all long _lines"),
623 "<control><alt>L", compose_wrap_cb, 1, NULL},
624 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
625 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
626 {N_("/_Edit/Edit with e_xternal editor"),
627 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
629 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
630 {N_("/_Spelling/_Check all or check selection"),
631 NULL, compose_check_all, 0, NULL},
632 {N_("/_Spelling/_Highlight all misspelled words"),
633 NULL, compose_highlight_all, 0, NULL},
634 {N_("/_Spelling/Check _backwards misspelled word"),
635 NULL, compose_check_backwards , 0, NULL},
636 {N_("/_Spelling/_Forward to next misspelled word"),
637 NULL, compose_check_forwards_go, 0, NULL},
639 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
642 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
643 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
644 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
648 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
649 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
650 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
651 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
655 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
657 #define ENC_ACTION(action) \
658 NULL, compose_set_encoding_cb, action, \
659 "/Options/Character encoding/Automatic"
661 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
662 {N_("/_Options/Character _encoding/_Automatic"),
663 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
664 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
667 ENC_ACTION(C_US_ASCII)},
668 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
669 ENC_ACTION(C_UTF_8)},
670 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
672 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
673 ENC_ACTION(C_ISO_8859_1)},
674 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
675 ENC_ACTION(C_ISO_8859_15)},
676 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
677 ENC_ACTION(C_WINDOWS_1252)},
678 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
680 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
681 ENC_ACTION(C_ISO_8859_2)},
682 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
684 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
685 ENC_ACTION(C_ISO_8859_13)},
686 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
687 ENC_ACTION(C_ISO_8859_4)},
688 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
690 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
691 ENC_ACTION(C_ISO_8859_7)},
692 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
694 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
695 ENC_ACTION(C_ISO_8859_8)},
696 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
697 ENC_ACTION(C_WINDOWS_1255)},
698 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
700 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
701 ENC_ACTION(C_ISO_8859_9)},
702 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
704 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
705 ENC_ACTION(C_ISO_8859_5)},
706 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
707 ENC_ACTION(C_KOI8_R)},
708 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
709 ENC_ACTION(C_KOI8_U)},
710 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
711 ENC_ACTION(C_WINDOWS_1251)},
712 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
714 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
715 ENC_ACTION(C_ISO_2022_JP)},
716 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
718 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
719 ENC_ACTION(C_GB2312)},
720 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
722 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
724 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
725 ENC_ACTION(C_EUC_TW)},
726 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
728 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
729 ENC_ACTION(C_EUC_KR)},
730 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
732 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
733 ENC_ACTION(C_TIS_620)},
734 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
735 ENC_ACTION(C_WINDOWS_874)},
737 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
738 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
739 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
740 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
741 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
742 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
743 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
746 static GtkTargetEntry compose_mime_types[] =
748 {"text/uri-list", 0, 0},
749 {"text/plain", 0, 0},
753 static gboolean compose_put_existing_to_front(MsgInfo *info)
755 GList *compose_list = compose_get_compose_list();
759 for (elem = compose_list; elem != NULL && elem->data != NULL;
761 Compose *c = (Compose*)elem->data;
763 if (!c->targetinfo || !c->targetinfo->msgid ||
767 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
768 gtkut_window_popup(c->window);
776 static GdkColor quote_color =
777 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
779 static GdkColor signature_color = {
786 static GdkColor uri_color = {
793 static void compose_create_tags(GtkTextView *text, Compose *compose)
795 GtkTextBuffer *buffer;
796 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
798 buffer = gtk_text_view_get_buffer(text);
800 if (prefs_common.enable_color) {
801 /* grab the quote colors, converting from an int to a GdkColor */
802 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
804 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
806 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
809 signature_color = quote_color = uri_color = black;
812 gtk_text_buffer_create_tag(buffer, "quote",
813 "foreground-gdk", "e_color,
815 gtk_text_buffer_create_tag(buffer, "signature",
816 "foreground-gdk", &signature_color,
818 gtk_text_buffer_create_tag(buffer, "link",
819 "foreground-gdk", &uri_color,
821 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
822 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
825 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
826 GPtrArray *attach_files)
828 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
831 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
833 return compose_generic_new(account, NULL, item, NULL, NULL);
836 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
838 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
841 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
842 GPtrArray *attach_files, GList *listAddress )
845 GtkTextView *textview;
846 GtkTextBuffer *textbuf;
848 GtkItemFactory *ifactory;
850 if (item && item->prefs && item->prefs->enable_default_account)
851 account = account_find_from_id(item->prefs->default_account);
853 if (!account) account = cur_account;
854 g_return_val_if_fail(account != NULL, NULL);
856 compose = compose_create(account, COMPOSE_NEW);
857 ifactory = gtk_item_factory_from_widget(compose->menubar);
859 compose->replyinfo = NULL;
860 compose->fwdinfo = NULL;
862 textview = GTK_TEXT_VIEW(compose->text);
863 textbuf = gtk_text_view_get_buffer(textview);
864 compose_create_tags(textview, compose);
866 undo_block(compose->undostruct);
868 if (item && item->prefs && item->prefs->enable_default_dictionary &&
870 gtkaspell_change_dict(compose->gtkaspell,
871 item->prefs->default_dictionary);
874 if (account->auto_sig)
875 compose_insert_sig(compose, FALSE);
876 gtk_text_buffer_get_start_iter(textbuf, &iter);
877 gtk_text_buffer_place_cursor(textbuf, &iter);
879 if (account->protocol != A_NNTP) {
880 if (mailto && *mailto != '\0') {
881 compose_entries_set(compose, mailto);
883 } else if (item && item->prefs->enable_default_to) {
884 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
885 compose_entry_mark_default_to(compose, item->prefs->default_to);
887 if (item && item->ret_rcpt) {
888 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
892 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
894 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
897 * CLAWS: just don't allow return receipt request, even if the user
898 * may want to send an email. simple but foolproof.
900 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
902 compose_add_field_list( compose, listAddress );
908 for (i = 0; i < attach_files->len; i++) {
909 file = g_ptr_array_index(attach_files, i);
910 compose_attach_append(compose, file, file, NULL);
914 compose_show_first_last_header(compose, TRUE);
916 /* Set save folder */
917 if (item && item->prefs && item->prefs->save_copy_to_folder) {
918 gchar *folderidentifier;
920 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
921 folderidentifier = folder_item_get_identifier(item);
922 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
923 g_free(folderidentifier);
926 gtk_widget_grab_focus(compose->header_last->entry);
928 undo_unblock(compose->undostruct);
930 if (prefs_common.auto_exteditor)
931 compose_exec_ext_editor(compose);
933 compose->modified = FALSE;
934 compose_set_title(compose);
938 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
939 gboolean override_pref)
941 gchar *privacy = NULL;
943 g_return_if_fail(compose != NULL);
944 g_return_if_fail(account != NULL);
946 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
949 if (account->default_privacy_system
950 && strlen(account->default_privacy_system)) {
951 privacy = account->default_privacy_system;
953 GSList *privacy_avail = privacy_get_system_ids();
954 if (privacy_avail && g_slist_length(privacy_avail)) {
955 privacy = (gchar *)(privacy_avail->data);
958 if (privacy != NULL) {
959 compose->privacy_system = g_strdup(privacy);
960 compose_update_privacy_system_menu_item(compose, FALSE);
961 compose_use_encryption(compose, TRUE);
965 static void compose_force_signing(Compose *compose, PrefsAccount *account)
967 gchar *privacy = NULL;
969 if (account->default_privacy_system
970 && strlen(account->default_privacy_system)) {
971 privacy = account->default_privacy_system;
973 GSList *privacy_avail = privacy_get_system_ids();
974 if (privacy_avail && g_slist_length(privacy_avail)) {
975 privacy = (gchar *)(privacy_avail->data);
978 if (privacy != NULL) {
979 compose->privacy_system = g_strdup(privacy);
980 compose_update_privacy_system_menu_item(compose, FALSE);
981 compose_use_signing(compose, TRUE);
985 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
989 Compose *compose = NULL;
990 g_return_val_if_fail(msginfo_list != NULL, NULL);
992 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
993 g_return_val_if_fail(msginfo != NULL, NULL);
995 list_len = g_slist_length(msginfo_list);
999 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1000 FALSE, prefs_common.default_reply_list, FALSE, body);
1002 case COMPOSE_REPLY_WITH_QUOTE:
1003 compose = compose_reply(msginfo, TRUE,
1004 FALSE, prefs_common.default_reply_list, FALSE, body);
1006 case COMPOSE_REPLY_WITHOUT_QUOTE:
1007 compose = compose_reply(msginfo, FALSE,
1008 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1010 case COMPOSE_REPLY_TO_SENDER:
1011 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1012 FALSE, FALSE, TRUE, body);
1014 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1015 compose = compose_followup_and_reply_to(msginfo,
1016 prefs_common.reply_with_quote,
1017 FALSE, FALSE, body);
1019 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1020 compose = compose_reply(msginfo, TRUE,
1021 FALSE, FALSE, TRUE, body);
1023 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1024 compose = compose_reply(msginfo, FALSE,
1025 FALSE, FALSE, TRUE, NULL);
1027 case COMPOSE_REPLY_TO_ALL:
1028 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1029 TRUE, FALSE, FALSE, body);
1031 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1032 compose = compose_reply(msginfo, TRUE,
1033 TRUE, FALSE, FALSE, body);
1035 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1036 compose = compose_reply(msginfo, FALSE,
1037 TRUE, FALSE, FALSE, NULL);
1039 case COMPOSE_REPLY_TO_LIST:
1040 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1041 FALSE, TRUE, FALSE, body);
1043 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1044 compose = compose_reply(msginfo, TRUE,
1045 FALSE, TRUE, FALSE, body);
1047 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1048 compose = compose_reply(msginfo, FALSE,
1049 FALSE, TRUE, FALSE, NULL);
1051 case COMPOSE_FORWARD:
1052 if (prefs_common.forward_as_attachment) {
1053 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1056 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1060 case COMPOSE_FORWARD_INLINE:
1061 /* check if we reply to more than one Message */
1062 if (list_len == 1) {
1063 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1066 /* more messages FALL THROUGH */
1067 case COMPOSE_FORWARD_AS_ATTACH:
1068 compose = compose_forward_multiple(NULL, msginfo_list);
1070 case COMPOSE_REDIRECT:
1071 compose = compose_redirect(NULL, msginfo);
1074 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1079 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1080 gboolean to_ml, gboolean to_sender,
1083 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1084 to_sender, FALSE, body);
1087 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1092 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1093 to_sender, TRUE, body);
1096 static void compose_extract_original_charset(Compose *compose)
1098 MsgInfo *info = NULL;
1099 if (compose->replyinfo) {
1100 info = compose->replyinfo;
1101 } else if (compose->fwdinfo) {
1102 info = compose->fwdinfo;
1103 } else if (compose->targetinfo) {
1104 info = compose->targetinfo;
1107 MimeInfo *mimeinfo = procmime_scan_message(info);
1108 MimeInfo *partinfo = mimeinfo;
1109 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1110 partinfo = procmime_mimeinfo_next(partinfo);
1112 compose->orig_charset =
1113 g_strdup(procmime_mimeinfo_get_parameter(
1114 partinfo, "charset"));
1116 procmime_mimeinfo_free_all(mimeinfo);
1120 #define SIGNAL_BLOCK(buffer) { \
1121 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1122 G_CALLBACK(compose_changed_cb), \
1124 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1125 G_CALLBACK(text_inserted), \
1129 #define SIGNAL_UNBLOCK(buffer) { \
1130 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1131 G_CALLBACK(compose_changed_cb), \
1133 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1134 G_CALLBACK(text_inserted), \
1138 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1139 gboolean to_all, gboolean to_ml,
1141 gboolean followup_and_reply_to,
1144 GtkItemFactory *ifactory;
1146 PrefsAccount *account = NULL;
1147 PrefsAccount *reply_account;
1148 GtkTextView *textview;
1149 GtkTextBuffer *textbuf;
1151 g_return_val_if_fail(msginfo != NULL, NULL);
1152 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1154 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1156 g_return_val_if_fail(account != NULL, NULL);
1158 if (to_sender && account->protocol == A_NNTP &&
1159 !followup_and_reply_to) {
1161 account_find_from_address(account->address);
1163 reply_account = compose_current_mail_account();
1167 reply_account = account;
1169 compose = compose_create(account, COMPOSE_REPLY);
1170 ifactory = gtk_item_factory_from_widget(compose->menubar);
1172 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1173 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1175 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1177 if (!compose->replyinfo)
1178 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1180 compose_extract_original_charset(compose);
1182 if (msginfo->folder && msginfo->folder->ret_rcpt)
1183 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1185 /* Set save folder */
1186 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1187 gchar *folderidentifier;
1189 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1190 folderidentifier = folder_item_get_identifier(msginfo->folder);
1191 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1192 g_free(folderidentifier);
1195 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1196 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1197 to_sender, followup_and_reply_to);
1198 compose_show_first_last_header(compose, TRUE);
1200 textview = (GTK_TEXT_VIEW(compose->text));
1201 textbuf = gtk_text_view_get_buffer(textview);
1202 compose_create_tags(textview, compose);
1204 undo_block(compose->undostruct);
1206 if (msginfo->folder && msginfo->folder->prefs &&
1207 msginfo->folder->prefs &&
1208 msginfo->folder->prefs->enable_default_dictionary &&
1210 gtkaspell_change_dict(compose->gtkaspell,
1211 msginfo->folder->prefs->default_dictionary);
1217 if (prefs_common.quotemark && *prefs_common.quotemark)
1218 qmark = prefs_common.quotemark;
1222 compose_quote_fmt(compose, compose->replyinfo,
1223 prefs_common.quotefmt,
1224 qmark, body, FALSE);
1226 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1227 compose_force_encryption(compose, account, FALSE);
1230 SIGNAL_BLOCK(textbuf);
1232 if (account->auto_sig)
1233 compose_insert_sig(compose, FALSE);
1235 compose_wrap_all(compose);
1237 SIGNAL_UNBLOCK(textbuf);
1239 gtk_widget_grab_focus(compose->text);
1241 undo_unblock(compose->undostruct);
1243 if (prefs_common.auto_exteditor)
1244 compose_exec_ext_editor(compose);
1246 compose->modified = FALSE;
1247 compose_set_title(compose);
1251 #define INSERT_FW_HEADER(var, hdr) \
1252 if (msginfo->var && *msginfo->var) { \
1253 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1254 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1255 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1258 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1259 gboolean as_attach, const gchar *body,
1260 gboolean no_extedit)
1263 GtkTextView *textview;
1264 GtkTextBuffer *textbuf;
1267 g_return_val_if_fail(msginfo != NULL, NULL);
1268 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1271 !(account = compose_guess_forward_account_from_msginfo
1273 account = cur_account;
1275 compose = compose_create(account, COMPOSE_FORWARD);
1277 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1278 if (!compose->fwdinfo)
1279 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1281 compose_extract_original_charset(compose);
1283 if (msginfo->subject && *msginfo->subject) {
1284 gchar *buf, *buf2, *p;
1286 buf = p = g_strdup(msginfo->subject);
1287 p += subject_get_prefix_length(p);
1288 memmove(buf, p, strlen(p) + 1);
1290 buf2 = g_strdup_printf("Fw: %s", buf);
1291 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1297 textview = GTK_TEXT_VIEW(compose->text);
1298 textbuf = gtk_text_view_get_buffer(textview);
1299 compose_create_tags(textview, compose);
1301 undo_block(compose->undostruct);
1305 msgfile = procmsg_get_message_file_path(msginfo);
1306 if (!is_file_exist(msgfile))
1307 g_warning("%s: file not exist\n", msgfile);
1309 compose_attach_append(compose, msgfile, msgfile,
1315 MsgInfo *full_msginfo;
1317 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1319 full_msginfo = procmsg_msginfo_copy(msginfo);
1321 if (prefs_common.fw_quotemark &&
1322 *prefs_common.fw_quotemark)
1323 qmark = prefs_common.fw_quotemark;
1327 compose_quote_fmt(compose, full_msginfo,
1328 prefs_common.fw_quotefmt,
1329 qmark, body, FALSE);
1330 compose_attach_parts(compose, msginfo);
1332 procmsg_msginfo_free(full_msginfo);
1335 SIGNAL_BLOCK(textbuf);
1337 if (account->auto_sig)
1338 compose_insert_sig(compose, FALSE);
1340 compose_wrap_all(compose);
1342 SIGNAL_UNBLOCK(textbuf);
1344 gtk_text_buffer_get_start_iter(textbuf, &iter);
1345 gtk_text_buffer_place_cursor(textbuf, &iter);
1347 gtk_widget_grab_focus(compose->header_last->entry);
1349 if (!no_extedit && prefs_common.auto_exteditor)
1350 compose_exec_ext_editor(compose);
1353 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1354 gchar *folderidentifier;
1356 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1357 folderidentifier = folder_item_get_identifier(msginfo->folder);
1358 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1359 g_free(folderidentifier);
1362 undo_unblock(compose->undostruct);
1364 compose->modified = FALSE;
1365 compose_set_title(compose);
1369 #undef INSERT_FW_HEADER
1371 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1374 GtkTextView *textview;
1375 GtkTextBuffer *textbuf;
1379 gboolean single_mail = TRUE;
1381 g_return_val_if_fail(msginfo_list != NULL, NULL);
1383 if (g_slist_length(msginfo_list) > 1)
1384 single_mail = FALSE;
1386 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1387 if (((MsgInfo *)msginfo->data)->folder == NULL)
1390 /* guess account from first selected message */
1392 !(account = compose_guess_forward_account_from_msginfo
1393 (msginfo_list->data)))
1394 account = cur_account;
1396 g_return_val_if_fail(account != NULL, NULL);
1398 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1399 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1400 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1403 compose = compose_create(account, COMPOSE_FORWARD);
1405 textview = GTK_TEXT_VIEW(compose->text);
1406 textbuf = gtk_text_view_get_buffer(textview);
1407 compose_create_tags(textview, compose);
1409 undo_block(compose->undostruct);
1410 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1411 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1412 if (!is_file_exist(msgfile))
1413 g_warning("%s: file not exist\n", msgfile);
1415 compose_attach_append(compose, msgfile, msgfile,
1421 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1422 if (info->subject && *info->subject) {
1423 gchar *buf, *buf2, *p;
1425 buf = p = g_strdup(info->subject);
1426 p += subject_get_prefix_length(p);
1427 memmove(buf, p, strlen(p) + 1);
1429 buf2 = g_strdup_printf("Fw: %s", buf);
1430 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1436 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1437 _("Fw: multiple emails"));
1440 SIGNAL_BLOCK(textbuf);
1442 if (account->auto_sig)
1443 compose_insert_sig(compose, FALSE);
1445 compose_wrap_all(compose);
1447 SIGNAL_UNBLOCK(textbuf);
1449 gtk_text_buffer_get_start_iter(textbuf, &iter);
1450 gtk_text_buffer_place_cursor(textbuf, &iter);
1452 gtk_widget_grab_focus(compose->header_last->entry);
1453 undo_unblock(compose->undostruct);
1454 compose->modified = FALSE;
1455 compose_set_title(compose);
1459 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1461 GtkTextIter start = *iter;
1462 GtkTextIter end_iter;
1463 int start_pos = gtk_text_iter_get_offset(&start);
1465 if (!compose->account->sig_sep)
1468 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1469 start_pos+strlen(compose->account->sig_sep));
1471 /* check sig separator */
1472 str = gtk_text_iter_get_text(&start, &end_iter);
1473 if (!strcmp(str, compose->account->sig_sep)) {
1475 /* check end of line (\n) */
1476 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1477 start_pos+strlen(compose->account->sig_sep));
1478 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1479 start_pos+strlen(compose->account->sig_sep)+1);
1480 tmp = gtk_text_iter_get_text(&start, &end_iter);
1481 if (!strcmp(tmp,"\n")) {
1493 static void compose_colorize_signature(Compose *compose)
1495 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1497 GtkTextIter end_iter;
1498 gtk_text_buffer_get_start_iter(buffer, &iter);
1499 while (gtk_text_iter_forward_line(&iter))
1500 if (compose_is_sig_separator(compose, buffer, &iter)) {
1501 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1502 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1506 void compose_reedit(MsgInfo *msginfo)
1508 Compose *compose = NULL;
1509 PrefsAccount *account = NULL;
1510 GtkTextView *textview;
1511 GtkTextBuffer *textbuf;
1515 gchar buf[BUFFSIZE];
1516 gboolean use_signing = FALSE;
1517 gboolean use_encryption = FALSE;
1518 gchar *privacy_system = NULL;
1520 g_return_if_fail(msginfo != NULL);
1521 g_return_if_fail(msginfo->folder != NULL);
1523 if (compose_put_existing_to_front(msginfo))
1526 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1527 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1528 gchar queueheader_buf[BUFFSIZE];
1531 /* Select Account from queue headers */
1532 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1533 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1534 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1535 account = account_find_from_id(id);
1537 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1538 sizeof(queueheader_buf), "NAID:")) {
1539 id = atoi(&queueheader_buf[strlen("NAID:")]);
1540 account = account_find_from_id(id);
1542 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1543 sizeof(queueheader_buf), "MAID:")) {
1544 id = atoi(&queueheader_buf[strlen("MAID:")]);
1545 account = account_find_from_id(id);
1547 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1548 sizeof(queueheader_buf), "S:")) {
1549 account = account_find_from_address(queueheader_buf);
1551 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1552 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1553 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1554 use_signing = param;
1557 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1558 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1559 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1560 use_encryption = param;
1562 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1563 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1564 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1566 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1567 sizeof(queueheader_buf), "X-Priority: ")) {
1568 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1569 compose->priority = param;
1572 account = msginfo->folder->folder->account;
1574 if (!account && prefs_common.reedit_account_autosel) {
1575 gchar from[BUFFSIZE];
1576 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1577 extract_address(from);
1578 account = account_find_from_address(from);
1581 if (!account) account = cur_account;
1582 g_return_if_fail(account != NULL);
1584 compose = compose_create(account, COMPOSE_REEDIT);
1585 if (privacy_system != NULL) {
1586 compose->privacy_system = privacy_system;
1587 compose_use_signing(compose, use_signing);
1588 compose_use_encryption(compose, use_encryption);
1589 compose_update_privacy_system_menu_item(compose, FALSE);
1591 activate_privacy_system(compose, account, FALSE);
1593 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1595 compose_extract_original_charset(compose);
1597 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1598 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1599 gchar queueheader_buf[BUFFSIZE];
1601 /* Set message save folder */
1602 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1605 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1606 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1607 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1609 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1610 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1612 GtkItemFactory *ifactory;
1613 ifactory = gtk_item_factory_from_widget(compose->menubar);
1614 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1619 if (compose_parse_header(compose, msginfo) < 0) return;
1620 compose_reedit_set_entry(compose, msginfo);
1622 textview = GTK_TEXT_VIEW(compose->text);
1623 textbuf = gtk_text_view_get_buffer(textview);
1624 compose_create_tags(textview, compose);
1626 mark = gtk_text_buffer_get_insert(textbuf);
1627 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1629 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1630 G_CALLBACK(compose_changed_cb),
1633 if (procmime_msginfo_is_encrypted(msginfo)) {
1634 fp = procmime_get_first_encrypted_text_content(msginfo);
1636 compose_force_encryption(compose, account, TRUE);
1638 fp = procmime_get_first_text_content(msginfo);
1640 g_warning("Can't get text part\n");
1643 gboolean prev_autowrap = compose->autowrap;
1645 compose->autowrap = FALSE;
1646 while (fgets(buf, sizeof(buf), fp) != NULL) {
1648 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1650 compose_wrap_all_full(compose, FALSE);
1651 compose->autowrap = prev_autowrap;
1655 compose_attach_parts(compose, msginfo);
1657 compose_colorize_signature(compose);
1659 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1660 G_CALLBACK(compose_changed_cb),
1663 gtk_widget_grab_focus(compose->text);
1665 if (prefs_common.auto_exteditor)
1666 compose_exec_ext_editor(compose);
1667 compose->modified = FALSE;
1668 compose_set_title(compose);
1671 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1675 GtkItemFactory *ifactory;
1678 g_return_val_if_fail(msginfo != NULL, NULL);
1681 account = account_get_reply_account(msginfo,
1682 prefs_common.reply_account_autosel);
1683 g_return_val_if_fail(account != NULL, NULL);
1685 compose = compose_create(account, COMPOSE_REDIRECT);
1686 ifactory = gtk_item_factory_from_widget(compose->menubar);
1687 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1688 compose->replyinfo = NULL;
1689 compose->fwdinfo = NULL;
1691 compose_show_first_last_header(compose, TRUE);
1693 gtk_widget_grab_focus(compose->header_last->entry);
1695 filename = procmsg_get_message_file_path(msginfo);
1696 if (filename == NULL)
1699 compose->redirect_filename = filename;
1701 /* Set save folder */
1702 item = msginfo->folder;
1703 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1704 gchar *folderidentifier;
1706 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1707 folderidentifier = folder_item_get_identifier(item);
1708 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1709 g_free(folderidentifier);
1712 compose_attach_parts(compose, msginfo);
1714 if (msginfo->subject)
1715 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1717 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1719 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1720 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1722 compose_colorize_signature(compose);
1724 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1725 menu_set_sensitive(ifactory, "/Add...", FALSE);
1726 menu_set_sensitive(ifactory, "/Remove", FALSE);
1727 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1729 ifactory = gtk_item_factory_from_widget(compose->menubar);
1730 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1731 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1732 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1733 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1734 menu_set_sensitive(ifactory, "/Edit", FALSE);
1735 menu_set_sensitive(ifactory, "/Options", FALSE);
1736 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1737 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1739 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1740 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1741 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1742 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1743 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1744 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1745 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1747 compose->modified = FALSE;
1748 compose_set_title(compose);
1752 GList *compose_get_compose_list(void)
1754 return compose_list;
1757 void compose_entry_append(Compose *compose, const gchar *address,
1758 ComposeEntryType type)
1762 gboolean in_quote = FALSE;
1763 if (!address || *address == '\0') return;
1770 header = N_("Bcc:");
1772 case COMPOSE_REPLYTO:
1773 header = N_("Reply-To:");
1775 case COMPOSE_NEWSGROUPS:
1776 header = N_("Newsgroups:");
1778 case COMPOSE_FOLLOWUPTO:
1779 header = N_( "Followup-To:");
1786 header = prefs_common.trans_hdr ? gettext(header) : header;
1788 cur = begin = (gchar *)address;
1790 /* we separate the line by commas, but not if we're inside a quoted
1792 while (*cur != '\0') {
1794 in_quote = !in_quote;
1795 if (*cur == ',' && !in_quote) {
1796 gchar *tmp = g_strdup(begin);
1798 tmp[cur-begin]='\0';
1803 compose_add_header_entry(compose, header, tmp);
1810 gchar *tmp = g_strdup(begin);
1812 tmp[cur-begin]='\0';
1817 compose_add_header_entry(compose, header, tmp);
1822 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1824 static GtkStyle *bold_style = NULL;
1825 static GdkColor bold_color;
1829 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1830 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1831 if (gtk_entry_get_text(entry) &&
1832 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1833 gtk_widget_ensure_style(GTK_WIDGET(entry));
1835 gtkut_convert_int_to_gdk_color
1836 (prefs_common.color_new, &bold_color);
1837 bold_style = gtk_style_copy(gtk_widget_get_style
1838 (GTK_WIDGET(entry)));
1839 pango_font_description_set_weight
1840 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
1841 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1843 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1848 void compose_toolbar_cb(gint action, gpointer data)
1850 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1851 Compose *compose = (Compose*)toolbar_item->parent;
1853 g_return_if_fail(compose != NULL);
1857 compose_send_cb(compose, 0, NULL);
1860 compose_send_later_cb(compose, 0, NULL);
1863 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1866 compose_insert_file_cb(compose, 0, NULL);
1869 compose_attach_cb(compose, 0, NULL);
1872 compose_insert_sig(compose, FALSE);
1875 compose_ext_editor_cb(compose, 0, NULL);
1877 case A_LINEWRAP_CURRENT:
1878 compose_beautify_paragraph(compose, NULL, TRUE);
1880 case A_LINEWRAP_ALL:
1881 compose_wrap_all_full(compose, TRUE);
1884 compose_address_cb(compose, 0, NULL);
1887 case A_CHECK_SPELLING:
1888 compose_check_all(compose);
1896 static void compose_entries_set(Compose *compose, const gchar *mailto)
1900 gchar *subject = NULL;
1905 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1908 compose_entry_append(compose, to, COMPOSE_TO);
1910 compose_entry_append(compose, cc, COMPOSE_CC);
1912 if (!g_utf8_validate (subject, -1, NULL)) {
1913 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1914 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1917 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1921 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1922 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1925 gboolean prev_autowrap = compose->autowrap;
1927 compose->autowrap = FALSE;
1929 mark = gtk_text_buffer_get_insert(buffer);
1930 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1932 if (!g_utf8_validate (body, -1, NULL)) {
1933 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1934 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1937 gtk_text_buffer_insert(buffer, &iter, body, -1);
1939 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1941 compose->autowrap = prev_autowrap;
1942 if (compose->autowrap)
1943 compose_wrap_all(compose);
1952 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1954 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1955 {"Cc:", NULL, TRUE},
1956 {"References:", NULL, FALSE},
1957 {"Bcc:", NULL, TRUE},
1958 {"Newsgroups:", NULL, TRUE},
1959 {"Followup-To:", NULL, TRUE},
1960 {"List-Post:", NULL, FALSE},
1961 {"X-Priority:", NULL, FALSE},
1962 {NULL, NULL, FALSE}};
1978 g_return_val_if_fail(msginfo != NULL, -1);
1980 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1981 procheader_get_header_fields(fp, hentry);
1984 if (hentry[H_REPLY_TO].body != NULL) {
1985 if (hentry[H_REPLY_TO].body[0] != '\0') {
1987 conv_unmime_header(hentry[H_REPLY_TO].body,
1990 g_free(hentry[H_REPLY_TO].body);
1991 hentry[H_REPLY_TO].body = NULL;
1993 if (hentry[H_CC].body != NULL) {
1994 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1995 g_free(hentry[H_CC].body);
1996 hentry[H_CC].body = NULL;
1998 if (hentry[H_REFERENCES].body != NULL) {
1999 if (compose->mode == COMPOSE_REEDIT)
2000 compose->references = hentry[H_REFERENCES].body;
2002 compose->references = compose_parse_references
2003 (hentry[H_REFERENCES].body, msginfo->msgid);
2004 g_free(hentry[H_REFERENCES].body);
2006 hentry[H_REFERENCES].body = NULL;
2008 if (hentry[H_BCC].body != NULL) {
2009 if (compose->mode == COMPOSE_REEDIT)
2011 conv_unmime_header(hentry[H_BCC].body, NULL);
2012 g_free(hentry[H_BCC].body);
2013 hentry[H_BCC].body = NULL;
2015 if (hentry[H_NEWSGROUPS].body != NULL) {
2016 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2017 hentry[H_NEWSGROUPS].body = NULL;
2019 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2020 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2021 compose->followup_to =
2022 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2025 g_free(hentry[H_FOLLOWUP_TO].body);
2026 hentry[H_FOLLOWUP_TO].body = NULL;
2028 if (hentry[H_LIST_POST].body != NULL) {
2031 extract_address(hentry[H_LIST_POST].body);
2032 if (hentry[H_LIST_POST].body[0] != '\0') {
2033 scan_mailto_url(hentry[H_LIST_POST].body,
2034 &to, NULL, NULL, NULL, NULL);
2036 g_free(compose->ml_post);
2037 compose->ml_post = to;
2040 g_free(hentry[H_LIST_POST].body);
2041 hentry[H_LIST_POST].body = NULL;
2044 /* CLAWS - X-Priority */
2045 if (compose->mode == COMPOSE_REEDIT)
2046 if (hentry[H_X_PRIORITY].body != NULL) {
2049 priority = atoi(hentry[H_X_PRIORITY].body);
2050 g_free(hentry[H_X_PRIORITY].body);
2052 hentry[H_X_PRIORITY].body = NULL;
2054 if (priority < PRIORITY_HIGHEST ||
2055 priority > PRIORITY_LOWEST)
2056 priority = PRIORITY_NORMAL;
2058 compose->priority = priority;
2061 if (compose->mode == COMPOSE_REEDIT) {
2062 if (msginfo->inreplyto && *msginfo->inreplyto)
2063 compose->inreplyto = g_strdup(msginfo->inreplyto);
2067 if (msginfo->msgid && *msginfo->msgid)
2068 compose->inreplyto = g_strdup(msginfo->msgid);
2070 if (!compose->references) {
2071 if (msginfo->msgid && *msginfo->msgid) {
2072 if (msginfo->inreplyto && *msginfo->inreplyto)
2073 compose->references =
2074 g_strdup_printf("<%s>\n\t<%s>",
2078 compose->references =
2079 g_strconcat("<", msginfo->msgid, ">",
2081 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2082 compose->references =
2083 g_strconcat("<", msginfo->inreplyto, ">",
2091 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2093 GSList *ref_id_list, *cur;
2097 ref_id_list = references_list_append(NULL, ref);
2098 if (!ref_id_list) return NULL;
2099 if (msgid && *msgid)
2100 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2105 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2106 /* "<" + Message-ID + ">" + CR+LF+TAB */
2107 len += strlen((gchar *)cur->data) + 5;
2109 if (len > MAX_REFERENCES_LEN) {
2110 /* remove second message-ID */
2111 if (ref_id_list && ref_id_list->next &&
2112 ref_id_list->next->next) {
2113 g_free(ref_id_list->next->data);
2114 ref_id_list = g_slist_remove
2115 (ref_id_list, ref_id_list->next->data);
2117 slist_free_strings(ref_id_list);
2118 g_slist_free(ref_id_list);
2125 new_ref = g_string_new("");
2126 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2127 if (new_ref->len > 0)
2128 g_string_append(new_ref, "\n\t");
2129 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2132 slist_free_strings(ref_id_list);
2133 g_slist_free(ref_id_list);
2135 new_ref_str = new_ref->str;
2136 g_string_free(new_ref, FALSE);
2141 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2142 const gchar *fmt, const gchar *qmark,
2143 const gchar *body, gboolean rewrap)
2145 static MsgInfo dummyinfo;
2146 gchar *quote_str = NULL;
2148 gboolean prev_autowrap;
2149 const gchar *trimmed_body = body;
2150 gint cursor_pos = -1;
2151 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2152 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2157 SIGNAL_BLOCK(buffer);
2160 msginfo = &dummyinfo;
2162 if (qmark != NULL) {
2163 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2164 quote_fmt_scan_string(qmark);
2167 buf = quote_fmt_get_buffer();
2169 alertpanel_error(_("Quote mark format error."));
2171 Xstrdup_a(quote_str, buf, goto error)
2174 if (fmt && *fmt != '\0') {
2175 while (trimmed_body && strlen(trimmed_body) > 1
2176 && trimmed_body[0]=='\n')
2179 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2180 quote_fmt_scan_string(fmt);
2183 buf = quote_fmt_get_buffer();
2185 alertpanel_error(_("Message reply/forward format error."));
2191 prev_autowrap = compose->autowrap;
2192 compose->autowrap = FALSE;
2194 mark = gtk_text_buffer_get_insert(buffer);
2195 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2196 if (g_utf8_validate(buf, -1, NULL)) {
2197 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2199 gchar *tmpout = NULL;
2200 tmpout = conv_codeset_strdup
2201 (buf, conv_get_locale_charset_str(),
2203 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2205 tmpout = g_malloc(strlen(buf)*2+1);
2206 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2208 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2212 cursor_pos = quote_fmt_get_cursor_pos();
2213 compose->set_cursor_pos = cursor_pos;
2214 if (cursor_pos == -1) {
2217 gtk_text_buffer_get_start_iter(buffer, &iter);
2218 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2219 gtk_text_buffer_place_cursor(buffer, &iter);
2221 compose->autowrap = prev_autowrap;
2222 if (compose->autowrap && rewrap)
2223 compose_wrap_all(compose);
2230 SIGNAL_UNBLOCK(buffer);
2236 /* if ml_post is of type addr@host and from is of type
2237 * addr-anything@host, return TRUE
2239 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2241 gchar *left_ml = NULL;
2242 gchar *right_ml = NULL;
2243 gchar *left_from = NULL;
2244 gchar *right_from = NULL;
2245 gboolean result = FALSE;
2247 if (!ml_post || !from)
2250 left_ml = g_strdup(ml_post);
2251 if (strstr(left_ml, "@")) {
2252 right_ml = strstr(left_ml, "@")+1;
2253 *(strstr(left_ml, "@")) = '\0';
2256 left_from = g_strdup(from);
2257 if (strstr(left_from, "@")) {
2258 right_from = strstr(left_from, "@")+1;
2259 *(strstr(left_from, "@")) = '\0';
2262 if (left_ml && left_from && right_ml && right_from
2263 && !strncmp(left_from, left_ml, strlen(left_ml))
2264 && !strcmp(right_from, right_ml)) {
2273 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2275 gchar *my_addr1, *my_addr2;
2277 if (!addr1 || !addr2)
2280 Xstrdup_a(my_addr1, addr1, return FALSE);
2281 Xstrdup_a(my_addr2, addr2, return FALSE);
2283 extract_address(my_addr1);
2284 extract_address(my_addr2);
2286 return !strcmp(my_addr1, my_addr2);
2289 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2290 gboolean to_all, gboolean to_ml,
2292 gboolean followup_and_reply_to)
2294 GSList *cc_list = NULL;
2297 gchar *replyto = NULL;
2298 GHashTable *to_table;
2300 gboolean reply_to_ml = FALSE;
2301 gboolean default_reply_to = FALSE;
2303 g_return_if_fail(compose->account != NULL);
2304 g_return_if_fail(msginfo != NULL);
2306 reply_to_ml = to_ml && compose->ml_post;
2308 default_reply_to = msginfo->folder &&
2309 msginfo->folder->prefs->enable_default_reply_to;
2311 if (compose->account->protocol != A_NNTP) {
2312 if (reply_to_ml && !default_reply_to) {
2314 gboolean is_subscr = is_subscription(compose->ml_post,
2317 /* normal answer to ml post with a reply-to */
2318 compose_entry_append(compose,
2321 if (compose->replyto
2322 && !same_address(compose->ml_post, compose->replyto))
2323 compose_entry_append(compose,
2327 /* answer to subscription confirmation */
2328 if (compose->replyto)
2329 compose_entry_append(compose,
2332 else if (msginfo->from)
2333 compose_entry_append(compose,
2338 else if (!(to_all || to_sender) && default_reply_to) {
2339 compose_entry_append(compose,
2340 msginfo->folder->prefs->default_reply_to,
2342 compose_entry_mark_default_to(compose,
2343 msginfo->folder->prefs->default_reply_to);
2346 Xstrdup_a(tmp1, msginfo->from, return);
2347 extract_address(tmp1);
2348 if (to_all || to_sender ||
2349 !account_find_from_address(tmp1))
2350 compose_entry_append(compose,
2351 (compose->replyto && !to_sender)
2352 ? compose->replyto :
2353 msginfo->from ? msginfo->from : "",
2355 else if (!to_all && !to_sender) {
2356 /* reply to the last list of recipients */
2357 compose_entry_append(compose,
2358 msginfo->to ? msginfo->to : "",
2360 compose_entry_append(compose,
2361 msginfo->cc ? msginfo->cc : "",
2366 if (to_sender || (compose->followup_to &&
2367 !strncmp(compose->followup_to, "poster", 6)))
2368 compose_entry_append
2370 (compose->replyto ? compose->replyto :
2371 msginfo->from ? msginfo->from : ""),
2374 else if (followup_and_reply_to || to_all) {
2375 compose_entry_append
2377 (compose->replyto ? compose->replyto :
2378 msginfo->from ? msginfo->from : ""),
2381 compose_entry_append
2383 compose->followup_to ? compose->followup_to :
2384 compose->newsgroups ? compose->newsgroups : "",
2385 COMPOSE_NEWSGROUPS);
2388 compose_entry_append
2390 compose->followup_to ? compose->followup_to :
2391 compose->newsgroups ? compose->newsgroups : "",
2392 COMPOSE_NEWSGROUPS);
2395 if (msginfo->subject && *msginfo->subject) {
2399 buf = p = g_strdup(msginfo->subject);
2400 p += subject_get_prefix_length(p);
2401 memmove(buf, p, strlen(p) + 1);
2403 buf2 = g_strdup_printf("Re: %s", buf);
2404 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2409 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2411 if (to_ml && compose->ml_post) return;
2412 if (!to_all || compose->account->protocol == A_NNTP) return;
2414 if (compose->replyto) {
2415 Xstrdup_a(replyto, compose->replyto, return);
2416 extract_address(replyto);
2418 if (msginfo->from) {
2419 Xstrdup_a(from, msginfo->from, return);
2420 extract_address(from);
2423 if (replyto && from)
2424 cc_list = address_list_append_with_comments(cc_list, from);
2425 if (to_all && msginfo->folder &&
2426 msginfo->folder->prefs->enable_default_reply_to)
2427 cc_list = address_list_append_with_comments(cc_list,
2428 msginfo->folder->prefs->default_reply_to);
2429 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2430 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2432 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2434 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2435 if (compose->account)
2436 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2437 GINT_TO_POINTER(1));
2439 /* remove address on To: and that of current account */
2440 for (cur = cc_list; cur != NULL; ) {
2441 GSList *next = cur->next;
2444 addr = g_strdup(cur->data);
2445 extract_address(addr);
2447 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2448 cc_list = g_slist_remove(cc_list, cur->data);
2450 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2454 hash_free_strings(to_table);
2455 g_hash_table_destroy(to_table);
2458 for (cur = cc_list; cur != NULL; cur = cur->next)
2459 compose_entry_append(compose, (gchar *)cur->data,
2461 slist_free_strings(cc_list);
2462 g_slist_free(cc_list);
2467 #define SET_ENTRY(entry, str) \
2470 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2473 #define SET_ADDRESS(type, str) \
2476 compose_entry_append(compose, str, type); \
2479 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2481 g_return_if_fail(msginfo != NULL);
2483 SET_ENTRY(subject_entry, msginfo->subject);
2484 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2485 SET_ADDRESS(COMPOSE_CC, compose->cc);
2486 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2487 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2488 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2489 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2491 compose_update_priority_menu_item(compose);
2492 compose_update_privacy_system_menu_item(compose, FALSE);
2493 compose_show_first_last_header(compose, TRUE);
2499 static void compose_insert_sig(Compose *compose, gboolean replace)
2501 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2502 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2504 GtkTextIter iter, iter_end;
2506 gboolean prev_autowrap;
2509 g_return_if_fail(compose->account != NULL);
2511 prev_autowrap = compose->autowrap;
2512 compose->autowrap = FALSE;
2514 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2515 G_CALLBACK(compose_changed_cb),
2518 mark = gtk_text_buffer_get_insert(buffer);
2519 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2520 cur_pos = gtk_text_iter_get_offset (&iter);
2522 gtk_text_buffer_get_end_iter(buffer, &iter);
2524 if (replace && compose->sig_str) {
2526 GtkTextIter first_iter, start_iter, end_iter;
2528 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2530 if (compose->sig_str[0] == '\0')
2533 found = gtk_text_iter_forward_search(&first_iter,
2535 GTK_TEXT_SEARCH_TEXT_ONLY,
2536 &start_iter, &end_iter,
2540 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2545 g_free(compose->sig_str);
2546 compose->sig_str = compose_get_signature_str(compose);
2547 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2548 compose->sig_str = g_strdup("");
2550 cur_pos = gtk_text_iter_get_offset(&iter);
2551 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2553 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2554 gtk_text_iter_forward_char(&iter);
2555 gtk_text_iter_forward_char(&iter);
2556 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2557 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2559 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2560 cur_pos = gtk_text_buffer_get_char_count (buffer);
2562 /* put the cursor where it should be
2563 * either where the quote_fmt says, either before the signature */
2564 if (compose->set_cursor_pos < 0)
2565 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2567 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2568 compose->set_cursor_pos);
2570 gtk_text_buffer_place_cursor(buffer, &iter);
2571 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2572 G_CALLBACK(compose_changed_cb),
2575 compose->autowrap = prev_autowrap;
2576 if (compose->autowrap)
2577 compose_wrap_all(compose);
2580 static gchar *compose_get_signature_str(Compose *compose)
2582 gchar *sig_body = NULL;
2583 gchar *sig_str = NULL;
2584 gchar *utf8_sig_str = NULL;
2586 g_return_val_if_fail(compose->account != NULL, NULL);
2588 if (!compose->account->sig_path)
2591 if (compose->account->sig_type == SIG_FILE) {
2592 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2593 g_warning("can't open signature file: %s\n",
2594 compose->account->sig_path);
2599 if (compose->account->sig_type == SIG_COMMAND)
2600 sig_body = get_command_output(compose->account->sig_path);
2604 tmp = file_read_to_str(compose->account->sig_path);
2607 sig_body = normalize_newlines(tmp);
2611 if (compose->account->sig_sep) {
2612 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2616 sig_str = g_strconcat("\n\n", sig_body, NULL);
2619 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2620 utf8_sig_str = sig_str;
2622 utf8_sig_str = conv_codeset_strdup
2623 (sig_str, conv_get_locale_charset_str(),
2629 return utf8_sig_str;
2632 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2635 GtkTextBuffer *buffer;
2638 const gchar *cur_encoding;
2639 gchar buf[BUFFSIZE];
2642 gboolean prev_autowrap;
2643 gboolean badtxt = FALSE;
2645 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2647 if ((fp = g_fopen(file, "rb")) == NULL) {
2648 FILE_OP_ERROR(file, "fopen");
2649 return COMPOSE_INSERT_READ_ERROR;
2652 prev_autowrap = compose->autowrap;
2653 compose->autowrap = FALSE;
2655 text = GTK_TEXT_VIEW(compose->text);
2656 buffer = gtk_text_view_get_buffer(text);
2657 mark = gtk_text_buffer_get_insert(buffer);
2658 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2660 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2661 G_CALLBACK(text_inserted),
2664 cur_encoding = conv_get_locale_charset_str();
2666 while (fgets(buf, sizeof(buf), fp) != NULL) {
2669 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2670 str = g_strdup(buf);
2672 str = conv_codeset_strdup
2673 (buf, cur_encoding, CS_INTERNAL);
2676 /* strip <CR> if DOS/Windows file,
2677 replace <CR> with <LF> if Macintosh file. */
2680 if (len > 0 && str[len - 1] != '\n') {
2682 if (str[len] == '\r') str[len] = '\n';
2685 gtk_text_buffer_insert(buffer, &iter, str, -1);
2689 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2690 G_CALLBACK(text_inserted),
2692 compose->autowrap = prev_autowrap;
2693 if (compose->autowrap)
2694 compose_wrap_all(compose);
2699 return COMPOSE_INSERT_INVALID_CHARACTER;
2701 return COMPOSE_INSERT_SUCCESS;
2704 static void compose_attach_append(Compose *compose, const gchar *file,
2705 const gchar *filename,
2706 const gchar *content_type)
2714 GtkListStore *store;
2717 if (!is_file_exist(file)) {
2718 g_warning("File %s doesn't exist\n", filename);
2721 if ((size = get_file_size(file)) < 0) {
2722 g_warning("Can't get file size of %s\n", filename);
2726 alertpanel_notice(_("File %s is empty."), filename);
2729 if ((fp = g_fopen(file, "rb")) == NULL) {
2730 alertpanel_error(_("Can't read %s."), filename);
2735 ainfo = g_new0(AttachInfo, 1);
2736 auto_ainfo = g_auto_pointer_new_with_free
2737 (ainfo, (GFreeFunc) compose_attach_info_free);
2738 ainfo->file = g_strdup(file);
2741 ainfo->content_type = g_strdup(content_type);
2742 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2744 MsgFlags flags = {0, 0};
2746 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2747 ainfo->encoding = ENC_7BIT;
2749 ainfo->encoding = ENC_8BIT;
2751 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2752 if (msginfo && msginfo->subject)
2753 name = g_strdup(msginfo->subject);
2755 name = g_path_get_basename(filename ? filename : file);
2757 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2759 procmsg_msginfo_free(msginfo);
2761 if (!g_ascii_strncasecmp(content_type, "text", 4))
2762 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2764 ainfo->encoding = ENC_BASE64;
2765 name = g_path_get_basename(filename ? filename : file);
2766 ainfo->name = g_strdup(name);
2770 ainfo->content_type = procmime_get_mime_type(file);
2771 if (!ainfo->content_type) {
2772 ainfo->content_type =
2773 g_strdup("application/octet-stream");
2774 ainfo->encoding = ENC_BASE64;
2775 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2777 procmime_get_encoding_for_text_file(file);
2779 ainfo->encoding = ENC_BASE64;
2780 name = g_path_get_basename(filename ? filename : file);
2781 ainfo->name = g_strdup(name);
2785 if (!strcmp(ainfo->content_type, "unknown")) {
2786 g_free(ainfo->content_type);
2787 ainfo->content_type = g_strdup("application/octet-stream");
2791 size_text = to_human_readable(size);
2793 store = GTK_LIST_STORE(gtk_tree_view_get_model
2794 (GTK_TREE_VIEW(compose->attach_clist)));
2796 gtk_list_store_append(store, &iter);
2797 gtk_list_store_set(store, &iter,
2798 COL_MIMETYPE, ainfo->content_type,
2799 COL_SIZE, size_text,
2800 COL_NAME, ainfo->name,
2802 COL_AUTODATA, auto_ainfo,
2805 g_auto_pointer_free(auto_ainfo);
2808 static void compose_use_signing(Compose *compose, gboolean use_signing)
2810 GtkItemFactory *ifactory;
2811 GtkWidget *menuitem = NULL;
2813 compose->use_signing = use_signing;
2814 ifactory = gtk_item_factory_from_widget(compose->menubar);
2815 menuitem = gtk_item_factory_get_item
2816 (ifactory, "/Options/Sign");
2817 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2821 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2823 GtkItemFactory *ifactory;
2824 GtkWidget *menuitem = NULL;
2826 compose->use_encryption = use_encryption;
2827 ifactory = gtk_item_factory_from_widget(compose->menubar);
2828 menuitem = gtk_item_factory_get_item
2829 (ifactory, "/Options/Encrypt");
2831 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2835 #define NEXT_PART_NOT_CHILD(info) \
2837 node = info->node; \
2838 while (node->children) \
2839 node = g_node_last_child(node); \
2840 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2843 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2847 MimeInfo *firsttext = NULL;
2848 MimeInfo *encrypted = NULL;
2851 const gchar *partname = NULL;
2853 mimeinfo = procmime_scan_message(msginfo);
2854 if (!mimeinfo) return;
2856 if (mimeinfo->node->children == NULL) {
2857 procmime_mimeinfo_free_all(mimeinfo);
2861 /* find first content part */
2862 child = (MimeInfo *) mimeinfo->node->children->data;
2863 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2864 child = (MimeInfo *)child->node->children->data;
2866 if (child->type == MIMETYPE_TEXT) {
2868 debug_print("First text part found\n");
2869 } else if (compose->mode == COMPOSE_REEDIT &&
2870 child->type == MIMETYPE_APPLICATION &&
2871 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2872 encrypted = (MimeInfo *)child->node->parent->data;
2875 child = (MimeInfo *) mimeinfo->node->children->data;
2876 while (child != NULL) {
2877 if (child == encrypted) {
2878 /* skip this part of tree */
2879 NEXT_PART_NOT_CHILD(child);
2883 if (child->type == MIMETYPE_MULTIPART) {
2884 /* get the actual content */
2885 child = procmime_mimeinfo_next(child);
2889 if (child == firsttext) {
2890 child = procmime_mimeinfo_next(child);
2894 outfile = procmime_get_tmp_file_name(child);
2895 if (procmime_get_part(outfile, child) < 0)
2896 g_warning("Can't get the part of multipart message.");
2898 gchar *content_type;
2900 content_type = procmime_get_content_type_str(child->type, child->subtype);
2902 /* if we meet a pgp signature, we don't attach it, but
2903 * we force signing. */
2904 if (strcmp(content_type, "application/pgp-signature")) {
2905 partname = procmime_mimeinfo_get_parameter(child, "filename");
2906 if (partname == NULL)
2907 partname = procmime_mimeinfo_get_parameter(child, "name");
2908 if (partname == NULL)
2910 compose_attach_append(compose, outfile,
2911 partname, content_type);
2913 compose_force_signing(compose, compose->account);
2915 g_free(content_type);
2918 NEXT_PART_NOT_CHILD(child);
2920 procmime_mimeinfo_free_all(mimeinfo);
2923 #undef NEXT_PART_NOT_CHILD
2928 WAIT_FOR_INDENT_CHAR,
2929 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2932 /* return indent length, we allow:
2933 indent characters followed by indent characters or spaces/tabs,
2934 alphabets and numbers immediately followed by indent characters,
2935 and the repeating sequences of the above
2936 If quote ends with multiple spaces, only the first one is included. */
2937 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2938 const GtkTextIter *start, gint *len)
2940 GtkTextIter iter = *start;
2944 IndentState state = WAIT_FOR_INDENT_CHAR;
2947 gint alnum_count = 0;
2948 gint space_count = 0;
2951 if (prefs_common.quote_chars == NULL) {
2955 while (!gtk_text_iter_ends_line(&iter)) {
2956 wc = gtk_text_iter_get_char(&iter);
2957 if (g_unichar_iswide(wc))
2959 clen = g_unichar_to_utf8(wc, ch);
2963 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2964 is_space = g_unichar_isspace(wc);
2966 if (state == WAIT_FOR_INDENT_CHAR) {
2967 if (!is_indent && !g_unichar_isalnum(wc))
2970 quote_len += alnum_count + space_count + 1;
2971 alnum_count = space_count = 0;
2972 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2975 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2976 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2980 else if (is_indent) {
2981 quote_len += alnum_count + space_count + 1;
2982 alnum_count = space_count = 0;
2985 state = WAIT_FOR_INDENT_CHAR;
2989 gtk_text_iter_forward_char(&iter);
2992 if (quote_len > 0 && space_count > 0)
2998 if (quote_len > 0) {
3000 gtk_text_iter_forward_chars(&iter, quote_len);
3001 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3007 /* return TRUE if the line is itemized */
3008 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3009 const GtkTextIter *start)
3011 GtkTextIter iter = *start;
3016 if (gtk_text_iter_ends_line(&iter))
3020 wc = gtk_text_iter_get_char(&iter);
3021 if (!g_unichar_isspace(wc))
3023 gtk_text_iter_forward_char(&iter);
3024 if (gtk_text_iter_ends_line(&iter))
3028 clen = g_unichar_to_utf8(wc, ch);
3032 if (!strchr("*-+", ch[0]))
3035 gtk_text_iter_forward_char(&iter);
3036 if (gtk_text_iter_ends_line(&iter))
3038 wc = gtk_text_iter_get_char(&iter);
3039 if (g_unichar_isspace(wc))
3045 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3046 const GtkTextIter *start,
3047 GtkTextIter *break_pos,
3051 GtkTextIter iter = *start, line_end = *start;
3052 PangoLogAttr *attrs;
3059 gboolean can_break = FALSE;
3060 gboolean do_break = FALSE;
3061 gboolean was_white = FALSE;
3062 gboolean prev_dont_break = FALSE;
3064 gtk_text_iter_forward_to_line_end(&line_end);
3065 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3066 len = g_utf8_strlen(str, -1);
3067 /* g_print("breaking line: %d: %s (len = %d)\n",
3068 gtk_text_iter_get_line(&iter), str, len); */
3069 attrs = g_new(PangoLogAttr, len + 1);
3071 pango_default_break(str, -1, NULL, attrs, len + 1);
3075 /* skip quote and leading spaces */
3076 for (i = 0; *p != '\0' && i < len; i++) {
3079 wc = g_utf8_get_char(p);
3080 if (i >= quote_len && !g_unichar_isspace(wc))
3082 if (g_unichar_iswide(wc))
3084 else if (*p == '\t')
3088 p = g_utf8_next_char(p);
3091 for (; *p != '\0' && i < len; i++) {
3092 PangoLogAttr *attr = attrs + i;
3096 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3099 was_white = attr->is_white;
3101 /* don't wrap URI */
3102 if ((uri_len = get_uri_len(p)) > 0) {
3104 if (pos > 0 && col > max_col) {
3114 wc = g_utf8_get_char(p);
3115 if (g_unichar_iswide(wc)) {
3117 if (prev_dont_break && can_break && attr->is_line_break)
3119 } else if (*p == '\t')
3123 if (pos > 0 && col > max_col) {
3128 if (*p == '-' || *p == '/')
3129 prev_dont_break = TRUE;
3131 prev_dont_break = FALSE;
3133 p = g_utf8_next_char(p);
3137 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3142 *break_pos = *start;
3143 gtk_text_iter_set_line_offset(break_pos, pos);
3148 static gboolean compose_join_next_line(Compose *compose,
3149 GtkTextBuffer *buffer,
3151 const gchar *quote_str)
3153 GtkTextIter iter_ = *iter, cur, prev, next, end;
3154 PangoLogAttr attrs[3];
3156 gchar *next_quote_str;
3159 gboolean keep_cursor = FALSE;
3161 if (!gtk_text_iter_forward_line(&iter_) ||
3162 gtk_text_iter_ends_line(&iter_))
3165 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3167 if ((quote_str || next_quote_str) &&
3168 strcmp2(quote_str, next_quote_str) != 0) {
3169 g_free(next_quote_str);
3172 g_free(next_quote_str);
3175 if (quote_len > 0) {
3176 gtk_text_iter_forward_chars(&end, quote_len);
3177 if (gtk_text_iter_ends_line(&end))
3181 /* don't join itemized lines */
3182 if (compose_is_itemized(buffer, &end))
3185 /* don't join signature separator */
3186 if (compose_is_sig_separator(compose, buffer, &iter_))
3189 /* delete quote str */
3191 gtk_text_buffer_delete(buffer, &iter_, &end);
3193 /* don't join line breaks put by the user */
3195 gtk_text_iter_backward_char(&cur);
3196 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3199 gtk_text_iter_forward_char(&cur);
3200 /* delete linebreak and extra spaces */
3201 while (gtk_text_iter_backward_char(&cur)) {
3202 wc1 = gtk_text_iter_get_char(&cur);
3203 if (!g_unichar_isspace(wc1))
3208 while (!gtk_text_iter_ends_line(&cur)) {
3209 wc1 = gtk_text_iter_get_char(&cur);
3210 if (!g_unichar_isspace(wc1))
3212 gtk_text_iter_forward_char(&cur);
3215 if (!gtk_text_iter_equal(&prev, &next)) {
3218 mark = gtk_text_buffer_get_insert(buffer);
3219 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3220 if (gtk_text_iter_equal(&prev, &cur))
3222 gtk_text_buffer_delete(buffer, &prev, &next);
3226 /* insert space if required */
3227 gtk_text_iter_backward_char(&prev);
3228 wc1 = gtk_text_iter_get_char(&prev);
3229 wc2 = gtk_text_iter_get_char(&next);
3230 gtk_text_iter_forward_char(&next);
3231 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3232 pango_default_break(str, -1, NULL, attrs, 3);
3233 if (!attrs[1].is_line_break ||
3234 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3235 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3237 gtk_text_iter_backward_char(&iter_);
3238 gtk_text_buffer_place_cursor(buffer, &iter_);
3247 #define ADD_TXT_POS(bp_, ep_, pti_) \
3248 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3249 last = last->next; \
3250 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3251 last->next = NULL; \
3253 g_warning("alloc error scanning URIs\n"); \
3256 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3258 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3259 GtkTextBuffer *buffer;
3260 GtkTextIter iter, break_pos, end_of_line;
3261 gchar *quote_str = NULL;
3263 gboolean wrap_quote = prefs_common.linewrap_quote;
3264 gboolean prev_autowrap = compose->autowrap;
3265 gint startq_offset = -1, noq_offset = -1;
3266 gint uri_start = -1, uri_stop = -1;
3267 gint nouri_start = -1, nouri_stop = -1;
3269 compose->autowrap = FALSE;
3271 buffer = gtk_text_view_get_buffer(text);
3272 undo_wrapping(compose->undostruct, TRUE);
3277 mark = gtk_text_buffer_get_insert(buffer);
3278 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3281 /* move to paragraph start */
3282 gtk_text_iter_set_line_offset(&iter, 0);
3283 if (gtk_text_iter_ends_line(&iter)) {
3284 while (gtk_text_iter_ends_line(&iter) &&
3285 gtk_text_iter_forward_line(&iter))
3288 while (gtk_text_iter_backward_line(&iter)) {
3289 if (gtk_text_iter_ends_line(&iter)) {
3290 gtk_text_iter_forward_line(&iter);
3296 /* go until paragraph end (empty line) */
3297 while (!gtk_text_iter_ends_line(&iter)) {
3298 gchar *scanpos = NULL;
3299 /* parse table - in order of priority */
3301 const gchar *needle; /* token */
3303 /* token search function */
3304 gchar *(*search) (const gchar *haystack,
3305 const gchar *needle);
3306 /* part parsing function */
3307 gboolean (*parse) (const gchar *start,
3308 const gchar *scanpos,
3312 /* part to URI function */
3313 gchar *(*build_uri) (const gchar *bp,
3317 static struct table parser[] = {
3318 {"http://", strcasestr, get_uri_part, make_uri_string},
3319 {"https://", strcasestr, get_uri_part, make_uri_string},
3320 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3321 {"www.", strcasestr, get_uri_part, make_http_string},
3322 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3323 {"@", strcasestr, get_email_part, make_email_string}
3325 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3326 gint last_index = PARSE_ELEMS;
3328 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3331 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3334 uri_start = uri_stop = -1;
3335 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3339 if (startq_offset == -1) {
3340 startq_offset = gtk_text_iter_get_offset(&iter);
3344 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3345 if (startq_offset == -1)
3346 startq_offset = gtk_text_iter_get_offset(&iter);
3348 if (startq_offset == -1)
3349 noq_offset = gtk_text_iter_get_offset(&iter);
3352 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3355 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3356 prefs_common.linewrap_len,
3358 GtkTextIter prev, next, cur;
3360 if (prev_autowrap != FALSE || force)
3361 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3362 else if (quote_str && wrap_quote)
3363 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3366 /* remove trailing spaces */
3368 gtk_text_iter_backward_char(&cur);
3370 while (!gtk_text_iter_starts_line(&cur)) {
3373 gtk_text_iter_backward_char(&cur);
3374 wc = gtk_text_iter_get_char(&cur);
3375 if (!g_unichar_isspace(wc))
3379 if (!gtk_text_iter_equal(&prev, &next)) {
3380 gtk_text_buffer_delete(buffer, &prev, &next);
3382 gtk_text_iter_forward_char(&break_pos);
3386 gtk_text_buffer_insert(buffer, &break_pos,
3390 compose_join_next_line(compose, buffer, &iter, quote_str);
3392 /* move iter to current line start */
3393 gtk_text_iter_set_line_offset(&iter, 0);
3400 /* move iter to next line start */
3406 while (!gtk_text_iter_ends_line(&end_of_line)) {
3407 gtk_text_iter_forward_char(&end_of_line);
3409 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3411 nouri_start = gtk_text_iter_get_offset(&iter);
3412 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3414 walk_pos = gtk_text_iter_get_offset(&iter);
3415 /* FIXME: this looks phony. scanning for anything in the parse table */
3416 for (n = 0; n < PARSE_ELEMS; n++) {
3419 tmp = parser[n].search(walk, parser[n].needle);
3421 if (scanpos == NULL || tmp < scanpos) {
3430 /* check if URI can be parsed */
3431 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3432 (const gchar **)&ep, FALSE)
3433 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3437 strlen(parser[last_index].needle);
3440 uri_start = walk_pos + (bp - o_walk);
3441 uri_stop = walk_pos + (ep - o_walk);
3445 gtk_text_iter_forward_line(&iter);
3448 if (startq_offset != -1) {
3449 GtkTextIter startquote, endquote;
3450 gtk_text_buffer_get_iter_at_offset(
3451 buffer, &startquote, startq_offset);
3453 gtk_text_buffer_apply_tag_by_name(
3454 buffer, "quote", &startquote, &endquote);
3456 } else if (noq_offset != -1) {
3457 GtkTextIter startnoquote, endnoquote;
3458 gtk_text_buffer_get_iter_at_offset(
3459 buffer, &startnoquote, noq_offset);
3461 gtk_text_buffer_remove_tag_by_name(
3462 buffer, "quote", &startnoquote, &endnoquote);
3467 GtkTextIter nouri_start_iter, nouri_end_iter;
3468 gtk_text_buffer_get_iter_at_offset(
3469 buffer, &nouri_start_iter, nouri_start);
3470 gtk_text_buffer_get_iter_at_offset(
3471 buffer, &nouri_end_iter, nouri_stop);
3472 gtk_text_buffer_remove_tag_by_name(
3473 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3475 if (uri_start > 0 && uri_stop > 0) {
3476 GtkTextIter uri_start_iter, uri_end_iter;
3477 gtk_text_buffer_get_iter_at_offset(
3478 buffer, &uri_start_iter, uri_start);
3479 gtk_text_buffer_get_iter_at_offset(
3480 buffer, &uri_end_iter, uri_stop);
3481 gtk_text_buffer_apply_tag_by_name(
3482 buffer, "link", &uri_start_iter, &uri_end_iter);
3488 undo_wrapping(compose->undostruct, FALSE);
3489 compose->autowrap = prev_autowrap;
3492 void compose_action_cb(void *data)
3494 Compose *compose = (Compose *)data;
3495 compose_wrap_all(compose);
3498 static void compose_wrap_all(Compose *compose)
3500 compose_wrap_all_full(compose, FALSE);
3503 static void compose_wrap_all_full(Compose *compose, gboolean force)
3505 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3506 GtkTextBuffer *buffer;
3509 buffer = gtk_text_view_get_buffer(text);
3511 gtk_text_buffer_get_start_iter(buffer, &iter);
3512 while (!gtk_text_iter_is_end(&iter))
3513 compose_beautify_paragraph(compose, &iter, force);
3517 static void compose_set_title(Compose *compose)
3523 edited = compose->modified ? _(" [Edited]") : "";
3525 subject = gtk_editable_get_chars(
3526 GTK_EDITABLE(compose->subject_entry), 0, -1);
3528 if (subject && strlen(subject))
3529 str = g_strdup_printf(_("%s - Compose message%s"),
3532 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3533 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3539 * compose_current_mail_account:
3541 * Find a current mail account (the currently selected account, or the
3542 * default account, if a news account is currently selected). If a
3543 * mail account cannot be found, display an error message.
3545 * Return value: Mail account, or NULL if not found.
3547 static PrefsAccount *
3548 compose_current_mail_account(void)
3552 if (cur_account && cur_account->protocol != A_NNTP)
3555 ac = account_get_default();
3556 if (!ac || ac->protocol == A_NNTP) {
3557 alertpanel_error(_("Account for sending mail is not specified.\n"
3558 "Please select a mail account before sending."));
3565 static void compose_select_account(Compose *compose, PrefsAccount *account,
3568 GtkItemFactory *ifactory;
3570 g_return_if_fail(account != NULL);
3572 compose->account = account;
3574 compose_set_title(compose);
3576 ifactory = gtk_item_factory_from_widget(compose->menubar);
3578 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3579 menu_set_active(ifactory, "/Options/Sign", TRUE);
3581 menu_set_active(ifactory, "/Options/Sign", FALSE);
3582 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3583 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3585 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3587 activate_privacy_system(compose, account, FALSE);
3589 if (!init && compose->mode != COMPOSE_REDIRECT)
3590 compose_insert_sig(compose, TRUE);
3593 gboolean compose_check_for_valid_recipient(Compose *compose) {
3594 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3595 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3596 gboolean recipient_found = FALSE;
3600 /* free to and newsgroup list */
3601 slist_free_strings(compose->to_list);
3602 g_slist_free(compose->to_list);
3603 compose->to_list = NULL;
3605 slist_free_strings(compose->newsgroup_list);
3606 g_slist_free(compose->newsgroup_list);
3607 compose->newsgroup_list = NULL;
3609 /* search header entries for to and newsgroup entries */
3610 for (list = compose->header_list; list; list = list->next) {
3613 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3614 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3616 if (entry[0] != '\0') {
3617 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3618 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3619 compose->to_list = address_list_append(compose->to_list, entry);
3620 recipient_found = TRUE;
3623 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3624 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3625 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3626 recipient_found = TRUE;
3633 return recipient_found;
3636 static gboolean compose_check_for_set_recipients(Compose *compose)
3638 if (compose->account->set_autocc && compose->account->auto_cc) {
3639 gboolean found_other = FALSE;
3641 /* search header entries for to and newsgroup entries */
3642 for (list = compose->header_list; list; list = list->next) {
3645 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3646 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3648 if (strcmp(entry, compose->account->auto_cc)
3649 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3659 aval = alertpanel(_("Send"),
3660 _("The only recipient is the default CC address. Send anyway?"),
3661 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3662 if (aval != G_ALERTDEFAULT)
3666 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3667 gboolean found_other = FALSE;
3669 /* search header entries for to and newsgroup entries */
3670 for (list = compose->header_list; list; list = list->next) {
3673 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3674 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3676 if (strcmp(entry, compose->account->auto_cc)
3677 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3687 aval = alertpanel(_("Send"),
3688 _("The only recipient is the default BCC address. Send anyway?"),
3689 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3690 if (aval != G_ALERTDEFAULT)
3697 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3701 if (compose_check_for_valid_recipient(compose) == FALSE) {
3702 alertpanel_error(_("Recipient is not specified."));
3706 if (compose_check_for_set_recipients(compose) == FALSE) {
3710 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3711 if (*str == '\0' && check_subject == TRUE) {
3714 aval = alertpanel(_("Send"),
3715 _("Subject is empty. Send it anyway?"),
3716 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3717 if (aval != G_ALERTDEFAULT)
3724 gint compose_send(Compose *compose)
3731 compose_allow_user_actions (compose, FALSE);
3732 compose->sending = TRUE;
3734 if (compose_check_entries(compose, TRUE) == FALSE)
3737 val = compose_queue(compose, &msgnum, &folder);
3741 alertpanel_error(_("Could not queue message for sending:\n\n"
3742 "Charset conversion failed."));
3743 } else if (val == -3) {
3744 alertpanel_error(_("Could not queue message for sending:\n\n"
3745 "Signature failed."));
3746 } else if (val == -2) {
3747 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3749 alertpanel_error(_("Could not queue message for sending."));
3755 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3756 compose->sending = FALSE;
3757 compose_close(compose);
3758 /* No more compose access in the normal codepath
3759 * after this point! */
3764 alertpanel_error(_("The message was queued but could not be "
3765 "sent.\nUse \"Send queued messages\" from "
3766 "the main window to retry."));
3767 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3768 compose->sending = FALSE;
3769 compose->modified = TRUE;
3770 compose_allow_user_actions (compose, TRUE);
3775 msgpath = folder_item_fetch_msg(folder, msgnum);
3776 val = procmsg_send_message_queue(msgpath);
3779 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3780 compose->sending = FALSE;
3781 compose_allow_user_actions (compose, TRUE);
3783 folder_item_remove_msg(folder, msgnum);
3784 folder_item_scan(folder);
3789 folder_item_remove_msg(folder, msgnum);
3790 folder_item_scan(folder);
3791 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3792 compose_close(compose);
3794 alertpanel_error(_("The message was queued but could not be "
3795 "sent.\nUse \"Send queued messages\" from "
3796 "the main window to retry."));
3797 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3798 compose_allow_user_actions (compose, TRUE);
3799 compose->modified = TRUE;
3800 compose->sending = FALSE;
3808 compose_allow_user_actions (compose, TRUE);
3809 compose->sending = FALSE;
3810 compose->modified = TRUE;
3815 static gboolean compose_use_attach(Compose *compose)
3817 GtkTreeModel *model = gtk_tree_view_get_model
3818 (GTK_TREE_VIEW(compose->attach_clist));
3819 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3822 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3825 gchar buf[BUFFSIZE];
3827 gboolean first_to_address;
3828 gboolean first_cc_address;
3830 ComposeHeaderEntry *headerentry;
3831 const gchar *headerentryname;
3835 debug_print("Writing redirect header\n");
3837 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3838 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3840 first_to_address = TRUE;
3841 for (list = compose->header_list; list; list = list->next) {
3842 headerentry = ((ComposeHeaderEntry *)list->data);
3843 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3845 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3846 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3847 Xstrdup_a(str, entstr, return -1);
3849 if (str[0] != '\0') {
3850 compose_convert_header
3851 (compose, buf, sizeof(buf), str,
3852 strlen("Resent-To") + 2, TRUE);
3854 if (first_to_address) {
3855 fprintf(fp, "Resent-To: ");
3856 first_to_address = FALSE;
3860 fprintf(fp, "%s", buf);
3864 if (!first_to_address) {
3868 first_cc_address = TRUE;
3869 for (list = compose->header_list; list; list = list->next) {
3870 headerentry = ((ComposeHeaderEntry *)list->data);
3871 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3873 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3874 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3875 Xstrdup_a(str, strg, return -1);
3877 if (str[0] != '\0') {
3878 compose_convert_header
3879 (compose, buf, sizeof(buf), str,
3880 strlen("Resent-Cc") + 2, TRUE);
3882 if (first_cc_address) {
3883 fprintf(fp, "Resent-Cc: ");
3884 first_cc_address = FALSE;
3888 fprintf(fp, "%s", buf);
3892 if (!first_cc_address) {
3899 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3901 gchar buf[BUFFSIZE];
3903 const gchar *entstr;
3904 /* struct utsname utsbuf; */
3906 g_return_val_if_fail(fp != NULL, -1);
3907 g_return_val_if_fail(compose->account != NULL, -1);
3908 g_return_val_if_fail(compose->account->address != NULL, -1);
3911 get_rfc822_date(buf, sizeof(buf));
3912 fprintf(fp, "Resent-Date: %s\n", buf);
3915 if (compose->account->name && *compose->account->name) {
3916 compose_convert_header
3917 (compose, buf, sizeof(buf), compose->account->name,
3918 strlen("From: "), TRUE);
3919 fprintf(fp, "Resent-From: %s <%s>\n",
3920 buf, compose->account->address);
3922 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3925 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3926 if (*entstr != '\0') {
3927 Xstrdup_a(str, entstr, return -1);
3930 compose_convert_header(compose, buf, sizeof(buf), str,
3931 strlen("Subject: "), FALSE);
3932 fprintf(fp, "Subject: %s\n", buf);
3936 /* Resent-Message-ID */
3937 if (compose->account->gen_msgid) {
3938 generate_msgid(buf, sizeof(buf));
3939 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3940 compose->msgid = g_strdup(buf);
3943 compose_redirect_write_headers_from_headerlist(compose, fp);
3945 /* separator between header and body */
3951 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3955 gchar buf[BUFFSIZE];
3957 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3958 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3962 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3963 /* should filter returnpath, delivered-to */
3964 if (g_ascii_strncasecmp(buf, "Return-Path:",
3965 strlen("Return-Path:")) == 0 ||
3966 g_ascii_strncasecmp(buf, "Delivered-To:",
3967 strlen("Delivered-To:")) == 0 ||
3968 g_ascii_strncasecmp(buf, "Received:",
3969 strlen("Received:")) == 0 ||
3970 g_ascii_strncasecmp(buf, "Subject:",
3971 strlen("Subject:")) == 0 ||
3972 g_ascii_strncasecmp(buf, "X-UIDL:",
3973 strlen("X-UIDL:")) == 0)
3976 if (fputs(buf, fdest) == -1)
3979 if (!prefs_common.redirect_keep_from) {
3980 if (g_ascii_strncasecmp(buf, "From:",
3981 strlen("From:")) == 0) {
3982 fputs(" (by way of ", fdest);
3983 if (compose->account->name
3984 && *compose->account->name) {
3985 compose_convert_header
3986 (compose, buf, sizeof(buf),
3987 compose->account->name,
3990 fprintf(fdest, "%s <%s>",
3992 compose->account->address);
3994 fprintf(fdest, "%s",
3995 compose->account->address);
4000 if (fputs("\n", fdest) == -1)
4004 compose_redirect_write_headers(compose, fdest);
4006 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4007 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4020 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4022 GtkTextBuffer *buffer;
4023 GtkTextIter start, end;
4026 const gchar *out_codeset;
4027 EncodingType encoding;
4028 MimeInfo *mimemsg, *mimetext;
4031 /* create message MimeInfo */
4032 mimemsg = procmime_mimeinfo_new();
4033 mimemsg->type = MIMETYPE_MESSAGE;
4034 mimemsg->subtype = g_strdup("rfc822");
4035 mimemsg->content = MIMECONTENT_MEM;
4036 mimemsg->tmp = TRUE; /* must free content later */
4037 mimemsg->data.mem = compose_get_header(compose);
4039 /* Create text part MimeInfo */
4040 /* get all composed text */
4041 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4042 gtk_text_buffer_get_start_iter(buffer, &start);
4043 gtk_text_buffer_get_end_iter(buffer, &end);
4044 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4045 if (is_ascii_str(chars)) {
4048 out_codeset = CS_US_ASCII;
4049 encoding = ENC_7BIT;
4051 const gchar *src_codeset = CS_INTERNAL;
4053 out_codeset = conv_get_charset_str(compose->out_encoding);
4056 gchar *test_conv_global_out = NULL;
4057 gchar *test_conv_reply = NULL;
4059 /* automatic mode. be automatic. */
4060 codeconv_set_strict(TRUE);
4062 out_codeset = conv_get_outgoing_charset_str();
4064 debug_print("trying to convert to %s\n", out_codeset);
4065 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4068 if (!test_conv_global_out && compose->orig_charset) {
4069 out_codeset = compose->orig_charset;
4070 debug_print("failure; trying to convert to %s\n", out_codeset);
4071 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4074 if (!test_conv_global_out && !test_conv_reply) {
4076 out_codeset = CS_INTERNAL;
4077 debug_print("finally using %s\n", out_codeset);
4079 g_free(test_conv_global_out);
4080 g_free(test_conv_reply);
4081 codeconv_set_strict(FALSE);
4084 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4085 out_codeset = CS_ISO_8859_1;
4087 if (prefs_common.encoding_method == CTE_BASE64)
4088 encoding = ENC_BASE64;
4089 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4090 encoding = ENC_QUOTED_PRINTABLE;
4091 else if (prefs_common.encoding_method == CTE_8BIT)
4092 encoding = ENC_8BIT;
4094 encoding = procmime_get_encoding_for_charset(out_codeset);
4096 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4097 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4099 if (action == COMPOSE_WRITE_FOR_SEND) {
4100 codeconv_set_strict(TRUE);
4101 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4102 codeconv_set_strict(FALSE);
4108 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4109 "to the specified %s charset.\n"
4110 "Send it as %s?"), out_codeset, src_codeset);
4111 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
4112 NULL, ALERT_ERROR, G_ALERTALTERNATE);
4115 if (aval != G_ALERTDEFAULT) {
4120 out_codeset = src_codeset;
4126 out_codeset = src_codeset;
4132 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4133 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4134 strstr(buf, "\nFrom ") != NULL) {
4135 encoding = ENC_QUOTED_PRINTABLE;
4139 mimetext = procmime_mimeinfo_new();
4140 mimetext->content = MIMECONTENT_MEM;
4141 mimetext->tmp = TRUE; /* must free content later */
4142 mimetext->data.mem = buf;
4143 mimetext->type = MIMETYPE_TEXT;
4144 mimetext->subtype = g_strdup("plain");
4145 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4146 g_strdup(out_codeset));
4147 /* protect trailing spaces when signing message */
4148 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4149 privacy_system_can_sign(compose->privacy_system)) {
4150 encoding = ENC_QUOTED_PRINTABLE;
4153 /* check for line length limit */
4154 if (action == COMPOSE_WRITE_FOR_SEND &&
4155 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4156 check_line_length(buf, 1000, &line) < 0) {
4160 msg = g_strdup_printf
4161 (_("Line %d exceeds the line length limit (998 bytes).\n"
4162 "The contents of the message might be broken on the way to the delivery.\n"
4164 "Send it anyway?"), line + 1);
4165 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
4167 if (aval != G_ALERTDEFAULT) {
4172 if (encoding != ENC_UNKNOWN)
4173 procmime_encode_content(mimetext, encoding);
4175 /* append attachment parts */
4176 if (compose_use_attach(compose)) {
4177 MimeInfo *mimempart;
4178 gchar *boundary = NULL;
4179 mimempart = procmime_mimeinfo_new();
4180 mimempart->content = MIMECONTENT_EMPTY;
4181 mimempart->type = MIMETYPE_MULTIPART;
4182 mimempart->subtype = g_strdup("mixed");
4187 boundary = generate_mime_boundary(NULL);
4188 } while (strstr(buf, boundary) != NULL);
4190 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4193 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4195 g_node_append(mimempart->node, mimetext->node);
4196 g_node_append(mimemsg->node, mimempart->node);
4198 compose_add_attachments(compose, mimempart);
4200 g_node_append(mimemsg->node, mimetext->node);
4202 /* sign message if sending */
4203 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4204 privacy_system_can_sign(compose->privacy_system))
4205 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4208 procmime_write_mimeinfo(mimemsg, fp);
4210 procmime_mimeinfo_free_all(mimemsg);
4215 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4217 GtkTextBuffer *buffer;
4218 GtkTextIter start, end;
4223 if ((fp = g_fopen(file, "wb")) == NULL) {
4224 FILE_OP_ERROR(file, "fopen");
4228 /* chmod for security */
4229 if (change_file_mode_rw(fp, file) < 0) {
4230 FILE_OP_ERROR(file, "chmod");
4231 g_warning("can't change file mode\n");
4234 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4235 gtk_text_buffer_get_start_iter(buffer, &start);
4236 gtk_text_buffer_get_end_iter(buffer, &end);
4237 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4239 chars = conv_codeset_strdup
4240 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4243 if (!chars) return -1;
4246 len = strlen(chars);
4247 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4248 FILE_OP_ERROR(file, "fwrite");
4257 if (fclose(fp) == EOF) {
4258 FILE_OP_ERROR(file, "fclose");
4265 static gint compose_remove_reedit_target(Compose *compose)
4268 MsgInfo *msginfo = compose->targetinfo;
4270 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4271 if (!msginfo) return -1;
4273 item = msginfo->folder;
4274 g_return_val_if_fail(item != NULL, -1);
4276 if (procmsg_msg_exist(msginfo) &&
4277 (folder_has_parent_of_type(item, F_QUEUE) ||
4278 folder_has_parent_of_type(item, F_DRAFT)
4279 || msginfo == compose->autosaved_draft)) {
4280 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4281 g_warning("can't remove the old message\n");
4289 void compose_remove_draft(Compose *compose)
4292 MsgInfo *msginfo = compose->targetinfo;
4293 drafts = account_get_special_folder(compose->account, F_DRAFT);
4295 if (procmsg_msg_exist(msginfo)) {
4296 folder_item_remove_msg(drafts, msginfo->msgnum);
4301 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4303 return compose_queue_sub (compose, msgnum, item, FALSE);
4305 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4312 static gboolean lock = FALSE;
4313 PrefsAccount *mailac = NULL, *newsac = NULL;
4315 debug_print("queueing message...\n");
4316 g_return_val_if_fail(compose->account != NULL, -1);
4320 if (compose_check_entries(compose, check_subject) == FALSE) {
4325 if (!compose->to_list && !compose->newsgroup_list) {
4326 g_warning("can't get recipient list.");
4331 if (compose->to_list) {
4332 if (compose->account->protocol != A_NNTP)
4333 mailac = compose->account;
4334 else if (cur_account && cur_account->protocol != A_NNTP)
4335 mailac = cur_account;
4336 else if (!(mailac = compose_current_mail_account())) {
4338 alertpanel_error(_("No account for sending mails available!"));
4343 if (compose->newsgroup_list) {
4344 if (compose->account->protocol == A_NNTP)
4345 newsac = compose->account;
4346 else if (!newsac->protocol != A_NNTP) {
4348 alertpanel_error(_("No account for posting news available!"));
4353 if (prefs_common.linewrap_at_send)
4354 compose_wrap_all(compose);
4356 /* write queue header */
4357 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4358 G_DIR_SEPARATOR, compose);
4359 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4360 FILE_OP_ERROR(tmp, "fopen");
4365 if (change_file_mode_rw(fp, tmp) < 0) {
4366 FILE_OP_ERROR(tmp, "chmod");
4367 g_warning("can't change file mode\n");
4370 /* queueing variables */
4371 fprintf(fp, "AF:\n");
4372 fprintf(fp, "NF:0\n");
4373 fprintf(fp, "PS:10\n");
4374 fprintf(fp, "SRH:1\n");
4375 fprintf(fp, "SFN:\n");
4376 fprintf(fp, "DSR:\n");
4378 fprintf(fp, "MID:<%s>\n", compose->msgid);
4380 fprintf(fp, "MID:\n");
4381 fprintf(fp, "CFG:\n");
4382 fprintf(fp, "PT:0\n");
4383 fprintf(fp, "S:%s\n", compose->account->address);
4384 fprintf(fp, "RQ:\n");
4386 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4388 fprintf(fp, "SSV:\n");
4390 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4392 fprintf(fp, "NSV:\n");
4393 fprintf(fp, "SSH:\n");
4394 /* write recepient list */
4395 if (compose->to_list) {
4396 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4397 for (cur = compose->to_list->next; cur != NULL;
4399 fprintf(fp, ",<%s>", (gchar *)cur->data);
4402 /* write newsgroup list */
4403 if (compose->newsgroup_list) {
4405 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4406 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4407 fprintf(fp, ",%s", (gchar *)cur->data);
4410 /* Sylpheed account IDs */
4412 fprintf(fp, "MAID:%d\n", mailac->account_id);
4414 fprintf(fp, "NAID:%d\n", newsac->account_id);
4416 if (compose->privacy_system != NULL) {
4417 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4418 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4419 if (compose->use_encryption) {
4422 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4423 if (encdata != NULL) {
4424 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4425 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4426 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4428 } /* else we finally dont want to encrypt */
4430 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4431 /* and if encdata was null, it means there's been a problem in
4438 /* Save copy folder */
4439 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4440 gchar *savefolderid;
4442 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4443 fprintf(fp, "SCF:%s\n", savefolderid);
4444 g_free(savefolderid);
4446 /* Save copy folder */
4447 if (compose->return_receipt) {
4448 fprintf(fp, "RRCPT:1\n");
4450 /* Message-ID of message replying to */
4451 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4454 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4455 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4458 /* Message-ID of message forwarding to */
4459 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4462 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4463 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4468 if (compose->redirect_filename != NULL) {
4469 if (compose_redirect_write_to_file(compose, fp) < 0) {
4478 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4483 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4487 if (fclose(fp) == EOF) {
4488 FILE_OP_ERROR(tmp, "fclose");
4494 queue = account_get_special_folder(compose->account, F_QUEUE);
4496 g_warning("can't find queue folder\n");
4501 folder_item_scan(queue);
4502 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4503 g_warning("can't queue the message\n");
4511 if (compose->mode == COMPOSE_REEDIT) {
4512 compose_remove_reedit_target(compose);
4515 if ((msgnum != NULL) && (item != NULL)) {
4523 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4526 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4528 struct stat statbuf;
4529 gchar *type, *subtype;
4530 GtkTreeModel *model;
4533 model = gtk_tree_view_get_model(tree_view);
4535 if (!gtk_tree_model_get_iter_first(model, &iter))
4538 gtk_tree_model_get(model, &iter,
4542 mimepart = procmime_mimeinfo_new();
4543 mimepart->content = MIMECONTENT_FILE;
4544 mimepart->data.filename = g_strdup(ainfo->file);
4545 mimepart->tmp = FALSE; /* or we destroy our attachment */
4546 mimepart->offset = 0;
4548 stat(ainfo->file, &statbuf);
4549 mimepart->length = statbuf.st_size;
4551 type = g_strdup(ainfo->content_type);
4553 if (!strchr(type, '/')) {
4555 type = g_strdup("application/octet-stream");
4558 subtype = strchr(type, '/') + 1;
4559 *(subtype - 1) = '\0';
4560 mimepart->type = procmime_get_media_type(type);
4561 mimepart->subtype = g_strdup(subtype);
4564 if (mimepart->type == MIMETYPE_MESSAGE &&
4565 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4566 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4568 g_hash_table_insert(mimepart->typeparameters,
4569 g_strdup("name"), g_strdup(ainfo->name));
4570 g_hash_table_insert(mimepart->dispositionparameters,
4571 g_strdup("filename"), g_strdup(ainfo->name));
4572 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4575 if (compose->use_signing) {
4576 if (ainfo->encoding == ENC_7BIT)
4577 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4578 else if (ainfo->encoding == ENC_8BIT)
4579 ainfo->encoding = ENC_BASE64;
4582 procmime_encode_content(mimepart, ainfo->encoding);
4584 g_node_append(parent->node, mimepart->node);
4585 } while (gtk_tree_model_iter_next(model, &iter));
4588 #define QUOTE_IF_REQUIRED(out, str) \
4590 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4594 len = strlen(str) + 3; \
4595 if ((__tmp = alloca(len)) == NULL) { \
4596 g_warning("can't allocate memory\n"); \
4597 g_string_free(header, TRUE); \
4600 g_snprintf(__tmp, len, "\"%s\"", str); \
4605 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4606 g_warning("can't allocate memory\n"); \
4607 g_string_free(header, TRUE); \
4610 strcpy(__tmp, str); \
4616 #define IS_IN_CUSTOM_HEADER(header) \
4617 (compose->account->add_customhdr && \
4618 custom_header_find(compose->account->customhdr_list, header) != NULL)
4620 static void compose_add_headerfield_from_headerlist(Compose *compose,
4622 const gchar *fieldname,
4623 const gchar *seperator)
4625 gchar *str, *fieldname_w_colon, *trans_fieldname;
4626 gboolean add_field = FALSE;
4628 ComposeHeaderEntry *headerentry;
4629 const gchar * headerentryname;
4632 if (IS_IN_CUSTOM_HEADER(fieldname))
4635 debug_print("Adding %s-fields\n", fieldname);
4637 fieldstr = g_string_sized_new(64);
4639 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4640 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4642 for (list = compose->header_list; list; list = list->next) {
4643 headerentry = ((ComposeHeaderEntry *)list->data);
4644 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4646 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4647 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4649 if (str[0] != '\0') {
4651 g_string_append(fieldstr, seperator);
4652 g_string_append(fieldstr, str);
4661 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4662 compose_convert_header
4663 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4664 strlen(fieldname) + 2, TRUE);
4665 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4669 g_free(fieldname_w_colon);
4670 g_string_free(fieldstr, TRUE);
4675 static gchar *compose_get_header(Compose *compose)
4677 gchar buf[BUFFSIZE];
4678 const gchar *entry_str;
4682 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4685 g_return_val_if_fail(compose->account != NULL, NULL);
4686 g_return_val_if_fail(compose->account->address != NULL, NULL);
4688 header = g_string_sized_new(64);
4691 if (compose->account->add_date) {
4692 get_rfc822_date(buf, sizeof(buf));
4693 g_string_append_printf(header, "Date: %s\n", buf);
4697 if (compose->account->name && *compose->account->name) {
4698 compose_convert_header
4699 (compose, buf, sizeof(buf), compose->account->name,
4700 strlen("From: "), TRUE);
4701 QUOTE_IF_REQUIRED(name, buf);
4702 g_string_append_printf(header, "From: %s <%s>\n",
4703 name, compose->account->address);
4705 g_string_append_printf(header, "From: %s\n", compose->account->address);
4708 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4711 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4714 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4717 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4720 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4722 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4725 compose_convert_header(compose, buf, sizeof(buf), str,
4726 strlen("Subject: "), FALSE);
4727 g_string_append_printf(header, "Subject: %s\n", buf);
4733 if (compose->account->gen_msgid) {
4734 generate_msgid(buf, sizeof(buf));
4735 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4736 compose->msgid = g_strdup(buf);
4739 if (compose->remove_references == FALSE) {
4741 if (compose->inreplyto && compose->to_list)
4742 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4745 if (compose->references)
4746 g_string_append_printf(header, "References: %s\n", compose->references);
4750 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4753 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4756 if (compose->account->organization &&
4757 strlen(compose->account->organization) &&
4758 !IS_IN_CUSTOM_HEADER("Organization")) {
4759 compose_convert_header(compose, buf, sizeof(buf),
4760 compose->account->organization,
4761 strlen("Organization: "), FALSE);
4762 g_string_append_printf(header, "Organization: %s\n", buf);
4765 /* Program version and system info */
4766 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4767 !compose->newsgroup_list) {
4768 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4770 gtk_major_version, gtk_minor_version, gtk_micro_version,
4773 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4774 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4776 gtk_major_version, gtk_minor_version, gtk_micro_version,
4780 /* custom headers */
4781 if (compose->account->add_customhdr) {
4784 for (cur = compose->account->customhdr_list; cur != NULL;
4786 CustomHeader *chdr = (CustomHeader *)cur->data;
4788 if (custom_header_is_allowed(chdr->name)) {
4789 compose_convert_header
4790 (compose, buf, sizeof(buf),
4791 chdr->value ? chdr->value : "",
4792 strlen(chdr->name) + 2, FALSE);
4793 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4799 switch (compose->priority) {
4800 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4801 "X-Priority: 1 (Highest)\n");
4803 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4804 "X-Priority: 2 (High)\n");
4806 case PRIORITY_NORMAL: break;
4807 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4808 "X-Priority: 4 (Low)\n");
4810 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4811 "X-Priority: 5 (Lowest)\n");
4813 default: debug_print("compose: priority unknown : %d\n",
4817 /* Request Return Receipt */
4818 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4819 if (compose->return_receipt) {
4820 if (compose->account->name
4821 && *compose->account->name) {
4822 compose_convert_header(compose, buf, sizeof(buf),
4823 compose->account->name,
4824 strlen("Disposition-Notification-To: "),
4826 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4828 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4832 /* get special headers */
4833 for (list = compose->header_list; list; list = list->next) {
4834 ComposeHeaderEntry *headerentry;
4837 gchar *headername_wcolon;
4838 gchar *headername_trans;
4841 gboolean standard_header = FALSE;
4843 headerentry = ((ComposeHeaderEntry *)list->data);
4845 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4846 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4851 if (!strstr(tmp, ":")) {
4852 headername_wcolon = g_strconcat(tmp, ":", NULL);
4853 headername = g_strdup(tmp);
4855 headername_wcolon = g_strdup(tmp);
4856 headername = g_strdup(strtok(tmp, ":"));
4860 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4861 Xstrdup_a(headervalue, entry_str, return NULL);
4862 subst_char(headervalue, '\r', ' ');
4863 subst_char(headervalue, '\n', ' ');
4864 string = std_headers;
4865 while (*string != NULL) {
4866 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4867 if (!strcmp(headername_trans,headername_wcolon))
4868 standard_header = TRUE;
4871 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4872 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4875 g_free(headername_wcolon);
4879 g_string_free(header, FALSE);
4884 #undef IS_IN_CUSTOM_HEADER
4886 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4887 gint header_len, gboolean addr_field)
4889 gchar *tmpstr = NULL;
4890 const gchar *out_codeset = NULL;
4892 g_return_if_fail(src != NULL);
4893 g_return_if_fail(dest != NULL);
4895 if (len < 1) return;
4897 tmpstr = g_strdup(src);
4899 subst_char(tmpstr, '\n', ' ');
4900 subst_char(tmpstr, '\r', ' ');
4903 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4904 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4905 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4910 codeconv_set_strict(TRUE);
4911 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4912 conv_get_charset_str(compose->out_encoding));
4913 codeconv_set_strict(FALSE);
4915 if (!dest || *dest == '\0') {
4916 gchar *test_conv_global_out = NULL;
4917 gchar *test_conv_reply = NULL;
4919 /* automatic mode. be automatic. */
4920 codeconv_set_strict(TRUE);
4922 out_codeset = conv_get_outgoing_charset_str();
4924 debug_print("trying to convert to %s\n", out_codeset);
4925 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4928 if (!test_conv_global_out && compose->orig_charset) {
4929 out_codeset = compose->orig_charset;
4930 debug_print("failure; trying to convert to %s\n", out_codeset);
4931 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4934 if (!test_conv_global_out && !test_conv_reply) {
4936 out_codeset = CS_INTERNAL;
4937 debug_print("finally using %s\n", out_codeset);
4939 g_free(test_conv_global_out);
4940 g_free(test_conv_reply);
4941 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4943 codeconv_set_strict(FALSE);
4948 static void compose_create_header_entry(Compose *compose)
4950 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4954 GList *combo_list = NULL;
4956 const gchar *header = NULL;
4957 ComposeHeaderEntry *headerentry;
4958 gboolean standard_header = FALSE;
4960 headerentry = g_new0(ComposeHeaderEntry, 1);
4963 combo = gtk_combo_new();
4965 while(*string != NULL) {
4966 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4969 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4970 g_list_free(combo_list);
4971 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4972 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4973 G_CALLBACK(compose_grab_focus_cb), compose);
4974 gtk_widget_show(combo);
4975 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4976 if (compose->header_last) {
4977 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4979 while (*string != NULL) {
4980 if (!strcmp(*string, last_header_entry))
4981 standard_header = TRUE;
4984 if (standard_header)
4985 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4987 if (!compose->header_last || !standard_header) {
4988 switch(compose->account->protocol) {
4990 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4993 header = prefs_common.trans_hdr ? _("To:") : "To:";
4998 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5000 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5001 G_CALLBACK(compose_grab_focus_cb), compose);
5004 entry = gtk_entry_new();
5005 gtk_widget_show(entry);
5006 gtk_table_attach(GTK_TABLE(compose->header_table), entry, 1, 2, compose->header_nextrow, compose->header_nextrow+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
5008 g_signal_connect(G_OBJECT(entry), "key-press-event",
5009 G_CALLBACK(compose_headerentry_key_press_event_cb),
5011 g_signal_connect(G_OBJECT(entry), "changed",
5012 G_CALLBACK(compose_headerentry_changed_cb),
5014 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5015 G_CALLBACK(compose_grab_focus_cb), compose);
5018 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5019 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5020 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5021 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5022 G_CALLBACK(compose_header_drag_received_cb),
5024 g_signal_connect(G_OBJECT(entry), "drag-drop",
5025 G_CALLBACK(compose_drag_drop),
5028 address_completion_register_entry(GTK_ENTRY(entry));
5030 headerentry->compose = compose;
5031 headerentry->combo = combo;
5032 headerentry->entry = entry;
5033 headerentry->headernum = compose->header_nextrow;
5035 compose->header_nextrow++;
5036 compose->header_last = headerentry;
5039 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5041 ComposeHeaderEntry *last_header;
5043 last_header = compose->header_last;
5045 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5046 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5049 static GtkWidget *compose_create_header(Compose *compose)
5053 GtkWidget *from_optmenu_hbox;
5054 GtkWidget *header_scrolledwin;
5055 GtkWidget *header_table;
5059 /* header labels and entries */
5060 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5061 gtk_widget_show(header_scrolledwin);
5062 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5064 header_table = gtk_table_new(2, 2, FALSE);
5065 gtk_widget_show(header_table);
5066 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5067 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5068 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5071 /* option menu for selecting accounts */
5072 hbox = gtk_hbox_new(FALSE, 0);
5073 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5074 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5075 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5077 from_optmenu_hbox = compose_account_option_menu_create(compose);
5078 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5079 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5082 compose->header_table = header_table;
5083 compose->header_list = NULL;
5084 compose->header_nextrow = count;
5086 compose_create_header_entry(compose);
5088 compose->table = NULL;
5090 return header_scrolledwin ;
5093 GtkWidget *compose_create_attach(Compose *compose)
5095 GtkWidget *attach_scrwin;
5096 GtkWidget *attach_clist;
5098 GtkListStore *store;
5099 GtkCellRenderer *renderer;
5100 GtkTreeViewColumn *column;
5101 GtkTreeSelection *selection;
5103 /* attachment list */
5104 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5105 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5106 GTK_POLICY_AUTOMATIC,
5107 GTK_POLICY_AUTOMATIC);
5108 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5110 store = gtk_list_store_new(N_ATTACH_COLS,
5115 G_TYPE_AUTO_POINTER,
5117 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5118 (GTK_TREE_MODEL(store)));
5119 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5120 g_object_unref(store);
5122 renderer = gtk_cell_renderer_text_new();
5123 column = gtk_tree_view_column_new_with_attributes
5124 (_("Mime type"), renderer, "text",
5125 COL_MIMETYPE, NULL);
5126 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5128 renderer = gtk_cell_renderer_text_new();
5129 column = gtk_tree_view_column_new_with_attributes
5130 (_("Size"), renderer, "text",
5132 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5134 renderer = gtk_cell_renderer_text_new();
5135 column = gtk_tree_view_column_new_with_attributes
5136 (_("Name"), renderer, "text",
5138 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5140 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5141 prefs_common.enable_rules_hint);
5142 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5143 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5145 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5146 G_CALLBACK(attach_selected), compose);
5147 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5148 G_CALLBACK(attach_button_pressed), compose);
5149 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5150 G_CALLBACK(attach_key_pressed), compose);
5153 gtk_drag_dest_set(attach_clist,
5154 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5155 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5156 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5157 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5158 G_CALLBACK(compose_attach_drag_received_cb),
5160 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5161 G_CALLBACK(compose_drag_drop),
5164 compose->attach_scrwin = attach_scrwin;
5165 compose->attach_clist = attach_clist;
5167 return attach_scrwin;
5170 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5171 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5173 static GtkWidget *compose_create_others(Compose *compose)
5176 GtkWidget *savemsg_checkbtn;
5177 GtkWidget *savemsg_entry;
5178 GtkWidget *savemsg_select;
5181 gchar *folderidentifier;
5183 /* Table for settings */
5184 table = gtk_table_new(3, 1, FALSE);
5185 gtk_widget_show(table);
5186 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5189 /* Save Message to folder */
5190 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5191 gtk_widget_show(savemsg_checkbtn);
5192 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5193 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5194 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5196 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5197 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5199 savemsg_entry = gtk_entry_new();
5200 gtk_widget_show(savemsg_entry);
5201 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5202 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5203 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5204 G_CALLBACK(compose_grab_focus_cb), compose);
5205 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5206 folderidentifier = folder_item_get_identifier(account_get_special_folder
5207 (compose->account, F_OUTBOX));
5208 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5209 g_free(folderidentifier);
5212 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5213 gtk_widget_show(savemsg_select);
5214 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5215 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5216 G_CALLBACK(compose_savemsg_select_cb),
5221 compose->savemsg_checkbtn = savemsg_checkbtn;
5222 compose->savemsg_entry = savemsg_entry;
5227 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5229 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5230 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5233 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5238 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5241 path = folder_item_get_identifier(dest);
5243 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5247 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5250 #define BLOCK_WRAP() { \
5251 prev_autowrap = compose->autowrap; \
5252 buffer = gtk_text_view_get_buffer( \
5253 GTK_TEXT_VIEW(compose->text)); \
5254 compose->autowrap = FALSE; \
5256 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5257 G_CALLBACK(compose_changed_cb), \
5259 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5260 G_CALLBACK(text_inserted), \
5263 #define UNBLOCK_WRAP() { \
5264 compose->autowrap = prev_autowrap; \
5265 if (compose->autowrap) \
5266 compose_wrap_all(compose); \
5268 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5269 G_CALLBACK(compose_changed_cb), \
5271 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5272 G_CALLBACK(text_inserted), \
5277 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5281 GtkTextBuffer *buffer;
5283 if (event->button == 3) {
5286 /* move the cursor to allow GtkAspell to check the word
5287 * under the mouse */
5288 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5289 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5291 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5293 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5294 return FALSE; /* pass the event so that the right-click goes through */
5297 if (event->button == 2) {
5299 entry_paste_clipboard(compose, compose->focused_editable,
5300 prefs_common.linewrap_pastes,
5301 GDK_SELECTION_PRIMARY);
5308 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5314 GtkWidget *handlebox;
5316 GtkWidget *notebook;
5321 GtkWidget *subject_hbox;
5322 GtkWidget *subject_frame;
5323 GtkWidget *subject_entry;
5327 GtkWidget *edit_vbox;
5328 GtkWidget *ruler_hbox;
5330 GtkWidget *scrolledwin;
5332 GtkTextBuffer *buffer;
5333 GtkClipboard *clipboard;
5335 UndoMain *undostruct;
5337 gchar *titles[N_ATTACH_COLS];
5338 guint n_menu_entries;
5341 gboolean success[1];
5342 GtkWidget *popupmenu;
5343 GtkItemFactory *popupfactory;
5344 GtkItemFactory *ifactory;
5345 GtkWidget *tmpl_menu;
5347 GtkWidget *menuitem;
5350 GtkAspell * gtkaspell = NULL;
5353 static GdkGeometry geometry;
5355 g_return_val_if_fail(account != NULL, NULL);
5357 debug_print("Creating compose window...\n");
5358 compose = g_new0(Compose, 1);
5360 titles[COL_MIMETYPE] = _("MIME type");
5361 titles[COL_SIZE] = _("Size");
5362 titles[COL_NAME] = _("Name");
5364 compose->account = account;
5366 compose->mutex = g_mutex_new();
5367 compose->set_cursor_pos = -1;
5369 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5370 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5371 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5373 if (!geometry.max_width) {
5374 geometry.max_width = gdk_screen_width();
5375 geometry.max_height = gdk_screen_height();
5378 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5379 &geometry, GDK_HINT_MAX_SIZE);
5380 if (!geometry.min_width) {
5381 geometry.min_width = 600;
5382 geometry.min_height = 480;
5384 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5385 &geometry, GDK_HINT_MIN_SIZE);
5386 gtk_widget_set_uposition(window, prefs_common.compose_x,
5387 prefs_common.compose_y);
5389 g_signal_connect(G_OBJECT(window), "delete_event",
5390 G_CALLBACK(compose_delete_cb), compose);
5391 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5392 gtk_widget_realize(window);
5394 gtkut_widget_set_composer_icon(window);
5396 vbox = gtk_vbox_new(FALSE, 0);
5397 gtk_container_add(GTK_CONTAINER(window), vbox);
5399 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5400 menubar = menubar_create(window, compose_entries,
5401 n_menu_entries, "<Compose>", compose);
5402 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5404 if (prefs_common.toolbar_detachable) {
5405 handlebox = gtk_handle_box_new();
5407 handlebox = gtk_hbox_new(FALSE, 0);
5409 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5411 gtk_widget_realize(handlebox);
5412 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5415 vbox2 = gtk_vbox_new(FALSE, 2);
5416 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5417 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5420 notebook = gtk_notebook_new();
5421 gtk_widget_set_size_request(notebook, -1, 130);
5422 gtk_widget_show(notebook);
5424 /* header labels and entries */
5425 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5426 /* attachment list */
5427 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5429 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5432 subject_hbox = gtk_hbox_new(FALSE, 0);
5433 gtk_widget_show(subject_hbox);
5435 subject_frame = gtk_frame_new(NULL);
5436 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5437 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5438 gtk_widget_show(subject_frame);
5440 subject = gtk_hbox_new(FALSE, 0);
5441 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5442 gtk_widget_show(subject);
5444 label = gtk_label_new(_("Subject:"));
5445 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5446 gtk_widget_show(label);
5448 subject_entry = gtk_entry_new();
5449 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5450 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5451 G_CALLBACK(compose_grab_focus_cb), compose);
5452 gtk_widget_show(subject_entry);
5453 compose->subject_entry = subject_entry;
5454 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5456 edit_vbox = gtk_vbox_new(FALSE, 0);
5458 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5461 ruler_hbox = gtk_hbox_new(FALSE, 0);
5462 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5464 ruler = gtk_shruler_new();
5465 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5466 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5470 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5471 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5472 GTK_POLICY_AUTOMATIC,
5473 GTK_POLICY_AUTOMATIC);
5474 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5476 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5477 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5479 text = gtk_text_view_new();
5480 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5481 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5482 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5483 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5484 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5486 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5488 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5489 G_CALLBACK(compose_edit_size_alloc),
5491 g_signal_connect(G_OBJECT(buffer), "changed",
5492 G_CALLBACK(compose_changed_cb), compose);
5493 g_signal_connect(G_OBJECT(text), "grab_focus",
5494 G_CALLBACK(compose_grab_focus_cb), compose);
5495 g_signal_connect(G_OBJECT(buffer), "insert_text",
5496 G_CALLBACK(text_inserted), compose);
5497 g_signal_connect(G_OBJECT(text), "button_press_event",
5498 G_CALLBACK(text_clicked), compose);
5501 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5502 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5503 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5504 g_signal_connect(G_OBJECT(text), "drag_data_received",
5505 G_CALLBACK(compose_insert_drag_received_cb),
5507 g_signal_connect(G_OBJECT(text), "drag-drop",
5508 G_CALLBACK(compose_drag_drop),
5510 gtk_widget_show_all(vbox);
5512 /* pane between attach clist and text */
5513 paned = gtk_vpaned_new();
5514 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5515 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5516 gtk_paned_add1(GTK_PANED(paned), notebook);
5517 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5518 gtk_widget_show_all(paned);
5521 if (prefs_common.textfont) {
5522 PangoFontDescription *font_desc;
5524 font_desc = pango_font_description_from_string
5525 (prefs_common.textfont);
5527 gtk_widget_modify_font(text, font_desc);
5528 pango_font_description_free(font_desc);
5532 color[0] = quote_color;
5533 cmap = gdk_drawable_get_colormap(window->window);
5534 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5535 if (success[0] == FALSE) {
5538 g_warning("Compose: color allocation failed.\n");
5539 style = gtk_widget_get_style(text);
5540 quote_color = style->black;
5543 n_entries = sizeof(compose_popup_entries) /
5544 sizeof(compose_popup_entries[0]);
5545 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5546 "<Compose>", &popupfactory,
5549 ifactory = gtk_item_factory_from_widget(menubar);
5550 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5551 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5552 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5554 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5556 undostruct = undo_init(text);
5557 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5560 address_completion_start(window);
5562 compose->window = window;
5563 compose->vbox = vbox;
5564 compose->menubar = menubar;
5565 compose->handlebox = handlebox;
5567 compose->vbox2 = vbox2;
5569 compose->paned = paned;
5571 compose->edit_vbox = edit_vbox;
5572 compose->ruler_hbox = ruler_hbox;
5573 compose->ruler = ruler;
5574 compose->scrolledwin = scrolledwin;
5575 compose->text = text;
5577 compose->focused_editable = NULL;
5579 compose->popupmenu = popupmenu;
5580 compose->popupfactory = popupfactory;
5582 compose->tmpl_menu = tmpl_menu;
5584 compose->mode = mode;
5586 compose->targetinfo = NULL;
5587 compose->replyinfo = NULL;
5588 compose->fwdinfo = NULL;
5590 compose->replyto = NULL;
5592 compose->bcc = NULL;
5593 compose->followup_to = NULL;
5595 compose->ml_post = NULL;
5597 compose->inreplyto = NULL;
5598 compose->references = NULL;
5599 compose->msgid = NULL;
5600 compose->boundary = NULL;
5602 compose->autowrap = prefs_common.autowrap;
5604 compose->use_signing = FALSE;
5605 compose->use_encryption = FALSE;
5606 compose->privacy_system = NULL;
5608 compose->modified = FALSE;
5610 compose->return_receipt = FALSE;
5612 compose->to_list = NULL;
5613 compose->newsgroup_list = NULL;
5615 compose->undostruct = undostruct;
5617 compose->sig_str = NULL;
5619 compose->exteditor_file = NULL;
5620 compose->exteditor_pid = -1;
5621 compose->exteditor_tag = -1;
5622 compose->draft_timeout_tag = -1;
5625 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5626 if (mode != COMPOSE_REDIRECT) {
5627 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5628 strcmp(prefs_common.dictionary, _("None"))) {
5629 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5630 prefs_common.dictionary,
5631 conv_get_locale_charset_str(),
5632 prefs_common.misspelled_col,
5633 prefs_common.check_while_typing,
5634 prefs_common.use_alternate,
5635 GTK_TEXT_VIEW(text),
5636 GTK_WINDOW(compose->window));
5638 alertpanel_error(_("Spell checker could not "
5640 gtkaspell_checkers_strerror());
5641 gtkaspell_checkers_reset_error();
5643 if (!gtkaspell_set_sug_mode(gtkaspell,
5644 prefs_common.aspell_sugmode)) {
5645 debug_print("Aspell: could not set "
5646 "suggestion mode %s\n",
5647 gtkaspell_checkers_strerror());
5648 gtkaspell_checkers_reset_error();
5651 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5655 compose->gtkaspell = gtkaspell;
5658 compose_select_account(compose, account, TRUE);
5660 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5661 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5662 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5664 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5665 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5667 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5668 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5671 if (account->protocol != A_NNTP)
5672 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5674 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5676 addressbook_set_target_compose(compose);
5678 if (mode != COMPOSE_REDIRECT)
5679 compose_set_template_menu(compose);
5681 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5682 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5685 compose_list = g_list_append(compose_list, compose);
5687 if (!prefs_common.show_ruler)
5688 gtk_widget_hide(ruler_hbox);
5690 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5691 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5692 prefs_common.show_ruler);
5695 compose->priority = PRIORITY_NORMAL;
5696 compose_update_priority_menu_item(compose);
5698 compose_set_out_encoding(compose);
5701 compose_update_actions_menu(compose);
5703 /* Privacy Systems menu */
5704 compose_update_privacy_systems_menu(compose);
5706 activate_privacy_system(compose, account, TRUE);
5707 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5708 gtk_widget_show(window);
5713 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5719 gint num = 0, def_menu = 0;
5721 accounts = account_get_list();
5722 g_return_val_if_fail(accounts != NULL, NULL);
5724 hbox = gtk_hbox_new(FALSE, 0);
5725 optmenu = gtk_option_menu_new();
5726 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5727 menu = gtk_menu_new();
5729 for (; accounts != NULL; accounts = accounts->next, num++) {
5730 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5731 GtkWidget *menuitem;
5734 if (ac == compose->account) def_menu = num;
5737 name = g_strdup_printf("%s: %s <%s>",
5739 ac->name, ac->address);
5741 name = g_strdup_printf("%s: %s",
5742 ac->account_name, ac->address);
5743 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5745 g_signal_connect(G_OBJECT(menuitem), "activate",
5746 G_CALLBACK(account_activated),
5750 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5751 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5756 static void compose_set_priority_cb(gpointer data,
5760 Compose *compose = (Compose *) data;
5761 compose->priority = action;
5764 static void compose_update_priority_menu_item(Compose * compose)
5766 GtkItemFactory *ifactory;
5767 GtkWidget *menuitem = NULL;
5769 ifactory = gtk_item_factory_from_widget(compose->menubar);
5771 switch (compose->priority) {
5772 case PRIORITY_HIGHEST:
5773 menuitem = gtk_item_factory_get_item
5774 (ifactory, "/Options/Priority/Highest");
5777 menuitem = gtk_item_factory_get_item
5778 (ifactory, "/Options/Priority/High");
5780 case PRIORITY_NORMAL:
5781 menuitem = gtk_item_factory_get_item
5782 (ifactory, "/Options/Priority/Normal");
5785 menuitem = gtk_item_factory_get_item
5786 (ifactory, "/Options/Priority/Low");
5788 case PRIORITY_LOWEST:
5789 menuitem = gtk_item_factory_get_item
5790 (ifactory, "/Options/Priority/Lowest");
5793 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5796 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5798 Compose *compose = (Compose *) data;
5800 GtkItemFactory *ifactory;
5801 gboolean can_sign = FALSE, can_encrypt = FALSE;
5803 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5805 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5808 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5809 g_free(compose->privacy_system);
5810 compose->privacy_system = NULL;
5811 if (systemid != NULL) {
5812 compose->privacy_system = g_strdup(systemid);
5814 can_sign = privacy_system_can_sign(systemid);
5815 can_encrypt = privacy_system_can_encrypt(systemid);
5818 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5820 ifactory = gtk_item_factory_from_widget(compose->menubar);
5821 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5822 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5825 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5827 static gchar *branch_path = "/Options/Privacy System";
5828 GtkItemFactory *ifactory;
5829 GtkWidget *menuitem = NULL;
5831 gboolean can_sign = FALSE, can_encrypt = FALSE;
5832 gboolean found = FALSE;
5834 ifactory = gtk_item_factory_from_widget(compose->menubar);
5836 if (compose->privacy_system != NULL) {
5839 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5840 g_return_if_fail(menuitem != NULL);
5842 amenu = GTK_MENU_SHELL(menuitem)->children;
5844 while (amenu != NULL) {
5845 GList *alist = amenu->next;
5847 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5848 if (systemid != NULL) {
5849 if (strcmp(systemid, compose->privacy_system) == 0) {
5850 menuitem = GTK_WIDGET(amenu->data);
5852 can_sign = privacy_system_can_sign(systemid);
5853 can_encrypt = privacy_system_can_encrypt(systemid);
5857 } else if (strlen(compose->privacy_system) == 0) {
5858 menuitem = GTK_WIDGET(amenu->data);
5861 can_encrypt = FALSE;
5868 if (menuitem != NULL)
5869 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5871 if (warn && !found && strlen(compose->privacy_system)) {
5872 gchar *tmp = g_strdup_printf(
5873 _("The privacy system '%s' cannot be loaded. You "
5874 "will not be able to sign or encrypt this message."),
5875 compose->privacy_system);
5876 alertpanel_warning(tmp);
5881 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5882 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5885 static void compose_set_out_encoding(Compose *compose)
5887 GtkItemFactoryEntry *entry;
5888 GtkItemFactory *ifactory;
5889 CharSet out_encoding;
5890 gchar *path, *p, *q;
5893 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5894 ifactory = gtk_item_factory_from_widget(compose->menubar);
5896 for (entry = compose_entries; entry->callback != compose_address_cb;
5898 if (entry->callback == compose_set_encoding_cb &&
5899 (CharSet)entry->callback_action == out_encoding) {
5900 p = q = path = g_strdup(entry->path);
5912 item = gtk_item_factory_get_item(ifactory, path);
5913 gtk_widget_activate(item);
5920 static void compose_set_template_menu(Compose *compose)
5922 GSList *tmpl_list, *cur;
5926 tmpl_list = template_get_config();
5928 menu = gtk_menu_new();
5930 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5931 Template *tmpl = (Template *)cur->data;
5933 item = gtk_menu_item_new_with_label(tmpl->name);
5934 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5935 g_signal_connect(G_OBJECT(item), "activate",
5936 G_CALLBACK(compose_template_activate_cb),
5938 g_object_set_data(G_OBJECT(item), "template", tmpl);
5939 gtk_widget_show(item);
5942 gtk_widget_show(menu);
5943 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5946 void compose_update_actions_menu(Compose *compose)
5948 GtkItemFactory *ifactory;
5950 ifactory = gtk_item_factory_from_widget(compose->menubar);
5951 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5954 void compose_update_privacy_systems_menu(Compose *compose)
5956 static gchar *branch_path = "/Options/Privacy System";
5957 GtkItemFactory *ifactory;
5958 GtkWidget *menuitem;
5959 GSList *systems, *cur;
5962 GtkWidget *system_none;
5965 ifactory = gtk_item_factory_from_widget(compose->menubar);
5967 /* remove old entries */
5968 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5969 g_return_if_fail(menuitem != NULL);
5971 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5972 while (amenu != NULL) {
5973 GList *alist = amenu->next;
5974 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5978 system_none = gtk_item_factory_get_widget(ifactory,
5979 "/Options/Privacy System/None");
5981 g_signal_connect(G_OBJECT(system_none), "activate",
5982 G_CALLBACK(compose_set_privacy_system_cb), compose);
5984 systems = privacy_get_system_ids();
5985 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5986 gchar *systemid = cur->data;
5988 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5989 widget = gtk_radio_menu_item_new_with_label(group,
5990 privacy_system_get_name(systemid));
5991 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5992 g_strdup(systemid), g_free);
5993 g_signal_connect(G_OBJECT(widget), "activate",
5994 G_CALLBACK(compose_set_privacy_system_cb), compose);
5996 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5997 gtk_widget_show(widget);
6000 g_slist_free(systems);
6003 void compose_reflect_prefs_all(void)
6008 for (cur = compose_list; cur != NULL; cur = cur->next) {
6009 compose = (Compose *)cur->data;
6010 compose_set_template_menu(compose);
6014 void compose_reflect_prefs_pixmap_theme(void)
6019 for (cur = compose_list; cur != NULL; cur = cur->next) {
6020 compose = (Compose *)cur->data;
6021 toolbar_update(TOOLBAR_COMPOSE, compose);
6025 static void compose_template_apply(Compose *compose, Template *tmpl,
6029 GtkTextBuffer *buffer;
6034 gint cursor_pos = 0;
6035 if (!tmpl || !tmpl->value) return;
6037 text = GTK_TEXT_VIEW(compose->text);
6038 buffer = gtk_text_view_get_buffer(text);
6040 if (tmpl->subject && *tmpl->subject != '\0')
6041 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
6043 if (tmpl->to && *tmpl->to != '\0')
6044 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
6045 if (tmpl->cc && *tmpl->cc != '\0')
6046 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
6048 if (tmpl->bcc && *tmpl->bcc != '\0')
6049 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
6052 gtk_text_buffer_set_text(buffer, "", -1);
6054 mark = gtk_text_buffer_get_insert(buffer);
6055 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6057 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6058 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6061 if (prefs_common.quotemark && *prefs_common.quotemark)
6062 qmark = prefs_common.quotemark;
6066 if (compose->replyinfo != NULL)
6067 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6068 tmpl->value, qmark, NULL, FALSE);
6069 else if (compose->fwdinfo != NULL)
6070 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6071 tmpl->value, qmark, NULL, FALSE);
6076 if (replace && parsed_str && compose->account->auto_sig)
6077 compose_insert_sig(compose, FALSE);
6079 if (replace && parsed_str) {
6080 gtk_text_buffer_get_start_iter(buffer, &iter);
6081 gtk_text_buffer_place_cursor(buffer, &iter);
6085 cursor_pos = quote_fmt_get_cursor_pos();
6086 compose->set_cursor_pos = cursor_pos;
6087 if (cursor_pos == -1)
6089 gtk_text_buffer_get_start_iter(buffer, &iter);
6090 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6091 gtk_text_buffer_place_cursor(buffer, &iter);
6095 compose_changed_cb(NULL, compose);
6098 static void compose_destroy(Compose *compose)
6100 compose_list = g_list_remove(compose_list, compose);
6102 /* NOTE: address_completion_end() does nothing with the window
6103 * however this may change. */
6104 address_completion_end(compose->window);
6106 slist_free_strings(compose->to_list);
6107 g_slist_free(compose->to_list);
6108 slist_free_strings(compose->newsgroup_list);
6109 g_slist_free(compose->newsgroup_list);
6110 slist_free_strings(compose->header_list);
6111 g_slist_free(compose->header_list);
6113 procmsg_msginfo_free(compose->targetinfo);
6114 procmsg_msginfo_free(compose->replyinfo);
6115 procmsg_msginfo_free(compose->fwdinfo);
6117 g_free(compose->replyto);
6118 g_free(compose->cc);
6119 g_free(compose->bcc);
6120 g_free(compose->newsgroups);
6121 g_free(compose->followup_to);
6123 g_free(compose->ml_post);
6125 g_free(compose->inreplyto);
6126 g_free(compose->references);
6127 g_free(compose->msgid);
6128 g_free(compose->boundary);
6130 if (compose->redirect_filename)
6131 g_free(compose->redirect_filename);
6132 if (compose->undostruct)
6133 undo_destroy(compose->undostruct);
6135 g_free(compose->sig_str);
6137 g_free(compose->exteditor_file);
6139 g_free(compose->orig_charset);
6141 g_free(compose->privacy_system);
6143 if (addressbook_get_target_compose() == compose)
6144 addressbook_set_target_compose(NULL);
6147 if (compose->gtkaspell) {
6148 gtkaspell_delete(compose->gtkaspell);
6149 compose->gtkaspell = NULL;
6153 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6154 prefs_common.compose_height = compose->window->allocation.height;
6156 if (!gtk_widget_get_parent(compose->paned))
6157 gtk_widget_destroy(compose->paned);
6158 gtk_widget_destroy(compose->popupmenu);
6160 gtk_widget_destroy(compose->window);
6161 toolbar_destroy(compose->toolbar);
6162 g_free(compose->toolbar);
6163 g_mutex_free(compose->mutex);
6167 static void compose_attach_info_free(AttachInfo *ainfo)
6169 g_free(ainfo->file);
6170 g_free(ainfo->content_type);
6171 g_free(ainfo->name);
6175 static void compose_attach_remove_selected(Compose *compose)
6177 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6178 GtkTreeSelection *selection;
6180 GtkTreeModel *model;
6182 selection = gtk_tree_view_get_selection(tree_view);
6183 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6188 for (cur = sel; cur != NULL; cur = cur->next) {
6189 GtkTreePath *path = cur->data;
6190 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6193 gtk_tree_path_free(path);
6196 for (cur = sel; cur != NULL; cur = cur->next) {
6197 GtkTreeRowReference *ref = cur->data;
6198 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6201 if (gtk_tree_model_get_iter(model, &iter, path))
6202 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6204 gtk_tree_path_free(path);
6205 gtk_tree_row_reference_free(ref);
6211 static struct _AttachProperty
6214 GtkWidget *mimetype_entry;
6215 GtkWidget *encoding_optmenu;
6216 GtkWidget *path_entry;
6217 GtkWidget *filename_entry;
6219 GtkWidget *cancel_btn;
6222 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6224 gtk_tree_path_free((GtkTreePath *)ptr);
6227 static void compose_attach_property(Compose *compose)
6229 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6231 GtkOptionMenu *optmenu;
6232 GtkTreeSelection *selection;
6234 GtkTreeModel *model;
6237 static gboolean cancelled;
6239 /* only if one selected */
6240 selection = gtk_tree_view_get_selection(tree_view);
6241 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6244 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6248 path = (GtkTreePath *) sel->data;
6249 gtk_tree_model_get_iter(model, &iter, path);
6250 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6253 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6259 if (!attach_prop.window)
6260 compose_attach_property_create(&cancelled);
6261 gtk_widget_grab_focus(attach_prop.ok_btn);
6262 gtk_widget_show(attach_prop.window);
6263 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6265 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6266 if (ainfo->encoding == ENC_UNKNOWN)
6267 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6268 GINT_TO_POINTER(ENC_BASE64));
6270 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6271 GINT_TO_POINTER(ainfo->encoding));
6273 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6274 ainfo->content_type ? ainfo->content_type : "");
6275 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6276 ainfo->file ? ainfo->file : "");
6277 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6278 ainfo->name ? ainfo->name : "");
6281 const gchar *entry_text;
6283 gchar *cnttype = NULL;
6287 GtkWidget *menuitem;
6292 gtk_widget_hide(attach_prop.window);
6297 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6298 if (*entry_text != '\0') {
6301 text = g_strstrip(g_strdup(entry_text));
6302 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6303 cnttype = g_strdup(text);
6306 alertpanel_error(_("Invalid MIME type."));
6312 menu = gtk_option_menu_get_menu(optmenu);
6313 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6314 ainfo->encoding = GPOINTER_TO_INT
6315 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6317 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6318 if (*entry_text != '\0') {
6319 if (is_file_exist(entry_text) &&
6320 (size = get_file_size(entry_text)) > 0)
6321 file = g_strdup(entry_text);
6324 (_("File doesn't exist or is empty."));
6330 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6331 if (*entry_text != '\0') {
6332 g_free(ainfo->name);
6333 ainfo->name = g_strdup(entry_text);
6337 g_free(ainfo->content_type);
6338 ainfo->content_type = cnttype;
6341 g_free(ainfo->file);
6347 /* update tree store */
6348 text = to_human_readable(ainfo->size);
6349 gtk_tree_model_get_iter(model, &iter, path);
6350 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6351 COL_MIMETYPE, ainfo->content_type,
6353 COL_NAME, ainfo->name,
6359 gtk_tree_path_free(path);
6362 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6364 label = gtk_label_new(str); \
6365 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6366 GTK_FILL, 0, 0, 0); \
6367 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6369 entry = gtk_entry_new(); \
6370 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6371 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6374 static void compose_attach_property_create(gboolean *cancelled)
6380 GtkWidget *mimetype_entry;
6383 GtkWidget *optmenu_menu;
6384 GtkWidget *menuitem;
6385 GtkWidget *path_entry;
6386 GtkWidget *filename_entry;
6389 GtkWidget *cancel_btn;
6390 GList *mime_type_list, *strlist;
6392 debug_print("Creating attach_property window...\n");
6394 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6395 gtk_widget_set_size_request(window, 480, -1);
6396 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6397 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6398 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6399 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6400 g_signal_connect(G_OBJECT(window), "delete_event",
6401 G_CALLBACK(attach_property_delete_event),
6403 g_signal_connect(G_OBJECT(window), "key_press_event",
6404 G_CALLBACK(attach_property_key_pressed),
6407 vbox = gtk_vbox_new(FALSE, 8);
6408 gtk_container_add(GTK_CONTAINER(window), vbox);
6410 table = gtk_table_new(4, 2, FALSE);
6411 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6412 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6413 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6415 label = gtk_label_new(_("MIME type"));
6416 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6418 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6419 mimetype_entry = gtk_combo_new();
6420 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6421 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6423 /* stuff with list */
6424 mime_type_list = procmime_get_mime_type_list();
6426 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6427 MimeType *type = (MimeType *) mime_type_list->data;
6430 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6432 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6435 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6436 (GCompareFunc)strcmp2);
6439 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6441 for (mime_type_list = strlist; mime_type_list != NULL;
6442 mime_type_list = mime_type_list->next)
6443 g_free(mime_type_list->data);
6444 g_list_free(strlist);
6446 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6448 label = gtk_label_new(_("Encoding"));
6449 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6451 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6453 hbox = gtk_hbox_new(FALSE, 0);
6454 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6455 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6457 optmenu = gtk_option_menu_new();
6458 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6460 optmenu_menu = gtk_menu_new();
6461 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6462 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6463 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6464 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6465 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6466 ENC_QUOTED_PRINTABLE);
6467 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6469 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6471 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6473 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6474 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6476 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
6477 &cancel_btn, GTK_STOCK_CANCEL,
6479 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6480 gtk_widget_grab_default(ok_btn);
6482 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6483 G_CALLBACK(attach_property_ok),
6485 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6486 G_CALLBACK(attach_property_cancel),
6489 gtk_widget_show_all(vbox);
6491 attach_prop.window = window;
6492 attach_prop.mimetype_entry = mimetype_entry;
6493 attach_prop.encoding_optmenu = optmenu;
6494 attach_prop.path_entry = path_entry;
6495 attach_prop.filename_entry = filename_entry;
6496 attach_prop.ok_btn = ok_btn;
6497 attach_prop.cancel_btn = cancel_btn;
6500 #undef SET_LABEL_AND_ENTRY
6502 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6508 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6514 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6515 gboolean *cancelled)
6523 static gboolean attach_property_key_pressed(GtkWidget *widget,
6525 gboolean *cancelled)
6527 if (event && event->keyval == GDK_Escape) {
6534 static void compose_exec_ext_editor(Compose *compose)
6541 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6542 G_DIR_SEPARATOR, compose);
6544 if (pipe(pipe_fds) < 0) {
6550 if ((pid = fork()) < 0) {
6557 /* close the write side of the pipe */
6560 compose->exteditor_file = g_strdup(tmp);
6561 compose->exteditor_pid = pid;
6563 compose_set_ext_editor_sensitive(compose, FALSE);
6565 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6566 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6570 } else { /* process-monitoring process */
6576 /* close the read side of the pipe */
6579 if (compose_write_body_to_file(compose, tmp) < 0) {
6580 fd_write_all(pipe_fds[1], "2\n", 2);
6584 pid_ed = compose_exec_ext_editor_real(tmp);
6586 fd_write_all(pipe_fds[1], "1\n", 2);
6590 /* wait until editor is terminated */
6591 waitpid(pid_ed, NULL, 0);
6593 fd_write_all(pipe_fds[1], "0\n", 2);
6600 #endif /* G_OS_UNIX */
6604 static gint compose_exec_ext_editor_real(const gchar *file)
6606 static gchar *def_cmd = "emacs %s";
6612 g_return_val_if_fail(file != NULL, -1);
6614 if ((pid = fork()) < 0) {
6619 if (pid != 0) return pid;
6621 /* grandchild process */
6623 if (setpgid(0, getppid()))
6626 if (prefs_common.ext_editor_cmd &&
6627 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6628 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6629 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6631 if (prefs_common.ext_editor_cmd)
6632 g_warning("External editor command line is invalid: '%s'\n",
6633 prefs_common.ext_editor_cmd);
6634 g_snprintf(buf, sizeof(buf), def_cmd, file);
6637 cmdline = strsplit_with_quote(buf, " ", 1024);
6638 execvp(cmdline[0], cmdline);
6641 g_strfreev(cmdline);
6646 static gboolean compose_ext_editor_kill(Compose *compose)
6648 pid_t pgid = compose->exteditor_pid * -1;
6651 ret = kill(pgid, 0);
6653 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6657 msg = g_strdup_printf
6658 (_("The external editor is still working.\n"
6659 "Force terminating the process?\n"
6660 "process group id: %d"), -pgid);
6661 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6662 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6666 if (val == G_ALERTDEFAULT) {
6667 g_source_remove(compose->exteditor_tag);
6668 g_io_channel_shutdown(compose->exteditor_ch,
6670 g_io_channel_unref(compose->exteditor_ch);
6672 if (kill(pgid, SIGTERM) < 0) perror("kill");
6673 waitpid(compose->exteditor_pid, NULL, 0);
6675 g_warning("Terminated process group id: %d", -pgid);
6676 g_warning("Temporary file: %s",
6677 compose->exteditor_file);
6679 compose_set_ext_editor_sensitive(compose, TRUE);
6681 g_free(compose->exteditor_file);
6682 compose->exteditor_file = NULL;
6683 compose->exteditor_pid = -1;
6684 compose->exteditor_ch = NULL;
6685 compose->exteditor_tag = -1;
6693 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6697 Compose *compose = (Compose *)data;
6700 debug_print(_("Compose: input from monitoring process\n"));
6702 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6704 g_io_channel_shutdown(source, FALSE, NULL);
6705 g_io_channel_unref(source);
6707 waitpid(compose->exteditor_pid, NULL, 0);
6709 if (buf[0] == '0') { /* success */
6710 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6711 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6713 gtk_text_buffer_set_text(buffer, "", -1);
6714 compose_insert_file(compose, compose->exteditor_file);
6715 compose_changed_cb(NULL, compose);
6717 if (g_unlink(compose->exteditor_file) < 0)
6718 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6719 } else if (buf[0] == '1') { /* failed */
6720 g_warning("Couldn't exec external editor\n");
6721 if (g_unlink(compose->exteditor_file) < 0)
6722 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6723 } else if (buf[0] == '2') {
6724 g_warning("Couldn't write to file\n");
6725 } else if (buf[0] == '3') {
6726 g_warning("Pipe read failed\n");
6729 compose_set_ext_editor_sensitive(compose, TRUE);
6731 g_free(compose->exteditor_file);
6732 compose->exteditor_file = NULL;
6733 compose->exteditor_pid = -1;
6734 compose->exteditor_ch = NULL;
6735 compose->exteditor_tag = -1;
6740 static void compose_set_ext_editor_sensitive(Compose *compose,
6743 GtkItemFactory *ifactory;
6745 ifactory = gtk_item_factory_from_widget(compose->menubar);
6747 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6748 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6749 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6750 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6751 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6752 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6753 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6756 gtk_widget_set_sensitive(compose->text, sensitive);
6757 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6758 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6759 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6760 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6761 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6762 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6763 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6764 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6766 #endif /* G_OS_UNIX */
6769 * compose_undo_state_changed:
6771 * Change the sensivity of the menuentries undo and redo
6773 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6774 gint redo_state, gpointer data)
6776 GtkWidget *widget = GTK_WIDGET(data);
6777 GtkItemFactory *ifactory;
6779 g_return_if_fail(widget != NULL);
6781 ifactory = gtk_item_factory_from_widget(widget);
6783 switch (undo_state) {
6784 case UNDO_STATE_TRUE:
6785 if (!undostruct->undo_state) {
6786 undostruct->undo_state = TRUE;
6787 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6790 case UNDO_STATE_FALSE:
6791 if (undostruct->undo_state) {
6792 undostruct->undo_state = FALSE;
6793 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6796 case UNDO_STATE_UNCHANGED:
6798 case UNDO_STATE_REFRESH:
6799 menu_set_sensitive(ifactory, "/Edit/Undo",
6800 undostruct->undo_state);
6803 g_warning("Undo state not recognized");
6807 switch (redo_state) {
6808 case UNDO_STATE_TRUE:
6809 if (!undostruct->redo_state) {
6810 undostruct->redo_state = TRUE;
6811 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6814 case UNDO_STATE_FALSE:
6815 if (undostruct->redo_state) {
6816 undostruct->redo_state = FALSE;
6817 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6820 case UNDO_STATE_UNCHANGED:
6822 case UNDO_STATE_REFRESH:
6823 menu_set_sensitive(ifactory, "/Edit/Redo",
6824 undostruct->redo_state);
6827 g_warning("Redo state not recognized");
6832 /* callback functions */
6834 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6835 * includes "non-client" (windows-izm) in calculation, so this calculation
6836 * may not be accurate.
6838 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6839 GtkAllocation *allocation,
6840 GtkSHRuler *shruler)
6842 if (prefs_common.show_ruler) {
6843 gint char_width = 0, char_height = 0;
6844 gint line_width_in_chars;
6846 gtkut_get_font_size(GTK_WIDGET(widget),
6847 &char_width, &char_height);
6848 line_width_in_chars =
6849 (allocation->width - allocation->x) / char_width;
6851 /* got the maximum */
6852 gtk_ruler_set_range(GTK_RULER(shruler),
6853 0.0, line_width_in_chars, 0,
6854 /*line_width_in_chars*/ char_width);
6860 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6862 Compose *compose = (Compose *)data;
6865 gchar *folderidentifier;
6867 ac = account_find_from_id(
6868 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6869 g_return_if_fail(ac != NULL);
6871 if (ac != compose->account)
6872 compose_select_account(compose, ac, FALSE);
6874 /* Set message save folder */
6875 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6876 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6878 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6879 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6881 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6882 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6883 folderidentifier = folder_item_get_identifier(account_get_special_folder
6884 (compose->account, F_OUTBOX));
6885 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6886 g_free(folderidentifier);
6890 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6891 GtkTreeViewColumn *column, Compose *compose)
6893 compose_attach_property(compose);
6896 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6899 Compose *compose = (Compose *)data;
6900 GtkTreeSelection *attach_selection;
6901 gint attach_nr_selected;
6902 GtkItemFactory *ifactory;
6904 if (!event) return FALSE;
6906 if (event->button == 3) {
6907 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6908 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6909 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6911 if (attach_nr_selected > 0)
6913 menu_set_sensitive(ifactory, "/Remove", TRUE);
6914 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6916 menu_set_sensitive(ifactory, "/Remove", FALSE);
6917 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6920 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6921 NULL, NULL, event->button, event->time);
6928 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6931 Compose *compose = (Compose *)data;
6933 if (!event) return FALSE;
6935 switch (event->keyval) {
6937 compose_attach_remove_selected(compose);
6943 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6945 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6946 toolbar_comp_set_sensitive(compose, allow);
6947 menu_set_sensitive(ifactory, "/Message", allow);
6948 menu_set_sensitive(ifactory, "/Edit", allow);
6950 menu_set_sensitive(ifactory, "/Spelling", allow);
6952 menu_set_sensitive(ifactory, "/Options", allow);
6953 menu_set_sensitive(ifactory, "/Tools", allow);
6954 menu_set_sensitive(ifactory, "/Help", allow);
6956 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6960 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6962 Compose *compose = (Compose *)data;
6964 if (prefs_common.work_offline && !inc_offline_should_override())
6967 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6968 gtk_timeout_remove(compose->draft_timeout_tag);
6969 compose->draft_timeout_tag = -1;
6972 compose_send(compose);
6975 static void compose_send_later_cb(gpointer data, guint action,
6978 Compose *compose = (Compose *)data;
6981 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6983 compose_close(compose);
6984 else if (val == -2) {
6985 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6989 void compose_draft (gpointer data)
6991 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6994 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6996 Compose *compose = (Compose *)data;
7000 MsgFlags flag = {0, 0};
7001 static gboolean lock = FALSE;
7002 MsgInfo *newmsginfo;
7007 draft = account_get_special_folder(compose->account, F_DRAFT);
7008 g_return_if_fail(draft != NULL);
7010 if (!g_mutex_trylock(compose->mutex)) {
7011 /* we don't want to lock the mutex once it's available,
7012 * because as the only other part of compose.c locking
7013 * it is compose_close - which means once unlocked,
7014 * the compose struct will be freed */
7015 debug_print("couldn't lock mutex, probably sending\n");
7021 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7022 G_DIR_SEPARATOR, compose);
7023 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7024 FILE_OP_ERROR(tmp, "fopen");
7028 /* chmod for security */
7029 if (change_file_mode_rw(fp, tmp) < 0) {
7030 FILE_OP_ERROR(tmp, "chmod");
7031 g_warning("can't change file mode\n");
7034 /* Save draft infos */
7035 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7036 fprintf(fp, "S:%s\n", compose->account->address);
7037 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7038 gchar *savefolderid;
7040 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7041 fprintf(fp, "SCF:%s\n", savefolderid);
7042 g_free(savefolderid);
7044 if (compose->return_receipt) {
7045 fprintf(fp, "RRCPT:1\n");
7047 if (compose->privacy_system) {
7048 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7049 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7050 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7054 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7062 folder_item_scan(draft);
7063 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7066 if (action != COMPOSE_AUTO_SAVE)
7067 alertpanel_error(_("Could not save draft."));
7071 draft->mtime = 0; /* force updating */
7073 if (compose->mode == COMPOSE_REEDIT) {
7074 compose_remove_reedit_target(compose);
7077 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7079 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7080 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7081 if (compose_use_attach(compose))
7082 procmsg_msginfo_set_flags(newmsginfo, 0,
7083 MSG_HAS_ATTACHMENT);
7085 procmsg_msginfo_free(newmsginfo);
7088 folder_item_scan(draft);
7090 if (action == COMPOSE_QUIT_EDITING) {
7092 g_mutex_unlock(compose->mutex); /* must be done before closing */
7093 compose_close(compose);
7099 path = folder_item_fetch_msg(draft, msgnum);
7100 g_return_if_fail(path != NULL);
7101 if (g_stat(path, &s) < 0) {
7102 FILE_OP_ERROR(path, "stat");
7108 procmsg_msginfo_free(compose->targetinfo);
7109 compose->targetinfo = procmsg_msginfo_new();
7110 compose->targetinfo->msgnum = msgnum;
7111 compose->targetinfo->size = s.st_size;
7112 compose->targetinfo->mtime = s.st_mtime;
7113 compose->targetinfo->folder = draft;
7114 compose->mode = COMPOSE_REEDIT;
7116 if (action == COMPOSE_AUTO_SAVE) {
7117 compose->autosaved_draft = compose->targetinfo;
7119 compose->modified = FALSE;
7120 compose_set_title(compose);
7124 g_mutex_unlock(compose->mutex);
7127 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7129 Compose *compose = (Compose *)data;
7132 if (compose->redirect_filename != NULL)
7135 file_list = filesel_select_multiple_files_open(_("Select file"));
7140 for ( tmp = file_list; tmp; tmp = tmp->next) {
7141 gchar *file = (gchar *) tmp->data;
7142 gchar *utf8_filename = conv_filename_to_utf8(file);
7143 compose_attach_append(compose, file, utf8_filename, NULL);
7144 compose_changed_cb(NULL, compose);
7146 g_free(utf8_filename);
7148 g_list_free(file_list);
7152 static void compose_insert_file_cb(gpointer data, guint action,
7155 Compose *compose = (Compose *)data;
7158 file_list = filesel_select_multiple_files_open(_("Select file"));
7163 for ( tmp = file_list; tmp; tmp = tmp->next) {
7164 gchar *file = (gchar *) tmp->data;
7165 gchar *filedup = g_strdup(file);
7166 gchar *shortfile = g_path_get_basename(filedup);
7167 ComposeInsertResult res;
7169 res = compose_insert_file(compose, file);
7170 if (res == COMPOSE_INSERT_READ_ERROR) {
7171 alertpanel_error(_("File '%s' could not be read."), shortfile);
7172 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7173 alertpanel_error(_("File '%s' contained invalid characters\n"
7174 "for the current encoding, insertion may be incorrect."), shortfile);
7180 g_list_free(file_list);
7184 static void compose_insert_sig_cb(gpointer data, guint action,
7187 Compose *compose = (Compose *)data;
7189 compose_insert_sig(compose, FALSE);
7192 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7196 Compose *compose = (Compose *)data;
7198 gtkut_widget_get_uposition(widget, &x, &y);
7199 prefs_common.compose_x = x;
7200 prefs_common.compose_y = y;
7202 if (compose->sending)
7204 compose_close_cb(compose, 0, NULL);
7208 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7210 Compose *compose = (Compose *)data;
7214 if (compose->exteditor_tag != -1) {
7215 if (!compose_ext_editor_kill(compose))
7220 if (compose->modified) {
7221 val = alertpanel(_("Discard message"),
7222 _("This message has been modified. Discard it?"),
7223 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7226 case G_ALERTDEFAULT:
7227 if (prefs_common.autosave)
7228 compose_remove_draft(compose);
7230 case G_ALERTALTERNATE:
7231 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7238 compose_close(compose);
7241 static void compose_set_encoding_cb(gpointer data, guint action,
7244 Compose *compose = (Compose *)data;
7246 if (GTK_CHECK_MENU_ITEM(widget)->active)
7247 compose->out_encoding = (CharSet)action;
7250 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7252 Compose *compose = (Compose *)data;
7254 addressbook_open(compose);
7257 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7259 Compose *compose = (Compose *)data;
7264 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7265 g_return_if_fail(tmpl != NULL);
7267 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7269 val = alertpanel(_("Apply template"), msg,
7270 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7273 if (val == G_ALERTDEFAULT)
7274 compose_template_apply(compose, tmpl, TRUE);
7275 else if (val == G_ALERTALTERNATE)
7276 compose_template_apply(compose, tmpl, FALSE);
7279 static void compose_ext_editor_cb(gpointer data, guint action,
7282 Compose *compose = (Compose *)data;
7284 compose_exec_ext_editor(compose);
7287 static void compose_undo_cb(Compose *compose)
7289 gboolean prev_autowrap = compose->autowrap;
7291 compose->autowrap = FALSE;
7292 undo_undo(compose->undostruct);
7293 compose->autowrap = prev_autowrap;
7296 static void compose_redo_cb(Compose *compose)
7298 gboolean prev_autowrap = compose->autowrap;
7300 compose->autowrap = FALSE;
7301 undo_redo(compose->undostruct);
7302 compose->autowrap = prev_autowrap;
7305 static void entry_cut_clipboard(GtkWidget *entry)
7307 if (GTK_IS_EDITABLE(entry))
7308 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7309 else if (GTK_IS_TEXT_VIEW(entry))
7310 gtk_text_buffer_cut_clipboard(
7311 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7312 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7316 static void entry_copy_clipboard(GtkWidget *entry)
7318 if (GTK_IS_EDITABLE(entry))
7319 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7320 else if (GTK_IS_TEXT_VIEW(entry))
7321 gtk_text_buffer_copy_clipboard(
7322 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7323 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7326 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7327 gboolean wrap, GdkAtom clip)
7329 if (GTK_IS_TEXT_VIEW(entry)) {
7330 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7331 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7332 GtkTextIter start_iter, end_iter;
7335 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7337 if (contents == NULL)
7340 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7341 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7343 start = gtk_text_iter_get_offset(&start_iter);
7345 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7348 end = start + strlen(contents);
7349 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7350 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7351 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7352 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7353 mark_start = gtk_text_buffer_get_insert(buffer);
7354 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7355 gtk_text_iter_backward_char(&start_iter);
7356 compose_beautify_paragraph(compose, &start_iter, TRUE);
7359 } else if (GTK_IS_EDITABLE(entry))
7360 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7364 static void entry_allsel(GtkWidget *entry)
7366 if (GTK_IS_EDITABLE(entry))
7367 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7368 else if (GTK_IS_TEXT_VIEW(entry)) {
7369 GtkTextIter startiter, enditer;
7370 GtkTextBuffer *textbuf;
7372 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7373 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7374 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7376 gtk_text_buffer_move_mark_by_name(textbuf,
7377 "selection_bound", &startiter);
7378 gtk_text_buffer_move_mark_by_name(textbuf,
7379 "insert", &enditer);
7383 static void compose_cut_cb(Compose *compose)
7385 if (compose->focused_editable &&
7386 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7387 entry_cut_clipboard(compose->focused_editable);
7390 static void compose_copy_cb(Compose *compose)
7392 if (compose->focused_editable &&
7393 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7394 entry_copy_clipboard(compose->focused_editable);
7397 static void compose_paste_cb(Compose *compose)
7400 GtkTextBuffer *buffer;
7402 if (compose->focused_editable &&
7403 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7404 entry_paste_clipboard(compose, compose->focused_editable,
7405 prefs_common.linewrap_pastes,
7406 GDK_SELECTION_CLIPBOARD);
7410 static void compose_paste_as_quote_cb(Compose *compose)
7412 gint wrap_quote = prefs_common.linewrap_quote;
7413 if (compose->focused_editable &&
7414 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7415 /* let text_insert() (called directly or at a later time
7416 * after the gtk_editable_paste_clipboard) know that
7417 * text is to be inserted as a quotation. implemented
7418 * by using a simple refcount... */
7419 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7420 G_OBJECT(compose->focused_editable),
7421 "paste_as_quotation"));
7422 g_object_set_data(G_OBJECT(compose->focused_editable),
7423 "paste_as_quotation",
7424 GINT_TO_POINTER(paste_as_quotation + 1));
7425 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7426 entry_paste_clipboard(compose, compose->focused_editable,
7427 prefs_common.linewrap_pastes,
7428 GDK_SELECTION_CLIPBOARD);
7429 prefs_common.linewrap_quote = wrap_quote;
7433 static void compose_paste_no_wrap_cb(Compose *compose)
7436 GtkTextBuffer *buffer;
7438 if (compose->focused_editable &&
7439 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7440 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7441 GDK_SELECTION_CLIPBOARD);
7445 static void compose_paste_wrap_cb(Compose *compose)
7448 GtkTextBuffer *buffer;
7450 if (compose->focused_editable &&
7451 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7452 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7453 GDK_SELECTION_CLIPBOARD);
7457 static void compose_allsel_cb(Compose *compose)
7459 if (compose->focused_editable &&
7460 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7461 entry_allsel(compose->focused_editable);
7464 static void textview_move_beginning_of_line (GtkTextView *text)
7466 GtkTextBuffer *buffer;
7470 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7472 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7473 mark = gtk_text_buffer_get_insert(buffer);
7474 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7475 gtk_text_iter_set_line_offset(&ins, 0);
7476 gtk_text_buffer_place_cursor(buffer, &ins);
7479 static void textview_move_forward_character (GtkTextView *text)
7481 GtkTextBuffer *buffer;
7485 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7487 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7488 mark = gtk_text_buffer_get_insert(buffer);
7489 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7490 if (gtk_text_iter_forward_cursor_position(&ins))
7491 gtk_text_buffer_place_cursor(buffer, &ins);
7494 static void textview_move_backward_character (GtkTextView *text)
7496 GtkTextBuffer *buffer;
7500 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7502 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7503 mark = gtk_text_buffer_get_insert(buffer);
7504 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7505 if (gtk_text_iter_backward_cursor_position(&ins))
7506 gtk_text_buffer_place_cursor(buffer, &ins);
7509 static void textview_move_forward_word (GtkTextView *text)
7511 GtkTextBuffer *buffer;
7516 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7518 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7519 mark = gtk_text_buffer_get_insert(buffer);
7520 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7521 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7522 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7523 gtk_text_iter_backward_word_start(&ins);
7524 gtk_text_buffer_place_cursor(buffer, &ins);
7528 static void textview_move_backward_word (GtkTextView *text)
7530 GtkTextBuffer *buffer;
7535 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7537 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7538 mark = gtk_text_buffer_get_insert(buffer);
7539 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7540 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7541 if (gtk_text_iter_backward_word_starts(&ins, 1))
7542 gtk_text_buffer_place_cursor(buffer, &ins);
7545 static void textview_move_end_of_line (GtkTextView *text)
7547 GtkTextBuffer *buffer;
7551 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7553 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7554 mark = gtk_text_buffer_get_insert(buffer);
7555 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7556 if (gtk_text_iter_forward_to_line_end(&ins))
7557 gtk_text_buffer_place_cursor(buffer, &ins);
7560 static void textview_move_next_line (GtkTextView *text)
7562 GtkTextBuffer *buffer;
7567 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7569 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7570 mark = gtk_text_buffer_get_insert(buffer);
7571 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7572 offset = gtk_text_iter_get_line_offset(&ins);
7573 if (gtk_text_iter_forward_line(&ins)) {
7574 gtk_text_iter_set_line_offset(&ins, offset);
7575 gtk_text_buffer_place_cursor(buffer, &ins);
7579 static void textview_move_previous_line (GtkTextView *text)
7581 GtkTextBuffer *buffer;
7586 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7588 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7589 mark = gtk_text_buffer_get_insert(buffer);
7590 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7591 offset = gtk_text_iter_get_line_offset(&ins);
7592 if (gtk_text_iter_backward_line(&ins)) {
7593 gtk_text_iter_set_line_offset(&ins, offset);
7594 gtk_text_buffer_place_cursor(buffer, &ins);
7598 static void textview_delete_forward_character (GtkTextView *text)
7600 GtkTextBuffer *buffer;
7602 GtkTextIter ins, end_iter;
7604 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7606 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7607 mark = gtk_text_buffer_get_insert(buffer);
7608 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7610 if (gtk_text_iter_forward_char(&end_iter)) {
7611 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7615 static void textview_delete_backward_character (GtkTextView *text)
7617 GtkTextBuffer *buffer;
7619 GtkTextIter ins, end_iter;
7621 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7623 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7624 mark = gtk_text_buffer_get_insert(buffer);
7625 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7627 if (gtk_text_iter_backward_char(&end_iter)) {
7628 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7632 static void textview_delete_forward_word (GtkTextView *text)
7634 GtkTextBuffer *buffer;
7636 GtkTextIter ins, end_iter;
7638 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7640 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7641 mark = gtk_text_buffer_get_insert(buffer);
7642 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7644 if (gtk_text_iter_forward_word_end(&end_iter)) {
7645 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7649 static void textview_delete_backward_word (GtkTextView *text)
7651 GtkTextBuffer *buffer;
7653 GtkTextIter ins, end_iter;
7655 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7657 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7658 mark = gtk_text_buffer_get_insert(buffer);
7659 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7661 if (gtk_text_iter_backward_word_start(&end_iter)) {
7662 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7666 static void textview_delete_line (GtkTextView *text)
7668 GtkTextBuffer *buffer;
7670 GtkTextIter ins, start_iter, end_iter;
7673 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7675 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7676 mark = gtk_text_buffer_get_insert(buffer);
7677 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7680 gtk_text_iter_set_line_offset(&start_iter, 0);
7683 if (gtk_text_iter_ends_line(&end_iter))
7684 found = gtk_text_iter_forward_char(&end_iter);
7686 found = gtk_text_iter_forward_to_line_end(&end_iter);
7689 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7692 static void textview_delete_to_line_end (GtkTextView *text)
7694 GtkTextBuffer *buffer;
7696 GtkTextIter ins, end_iter;
7699 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7701 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7702 mark = gtk_text_buffer_get_insert(buffer);
7703 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7705 if (gtk_text_iter_ends_line(&end_iter))
7706 found = gtk_text_iter_forward_char(&end_iter);
7708 found = gtk_text_iter_forward_to_line_end(&end_iter);
7710 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7713 static void compose_advanced_action_cb(Compose *compose,
7714 ComposeCallAdvancedAction action)
7716 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7718 void (*do_action) (GtkTextView *text);
7719 } action_table[] = {
7720 {textview_move_beginning_of_line},
7721 {textview_move_forward_character},
7722 {textview_move_backward_character},
7723 {textview_move_forward_word},
7724 {textview_move_backward_word},
7725 {textview_move_end_of_line},
7726 {textview_move_next_line},
7727 {textview_move_previous_line},
7728 {textview_delete_forward_character},
7729 {textview_delete_backward_character},
7730 {textview_delete_forward_word},
7731 {textview_delete_backward_word},
7732 {textview_delete_line},
7733 {NULL}, /* gtk_stext_delete_line_n */
7734 {textview_delete_to_line_end}
7737 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7739 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7740 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7741 if (action_table[action].do_action)
7742 action_table[action].do_action(text);
7744 g_warning("Not implemented yet.");
7748 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7752 if (GTK_IS_EDITABLE(widget)) {
7753 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7754 gtk_editable_set_position(GTK_EDITABLE(widget),
7757 if (widget->parent && widget->parent->parent
7758 && widget->parent->parent->parent) {
7759 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7760 gint y = widget->allocation.y;
7761 gint height = widget->allocation.height;
7762 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7763 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7765 if (y < (int)shown->value) {
7766 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7768 if (y + height > (int)shown->value + (int)shown->page_size) {
7769 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7770 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7771 y + height - (int)shown->page_size - 1);
7773 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7774 (int)shown->upper - (int)shown->page_size - 1);
7781 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7782 compose->focused_editable = widget;
7785 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7787 compose->modified = TRUE;
7788 compose_set_title(compose);
7791 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7793 Compose *compose = (Compose *)data;
7796 compose_wrap_all_full(compose, TRUE);
7798 compose_beautify_paragraph(compose, NULL, TRUE);
7801 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7804 Compose *compose = (Compose *)data;
7805 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7806 if (compose->autowrap)
7807 compose_wrap_all_full(compose, TRUE);
7810 static void compose_toggle_sign_cb(gpointer data, guint action,
7813 Compose *compose = (Compose *)data;
7815 if (GTK_CHECK_MENU_ITEM(widget)->active)
7816 compose->use_signing = TRUE;
7818 compose->use_signing = FALSE;
7821 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7824 Compose *compose = (Compose *)data;
7826 if (GTK_CHECK_MENU_ITEM(widget)->active)
7827 compose->use_encryption = TRUE;
7829 compose->use_encryption = FALSE;
7832 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7834 g_free(compose->privacy_system);
7836 compose->privacy_system = g_strdup(account->default_privacy_system);
7837 compose_update_privacy_system_menu_item(compose, warn);
7840 static void compose_toggle_ruler_cb(gpointer data, guint action,
7843 Compose *compose = (Compose *)data;
7845 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7846 gtk_widget_show(compose->ruler_hbox);
7847 prefs_common.show_ruler = TRUE;
7849 gtk_widget_hide(compose->ruler_hbox);
7850 gtk_widget_queue_resize(compose->edit_vbox);
7851 prefs_common.show_ruler = FALSE;
7855 static void compose_attach_drag_received_cb (GtkWidget *widget,
7856 GdkDragContext *drag_context,
7859 GtkSelectionData *data,
7864 Compose *compose = (Compose *)user_data;
7867 if (gdk_atom_name(data->type) &&
7868 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7869 list = uri_list_extract_filenames((const gchar *)data->data);
7870 for (tmp = list; tmp != NULL; tmp = tmp->next)
7871 compose_attach_append
7872 (compose, (const gchar *)tmp->data,
7873 (const gchar *)tmp->data, NULL);
7874 if (list) compose_changed_cb(NULL, compose);
7875 list_free_strings(list);
7877 } else if (gdk_atom_name(data->type) &&
7878 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7879 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7880 /* comes from our summaryview */
7881 SummaryView * summaryview = NULL;
7882 GSList * list = NULL, *cur = NULL;
7884 if (mainwindow_get_mainwindow())
7885 summaryview = mainwindow_get_mainwindow()->summaryview;
7888 list = summary_get_selected_msg_list(summaryview);
7890 for (cur = list; cur; cur = cur->next) {
7891 MsgInfo *msginfo = (MsgInfo *)cur->data;
7894 file = procmsg_get_message_file_full(msginfo,
7897 compose_attach_append(compose, (const gchar *)file,
7898 (const gchar *)file, "message/rfc822");
7906 static gboolean compose_drag_drop(GtkWidget *widget,
7907 GdkDragContext *drag_context,
7909 guint time, gpointer user_data)
7911 /* not handling this signal makes compose_insert_drag_received_cb
7916 static void compose_insert_drag_received_cb (GtkWidget *widget,
7917 GdkDragContext *drag_context,
7920 GtkSelectionData *data,
7925 Compose *compose = (Compose *)user_data;
7928 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7930 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7931 list = uri_list_extract_filenames((const gchar *)data->data);
7932 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7933 compose_insert_file(compose, (const gchar *)tmp->data);
7935 list_free_strings(list);
7937 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7940 #if GTK_CHECK_VERSION(2, 8, 0)
7941 /* do nothing, handled by GTK */
7943 gchar *tmpfile = get_tmp_file();
7944 str_write_to_file((const gchar *)data->data, tmpfile);
7945 compose_insert_file(compose, tmpfile);
7948 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7952 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7955 static void compose_header_drag_received_cb (GtkWidget *widget,
7956 GdkDragContext *drag_context,
7959 GtkSelectionData *data,
7964 GtkEditable *entry = (GtkEditable *)user_data;
7965 gchar *email = (gchar *)data->data;
7967 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7970 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7971 gchar *decoded=g_new(gchar, strlen(email));
7974 email += strlen("mailto:");
7975 decode_uri(decoded, email); /* will fit */
7976 gtk_editable_delete_text(entry, 0, -1);
7977 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7978 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7982 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7985 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7988 Compose *compose = (Compose *)data;
7990 if (GTK_CHECK_MENU_ITEM(widget)->active)
7991 compose->return_receipt = TRUE;
7993 compose->return_receipt = FALSE;
7996 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7999 Compose *compose = (Compose *)data;
8001 if (GTK_CHECK_MENU_ITEM(widget)->active)
8002 compose->remove_references = TRUE;
8004 compose->remove_references = FALSE;
8007 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8009 ComposeHeaderEntry *headerentry)
8011 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8012 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8013 !(event->state & GDK_MODIFIER_MASK) &&
8014 (event->keyval == GDK_BackSpace) &&
8015 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8016 gtk_container_remove
8017 (GTK_CONTAINER(headerentry->compose->header_table),
8018 headerentry->combo);
8019 gtk_container_remove
8020 (GTK_CONTAINER(headerentry->compose->header_table),
8021 headerentry->entry);
8022 headerentry->compose->header_list =
8023 g_slist_remove(headerentry->compose->header_list,
8025 g_free(headerentry);
8026 } else if (event->keyval == GDK_Tab) {
8027 if (headerentry->compose->header_last == headerentry) {
8028 /* Override default next focus, and give it to subject_entry
8029 * instead of notebook tabs
8031 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8032 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8039 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8040 ComposeHeaderEntry *headerentry)
8042 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8043 headerentry->compose->header_list =
8044 g_slist_append(headerentry->compose->header_list,
8047 compose_create_header_entry(headerentry->compose);
8048 g_signal_handlers_disconnect_matched
8049 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8050 0, 0, NULL, NULL, headerentry);
8052 /* Automatically scroll down */
8053 compose_show_first_last_header(headerentry->compose, FALSE);
8059 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8061 GtkAdjustment *vadj;
8063 g_return_if_fail(compose);
8064 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8065 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8067 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8068 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8071 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8072 const gchar *text, gint len, Compose *compose)
8074 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8075 (G_OBJECT(compose->text), "paste_as_quotation"));
8078 g_return_if_fail(text != NULL);
8080 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8081 G_CALLBACK(text_inserted),
8083 if (paste_as_quotation) {
8090 new_text = g_strndup(text, len);
8091 if (prefs_common.quotemark && *prefs_common.quotemark)
8092 qmark = prefs_common.quotemark;
8096 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8097 gtk_text_buffer_place_cursor(buffer, iter);
8099 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8101 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8102 GINT_TO_POINTER(paste_as_quotation - 1));
8104 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8105 gtk_text_buffer_place_cursor(buffer, iter);
8107 if (strcmp(text, "\n"))
8108 gtk_text_buffer_insert(buffer, iter, text, len);
8110 gtk_text_buffer_insert_with_tags_by_name(buffer,
8111 iter, text, len, "no_join", NULL);
8114 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8116 compose_beautify_paragraph(compose, iter, FALSE);
8118 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8119 gtk_text_buffer_delete_mark(buffer, mark);
8121 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8122 G_CALLBACK(text_inserted),
8124 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8126 if (prefs_common.autosave &&
8127 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8128 compose->draft_timeout_tag = gtk_timeout_add
8129 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8131 static gint compose_defer_auto_save_draft(Compose *compose)
8133 compose->draft_timeout_tag = -1;
8134 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8139 static void compose_check_all(Compose *compose)
8141 if (compose->gtkaspell)
8142 gtkaspell_check_all(compose->gtkaspell);
8145 static void compose_highlight_all(Compose *compose)
8147 if (compose->gtkaspell)
8148 gtkaspell_highlight_all(compose->gtkaspell);
8151 static void compose_check_backwards(Compose *compose)
8153 if (compose->gtkaspell)
8154 gtkaspell_check_backwards(compose->gtkaspell);
8156 GtkItemFactory *ifactory;
8157 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8158 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8159 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8163 static void compose_check_forwards_go(Compose *compose)
8165 if (compose->gtkaspell)
8166 gtkaspell_check_forwards_go(compose->gtkaspell);
8168 GtkItemFactory *ifactory;
8169 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8170 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8171 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8177 *\brief Guess originating forward account from MsgInfo and several
8178 * "common preference" settings. Return NULL if no guess.
8180 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8182 PrefsAccount *account = NULL;
8184 g_return_val_if_fail(msginfo, NULL);
8185 g_return_val_if_fail(msginfo->folder, NULL);
8186 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8188 if (msginfo->folder->prefs->enable_default_account)
8189 account = account_find_from_id(msginfo->folder->prefs->default_account);
8192 account = msginfo->folder->folder->account;
8194 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8196 Xstrdup_a(to, msginfo->to, return NULL);
8197 extract_address(to);
8198 account = account_find_from_address(to);
8201 if (!account && prefs_common.forward_account_autosel) {
8203 if (!procheader_get_header_from_msginfo
8204 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8205 extract_address(cc);
8206 account = account_find_from_address(cc);
8213 static gboolean compose_close(Compose *compose)
8217 if (!g_mutex_trylock(compose->mutex)) {
8218 /* we have to wait for the (possibly deferred by auto-save)
8219 * drafting to be done, before destroying the compose under
8221 debug_print("waiting for drafting to finish...\n");
8222 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8225 g_return_val_if_fail(compose, FALSE);
8226 gtkut_widget_get_uposition(compose->window, &x, &y);
8227 prefs_common.compose_x = x;
8228 prefs_common.compose_y = y;
8229 g_mutex_unlock(compose->mutex);
8230 compose_destroy(compose);
8235 * Add entry field for each address in list.
8236 * \param compose E-Mail composition object.
8237 * \param listAddress List of (formatted) E-Mail addresses.
8239 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8244 addr = ( gchar * ) node->data;
8245 compose_entry_append( compose, addr, COMPOSE_TO );
8246 node = g_list_next( node );
8250 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8254 GSList *new_msglist = NULL;
8255 MsgInfo *tmp_msginfo = NULL;
8256 gboolean originally_enc = FALSE;
8257 Compose *compose = NULL;
8259 g_return_if_fail(msgview != NULL);
8261 g_return_if_fail(msginfo_list != NULL);
8263 if (g_slist_length(msginfo_list) == 1) {
8264 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8265 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8267 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8268 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8269 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8270 orig_msginfo, mimeinfo);
8271 if (tmp_msginfo != NULL) {
8272 new_msglist = g_slist_append(NULL, tmp_msginfo);
8273 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8274 originally_enc = TRUE;
8280 body = messageview_get_selection(msgview);
8283 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8284 procmsg_msginfo_free(tmp_msginfo);
8285 g_slist_free(new_msglist);
8287 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8289 if (originally_enc) {
8290 compose_force_encryption(compose, compose->account, FALSE);