2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
134 #define N_ATTACH_COLS (N_COL_COLUMNS)
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
153 } ComposeCallAdvancedAction;
157 PRIORITY_HIGHEST = 1,
166 COMPOSE_INSERT_SUCCESS,
167 COMPOSE_INSERT_READ_ERROR,
168 COMPOSE_INSERT_INVALID_CHARACTER,
169 COMPOSE_INSERT_NO_FILE
170 } ComposeInsertResult;
174 COMPOSE_QUIT_EDITING,
175 COMPOSE_KEEP_EDITING,
177 } ComposeDraftAction;
181 COMPOSE_WRITE_FOR_SEND,
182 COMPOSE_WRITE_FOR_STORE
185 #define B64_LINE_SIZE 57
186 #define B64_BUFFSIZE 77
188 #define MAX_REFERENCES_LEN 999
190 static GList *compose_list = NULL;
192 Compose *compose_generic_new (PrefsAccount *account,
195 GPtrArray *attach_files,
196 GList *listAddress );
198 static Compose *compose_create (PrefsAccount *account,
201 static GtkWidget *compose_account_option_menu_create
203 static void compose_set_out_encoding (Compose *compose);
204 static void compose_set_template_menu (Compose *compose);
205 static void compose_template_apply (Compose *compose,
208 static void compose_destroy (Compose *compose);
210 static void compose_entries_set (Compose *compose,
211 const gchar *mailto);
212 static gint compose_parse_header (Compose *compose,
214 static gchar *compose_parse_references (const gchar *ref,
217 static gchar *compose_quote_fmt (Compose *compose,
224 static void compose_reply_set_entry (Compose *compose,
230 followup_and_reply_to);
231 static void compose_reedit_set_entry (Compose *compose,
234 static void compose_insert_sig (Compose *compose,
236 static gchar *compose_get_signature_str (Compose *compose);
237 static ComposeInsertResult compose_insert_file (Compose *compose,
240 static void compose_attach_append (Compose *compose,
243 const gchar *content_type);
244 static void compose_attach_parts (Compose *compose,
247 static void compose_beautify_paragraph (Compose *compose,
248 GtkTextIter *par_iter,
250 static void compose_wrap_all (Compose *compose);
251 static void compose_wrap_all_full (Compose *compose,
254 static void compose_set_title (Compose *compose);
255 static void compose_select_account (Compose *compose,
256 PrefsAccount *account,
259 static PrefsAccount *compose_current_mail_account(void);
260 /* static gint compose_send (Compose *compose); */
261 static gboolean compose_check_for_valid_recipient
263 static gboolean compose_check_entries (Compose *compose,
264 gboolean check_subject);
265 static gint compose_write_to_file (Compose *compose,
268 static gint compose_write_body_to_file (Compose *compose,
270 static gint compose_remove_reedit_target (Compose *compose,
272 void compose_remove_draft (Compose *compose);
273 static gint compose_queue (Compose *compose,
277 static gint compose_queue_sub (Compose *compose,
281 gboolean check_subject);
282 static void compose_add_attachments (Compose *compose,
284 static gchar *compose_get_header (Compose *compose);
286 static void compose_convert_header (Compose *compose,
291 gboolean addr_field);
293 static void compose_attach_info_free (AttachInfo *ainfo);
294 static void compose_attach_remove_selected (Compose *compose);
296 static void compose_attach_property (Compose *compose);
297 static void compose_attach_property_create (gboolean *cancelled);
298 static void attach_property_ok (GtkWidget *widget,
299 gboolean *cancelled);
300 static void attach_property_cancel (GtkWidget *widget,
301 gboolean *cancelled);
302 static gint attach_property_delete_event (GtkWidget *widget,
304 gboolean *cancelled);
305 static gboolean attach_property_key_pressed (GtkWidget *widget,
307 gboolean *cancelled);
309 static void compose_exec_ext_editor (Compose *compose);
311 static gint compose_exec_ext_editor_real (const gchar *file);
312 static gboolean compose_ext_editor_kill (Compose *compose);
313 static gboolean compose_input_cb (GIOChannel *source,
314 GIOCondition condition,
316 static void compose_set_ext_editor_sensitive (Compose *compose,
318 #endif /* G_OS_UNIX */
320 static void compose_undo_state_changed (UndoMain *undostruct,
325 static void compose_create_header_entry (Compose *compose);
326 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
327 static void compose_update_priority_menu_item(Compose * compose);
329 static void compose_add_field_list ( Compose *compose,
330 GList *listAddress );
332 /* callback functions */
334 static gboolean compose_edit_size_alloc (GtkEditable *widget,
335 GtkAllocation *allocation,
336 GtkSHRuler *shruler);
337 static void account_activated (GtkMenuItem *menuitem,
339 static void attach_selected (GtkTreeView *tree_view,
340 GtkTreePath *tree_path,
341 GtkTreeViewColumn *column,
343 static gboolean attach_button_pressed (GtkWidget *widget,
344 GdkEventButton *event,
346 static gboolean attach_key_pressed (GtkWidget *widget,
350 static void compose_send_cb (gpointer data,
353 static void compose_send_later_cb (gpointer data,
357 static void compose_draft_cb (gpointer data,
361 static void compose_attach_cb (gpointer data,
364 static void compose_insert_file_cb (gpointer data,
367 static void compose_insert_sig_cb (gpointer data,
371 static void compose_close_cb (gpointer data,
375 static void compose_set_encoding_cb (gpointer data,
379 static void compose_address_cb (gpointer data,
382 static void compose_template_activate_cb(GtkWidget *widget,
385 static void compose_ext_editor_cb (gpointer data,
389 static gint compose_delete_cb (GtkWidget *widget,
393 static void compose_undo_cb (Compose *compose);
394 static void compose_redo_cb (Compose *compose);
395 static void compose_cut_cb (Compose *compose);
396 static void compose_copy_cb (Compose *compose);
397 static void compose_paste_cb (Compose *compose);
398 static void compose_paste_as_quote_cb (Compose *compose);
399 static void compose_paste_no_wrap_cb (Compose *compose);
400 static void compose_paste_wrap_cb (Compose *compose);
401 static void compose_allsel_cb (Compose *compose);
403 static void compose_advanced_action_cb (Compose *compose,
404 ComposeCallAdvancedAction action);
406 static void compose_grab_focus_cb (GtkWidget *widget,
409 static void compose_changed_cb (GtkTextBuffer *textbuf,
412 static void compose_wrap_cb (gpointer data,
415 static void compose_find_cb (gpointer data,
418 static void compose_toggle_autowrap_cb (gpointer data,
422 static void compose_toggle_ruler_cb (gpointer data,
425 static void compose_toggle_sign_cb (gpointer data,
428 static void compose_toggle_encrypt_cb (gpointer data,
431 static void compose_set_privacy_system_cb(GtkWidget *widget,
433 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
434 static void activate_privacy_system (Compose *compose,
435 PrefsAccount *account,
437 static void compose_use_signing(Compose *compose, gboolean use_signing);
438 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
439 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
441 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
443 static void compose_set_priority_cb (gpointer data,
447 static void compose_attach_drag_received_cb (GtkWidget *widget,
448 GdkDragContext *drag_context,
451 GtkSelectionData *data,
455 static void compose_insert_drag_received_cb (GtkWidget *widget,
456 GdkDragContext *drag_context,
459 GtkSelectionData *data,
463 static void compose_header_drag_received_cb (GtkWidget *widget,
464 GdkDragContext *drag_context,
467 GtkSelectionData *data,
472 static gboolean compose_drag_drop (GtkWidget *widget,
473 GdkDragContext *drag_context,
475 guint time, gpointer user_data);
477 static void text_inserted (GtkTextBuffer *buffer,
482 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
483 gboolean to_all, gboolean to_ml,
485 gboolean followup_and_reply_to,
488 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
489 ComposeHeaderEntry *headerentry);
490 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
492 ComposeHeaderEntry *headerentry);
494 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
496 static void compose_allow_user_actions (Compose *compose, gboolean allow);
499 static void compose_check_all (Compose *compose);
500 static void compose_highlight_all (Compose *compose);
501 static void compose_check_backwards (Compose *compose);
502 static void compose_check_forwards_go (Compose *compose);
505 static gint compose_defer_auto_save_draft (Compose *compose);
506 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
508 static gboolean compose_close (Compose *compose);
510 static GtkItemFactoryEntry compose_popup_entries[] =
512 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
513 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
514 {N_("/---"), NULL, NULL, 0, "<Separator>"},
515 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
518 static GtkItemFactoryEntry compose_entries[] =
520 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
521 {N_("/_Message/_Send"), "<control>Return",
522 compose_send_cb, 0, NULL},
523 {N_("/_Message/Send _later"), "<shift><control>S",
524 compose_send_later_cb, 0, NULL},
525 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
527 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
528 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
529 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
530 {N_("/_Message/_Save"),
531 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
532 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
533 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
535 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
536 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
537 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
538 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
539 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
540 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
541 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
542 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
543 {N_("/_Edit/Special paste/as _quotation"),
544 NULL, compose_paste_as_quote_cb, 0, NULL},
545 {N_("/_Edit/Special paste/_wrapped"),
546 NULL, compose_paste_wrap_cb, 0, NULL},
547 {N_("/_Edit/Special paste/_unwrapped"),
548 NULL, compose_paste_no_wrap_cb, 0, NULL},
549 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
550 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
551 {N_("/_Edit/A_dvanced/Move a character backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
556 {N_("/_Edit/A_dvanced/Move a character forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
561 {N_("/_Edit/A_dvanced/Move a word backward"),
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
566 {N_("/_Edit/A_dvanced/Move a word forward"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
571 {N_("/_Edit/A_dvanced/Move to beginning of line"),
572 NULL, /* "<control>A" */
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
576 {N_("/_Edit/A_dvanced/Move to end of line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
581 {N_("/_Edit/A_dvanced/Move to previous line"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
586 {N_("/_Edit/A_dvanced/Move to next line"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
591 {N_("/_Edit/A_dvanced/Delete a character backward"),
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
596 {N_("/_Edit/A_dvanced/Delete a character forward"),
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
601 {N_("/_Edit/A_dvanced/Delete a word backward"),
602 NULL, /* "<control>W" */
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
606 {N_("/_Edit/A_dvanced/Delete a word forward"),
607 NULL, /* "<alt>D", */
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
611 {N_("/_Edit/A_dvanced/Delete line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
616 {N_("/_Edit/A_dvanced/Delete entire line"),
618 compose_advanced_action_cb,
619 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
621 {N_("/_Edit/A_dvanced/Delete to end of line"),
623 compose_advanced_action_cb,
624 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
626 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
628 "<control>F", compose_find_cb, 0, NULL},
629 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_Edit/_Wrap current paragraph"),
631 "<control>L", compose_wrap_cb, 0, NULL},
632 {N_("/_Edit/Wrap all long _lines"),
633 "<control><alt>L", compose_wrap_cb, 1, NULL},
634 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
635 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Edit/Edit with e_xternal editor"),
637 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
639 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Spelling/_Check all or check selection"),
641 NULL, compose_check_all, 0, NULL},
642 {N_("/_Spelling/_Highlight all misspelled words"),
643 NULL, compose_highlight_all, 0, NULL},
644 {N_("/_Spelling/Check _backwards misspelled word"),
645 NULL, compose_check_backwards , 0, NULL},
646 {N_("/_Spelling/_Forward to next misspelled word"),
647 NULL, compose_check_forwards_go, 0, NULL},
649 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
650 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
651 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
652 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
653 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
654 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
655 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
656 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
657 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
658 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
660 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
661 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
663 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
664 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
665 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
667 #define ENC_ACTION(action) \
668 NULL, compose_set_encoding_cb, action, \
669 "/Options/Character encoding/Automatic"
671 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
672 {N_("/_Options/Character _encoding/_Automatic"),
673 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
674 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
676 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
677 ENC_ACTION(C_US_ASCII)},
678 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
679 ENC_ACTION(C_UTF_8)},
680 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
682 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
683 ENC_ACTION(C_ISO_8859_1)},
684 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
685 ENC_ACTION(C_ISO_8859_15)},
686 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
687 ENC_ACTION(C_WINDOWS_1252)},
688 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
690 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
691 ENC_ACTION(C_ISO_8859_2)},
692 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
694 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
695 ENC_ACTION(C_ISO_8859_13)},
696 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
697 ENC_ACTION(C_ISO_8859_4)},
698 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
700 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
701 ENC_ACTION(C_ISO_8859_7)},
702 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
704 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
705 ENC_ACTION(C_ISO_8859_8)},
706 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
707 ENC_ACTION(C_WINDOWS_1255)},
708 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
710 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
711 ENC_ACTION(C_ISO_8859_6)},
712 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
713 ENC_ACTION(C_CP1256)},
714 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
716 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
717 ENC_ACTION(C_ISO_8859_9)},
718 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
720 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
721 ENC_ACTION(C_ISO_8859_5)},
722 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
723 ENC_ACTION(C_KOI8_R)},
724 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
725 ENC_ACTION(C_KOI8_U)},
726 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
727 ENC_ACTION(C_WINDOWS_1251)},
728 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
730 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
731 ENC_ACTION(C_ISO_2022_JP)},
732 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
735 ENC_ACTION(C_GB2312)},
736 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
738 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
740 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
741 ENC_ACTION(C_EUC_TW)},
742 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
744 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
745 ENC_ACTION(C_EUC_KR)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
749 ENC_ACTION(C_TIS_620)},
750 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
751 ENC_ACTION(C_WINDOWS_874)},
753 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
754 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
755 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
756 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
757 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
759 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
762 static GtkTargetEntry compose_mime_types[] =
764 {"text/uri-list", 0, 0},
765 {"text/plain", 0, 0},
769 static gboolean compose_put_existing_to_front(MsgInfo *info)
771 GList *compose_list = compose_get_compose_list();
775 for (elem = compose_list; elem != NULL && elem->data != NULL;
777 Compose *c = (Compose*)elem->data;
779 if (!c->targetinfo || !c->targetinfo->msgid ||
783 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
784 gtkut_window_popup(c->window);
792 static GdkColor quote_color =
793 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
795 static GdkColor signature_color = {
802 static GdkColor uri_color = {
809 static void compose_create_tags(GtkTextView *text, Compose *compose)
811 GtkTextBuffer *buffer;
812 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
814 buffer = gtk_text_view_get_buffer(text);
816 if (prefs_common.enable_color) {
817 /* grab the quote colors, converting from an int to a GdkColor */
818 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
820 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
822 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
825 signature_color = quote_color = uri_color = black;
828 gtk_text_buffer_create_tag(buffer, "quote",
829 "foreground-gdk", "e_color,
831 gtk_text_buffer_create_tag(buffer, "signature",
832 "foreground-gdk", &signature_color,
834 gtk_text_buffer_create_tag(buffer, "link",
835 "foreground-gdk", &uri_color,
837 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
838 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
841 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
842 GPtrArray *attach_files)
844 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
847 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
849 return compose_generic_new(account, NULL, item, NULL, NULL);
852 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
854 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
857 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
858 GPtrArray *attach_files, GList *listAddress )
861 GtkTextView *textview;
862 GtkTextBuffer *textbuf;
864 GtkItemFactory *ifactory;
866 if (item && item->prefs && item->prefs->enable_default_account)
867 account = account_find_from_id(item->prefs->default_account);
869 if (!account) account = cur_account;
870 g_return_val_if_fail(account != NULL, NULL);
872 compose = compose_create(account, COMPOSE_NEW);
873 ifactory = gtk_item_factory_from_widget(compose->menubar);
875 compose->replyinfo = NULL;
876 compose->fwdinfo = NULL;
878 textview = GTK_TEXT_VIEW(compose->text);
879 textbuf = gtk_text_view_get_buffer(textview);
880 compose_create_tags(textview, compose);
882 undo_block(compose->undostruct);
884 if (item && item->prefs && item->prefs->enable_default_dictionary &&
886 gtkaspell_change_dict(compose->gtkaspell,
887 item->prefs->default_dictionary);
890 if (account->auto_sig)
891 compose_insert_sig(compose, FALSE);
892 gtk_text_buffer_get_start_iter(textbuf, &iter);
893 gtk_text_buffer_place_cursor(textbuf, &iter);
895 if (account->protocol != A_NNTP) {
896 if (mailto && *mailto != '\0') {
897 compose_entries_set(compose, mailto);
899 } else if (item && item->prefs->enable_default_to) {
900 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
901 compose_entry_mark_default_to(compose, item->prefs->default_to);
903 if (item && item->ret_rcpt) {
904 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
908 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
910 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
913 * CLAWS: just don't allow return receipt request, even if the user
914 * may want to send an email. simple but foolproof.
916 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
918 compose_add_field_list( compose, listAddress );
924 for (i = 0; i < attach_files->len; i++) {
925 file = g_ptr_array_index(attach_files, i);
926 compose_attach_append(compose, file, file, NULL);
930 compose_show_first_last_header(compose, TRUE);
932 /* Set save folder */
933 if (item && item->prefs && item->prefs->save_copy_to_folder) {
934 gchar *folderidentifier;
936 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
937 folderidentifier = folder_item_get_identifier(item);
938 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
939 g_free(folderidentifier);
942 gtk_widget_grab_focus(compose->header_last->entry);
944 undo_unblock(compose->undostruct);
946 if (prefs_common.auto_exteditor)
947 compose_exec_ext_editor(compose);
949 compose->modified = FALSE;
950 compose_set_title(compose);
954 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
955 gboolean override_pref)
957 gchar *privacy = NULL;
959 g_return_if_fail(compose != NULL);
960 g_return_if_fail(account != NULL);
962 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
965 if (account->default_privacy_system
966 && strlen(account->default_privacy_system)) {
967 privacy = account->default_privacy_system;
969 GSList *privacy_avail = privacy_get_system_ids();
970 if (privacy_avail && g_slist_length(privacy_avail)) {
971 privacy = (gchar *)(privacy_avail->data);
974 if (privacy != NULL) {
975 compose->privacy_system = g_strdup(privacy);
976 compose_update_privacy_system_menu_item(compose, FALSE);
977 compose_use_encryption(compose, TRUE);
981 static void compose_force_signing(Compose *compose, PrefsAccount *account)
983 gchar *privacy = NULL;
985 if (account->default_privacy_system
986 && strlen(account->default_privacy_system)) {
987 privacy = account->default_privacy_system;
989 GSList *privacy_avail = privacy_get_system_ids();
990 if (privacy_avail && g_slist_length(privacy_avail)) {
991 privacy = (gchar *)(privacy_avail->data);
994 if (privacy != NULL) {
995 compose->privacy_system = g_strdup(privacy);
996 compose_update_privacy_system_menu_item(compose, FALSE);
997 compose_use_signing(compose, TRUE);
1001 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1005 Compose *compose = NULL;
1006 g_return_val_if_fail(msginfo_list != NULL, NULL);
1008 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1009 g_return_val_if_fail(msginfo != NULL, NULL);
1011 list_len = g_slist_length(msginfo_list);
1015 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1016 FALSE, prefs_common.default_reply_list, FALSE, body);
1018 case COMPOSE_REPLY_WITH_QUOTE:
1019 compose = compose_reply(msginfo, TRUE,
1020 FALSE, prefs_common.default_reply_list, FALSE, body);
1022 case COMPOSE_REPLY_WITHOUT_QUOTE:
1023 compose = compose_reply(msginfo, FALSE,
1024 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1026 case COMPOSE_REPLY_TO_SENDER:
1027 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1028 FALSE, FALSE, TRUE, body);
1030 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1031 compose = compose_followup_and_reply_to(msginfo,
1032 prefs_common.reply_with_quote,
1033 FALSE, FALSE, body);
1035 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1036 compose = compose_reply(msginfo, TRUE,
1037 FALSE, FALSE, TRUE, body);
1039 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1040 compose = compose_reply(msginfo, FALSE,
1041 FALSE, FALSE, TRUE, NULL);
1043 case COMPOSE_REPLY_TO_ALL:
1044 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1045 TRUE, FALSE, FALSE, body);
1047 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1048 compose = compose_reply(msginfo, TRUE,
1049 TRUE, FALSE, FALSE, body);
1051 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1052 compose = compose_reply(msginfo, FALSE,
1053 TRUE, FALSE, FALSE, NULL);
1055 case COMPOSE_REPLY_TO_LIST:
1056 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1057 FALSE, TRUE, FALSE, body);
1059 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1060 compose = compose_reply(msginfo, TRUE,
1061 FALSE, TRUE, FALSE, body);
1063 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1064 compose = compose_reply(msginfo, FALSE,
1065 FALSE, TRUE, FALSE, NULL);
1067 case COMPOSE_FORWARD:
1068 if (prefs_common.forward_as_attachment) {
1069 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1072 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1076 case COMPOSE_FORWARD_INLINE:
1077 /* check if we reply to more than one Message */
1078 if (list_len == 1) {
1079 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1082 /* more messages FALL THROUGH */
1083 case COMPOSE_FORWARD_AS_ATTACH:
1084 compose = compose_forward_multiple(NULL, msginfo_list);
1086 case COMPOSE_REDIRECT:
1087 compose = compose_redirect(NULL, msginfo);
1090 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1095 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1096 gboolean to_ml, gboolean to_sender,
1099 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1100 to_sender, FALSE, body);
1103 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1108 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1109 to_sender, TRUE, body);
1112 static void compose_extract_original_charset(Compose *compose)
1114 MsgInfo *info = NULL;
1115 if (compose->replyinfo) {
1116 info = compose->replyinfo;
1117 } else if (compose->fwdinfo) {
1118 info = compose->fwdinfo;
1119 } else if (compose->targetinfo) {
1120 info = compose->targetinfo;
1123 MimeInfo *mimeinfo = procmime_scan_message(info);
1124 MimeInfo *partinfo = mimeinfo;
1125 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1126 partinfo = procmime_mimeinfo_next(partinfo);
1128 compose->orig_charset =
1129 g_strdup(procmime_mimeinfo_get_parameter(
1130 partinfo, "charset"));
1132 procmime_mimeinfo_free_all(mimeinfo);
1136 #define SIGNAL_BLOCK(buffer) { \
1137 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1138 G_CALLBACK(compose_changed_cb), \
1140 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1141 G_CALLBACK(text_inserted), \
1145 #define SIGNAL_UNBLOCK(buffer) { \
1146 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1147 G_CALLBACK(compose_changed_cb), \
1149 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1150 G_CALLBACK(text_inserted), \
1154 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1155 gboolean to_all, gboolean to_ml,
1157 gboolean followup_and_reply_to,
1160 GtkItemFactory *ifactory;
1162 PrefsAccount *account = NULL;
1163 PrefsAccount *reply_account;
1164 GtkTextView *textview;
1165 GtkTextBuffer *textbuf;
1167 g_return_val_if_fail(msginfo != NULL, NULL);
1168 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1170 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1172 g_return_val_if_fail(account != NULL, NULL);
1174 if (to_sender && account->protocol == A_NNTP &&
1175 !followup_and_reply_to) {
1177 account_find_from_address(account->address);
1179 reply_account = compose_current_mail_account();
1183 reply_account = account;
1185 compose = compose_create(account, COMPOSE_REPLY);
1186 ifactory = gtk_item_factory_from_widget(compose->menubar);
1188 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1189 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1191 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1193 if (!compose->replyinfo)
1194 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1196 compose_extract_original_charset(compose);
1198 if (msginfo->folder && msginfo->folder->ret_rcpt)
1199 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1201 /* Set save folder */
1202 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1203 gchar *folderidentifier;
1205 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1206 folderidentifier = folder_item_get_identifier(msginfo->folder);
1207 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1208 g_free(folderidentifier);
1211 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1212 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1213 to_sender, followup_and_reply_to);
1214 compose_show_first_last_header(compose, TRUE);
1216 textview = (GTK_TEXT_VIEW(compose->text));
1217 textbuf = gtk_text_view_get_buffer(textview);
1218 compose_create_tags(textview, compose);
1220 undo_block(compose->undostruct);
1222 if (msginfo->folder && msginfo->folder->prefs &&
1223 msginfo->folder->prefs &&
1224 msginfo->folder->prefs->enable_default_dictionary &&
1226 gtkaspell_change_dict(compose->gtkaspell,
1227 msginfo->folder->prefs->default_dictionary);
1233 if (prefs_common.quotemark && *prefs_common.quotemark)
1234 qmark = prefs_common.quotemark;
1238 compose_quote_fmt(compose, compose->replyinfo,
1239 prefs_common.quotefmt,
1240 qmark, body, FALSE);
1242 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1243 compose_force_encryption(compose, account, FALSE);
1246 SIGNAL_BLOCK(textbuf);
1248 if (account->auto_sig)
1249 compose_insert_sig(compose, FALSE);
1251 compose_wrap_all(compose);
1253 SIGNAL_UNBLOCK(textbuf);
1255 gtk_widget_grab_focus(compose->text);
1257 undo_unblock(compose->undostruct);
1259 if (prefs_common.auto_exteditor)
1260 compose_exec_ext_editor(compose);
1262 compose->modified = FALSE;
1263 compose_set_title(compose);
1267 #define INSERT_FW_HEADER(var, hdr) \
1268 if (msginfo->var && *msginfo->var) { \
1269 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1270 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1271 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1274 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1275 gboolean as_attach, const gchar *body,
1276 gboolean no_extedit)
1279 GtkTextView *textview;
1280 GtkTextBuffer *textbuf;
1283 g_return_val_if_fail(msginfo != NULL, NULL);
1284 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1287 !(account = compose_guess_forward_account_from_msginfo
1289 account = cur_account;
1291 compose = compose_create(account, COMPOSE_FORWARD);
1293 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1294 if (!compose->fwdinfo)
1295 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1297 compose_extract_original_charset(compose);
1299 if (msginfo->subject && *msginfo->subject) {
1300 gchar *buf, *buf2, *p;
1302 buf = p = g_strdup(msginfo->subject);
1303 p += subject_get_prefix_length(p);
1304 memmove(buf, p, strlen(p) + 1);
1306 buf2 = g_strdup_printf("Fw: %s", buf);
1307 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1313 textview = GTK_TEXT_VIEW(compose->text);
1314 textbuf = gtk_text_view_get_buffer(textview);
1315 compose_create_tags(textview, compose);
1317 undo_block(compose->undostruct);
1321 msgfile = procmsg_get_message_file_path(msginfo);
1322 if (!is_file_exist(msgfile))
1323 g_warning("%s: file not exist\n", msgfile);
1325 compose_attach_append(compose, msgfile, msgfile,
1331 MsgInfo *full_msginfo;
1333 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1335 full_msginfo = procmsg_msginfo_copy(msginfo);
1337 if (prefs_common.fw_quotemark &&
1338 *prefs_common.fw_quotemark)
1339 qmark = prefs_common.fw_quotemark;
1343 compose_quote_fmt(compose, full_msginfo,
1344 prefs_common.fw_quotefmt,
1345 qmark, body, FALSE);
1346 compose_attach_parts(compose, msginfo);
1348 procmsg_msginfo_free(full_msginfo);
1351 SIGNAL_BLOCK(textbuf);
1353 if (account->auto_sig)
1354 compose_insert_sig(compose, FALSE);
1356 compose_wrap_all(compose);
1358 SIGNAL_UNBLOCK(textbuf);
1360 gtk_text_buffer_get_start_iter(textbuf, &iter);
1361 gtk_text_buffer_place_cursor(textbuf, &iter);
1363 gtk_widget_grab_focus(compose->header_last->entry);
1365 if (!no_extedit && prefs_common.auto_exteditor)
1366 compose_exec_ext_editor(compose);
1369 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1370 gchar *folderidentifier;
1372 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1373 folderidentifier = folder_item_get_identifier(msginfo->folder);
1374 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1375 g_free(folderidentifier);
1378 undo_unblock(compose->undostruct);
1380 compose->modified = FALSE;
1381 compose_set_title(compose);
1385 #undef INSERT_FW_HEADER
1387 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1390 GtkTextView *textview;
1391 GtkTextBuffer *textbuf;
1395 gboolean single_mail = TRUE;
1397 g_return_val_if_fail(msginfo_list != NULL, NULL);
1399 if (g_slist_length(msginfo_list) > 1)
1400 single_mail = FALSE;
1402 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1403 if (((MsgInfo *)msginfo->data)->folder == NULL)
1406 /* guess account from first selected message */
1408 !(account = compose_guess_forward_account_from_msginfo
1409 (msginfo_list->data)))
1410 account = cur_account;
1412 g_return_val_if_fail(account != NULL, NULL);
1414 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1415 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1416 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1419 compose = compose_create(account, COMPOSE_FORWARD);
1421 textview = GTK_TEXT_VIEW(compose->text);
1422 textbuf = gtk_text_view_get_buffer(textview);
1423 compose_create_tags(textview, compose);
1425 undo_block(compose->undostruct);
1426 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1427 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1428 if (!is_file_exist(msgfile))
1429 g_warning("%s: file not exist\n", msgfile);
1431 compose_attach_append(compose, msgfile, msgfile,
1437 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1438 if (info->subject && *info->subject) {
1439 gchar *buf, *buf2, *p;
1441 buf = p = g_strdup(info->subject);
1442 p += subject_get_prefix_length(p);
1443 memmove(buf, p, strlen(p) + 1);
1445 buf2 = g_strdup_printf("Fw: %s", buf);
1446 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1452 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1453 _("Fw: multiple emails"));
1456 SIGNAL_BLOCK(textbuf);
1458 if (account->auto_sig)
1459 compose_insert_sig(compose, FALSE);
1461 compose_wrap_all(compose);
1463 SIGNAL_UNBLOCK(textbuf);
1465 gtk_text_buffer_get_start_iter(textbuf, &iter);
1466 gtk_text_buffer_place_cursor(textbuf, &iter);
1468 gtk_widget_grab_focus(compose->header_last->entry);
1469 undo_unblock(compose->undostruct);
1470 compose->modified = FALSE;
1471 compose_set_title(compose);
1475 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1477 GtkTextIter start = *iter;
1478 GtkTextIter end_iter;
1479 int start_pos = gtk_text_iter_get_offset(&start);
1481 if (!compose->account->sig_sep)
1484 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1485 start_pos+strlen(compose->account->sig_sep));
1487 /* check sig separator */
1488 str = gtk_text_iter_get_text(&start, &end_iter);
1489 if (!strcmp(str, compose->account->sig_sep)) {
1491 /* check end of line (\n) */
1492 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1493 start_pos+strlen(compose->account->sig_sep));
1494 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1495 start_pos+strlen(compose->account->sig_sep)+1);
1496 tmp = gtk_text_iter_get_text(&start, &end_iter);
1497 if (!strcmp(tmp,"\n")) {
1509 static void compose_colorize_signature(Compose *compose)
1511 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1513 GtkTextIter end_iter;
1514 gtk_text_buffer_get_start_iter(buffer, &iter);
1515 while (gtk_text_iter_forward_line(&iter))
1516 if (compose_is_sig_separator(compose, buffer, &iter)) {
1517 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1518 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1522 void compose_reedit(MsgInfo *msginfo)
1524 Compose *compose = NULL;
1525 PrefsAccount *account = NULL;
1526 GtkTextView *textview;
1527 GtkTextBuffer *textbuf;
1531 gchar buf[BUFFSIZE];
1532 gboolean use_signing = FALSE;
1533 gboolean use_encryption = FALSE;
1534 gchar *privacy_system = NULL;
1536 g_return_if_fail(msginfo != NULL);
1537 g_return_if_fail(msginfo->folder != NULL);
1539 if (compose_put_existing_to_front(msginfo))
1542 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1543 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1544 gchar queueheader_buf[BUFFSIZE];
1547 /* Select Account from queue headers */
1548 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1549 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1550 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1551 account = account_find_from_id(id);
1553 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1554 sizeof(queueheader_buf), "NAID:")) {
1555 id = atoi(&queueheader_buf[strlen("NAID:")]);
1556 account = account_find_from_id(id);
1558 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1559 sizeof(queueheader_buf), "MAID:")) {
1560 id = atoi(&queueheader_buf[strlen("MAID:")]);
1561 account = account_find_from_id(id);
1563 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1564 sizeof(queueheader_buf), "S:")) {
1565 account = account_find_from_address(queueheader_buf);
1567 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1568 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1569 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1570 use_signing = param;
1573 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1574 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1575 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1576 use_encryption = param;
1578 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1579 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1580 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1582 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1583 sizeof(queueheader_buf), "X-Priority: ")) {
1584 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1585 compose->priority = param;
1588 account = msginfo->folder->folder->account;
1590 if (!account && prefs_common.reedit_account_autosel) {
1591 gchar from[BUFFSIZE];
1592 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1593 extract_address(from);
1594 account = account_find_from_address(from);
1597 if (!account) account = cur_account;
1598 g_return_if_fail(account != NULL);
1600 compose = compose_create(account, COMPOSE_REEDIT);
1601 if (privacy_system != NULL) {
1602 compose->privacy_system = privacy_system;
1603 compose_use_signing(compose, use_signing);
1604 compose_use_encryption(compose, use_encryption);
1605 compose_update_privacy_system_menu_item(compose, FALSE);
1607 activate_privacy_system(compose, account, FALSE);
1609 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1611 compose_extract_original_charset(compose);
1613 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1614 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1615 gchar queueheader_buf[BUFFSIZE];
1617 /* Set message save folder */
1618 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1621 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1622 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1623 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1625 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1626 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1628 GtkItemFactory *ifactory;
1629 ifactory = gtk_item_factory_from_widget(compose->menubar);
1630 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1635 if (compose_parse_header(compose, msginfo) < 0) return;
1636 compose_reedit_set_entry(compose, msginfo);
1638 textview = GTK_TEXT_VIEW(compose->text);
1639 textbuf = gtk_text_view_get_buffer(textview);
1640 compose_create_tags(textview, compose);
1642 mark = gtk_text_buffer_get_insert(textbuf);
1643 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1645 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1646 G_CALLBACK(compose_changed_cb),
1649 if (procmime_msginfo_is_encrypted(msginfo)) {
1650 fp = procmime_get_first_encrypted_text_content(msginfo);
1652 compose_force_encryption(compose, account, TRUE);
1654 fp = procmime_get_first_text_content(msginfo);
1656 g_warning("Can't get text part\n");
1659 gboolean prev_autowrap = compose->autowrap;
1661 compose->autowrap = FALSE;
1662 while (fgets(buf, sizeof(buf), fp) != NULL) {
1664 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1666 compose_wrap_all_full(compose, FALSE);
1667 compose->autowrap = prev_autowrap;
1671 compose_attach_parts(compose, msginfo);
1673 compose_colorize_signature(compose);
1675 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1676 G_CALLBACK(compose_changed_cb),
1679 gtk_widget_grab_focus(compose->text);
1681 if (prefs_common.auto_exteditor)
1682 compose_exec_ext_editor(compose);
1683 compose->modified = FALSE;
1684 compose_set_title(compose);
1687 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1691 GtkItemFactory *ifactory;
1694 g_return_val_if_fail(msginfo != NULL, NULL);
1697 account = account_get_reply_account(msginfo,
1698 prefs_common.reply_account_autosel);
1699 g_return_val_if_fail(account != NULL, NULL);
1701 compose = compose_create(account, COMPOSE_REDIRECT);
1702 ifactory = gtk_item_factory_from_widget(compose->menubar);
1703 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1704 compose->replyinfo = NULL;
1705 compose->fwdinfo = NULL;
1707 compose_show_first_last_header(compose, TRUE);
1709 gtk_widget_grab_focus(compose->header_last->entry);
1711 filename = procmsg_get_message_file_path(msginfo);
1712 if (filename == NULL)
1715 compose->redirect_filename = filename;
1717 /* Set save folder */
1718 item = msginfo->folder;
1719 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1720 gchar *folderidentifier;
1722 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1723 folderidentifier = folder_item_get_identifier(item);
1724 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1725 g_free(folderidentifier);
1728 compose_attach_parts(compose, msginfo);
1730 if (msginfo->subject)
1731 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1733 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1735 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1736 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1738 compose_colorize_signature(compose);
1740 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1741 menu_set_sensitive(ifactory, "/Add...", FALSE);
1742 menu_set_sensitive(ifactory, "/Remove", FALSE);
1743 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1745 ifactory = gtk_item_factory_from_widget(compose->menubar);
1746 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1747 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1748 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1749 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1750 menu_set_sensitive(ifactory, "/Edit", FALSE);
1751 menu_set_sensitive(ifactory, "/Options", FALSE);
1752 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1753 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1755 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1756 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1757 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1758 if (compose->toolbar->sig_btn)
1759 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1760 if (compose->toolbar->exteditor_btn)
1761 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1762 if (compose->toolbar->linewrap_current_btn)
1763 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1764 if (compose->toolbar->linewrap_all_btn)
1765 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1767 compose->modified = FALSE;
1768 compose_set_title(compose);
1772 GList *compose_get_compose_list(void)
1774 return compose_list;
1777 void compose_entry_append(Compose *compose, const gchar *address,
1778 ComposeEntryType type)
1782 gboolean in_quote = FALSE;
1783 if (!address || *address == '\0') return;
1790 header = N_("Bcc:");
1792 case COMPOSE_REPLYTO:
1793 header = N_("Reply-To:");
1795 case COMPOSE_NEWSGROUPS:
1796 header = N_("Newsgroups:");
1798 case COMPOSE_FOLLOWUPTO:
1799 header = N_( "Followup-To:");
1806 header = prefs_common.trans_hdr ? gettext(header) : header;
1808 cur = begin = (gchar *)address;
1810 /* we separate the line by commas, but not if we're inside a quoted
1812 while (*cur != '\0') {
1814 in_quote = !in_quote;
1815 if (*cur == ',' && !in_quote) {
1816 gchar *tmp = g_strdup(begin);
1818 tmp[cur-begin]='\0';
1823 compose_add_header_entry(compose, header, tmp);
1830 gchar *tmp = g_strdup(begin);
1832 tmp[cur-begin]='\0';
1837 compose_add_header_entry(compose, header, tmp);
1842 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1844 static GdkColor yellow;
1845 static GdkColor black;
1846 static gboolean yellow_initialised = FALSE;
1850 if (!yellow_initialised) {
1851 gdk_color_parse("#f5f6be", &yellow);
1852 gdk_color_parse("#000000", &black);
1853 yellow_initialised = gdk_colormap_alloc_color(
1854 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
1855 yellow_initialised &= gdk_colormap_alloc_color(
1856 gdk_colormap_get_system(), &black, FALSE, TRUE);
1859 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1860 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1861 if (gtk_entry_get_text(entry) &&
1862 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1863 if (yellow_initialised) {
1864 gtk_widget_modify_base(
1865 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1866 GTK_STATE_NORMAL, &yellow);
1867 gtk_widget_modify_text(
1868 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1869 GTK_STATE_NORMAL, &black);
1875 void compose_toolbar_cb(gint action, gpointer data)
1877 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1878 Compose *compose = (Compose*)toolbar_item->parent;
1880 g_return_if_fail(compose != NULL);
1884 compose_send_cb(compose, 0, NULL);
1887 compose_send_later_cb(compose, 0, NULL);
1890 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1893 compose_insert_file_cb(compose, 0, NULL);
1896 compose_attach_cb(compose, 0, NULL);
1899 compose_insert_sig(compose, FALSE);
1902 compose_ext_editor_cb(compose, 0, NULL);
1904 case A_LINEWRAP_CURRENT:
1905 compose_beautify_paragraph(compose, NULL, TRUE);
1907 case A_LINEWRAP_ALL:
1908 compose_wrap_all_full(compose, TRUE);
1911 compose_address_cb(compose, 0, NULL);
1914 case A_CHECK_SPELLING:
1915 compose_check_all(compose);
1923 static void compose_entries_set(Compose *compose, const gchar *mailto)
1927 gchar *subject = NULL;
1932 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1935 compose_entry_append(compose, to, COMPOSE_TO);
1937 compose_entry_append(compose, cc, COMPOSE_CC);
1939 if (!g_utf8_validate (subject, -1, NULL)) {
1940 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1941 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1944 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1948 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1949 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1952 gboolean prev_autowrap = compose->autowrap;
1954 compose->autowrap = FALSE;
1956 mark = gtk_text_buffer_get_insert(buffer);
1957 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1959 if (!g_utf8_validate (body, -1, NULL)) {
1960 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1961 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1964 gtk_text_buffer_insert(buffer, &iter, body, -1);
1966 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1968 compose->autowrap = prev_autowrap;
1969 if (compose->autowrap)
1970 compose_wrap_all(compose);
1979 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1981 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1982 {"Cc:", NULL, TRUE},
1983 {"References:", NULL, FALSE},
1984 {"Bcc:", NULL, TRUE},
1985 {"Newsgroups:", NULL, TRUE},
1986 {"Followup-To:", NULL, TRUE},
1987 {"List-Post:", NULL, FALSE},
1988 {"X-Priority:", NULL, FALSE},
1989 {NULL, NULL, FALSE}};
2005 g_return_val_if_fail(msginfo != NULL, -1);
2007 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2008 procheader_get_header_fields(fp, hentry);
2011 if (hentry[H_REPLY_TO].body != NULL) {
2012 if (hentry[H_REPLY_TO].body[0] != '\0') {
2014 conv_unmime_header(hentry[H_REPLY_TO].body,
2017 g_free(hentry[H_REPLY_TO].body);
2018 hentry[H_REPLY_TO].body = NULL;
2020 if (hentry[H_CC].body != NULL) {
2021 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2022 g_free(hentry[H_CC].body);
2023 hentry[H_CC].body = NULL;
2025 if (hentry[H_REFERENCES].body != NULL) {
2026 if (compose->mode == COMPOSE_REEDIT)
2027 compose->references = hentry[H_REFERENCES].body;
2029 compose->references = compose_parse_references
2030 (hentry[H_REFERENCES].body, msginfo->msgid);
2031 g_free(hentry[H_REFERENCES].body);
2033 hentry[H_REFERENCES].body = NULL;
2035 if (hentry[H_BCC].body != NULL) {
2036 if (compose->mode == COMPOSE_REEDIT)
2038 conv_unmime_header(hentry[H_BCC].body, NULL);
2039 g_free(hentry[H_BCC].body);
2040 hentry[H_BCC].body = NULL;
2042 if (hentry[H_NEWSGROUPS].body != NULL) {
2043 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2044 hentry[H_NEWSGROUPS].body = NULL;
2046 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2047 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2048 compose->followup_to =
2049 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2052 g_free(hentry[H_FOLLOWUP_TO].body);
2053 hentry[H_FOLLOWUP_TO].body = NULL;
2055 if (hentry[H_LIST_POST].body != NULL) {
2058 extract_address(hentry[H_LIST_POST].body);
2059 if (hentry[H_LIST_POST].body[0] != '\0') {
2060 scan_mailto_url(hentry[H_LIST_POST].body,
2061 &to, NULL, NULL, NULL, NULL);
2063 g_free(compose->ml_post);
2064 compose->ml_post = to;
2067 g_free(hentry[H_LIST_POST].body);
2068 hentry[H_LIST_POST].body = NULL;
2071 /* CLAWS - X-Priority */
2072 if (compose->mode == COMPOSE_REEDIT)
2073 if (hentry[H_X_PRIORITY].body != NULL) {
2076 priority = atoi(hentry[H_X_PRIORITY].body);
2077 g_free(hentry[H_X_PRIORITY].body);
2079 hentry[H_X_PRIORITY].body = NULL;
2081 if (priority < PRIORITY_HIGHEST ||
2082 priority > PRIORITY_LOWEST)
2083 priority = PRIORITY_NORMAL;
2085 compose->priority = priority;
2088 if (compose->mode == COMPOSE_REEDIT) {
2089 if (msginfo->inreplyto && *msginfo->inreplyto)
2090 compose->inreplyto = g_strdup(msginfo->inreplyto);
2094 if (msginfo->msgid && *msginfo->msgid)
2095 compose->inreplyto = g_strdup(msginfo->msgid);
2097 if (!compose->references) {
2098 if (msginfo->msgid && *msginfo->msgid) {
2099 if (msginfo->inreplyto && *msginfo->inreplyto)
2100 compose->references =
2101 g_strdup_printf("<%s>\n\t<%s>",
2105 compose->references =
2106 g_strconcat("<", msginfo->msgid, ">",
2108 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2109 compose->references =
2110 g_strconcat("<", msginfo->inreplyto, ">",
2118 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2120 GSList *ref_id_list, *cur;
2124 ref_id_list = references_list_append(NULL, ref);
2125 if (!ref_id_list) return NULL;
2126 if (msgid && *msgid)
2127 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2132 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2133 /* "<" + Message-ID + ">" + CR+LF+TAB */
2134 len += strlen((gchar *)cur->data) + 5;
2136 if (len > MAX_REFERENCES_LEN) {
2137 /* remove second message-ID */
2138 if (ref_id_list && ref_id_list->next &&
2139 ref_id_list->next->next) {
2140 g_free(ref_id_list->next->data);
2141 ref_id_list = g_slist_remove
2142 (ref_id_list, ref_id_list->next->data);
2144 slist_free_strings(ref_id_list);
2145 g_slist_free(ref_id_list);
2152 new_ref = g_string_new("");
2153 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2154 if (new_ref->len > 0)
2155 g_string_append(new_ref, "\n\t");
2156 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2159 slist_free_strings(ref_id_list);
2160 g_slist_free(ref_id_list);
2162 new_ref_str = new_ref->str;
2163 g_string_free(new_ref, FALSE);
2168 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2169 const gchar *fmt, const gchar *qmark,
2170 const gchar *body, gboolean rewrap)
2172 static MsgInfo dummyinfo;
2173 gchar *quote_str = NULL;
2175 gboolean prev_autowrap;
2176 const gchar *trimmed_body = body;
2177 gint cursor_pos = -1;
2178 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2179 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2184 SIGNAL_BLOCK(buffer);
2187 msginfo = &dummyinfo;
2189 if (qmark != NULL) {
2190 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2191 quote_fmt_scan_string(qmark);
2194 buf = quote_fmt_get_buffer();
2196 alertpanel_error(_("Quote mark format error."));
2198 Xstrdup_a(quote_str, buf, goto error)
2201 if (fmt && *fmt != '\0') {
2202 while (trimmed_body && strlen(trimmed_body) > 1
2203 && trimmed_body[0]=='\n')
2206 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2207 quote_fmt_scan_string(fmt);
2210 buf = quote_fmt_get_buffer();
2212 alertpanel_error(_("Message reply/forward format error."));
2218 prev_autowrap = compose->autowrap;
2219 compose->autowrap = FALSE;
2221 mark = gtk_text_buffer_get_insert(buffer);
2222 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2223 if (g_utf8_validate(buf, -1, NULL)) {
2224 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2226 gchar *tmpout = NULL;
2227 tmpout = conv_codeset_strdup
2228 (buf, conv_get_locale_charset_str(),
2230 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2232 tmpout = g_malloc(strlen(buf)*2+1);
2233 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2235 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2239 cursor_pos = quote_fmt_get_cursor_pos();
2240 compose->set_cursor_pos = cursor_pos;
2241 if (cursor_pos == -1) {
2244 gtk_text_buffer_get_start_iter(buffer, &iter);
2245 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2246 gtk_text_buffer_place_cursor(buffer, &iter);
2248 compose->autowrap = prev_autowrap;
2249 if (compose->autowrap && rewrap)
2250 compose_wrap_all(compose);
2257 SIGNAL_UNBLOCK(buffer);
2263 /* if ml_post is of type addr@host and from is of type
2264 * addr-anything@host, return TRUE
2266 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2268 gchar *left_ml = NULL;
2269 gchar *right_ml = NULL;
2270 gchar *left_from = NULL;
2271 gchar *right_from = NULL;
2272 gboolean result = FALSE;
2274 if (!ml_post || !from)
2277 left_ml = g_strdup(ml_post);
2278 if (strstr(left_ml, "@")) {
2279 right_ml = strstr(left_ml, "@")+1;
2280 *(strstr(left_ml, "@")) = '\0';
2283 left_from = g_strdup(from);
2284 if (strstr(left_from, "@")) {
2285 right_from = strstr(left_from, "@")+1;
2286 *(strstr(left_from, "@")) = '\0';
2289 if (left_ml && left_from && right_ml && right_from
2290 && !strncmp(left_from, left_ml, strlen(left_ml))
2291 && !strcmp(right_from, right_ml)) {
2300 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2302 gchar *my_addr1, *my_addr2;
2304 if (!addr1 || !addr2)
2307 Xstrdup_a(my_addr1, addr1, return FALSE);
2308 Xstrdup_a(my_addr2, addr2, return FALSE);
2310 extract_address(my_addr1);
2311 extract_address(my_addr2);
2313 return !strcmp(my_addr1, my_addr2);
2316 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2317 gboolean to_all, gboolean to_ml,
2319 gboolean followup_and_reply_to)
2321 GSList *cc_list = NULL;
2324 gchar *replyto = NULL;
2325 GHashTable *to_table;
2327 gboolean reply_to_ml = FALSE;
2328 gboolean default_reply_to = FALSE;
2330 g_return_if_fail(compose->account != NULL);
2331 g_return_if_fail(msginfo != NULL);
2333 reply_to_ml = to_ml && compose->ml_post;
2335 default_reply_to = msginfo->folder &&
2336 msginfo->folder->prefs->enable_default_reply_to;
2338 if (compose->account->protocol != A_NNTP) {
2339 if (reply_to_ml && !default_reply_to) {
2341 gboolean is_subscr = is_subscription(compose->ml_post,
2344 /* normal answer to ml post with a reply-to */
2345 compose_entry_append(compose,
2348 if (compose->replyto
2349 && !same_address(compose->ml_post, compose->replyto))
2350 compose_entry_append(compose,
2354 /* answer to subscription confirmation */
2355 if (compose->replyto)
2356 compose_entry_append(compose,
2359 else if (msginfo->from)
2360 compose_entry_append(compose,
2365 else if (!(to_all || to_sender) && default_reply_to) {
2366 compose_entry_append(compose,
2367 msginfo->folder->prefs->default_reply_to,
2369 compose_entry_mark_default_to(compose,
2370 msginfo->folder->prefs->default_reply_to);
2373 Xstrdup_a(tmp1, msginfo->from, return);
2374 extract_address(tmp1);
2375 if (to_all || to_sender ||
2376 !account_find_from_address(tmp1))
2377 compose_entry_append(compose,
2378 (compose->replyto && !to_sender)
2379 ? compose->replyto :
2380 msginfo->from ? msginfo->from : "",
2382 else if (!to_all && !to_sender) {
2383 /* reply to the last list of recipients */
2384 compose_entry_append(compose,
2385 msginfo->to ? msginfo->to : "",
2387 compose_entry_append(compose,
2388 msginfo->cc ? msginfo->cc : "",
2393 if (to_sender || (compose->followup_to &&
2394 !strncmp(compose->followup_to, "poster", 6)))
2395 compose_entry_append
2397 (compose->replyto ? compose->replyto :
2398 msginfo->from ? msginfo->from : ""),
2401 else if (followup_and_reply_to || to_all) {
2402 compose_entry_append
2404 (compose->replyto ? compose->replyto :
2405 msginfo->from ? msginfo->from : ""),
2408 compose_entry_append
2410 compose->followup_to ? compose->followup_to :
2411 compose->newsgroups ? compose->newsgroups : "",
2412 COMPOSE_NEWSGROUPS);
2415 compose_entry_append
2417 compose->followup_to ? compose->followup_to :
2418 compose->newsgroups ? compose->newsgroups : "",
2419 COMPOSE_NEWSGROUPS);
2422 if (msginfo->subject && *msginfo->subject) {
2426 buf = p = g_strdup(msginfo->subject);
2427 p += subject_get_prefix_length(p);
2428 memmove(buf, p, strlen(p) + 1);
2430 buf2 = g_strdup_printf("Re: %s", buf);
2431 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2436 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2438 if (to_ml && compose->ml_post) return;
2439 if (!to_all || compose->account->protocol == A_NNTP) return;
2441 if (compose->replyto) {
2442 Xstrdup_a(replyto, compose->replyto, return);
2443 extract_address(replyto);
2445 if (msginfo->from) {
2446 Xstrdup_a(from, msginfo->from, return);
2447 extract_address(from);
2450 if (replyto && from)
2451 cc_list = address_list_append_with_comments(cc_list, from);
2452 if (to_all && msginfo->folder &&
2453 msginfo->folder->prefs->enable_default_reply_to)
2454 cc_list = address_list_append_with_comments(cc_list,
2455 msginfo->folder->prefs->default_reply_to);
2456 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2457 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2459 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2461 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2462 if (compose->account)
2463 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2464 GINT_TO_POINTER(1));
2466 /* remove address on To: and that of current account */
2467 for (cur = cc_list; cur != NULL; ) {
2468 GSList *next = cur->next;
2471 addr = g_strdup(cur->data);
2472 extract_address(addr);
2474 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2475 cc_list = g_slist_remove(cc_list, cur->data);
2477 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2481 hash_free_strings(to_table);
2482 g_hash_table_destroy(to_table);
2485 for (cur = cc_list; cur != NULL; cur = cur->next)
2486 compose_entry_append(compose, (gchar *)cur->data,
2488 slist_free_strings(cc_list);
2489 g_slist_free(cc_list);
2494 #define SET_ENTRY(entry, str) \
2497 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2500 #define SET_ADDRESS(type, str) \
2503 compose_entry_append(compose, str, type); \
2506 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2508 g_return_if_fail(msginfo != NULL);
2510 SET_ENTRY(subject_entry, msginfo->subject);
2511 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2512 SET_ADDRESS(COMPOSE_CC, compose->cc);
2513 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2514 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2515 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2516 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2518 compose_update_priority_menu_item(compose);
2519 compose_update_privacy_system_menu_item(compose, FALSE);
2520 compose_show_first_last_header(compose, TRUE);
2526 static void compose_insert_sig(Compose *compose, gboolean replace)
2528 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2529 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2531 GtkTextIter iter, iter_end;
2533 gboolean prev_autowrap;
2536 g_return_if_fail(compose->account != NULL);
2538 prev_autowrap = compose->autowrap;
2539 compose->autowrap = FALSE;
2541 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2542 G_CALLBACK(compose_changed_cb),
2545 mark = gtk_text_buffer_get_insert(buffer);
2546 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2547 cur_pos = gtk_text_iter_get_offset (&iter);
2549 gtk_text_buffer_get_end_iter(buffer, &iter);
2551 if (replace && compose->sig_str) {
2553 GtkTextIter first_iter, start_iter, end_iter;
2555 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2557 if (compose->sig_str[0] == '\0')
2560 found = gtk_text_iter_forward_search(&first_iter,
2562 GTK_TEXT_SEARCH_TEXT_ONLY,
2563 &start_iter, &end_iter,
2567 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2572 g_free(compose->sig_str);
2573 compose->sig_str = compose_get_signature_str(compose);
2574 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2575 compose->sig_str = g_strdup("");
2577 cur_pos = gtk_text_iter_get_offset(&iter);
2578 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2580 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2581 gtk_text_iter_forward_char(&iter);
2582 gtk_text_iter_forward_char(&iter);
2583 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2584 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2586 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2587 cur_pos = gtk_text_buffer_get_char_count (buffer);
2589 /* put the cursor where it should be
2590 * either where the quote_fmt says, either before the signature */
2591 if (compose->set_cursor_pos < 0)
2592 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2594 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2595 compose->set_cursor_pos);
2597 gtk_text_buffer_place_cursor(buffer, &iter);
2598 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2599 G_CALLBACK(compose_changed_cb),
2602 compose->autowrap = prev_autowrap;
2603 if (compose->autowrap)
2604 compose_wrap_all(compose);
2607 static gchar *compose_get_signature_str(Compose *compose)
2609 gchar *sig_body = NULL;
2610 gchar *sig_str = NULL;
2611 gchar *utf8_sig_str = NULL;
2613 g_return_val_if_fail(compose->account != NULL, NULL);
2615 if (!compose->account->sig_path)
2618 if (compose->account->sig_type == SIG_FILE) {
2619 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2620 g_warning("can't open signature file: %s\n",
2621 compose->account->sig_path);
2626 if (compose->account->sig_type == SIG_COMMAND)
2627 sig_body = get_command_output(compose->account->sig_path);
2631 tmp = file_read_to_str(compose->account->sig_path);
2634 sig_body = normalize_newlines(tmp);
2638 if (compose->account->sig_sep) {
2639 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2643 sig_str = g_strconcat("\n\n", sig_body, NULL);
2646 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2647 utf8_sig_str = sig_str;
2649 utf8_sig_str = conv_codeset_strdup
2650 (sig_str, conv_get_locale_charset_str(),
2656 return utf8_sig_str;
2659 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2662 GtkTextBuffer *buffer;
2665 const gchar *cur_encoding;
2666 gchar buf[BUFFSIZE];
2669 gboolean prev_autowrap;
2670 gboolean badtxt = FALSE;
2672 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2674 if ((fp = g_fopen(file, "rb")) == NULL) {
2675 FILE_OP_ERROR(file, "fopen");
2676 return COMPOSE_INSERT_READ_ERROR;
2679 prev_autowrap = compose->autowrap;
2680 compose->autowrap = FALSE;
2682 text = GTK_TEXT_VIEW(compose->text);
2683 buffer = gtk_text_view_get_buffer(text);
2684 mark = gtk_text_buffer_get_insert(buffer);
2685 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2687 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2688 G_CALLBACK(text_inserted),
2691 cur_encoding = conv_get_locale_charset_str();
2693 while (fgets(buf, sizeof(buf), fp) != NULL) {
2696 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2697 str = g_strdup(buf);
2699 str = conv_codeset_strdup
2700 (buf, cur_encoding, CS_INTERNAL);
2703 /* strip <CR> if DOS/Windows file,
2704 replace <CR> with <LF> if Macintosh file. */
2707 if (len > 0 && str[len - 1] != '\n') {
2709 if (str[len] == '\r') str[len] = '\n';
2712 gtk_text_buffer_insert(buffer, &iter, str, -1);
2716 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2717 G_CALLBACK(text_inserted),
2719 compose->autowrap = prev_autowrap;
2720 if (compose->autowrap)
2721 compose_wrap_all(compose);
2726 return COMPOSE_INSERT_INVALID_CHARACTER;
2728 return COMPOSE_INSERT_SUCCESS;
2731 static void compose_attach_append(Compose *compose, const gchar *file,
2732 const gchar *filename,
2733 const gchar *content_type)
2741 GtkListStore *store;
2743 gboolean has_binary = FALSE;
2745 if (!is_file_exist(file)) {
2746 g_warning("File %s doesn't exist\n", filename);
2749 if ((size = get_file_size(file)) < 0) {
2750 g_warning("Can't get file size of %s\n", filename);
2754 alertpanel_notice(_("File %s is empty."), filename);
2757 if ((fp = g_fopen(file, "rb")) == NULL) {
2758 alertpanel_error(_("Can't read %s."), filename);
2763 ainfo = g_new0(AttachInfo, 1);
2764 auto_ainfo = g_auto_pointer_new_with_free
2765 (ainfo, (GFreeFunc) compose_attach_info_free);
2766 ainfo->file = g_strdup(file);
2769 ainfo->content_type = g_strdup(content_type);
2770 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2772 MsgFlags flags = {0, 0};
2774 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2775 ainfo->encoding = ENC_7BIT;
2777 ainfo->encoding = ENC_8BIT;
2779 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2780 if (msginfo && msginfo->subject)
2781 name = g_strdup(msginfo->subject);
2783 name = g_path_get_basename(filename ? filename : file);
2785 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2787 procmsg_msginfo_free(msginfo);
2789 if (!g_ascii_strncasecmp(content_type, "text", 4))
2790 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2792 ainfo->encoding = ENC_BASE64;
2793 name = g_path_get_basename(filename ? filename : file);
2794 ainfo->name = g_strdup(name);
2798 ainfo->content_type = procmime_get_mime_type(file);
2799 if (!ainfo->content_type) {
2800 ainfo->content_type =
2801 g_strdup("application/octet-stream");
2802 ainfo->encoding = ENC_BASE64;
2803 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2805 procmime_get_encoding_for_text_file(file, &has_binary);
2807 ainfo->encoding = ENC_BASE64;
2808 name = g_path_get_basename(filename ? filename : file);
2809 ainfo->name = g_strdup(name);
2813 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2814 g_free(ainfo->content_type);
2815 ainfo->content_type = g_strdup("application/octet-stream");
2819 size_text = to_human_readable(size);
2821 store = GTK_LIST_STORE(gtk_tree_view_get_model
2822 (GTK_TREE_VIEW(compose->attach_clist)));
2824 gtk_list_store_append(store, &iter);
2825 gtk_list_store_set(store, &iter,
2826 COL_MIMETYPE, ainfo->content_type,
2827 COL_SIZE, size_text,
2828 COL_NAME, ainfo->name,
2830 COL_AUTODATA, auto_ainfo,
2833 g_auto_pointer_free(auto_ainfo);
2836 static void compose_use_signing(Compose *compose, gboolean use_signing)
2838 GtkItemFactory *ifactory;
2839 GtkWidget *menuitem = NULL;
2841 compose->use_signing = use_signing;
2842 ifactory = gtk_item_factory_from_widget(compose->menubar);
2843 menuitem = gtk_item_factory_get_item
2844 (ifactory, "/Options/Sign");
2845 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2849 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2851 GtkItemFactory *ifactory;
2852 GtkWidget *menuitem = NULL;
2854 compose->use_encryption = use_encryption;
2855 ifactory = gtk_item_factory_from_widget(compose->menubar);
2856 menuitem = gtk_item_factory_get_item
2857 (ifactory, "/Options/Encrypt");
2859 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2863 #define NEXT_PART_NOT_CHILD(info) \
2865 node = info->node; \
2866 while (node->children) \
2867 node = g_node_last_child(node); \
2868 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2871 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2875 MimeInfo *firsttext = NULL;
2876 MimeInfo *encrypted = NULL;
2879 const gchar *partname = NULL;
2881 mimeinfo = procmime_scan_message(msginfo);
2882 if (!mimeinfo) return;
2884 if (mimeinfo->node->children == NULL) {
2885 procmime_mimeinfo_free_all(mimeinfo);
2889 /* find first content part */
2890 child = (MimeInfo *) mimeinfo->node->children->data;
2891 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2892 child = (MimeInfo *)child->node->children->data;
2894 if (child->type == MIMETYPE_TEXT) {
2896 debug_print("First text part found\n");
2897 } else if (compose->mode == COMPOSE_REEDIT &&
2898 child->type == MIMETYPE_APPLICATION &&
2899 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2900 encrypted = (MimeInfo *)child->node->parent->data;
2903 child = (MimeInfo *) mimeinfo->node->children->data;
2904 while (child != NULL) {
2905 if (child == encrypted) {
2906 /* skip this part of tree */
2907 NEXT_PART_NOT_CHILD(child);
2911 if (child->type == MIMETYPE_MULTIPART) {
2912 /* get the actual content */
2913 child = procmime_mimeinfo_next(child);
2917 if (child == firsttext) {
2918 child = procmime_mimeinfo_next(child);
2922 outfile = procmime_get_tmp_file_name(child);
2923 if (procmime_get_part(outfile, child) < 0)
2924 g_warning("Can't get the part of multipart message.");
2926 gchar *content_type;
2928 content_type = procmime_get_content_type_str(child->type, child->subtype);
2930 /* if we meet a pgp signature, we don't attach it, but
2931 * we force signing. */
2932 if (strcmp(content_type, "application/pgp-signature")) {
2933 partname = procmime_mimeinfo_get_parameter(child, "filename");
2934 if (partname == NULL)
2935 partname = procmime_mimeinfo_get_parameter(child, "name");
2936 if (partname == NULL)
2938 compose_attach_append(compose, outfile,
2939 partname, content_type);
2941 compose_force_signing(compose, compose->account);
2943 g_free(content_type);
2946 NEXT_PART_NOT_CHILD(child);
2948 procmime_mimeinfo_free_all(mimeinfo);
2951 #undef NEXT_PART_NOT_CHILD
2956 WAIT_FOR_INDENT_CHAR,
2957 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2960 /* return indent length, we allow:
2961 indent characters followed by indent characters or spaces/tabs,
2962 alphabets and numbers immediately followed by indent characters,
2963 and the repeating sequences of the above
2964 If quote ends with multiple spaces, only the first one is included. */
2965 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2966 const GtkTextIter *start, gint *len)
2968 GtkTextIter iter = *start;
2972 IndentState state = WAIT_FOR_INDENT_CHAR;
2975 gint alnum_count = 0;
2976 gint space_count = 0;
2979 if (prefs_common.quote_chars == NULL) {
2983 while (!gtk_text_iter_ends_line(&iter)) {
2984 wc = gtk_text_iter_get_char(&iter);
2985 if (g_unichar_iswide(wc))
2987 clen = g_unichar_to_utf8(wc, ch);
2991 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2992 is_space = g_unichar_isspace(wc);
2994 if (state == WAIT_FOR_INDENT_CHAR) {
2995 if (!is_indent && !g_unichar_isalnum(wc))
2998 quote_len += alnum_count + space_count + 1;
2999 alnum_count = space_count = 0;
3000 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3003 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3004 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3008 else if (is_indent) {
3009 quote_len += alnum_count + space_count + 1;
3010 alnum_count = space_count = 0;
3013 state = WAIT_FOR_INDENT_CHAR;
3017 gtk_text_iter_forward_char(&iter);
3020 if (quote_len > 0 && space_count > 0)
3026 if (quote_len > 0) {
3028 gtk_text_iter_forward_chars(&iter, quote_len);
3029 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3035 /* return TRUE if the line is itemized */
3036 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3037 const GtkTextIter *start)
3039 GtkTextIter iter = *start;
3044 if (gtk_text_iter_ends_line(&iter))
3048 wc = gtk_text_iter_get_char(&iter);
3049 if (!g_unichar_isspace(wc))
3051 gtk_text_iter_forward_char(&iter);
3052 if (gtk_text_iter_ends_line(&iter))
3056 clen = g_unichar_to_utf8(wc, ch);
3060 if (!strchr("*-+", ch[0]))
3063 gtk_text_iter_forward_char(&iter);
3064 if (gtk_text_iter_ends_line(&iter))
3066 wc = gtk_text_iter_get_char(&iter);
3067 if (g_unichar_isspace(wc))
3073 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3074 const GtkTextIter *start,
3075 GtkTextIter *break_pos,
3079 GtkTextIter iter = *start, line_end = *start;
3080 PangoLogAttr *attrs;
3087 gboolean can_break = FALSE;
3088 gboolean do_break = FALSE;
3089 gboolean was_white = FALSE;
3090 gboolean prev_dont_break = FALSE;
3092 gtk_text_iter_forward_to_line_end(&line_end);
3093 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3094 len = g_utf8_strlen(str, -1);
3095 /* g_print("breaking line: %d: %s (len = %d)\n",
3096 gtk_text_iter_get_line(&iter), str, len); */
3097 attrs = g_new(PangoLogAttr, len + 1);
3099 pango_default_break(str, -1, NULL, attrs, len + 1);
3103 /* skip quote and leading spaces */
3104 for (i = 0; *p != '\0' && i < len; i++) {
3107 wc = g_utf8_get_char(p);
3108 if (i >= quote_len && !g_unichar_isspace(wc))
3110 if (g_unichar_iswide(wc))
3112 else if (*p == '\t')
3116 p = g_utf8_next_char(p);
3119 for (; *p != '\0' && i < len; i++) {
3120 PangoLogAttr *attr = attrs + i;
3124 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3127 was_white = attr->is_white;
3129 /* don't wrap URI */
3130 if ((uri_len = get_uri_len(p)) > 0) {
3132 if (pos > 0 && col > max_col) {
3142 wc = g_utf8_get_char(p);
3143 if (g_unichar_iswide(wc)) {
3145 if (prev_dont_break && can_break && attr->is_line_break)
3147 } else if (*p == '\t')
3151 if (pos > 0 && col > max_col) {
3156 if (*p == '-' || *p == '/')
3157 prev_dont_break = TRUE;
3159 prev_dont_break = FALSE;
3161 p = g_utf8_next_char(p);
3165 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3170 *break_pos = *start;
3171 gtk_text_iter_set_line_offset(break_pos, pos);
3176 static gboolean compose_join_next_line(Compose *compose,
3177 GtkTextBuffer *buffer,
3179 const gchar *quote_str)
3181 GtkTextIter iter_ = *iter, cur, prev, next, end;
3182 PangoLogAttr attrs[3];
3184 gchar *next_quote_str;
3187 gboolean keep_cursor = FALSE;
3189 if (!gtk_text_iter_forward_line(&iter_) ||
3190 gtk_text_iter_ends_line(&iter_))
3193 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3195 if ((quote_str || next_quote_str) &&
3196 strcmp2(quote_str, next_quote_str) != 0) {
3197 g_free(next_quote_str);
3200 g_free(next_quote_str);
3203 if (quote_len > 0) {
3204 gtk_text_iter_forward_chars(&end, quote_len);
3205 if (gtk_text_iter_ends_line(&end))
3209 /* don't join itemized lines */
3210 if (compose_is_itemized(buffer, &end))
3213 /* don't join signature separator */
3214 if (compose_is_sig_separator(compose, buffer, &iter_))
3217 /* delete quote str */
3219 gtk_text_buffer_delete(buffer, &iter_, &end);
3221 /* don't join line breaks put by the user */
3223 gtk_text_iter_backward_char(&cur);
3224 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3225 gtk_text_iter_forward_char(&cur);
3229 gtk_text_iter_forward_char(&cur);
3230 /* delete linebreak and extra spaces */
3231 while (gtk_text_iter_backward_char(&cur)) {
3232 wc1 = gtk_text_iter_get_char(&cur);
3233 if (!g_unichar_isspace(wc1))
3238 while (!gtk_text_iter_ends_line(&cur)) {
3239 wc1 = gtk_text_iter_get_char(&cur);
3240 if (!g_unichar_isspace(wc1))
3242 gtk_text_iter_forward_char(&cur);
3245 if (!gtk_text_iter_equal(&prev, &next)) {
3248 mark = gtk_text_buffer_get_insert(buffer);
3249 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3250 if (gtk_text_iter_equal(&prev, &cur))
3252 gtk_text_buffer_delete(buffer, &prev, &next);
3256 /* insert space if required */
3257 gtk_text_iter_backward_char(&prev);
3258 wc1 = gtk_text_iter_get_char(&prev);
3259 wc2 = gtk_text_iter_get_char(&next);
3260 gtk_text_iter_forward_char(&next);
3261 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3262 pango_default_break(str, -1, NULL, attrs, 3);
3263 if (!attrs[1].is_line_break ||
3264 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3265 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3267 gtk_text_iter_backward_char(&iter_);
3268 gtk_text_buffer_place_cursor(buffer, &iter_);
3277 #define ADD_TXT_POS(bp_, ep_, pti_) \
3278 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3279 last = last->next; \
3280 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3281 last->next = NULL; \
3283 g_warning("alloc error scanning URIs\n"); \
3286 static gboolean automatic_break = FALSE;
3287 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3289 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3290 GtkTextBuffer *buffer;
3291 GtkTextIter iter, break_pos, end_of_line;
3292 gchar *quote_str = NULL;
3294 gboolean wrap_quote = prefs_common.linewrap_quote;
3295 gboolean prev_autowrap = compose->autowrap;
3296 gint startq_offset = -1, noq_offset = -1;
3297 gint uri_start = -1, uri_stop = -1;
3298 gint nouri_start = -1, nouri_stop = -1;
3299 gint num_blocks = 0;
3301 compose->autowrap = FALSE;
3303 buffer = gtk_text_view_get_buffer(text);
3304 undo_wrapping(compose->undostruct, TRUE);
3309 mark = gtk_text_buffer_get_insert(buffer);
3310 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3313 /* move to paragraph start */
3314 gtk_text_iter_set_line_offset(&iter, 0);
3315 if (gtk_text_iter_ends_line(&iter)) {
3316 while (gtk_text_iter_ends_line(&iter) &&
3317 gtk_text_iter_forward_line(&iter))
3320 while (gtk_text_iter_backward_line(&iter)) {
3321 if (gtk_text_iter_ends_line(&iter)) {
3322 gtk_text_iter_forward_line(&iter);
3328 /* go until paragraph end (empty line) */
3330 while (!gtk_text_iter_ends_line(&iter)) {
3331 gchar *scanpos = NULL;
3332 /* parse table - in order of priority */
3334 const gchar *needle; /* token */
3336 /* token search function */
3337 gchar *(*search) (const gchar *haystack,
3338 const gchar *needle);
3339 /* part parsing function */
3340 gboolean (*parse) (const gchar *start,
3341 const gchar *scanpos,
3345 /* part to URI function */
3346 gchar *(*build_uri) (const gchar *bp,
3350 static struct table parser[] = {
3351 {"http://", strcasestr, get_uri_part, make_uri_string},
3352 {"https://", strcasestr, get_uri_part, make_uri_string},
3353 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3354 {"www.", strcasestr, get_uri_part, make_http_string},
3355 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3356 {"@", strcasestr, get_email_part, make_email_string}
3358 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3359 gint last_index = PARSE_ELEMS;
3361 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3364 if (!prev_autowrap && num_blocks == 0) {
3366 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3367 G_CALLBACK(text_inserted),
3370 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3373 uri_start = uri_stop = -1;
3375 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3379 if (startq_offset == -1) {
3380 startq_offset = gtk_text_iter_get_offset(&iter);
3384 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3385 if (startq_offset == -1)
3386 startq_offset = gtk_text_iter_get_offset(&iter);
3388 if (startq_offset == -1)
3389 noq_offset = gtk_text_iter_get_offset(&iter);
3392 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3395 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3396 prefs_common.linewrap_len,
3398 GtkTextIter prev, next, cur;
3400 if (prev_autowrap != FALSE || force) {
3401 automatic_break = TRUE;
3402 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3403 automatic_break = FALSE;
3404 } else if (quote_str && wrap_quote) {
3405 automatic_break = TRUE;
3406 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3407 automatic_break = FALSE;
3410 /* remove trailing spaces */
3412 gtk_text_iter_backward_char(&cur);
3414 while (!gtk_text_iter_starts_line(&cur)) {
3417 gtk_text_iter_backward_char(&cur);
3418 wc = gtk_text_iter_get_char(&cur);
3419 if (!g_unichar_isspace(wc))
3423 if (!gtk_text_iter_equal(&prev, &next)) {
3424 gtk_text_buffer_delete(buffer, &prev, &next);
3426 gtk_text_iter_forward_char(&break_pos);
3430 gtk_text_buffer_insert(buffer, &break_pos,
3434 compose_join_next_line(compose, buffer, &iter, quote_str);
3436 /* move iter to current line start */
3437 gtk_text_iter_set_line_offset(&iter, 0);
3444 /* move iter to next line start */
3449 if (!prev_autowrap && num_blocks > 0) {
3451 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3452 G_CALLBACK(text_inserted),
3456 while (!gtk_text_iter_ends_line(&end_of_line)) {
3457 gtk_text_iter_forward_char(&end_of_line);
3459 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3461 nouri_start = gtk_text_iter_get_offset(&iter);
3462 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3464 walk_pos = gtk_text_iter_get_offset(&iter);
3465 /* FIXME: this looks phony. scanning for anything in the parse table */
3466 for (n = 0; n < PARSE_ELEMS; n++) {
3469 tmp = parser[n].search(walk, parser[n].needle);
3471 if (scanpos == NULL || tmp < scanpos) {
3480 /* check if URI can be parsed */
3481 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3482 (const gchar **)&ep, FALSE)
3483 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3487 strlen(parser[last_index].needle);
3490 uri_start = walk_pos + (bp - o_walk);
3491 uri_stop = walk_pos + (ep - o_walk);
3495 gtk_text_iter_forward_line(&iter);
3498 if (startq_offset != -1) {
3499 GtkTextIter startquote, endquote;
3500 gtk_text_buffer_get_iter_at_offset(
3501 buffer, &startquote, startq_offset);
3503 gtk_text_buffer_apply_tag_by_name(
3504 buffer, "quote", &startquote, &endquote);
3506 } else if (noq_offset != -1) {
3507 GtkTextIter startnoquote, endnoquote;
3508 gtk_text_buffer_get_iter_at_offset(
3509 buffer, &startnoquote, noq_offset);
3511 gtk_text_buffer_remove_tag_by_name(
3512 buffer, "quote", &startnoquote, &endnoquote);
3517 GtkTextIter nouri_start_iter, nouri_end_iter;
3518 gtk_text_buffer_get_iter_at_offset(
3519 buffer, &nouri_start_iter, nouri_start);
3520 gtk_text_buffer_get_iter_at_offset(
3521 buffer, &nouri_end_iter, nouri_stop);
3522 gtk_text_buffer_remove_tag_by_name(
3523 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3525 if (uri_start > 0 && uri_stop > 0) {
3526 GtkTextIter uri_start_iter, uri_end_iter;
3527 gtk_text_buffer_get_iter_at_offset(
3528 buffer, &uri_start_iter, uri_start);
3529 gtk_text_buffer_get_iter_at_offset(
3530 buffer, &uri_end_iter, uri_stop);
3531 gtk_text_buffer_apply_tag_by_name(
3532 buffer, "link", &uri_start_iter, &uri_end_iter);
3538 undo_wrapping(compose->undostruct, FALSE);
3539 compose->autowrap = prev_autowrap;
3542 void compose_action_cb(void *data)
3544 Compose *compose = (Compose *)data;
3545 compose_wrap_all(compose);
3548 static void compose_wrap_all(Compose *compose)
3550 compose_wrap_all_full(compose, FALSE);
3553 static void compose_wrap_all_full(Compose *compose, gboolean force)
3555 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3556 GtkTextBuffer *buffer;
3559 buffer = gtk_text_view_get_buffer(text);
3561 gtk_text_buffer_get_start_iter(buffer, &iter);
3562 while (!gtk_text_iter_is_end(&iter))
3563 compose_beautify_paragraph(compose, &iter, force);
3567 static void compose_set_title(Compose *compose)
3573 edited = compose->modified ? _(" [Edited]") : "";
3575 subject = gtk_editable_get_chars(
3576 GTK_EDITABLE(compose->subject_entry), 0, -1);
3578 if (subject && strlen(subject))
3579 str = g_strdup_printf(_("%s - Compose message%s"),
3582 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3583 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3589 * compose_current_mail_account:
3591 * Find a current mail account (the currently selected account, or the
3592 * default account, if a news account is currently selected). If a
3593 * mail account cannot be found, display an error message.
3595 * Return value: Mail account, or NULL if not found.
3597 static PrefsAccount *
3598 compose_current_mail_account(void)
3602 if (cur_account && cur_account->protocol != A_NNTP)
3605 ac = account_get_default();
3606 if (!ac || ac->protocol == A_NNTP) {
3607 alertpanel_error(_("Account for sending mail is not specified.\n"
3608 "Please select a mail account before sending."));
3615 static void compose_select_account(Compose *compose, PrefsAccount *account,
3618 GtkItemFactory *ifactory;
3620 g_return_if_fail(account != NULL);
3622 compose->account = account;
3624 compose_set_title(compose);
3626 ifactory = gtk_item_factory_from_widget(compose->menubar);
3628 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3629 menu_set_active(ifactory, "/Options/Sign", TRUE);
3631 menu_set_active(ifactory, "/Options/Sign", FALSE);
3632 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3633 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3635 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3637 activate_privacy_system(compose, account, FALSE);
3639 if (!init && compose->mode != COMPOSE_REDIRECT)
3640 compose_insert_sig(compose, TRUE);
3643 gboolean compose_check_for_valid_recipient(Compose *compose) {
3644 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3645 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3646 gboolean recipient_found = FALSE;
3650 /* free to and newsgroup list */
3651 slist_free_strings(compose->to_list);
3652 g_slist_free(compose->to_list);
3653 compose->to_list = NULL;
3655 slist_free_strings(compose->newsgroup_list);
3656 g_slist_free(compose->newsgroup_list);
3657 compose->newsgroup_list = NULL;
3659 /* search header entries for to and newsgroup entries */
3660 for (list = compose->header_list; list; list = list->next) {
3663 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3664 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3666 if (entry[0] != '\0') {
3667 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3668 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3669 compose->to_list = address_list_append(compose->to_list, entry);
3670 recipient_found = TRUE;
3673 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3674 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3675 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3676 recipient_found = TRUE;
3683 return recipient_found;
3686 static gboolean compose_check_for_set_recipients(Compose *compose)
3688 if (compose->account->set_autocc && compose->account->auto_cc) {
3689 gboolean found_other = FALSE;
3691 /* search header entries for to and newsgroup entries */
3692 for (list = compose->header_list; list; list = list->next) {
3695 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3696 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3698 if (strcmp(entry, compose->account->auto_cc)
3699 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3709 aval = alertpanel(_("Send"),
3710 _("The only recipient is the default CC address. Send anyway?"),
3711 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3712 if (aval != G_ALERTALTERNATE)
3716 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3717 gboolean found_other = FALSE;
3719 /* search header entries for to and newsgroup entries */
3720 for (list = compose->header_list; list; list = list->next) {
3723 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3724 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3726 if (strcmp(entry, compose->account->auto_cc)
3727 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3737 aval = alertpanel(_("Send"),
3738 _("The only recipient is the default BCC address. Send anyway?"),
3739 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3740 if (aval != G_ALERTALTERNATE)
3747 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3751 if (compose_check_for_valid_recipient(compose) == FALSE) {
3752 alertpanel_error(_("Recipient is not specified."));
3756 if (compose_check_for_set_recipients(compose) == FALSE) {
3760 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3761 if (*str == '\0' && check_subject == TRUE) {
3764 aval = alertpanel(_("Send"),
3765 _("Subject is empty. Send it anyway?"),
3766 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3767 if (aval != G_ALERTALTERNATE)
3774 gint compose_send(Compose *compose)
3779 gchar *msgpath = NULL;
3781 compose_allow_user_actions (compose, FALSE);
3782 compose->sending = TRUE;
3784 if (compose_check_entries(compose, TRUE) == FALSE)
3787 val = compose_queue(compose, &msgnum, &folder, &msgpath);
3791 alertpanel_error(_("Could not queue message for sending:\n\n"
3792 "Charset conversion failed."));
3793 } else if (val == -3) {
3794 alertpanel_error(_("Could not queue message for sending:\n\n"
3795 "Signature failed."));
3796 } else if (val == -2 && errno != 0) {
3797 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3799 alertpanel_error(_("Could not queue message for sending."));
3805 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3806 compose->sending = FALSE;
3807 compose_close(compose);
3808 /* No more compose access in the normal codepath
3809 * after this point! */
3814 alertpanel_error(_("The message was queued but could not be "
3815 "sent.\nUse \"Send queued messages\" from "
3816 "the main window to retry."));
3817 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3818 compose->sending = FALSE;
3819 compose->modified = TRUE;
3820 compose_allow_user_actions (compose, TRUE);
3825 if (msgpath == NULL) {
3826 msgpath = folder_item_fetch_msg(folder, msgnum);
3827 val = procmsg_send_message_queue(msgpath);
3830 val = procmsg_send_message_queue(msgpath);
3834 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3835 compose->sending = FALSE;
3836 compose_allow_user_actions (compose, TRUE);
3838 folder_item_remove_msg(folder, msgnum);
3839 folder_item_scan(folder);
3844 folder_item_remove_msg(folder, msgnum);
3845 folder_item_scan(folder);
3846 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3847 compose_close(compose);
3849 alertpanel_error(_("The message was queued but could not be "
3850 "sent.\nUse \"Send queued messages\" from "
3851 "the main window to retry."));
3852 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3853 compose_allow_user_actions (compose, TRUE);
3854 compose->modified = TRUE;
3855 compose->sending = FALSE;
3863 compose_allow_user_actions (compose, TRUE);
3864 compose->sending = FALSE;
3865 compose->modified = TRUE;
3870 static gboolean compose_use_attach(Compose *compose)
3872 GtkTreeModel *model = gtk_tree_view_get_model
3873 (GTK_TREE_VIEW(compose->attach_clist));
3874 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3877 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3880 gchar buf[BUFFSIZE];
3882 gboolean first_to_address;
3883 gboolean first_cc_address;
3885 ComposeHeaderEntry *headerentry;
3886 const gchar *headerentryname;
3890 debug_print("Writing redirect header\n");
3892 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3893 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3895 first_to_address = TRUE;
3896 for (list = compose->header_list; list; list = list->next) {
3897 headerentry = ((ComposeHeaderEntry *)list->data);
3898 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3900 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3901 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3902 Xstrdup_a(str, entstr, return -1);
3904 if (str[0] != '\0') {
3905 compose_convert_header
3906 (compose, buf, sizeof(buf), str,
3907 strlen("Resent-To") + 2, TRUE);
3909 if (first_to_address) {
3910 fprintf(fp, "Resent-To: ");
3911 first_to_address = FALSE;
3915 fprintf(fp, "%s", buf);
3919 if (!first_to_address) {
3923 first_cc_address = TRUE;
3924 for (list = compose->header_list; list; list = list->next) {
3925 headerentry = ((ComposeHeaderEntry *)list->data);
3926 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3928 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3929 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3930 Xstrdup_a(str, strg, return -1);
3932 if (str[0] != '\0') {
3933 compose_convert_header
3934 (compose, buf, sizeof(buf), str,
3935 strlen("Resent-Cc") + 2, TRUE);
3937 if (first_cc_address) {
3938 fprintf(fp, "Resent-Cc: ");
3939 first_cc_address = FALSE;
3943 fprintf(fp, "%s", buf);
3947 if (!first_cc_address) {
3954 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3956 gchar buf[BUFFSIZE];
3958 const gchar *entstr;
3959 /* struct utsname utsbuf; */
3961 g_return_val_if_fail(fp != NULL, -1);
3962 g_return_val_if_fail(compose->account != NULL, -1);
3963 g_return_val_if_fail(compose->account->address != NULL, -1);
3966 get_rfc822_date(buf, sizeof(buf));
3967 fprintf(fp, "Resent-Date: %s\n", buf);
3970 if (compose->account->name && *compose->account->name) {
3971 compose_convert_header
3972 (compose, buf, sizeof(buf), compose->account->name,
3973 strlen("From: "), TRUE);
3974 fprintf(fp, "Resent-From: %s <%s>\n",
3975 buf, compose->account->address);
3977 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3980 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3981 if (*entstr != '\0') {
3982 Xstrdup_a(str, entstr, return -1);
3985 compose_convert_header(compose, buf, sizeof(buf), str,
3986 strlen("Subject: "), FALSE);
3987 fprintf(fp, "Subject: %s\n", buf);
3991 /* Resent-Message-ID */
3992 if (compose->account->gen_msgid) {
3993 generate_msgid(buf, sizeof(buf));
3994 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3995 compose->msgid = g_strdup(buf);
3998 compose_redirect_write_headers_from_headerlist(compose, fp);
4000 /* separator between header and body */
4006 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4010 gchar buf[BUFFSIZE];
4012 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4013 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4017 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4018 /* should filter returnpath, delivered-to */
4019 if (g_ascii_strncasecmp(buf, "Return-Path:",
4020 strlen("Return-Path:")) == 0 ||
4021 g_ascii_strncasecmp(buf, "Delivered-To:",
4022 strlen("Delivered-To:")) == 0 ||
4023 g_ascii_strncasecmp(buf, "Received:",
4024 strlen("Received:")) == 0 ||
4025 g_ascii_strncasecmp(buf, "Subject:",
4026 strlen("Subject:")) == 0 ||
4027 g_ascii_strncasecmp(buf, "X-UIDL:",
4028 strlen("X-UIDL:")) == 0)
4031 if (fputs(buf, fdest) == -1)
4034 if (!prefs_common.redirect_keep_from) {
4035 if (g_ascii_strncasecmp(buf, "From:",
4036 strlen("From:")) == 0) {
4037 fputs(" (by way of ", fdest);
4038 if (compose->account->name
4039 && *compose->account->name) {
4040 compose_convert_header
4041 (compose, buf, sizeof(buf),
4042 compose->account->name,
4045 fprintf(fdest, "%s <%s>",
4047 compose->account->address);
4049 fprintf(fdest, "%s",
4050 compose->account->address);
4055 if (fputs("\n", fdest) == -1)
4059 compose_redirect_write_headers(compose, fdest);
4061 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4062 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4075 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4077 GtkTextBuffer *buffer;
4078 GtkTextIter start, end;
4081 const gchar *out_codeset;
4082 EncodingType encoding;
4083 MimeInfo *mimemsg, *mimetext;
4086 /* create message MimeInfo */
4087 mimemsg = procmime_mimeinfo_new();
4088 mimemsg->type = MIMETYPE_MESSAGE;
4089 mimemsg->subtype = g_strdup("rfc822");
4090 mimemsg->content = MIMECONTENT_MEM;
4091 mimemsg->tmp = TRUE; /* must free content later */
4092 mimemsg->data.mem = compose_get_header(compose);
4094 /* Create text part MimeInfo */
4095 /* get all composed text */
4096 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4097 gtk_text_buffer_get_start_iter(buffer, &start);
4098 gtk_text_buffer_get_end_iter(buffer, &end);
4099 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4100 if (is_ascii_str(chars)) {
4103 out_codeset = CS_US_ASCII;
4104 encoding = ENC_7BIT;
4106 const gchar *src_codeset = CS_INTERNAL;
4108 out_codeset = conv_get_charset_str(compose->out_encoding);
4111 gchar *test_conv_global_out = NULL;
4112 gchar *test_conv_reply = NULL;
4114 /* automatic mode. be automatic. */
4115 codeconv_set_strict(TRUE);
4117 out_codeset = conv_get_outgoing_charset_str();
4119 debug_print("trying to convert to %s\n", out_codeset);
4120 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4123 if (!test_conv_global_out && compose->orig_charset
4124 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4125 out_codeset = compose->orig_charset;
4126 debug_print("failure; trying to convert to %s\n", out_codeset);
4127 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4130 if (!test_conv_global_out && !test_conv_reply) {
4132 out_codeset = CS_INTERNAL;
4133 debug_print("failure; finally using %s\n", out_codeset);
4135 g_free(test_conv_global_out);
4136 g_free(test_conv_reply);
4137 codeconv_set_strict(FALSE);
4140 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4141 out_codeset = CS_ISO_8859_1;
4143 if (prefs_common.encoding_method == CTE_BASE64)
4144 encoding = ENC_BASE64;
4145 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4146 encoding = ENC_QUOTED_PRINTABLE;
4147 else if (prefs_common.encoding_method == CTE_8BIT)
4148 encoding = ENC_8BIT;
4150 encoding = procmime_get_encoding_for_charset(out_codeset);
4152 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4153 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4155 if (action == COMPOSE_WRITE_FOR_SEND) {
4156 codeconv_set_strict(TRUE);
4157 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4158 codeconv_set_strict(FALSE);
4164 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4165 "to the specified %s charset.\n"
4166 "Send it as %s?"), out_codeset, src_codeset);
4167 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4168 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4171 if (aval != G_ALERTALTERNATE) {
4176 out_codeset = src_codeset;
4182 out_codeset = src_codeset;
4188 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4189 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4190 strstr(buf, "\nFrom ") != NULL) {
4191 encoding = ENC_QUOTED_PRINTABLE;
4195 mimetext = procmime_mimeinfo_new();
4196 mimetext->content = MIMECONTENT_MEM;
4197 mimetext->tmp = TRUE; /* must free content later */
4198 mimetext->data.mem = buf;
4199 mimetext->type = MIMETYPE_TEXT;
4200 mimetext->subtype = g_strdup("plain");
4201 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4202 g_strdup(out_codeset));
4203 /* protect trailing spaces when signing message */
4204 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4205 privacy_system_can_sign(compose->privacy_system)) {
4206 encoding = ENC_QUOTED_PRINTABLE;
4209 /* check for line length limit */
4210 if (action == COMPOSE_WRITE_FOR_SEND &&
4211 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4212 check_line_length(buf, 1000, &line) < 0) {
4216 msg = g_strdup_printf
4217 (_("Line %d exceeds the line length limit (998 bytes).\n"
4218 "The contents of the message might be broken on the way to the delivery.\n"
4220 "Send it anyway?"), line + 1);
4221 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4223 if (aval != G_ALERTALTERNATE) {
4228 if (encoding != ENC_UNKNOWN)
4229 procmime_encode_content(mimetext, encoding);
4231 /* append attachment parts */
4232 if (compose_use_attach(compose)) {
4233 MimeInfo *mimempart;
4234 gchar *boundary = NULL;
4235 mimempart = procmime_mimeinfo_new();
4236 mimempart->content = MIMECONTENT_EMPTY;
4237 mimempart->type = MIMETYPE_MULTIPART;
4238 mimempart->subtype = g_strdup("mixed");
4243 boundary = generate_mime_boundary(NULL);
4244 } while (strstr(buf, boundary) != NULL);
4246 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4249 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4251 g_node_append(mimempart->node, mimetext->node);
4252 g_node_append(mimemsg->node, mimempart->node);
4254 compose_add_attachments(compose, mimempart);
4256 g_node_append(mimemsg->node, mimetext->node);
4258 /* sign message if sending */
4259 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4260 privacy_system_can_sign(compose->privacy_system))
4261 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4264 procmime_write_mimeinfo(mimemsg, fp);
4266 procmime_mimeinfo_free_all(mimemsg);
4271 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4273 GtkTextBuffer *buffer;
4274 GtkTextIter start, end;
4279 if ((fp = g_fopen(file, "wb")) == NULL) {
4280 FILE_OP_ERROR(file, "fopen");
4284 /* chmod for security */
4285 if (change_file_mode_rw(fp, file) < 0) {
4286 FILE_OP_ERROR(file, "chmod");
4287 g_warning("can't change file mode\n");
4290 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4291 gtk_text_buffer_get_start_iter(buffer, &start);
4292 gtk_text_buffer_get_end_iter(buffer, &end);
4293 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4295 chars = conv_codeset_strdup
4296 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4299 if (!chars) return -1;
4302 len = strlen(chars);
4303 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4304 FILE_OP_ERROR(file, "fwrite");
4313 if (fclose(fp) == EOF) {
4314 FILE_OP_ERROR(file, "fclose");
4321 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4324 MsgInfo *msginfo = compose->targetinfo;
4326 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4327 if (!msginfo) return -1;
4329 if (!force && MSG_IS_LOCKED(msginfo->flags))
4332 item = msginfo->folder;
4333 g_return_val_if_fail(item != NULL, -1);
4335 if (procmsg_msg_exist(msginfo) &&
4336 (folder_has_parent_of_type(item, F_QUEUE) ||
4337 folder_has_parent_of_type(item, F_DRAFT)
4338 || msginfo == compose->autosaved_draft)) {
4339 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4340 g_warning("can't remove the old message\n");
4348 void compose_remove_draft(Compose *compose)
4351 MsgInfo *msginfo = compose->targetinfo;
4352 drafts = account_get_special_folder(compose->account, F_DRAFT);
4354 if (procmsg_msg_exist(msginfo)) {
4355 folder_item_remove_msg(drafts, msginfo->msgnum);
4360 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath)
4362 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE);
4364 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath, gboolean check_subject)
4371 static gboolean lock = FALSE;
4372 PrefsAccount *mailac = NULL, *newsac = NULL;
4374 debug_print("queueing message...\n");
4375 g_return_val_if_fail(compose->account != NULL, -1);
4379 if (compose_check_entries(compose, check_subject) == FALSE) {
4384 if (!compose->to_list && !compose->newsgroup_list) {
4385 g_warning("can't get recipient list.");
4390 if (compose->to_list) {
4391 if (compose->account->protocol != A_NNTP)
4392 mailac = compose->account;
4393 else if (cur_account && cur_account->protocol != A_NNTP)
4394 mailac = cur_account;
4395 else if (!(mailac = compose_current_mail_account())) {
4397 alertpanel_error(_("No account for sending mails available!"));
4402 if (compose->newsgroup_list) {
4403 if (compose->account->protocol == A_NNTP)
4404 newsac = compose->account;
4405 else if (!newsac->protocol != A_NNTP) {
4407 alertpanel_error(_("No account for posting news available!"));
4412 /* write queue header */
4413 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4414 G_DIR_SEPARATOR, compose);
4415 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4416 FILE_OP_ERROR(tmp, "fopen");
4421 if (change_file_mode_rw(fp, tmp) < 0) {
4422 FILE_OP_ERROR(tmp, "chmod");
4423 g_warning("can't change file mode\n");
4426 /* queueing variables */
4427 fprintf(fp, "AF:\n");
4428 fprintf(fp, "NF:0\n");
4429 fprintf(fp, "PS:10\n");
4430 fprintf(fp, "SRH:1\n");
4431 fprintf(fp, "SFN:\n");
4432 fprintf(fp, "DSR:\n");
4434 fprintf(fp, "MID:<%s>\n", compose->msgid);
4436 fprintf(fp, "MID:\n");
4437 fprintf(fp, "CFG:\n");
4438 fprintf(fp, "PT:0\n");
4439 fprintf(fp, "S:%s\n", compose->account->address);
4440 fprintf(fp, "RQ:\n");
4442 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4444 fprintf(fp, "SSV:\n");
4446 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4448 fprintf(fp, "NSV:\n");
4449 fprintf(fp, "SSH:\n");
4450 /* write recepient list */
4451 if (compose->to_list) {
4452 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4453 for (cur = compose->to_list->next; cur != NULL;
4455 fprintf(fp, ",<%s>", (gchar *)cur->data);
4458 /* write newsgroup list */
4459 if (compose->newsgroup_list) {
4461 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4462 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4463 fprintf(fp, ",%s", (gchar *)cur->data);
4466 /* Sylpheed account IDs */
4468 fprintf(fp, "MAID:%d\n", mailac->account_id);
4470 fprintf(fp, "NAID:%d\n", newsac->account_id);
4472 if (compose->privacy_system != NULL) {
4473 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4474 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4475 if (compose->use_encryption) {
4478 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4479 if (encdata != NULL) {
4480 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4481 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4482 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4484 } /* else we finally dont want to encrypt */
4486 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4487 /* and if encdata was null, it means there's been a problem in
4494 /* Save copy folder */
4495 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4496 gchar *savefolderid;
4498 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4499 fprintf(fp, "SCF:%s\n", savefolderid);
4500 g_free(savefolderid);
4502 /* Save copy folder */
4503 if (compose->return_receipt) {
4504 fprintf(fp, "RRCPT:1\n");
4506 /* Message-ID of message replying to */
4507 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4510 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4511 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4514 /* Message-ID of message forwarding to */
4515 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4518 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4519 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4524 if (compose->redirect_filename != NULL) {
4525 if (compose_redirect_write_to_file(compose, fp) < 0) {
4534 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4539 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4543 if (fclose(fp) == EOF) {
4544 FILE_OP_ERROR(tmp, "fclose");
4550 queue = account_get_special_folder(compose->account, F_QUEUE);
4552 g_warning("can't find queue folder\n");
4557 folder_item_scan(queue);
4558 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4559 g_warning("can't queue the message\n");
4565 if (msgpath == NULL) {
4571 if (compose->mode == COMPOSE_REEDIT) {
4572 compose_remove_reedit_target(compose, FALSE);
4575 if ((msgnum != NULL) && (item != NULL)) {
4583 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4586 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4588 struct stat statbuf;
4589 gchar *type, *subtype;
4590 GtkTreeModel *model;
4593 model = gtk_tree_view_get_model(tree_view);
4595 if (!gtk_tree_model_get_iter_first(model, &iter))
4598 gtk_tree_model_get(model, &iter,
4602 mimepart = procmime_mimeinfo_new();
4603 mimepart->content = MIMECONTENT_FILE;
4604 mimepart->data.filename = g_strdup(ainfo->file);
4605 mimepart->tmp = FALSE; /* or we destroy our attachment */
4606 mimepart->offset = 0;
4608 stat(ainfo->file, &statbuf);
4609 mimepart->length = statbuf.st_size;
4611 type = g_strdup(ainfo->content_type);
4613 if (!strchr(type, '/')) {
4615 type = g_strdup("application/octet-stream");
4618 subtype = strchr(type, '/') + 1;
4619 *(subtype - 1) = '\0';
4620 mimepart->type = procmime_get_media_type(type);
4621 mimepart->subtype = g_strdup(subtype);
4624 if (mimepart->type == MIMETYPE_MESSAGE &&
4625 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4626 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4628 g_hash_table_insert(mimepart->typeparameters,
4629 g_strdup("name"), g_strdup(ainfo->name));
4630 g_hash_table_insert(mimepart->dispositionparameters,
4631 g_strdup("filename"), g_strdup(ainfo->name));
4632 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4635 if (compose->use_signing) {
4636 if (ainfo->encoding == ENC_7BIT)
4637 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4638 else if (ainfo->encoding == ENC_8BIT)
4639 ainfo->encoding = ENC_BASE64;
4642 procmime_encode_content(mimepart, ainfo->encoding);
4644 g_node_append(parent->node, mimepart->node);
4645 } while (gtk_tree_model_iter_next(model, &iter));
4648 #define QUOTE_IF_REQUIRED(out, str) \
4650 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4654 len = strlen(str) + 3; \
4655 if ((__tmp = alloca(len)) == NULL) { \
4656 g_warning("can't allocate memory\n"); \
4657 g_string_free(header, TRUE); \
4660 g_snprintf(__tmp, len, "\"%s\"", str); \
4665 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4666 g_warning("can't allocate memory\n"); \
4667 g_string_free(header, TRUE); \
4670 strcpy(__tmp, str); \
4676 #define IS_IN_CUSTOM_HEADER(header) \
4677 (compose->account->add_customhdr && \
4678 custom_header_find(compose->account->customhdr_list, header) != NULL)
4680 static void compose_add_headerfield_from_headerlist(Compose *compose,
4682 const gchar *fieldname,
4683 const gchar *seperator)
4685 gchar *str, *fieldname_w_colon, *trans_fieldname;
4686 gboolean add_field = FALSE;
4688 ComposeHeaderEntry *headerentry;
4689 const gchar * headerentryname;
4692 if (IS_IN_CUSTOM_HEADER(fieldname))
4695 debug_print("Adding %s-fields\n", fieldname);
4697 fieldstr = g_string_sized_new(64);
4699 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4700 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4702 for (list = compose->header_list; list; list = list->next) {
4703 headerentry = ((ComposeHeaderEntry *)list->data);
4704 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4706 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4707 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4709 if (str[0] != '\0') {
4711 g_string_append(fieldstr, seperator);
4712 g_string_append(fieldstr, str);
4721 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4722 compose_convert_header
4723 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4724 strlen(fieldname) + 2, TRUE);
4725 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4729 g_free(fieldname_w_colon);
4730 g_string_free(fieldstr, TRUE);
4735 static gchar *compose_get_header(Compose *compose)
4737 gchar buf[BUFFSIZE];
4738 const gchar *entry_str;
4742 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4745 g_return_val_if_fail(compose->account != NULL, NULL);
4746 g_return_val_if_fail(compose->account->address != NULL, NULL);
4748 header = g_string_sized_new(64);
4751 if (compose->account->add_date) {
4752 get_rfc822_date(buf, sizeof(buf));
4753 g_string_append_printf(header, "Date: %s\n", buf);
4757 if (compose->account->name && *compose->account->name) {
4758 compose_convert_header
4759 (compose, buf, sizeof(buf), compose->account->name,
4760 strlen("From: "), TRUE);
4761 QUOTE_IF_REQUIRED(name, buf);
4762 g_string_append_printf(header, "From: %s <%s>\n",
4763 name, compose->account->address);
4765 g_string_append_printf(header, "From: %s\n", compose->account->address);
4768 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4771 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4774 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4777 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4780 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4782 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4785 compose_convert_header(compose, buf, sizeof(buf), str,
4786 strlen("Subject: "), FALSE);
4787 g_string_append_printf(header, "Subject: %s\n", buf);
4793 if (compose->account->gen_msgid) {
4794 generate_msgid(buf, sizeof(buf));
4795 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4796 compose->msgid = g_strdup(buf);
4799 if (compose->remove_references == FALSE) {
4801 if (compose->inreplyto && compose->to_list)
4802 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4805 if (compose->references)
4806 g_string_append_printf(header, "References: %s\n", compose->references);
4810 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4813 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4816 if (compose->account->organization &&
4817 strlen(compose->account->organization) &&
4818 !IS_IN_CUSTOM_HEADER("Organization")) {
4819 compose_convert_header(compose, buf, sizeof(buf),
4820 compose->account->organization,
4821 strlen("Organization: "), FALSE);
4822 g_string_append_printf(header, "Organization: %s\n", buf);
4825 /* Program version and system info */
4826 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4827 !compose->newsgroup_list) {
4828 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4830 gtk_major_version, gtk_minor_version, gtk_micro_version,
4833 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4834 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4836 gtk_major_version, gtk_minor_version, gtk_micro_version,
4840 /* custom headers */
4841 if (compose->account->add_customhdr) {
4844 for (cur = compose->account->customhdr_list; cur != NULL;
4846 CustomHeader *chdr = (CustomHeader *)cur->data;
4848 if (custom_header_is_allowed(chdr->name)) {
4849 compose_convert_header
4850 (compose, buf, sizeof(buf),
4851 chdr->value ? chdr->value : "",
4852 strlen(chdr->name) + 2, FALSE);
4853 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4859 switch (compose->priority) {
4860 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4861 "X-Priority: 1 (Highest)\n");
4863 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4864 "X-Priority: 2 (High)\n");
4866 case PRIORITY_NORMAL: break;
4867 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4868 "X-Priority: 4 (Low)\n");
4870 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4871 "X-Priority: 5 (Lowest)\n");
4873 default: debug_print("compose: priority unknown : %d\n",
4877 /* Request Return Receipt */
4878 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4879 if (compose->return_receipt) {
4880 if (compose->account->name
4881 && *compose->account->name) {
4882 compose_convert_header(compose, buf, sizeof(buf),
4883 compose->account->name,
4884 strlen("Disposition-Notification-To: "),
4886 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4888 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4892 /* get special headers */
4893 for (list = compose->header_list; list; list = list->next) {
4894 ComposeHeaderEntry *headerentry;
4897 gchar *headername_wcolon;
4898 gchar *headername_trans;
4901 gboolean standard_header = FALSE;
4903 headerentry = ((ComposeHeaderEntry *)list->data);
4905 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4906 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4911 if (!strstr(tmp, ":")) {
4912 headername_wcolon = g_strconcat(tmp, ":", NULL);
4913 headername = g_strdup(tmp);
4915 headername_wcolon = g_strdup(tmp);
4916 headername = g_strdup(strtok(tmp, ":"));
4920 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4921 Xstrdup_a(headervalue, entry_str, return NULL);
4922 subst_char(headervalue, '\r', ' ');
4923 subst_char(headervalue, '\n', ' ');
4924 string = std_headers;
4925 while (*string != NULL) {
4926 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4927 if (!strcmp(headername_trans,headername_wcolon))
4928 standard_header = TRUE;
4931 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4932 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4935 g_free(headername_wcolon);
4939 g_string_free(header, FALSE);
4944 #undef IS_IN_CUSTOM_HEADER
4946 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4947 gint header_len, gboolean addr_field)
4949 gchar *tmpstr = NULL;
4950 const gchar *out_codeset = NULL;
4952 g_return_if_fail(src != NULL);
4953 g_return_if_fail(dest != NULL);
4955 if (len < 1) return;
4957 tmpstr = g_strdup(src);
4959 subst_char(tmpstr, '\n', ' ');
4960 subst_char(tmpstr, '\r', ' ');
4963 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4964 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4965 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4970 codeconv_set_strict(TRUE);
4971 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4972 conv_get_charset_str(compose->out_encoding));
4973 codeconv_set_strict(FALSE);
4975 if (!dest || *dest == '\0') {
4976 gchar *test_conv_global_out = NULL;
4977 gchar *test_conv_reply = NULL;
4979 /* automatic mode. be automatic. */
4980 codeconv_set_strict(TRUE);
4982 out_codeset = conv_get_outgoing_charset_str();
4984 debug_print("trying to convert to %s\n", out_codeset);
4985 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4988 if (!test_conv_global_out && compose->orig_charset) {
4989 out_codeset = compose->orig_charset;
4990 debug_print("failure; trying to convert to %s\n", out_codeset);
4991 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4994 if (!test_conv_global_out && !test_conv_reply) {
4996 out_codeset = CS_INTERNAL;
4997 debug_print("finally using %s\n", out_codeset);
4999 g_free(test_conv_global_out);
5000 g_free(test_conv_reply);
5001 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5003 codeconv_set_strict(FALSE);
5008 static void compose_create_header_entry(Compose *compose)
5010 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5014 GList *combo_list = NULL;
5016 const gchar *header = NULL;
5017 ComposeHeaderEntry *headerentry;
5018 gboolean standard_header = FALSE;
5020 headerentry = g_new0(ComposeHeaderEntry, 1);
5023 combo = gtk_combo_new();
5025 while(*string != NULL) {
5026 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5029 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5030 g_list_free(combo_list);
5031 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5032 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5033 G_CALLBACK(compose_grab_focus_cb), compose);
5034 gtk_widget_show(combo);
5035 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5036 if (compose->header_last) {
5037 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5039 while (*string != NULL) {
5040 if (!strcmp(*string, last_header_entry))
5041 standard_header = TRUE;
5044 if (standard_header)
5045 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5047 if (!compose->header_last || !standard_header) {
5048 switch(compose->account->protocol) {
5050 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5053 header = prefs_common.trans_hdr ? _("To:") : "To:";
5058 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5060 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5061 G_CALLBACK(compose_grab_focus_cb), compose);
5064 entry = gtk_entry_new();
5065 gtk_widget_show(entry);
5066 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);
5068 g_signal_connect(G_OBJECT(entry), "key-press-event",
5069 G_CALLBACK(compose_headerentry_key_press_event_cb),
5071 g_signal_connect(G_OBJECT(entry), "changed",
5072 G_CALLBACK(compose_headerentry_changed_cb),
5074 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5075 G_CALLBACK(compose_grab_focus_cb), compose);
5078 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5079 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5080 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5081 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5082 G_CALLBACK(compose_header_drag_received_cb),
5084 g_signal_connect(G_OBJECT(entry), "drag-drop",
5085 G_CALLBACK(compose_drag_drop),
5088 address_completion_register_entry(GTK_ENTRY(entry));
5090 headerentry->compose = compose;
5091 headerentry->combo = combo;
5092 headerentry->entry = entry;
5093 headerentry->headernum = compose->header_nextrow;
5095 compose->header_nextrow++;
5096 compose->header_last = headerentry;
5099 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5101 ComposeHeaderEntry *last_header;
5103 last_header = compose->header_last;
5105 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5106 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5109 static GtkWidget *compose_create_header(Compose *compose)
5113 GtkWidget *from_optmenu_hbox;
5114 GtkWidget *header_scrolledwin;
5115 GtkWidget *header_table;
5119 /* header labels and entries */
5120 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5121 gtk_widget_show(header_scrolledwin);
5122 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5124 header_table = gtk_table_new(2, 2, FALSE);
5125 gtk_widget_show(header_table);
5126 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5127 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5128 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5131 /* option menu for selecting accounts */
5132 hbox = gtk_hbox_new(FALSE, 0);
5133 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5134 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5135 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5137 from_optmenu_hbox = compose_account_option_menu_create(compose);
5138 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5139 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5142 compose->header_table = header_table;
5143 compose->header_list = NULL;
5144 compose->header_nextrow = count;
5146 compose_create_header_entry(compose);
5148 compose->table = NULL;
5150 return header_scrolledwin ;
5153 GtkWidget *compose_create_attach(Compose *compose)
5155 GtkWidget *attach_scrwin;
5156 GtkWidget *attach_clist;
5158 GtkListStore *store;
5159 GtkCellRenderer *renderer;
5160 GtkTreeViewColumn *column;
5161 GtkTreeSelection *selection;
5163 /* attachment list */
5164 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5165 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5166 GTK_POLICY_AUTOMATIC,
5167 GTK_POLICY_AUTOMATIC);
5168 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5170 store = gtk_list_store_new(N_ATTACH_COLS,
5175 G_TYPE_AUTO_POINTER,
5177 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5178 (GTK_TREE_MODEL(store)));
5179 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5180 g_object_unref(store);
5182 renderer = gtk_cell_renderer_text_new();
5183 column = gtk_tree_view_column_new_with_attributes
5184 (_("Mime type"), renderer, "text",
5185 COL_MIMETYPE, NULL);
5186 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5188 renderer = gtk_cell_renderer_text_new();
5189 column = gtk_tree_view_column_new_with_attributes
5190 (_("Size"), renderer, "text",
5192 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5194 renderer = gtk_cell_renderer_text_new();
5195 column = gtk_tree_view_column_new_with_attributes
5196 (_("Name"), renderer, "text",
5198 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5200 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5201 prefs_common.enable_rules_hint);
5202 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5203 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5205 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5206 G_CALLBACK(attach_selected), compose);
5207 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5208 G_CALLBACK(attach_button_pressed), compose);
5209 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5210 G_CALLBACK(attach_key_pressed), compose);
5213 gtk_drag_dest_set(attach_clist,
5214 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5215 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5216 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5217 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5218 G_CALLBACK(compose_attach_drag_received_cb),
5220 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5221 G_CALLBACK(compose_drag_drop),
5224 compose->attach_scrwin = attach_scrwin;
5225 compose->attach_clist = attach_clist;
5227 return attach_scrwin;
5230 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5231 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5233 static GtkWidget *compose_create_others(Compose *compose)
5236 GtkWidget *savemsg_checkbtn;
5237 GtkWidget *savemsg_entry;
5238 GtkWidget *savemsg_select;
5241 gchar *folderidentifier;
5243 /* Table for settings */
5244 table = gtk_table_new(3, 1, FALSE);
5245 gtk_widget_show(table);
5246 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5249 /* Save Message to folder */
5250 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5251 gtk_widget_show(savemsg_checkbtn);
5252 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5253 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5254 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5256 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5257 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5259 savemsg_entry = gtk_entry_new();
5260 gtk_widget_show(savemsg_entry);
5261 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5262 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5263 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5264 G_CALLBACK(compose_grab_focus_cb), compose);
5265 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5266 folderidentifier = folder_item_get_identifier(account_get_special_folder
5267 (compose->account, F_OUTBOX));
5268 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5269 g_free(folderidentifier);
5272 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5273 gtk_widget_show(savemsg_select);
5274 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5275 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5276 G_CALLBACK(compose_savemsg_select_cb),
5281 compose->savemsg_checkbtn = savemsg_checkbtn;
5282 compose->savemsg_entry = savemsg_entry;
5287 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5289 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5290 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5293 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5298 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5301 path = folder_item_get_identifier(dest);
5303 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5307 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5310 #define BLOCK_WRAP() { \
5311 prev_autowrap = compose->autowrap; \
5312 buffer = gtk_text_view_get_buffer( \
5313 GTK_TEXT_VIEW(compose->text)); \
5314 compose->autowrap = FALSE; \
5316 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5317 G_CALLBACK(compose_changed_cb), \
5319 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5320 G_CALLBACK(text_inserted), \
5323 #define UNBLOCK_WRAP() { \
5324 compose->autowrap = prev_autowrap; \
5325 if (compose->autowrap) \
5326 compose_wrap_all(compose); \
5328 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5329 G_CALLBACK(compose_changed_cb), \
5331 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5332 G_CALLBACK(text_inserted), \
5337 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5341 GtkTextBuffer *buffer;
5343 if (event->button == 3) {
5345 GtkTextIter sel_start, sel_end;
5346 gboolean stuff_selected;
5348 /* move the cursor to allow GtkAspell to check the word
5349 * under the mouse */
5350 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5351 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5353 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5356 stuff_selected = gtk_text_buffer_get_selection_bounds(
5357 GTK_TEXT_VIEW(text)->buffer,
5358 &sel_start, &sel_end);
5360 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5361 /* reselect stuff */
5363 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5364 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5365 &sel_start, &sel_end);
5367 return FALSE; /* pass the event so that the right-click goes through */
5370 if (event->button == 2) {
5372 entry_paste_clipboard(compose, compose->focused_editable,
5373 prefs_common.linewrap_pastes,
5374 GDK_SELECTION_PRIMARY);
5381 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5387 GtkWidget *handlebox;
5389 GtkWidget *notebook;
5394 GtkWidget *subject_hbox;
5395 GtkWidget *subject_frame;
5396 GtkWidget *subject_entry;
5400 GtkWidget *edit_vbox;
5401 GtkWidget *ruler_hbox;
5403 GtkWidget *scrolledwin;
5405 GtkTextBuffer *buffer;
5406 GtkClipboard *clipboard;
5408 UndoMain *undostruct;
5410 gchar *titles[N_ATTACH_COLS];
5411 guint n_menu_entries;
5414 gboolean success[1];
5415 GtkWidget *popupmenu;
5416 GtkItemFactory *popupfactory;
5417 GtkItemFactory *ifactory;
5418 GtkWidget *tmpl_menu;
5420 GtkWidget *menuitem;
5423 GtkAspell * gtkaspell = NULL;
5426 static GdkGeometry geometry;
5428 g_return_val_if_fail(account != NULL, NULL);
5430 debug_print("Creating compose window...\n");
5431 compose = g_new0(Compose, 1);
5433 titles[COL_MIMETYPE] = _("MIME type");
5434 titles[COL_SIZE] = _("Size");
5435 titles[COL_NAME] = _("Name");
5437 compose->account = account;
5439 compose->mutex = g_mutex_new();
5440 compose->set_cursor_pos = -1;
5442 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5443 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5444 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5446 if (!geometry.max_width) {
5447 geometry.max_width = gdk_screen_width();
5448 geometry.max_height = gdk_screen_height();
5451 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5452 &geometry, GDK_HINT_MAX_SIZE);
5453 if (!geometry.min_width) {
5454 geometry.min_width = 600;
5455 geometry.min_height = 480;
5457 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5458 &geometry, GDK_HINT_MIN_SIZE);
5459 gtk_widget_set_uposition(window, prefs_common.compose_x,
5460 prefs_common.compose_y);
5462 g_signal_connect(G_OBJECT(window), "delete_event",
5463 G_CALLBACK(compose_delete_cb), compose);
5464 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5465 gtk_widget_realize(window);
5467 gtkut_widget_set_composer_icon(window);
5469 vbox = gtk_vbox_new(FALSE, 0);
5470 gtk_container_add(GTK_CONTAINER(window), vbox);
5472 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5473 menubar = menubar_create(window, compose_entries,
5474 n_menu_entries, "<Compose>", compose);
5475 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5477 if (prefs_common.toolbar_detachable) {
5478 handlebox = gtk_handle_box_new();
5480 handlebox = gtk_hbox_new(FALSE, 0);
5482 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5484 gtk_widget_realize(handlebox);
5485 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5488 vbox2 = gtk_vbox_new(FALSE, 2);
5489 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5490 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5493 notebook = gtk_notebook_new();
5494 gtk_widget_set_size_request(notebook, -1, 130);
5495 gtk_widget_show(notebook);
5497 /* header labels and entries */
5498 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5499 compose_create_header(compose),
5500 gtk_label_new_with_mnemonic(_("Hea_der")));
5501 /* attachment list */
5502 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5503 compose_create_attach(compose),
5504 gtk_label_new_with_mnemonic(_("_Attachments")));
5506 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5507 compose_create_others(compose),
5508 gtk_label_new_with_mnemonic(_("Othe_rs")));
5511 subject_hbox = gtk_hbox_new(FALSE, 0);
5512 gtk_widget_show(subject_hbox);
5514 subject_frame = gtk_frame_new(NULL);
5515 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5516 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5517 gtk_widget_show(subject_frame);
5519 subject = gtk_hbox_new(FALSE, 0);
5520 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5521 gtk_widget_show(subject);
5523 label = gtk_label_new(_("Subject:"));
5524 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5525 gtk_widget_show(label);
5527 subject_entry = gtk_entry_new();
5528 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5529 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5530 G_CALLBACK(compose_grab_focus_cb), compose);
5531 gtk_widget_show(subject_entry);
5532 compose->subject_entry = subject_entry;
5533 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5535 edit_vbox = gtk_vbox_new(FALSE, 0);
5537 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5540 ruler_hbox = gtk_hbox_new(FALSE, 0);
5541 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5543 ruler = gtk_shruler_new();
5544 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5545 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5549 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5550 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5551 GTK_POLICY_AUTOMATIC,
5552 GTK_POLICY_AUTOMATIC);
5553 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5555 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5556 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5558 text = gtk_text_view_new();
5559 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5560 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5561 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5562 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5563 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5565 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5567 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5568 G_CALLBACK(compose_edit_size_alloc),
5570 g_signal_connect(G_OBJECT(buffer), "changed",
5571 G_CALLBACK(compose_changed_cb), compose);
5572 g_signal_connect(G_OBJECT(text), "grab_focus",
5573 G_CALLBACK(compose_grab_focus_cb), compose);
5574 g_signal_connect(G_OBJECT(buffer), "insert_text",
5575 G_CALLBACK(text_inserted), compose);
5576 g_signal_connect(G_OBJECT(text), "button_press_event",
5577 G_CALLBACK(text_clicked), compose);
5578 g_signal_connect(G_OBJECT(subject_entry), "changed",
5579 G_CALLBACK(compose_changed_cb), compose);
5582 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5583 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5584 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5585 g_signal_connect(G_OBJECT(text), "drag_data_received",
5586 G_CALLBACK(compose_insert_drag_received_cb),
5588 g_signal_connect(G_OBJECT(text), "drag-drop",
5589 G_CALLBACK(compose_drag_drop),
5591 gtk_widget_show_all(vbox);
5593 /* pane between attach clist and text */
5594 paned = gtk_vpaned_new();
5595 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5596 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5597 gtk_paned_add1(GTK_PANED(paned), notebook);
5598 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5599 gtk_widget_show_all(paned);
5602 if (prefs_common.textfont) {
5603 PangoFontDescription *font_desc;
5605 font_desc = pango_font_description_from_string
5606 (prefs_common.textfont);
5608 gtk_widget_modify_font(text, font_desc);
5609 pango_font_description_free(font_desc);
5613 color[0] = quote_color;
5614 cmap = gdk_drawable_get_colormap(window->window);
5615 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5616 if (success[0] == FALSE) {
5619 g_warning("Compose: color allocation failed.\n");
5620 style = gtk_widget_get_style(text);
5621 quote_color = style->black;
5624 n_entries = sizeof(compose_popup_entries) /
5625 sizeof(compose_popup_entries[0]);
5626 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5627 "<Compose>", &popupfactory,
5630 ifactory = gtk_item_factory_from_widget(menubar);
5631 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5632 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5633 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5635 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5637 undostruct = undo_init(text);
5638 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5641 address_completion_start(window);
5643 compose->window = window;
5644 compose->vbox = vbox;
5645 compose->menubar = menubar;
5646 compose->handlebox = handlebox;
5648 compose->vbox2 = vbox2;
5650 compose->paned = paned;
5652 compose->edit_vbox = edit_vbox;
5653 compose->ruler_hbox = ruler_hbox;
5654 compose->ruler = ruler;
5655 compose->scrolledwin = scrolledwin;
5656 compose->text = text;
5658 compose->focused_editable = NULL;
5660 compose->popupmenu = popupmenu;
5661 compose->popupfactory = popupfactory;
5663 compose->tmpl_menu = tmpl_menu;
5665 compose->mode = mode;
5667 compose->targetinfo = NULL;
5668 compose->replyinfo = NULL;
5669 compose->fwdinfo = NULL;
5671 compose->replyto = NULL;
5673 compose->bcc = NULL;
5674 compose->followup_to = NULL;
5676 compose->ml_post = NULL;
5678 compose->inreplyto = NULL;
5679 compose->references = NULL;
5680 compose->msgid = NULL;
5681 compose->boundary = NULL;
5683 compose->autowrap = prefs_common.autowrap;
5685 compose->use_signing = FALSE;
5686 compose->use_encryption = FALSE;
5687 compose->privacy_system = NULL;
5689 compose->modified = FALSE;
5691 compose->return_receipt = FALSE;
5693 compose->to_list = NULL;
5694 compose->newsgroup_list = NULL;
5696 compose->undostruct = undostruct;
5698 compose->sig_str = NULL;
5700 compose->exteditor_file = NULL;
5701 compose->exteditor_pid = -1;
5702 compose->exteditor_tag = -1;
5703 compose->draft_timeout_tag = -1;
5706 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5707 if (mode != COMPOSE_REDIRECT) {
5708 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5709 strcmp(prefs_common.dictionary, _("None"))) {
5710 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5711 prefs_common.dictionary,
5712 conv_get_locale_charset_str(),
5713 prefs_common.misspelled_col,
5714 prefs_common.check_while_typing,
5715 prefs_common.recheck_when_changing_dict,
5716 prefs_common.use_alternate,
5717 GTK_TEXT_VIEW(text),
5718 GTK_WINDOW(compose->window));
5720 alertpanel_error(_("Spell checker could not "
5722 gtkaspell_checkers_strerror());
5723 gtkaspell_checkers_reset_error();
5725 if (!gtkaspell_set_sug_mode(gtkaspell,
5726 prefs_common.aspell_sugmode)) {
5727 debug_print("Aspell: could not set "
5728 "suggestion mode %s\n",
5729 gtkaspell_checkers_strerror());
5730 gtkaspell_checkers_reset_error();
5733 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5737 compose->gtkaspell = gtkaspell;
5740 compose_select_account(compose, account, TRUE);
5742 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5743 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5744 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5746 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5747 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5749 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5750 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5753 if (account->protocol != A_NNTP)
5754 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5756 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5758 addressbook_set_target_compose(compose);
5760 if (mode != COMPOSE_REDIRECT)
5761 compose_set_template_menu(compose);
5763 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5764 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5767 compose_list = g_list_append(compose_list, compose);
5769 if (!prefs_common.show_ruler)
5770 gtk_widget_hide(ruler_hbox);
5772 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5773 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5774 prefs_common.show_ruler);
5777 compose->priority = PRIORITY_NORMAL;
5778 compose_update_priority_menu_item(compose);
5780 compose_set_out_encoding(compose);
5783 compose_update_actions_menu(compose);
5785 /* Privacy Systems menu */
5786 compose_update_privacy_systems_menu(compose);
5788 activate_privacy_system(compose, account, TRUE);
5789 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5790 gtk_widget_show(window);
5795 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5801 gint num = 0, def_menu = 0;
5803 accounts = account_get_list();
5804 g_return_val_if_fail(accounts != NULL, NULL);
5806 hbox = gtk_hbox_new(FALSE, 0);
5807 optmenu = gtk_option_menu_new();
5808 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5809 menu = gtk_menu_new();
5811 for (; accounts != NULL; accounts = accounts->next, num++) {
5812 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5813 GtkWidget *menuitem;
5816 if (ac == compose->account) def_menu = num;
5819 name = g_strdup_printf("%s: %s <%s>",
5821 ac->name, ac->address);
5823 name = g_strdup_printf("%s: %s",
5824 ac->account_name, ac->address);
5825 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5827 g_signal_connect(G_OBJECT(menuitem), "activate",
5828 G_CALLBACK(account_activated),
5832 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5833 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5838 static void compose_set_priority_cb(gpointer data,
5842 Compose *compose = (Compose *) data;
5843 compose->priority = action;
5846 static void compose_update_priority_menu_item(Compose * compose)
5848 GtkItemFactory *ifactory;
5849 GtkWidget *menuitem = NULL;
5851 ifactory = gtk_item_factory_from_widget(compose->menubar);
5853 switch (compose->priority) {
5854 case PRIORITY_HIGHEST:
5855 menuitem = gtk_item_factory_get_item
5856 (ifactory, "/Options/Priority/Highest");
5859 menuitem = gtk_item_factory_get_item
5860 (ifactory, "/Options/Priority/High");
5862 case PRIORITY_NORMAL:
5863 menuitem = gtk_item_factory_get_item
5864 (ifactory, "/Options/Priority/Normal");
5867 menuitem = gtk_item_factory_get_item
5868 (ifactory, "/Options/Priority/Low");
5870 case PRIORITY_LOWEST:
5871 menuitem = gtk_item_factory_get_item
5872 (ifactory, "/Options/Priority/Lowest");
5875 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5878 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5880 Compose *compose = (Compose *) data;
5882 GtkItemFactory *ifactory;
5883 gboolean can_sign = FALSE, can_encrypt = FALSE;
5885 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5887 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5890 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5891 g_free(compose->privacy_system);
5892 compose->privacy_system = NULL;
5893 if (systemid != NULL) {
5894 compose->privacy_system = g_strdup(systemid);
5896 can_sign = privacy_system_can_sign(systemid);
5897 can_encrypt = privacy_system_can_encrypt(systemid);
5900 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5902 ifactory = gtk_item_factory_from_widget(compose->menubar);
5903 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5904 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5907 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5909 static gchar *branch_path = "/Options/Privacy System";
5910 GtkItemFactory *ifactory;
5911 GtkWidget *menuitem = NULL;
5913 gboolean can_sign = FALSE, can_encrypt = FALSE;
5914 gboolean found = FALSE;
5916 ifactory = gtk_item_factory_from_widget(compose->menubar);
5918 if (compose->privacy_system != NULL) {
5921 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5922 g_return_if_fail(menuitem != NULL);
5924 amenu = GTK_MENU_SHELL(menuitem)->children;
5926 while (amenu != NULL) {
5927 GList *alist = amenu->next;
5929 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5930 if (systemid != NULL) {
5931 if (strcmp(systemid, compose->privacy_system) == 0) {
5932 menuitem = GTK_WIDGET(amenu->data);
5934 can_sign = privacy_system_can_sign(systemid);
5935 can_encrypt = privacy_system_can_encrypt(systemid);
5939 } else if (strlen(compose->privacy_system) == 0) {
5940 menuitem = GTK_WIDGET(amenu->data);
5943 can_encrypt = FALSE;
5950 if (menuitem != NULL)
5951 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5953 if (warn && !found && strlen(compose->privacy_system)) {
5954 gchar *tmp = g_strdup_printf(
5955 _("The privacy system '%s' cannot be loaded. You "
5956 "will not be able to sign or encrypt this message."),
5957 compose->privacy_system);
5958 alertpanel_warning(tmp);
5963 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5964 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5967 static void compose_set_out_encoding(Compose *compose)
5969 GtkItemFactoryEntry *entry;
5970 GtkItemFactory *ifactory;
5971 CharSet out_encoding;
5972 gchar *path, *p, *q;
5975 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5976 ifactory = gtk_item_factory_from_widget(compose->menubar);
5978 for (entry = compose_entries; entry->callback != compose_address_cb;
5980 if (entry->callback == compose_set_encoding_cb &&
5981 (CharSet)entry->callback_action == out_encoding) {
5982 p = q = path = g_strdup(entry->path);
5994 item = gtk_item_factory_get_item(ifactory, path);
5995 gtk_widget_activate(item);
6002 static void compose_set_template_menu(Compose *compose)
6004 GSList *tmpl_list, *cur;
6008 tmpl_list = template_get_config();
6010 menu = gtk_menu_new();
6012 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6013 Template *tmpl = (Template *)cur->data;
6015 item = gtk_menu_item_new_with_label(tmpl->name);
6016 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6017 g_signal_connect(G_OBJECT(item), "activate",
6018 G_CALLBACK(compose_template_activate_cb),
6020 g_object_set_data(G_OBJECT(item), "template", tmpl);
6021 gtk_widget_show(item);
6024 gtk_widget_show(menu);
6025 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6028 void compose_update_actions_menu(Compose *compose)
6030 GtkItemFactory *ifactory;
6032 ifactory = gtk_item_factory_from_widget(compose->menubar);
6033 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6036 void compose_update_privacy_systems_menu(Compose *compose)
6038 static gchar *branch_path = "/Options/Privacy System";
6039 GtkItemFactory *ifactory;
6040 GtkWidget *menuitem;
6041 GSList *systems, *cur;
6044 GtkWidget *system_none;
6047 ifactory = gtk_item_factory_from_widget(compose->menubar);
6049 /* remove old entries */
6050 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6051 g_return_if_fail(menuitem != NULL);
6053 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6054 while (amenu != NULL) {
6055 GList *alist = amenu->next;
6056 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6060 system_none = gtk_item_factory_get_widget(ifactory,
6061 "/Options/Privacy System/None");
6063 g_signal_connect(G_OBJECT(system_none), "activate",
6064 G_CALLBACK(compose_set_privacy_system_cb), compose);
6066 systems = privacy_get_system_ids();
6067 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6068 gchar *systemid = cur->data;
6070 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6071 widget = gtk_radio_menu_item_new_with_label(group,
6072 privacy_system_get_name(systemid));
6073 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6074 g_strdup(systemid), g_free);
6075 g_signal_connect(G_OBJECT(widget), "activate",
6076 G_CALLBACK(compose_set_privacy_system_cb), compose);
6078 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6079 gtk_widget_show(widget);
6082 g_slist_free(systems);
6085 void compose_reflect_prefs_all(void)
6090 for (cur = compose_list; cur != NULL; cur = cur->next) {
6091 compose = (Compose *)cur->data;
6092 compose_set_template_menu(compose);
6096 void compose_reflect_prefs_pixmap_theme(void)
6101 for (cur = compose_list; cur != NULL; cur = cur->next) {
6102 compose = (Compose *)cur->data;
6103 toolbar_update(TOOLBAR_COMPOSE, compose);
6107 static void compose_template_apply(Compose *compose, Template *tmpl,
6111 GtkTextBuffer *buffer;
6115 gchar *parsed_str = NULL;
6116 gint cursor_pos = 0;
6119 /* process the body */
6121 text = GTK_TEXT_VIEW(compose->text);
6122 buffer = gtk_text_view_get_buffer(text);
6125 gtk_text_buffer_set_text(buffer, "", -1);
6127 mark = gtk_text_buffer_get_insert(buffer);
6128 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6131 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6132 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6135 if (prefs_common.quotemark && *prefs_common.quotemark)
6136 qmark = prefs_common.quotemark;
6140 if (compose->replyinfo != NULL)
6141 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6142 tmpl->value, qmark, NULL, FALSE);
6143 else if (compose->fwdinfo != NULL)
6144 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6145 tmpl->value, qmark, NULL, FALSE);
6150 if (replace && parsed_str && compose->account->auto_sig)
6151 compose_insert_sig(compose, FALSE);
6153 if (replace && parsed_str) {
6154 gtk_text_buffer_get_start_iter(buffer, &iter);
6155 gtk_text_buffer_place_cursor(buffer, &iter);
6159 cursor_pos = quote_fmt_get_cursor_pos();
6160 compose->set_cursor_pos = cursor_pos;
6161 if (cursor_pos == -1)
6163 gtk_text_buffer_get_start_iter(buffer, &iter);
6164 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6165 gtk_text_buffer_place_cursor(buffer, &iter);
6168 /* process the other fields */
6169 compose_template_apply_fields(compose, tmpl);
6171 compose_changed_cb(NULL, compose);
6174 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6176 static MsgInfo dummyinfo;
6177 MsgInfo *msginfo = NULL;
6180 if (compose->replyinfo != NULL)
6181 msginfo = compose->replyinfo;
6182 else if (compose->fwdinfo != NULL)
6183 msginfo = compose->fwdinfo;
6185 msginfo = &dummyinfo;
6187 if (tmpl->to && *tmpl->to != '\0') {
6188 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6189 quote_fmt_scan_string(tmpl->to);
6192 buf = quote_fmt_get_buffer();
6194 alertpanel_error(_("Message To format error."));
6196 compose_entry_append(compose, buf, COMPOSE_TO);
6200 if (tmpl->cc && *tmpl->cc != '\0') {
6201 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6202 quote_fmt_scan_string(tmpl->cc);
6205 buf = quote_fmt_get_buffer();
6207 alertpanel_error(_("Message Cc format error."));
6209 compose_entry_append(compose, buf, COMPOSE_CC);
6213 if (tmpl->bcc && *tmpl->bcc != '\0') {
6214 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6215 quote_fmt_scan_string(tmpl->bcc);
6218 buf = quote_fmt_get_buffer();
6220 alertpanel_error(_("Message Bcc format error."));
6222 compose_entry_append(compose, buf, COMPOSE_BCC);
6226 /* process the subject */
6227 if (tmpl->subject && *tmpl->subject != '\0') {
6228 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6229 quote_fmt_scan_string(tmpl->subject);
6232 buf = quote_fmt_get_buffer();
6234 alertpanel_error(_("Message subject format error."));
6236 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6241 static void compose_destroy(Compose *compose)
6243 compose_list = g_list_remove(compose_list, compose);
6245 /* NOTE: address_completion_end() does nothing with the window
6246 * however this may change. */
6247 address_completion_end(compose->window);
6249 slist_free_strings(compose->to_list);
6250 g_slist_free(compose->to_list);
6251 slist_free_strings(compose->newsgroup_list);
6252 g_slist_free(compose->newsgroup_list);
6253 slist_free_strings(compose->header_list);
6254 g_slist_free(compose->header_list);
6256 procmsg_msginfo_free(compose->targetinfo);
6257 procmsg_msginfo_free(compose->replyinfo);
6258 procmsg_msginfo_free(compose->fwdinfo);
6260 g_free(compose->replyto);
6261 g_free(compose->cc);
6262 g_free(compose->bcc);
6263 g_free(compose->newsgroups);
6264 g_free(compose->followup_to);
6266 g_free(compose->ml_post);
6268 g_free(compose->inreplyto);
6269 g_free(compose->references);
6270 g_free(compose->msgid);
6271 g_free(compose->boundary);
6273 if (compose->redirect_filename)
6274 g_free(compose->redirect_filename);
6275 if (compose->undostruct)
6276 undo_destroy(compose->undostruct);
6278 g_free(compose->sig_str);
6280 g_free(compose->exteditor_file);
6282 g_free(compose->orig_charset);
6284 g_free(compose->privacy_system);
6286 if (addressbook_get_target_compose() == compose)
6287 addressbook_set_target_compose(NULL);
6290 if (compose->gtkaspell) {
6291 gtkaspell_delete(compose->gtkaspell);
6292 compose->gtkaspell = NULL;
6296 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6297 prefs_common.compose_height = compose->window->allocation.height;
6299 if (!gtk_widget_get_parent(compose->paned))
6300 gtk_widget_destroy(compose->paned);
6301 gtk_widget_destroy(compose->popupmenu);
6303 gtk_widget_destroy(compose->window);
6304 toolbar_destroy(compose->toolbar);
6305 g_free(compose->toolbar);
6306 g_mutex_free(compose->mutex);
6310 static void compose_attach_info_free(AttachInfo *ainfo)
6312 g_free(ainfo->file);
6313 g_free(ainfo->content_type);
6314 g_free(ainfo->name);
6318 static void compose_attach_remove_selected(Compose *compose)
6320 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6321 GtkTreeSelection *selection;
6323 GtkTreeModel *model;
6325 selection = gtk_tree_view_get_selection(tree_view);
6326 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6331 for (cur = sel; cur != NULL; cur = cur->next) {
6332 GtkTreePath *path = cur->data;
6333 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6336 gtk_tree_path_free(path);
6339 for (cur = sel; cur != NULL; cur = cur->next) {
6340 GtkTreeRowReference *ref = cur->data;
6341 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6344 if (gtk_tree_model_get_iter(model, &iter, path))
6345 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6347 gtk_tree_path_free(path);
6348 gtk_tree_row_reference_free(ref);
6354 static struct _AttachProperty
6357 GtkWidget *mimetype_entry;
6358 GtkWidget *encoding_optmenu;
6359 GtkWidget *path_entry;
6360 GtkWidget *filename_entry;
6362 GtkWidget *cancel_btn;
6365 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6367 gtk_tree_path_free((GtkTreePath *)ptr);
6370 static void compose_attach_property(Compose *compose)
6372 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6374 GtkOptionMenu *optmenu;
6375 GtkTreeSelection *selection;
6377 GtkTreeModel *model;
6380 static gboolean cancelled;
6382 /* only if one selected */
6383 selection = gtk_tree_view_get_selection(tree_view);
6384 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6387 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6391 path = (GtkTreePath *) sel->data;
6392 gtk_tree_model_get_iter(model, &iter, path);
6393 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6396 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6402 if (!attach_prop.window)
6403 compose_attach_property_create(&cancelled);
6404 gtk_widget_grab_focus(attach_prop.ok_btn);
6405 gtk_widget_show(attach_prop.window);
6406 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6408 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6409 if (ainfo->encoding == ENC_UNKNOWN)
6410 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6411 GINT_TO_POINTER(ENC_BASE64));
6413 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6414 GINT_TO_POINTER(ainfo->encoding));
6416 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6417 ainfo->content_type ? ainfo->content_type : "");
6418 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6419 ainfo->file ? ainfo->file : "");
6420 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6421 ainfo->name ? ainfo->name : "");
6424 const gchar *entry_text;
6426 gchar *cnttype = NULL;
6430 GtkWidget *menuitem;
6435 gtk_widget_hide(attach_prop.window);
6440 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6441 if (*entry_text != '\0') {
6444 text = g_strstrip(g_strdup(entry_text));
6445 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6446 cnttype = g_strdup(text);
6449 alertpanel_error(_("Invalid MIME type."));
6455 menu = gtk_option_menu_get_menu(optmenu);
6456 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6457 ainfo->encoding = GPOINTER_TO_INT
6458 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6460 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6461 if (*entry_text != '\0') {
6462 if (is_file_exist(entry_text) &&
6463 (size = get_file_size(entry_text)) > 0)
6464 file = g_strdup(entry_text);
6467 (_("File doesn't exist or is empty."));
6473 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6474 if (*entry_text != '\0') {
6475 g_free(ainfo->name);
6476 ainfo->name = g_strdup(entry_text);
6480 g_free(ainfo->content_type);
6481 ainfo->content_type = cnttype;
6484 g_free(ainfo->file);
6490 /* update tree store */
6491 text = to_human_readable(ainfo->size);
6492 gtk_tree_model_get_iter(model, &iter, path);
6493 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6494 COL_MIMETYPE, ainfo->content_type,
6496 COL_NAME, ainfo->name,
6502 gtk_tree_path_free(path);
6505 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6507 label = gtk_label_new(str); \
6508 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6509 GTK_FILL, 0, 0, 0); \
6510 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6512 entry = gtk_entry_new(); \
6513 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6514 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6517 static void compose_attach_property_create(gboolean *cancelled)
6523 GtkWidget *mimetype_entry;
6526 GtkWidget *optmenu_menu;
6527 GtkWidget *menuitem;
6528 GtkWidget *path_entry;
6529 GtkWidget *filename_entry;
6532 GtkWidget *cancel_btn;
6533 GList *mime_type_list, *strlist;
6535 debug_print("Creating attach_property window...\n");
6537 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6538 gtk_widget_set_size_request(window, 480, -1);
6539 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6540 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6541 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6542 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6543 g_signal_connect(G_OBJECT(window), "delete_event",
6544 G_CALLBACK(attach_property_delete_event),
6546 g_signal_connect(G_OBJECT(window), "key_press_event",
6547 G_CALLBACK(attach_property_key_pressed),
6550 vbox = gtk_vbox_new(FALSE, 8);
6551 gtk_container_add(GTK_CONTAINER(window), vbox);
6553 table = gtk_table_new(4, 2, FALSE);
6554 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6555 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6556 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6558 label = gtk_label_new(_("MIME type"));
6559 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6561 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6562 mimetype_entry = gtk_combo_new();
6563 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6564 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6566 /* stuff with list */
6567 mime_type_list = procmime_get_mime_type_list();
6569 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6570 MimeType *type = (MimeType *) mime_type_list->data;
6573 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6575 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6578 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6579 (GCompareFunc)strcmp2);
6582 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6584 for (mime_type_list = strlist; mime_type_list != NULL;
6585 mime_type_list = mime_type_list->next)
6586 g_free(mime_type_list->data);
6587 g_list_free(strlist);
6589 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6591 label = gtk_label_new(_("Encoding"));
6592 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6594 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6596 hbox = gtk_hbox_new(FALSE, 0);
6597 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6598 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6600 optmenu = gtk_option_menu_new();
6601 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6603 optmenu_menu = gtk_menu_new();
6604 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6605 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6606 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6607 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6608 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6609 ENC_QUOTED_PRINTABLE);
6610 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6612 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6614 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6616 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6617 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6619 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6620 &ok_btn, GTK_STOCK_OK,
6622 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6623 gtk_widget_grab_default(ok_btn);
6625 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6626 G_CALLBACK(attach_property_ok),
6628 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6629 G_CALLBACK(attach_property_cancel),
6632 gtk_widget_show_all(vbox);
6634 attach_prop.window = window;
6635 attach_prop.mimetype_entry = mimetype_entry;
6636 attach_prop.encoding_optmenu = optmenu;
6637 attach_prop.path_entry = path_entry;
6638 attach_prop.filename_entry = filename_entry;
6639 attach_prop.ok_btn = ok_btn;
6640 attach_prop.cancel_btn = cancel_btn;
6643 #undef SET_LABEL_AND_ENTRY
6645 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6651 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6657 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6658 gboolean *cancelled)
6666 static gboolean attach_property_key_pressed(GtkWidget *widget,
6668 gboolean *cancelled)
6670 if (event && event->keyval == GDK_Escape) {
6677 static void compose_exec_ext_editor(Compose *compose)
6684 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6685 G_DIR_SEPARATOR, compose);
6687 if (pipe(pipe_fds) < 0) {
6693 if ((pid = fork()) < 0) {
6700 /* close the write side of the pipe */
6703 compose->exteditor_file = g_strdup(tmp);
6704 compose->exteditor_pid = pid;
6706 compose_set_ext_editor_sensitive(compose, FALSE);
6708 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6709 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6713 } else { /* process-monitoring process */
6719 /* close the read side of the pipe */
6722 if (compose_write_body_to_file(compose, tmp) < 0) {
6723 fd_write_all(pipe_fds[1], "2\n", 2);
6727 pid_ed = compose_exec_ext_editor_real(tmp);
6729 fd_write_all(pipe_fds[1], "1\n", 2);
6733 /* wait until editor is terminated */
6734 waitpid(pid_ed, NULL, 0);
6736 fd_write_all(pipe_fds[1], "0\n", 2);
6743 #endif /* G_OS_UNIX */
6747 static gint compose_exec_ext_editor_real(const gchar *file)
6754 g_return_val_if_fail(file != NULL, -1);
6756 if ((pid = fork()) < 0) {
6761 if (pid != 0) return pid;
6763 /* grandchild process */
6765 if (setpgid(0, getppid()))
6768 if (prefs_common.ext_editor_cmd &&
6769 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6770 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6771 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6773 if (prefs_common.ext_editor_cmd)
6774 g_warning("External editor command line is invalid: '%s'\n",
6775 prefs_common.ext_editor_cmd);
6776 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
6779 cmdline = strsplit_with_quote(buf, " ", 1024);
6780 execvp(cmdline[0], cmdline);
6783 g_strfreev(cmdline);
6788 static gboolean compose_ext_editor_kill(Compose *compose)
6790 pid_t pgid = compose->exteditor_pid * -1;
6793 ret = kill(pgid, 0);
6795 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6799 msg = g_strdup_printf
6800 (_("The external editor is still working.\n"
6801 "Force terminating the process?\n"
6802 "process group id: %d"), -pgid);
6803 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
6804 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
6808 if (val == G_ALERTALTERNATE) {
6809 g_source_remove(compose->exteditor_tag);
6810 g_io_channel_shutdown(compose->exteditor_ch,
6812 g_io_channel_unref(compose->exteditor_ch);
6814 if (kill(pgid, SIGTERM) < 0) perror("kill");
6815 waitpid(compose->exteditor_pid, NULL, 0);
6817 g_warning("Terminated process group id: %d", -pgid);
6818 g_warning("Temporary file: %s",
6819 compose->exteditor_file);
6821 compose_set_ext_editor_sensitive(compose, TRUE);
6823 g_free(compose->exteditor_file);
6824 compose->exteditor_file = NULL;
6825 compose->exteditor_pid = -1;
6826 compose->exteditor_ch = NULL;
6827 compose->exteditor_tag = -1;
6835 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6839 Compose *compose = (Compose *)data;
6842 debug_print(_("Compose: input from monitoring process\n"));
6844 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6846 g_io_channel_shutdown(source, FALSE, NULL);
6847 g_io_channel_unref(source);
6849 waitpid(compose->exteditor_pid, NULL, 0);
6851 if (buf[0] == '0') { /* success */
6852 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6853 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6855 gtk_text_buffer_set_text(buffer, "", -1);
6856 compose_insert_file(compose, compose->exteditor_file);
6857 compose_changed_cb(NULL, compose);
6859 if (g_unlink(compose->exteditor_file) < 0)
6860 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6861 } else if (buf[0] == '1') { /* failed */
6862 g_warning("Couldn't exec external editor\n");
6863 if (g_unlink(compose->exteditor_file) < 0)
6864 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6865 } else if (buf[0] == '2') {
6866 g_warning("Couldn't write to file\n");
6867 } else if (buf[0] == '3') {
6868 g_warning("Pipe read failed\n");
6871 compose_set_ext_editor_sensitive(compose, TRUE);
6873 g_free(compose->exteditor_file);
6874 compose->exteditor_file = NULL;
6875 compose->exteditor_pid = -1;
6876 compose->exteditor_ch = NULL;
6877 compose->exteditor_tag = -1;
6882 static void compose_set_ext_editor_sensitive(Compose *compose,
6885 GtkItemFactory *ifactory;
6887 ifactory = gtk_item_factory_from_widget(compose->menubar);
6889 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6890 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6891 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6892 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6893 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6894 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6895 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6898 gtk_widget_set_sensitive(compose->text, sensitive);
6899 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6900 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6901 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6902 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6903 if (compose->toolbar->sig_btn)
6904 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6905 if (compose->toolbar->exteditor_btn)
6906 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6907 if (compose->toolbar->linewrap_current_btn)
6908 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6909 if (compose->toolbar->linewrap_all_btn)
6910 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6912 #endif /* G_OS_UNIX */
6915 * compose_undo_state_changed:
6917 * Change the sensivity of the menuentries undo and redo
6919 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6920 gint redo_state, gpointer data)
6922 GtkWidget *widget = GTK_WIDGET(data);
6923 GtkItemFactory *ifactory;
6925 g_return_if_fail(widget != NULL);
6927 ifactory = gtk_item_factory_from_widget(widget);
6929 switch (undo_state) {
6930 case UNDO_STATE_TRUE:
6931 if (!undostruct->undo_state) {
6932 undostruct->undo_state = TRUE;
6933 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6936 case UNDO_STATE_FALSE:
6937 if (undostruct->undo_state) {
6938 undostruct->undo_state = FALSE;
6939 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6942 case UNDO_STATE_UNCHANGED:
6944 case UNDO_STATE_REFRESH:
6945 menu_set_sensitive(ifactory, "/Edit/Undo",
6946 undostruct->undo_state);
6949 g_warning("Undo state not recognized");
6953 switch (redo_state) {
6954 case UNDO_STATE_TRUE:
6955 if (!undostruct->redo_state) {
6956 undostruct->redo_state = TRUE;
6957 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6960 case UNDO_STATE_FALSE:
6961 if (undostruct->redo_state) {
6962 undostruct->redo_state = FALSE;
6963 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6966 case UNDO_STATE_UNCHANGED:
6968 case UNDO_STATE_REFRESH:
6969 menu_set_sensitive(ifactory, "/Edit/Redo",
6970 undostruct->redo_state);
6973 g_warning("Redo state not recognized");
6978 /* callback functions */
6980 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6981 * includes "non-client" (windows-izm) in calculation, so this calculation
6982 * may not be accurate.
6984 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6985 GtkAllocation *allocation,
6986 GtkSHRuler *shruler)
6988 if (prefs_common.show_ruler) {
6989 gint char_width = 0, char_height = 0;
6990 gint line_width_in_chars;
6992 gtkut_get_font_size(GTK_WIDGET(widget),
6993 &char_width, &char_height);
6994 line_width_in_chars =
6995 (allocation->width - allocation->x) / char_width;
6997 /* got the maximum */
6998 gtk_ruler_set_range(GTK_RULER(shruler),
6999 0.0, line_width_in_chars, 0,
7000 /*line_width_in_chars*/ char_width);
7006 static void account_activated(GtkMenuItem *menuitem, gpointer data)
7008 Compose *compose = (Compose *)data;
7011 gchar *folderidentifier;
7013 ac = account_find_from_id(
7014 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
7015 g_return_if_fail(ac != NULL);
7017 if (ac != compose->account)
7018 compose_select_account(compose, ac, FALSE);
7020 /* Set message save folder */
7021 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7022 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7024 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7025 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7027 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7028 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7029 folderidentifier = folder_item_get_identifier(account_get_special_folder
7030 (compose->account, F_OUTBOX));
7031 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7032 g_free(folderidentifier);
7036 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7037 GtkTreeViewColumn *column, Compose *compose)
7039 compose_attach_property(compose);
7042 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7045 Compose *compose = (Compose *)data;
7046 GtkTreeSelection *attach_selection;
7047 gint attach_nr_selected;
7048 GtkItemFactory *ifactory;
7050 if (!event) return FALSE;
7052 if (event->button == 3) {
7053 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7054 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7055 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7057 if (attach_nr_selected > 0)
7059 menu_set_sensitive(ifactory, "/Remove", TRUE);
7060 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7062 menu_set_sensitive(ifactory, "/Remove", FALSE);
7063 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7066 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7067 NULL, NULL, event->button, event->time);
7074 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7077 Compose *compose = (Compose *)data;
7079 if (!event) return FALSE;
7081 switch (event->keyval) {
7083 compose_attach_remove_selected(compose);
7089 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7091 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7092 toolbar_comp_set_sensitive(compose, allow);
7093 menu_set_sensitive(ifactory, "/Message", allow);
7094 menu_set_sensitive(ifactory, "/Edit", allow);
7096 menu_set_sensitive(ifactory, "/Spelling", allow);
7098 menu_set_sensitive(ifactory, "/Options", allow);
7099 menu_set_sensitive(ifactory, "/Tools", allow);
7100 menu_set_sensitive(ifactory, "/Help", allow);
7102 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7106 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7108 Compose *compose = (Compose *)data;
7110 if (prefs_common.work_offline && !inc_offline_should_override())
7113 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7114 gtk_timeout_remove(compose->draft_timeout_tag);
7115 compose->draft_timeout_tag = -1;
7118 compose_send(compose);
7121 static void compose_send_later_cb(gpointer data, guint action,
7124 Compose *compose = (Compose *)data;
7127 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE);
7129 compose_close(compose);
7130 else if (val == -2) {
7131 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7135 void compose_draft (gpointer data)
7137 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7140 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7142 Compose *compose = (Compose *)data;
7146 MsgFlags flag = {0, 0};
7147 static gboolean lock = FALSE;
7148 MsgInfo *newmsginfo;
7150 gboolean target_locked = FALSE;
7154 draft = account_get_special_folder(compose->account, F_DRAFT);
7155 g_return_if_fail(draft != NULL);
7157 if (!g_mutex_trylock(compose->mutex)) {
7158 /* we don't want to lock the mutex once it's available,
7159 * because as the only other part of compose.c locking
7160 * it is compose_close - which means once unlocked,
7161 * the compose struct will be freed */
7162 debug_print("couldn't lock mutex, probably sending\n");
7168 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7169 G_DIR_SEPARATOR, compose);
7170 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7171 FILE_OP_ERROR(tmp, "fopen");
7175 /* chmod for security */
7176 if (change_file_mode_rw(fp, tmp) < 0) {
7177 FILE_OP_ERROR(tmp, "chmod");
7178 g_warning("can't change file mode\n");
7181 /* Save draft infos */
7182 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7183 fprintf(fp, "S:%s\n", compose->account->address);
7184 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7185 gchar *savefolderid;
7187 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7188 fprintf(fp, "SCF:%s\n", savefolderid);
7189 g_free(savefolderid);
7191 if (compose->return_receipt) {
7192 fprintf(fp, "RRCPT:1\n");
7194 if (compose->privacy_system) {
7195 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7196 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7197 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7201 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7209 if (compose->targetinfo) {
7210 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7211 flag.perm_flags = target_locked?MSG_LOCKED:0;
7213 flag.tmp_flags = MSG_DRAFT;
7215 folder_item_scan(draft);
7216 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7219 if (action != COMPOSE_AUTO_SAVE)
7220 alertpanel_error(_("Could not save draft."));
7224 draft->mtime = 0; /* force updating */
7226 if (compose->mode == COMPOSE_REEDIT) {
7227 compose_remove_reedit_target(compose, TRUE);
7230 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7232 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7234 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7236 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7237 if (compose_use_attach(compose))
7238 procmsg_msginfo_set_flags(newmsginfo, 0,
7239 MSG_HAS_ATTACHMENT);
7241 procmsg_msginfo_free(newmsginfo);
7244 folder_item_scan(draft);
7246 if (action == COMPOSE_QUIT_EDITING) {
7248 g_mutex_unlock(compose->mutex); /* must be done before closing */
7249 compose_close(compose);
7255 path = folder_item_fetch_msg(draft, msgnum);
7257 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7260 if (g_stat(path, &s) < 0) {
7261 FILE_OP_ERROR(path, "stat");
7267 procmsg_msginfo_free(compose->targetinfo);
7268 compose->targetinfo = procmsg_msginfo_new();
7269 compose->targetinfo->msgnum = msgnum;
7270 compose->targetinfo->size = s.st_size;
7271 compose->targetinfo->mtime = s.st_mtime;
7272 compose->targetinfo->folder = draft;
7274 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7275 compose->mode = COMPOSE_REEDIT;
7277 if (action == COMPOSE_AUTO_SAVE) {
7278 compose->autosaved_draft = compose->targetinfo;
7280 compose->modified = FALSE;
7281 compose_set_title(compose);
7285 g_mutex_unlock(compose->mutex);
7288 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7290 Compose *compose = (Compose *)data;
7293 if (compose->redirect_filename != NULL)
7296 file_list = filesel_select_multiple_files_open(_("Select file"));
7301 for ( tmp = file_list; tmp; tmp = tmp->next) {
7302 gchar *file = (gchar *) tmp->data;
7303 gchar *utf8_filename = conv_filename_to_utf8(file);
7304 compose_attach_append(compose, file, utf8_filename, NULL);
7305 compose_changed_cb(NULL, compose);
7307 g_free(utf8_filename);
7309 g_list_free(file_list);
7313 static void compose_insert_file_cb(gpointer data, guint action,
7316 Compose *compose = (Compose *)data;
7319 file_list = filesel_select_multiple_files_open(_("Select file"));
7324 for ( tmp = file_list; tmp; tmp = tmp->next) {
7325 gchar *file = (gchar *) tmp->data;
7326 gchar *filedup = g_strdup(file);
7327 gchar *shortfile = g_path_get_basename(filedup);
7328 ComposeInsertResult res;
7330 res = compose_insert_file(compose, file);
7331 if (res == COMPOSE_INSERT_READ_ERROR) {
7332 alertpanel_error(_("File '%s' could not be read."), shortfile);
7333 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7334 alertpanel_error(_("File '%s' contained invalid characters\n"
7335 "for the current encoding, insertion may be incorrect."), shortfile);
7341 g_list_free(file_list);
7345 static void compose_insert_sig_cb(gpointer data, guint action,
7348 Compose *compose = (Compose *)data;
7350 compose_insert_sig(compose, FALSE);
7353 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7357 Compose *compose = (Compose *)data;
7359 gtkut_widget_get_uposition(widget, &x, &y);
7360 prefs_common.compose_x = x;
7361 prefs_common.compose_y = y;
7363 if (compose->sending)
7365 compose_close_cb(compose, 0, NULL);
7369 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7371 Compose *compose = (Compose *)data;
7375 if (compose->exteditor_tag != -1) {
7376 if (!compose_ext_editor_kill(compose))
7381 if (compose->modified) {
7382 val = alertpanel(_("Discard message"),
7383 _("This message has been modified. Discard it?"),
7384 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7387 case G_ALERTDEFAULT:
7388 if (prefs_common.autosave)
7389 compose_remove_draft(compose);
7391 case G_ALERTALTERNATE:
7392 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7399 compose_close(compose);
7402 static void compose_set_encoding_cb(gpointer data, guint action,
7405 Compose *compose = (Compose *)data;
7407 if (GTK_CHECK_MENU_ITEM(widget)->active)
7408 compose->out_encoding = (CharSet)action;
7411 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7413 Compose *compose = (Compose *)data;
7415 addressbook_open(compose);
7418 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7420 Compose *compose = (Compose *)data;
7425 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7426 g_return_if_fail(tmpl != NULL);
7428 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7430 val = alertpanel(_("Apply template"), msg,
7431 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7434 if (val == G_ALERTDEFAULT)
7435 compose_template_apply(compose, tmpl, TRUE);
7436 else if (val == G_ALERTALTERNATE)
7437 compose_template_apply(compose, tmpl, FALSE);
7440 static void compose_ext_editor_cb(gpointer data, guint action,
7443 Compose *compose = (Compose *)data;
7445 compose_exec_ext_editor(compose);
7448 static void compose_undo_cb(Compose *compose)
7450 gboolean prev_autowrap = compose->autowrap;
7452 compose->autowrap = FALSE;
7453 undo_undo(compose->undostruct);
7454 compose->autowrap = prev_autowrap;
7457 static void compose_redo_cb(Compose *compose)
7459 gboolean prev_autowrap = compose->autowrap;
7461 compose->autowrap = FALSE;
7462 undo_redo(compose->undostruct);
7463 compose->autowrap = prev_autowrap;
7466 static void entry_cut_clipboard(GtkWidget *entry)
7468 if (GTK_IS_EDITABLE(entry))
7469 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7470 else if (GTK_IS_TEXT_VIEW(entry))
7471 gtk_text_buffer_cut_clipboard(
7472 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7473 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7477 static void entry_copy_clipboard(GtkWidget *entry)
7479 if (GTK_IS_EDITABLE(entry))
7480 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7481 else if (GTK_IS_TEXT_VIEW(entry))
7482 gtk_text_buffer_copy_clipboard(
7483 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7484 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7487 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7488 gboolean wrap, GdkAtom clip)
7490 if (GTK_IS_TEXT_VIEW(entry)) {
7491 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7492 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7493 GtkTextIter start_iter, end_iter;
7496 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7498 if (contents == NULL)
7501 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7502 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7504 start = gtk_text_iter_get_offset(&start_iter);
7506 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7509 end = start + strlen(contents);
7510 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7511 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7512 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7513 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7514 mark_start = gtk_text_buffer_get_insert(buffer);
7515 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7516 gtk_text_iter_backward_char(&start_iter);
7517 compose_beautify_paragraph(compose, &start_iter, TRUE);
7520 } else if (GTK_IS_EDITABLE(entry))
7521 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7525 static void entry_allsel(GtkWidget *entry)
7527 if (GTK_IS_EDITABLE(entry))
7528 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7529 else if (GTK_IS_TEXT_VIEW(entry)) {
7530 GtkTextIter startiter, enditer;
7531 GtkTextBuffer *textbuf;
7533 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7534 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7535 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7537 gtk_text_buffer_move_mark_by_name(textbuf,
7538 "selection_bound", &startiter);
7539 gtk_text_buffer_move_mark_by_name(textbuf,
7540 "insert", &enditer);
7544 static void compose_cut_cb(Compose *compose)
7546 if (compose->focused_editable &&
7547 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7548 entry_cut_clipboard(compose->focused_editable);
7551 static void compose_copy_cb(Compose *compose)
7553 if (compose->focused_editable &&
7554 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7555 entry_copy_clipboard(compose->focused_editable);
7558 static void compose_paste_cb(Compose *compose)
7561 GtkTextBuffer *buffer;
7563 if (compose->focused_editable &&
7564 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7565 entry_paste_clipboard(compose, compose->focused_editable,
7566 prefs_common.linewrap_pastes,
7567 GDK_SELECTION_CLIPBOARD);
7571 static void compose_paste_as_quote_cb(Compose *compose)
7573 gint wrap_quote = prefs_common.linewrap_quote;
7574 if (compose->focused_editable &&
7575 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7576 /* let text_insert() (called directly or at a later time
7577 * after the gtk_editable_paste_clipboard) know that
7578 * text is to be inserted as a quotation. implemented
7579 * by using a simple refcount... */
7580 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7581 G_OBJECT(compose->focused_editable),
7582 "paste_as_quotation"));
7583 g_object_set_data(G_OBJECT(compose->focused_editable),
7584 "paste_as_quotation",
7585 GINT_TO_POINTER(paste_as_quotation + 1));
7586 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7587 entry_paste_clipboard(compose, compose->focused_editable,
7588 prefs_common.linewrap_pastes,
7589 GDK_SELECTION_CLIPBOARD);
7590 prefs_common.linewrap_quote = wrap_quote;
7594 static void compose_paste_no_wrap_cb(Compose *compose)
7597 GtkTextBuffer *buffer;
7599 if (compose->focused_editable &&
7600 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7601 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7602 GDK_SELECTION_CLIPBOARD);
7606 static void compose_paste_wrap_cb(Compose *compose)
7609 GtkTextBuffer *buffer;
7611 if (compose->focused_editable &&
7612 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7613 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7614 GDK_SELECTION_CLIPBOARD);
7618 static void compose_allsel_cb(Compose *compose)
7620 if (compose->focused_editable &&
7621 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7622 entry_allsel(compose->focused_editable);
7625 static void textview_move_beginning_of_line (GtkTextView *text)
7627 GtkTextBuffer *buffer;
7631 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7633 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7634 mark = gtk_text_buffer_get_insert(buffer);
7635 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7636 gtk_text_iter_set_line_offset(&ins, 0);
7637 gtk_text_buffer_place_cursor(buffer, &ins);
7640 static void textview_move_forward_character (GtkTextView *text)
7642 GtkTextBuffer *buffer;
7646 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7648 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7649 mark = gtk_text_buffer_get_insert(buffer);
7650 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7651 if (gtk_text_iter_forward_cursor_position(&ins))
7652 gtk_text_buffer_place_cursor(buffer, &ins);
7655 static void textview_move_backward_character (GtkTextView *text)
7657 GtkTextBuffer *buffer;
7661 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7663 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7664 mark = gtk_text_buffer_get_insert(buffer);
7665 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7666 if (gtk_text_iter_backward_cursor_position(&ins))
7667 gtk_text_buffer_place_cursor(buffer, &ins);
7670 static void textview_move_forward_word (GtkTextView *text)
7672 GtkTextBuffer *buffer;
7677 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7679 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7680 mark = gtk_text_buffer_get_insert(buffer);
7681 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7682 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7683 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7684 gtk_text_iter_backward_word_start(&ins);
7685 gtk_text_buffer_place_cursor(buffer, &ins);
7689 static void textview_move_backward_word (GtkTextView *text)
7691 GtkTextBuffer *buffer;
7696 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7698 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7699 mark = gtk_text_buffer_get_insert(buffer);
7700 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7701 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7702 if (gtk_text_iter_backward_word_starts(&ins, 1))
7703 gtk_text_buffer_place_cursor(buffer, &ins);
7706 static void textview_move_end_of_line (GtkTextView *text)
7708 GtkTextBuffer *buffer;
7712 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7714 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7715 mark = gtk_text_buffer_get_insert(buffer);
7716 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7717 if (gtk_text_iter_forward_to_line_end(&ins))
7718 gtk_text_buffer_place_cursor(buffer, &ins);
7721 static void textview_move_next_line (GtkTextView *text)
7723 GtkTextBuffer *buffer;
7728 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7730 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7731 mark = gtk_text_buffer_get_insert(buffer);
7732 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7733 offset = gtk_text_iter_get_line_offset(&ins);
7734 if (gtk_text_iter_forward_line(&ins)) {
7735 gtk_text_iter_set_line_offset(&ins, offset);
7736 gtk_text_buffer_place_cursor(buffer, &ins);
7740 static void textview_move_previous_line (GtkTextView *text)
7742 GtkTextBuffer *buffer;
7747 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7749 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7750 mark = gtk_text_buffer_get_insert(buffer);
7751 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7752 offset = gtk_text_iter_get_line_offset(&ins);
7753 if (gtk_text_iter_backward_line(&ins)) {
7754 gtk_text_iter_set_line_offset(&ins, offset);
7755 gtk_text_buffer_place_cursor(buffer, &ins);
7759 static void textview_delete_forward_character (GtkTextView *text)
7761 GtkTextBuffer *buffer;
7763 GtkTextIter ins, end_iter;
7765 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7767 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7768 mark = gtk_text_buffer_get_insert(buffer);
7769 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7771 if (gtk_text_iter_forward_char(&end_iter)) {
7772 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7776 static void textview_delete_backward_character (GtkTextView *text)
7778 GtkTextBuffer *buffer;
7780 GtkTextIter ins, end_iter;
7782 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7784 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7785 mark = gtk_text_buffer_get_insert(buffer);
7786 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7788 if (gtk_text_iter_backward_char(&end_iter)) {
7789 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7793 static void textview_delete_forward_word (GtkTextView *text)
7795 GtkTextBuffer *buffer;
7797 GtkTextIter ins, end_iter;
7799 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7801 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7802 mark = gtk_text_buffer_get_insert(buffer);
7803 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7805 if (gtk_text_iter_forward_word_end(&end_iter)) {
7806 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7810 static void textview_delete_backward_word (GtkTextView *text)
7812 GtkTextBuffer *buffer;
7814 GtkTextIter ins, end_iter;
7816 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7818 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7819 mark = gtk_text_buffer_get_insert(buffer);
7820 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7822 if (gtk_text_iter_backward_word_start(&end_iter)) {
7823 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7827 static void textview_delete_line (GtkTextView *text)
7829 GtkTextBuffer *buffer;
7831 GtkTextIter ins, start_iter, end_iter;
7834 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7836 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7837 mark = gtk_text_buffer_get_insert(buffer);
7838 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7841 gtk_text_iter_set_line_offset(&start_iter, 0);
7844 if (gtk_text_iter_ends_line(&end_iter))
7845 found = gtk_text_iter_forward_char(&end_iter);
7847 found = gtk_text_iter_forward_to_line_end(&end_iter);
7850 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7853 static void textview_delete_to_line_end (GtkTextView *text)
7855 GtkTextBuffer *buffer;
7857 GtkTextIter ins, end_iter;
7860 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7862 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7863 mark = gtk_text_buffer_get_insert(buffer);
7864 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7866 if (gtk_text_iter_ends_line(&end_iter))
7867 found = gtk_text_iter_forward_char(&end_iter);
7869 found = gtk_text_iter_forward_to_line_end(&end_iter);
7871 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7874 static void compose_advanced_action_cb(Compose *compose,
7875 ComposeCallAdvancedAction action)
7877 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7879 void (*do_action) (GtkTextView *text);
7880 } action_table[] = {
7881 {textview_move_beginning_of_line},
7882 {textview_move_forward_character},
7883 {textview_move_backward_character},
7884 {textview_move_forward_word},
7885 {textview_move_backward_word},
7886 {textview_move_end_of_line},
7887 {textview_move_next_line},
7888 {textview_move_previous_line},
7889 {textview_delete_forward_character},
7890 {textview_delete_backward_character},
7891 {textview_delete_forward_word},
7892 {textview_delete_backward_word},
7893 {textview_delete_line},
7894 {NULL}, /* gtk_stext_delete_line_n */
7895 {textview_delete_to_line_end}
7898 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7900 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7901 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7902 if (action_table[action].do_action)
7903 action_table[action].do_action(text);
7905 g_warning("Not implemented yet.");
7909 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7913 if (GTK_IS_EDITABLE(widget)) {
7914 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7915 gtk_editable_set_position(GTK_EDITABLE(widget),
7918 if (widget->parent && widget->parent->parent
7919 && widget->parent->parent->parent) {
7920 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7921 gint y = widget->allocation.y;
7922 gint height = widget->allocation.height;
7923 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7924 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7926 if (y < (int)shown->value) {
7927 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7929 if (y + height > (int)shown->value + (int)shown->page_size) {
7930 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7931 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7932 y + height - (int)shown->page_size - 1);
7934 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7935 (int)shown->upper - (int)shown->page_size - 1);
7942 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7943 compose->focused_editable = widget;
7946 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7948 compose->modified = TRUE;
7949 compose_set_title(compose);
7952 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7954 Compose *compose = (Compose *)data;
7957 compose_wrap_all_full(compose, TRUE);
7959 compose_beautify_paragraph(compose, NULL, TRUE);
7962 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
7964 Compose *compose = (Compose *)data;
7966 message_search_compose(compose);
7969 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7972 Compose *compose = (Compose *)data;
7973 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7974 if (compose->autowrap)
7975 compose_wrap_all_full(compose, TRUE);
7976 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7979 static void compose_toggle_sign_cb(gpointer data, guint action,
7982 Compose *compose = (Compose *)data;
7984 if (GTK_CHECK_MENU_ITEM(widget)->active)
7985 compose->use_signing = TRUE;
7987 compose->use_signing = FALSE;
7990 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7993 Compose *compose = (Compose *)data;
7995 if (GTK_CHECK_MENU_ITEM(widget)->active)
7996 compose->use_encryption = TRUE;
7998 compose->use_encryption = FALSE;
8001 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8003 g_free(compose->privacy_system);
8005 compose->privacy_system = g_strdup(account->default_privacy_system);
8006 compose_update_privacy_system_menu_item(compose, warn);
8009 static void compose_toggle_ruler_cb(gpointer data, guint action,
8012 Compose *compose = (Compose *)data;
8014 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8015 gtk_widget_show(compose->ruler_hbox);
8016 prefs_common.show_ruler = TRUE;
8018 gtk_widget_hide(compose->ruler_hbox);
8019 gtk_widget_queue_resize(compose->edit_vbox);
8020 prefs_common.show_ruler = FALSE;
8024 static void compose_attach_drag_received_cb (GtkWidget *widget,
8025 GdkDragContext *context,
8028 GtkSelectionData *data,
8033 Compose *compose = (Compose *)user_data;
8036 if (gdk_atom_name(data->type) &&
8037 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8038 && gtk_drag_get_source_widget(context) !=
8039 mainwindow_get_mainwindow()->summaryview->ctree) {
8040 list = uri_list_extract_filenames((const gchar *)data->data);
8041 for (tmp = list; tmp != NULL; tmp = tmp->next)
8042 compose_attach_append
8043 (compose, (const gchar *)tmp->data,
8044 (const gchar *)tmp->data, NULL);
8045 if (list) compose_changed_cb(NULL, compose);
8046 list_free_strings(list);
8048 } else if (gtk_drag_get_source_widget(context)
8049 == mainwindow_get_mainwindow()->summaryview->ctree) {
8050 /* comes from our summaryview */
8051 SummaryView * summaryview = NULL;
8052 GSList * list = NULL, *cur = NULL;
8054 if (mainwindow_get_mainwindow())
8055 summaryview = mainwindow_get_mainwindow()->summaryview;
8058 list = summary_get_selected_msg_list(summaryview);
8060 for (cur = list; cur; cur = cur->next) {
8061 MsgInfo *msginfo = (MsgInfo *)cur->data;
8064 file = procmsg_get_message_file_full(msginfo,
8067 compose_attach_append(compose, (const gchar *)file,
8068 (const gchar *)file, "message/rfc822");
8076 static gboolean compose_drag_drop(GtkWidget *widget,
8077 GdkDragContext *drag_context,
8079 guint time, gpointer user_data)
8081 /* not handling this signal makes compose_insert_drag_received_cb
8086 static void compose_insert_drag_received_cb (GtkWidget *widget,
8087 GdkDragContext *drag_context,
8090 GtkSelectionData *data,
8095 Compose *compose = (Compose *)user_data;
8098 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8100 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8101 list = uri_list_extract_filenames((const gchar *)data->data);
8102 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8103 compose_insert_file(compose, (const gchar *)tmp->data);
8105 list_free_strings(list);
8107 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8110 #if GTK_CHECK_VERSION(2, 8, 0)
8111 /* do nothing, handled by GTK */
8113 gchar *tmpfile = get_tmp_file();
8114 str_write_to_file((const gchar *)data->data, tmpfile);
8115 compose_insert_file(compose, tmpfile);
8118 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8122 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8125 static void compose_header_drag_received_cb (GtkWidget *widget,
8126 GdkDragContext *drag_context,
8129 GtkSelectionData *data,
8134 GtkEditable *entry = (GtkEditable *)user_data;
8135 gchar *email = (gchar *)data->data;
8137 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8140 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8141 gchar *decoded=g_new(gchar, strlen(email));
8144 email += strlen("mailto:");
8145 decode_uri(decoded, email); /* will fit */
8146 gtk_editable_delete_text(entry, 0, -1);
8147 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8148 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8152 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8155 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8158 Compose *compose = (Compose *)data;
8160 if (GTK_CHECK_MENU_ITEM(widget)->active)
8161 compose->return_receipt = TRUE;
8163 compose->return_receipt = FALSE;
8166 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8169 Compose *compose = (Compose *)data;
8171 if (GTK_CHECK_MENU_ITEM(widget)->active)
8172 compose->remove_references = TRUE;
8174 compose->remove_references = FALSE;
8177 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8179 ComposeHeaderEntry *headerentry)
8181 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8182 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8183 !(event->state & GDK_MODIFIER_MASK) &&
8184 (event->keyval == GDK_BackSpace) &&
8185 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8186 gtk_container_remove
8187 (GTK_CONTAINER(headerentry->compose->header_table),
8188 headerentry->combo);
8189 gtk_container_remove
8190 (GTK_CONTAINER(headerentry->compose->header_table),
8191 headerentry->entry);
8192 headerentry->compose->header_list =
8193 g_slist_remove(headerentry->compose->header_list,
8195 g_free(headerentry);
8196 } else if (event->keyval == GDK_Tab) {
8197 if (headerentry->compose->header_last == headerentry) {
8198 /* Override default next focus, and give it to subject_entry
8199 * instead of notebook tabs
8201 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8202 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8209 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8210 ComposeHeaderEntry *headerentry)
8212 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8213 headerentry->compose->header_list =
8214 g_slist_append(headerentry->compose->header_list,
8217 compose_create_header_entry(headerentry->compose);
8218 g_signal_handlers_disconnect_matched
8219 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8220 0, 0, NULL, NULL, headerentry);
8222 /* Automatically scroll down */
8223 compose_show_first_last_header(headerentry->compose, FALSE);
8229 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8231 GtkAdjustment *vadj;
8233 g_return_if_fail(compose);
8234 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8235 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8237 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8238 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8241 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8242 const gchar *text, gint len, Compose *compose)
8244 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8245 (G_OBJECT(compose->text), "paste_as_quotation"));
8248 g_return_if_fail(text != NULL);
8250 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8251 G_CALLBACK(text_inserted),
8253 if (paste_as_quotation) {
8260 new_text = g_strndup(text, len);
8261 if (prefs_common.quotemark && *prefs_common.quotemark)
8262 qmark = prefs_common.quotemark;
8266 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8267 gtk_text_buffer_place_cursor(buffer, iter);
8269 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8271 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8272 GINT_TO_POINTER(paste_as_quotation - 1));
8274 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8275 gtk_text_buffer_place_cursor(buffer, iter);
8277 if (strcmp(text, "\n") || automatic_break
8278 || gtk_text_iter_starts_line(iter))
8279 gtk_text_buffer_insert(buffer, iter, text, len);
8281 debug_print("insert nowrap \\n\n");
8282 gtk_text_buffer_insert_with_tags_by_name(buffer,
8283 iter, text, len, "no_join", NULL);
8287 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8289 compose_beautify_paragraph(compose, iter, FALSE);
8291 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8292 gtk_text_buffer_delete_mark(buffer, mark);
8294 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8295 G_CALLBACK(text_inserted),
8297 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8299 if (prefs_common.autosave &&
8300 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8301 compose->draft_timeout_tag = gtk_timeout_add
8302 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8304 static gint compose_defer_auto_save_draft(Compose *compose)
8306 compose->draft_timeout_tag = -1;
8307 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8312 static void compose_check_all(Compose *compose)
8314 if (compose->gtkaspell)
8315 gtkaspell_check_all(compose->gtkaspell);
8318 static void compose_highlight_all(Compose *compose)
8320 if (compose->gtkaspell)
8321 gtkaspell_highlight_all(compose->gtkaspell);
8324 static void compose_check_backwards(Compose *compose)
8326 if (compose->gtkaspell)
8327 gtkaspell_check_backwards(compose->gtkaspell);
8329 GtkItemFactory *ifactory;
8330 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8331 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8332 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8336 static void compose_check_forwards_go(Compose *compose)
8338 if (compose->gtkaspell)
8339 gtkaspell_check_forwards_go(compose->gtkaspell);
8341 GtkItemFactory *ifactory;
8342 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8343 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8344 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8350 *\brief Guess originating forward account from MsgInfo and several
8351 * "common preference" settings. Return NULL if no guess.
8353 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8355 PrefsAccount *account = NULL;
8357 g_return_val_if_fail(msginfo, NULL);
8358 g_return_val_if_fail(msginfo->folder, NULL);
8359 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8361 if (msginfo->folder->prefs->enable_default_account)
8362 account = account_find_from_id(msginfo->folder->prefs->default_account);
8365 account = msginfo->folder->folder->account;
8367 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8369 Xstrdup_a(to, msginfo->to, return NULL);
8370 extract_address(to);
8371 account = account_find_from_address(to);
8374 if (!account && prefs_common.forward_account_autosel) {
8376 if (!procheader_get_header_from_msginfo
8377 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8378 extract_address(cc);
8379 account = account_find_from_address(cc);
8386 static gboolean compose_close(Compose *compose)
8390 if (!g_mutex_trylock(compose->mutex)) {
8391 /* we have to wait for the (possibly deferred by auto-save)
8392 * drafting to be done, before destroying the compose under
8394 debug_print("waiting for drafting to finish...\n");
8395 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8398 g_return_val_if_fail(compose, FALSE);
8399 gtkut_widget_get_uposition(compose->window, &x, &y);
8400 prefs_common.compose_x = x;
8401 prefs_common.compose_y = y;
8402 g_mutex_unlock(compose->mutex);
8403 compose_destroy(compose);
8408 * Add entry field for each address in list.
8409 * \param compose E-Mail composition object.
8410 * \param listAddress List of (formatted) E-Mail addresses.
8412 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8417 addr = ( gchar * ) node->data;
8418 compose_entry_append( compose, addr, COMPOSE_TO );
8419 node = g_list_next( node );
8423 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8427 GSList *new_msglist = NULL;
8428 MsgInfo *tmp_msginfo = NULL;
8429 gboolean originally_enc = FALSE;
8430 Compose *compose = NULL;
8432 g_return_if_fail(msgview != NULL);
8434 g_return_if_fail(msginfo_list != NULL);
8436 if (g_slist_length(msginfo_list) == 1) {
8437 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8438 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8440 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8441 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8442 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8443 orig_msginfo, mimeinfo);
8444 if (tmp_msginfo != NULL) {
8445 new_msglist = g_slist_append(NULL, tmp_msginfo);
8446 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8447 originally_enc = TRUE;
8453 body = messageview_get_selection(msgview);
8456 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8457 procmsg_msginfo_free(tmp_msginfo);
8458 g_slist_free(new_msglist);
8460 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8462 if (originally_enc) {
8463 compose_force_encryption(compose, compose->account, FALSE);
8469 void compose_set_position(Compose *compose, gint pos)
8471 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8473 gtkut_text_view_set_position(text, pos);
8476 gboolean compose_search_string(Compose *compose,
8477 const gchar *str, gboolean case_sens)
8479 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8481 return gtkut_text_view_search_string(text, str, case_sens);
8484 gboolean compose_search_string_backward(Compose *compose,
8485 const gchar *str, gboolean case_sens)
8487 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8489 return gtkut_text_view_search_string_backward(text, str, case_sens);