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,
276 static gint compose_queue_sub (Compose *compose,
279 gboolean check_subject);
280 static void compose_add_attachments (Compose *compose,
282 static gchar *compose_get_header (Compose *compose);
284 static void compose_convert_header (Compose *compose,
289 gboolean addr_field);
291 static void compose_attach_info_free (AttachInfo *ainfo);
292 static void compose_attach_remove_selected (Compose *compose);
294 static void compose_attach_property (Compose *compose);
295 static void compose_attach_property_create (gboolean *cancelled);
296 static void attach_property_ok (GtkWidget *widget,
297 gboolean *cancelled);
298 static void attach_property_cancel (GtkWidget *widget,
299 gboolean *cancelled);
300 static gint attach_property_delete_event (GtkWidget *widget,
302 gboolean *cancelled);
303 static gboolean attach_property_key_pressed (GtkWidget *widget,
305 gboolean *cancelled);
307 static void compose_exec_ext_editor (Compose *compose);
309 static gint compose_exec_ext_editor_real (const gchar *file);
310 static gboolean compose_ext_editor_kill (Compose *compose);
311 static gboolean compose_input_cb (GIOChannel *source,
312 GIOCondition condition,
314 static void compose_set_ext_editor_sensitive (Compose *compose,
316 #endif /* G_OS_UNIX */
318 static void compose_undo_state_changed (UndoMain *undostruct,
323 static void compose_create_header_entry (Compose *compose);
324 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
325 static void compose_update_priority_menu_item(Compose * compose);
327 static void compose_add_field_list ( Compose *compose,
328 GList *listAddress );
330 /* callback functions */
332 static gboolean compose_edit_size_alloc (GtkEditable *widget,
333 GtkAllocation *allocation,
334 GtkSHRuler *shruler);
335 static void account_activated (GtkMenuItem *menuitem,
337 static void attach_selected (GtkTreeView *tree_view,
338 GtkTreePath *tree_path,
339 GtkTreeViewColumn *column,
341 static gboolean attach_button_pressed (GtkWidget *widget,
342 GdkEventButton *event,
344 static gboolean attach_key_pressed (GtkWidget *widget,
348 static void compose_send_cb (gpointer data,
351 static void compose_send_later_cb (gpointer data,
355 static void compose_draft_cb (gpointer data,
359 static void compose_attach_cb (gpointer data,
362 static void compose_insert_file_cb (gpointer data,
365 static void compose_insert_sig_cb (gpointer data,
369 static void compose_close_cb (gpointer data,
373 static void compose_set_encoding_cb (gpointer data,
377 static void compose_address_cb (gpointer data,
380 static void compose_template_activate_cb(GtkWidget *widget,
383 static void compose_ext_editor_cb (gpointer data,
387 static gint compose_delete_cb (GtkWidget *widget,
391 static void compose_undo_cb (Compose *compose);
392 static void compose_redo_cb (Compose *compose);
393 static void compose_cut_cb (Compose *compose);
394 static void compose_copy_cb (Compose *compose);
395 static void compose_paste_cb (Compose *compose);
396 static void compose_paste_as_quote_cb (Compose *compose);
397 static void compose_paste_no_wrap_cb (Compose *compose);
398 static void compose_paste_wrap_cb (Compose *compose);
399 static void compose_allsel_cb (Compose *compose);
401 static void compose_advanced_action_cb (Compose *compose,
402 ComposeCallAdvancedAction action);
404 static void compose_grab_focus_cb (GtkWidget *widget,
407 static void compose_changed_cb (GtkTextBuffer *textbuf,
410 static void compose_wrap_cb (gpointer data,
413 static void compose_find_cb (gpointer data,
416 static void compose_toggle_autowrap_cb (gpointer data,
420 static void compose_toggle_ruler_cb (gpointer data,
423 static void compose_toggle_sign_cb (gpointer data,
426 static void compose_toggle_encrypt_cb (gpointer data,
429 static void compose_set_privacy_system_cb(GtkWidget *widget,
431 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
432 static void activate_privacy_system (Compose *compose,
433 PrefsAccount *account,
435 static void compose_use_signing(Compose *compose, gboolean use_signing);
436 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
437 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
439 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
441 static void compose_set_priority_cb (gpointer data,
445 static void compose_attach_drag_received_cb (GtkWidget *widget,
446 GdkDragContext *drag_context,
449 GtkSelectionData *data,
453 static void compose_insert_drag_received_cb (GtkWidget *widget,
454 GdkDragContext *drag_context,
457 GtkSelectionData *data,
461 static void compose_header_drag_received_cb (GtkWidget *widget,
462 GdkDragContext *drag_context,
465 GtkSelectionData *data,
470 static gboolean compose_drag_drop (GtkWidget *widget,
471 GdkDragContext *drag_context,
473 guint time, gpointer user_data);
475 static void text_inserted (GtkTextBuffer *buffer,
480 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
481 gboolean to_all, gboolean to_ml,
483 gboolean followup_and_reply_to,
486 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
487 ComposeHeaderEntry *headerentry);
488 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
490 ComposeHeaderEntry *headerentry);
492 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
494 static void compose_allow_user_actions (Compose *compose, gboolean allow);
497 static void compose_check_all (Compose *compose);
498 static void compose_highlight_all (Compose *compose);
499 static void compose_check_backwards (Compose *compose);
500 static void compose_check_forwards_go (Compose *compose);
503 static gint compose_defer_auto_save_draft (Compose *compose);
504 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
506 static gboolean compose_close (Compose *compose);
508 static GtkItemFactoryEntry compose_popup_entries[] =
510 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
511 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
512 {N_("/---"), NULL, NULL, 0, "<Separator>"},
513 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
516 static GtkItemFactoryEntry compose_entries[] =
518 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
519 {N_("/_Message/_Send"), "<control>Return",
520 compose_send_cb, 0, NULL},
521 {N_("/_Message/Send _later"), "<shift><control>S",
522 compose_send_later_cb, 0, NULL},
523 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
524 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
525 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
526 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
527 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
528 {N_("/_Message/_Save"),
529 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
533 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
534 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
535 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
536 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
537 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
538 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
539 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
540 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/Special paste/as _quotation"),
542 NULL, compose_paste_as_quote_cb, 0, NULL},
543 {N_("/_Edit/Special paste/_wrapped"),
544 NULL, compose_paste_wrap_cb, 0, NULL},
545 {N_("/_Edit/Special paste/_unwrapped"),
546 NULL, compose_paste_no_wrap_cb, 0, NULL},
547 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
548 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
549 {N_("/_Edit/A_dvanced/Move a character backward"),
551 compose_advanced_action_cb,
552 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
554 {N_("/_Edit/A_dvanced/Move a character forward"),
556 compose_advanced_action_cb,
557 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
559 {N_("/_Edit/A_dvanced/Move a word backward"),
561 compose_advanced_action_cb,
562 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
564 {N_("/_Edit/A_dvanced/Move a word forward"),
566 compose_advanced_action_cb,
567 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
569 {N_("/_Edit/A_dvanced/Move to beginning of line"),
570 NULL, /* "<control>A" */
571 compose_advanced_action_cb,
572 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
574 {N_("/_Edit/A_dvanced/Move to end of line"),
576 compose_advanced_action_cb,
577 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
579 {N_("/_Edit/A_dvanced/Move to previous line"),
581 compose_advanced_action_cb,
582 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
584 {N_("/_Edit/A_dvanced/Move to next line"),
586 compose_advanced_action_cb,
587 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
589 {N_("/_Edit/A_dvanced/Delete a character backward"),
591 compose_advanced_action_cb,
592 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
594 {N_("/_Edit/A_dvanced/Delete a character forward"),
596 compose_advanced_action_cb,
597 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
599 {N_("/_Edit/A_dvanced/Delete a word backward"),
600 NULL, /* "<control>W" */
601 compose_advanced_action_cb,
602 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
604 {N_("/_Edit/A_dvanced/Delete a word forward"),
605 NULL, /* "<alt>D", */
606 compose_advanced_action_cb,
607 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
609 {N_("/_Edit/A_dvanced/Delete line"),
611 compose_advanced_action_cb,
612 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
614 {N_("/_Edit/A_dvanced/Delete entire line"),
616 compose_advanced_action_cb,
617 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
619 {N_("/_Edit/A_dvanced/Delete to end of line"),
621 compose_advanced_action_cb,
622 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
624 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
626 "<control>F", compose_find_cb, 0, NULL},
627 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
628 {N_("/_Edit/_Wrap current paragraph"),
629 "<control>L", compose_wrap_cb, 0, NULL},
630 {N_("/_Edit/Wrap all long _lines"),
631 "<control><alt>L", compose_wrap_cb, 1, NULL},
632 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
633 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
634 {N_("/_Edit/Edit with e_xternal editor"),
635 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
637 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Spelling/_Check all or check selection"),
639 NULL, compose_check_all, 0, NULL},
640 {N_("/_Spelling/_Highlight all misspelled words"),
641 NULL, compose_highlight_all, 0, NULL},
642 {N_("/_Spelling/Check _backwards misspelled word"),
643 NULL, compose_check_backwards , 0, NULL},
644 {N_("/_Spelling/_Forward to next misspelled word"),
645 NULL, compose_check_forwards_go, 0, NULL},
647 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
648 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
649 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
650 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
651 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
652 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
653 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
655 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
656 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
657 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
658 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
659 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
660 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
661 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
663 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
665 #define ENC_ACTION(action) \
666 NULL, compose_set_encoding_cb, action, \
667 "/Options/Character encoding/Automatic"
669 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
670 {N_("/_Options/Character _encoding/_Automatic"),
671 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
672 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
674 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
675 ENC_ACTION(C_US_ASCII)},
676 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
677 ENC_ACTION(C_UTF_8)},
678 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
680 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
681 ENC_ACTION(C_ISO_8859_1)},
682 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
683 ENC_ACTION(C_ISO_8859_15)},
684 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
685 ENC_ACTION(C_WINDOWS_1252)},
686 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
688 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
689 ENC_ACTION(C_ISO_8859_2)},
690 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
692 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
693 ENC_ACTION(C_ISO_8859_13)},
694 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
695 ENC_ACTION(C_ISO_8859_4)},
696 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
698 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
699 ENC_ACTION(C_ISO_8859_7)},
700 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
702 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
703 ENC_ACTION(C_ISO_8859_8)},
704 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
705 ENC_ACTION(C_WINDOWS_1255)},
706 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
708 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
709 ENC_ACTION(C_ISO_8859_6)},
710 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
711 ENC_ACTION(C_CP1256)},
712 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
714 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
715 ENC_ACTION(C_ISO_8859_9)},
716 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
718 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
719 ENC_ACTION(C_ISO_8859_5)},
720 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
721 ENC_ACTION(C_KOI8_R)},
722 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
723 ENC_ACTION(C_KOI8_U)},
724 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
725 ENC_ACTION(C_WINDOWS_1251)},
726 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
728 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
729 ENC_ACTION(C_ISO_2022_JP)},
730 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
732 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
733 ENC_ACTION(C_GB2312)},
734 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
736 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
738 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
739 ENC_ACTION(C_EUC_TW)},
740 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
742 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
743 ENC_ACTION(C_EUC_KR)},
744 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
746 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
747 ENC_ACTION(C_TIS_620)},
748 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
749 ENC_ACTION(C_WINDOWS_874)},
751 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
752 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
753 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
754 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
755 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
756 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
757 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
760 static GtkTargetEntry compose_mime_types[] =
762 {"text/uri-list", 0, 0},
763 {"text/plain", 0, 0},
767 static gboolean compose_put_existing_to_front(MsgInfo *info)
769 GList *compose_list = compose_get_compose_list();
773 for (elem = compose_list; elem != NULL && elem->data != NULL;
775 Compose *c = (Compose*)elem->data;
777 if (!c->targetinfo || !c->targetinfo->msgid ||
781 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
782 gtkut_window_popup(c->window);
790 static GdkColor quote_color =
791 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
793 static GdkColor signature_color = {
800 static GdkColor uri_color = {
807 static void compose_create_tags(GtkTextView *text, Compose *compose)
809 GtkTextBuffer *buffer;
810 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
812 buffer = gtk_text_view_get_buffer(text);
814 if (prefs_common.enable_color) {
815 /* grab the quote colors, converting from an int to a GdkColor */
816 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
818 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
820 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
823 signature_color = quote_color = uri_color = black;
826 gtk_text_buffer_create_tag(buffer, "quote",
827 "foreground-gdk", "e_color,
829 gtk_text_buffer_create_tag(buffer, "signature",
830 "foreground-gdk", &signature_color,
832 gtk_text_buffer_create_tag(buffer, "link",
833 "foreground-gdk", &uri_color,
835 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
836 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
839 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
840 GPtrArray *attach_files)
842 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
845 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
847 return compose_generic_new(account, NULL, item, NULL, NULL);
850 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
852 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
855 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
856 GPtrArray *attach_files, GList *listAddress )
859 GtkTextView *textview;
860 GtkTextBuffer *textbuf;
862 GtkItemFactory *ifactory;
864 if (item && item->prefs && item->prefs->enable_default_account)
865 account = account_find_from_id(item->prefs->default_account);
867 if (!account) account = cur_account;
868 g_return_val_if_fail(account != NULL, NULL);
870 compose = compose_create(account, COMPOSE_NEW);
871 ifactory = gtk_item_factory_from_widget(compose->menubar);
873 compose->replyinfo = NULL;
874 compose->fwdinfo = NULL;
876 textview = GTK_TEXT_VIEW(compose->text);
877 textbuf = gtk_text_view_get_buffer(textview);
878 compose_create_tags(textview, compose);
880 undo_block(compose->undostruct);
882 if (item && item->prefs && item->prefs->enable_default_dictionary &&
884 gtkaspell_change_dict(compose->gtkaspell,
885 item->prefs->default_dictionary);
888 if (account->auto_sig)
889 compose_insert_sig(compose, FALSE);
890 gtk_text_buffer_get_start_iter(textbuf, &iter);
891 gtk_text_buffer_place_cursor(textbuf, &iter);
893 if (account->protocol != A_NNTP) {
894 if (mailto && *mailto != '\0') {
895 compose_entries_set(compose, mailto);
897 } else if (item && item->prefs->enable_default_to) {
898 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
899 compose_entry_mark_default_to(compose, item->prefs->default_to);
901 if (item && item->ret_rcpt) {
902 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
906 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
908 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
911 * CLAWS: just don't allow return receipt request, even if the user
912 * may want to send an email. simple but foolproof.
914 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
916 compose_add_field_list( compose, listAddress );
922 for (i = 0; i < attach_files->len; i++) {
923 file = g_ptr_array_index(attach_files, i);
924 compose_attach_append(compose, file, file, NULL);
928 compose_show_first_last_header(compose, TRUE);
930 /* Set save folder */
931 if (item && item->prefs && item->prefs->save_copy_to_folder) {
932 gchar *folderidentifier;
934 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
935 folderidentifier = folder_item_get_identifier(item);
936 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
937 g_free(folderidentifier);
940 gtk_widget_grab_focus(compose->header_last->entry);
942 undo_unblock(compose->undostruct);
944 if (prefs_common.auto_exteditor)
945 compose_exec_ext_editor(compose);
947 compose->modified = FALSE;
948 compose_set_title(compose);
952 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
953 gboolean override_pref)
955 gchar *privacy = NULL;
957 g_return_if_fail(compose != NULL);
958 g_return_if_fail(account != NULL);
960 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
963 if (account->default_privacy_system
964 && strlen(account->default_privacy_system)) {
965 privacy = account->default_privacy_system;
967 GSList *privacy_avail = privacy_get_system_ids();
968 if (privacy_avail && g_slist_length(privacy_avail)) {
969 privacy = (gchar *)(privacy_avail->data);
972 if (privacy != NULL) {
973 compose->privacy_system = g_strdup(privacy);
974 compose_update_privacy_system_menu_item(compose, FALSE);
975 compose_use_encryption(compose, TRUE);
979 static void compose_force_signing(Compose *compose, PrefsAccount *account)
981 gchar *privacy = NULL;
983 if (account->default_privacy_system
984 && strlen(account->default_privacy_system)) {
985 privacy = account->default_privacy_system;
987 GSList *privacy_avail = privacy_get_system_ids();
988 if (privacy_avail && g_slist_length(privacy_avail)) {
989 privacy = (gchar *)(privacy_avail->data);
992 if (privacy != NULL) {
993 compose->privacy_system = g_strdup(privacy);
994 compose_update_privacy_system_menu_item(compose, FALSE);
995 compose_use_signing(compose, TRUE);
999 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1003 Compose *compose = NULL;
1004 g_return_val_if_fail(msginfo_list != NULL, NULL);
1006 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1007 g_return_val_if_fail(msginfo != NULL, NULL);
1009 list_len = g_slist_length(msginfo_list);
1013 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1014 FALSE, prefs_common.default_reply_list, FALSE, body);
1016 case COMPOSE_REPLY_WITH_QUOTE:
1017 compose = compose_reply(msginfo, TRUE,
1018 FALSE, prefs_common.default_reply_list, FALSE, body);
1020 case COMPOSE_REPLY_WITHOUT_QUOTE:
1021 compose = compose_reply(msginfo, FALSE,
1022 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1024 case COMPOSE_REPLY_TO_SENDER:
1025 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1026 FALSE, FALSE, TRUE, body);
1028 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1029 compose = compose_followup_and_reply_to(msginfo,
1030 prefs_common.reply_with_quote,
1031 FALSE, FALSE, body);
1033 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1034 compose = compose_reply(msginfo, TRUE,
1035 FALSE, FALSE, TRUE, body);
1037 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1038 compose = compose_reply(msginfo, FALSE,
1039 FALSE, FALSE, TRUE, NULL);
1041 case COMPOSE_REPLY_TO_ALL:
1042 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1043 TRUE, FALSE, FALSE, body);
1045 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1046 compose = compose_reply(msginfo, TRUE,
1047 TRUE, FALSE, FALSE, body);
1049 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1050 compose = compose_reply(msginfo, FALSE,
1051 TRUE, FALSE, FALSE, NULL);
1053 case COMPOSE_REPLY_TO_LIST:
1054 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1055 FALSE, TRUE, FALSE, body);
1057 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1058 compose = compose_reply(msginfo, TRUE,
1059 FALSE, TRUE, FALSE, body);
1061 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1062 compose = compose_reply(msginfo, FALSE,
1063 FALSE, TRUE, FALSE, NULL);
1065 case COMPOSE_FORWARD:
1066 if (prefs_common.forward_as_attachment) {
1067 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1070 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1074 case COMPOSE_FORWARD_INLINE:
1075 /* check if we reply to more than one Message */
1076 if (list_len == 1) {
1077 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1080 /* more messages FALL THROUGH */
1081 case COMPOSE_FORWARD_AS_ATTACH:
1082 compose = compose_forward_multiple(NULL, msginfo_list);
1084 case COMPOSE_REDIRECT:
1085 compose = compose_redirect(NULL, msginfo);
1088 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1093 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1094 gboolean to_ml, gboolean to_sender,
1097 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1098 to_sender, FALSE, body);
1101 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1106 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1107 to_sender, TRUE, body);
1110 static void compose_extract_original_charset(Compose *compose)
1112 MsgInfo *info = NULL;
1113 if (compose->replyinfo) {
1114 info = compose->replyinfo;
1115 } else if (compose->fwdinfo) {
1116 info = compose->fwdinfo;
1117 } else if (compose->targetinfo) {
1118 info = compose->targetinfo;
1121 MimeInfo *mimeinfo = procmime_scan_message(info);
1122 MimeInfo *partinfo = mimeinfo;
1123 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1124 partinfo = procmime_mimeinfo_next(partinfo);
1126 compose->orig_charset =
1127 g_strdup(procmime_mimeinfo_get_parameter(
1128 partinfo, "charset"));
1130 procmime_mimeinfo_free_all(mimeinfo);
1134 #define SIGNAL_BLOCK(buffer) { \
1135 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1136 G_CALLBACK(compose_changed_cb), \
1138 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1139 G_CALLBACK(text_inserted), \
1143 #define SIGNAL_UNBLOCK(buffer) { \
1144 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1145 G_CALLBACK(compose_changed_cb), \
1147 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1148 G_CALLBACK(text_inserted), \
1152 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1153 gboolean to_all, gboolean to_ml,
1155 gboolean followup_and_reply_to,
1158 GtkItemFactory *ifactory;
1160 PrefsAccount *account = NULL;
1161 PrefsAccount *reply_account;
1162 GtkTextView *textview;
1163 GtkTextBuffer *textbuf;
1165 g_return_val_if_fail(msginfo != NULL, NULL);
1166 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1168 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1170 g_return_val_if_fail(account != NULL, NULL);
1172 if (to_sender && account->protocol == A_NNTP &&
1173 !followup_and_reply_to) {
1175 account_find_from_address(account->address);
1177 reply_account = compose_current_mail_account();
1181 reply_account = account;
1183 compose = compose_create(account, COMPOSE_REPLY);
1184 ifactory = gtk_item_factory_from_widget(compose->menubar);
1186 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1187 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1189 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1191 if (!compose->replyinfo)
1192 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1194 compose_extract_original_charset(compose);
1196 if (msginfo->folder && msginfo->folder->ret_rcpt)
1197 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1199 /* Set save folder */
1200 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1201 gchar *folderidentifier;
1203 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1204 folderidentifier = folder_item_get_identifier(msginfo->folder);
1205 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1206 g_free(folderidentifier);
1209 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1210 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1211 to_sender, followup_and_reply_to);
1212 compose_show_first_last_header(compose, TRUE);
1214 textview = (GTK_TEXT_VIEW(compose->text));
1215 textbuf = gtk_text_view_get_buffer(textview);
1216 compose_create_tags(textview, compose);
1218 undo_block(compose->undostruct);
1220 if (msginfo->folder && msginfo->folder->prefs &&
1221 msginfo->folder->prefs &&
1222 msginfo->folder->prefs->enable_default_dictionary &&
1224 gtkaspell_change_dict(compose->gtkaspell,
1225 msginfo->folder->prefs->default_dictionary);
1231 if (prefs_common.quotemark && *prefs_common.quotemark)
1232 qmark = prefs_common.quotemark;
1236 compose_quote_fmt(compose, compose->replyinfo,
1237 prefs_common.quotefmt,
1238 qmark, body, FALSE);
1240 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1241 compose_force_encryption(compose, account, FALSE);
1244 SIGNAL_BLOCK(textbuf);
1246 if (account->auto_sig)
1247 compose_insert_sig(compose, FALSE);
1249 compose_wrap_all(compose);
1251 SIGNAL_UNBLOCK(textbuf);
1253 gtk_widget_grab_focus(compose->text);
1255 undo_unblock(compose->undostruct);
1257 if (prefs_common.auto_exteditor)
1258 compose_exec_ext_editor(compose);
1260 compose->modified = FALSE;
1261 compose_set_title(compose);
1265 #define INSERT_FW_HEADER(var, hdr) \
1266 if (msginfo->var && *msginfo->var) { \
1267 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1268 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1269 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1272 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1273 gboolean as_attach, const gchar *body,
1274 gboolean no_extedit)
1277 GtkTextView *textview;
1278 GtkTextBuffer *textbuf;
1281 g_return_val_if_fail(msginfo != NULL, NULL);
1282 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1285 !(account = compose_guess_forward_account_from_msginfo
1287 account = cur_account;
1289 compose = compose_create(account, COMPOSE_FORWARD);
1291 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1292 if (!compose->fwdinfo)
1293 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1295 compose_extract_original_charset(compose);
1297 if (msginfo->subject && *msginfo->subject) {
1298 gchar *buf, *buf2, *p;
1300 buf = p = g_strdup(msginfo->subject);
1301 p += subject_get_prefix_length(p);
1302 memmove(buf, p, strlen(p) + 1);
1304 buf2 = g_strdup_printf("Fw: %s", buf);
1305 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1311 textview = GTK_TEXT_VIEW(compose->text);
1312 textbuf = gtk_text_view_get_buffer(textview);
1313 compose_create_tags(textview, compose);
1315 undo_block(compose->undostruct);
1319 msgfile = procmsg_get_message_file_path(msginfo);
1320 if (!is_file_exist(msgfile))
1321 g_warning("%s: file not exist\n", msgfile);
1323 compose_attach_append(compose, msgfile, msgfile,
1329 MsgInfo *full_msginfo;
1331 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1333 full_msginfo = procmsg_msginfo_copy(msginfo);
1335 if (prefs_common.fw_quotemark &&
1336 *prefs_common.fw_quotemark)
1337 qmark = prefs_common.fw_quotemark;
1341 compose_quote_fmt(compose, full_msginfo,
1342 prefs_common.fw_quotefmt,
1343 qmark, body, FALSE);
1344 compose_attach_parts(compose, msginfo);
1346 procmsg_msginfo_free(full_msginfo);
1349 SIGNAL_BLOCK(textbuf);
1351 if (account->auto_sig)
1352 compose_insert_sig(compose, FALSE);
1354 compose_wrap_all(compose);
1356 SIGNAL_UNBLOCK(textbuf);
1358 gtk_text_buffer_get_start_iter(textbuf, &iter);
1359 gtk_text_buffer_place_cursor(textbuf, &iter);
1361 gtk_widget_grab_focus(compose->header_last->entry);
1363 if (!no_extedit && prefs_common.auto_exteditor)
1364 compose_exec_ext_editor(compose);
1367 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1368 gchar *folderidentifier;
1370 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1371 folderidentifier = folder_item_get_identifier(msginfo->folder);
1372 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1373 g_free(folderidentifier);
1376 undo_unblock(compose->undostruct);
1378 compose->modified = FALSE;
1379 compose_set_title(compose);
1383 #undef INSERT_FW_HEADER
1385 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1388 GtkTextView *textview;
1389 GtkTextBuffer *textbuf;
1393 gboolean single_mail = TRUE;
1395 g_return_val_if_fail(msginfo_list != NULL, NULL);
1397 if (g_slist_length(msginfo_list) > 1)
1398 single_mail = FALSE;
1400 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1401 if (((MsgInfo *)msginfo->data)->folder == NULL)
1404 /* guess account from first selected message */
1406 !(account = compose_guess_forward_account_from_msginfo
1407 (msginfo_list->data)))
1408 account = cur_account;
1410 g_return_val_if_fail(account != NULL, NULL);
1412 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1413 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1414 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1417 compose = compose_create(account, COMPOSE_FORWARD);
1419 textview = GTK_TEXT_VIEW(compose->text);
1420 textbuf = gtk_text_view_get_buffer(textview);
1421 compose_create_tags(textview, compose);
1423 undo_block(compose->undostruct);
1424 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1425 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1426 if (!is_file_exist(msgfile))
1427 g_warning("%s: file not exist\n", msgfile);
1429 compose_attach_append(compose, msgfile, msgfile,
1435 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1436 if (info->subject && *info->subject) {
1437 gchar *buf, *buf2, *p;
1439 buf = p = g_strdup(info->subject);
1440 p += subject_get_prefix_length(p);
1441 memmove(buf, p, strlen(p) + 1);
1443 buf2 = g_strdup_printf("Fw: %s", buf);
1444 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1450 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1451 _("Fw: multiple emails"));
1454 SIGNAL_BLOCK(textbuf);
1456 if (account->auto_sig)
1457 compose_insert_sig(compose, FALSE);
1459 compose_wrap_all(compose);
1461 SIGNAL_UNBLOCK(textbuf);
1463 gtk_text_buffer_get_start_iter(textbuf, &iter);
1464 gtk_text_buffer_place_cursor(textbuf, &iter);
1466 gtk_widget_grab_focus(compose->header_last->entry);
1467 undo_unblock(compose->undostruct);
1468 compose->modified = FALSE;
1469 compose_set_title(compose);
1473 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1475 GtkTextIter start = *iter;
1476 GtkTextIter end_iter;
1477 int start_pos = gtk_text_iter_get_offset(&start);
1479 if (!compose->account->sig_sep)
1482 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1483 start_pos+strlen(compose->account->sig_sep));
1485 /* check sig separator */
1486 str = gtk_text_iter_get_text(&start, &end_iter);
1487 if (!strcmp(str, compose->account->sig_sep)) {
1489 /* check end of line (\n) */
1490 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1491 start_pos+strlen(compose->account->sig_sep));
1492 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1493 start_pos+strlen(compose->account->sig_sep)+1);
1494 tmp = gtk_text_iter_get_text(&start, &end_iter);
1495 if (!strcmp(tmp,"\n")) {
1507 static void compose_colorize_signature(Compose *compose)
1509 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1511 GtkTextIter end_iter;
1512 gtk_text_buffer_get_start_iter(buffer, &iter);
1513 while (gtk_text_iter_forward_line(&iter))
1514 if (compose_is_sig_separator(compose, buffer, &iter)) {
1515 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1516 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1520 void compose_reedit(MsgInfo *msginfo)
1522 Compose *compose = NULL;
1523 PrefsAccount *account = NULL;
1524 GtkTextView *textview;
1525 GtkTextBuffer *textbuf;
1529 gchar buf[BUFFSIZE];
1530 gboolean use_signing = FALSE;
1531 gboolean use_encryption = FALSE;
1532 gchar *privacy_system = NULL;
1534 g_return_if_fail(msginfo != NULL);
1535 g_return_if_fail(msginfo->folder != NULL);
1537 if (compose_put_existing_to_front(msginfo))
1540 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1541 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1542 gchar queueheader_buf[BUFFSIZE];
1545 /* Select Account from queue headers */
1546 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1547 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1548 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1549 account = account_find_from_id(id);
1551 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1552 sizeof(queueheader_buf), "NAID:")) {
1553 id = atoi(&queueheader_buf[strlen("NAID:")]);
1554 account = account_find_from_id(id);
1556 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1557 sizeof(queueheader_buf), "MAID:")) {
1558 id = atoi(&queueheader_buf[strlen("MAID:")]);
1559 account = account_find_from_id(id);
1561 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1562 sizeof(queueheader_buf), "S:")) {
1563 account = account_find_from_address(queueheader_buf);
1565 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1566 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1567 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1568 use_signing = param;
1571 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1572 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1573 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1574 use_encryption = param;
1576 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1577 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1578 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1580 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1581 sizeof(queueheader_buf), "X-Priority: ")) {
1582 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1583 compose->priority = param;
1586 account = msginfo->folder->folder->account;
1588 if (!account && prefs_common.reedit_account_autosel) {
1589 gchar from[BUFFSIZE];
1590 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1591 extract_address(from);
1592 account = account_find_from_address(from);
1595 if (!account) account = cur_account;
1596 g_return_if_fail(account != NULL);
1598 compose = compose_create(account, COMPOSE_REEDIT);
1599 if (privacy_system != NULL) {
1600 compose->privacy_system = privacy_system;
1601 compose_use_signing(compose, use_signing);
1602 compose_use_encryption(compose, use_encryption);
1603 compose_update_privacy_system_menu_item(compose, FALSE);
1605 activate_privacy_system(compose, account, FALSE);
1607 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1609 compose_extract_original_charset(compose);
1611 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1612 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1613 gchar queueheader_buf[BUFFSIZE];
1615 /* Set message save folder */
1616 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1619 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1620 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1621 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1623 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1624 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1626 GtkItemFactory *ifactory;
1627 ifactory = gtk_item_factory_from_widget(compose->menubar);
1628 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1633 if (compose_parse_header(compose, msginfo) < 0) return;
1634 compose_reedit_set_entry(compose, msginfo);
1636 textview = GTK_TEXT_VIEW(compose->text);
1637 textbuf = gtk_text_view_get_buffer(textview);
1638 compose_create_tags(textview, compose);
1640 mark = gtk_text_buffer_get_insert(textbuf);
1641 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1643 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1644 G_CALLBACK(compose_changed_cb),
1647 if (procmime_msginfo_is_encrypted(msginfo)) {
1648 fp = procmime_get_first_encrypted_text_content(msginfo);
1650 compose_force_encryption(compose, account, TRUE);
1652 fp = procmime_get_first_text_content(msginfo);
1654 g_warning("Can't get text part\n");
1657 gboolean prev_autowrap = compose->autowrap;
1659 compose->autowrap = FALSE;
1660 while (fgets(buf, sizeof(buf), fp) != NULL) {
1662 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1664 compose_wrap_all_full(compose, FALSE);
1665 compose->autowrap = prev_autowrap;
1669 compose_attach_parts(compose, msginfo);
1671 compose_colorize_signature(compose);
1673 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1674 G_CALLBACK(compose_changed_cb),
1677 gtk_widget_grab_focus(compose->text);
1679 if (prefs_common.auto_exteditor)
1680 compose_exec_ext_editor(compose);
1681 compose->modified = FALSE;
1682 compose_set_title(compose);
1685 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1689 GtkItemFactory *ifactory;
1692 g_return_val_if_fail(msginfo != NULL, NULL);
1695 account = account_get_reply_account(msginfo,
1696 prefs_common.reply_account_autosel);
1697 g_return_val_if_fail(account != NULL, NULL);
1699 compose = compose_create(account, COMPOSE_REDIRECT);
1700 ifactory = gtk_item_factory_from_widget(compose->menubar);
1701 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1702 compose->replyinfo = NULL;
1703 compose->fwdinfo = NULL;
1705 compose_show_first_last_header(compose, TRUE);
1707 gtk_widget_grab_focus(compose->header_last->entry);
1709 filename = procmsg_get_message_file_path(msginfo);
1710 if (filename == NULL)
1713 compose->redirect_filename = filename;
1715 /* Set save folder */
1716 item = msginfo->folder;
1717 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1718 gchar *folderidentifier;
1720 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1721 folderidentifier = folder_item_get_identifier(item);
1722 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1723 g_free(folderidentifier);
1726 compose_attach_parts(compose, msginfo);
1728 if (msginfo->subject)
1729 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1731 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1733 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1734 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1736 compose_colorize_signature(compose);
1738 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1739 menu_set_sensitive(ifactory, "/Add...", FALSE);
1740 menu_set_sensitive(ifactory, "/Remove", FALSE);
1741 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1743 ifactory = gtk_item_factory_from_widget(compose->menubar);
1744 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1745 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1746 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1747 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1748 menu_set_sensitive(ifactory, "/Edit", FALSE);
1749 menu_set_sensitive(ifactory, "/Options", FALSE);
1750 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1751 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1753 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1754 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1755 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1756 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1757 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1758 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1759 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1761 compose->modified = FALSE;
1762 compose_set_title(compose);
1766 GList *compose_get_compose_list(void)
1768 return compose_list;
1771 void compose_entry_append(Compose *compose, const gchar *address,
1772 ComposeEntryType type)
1776 gboolean in_quote = FALSE;
1777 if (!address || *address == '\0') return;
1784 header = N_("Bcc:");
1786 case COMPOSE_REPLYTO:
1787 header = N_("Reply-To:");
1789 case COMPOSE_NEWSGROUPS:
1790 header = N_("Newsgroups:");
1792 case COMPOSE_FOLLOWUPTO:
1793 header = N_( "Followup-To:");
1800 header = prefs_common.trans_hdr ? gettext(header) : header;
1802 cur = begin = (gchar *)address;
1804 /* we separate the line by commas, but not if we're inside a quoted
1806 while (*cur != '\0') {
1808 in_quote = !in_quote;
1809 if (*cur == ',' && !in_quote) {
1810 gchar *tmp = g_strdup(begin);
1812 tmp[cur-begin]='\0';
1817 compose_add_header_entry(compose, header, tmp);
1824 gchar *tmp = g_strdup(begin);
1826 tmp[cur-begin]='\0';
1831 compose_add_header_entry(compose, header, tmp);
1836 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1838 static GdkColor yellow;
1839 static GdkColor black;
1840 static gboolean yellow_initialised = FALSE;
1844 if (!yellow_initialised) {
1845 gdk_color_parse("#f5f6be", &yellow);
1846 gdk_color_parse("#000000", &black);
1847 yellow_initialised = gdk_colormap_alloc_color(
1848 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
1849 yellow_initialised &= gdk_colormap_alloc_color(
1850 gdk_colormap_get_system(), &black, FALSE, TRUE);
1853 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1854 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1855 if (gtk_entry_get_text(entry) &&
1856 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1857 if (yellow_initialised) {
1858 gtk_widget_modify_base(
1859 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1860 GTK_STATE_NORMAL, &yellow);
1861 gtk_widget_modify_text(
1862 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1863 GTK_STATE_NORMAL, &black);
1869 void compose_toolbar_cb(gint action, gpointer data)
1871 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1872 Compose *compose = (Compose*)toolbar_item->parent;
1874 g_return_if_fail(compose != NULL);
1878 compose_send_cb(compose, 0, NULL);
1881 compose_send_later_cb(compose, 0, NULL);
1884 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1887 compose_insert_file_cb(compose, 0, NULL);
1890 compose_attach_cb(compose, 0, NULL);
1893 compose_insert_sig(compose, FALSE);
1896 compose_ext_editor_cb(compose, 0, NULL);
1898 case A_LINEWRAP_CURRENT:
1899 compose_beautify_paragraph(compose, NULL, TRUE);
1901 case A_LINEWRAP_ALL:
1902 compose_wrap_all_full(compose, TRUE);
1905 compose_address_cb(compose, 0, NULL);
1908 case A_CHECK_SPELLING:
1909 compose_check_all(compose);
1917 static void compose_entries_set(Compose *compose, const gchar *mailto)
1921 gchar *subject = NULL;
1926 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1929 compose_entry_append(compose, to, COMPOSE_TO);
1931 compose_entry_append(compose, cc, COMPOSE_CC);
1933 if (!g_utf8_validate (subject, -1, NULL)) {
1934 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1935 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1938 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1942 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1943 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1946 gboolean prev_autowrap = compose->autowrap;
1948 compose->autowrap = FALSE;
1950 mark = gtk_text_buffer_get_insert(buffer);
1951 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1953 if (!g_utf8_validate (body, -1, NULL)) {
1954 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1955 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1958 gtk_text_buffer_insert(buffer, &iter, body, -1);
1960 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1962 compose->autowrap = prev_autowrap;
1963 if (compose->autowrap)
1964 compose_wrap_all(compose);
1973 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1975 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1976 {"Cc:", NULL, TRUE},
1977 {"References:", NULL, FALSE},
1978 {"Bcc:", NULL, TRUE},
1979 {"Newsgroups:", NULL, TRUE},
1980 {"Followup-To:", NULL, TRUE},
1981 {"List-Post:", NULL, FALSE},
1982 {"X-Priority:", NULL, FALSE},
1983 {NULL, NULL, FALSE}};
1999 g_return_val_if_fail(msginfo != NULL, -1);
2001 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2002 procheader_get_header_fields(fp, hentry);
2005 if (hentry[H_REPLY_TO].body != NULL) {
2006 if (hentry[H_REPLY_TO].body[0] != '\0') {
2008 conv_unmime_header(hentry[H_REPLY_TO].body,
2011 g_free(hentry[H_REPLY_TO].body);
2012 hentry[H_REPLY_TO].body = NULL;
2014 if (hentry[H_CC].body != NULL) {
2015 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2016 g_free(hentry[H_CC].body);
2017 hentry[H_CC].body = NULL;
2019 if (hentry[H_REFERENCES].body != NULL) {
2020 if (compose->mode == COMPOSE_REEDIT)
2021 compose->references = hentry[H_REFERENCES].body;
2023 compose->references = compose_parse_references
2024 (hentry[H_REFERENCES].body, msginfo->msgid);
2025 g_free(hentry[H_REFERENCES].body);
2027 hentry[H_REFERENCES].body = NULL;
2029 if (hentry[H_BCC].body != NULL) {
2030 if (compose->mode == COMPOSE_REEDIT)
2032 conv_unmime_header(hentry[H_BCC].body, NULL);
2033 g_free(hentry[H_BCC].body);
2034 hentry[H_BCC].body = NULL;
2036 if (hentry[H_NEWSGROUPS].body != NULL) {
2037 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2038 hentry[H_NEWSGROUPS].body = NULL;
2040 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2041 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2042 compose->followup_to =
2043 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2046 g_free(hentry[H_FOLLOWUP_TO].body);
2047 hentry[H_FOLLOWUP_TO].body = NULL;
2049 if (hentry[H_LIST_POST].body != NULL) {
2052 extract_address(hentry[H_LIST_POST].body);
2053 if (hentry[H_LIST_POST].body[0] != '\0') {
2054 scan_mailto_url(hentry[H_LIST_POST].body,
2055 &to, NULL, NULL, NULL, NULL);
2057 g_free(compose->ml_post);
2058 compose->ml_post = to;
2061 g_free(hentry[H_LIST_POST].body);
2062 hentry[H_LIST_POST].body = NULL;
2065 /* CLAWS - X-Priority */
2066 if (compose->mode == COMPOSE_REEDIT)
2067 if (hentry[H_X_PRIORITY].body != NULL) {
2070 priority = atoi(hentry[H_X_PRIORITY].body);
2071 g_free(hentry[H_X_PRIORITY].body);
2073 hentry[H_X_PRIORITY].body = NULL;
2075 if (priority < PRIORITY_HIGHEST ||
2076 priority > PRIORITY_LOWEST)
2077 priority = PRIORITY_NORMAL;
2079 compose->priority = priority;
2082 if (compose->mode == COMPOSE_REEDIT) {
2083 if (msginfo->inreplyto && *msginfo->inreplyto)
2084 compose->inreplyto = g_strdup(msginfo->inreplyto);
2088 if (msginfo->msgid && *msginfo->msgid)
2089 compose->inreplyto = g_strdup(msginfo->msgid);
2091 if (!compose->references) {
2092 if (msginfo->msgid && *msginfo->msgid) {
2093 if (msginfo->inreplyto && *msginfo->inreplyto)
2094 compose->references =
2095 g_strdup_printf("<%s>\n\t<%s>",
2099 compose->references =
2100 g_strconcat("<", msginfo->msgid, ">",
2102 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2103 compose->references =
2104 g_strconcat("<", msginfo->inreplyto, ">",
2112 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2114 GSList *ref_id_list, *cur;
2118 ref_id_list = references_list_append(NULL, ref);
2119 if (!ref_id_list) return NULL;
2120 if (msgid && *msgid)
2121 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2126 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2127 /* "<" + Message-ID + ">" + CR+LF+TAB */
2128 len += strlen((gchar *)cur->data) + 5;
2130 if (len > MAX_REFERENCES_LEN) {
2131 /* remove second message-ID */
2132 if (ref_id_list && ref_id_list->next &&
2133 ref_id_list->next->next) {
2134 g_free(ref_id_list->next->data);
2135 ref_id_list = g_slist_remove
2136 (ref_id_list, ref_id_list->next->data);
2138 slist_free_strings(ref_id_list);
2139 g_slist_free(ref_id_list);
2146 new_ref = g_string_new("");
2147 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2148 if (new_ref->len > 0)
2149 g_string_append(new_ref, "\n\t");
2150 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2153 slist_free_strings(ref_id_list);
2154 g_slist_free(ref_id_list);
2156 new_ref_str = new_ref->str;
2157 g_string_free(new_ref, FALSE);
2162 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2163 const gchar *fmt, const gchar *qmark,
2164 const gchar *body, gboolean rewrap)
2166 static MsgInfo dummyinfo;
2167 gchar *quote_str = NULL;
2169 gboolean prev_autowrap;
2170 const gchar *trimmed_body = body;
2171 gint cursor_pos = -1;
2172 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2173 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2178 SIGNAL_BLOCK(buffer);
2181 msginfo = &dummyinfo;
2183 if (qmark != NULL) {
2184 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2185 quote_fmt_scan_string(qmark);
2188 buf = quote_fmt_get_buffer();
2190 alertpanel_error(_("Quote mark format error."));
2192 Xstrdup_a(quote_str, buf, goto error)
2195 if (fmt && *fmt != '\0') {
2196 while (trimmed_body && strlen(trimmed_body) > 1
2197 && trimmed_body[0]=='\n')
2200 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2201 quote_fmt_scan_string(fmt);
2204 buf = quote_fmt_get_buffer();
2206 alertpanel_error(_("Message reply/forward format error."));
2212 prev_autowrap = compose->autowrap;
2213 compose->autowrap = FALSE;
2215 mark = gtk_text_buffer_get_insert(buffer);
2216 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2217 if (g_utf8_validate(buf, -1, NULL)) {
2218 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2220 gchar *tmpout = NULL;
2221 tmpout = conv_codeset_strdup
2222 (buf, conv_get_locale_charset_str(),
2224 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2226 tmpout = g_malloc(strlen(buf)*2+1);
2227 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2229 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2233 cursor_pos = quote_fmt_get_cursor_pos();
2234 compose->set_cursor_pos = cursor_pos;
2235 if (cursor_pos == -1) {
2238 gtk_text_buffer_get_start_iter(buffer, &iter);
2239 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2240 gtk_text_buffer_place_cursor(buffer, &iter);
2242 compose->autowrap = prev_autowrap;
2243 if (compose->autowrap && rewrap)
2244 compose_wrap_all(compose);
2251 SIGNAL_UNBLOCK(buffer);
2257 /* if ml_post is of type addr@host and from is of type
2258 * addr-anything@host, return TRUE
2260 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2262 gchar *left_ml = NULL;
2263 gchar *right_ml = NULL;
2264 gchar *left_from = NULL;
2265 gchar *right_from = NULL;
2266 gboolean result = FALSE;
2268 if (!ml_post || !from)
2271 left_ml = g_strdup(ml_post);
2272 if (strstr(left_ml, "@")) {
2273 right_ml = strstr(left_ml, "@")+1;
2274 *(strstr(left_ml, "@")) = '\0';
2277 left_from = g_strdup(from);
2278 if (strstr(left_from, "@")) {
2279 right_from = strstr(left_from, "@")+1;
2280 *(strstr(left_from, "@")) = '\0';
2283 if (left_ml && left_from && right_ml && right_from
2284 && !strncmp(left_from, left_ml, strlen(left_ml))
2285 && !strcmp(right_from, right_ml)) {
2294 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2296 gchar *my_addr1, *my_addr2;
2298 if (!addr1 || !addr2)
2301 Xstrdup_a(my_addr1, addr1, return FALSE);
2302 Xstrdup_a(my_addr2, addr2, return FALSE);
2304 extract_address(my_addr1);
2305 extract_address(my_addr2);
2307 return !strcmp(my_addr1, my_addr2);
2310 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2311 gboolean to_all, gboolean to_ml,
2313 gboolean followup_and_reply_to)
2315 GSList *cc_list = NULL;
2318 gchar *replyto = NULL;
2319 GHashTable *to_table;
2321 gboolean reply_to_ml = FALSE;
2322 gboolean default_reply_to = FALSE;
2324 g_return_if_fail(compose->account != NULL);
2325 g_return_if_fail(msginfo != NULL);
2327 reply_to_ml = to_ml && compose->ml_post;
2329 default_reply_to = msginfo->folder &&
2330 msginfo->folder->prefs->enable_default_reply_to;
2332 if (compose->account->protocol != A_NNTP) {
2333 if (reply_to_ml && !default_reply_to) {
2335 gboolean is_subscr = is_subscription(compose->ml_post,
2338 /* normal answer to ml post with a reply-to */
2339 compose_entry_append(compose,
2342 if (compose->replyto
2343 && !same_address(compose->ml_post, compose->replyto))
2344 compose_entry_append(compose,
2348 /* answer to subscription confirmation */
2349 if (compose->replyto)
2350 compose_entry_append(compose,
2353 else if (msginfo->from)
2354 compose_entry_append(compose,
2359 else if (!(to_all || to_sender) && default_reply_to) {
2360 compose_entry_append(compose,
2361 msginfo->folder->prefs->default_reply_to,
2363 compose_entry_mark_default_to(compose,
2364 msginfo->folder->prefs->default_reply_to);
2367 Xstrdup_a(tmp1, msginfo->from, return);
2368 extract_address(tmp1);
2369 if (to_all || to_sender ||
2370 !account_find_from_address(tmp1))
2371 compose_entry_append(compose,
2372 (compose->replyto && !to_sender)
2373 ? compose->replyto :
2374 msginfo->from ? msginfo->from : "",
2376 else if (!to_all && !to_sender) {
2377 /* reply to the last list of recipients */
2378 compose_entry_append(compose,
2379 msginfo->to ? msginfo->to : "",
2381 compose_entry_append(compose,
2382 msginfo->cc ? msginfo->cc : "",
2387 if (to_sender || (compose->followup_to &&
2388 !strncmp(compose->followup_to, "poster", 6)))
2389 compose_entry_append
2391 (compose->replyto ? compose->replyto :
2392 msginfo->from ? msginfo->from : ""),
2395 else if (followup_and_reply_to || to_all) {
2396 compose_entry_append
2398 (compose->replyto ? compose->replyto :
2399 msginfo->from ? msginfo->from : ""),
2402 compose_entry_append
2404 compose->followup_to ? compose->followup_to :
2405 compose->newsgroups ? compose->newsgroups : "",
2406 COMPOSE_NEWSGROUPS);
2409 compose_entry_append
2411 compose->followup_to ? compose->followup_to :
2412 compose->newsgroups ? compose->newsgroups : "",
2413 COMPOSE_NEWSGROUPS);
2416 if (msginfo->subject && *msginfo->subject) {
2420 buf = p = g_strdup(msginfo->subject);
2421 p += subject_get_prefix_length(p);
2422 memmove(buf, p, strlen(p) + 1);
2424 buf2 = g_strdup_printf("Re: %s", buf);
2425 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2430 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2432 if (to_ml && compose->ml_post) return;
2433 if (!to_all || compose->account->protocol == A_NNTP) return;
2435 if (compose->replyto) {
2436 Xstrdup_a(replyto, compose->replyto, return);
2437 extract_address(replyto);
2439 if (msginfo->from) {
2440 Xstrdup_a(from, msginfo->from, return);
2441 extract_address(from);
2444 if (replyto && from)
2445 cc_list = address_list_append_with_comments(cc_list, from);
2446 if (to_all && msginfo->folder &&
2447 msginfo->folder->prefs->enable_default_reply_to)
2448 cc_list = address_list_append_with_comments(cc_list,
2449 msginfo->folder->prefs->default_reply_to);
2450 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2451 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2453 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2455 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2456 if (compose->account)
2457 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2458 GINT_TO_POINTER(1));
2460 /* remove address on To: and that of current account */
2461 for (cur = cc_list; cur != NULL; ) {
2462 GSList *next = cur->next;
2465 addr = g_strdup(cur->data);
2466 extract_address(addr);
2468 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2469 cc_list = g_slist_remove(cc_list, cur->data);
2471 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2475 hash_free_strings(to_table);
2476 g_hash_table_destroy(to_table);
2479 for (cur = cc_list; cur != NULL; cur = cur->next)
2480 compose_entry_append(compose, (gchar *)cur->data,
2482 slist_free_strings(cc_list);
2483 g_slist_free(cc_list);
2488 #define SET_ENTRY(entry, str) \
2491 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2494 #define SET_ADDRESS(type, str) \
2497 compose_entry_append(compose, str, type); \
2500 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2502 g_return_if_fail(msginfo != NULL);
2504 SET_ENTRY(subject_entry, msginfo->subject);
2505 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2506 SET_ADDRESS(COMPOSE_CC, compose->cc);
2507 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2508 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2509 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2510 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2512 compose_update_priority_menu_item(compose);
2513 compose_update_privacy_system_menu_item(compose, FALSE);
2514 compose_show_first_last_header(compose, TRUE);
2520 static void compose_insert_sig(Compose *compose, gboolean replace)
2522 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2523 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2525 GtkTextIter iter, iter_end;
2527 gboolean prev_autowrap;
2530 g_return_if_fail(compose->account != NULL);
2532 prev_autowrap = compose->autowrap;
2533 compose->autowrap = FALSE;
2535 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2536 G_CALLBACK(compose_changed_cb),
2539 mark = gtk_text_buffer_get_insert(buffer);
2540 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2541 cur_pos = gtk_text_iter_get_offset (&iter);
2543 gtk_text_buffer_get_end_iter(buffer, &iter);
2545 if (replace && compose->sig_str) {
2547 GtkTextIter first_iter, start_iter, end_iter;
2549 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2551 if (compose->sig_str[0] == '\0')
2554 found = gtk_text_iter_forward_search(&first_iter,
2556 GTK_TEXT_SEARCH_TEXT_ONLY,
2557 &start_iter, &end_iter,
2561 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2566 g_free(compose->sig_str);
2567 compose->sig_str = compose_get_signature_str(compose);
2568 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2569 compose->sig_str = g_strdup("");
2571 cur_pos = gtk_text_iter_get_offset(&iter);
2572 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2574 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2575 gtk_text_iter_forward_char(&iter);
2576 gtk_text_iter_forward_char(&iter);
2577 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2578 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2580 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2581 cur_pos = gtk_text_buffer_get_char_count (buffer);
2583 /* put the cursor where it should be
2584 * either where the quote_fmt says, either before the signature */
2585 if (compose->set_cursor_pos < 0)
2586 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2588 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2589 compose->set_cursor_pos);
2591 gtk_text_buffer_place_cursor(buffer, &iter);
2592 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2593 G_CALLBACK(compose_changed_cb),
2596 compose->autowrap = prev_autowrap;
2597 if (compose->autowrap)
2598 compose_wrap_all(compose);
2601 static gchar *compose_get_signature_str(Compose *compose)
2603 gchar *sig_body = NULL;
2604 gchar *sig_str = NULL;
2605 gchar *utf8_sig_str = NULL;
2607 g_return_val_if_fail(compose->account != NULL, NULL);
2609 if (!compose->account->sig_path)
2612 if (compose->account->sig_type == SIG_FILE) {
2613 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2614 g_warning("can't open signature file: %s\n",
2615 compose->account->sig_path);
2620 if (compose->account->sig_type == SIG_COMMAND)
2621 sig_body = get_command_output(compose->account->sig_path);
2625 tmp = file_read_to_str(compose->account->sig_path);
2628 sig_body = normalize_newlines(tmp);
2632 if (compose->account->sig_sep) {
2633 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2637 sig_str = g_strconcat("\n\n", sig_body, NULL);
2640 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2641 utf8_sig_str = sig_str;
2643 utf8_sig_str = conv_codeset_strdup
2644 (sig_str, conv_get_locale_charset_str(),
2650 return utf8_sig_str;
2653 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2656 GtkTextBuffer *buffer;
2659 const gchar *cur_encoding;
2660 gchar buf[BUFFSIZE];
2663 gboolean prev_autowrap;
2664 gboolean badtxt = FALSE;
2666 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2668 if ((fp = g_fopen(file, "rb")) == NULL) {
2669 FILE_OP_ERROR(file, "fopen");
2670 return COMPOSE_INSERT_READ_ERROR;
2673 prev_autowrap = compose->autowrap;
2674 compose->autowrap = FALSE;
2676 text = GTK_TEXT_VIEW(compose->text);
2677 buffer = gtk_text_view_get_buffer(text);
2678 mark = gtk_text_buffer_get_insert(buffer);
2679 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2681 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2682 G_CALLBACK(text_inserted),
2685 cur_encoding = conv_get_locale_charset_str();
2687 while (fgets(buf, sizeof(buf), fp) != NULL) {
2690 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2691 str = g_strdup(buf);
2693 str = conv_codeset_strdup
2694 (buf, cur_encoding, CS_INTERNAL);
2697 /* strip <CR> if DOS/Windows file,
2698 replace <CR> with <LF> if Macintosh file. */
2701 if (len > 0 && str[len - 1] != '\n') {
2703 if (str[len] == '\r') str[len] = '\n';
2706 gtk_text_buffer_insert(buffer, &iter, str, -1);
2710 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2711 G_CALLBACK(text_inserted),
2713 compose->autowrap = prev_autowrap;
2714 if (compose->autowrap)
2715 compose_wrap_all(compose);
2720 return COMPOSE_INSERT_INVALID_CHARACTER;
2722 return COMPOSE_INSERT_SUCCESS;
2725 static void compose_attach_append(Compose *compose, const gchar *file,
2726 const gchar *filename,
2727 const gchar *content_type)
2735 GtkListStore *store;
2737 gboolean has_binary = FALSE;
2739 if (!is_file_exist(file)) {
2740 g_warning("File %s doesn't exist\n", filename);
2743 if ((size = get_file_size(file)) < 0) {
2744 g_warning("Can't get file size of %s\n", filename);
2748 alertpanel_notice(_("File %s is empty."), filename);
2751 if ((fp = g_fopen(file, "rb")) == NULL) {
2752 alertpanel_error(_("Can't read %s."), filename);
2757 ainfo = g_new0(AttachInfo, 1);
2758 auto_ainfo = g_auto_pointer_new_with_free
2759 (ainfo, (GFreeFunc) compose_attach_info_free);
2760 ainfo->file = g_strdup(file);
2763 ainfo->content_type = g_strdup(content_type);
2764 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2766 MsgFlags flags = {0, 0};
2768 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2769 ainfo->encoding = ENC_7BIT;
2771 ainfo->encoding = ENC_8BIT;
2773 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2774 if (msginfo && msginfo->subject)
2775 name = g_strdup(msginfo->subject);
2777 name = g_path_get_basename(filename ? filename : file);
2779 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2781 procmsg_msginfo_free(msginfo);
2783 if (!g_ascii_strncasecmp(content_type, "text", 4))
2784 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2786 ainfo->encoding = ENC_BASE64;
2787 name = g_path_get_basename(filename ? filename : file);
2788 ainfo->name = g_strdup(name);
2792 ainfo->content_type = procmime_get_mime_type(file);
2793 if (!ainfo->content_type) {
2794 ainfo->content_type =
2795 g_strdup("application/octet-stream");
2796 ainfo->encoding = ENC_BASE64;
2797 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2799 procmime_get_encoding_for_text_file(file, &has_binary);
2801 ainfo->encoding = ENC_BASE64;
2802 name = g_path_get_basename(filename ? filename : file);
2803 ainfo->name = g_strdup(name);
2807 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2808 g_free(ainfo->content_type);
2809 ainfo->content_type = g_strdup("application/octet-stream");
2813 size_text = to_human_readable(size);
2815 store = GTK_LIST_STORE(gtk_tree_view_get_model
2816 (GTK_TREE_VIEW(compose->attach_clist)));
2818 gtk_list_store_append(store, &iter);
2819 gtk_list_store_set(store, &iter,
2820 COL_MIMETYPE, ainfo->content_type,
2821 COL_SIZE, size_text,
2822 COL_NAME, ainfo->name,
2824 COL_AUTODATA, auto_ainfo,
2827 g_auto_pointer_free(auto_ainfo);
2830 static void compose_use_signing(Compose *compose, gboolean use_signing)
2832 GtkItemFactory *ifactory;
2833 GtkWidget *menuitem = NULL;
2835 compose->use_signing = use_signing;
2836 ifactory = gtk_item_factory_from_widget(compose->menubar);
2837 menuitem = gtk_item_factory_get_item
2838 (ifactory, "/Options/Sign");
2839 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2843 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2845 GtkItemFactory *ifactory;
2846 GtkWidget *menuitem = NULL;
2848 compose->use_encryption = use_encryption;
2849 ifactory = gtk_item_factory_from_widget(compose->menubar);
2850 menuitem = gtk_item_factory_get_item
2851 (ifactory, "/Options/Encrypt");
2853 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2857 #define NEXT_PART_NOT_CHILD(info) \
2859 node = info->node; \
2860 while (node->children) \
2861 node = g_node_last_child(node); \
2862 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2865 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2869 MimeInfo *firsttext = NULL;
2870 MimeInfo *encrypted = NULL;
2873 const gchar *partname = NULL;
2875 mimeinfo = procmime_scan_message(msginfo);
2876 if (!mimeinfo) return;
2878 if (mimeinfo->node->children == NULL) {
2879 procmime_mimeinfo_free_all(mimeinfo);
2883 /* find first content part */
2884 child = (MimeInfo *) mimeinfo->node->children->data;
2885 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2886 child = (MimeInfo *)child->node->children->data;
2888 if (child->type == MIMETYPE_TEXT) {
2890 debug_print("First text part found\n");
2891 } else if (compose->mode == COMPOSE_REEDIT &&
2892 child->type == MIMETYPE_APPLICATION &&
2893 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2894 encrypted = (MimeInfo *)child->node->parent->data;
2897 child = (MimeInfo *) mimeinfo->node->children->data;
2898 while (child != NULL) {
2899 if (child == encrypted) {
2900 /* skip this part of tree */
2901 NEXT_PART_NOT_CHILD(child);
2905 if (child->type == MIMETYPE_MULTIPART) {
2906 /* get the actual content */
2907 child = procmime_mimeinfo_next(child);
2911 if (child == firsttext) {
2912 child = procmime_mimeinfo_next(child);
2916 outfile = procmime_get_tmp_file_name(child);
2917 if (procmime_get_part(outfile, child) < 0)
2918 g_warning("Can't get the part of multipart message.");
2920 gchar *content_type;
2922 content_type = procmime_get_content_type_str(child->type, child->subtype);
2924 /* if we meet a pgp signature, we don't attach it, but
2925 * we force signing. */
2926 if (strcmp(content_type, "application/pgp-signature")) {
2927 partname = procmime_mimeinfo_get_parameter(child, "filename");
2928 if (partname == NULL)
2929 partname = procmime_mimeinfo_get_parameter(child, "name");
2930 if (partname == NULL)
2932 compose_attach_append(compose, outfile,
2933 partname, content_type);
2935 compose_force_signing(compose, compose->account);
2937 g_free(content_type);
2940 NEXT_PART_NOT_CHILD(child);
2942 procmime_mimeinfo_free_all(mimeinfo);
2945 #undef NEXT_PART_NOT_CHILD
2950 WAIT_FOR_INDENT_CHAR,
2951 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2954 /* return indent length, we allow:
2955 indent characters followed by indent characters or spaces/tabs,
2956 alphabets and numbers immediately followed by indent characters,
2957 and the repeating sequences of the above
2958 If quote ends with multiple spaces, only the first one is included. */
2959 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2960 const GtkTextIter *start, gint *len)
2962 GtkTextIter iter = *start;
2966 IndentState state = WAIT_FOR_INDENT_CHAR;
2969 gint alnum_count = 0;
2970 gint space_count = 0;
2973 if (prefs_common.quote_chars == NULL) {
2977 while (!gtk_text_iter_ends_line(&iter)) {
2978 wc = gtk_text_iter_get_char(&iter);
2979 if (g_unichar_iswide(wc))
2981 clen = g_unichar_to_utf8(wc, ch);
2985 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2986 is_space = g_unichar_isspace(wc);
2988 if (state == WAIT_FOR_INDENT_CHAR) {
2989 if (!is_indent && !g_unichar_isalnum(wc))
2992 quote_len += alnum_count + space_count + 1;
2993 alnum_count = space_count = 0;
2994 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2997 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2998 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3002 else if (is_indent) {
3003 quote_len += alnum_count + space_count + 1;
3004 alnum_count = space_count = 0;
3007 state = WAIT_FOR_INDENT_CHAR;
3011 gtk_text_iter_forward_char(&iter);
3014 if (quote_len > 0 && space_count > 0)
3020 if (quote_len > 0) {
3022 gtk_text_iter_forward_chars(&iter, quote_len);
3023 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3029 /* return TRUE if the line is itemized */
3030 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3031 const GtkTextIter *start)
3033 GtkTextIter iter = *start;
3038 if (gtk_text_iter_ends_line(&iter))
3042 wc = gtk_text_iter_get_char(&iter);
3043 if (!g_unichar_isspace(wc))
3045 gtk_text_iter_forward_char(&iter);
3046 if (gtk_text_iter_ends_line(&iter))
3050 clen = g_unichar_to_utf8(wc, ch);
3054 if (!strchr("*-+", ch[0]))
3057 gtk_text_iter_forward_char(&iter);
3058 if (gtk_text_iter_ends_line(&iter))
3060 wc = gtk_text_iter_get_char(&iter);
3061 if (g_unichar_isspace(wc))
3067 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3068 const GtkTextIter *start,
3069 GtkTextIter *break_pos,
3073 GtkTextIter iter = *start, line_end = *start;
3074 PangoLogAttr *attrs;
3081 gboolean can_break = FALSE;
3082 gboolean do_break = FALSE;
3083 gboolean was_white = FALSE;
3084 gboolean prev_dont_break = FALSE;
3086 gtk_text_iter_forward_to_line_end(&line_end);
3087 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3088 len = g_utf8_strlen(str, -1);
3089 /* g_print("breaking line: %d: %s (len = %d)\n",
3090 gtk_text_iter_get_line(&iter), str, len); */
3091 attrs = g_new(PangoLogAttr, len + 1);
3093 pango_default_break(str, -1, NULL, attrs, len + 1);
3097 /* skip quote and leading spaces */
3098 for (i = 0; *p != '\0' && i < len; i++) {
3101 wc = g_utf8_get_char(p);
3102 if (i >= quote_len && !g_unichar_isspace(wc))
3104 if (g_unichar_iswide(wc))
3106 else if (*p == '\t')
3110 p = g_utf8_next_char(p);
3113 for (; *p != '\0' && i < len; i++) {
3114 PangoLogAttr *attr = attrs + i;
3118 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3121 was_white = attr->is_white;
3123 /* don't wrap URI */
3124 if ((uri_len = get_uri_len(p)) > 0) {
3126 if (pos > 0 && col > max_col) {
3136 wc = g_utf8_get_char(p);
3137 if (g_unichar_iswide(wc)) {
3139 if (prev_dont_break && can_break && attr->is_line_break)
3141 } else if (*p == '\t')
3145 if (pos > 0 && col > max_col) {
3150 if (*p == '-' || *p == '/')
3151 prev_dont_break = TRUE;
3153 prev_dont_break = FALSE;
3155 p = g_utf8_next_char(p);
3159 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3164 *break_pos = *start;
3165 gtk_text_iter_set_line_offset(break_pos, pos);
3170 static gboolean compose_join_next_line(Compose *compose,
3171 GtkTextBuffer *buffer,
3173 const gchar *quote_str)
3175 GtkTextIter iter_ = *iter, cur, prev, next, end;
3176 PangoLogAttr attrs[3];
3178 gchar *next_quote_str;
3181 gboolean keep_cursor = FALSE;
3183 if (!gtk_text_iter_forward_line(&iter_) ||
3184 gtk_text_iter_ends_line(&iter_))
3187 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3189 if ((quote_str || next_quote_str) &&
3190 strcmp2(quote_str, next_quote_str) != 0) {
3191 g_free(next_quote_str);
3194 g_free(next_quote_str);
3197 if (quote_len > 0) {
3198 gtk_text_iter_forward_chars(&end, quote_len);
3199 if (gtk_text_iter_ends_line(&end))
3203 /* don't join itemized lines */
3204 if (compose_is_itemized(buffer, &end))
3207 /* don't join signature separator */
3208 if (compose_is_sig_separator(compose, buffer, &iter_))
3211 /* delete quote str */
3213 gtk_text_buffer_delete(buffer, &iter_, &end);
3215 /* don't join line breaks put by the user */
3217 gtk_text_iter_backward_char(&cur);
3218 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3219 gtk_text_iter_forward_char(&cur);
3223 gtk_text_iter_forward_char(&cur);
3224 /* delete linebreak and extra spaces */
3225 while (gtk_text_iter_backward_char(&cur)) {
3226 wc1 = gtk_text_iter_get_char(&cur);
3227 if (!g_unichar_isspace(wc1))
3232 while (!gtk_text_iter_ends_line(&cur)) {
3233 wc1 = gtk_text_iter_get_char(&cur);
3234 if (!g_unichar_isspace(wc1))
3236 gtk_text_iter_forward_char(&cur);
3239 if (!gtk_text_iter_equal(&prev, &next)) {
3242 mark = gtk_text_buffer_get_insert(buffer);
3243 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3244 if (gtk_text_iter_equal(&prev, &cur))
3246 gtk_text_buffer_delete(buffer, &prev, &next);
3250 /* insert space if required */
3251 gtk_text_iter_backward_char(&prev);
3252 wc1 = gtk_text_iter_get_char(&prev);
3253 wc2 = gtk_text_iter_get_char(&next);
3254 gtk_text_iter_forward_char(&next);
3255 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3256 pango_default_break(str, -1, NULL, attrs, 3);
3257 if (!attrs[1].is_line_break ||
3258 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3259 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3261 gtk_text_iter_backward_char(&iter_);
3262 gtk_text_buffer_place_cursor(buffer, &iter_);
3271 #define ADD_TXT_POS(bp_, ep_, pti_) \
3272 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3273 last = last->next; \
3274 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3275 last->next = NULL; \
3277 g_warning("alloc error scanning URIs\n"); \
3280 static gboolean automatic_break = FALSE;
3281 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3283 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3284 GtkTextBuffer *buffer;
3285 GtkTextIter iter, break_pos, end_of_line;
3286 gchar *quote_str = NULL;
3288 gboolean wrap_quote = prefs_common.linewrap_quote;
3289 gboolean prev_autowrap = compose->autowrap;
3290 gint startq_offset = -1, noq_offset = -1;
3291 gint uri_start = -1, uri_stop = -1;
3292 gint nouri_start = -1, nouri_stop = -1;
3293 gint num_blocks = 0;
3295 compose->autowrap = FALSE;
3297 buffer = gtk_text_view_get_buffer(text);
3298 undo_wrapping(compose->undostruct, TRUE);
3303 mark = gtk_text_buffer_get_insert(buffer);
3304 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3307 /* move to paragraph start */
3308 gtk_text_iter_set_line_offset(&iter, 0);
3309 if (gtk_text_iter_ends_line(&iter)) {
3310 while (gtk_text_iter_ends_line(&iter) &&
3311 gtk_text_iter_forward_line(&iter))
3314 while (gtk_text_iter_backward_line(&iter)) {
3315 if (gtk_text_iter_ends_line(&iter)) {
3316 gtk_text_iter_forward_line(&iter);
3322 /* go until paragraph end (empty line) */
3324 while (!gtk_text_iter_ends_line(&iter)) {
3325 gchar *scanpos = NULL;
3326 /* parse table - in order of priority */
3328 const gchar *needle; /* token */
3330 /* token search function */
3331 gchar *(*search) (const gchar *haystack,
3332 const gchar *needle);
3333 /* part parsing function */
3334 gboolean (*parse) (const gchar *start,
3335 const gchar *scanpos,
3339 /* part to URI function */
3340 gchar *(*build_uri) (const gchar *bp,
3344 static struct table parser[] = {
3345 {"http://", strcasestr, get_uri_part, make_uri_string},
3346 {"https://", strcasestr, get_uri_part, make_uri_string},
3347 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3348 {"www.", strcasestr, get_uri_part, make_http_string},
3349 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3350 {"@", strcasestr, get_email_part, make_email_string}
3352 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3353 gint last_index = PARSE_ELEMS;
3355 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3358 if (!prev_autowrap && num_blocks == 0) {
3360 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3361 G_CALLBACK(text_inserted),
3364 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3367 uri_start = uri_stop = -1;
3369 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3373 if (startq_offset == -1) {
3374 startq_offset = gtk_text_iter_get_offset(&iter);
3378 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3379 if (startq_offset == -1)
3380 startq_offset = gtk_text_iter_get_offset(&iter);
3382 if (startq_offset == -1)
3383 noq_offset = gtk_text_iter_get_offset(&iter);
3386 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3389 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3390 prefs_common.linewrap_len,
3392 GtkTextIter prev, next, cur;
3394 if (prev_autowrap != FALSE || force) {
3395 automatic_break = TRUE;
3396 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3397 automatic_break = FALSE;
3398 } else if (quote_str && wrap_quote) {
3399 automatic_break = TRUE;
3400 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3401 automatic_break = FALSE;
3404 /* remove trailing spaces */
3406 gtk_text_iter_backward_char(&cur);
3408 while (!gtk_text_iter_starts_line(&cur)) {
3411 gtk_text_iter_backward_char(&cur);
3412 wc = gtk_text_iter_get_char(&cur);
3413 if (!g_unichar_isspace(wc))
3417 if (!gtk_text_iter_equal(&prev, &next)) {
3418 gtk_text_buffer_delete(buffer, &prev, &next);
3420 gtk_text_iter_forward_char(&break_pos);
3424 gtk_text_buffer_insert(buffer, &break_pos,
3428 compose_join_next_line(compose, buffer, &iter, quote_str);
3430 /* move iter to current line start */
3431 gtk_text_iter_set_line_offset(&iter, 0);
3438 /* move iter to next line start */
3443 if (!prev_autowrap && num_blocks > 0) {
3445 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3446 G_CALLBACK(text_inserted),
3450 while (!gtk_text_iter_ends_line(&end_of_line)) {
3451 gtk_text_iter_forward_char(&end_of_line);
3453 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3455 nouri_start = gtk_text_iter_get_offset(&iter);
3456 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3458 walk_pos = gtk_text_iter_get_offset(&iter);
3459 /* FIXME: this looks phony. scanning for anything in the parse table */
3460 for (n = 0; n < PARSE_ELEMS; n++) {
3463 tmp = parser[n].search(walk, parser[n].needle);
3465 if (scanpos == NULL || tmp < scanpos) {
3474 /* check if URI can be parsed */
3475 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3476 (const gchar **)&ep, FALSE)
3477 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3481 strlen(parser[last_index].needle);
3484 uri_start = walk_pos + (bp - o_walk);
3485 uri_stop = walk_pos + (ep - o_walk);
3489 gtk_text_iter_forward_line(&iter);
3492 if (startq_offset != -1) {
3493 GtkTextIter startquote, endquote;
3494 gtk_text_buffer_get_iter_at_offset(
3495 buffer, &startquote, startq_offset);
3497 gtk_text_buffer_apply_tag_by_name(
3498 buffer, "quote", &startquote, &endquote);
3500 } else if (noq_offset != -1) {
3501 GtkTextIter startnoquote, endnoquote;
3502 gtk_text_buffer_get_iter_at_offset(
3503 buffer, &startnoquote, noq_offset);
3505 gtk_text_buffer_remove_tag_by_name(
3506 buffer, "quote", &startnoquote, &endnoquote);
3511 GtkTextIter nouri_start_iter, nouri_end_iter;
3512 gtk_text_buffer_get_iter_at_offset(
3513 buffer, &nouri_start_iter, nouri_start);
3514 gtk_text_buffer_get_iter_at_offset(
3515 buffer, &nouri_end_iter, nouri_stop);
3516 gtk_text_buffer_remove_tag_by_name(
3517 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3519 if (uri_start > 0 && uri_stop > 0) {
3520 GtkTextIter uri_start_iter, uri_end_iter;
3521 gtk_text_buffer_get_iter_at_offset(
3522 buffer, &uri_start_iter, uri_start);
3523 gtk_text_buffer_get_iter_at_offset(
3524 buffer, &uri_end_iter, uri_stop);
3525 gtk_text_buffer_apply_tag_by_name(
3526 buffer, "link", &uri_start_iter, &uri_end_iter);
3532 undo_wrapping(compose->undostruct, FALSE);
3533 compose->autowrap = prev_autowrap;
3536 void compose_action_cb(void *data)
3538 Compose *compose = (Compose *)data;
3539 compose_wrap_all(compose);
3542 static void compose_wrap_all(Compose *compose)
3544 compose_wrap_all_full(compose, FALSE);
3547 static void compose_wrap_all_full(Compose *compose, gboolean force)
3549 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3550 GtkTextBuffer *buffer;
3553 buffer = gtk_text_view_get_buffer(text);
3555 gtk_text_buffer_get_start_iter(buffer, &iter);
3556 while (!gtk_text_iter_is_end(&iter))
3557 compose_beautify_paragraph(compose, &iter, force);
3561 static void compose_set_title(Compose *compose)
3567 edited = compose->modified ? _(" [Edited]") : "";
3569 subject = gtk_editable_get_chars(
3570 GTK_EDITABLE(compose->subject_entry), 0, -1);
3572 if (subject && strlen(subject))
3573 str = g_strdup_printf(_("%s - Compose message%s"),
3576 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3577 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3583 * compose_current_mail_account:
3585 * Find a current mail account (the currently selected account, or the
3586 * default account, if a news account is currently selected). If a
3587 * mail account cannot be found, display an error message.
3589 * Return value: Mail account, or NULL if not found.
3591 static PrefsAccount *
3592 compose_current_mail_account(void)
3596 if (cur_account && cur_account->protocol != A_NNTP)
3599 ac = account_get_default();
3600 if (!ac || ac->protocol == A_NNTP) {
3601 alertpanel_error(_("Account for sending mail is not specified.\n"
3602 "Please select a mail account before sending."));
3609 static void compose_select_account(Compose *compose, PrefsAccount *account,
3612 GtkItemFactory *ifactory;
3614 g_return_if_fail(account != NULL);
3616 compose->account = account;
3618 compose_set_title(compose);
3620 ifactory = gtk_item_factory_from_widget(compose->menubar);
3622 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3623 menu_set_active(ifactory, "/Options/Sign", TRUE);
3625 menu_set_active(ifactory, "/Options/Sign", FALSE);
3626 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3627 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3629 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3631 activate_privacy_system(compose, account, FALSE);
3633 if (!init && compose->mode != COMPOSE_REDIRECT)
3634 compose_insert_sig(compose, TRUE);
3637 gboolean compose_check_for_valid_recipient(Compose *compose) {
3638 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3639 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3640 gboolean recipient_found = FALSE;
3644 /* free to and newsgroup list */
3645 slist_free_strings(compose->to_list);
3646 g_slist_free(compose->to_list);
3647 compose->to_list = NULL;
3649 slist_free_strings(compose->newsgroup_list);
3650 g_slist_free(compose->newsgroup_list);
3651 compose->newsgroup_list = NULL;
3653 /* search header entries for to and newsgroup entries */
3654 for (list = compose->header_list; list; list = list->next) {
3657 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3658 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3660 if (entry[0] != '\0') {
3661 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3662 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3663 compose->to_list = address_list_append(compose->to_list, entry);
3664 recipient_found = TRUE;
3667 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3668 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3669 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3670 recipient_found = TRUE;
3677 return recipient_found;
3680 static gboolean compose_check_for_set_recipients(Compose *compose)
3682 if (compose->account->set_autocc && compose->account->auto_cc) {
3683 gboolean found_other = FALSE;
3685 /* search header entries for to and newsgroup entries */
3686 for (list = compose->header_list; list; list = list->next) {
3689 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3690 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3692 if (strcmp(entry, compose->account->auto_cc)
3693 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3703 aval = alertpanel(_("Send"),
3704 _("The only recipient is the default CC address. Send anyway?"),
3705 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3706 if (aval != G_ALERTALTERNATE)
3710 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3711 gboolean found_other = FALSE;
3713 /* search header entries for to and newsgroup entries */
3714 for (list = compose->header_list; list; list = list->next) {
3717 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3718 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3720 if (strcmp(entry, compose->account->auto_cc)
3721 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3731 aval = alertpanel(_("Send"),
3732 _("The only recipient is the default BCC address. Send anyway?"),
3733 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3734 if (aval != G_ALERTALTERNATE)
3741 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3745 if (compose_check_for_valid_recipient(compose) == FALSE) {
3746 alertpanel_error(_("Recipient is not specified."));
3750 if (compose_check_for_set_recipients(compose) == FALSE) {
3754 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3755 if (*str == '\0' && check_subject == TRUE) {
3758 aval = alertpanel(_("Send"),
3759 _("Subject is empty. Send it anyway?"),
3760 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3761 if (aval != G_ALERTALTERNATE)
3768 gint compose_send(Compose *compose)
3775 compose_allow_user_actions (compose, FALSE);
3776 compose->sending = TRUE;
3778 if (compose_check_entries(compose, TRUE) == FALSE)
3781 val = compose_queue(compose, &msgnum, &folder);
3785 alertpanel_error(_("Could not queue message for sending:\n\n"
3786 "Charset conversion failed."));
3787 } else if (val == -3) {
3788 alertpanel_error(_("Could not queue message for sending:\n\n"
3789 "Signature failed."));
3790 } else if (val == -2 && errno != 0) {
3791 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3793 alertpanel_error(_("Could not queue message for sending."));
3799 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3800 compose->sending = FALSE;
3801 compose_close(compose);
3802 /* No more compose access in the normal codepath
3803 * after this point! */
3808 alertpanel_error(_("The message was queued but could not be "
3809 "sent.\nUse \"Send queued messages\" from "
3810 "the main window to retry."));
3811 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3812 compose->sending = FALSE;
3813 compose->modified = TRUE;
3814 compose_allow_user_actions (compose, TRUE);
3819 msgpath = folder_item_fetch_msg(folder, msgnum);
3820 val = procmsg_send_message_queue(msgpath);
3823 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3824 compose->sending = FALSE;
3825 compose_allow_user_actions (compose, TRUE);
3827 folder_item_remove_msg(folder, msgnum);
3828 folder_item_scan(folder);
3833 folder_item_remove_msg(folder, msgnum);
3834 folder_item_scan(folder);
3835 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3836 compose_close(compose);
3838 alertpanel_error(_("The message was queued but could not be "
3839 "sent.\nUse \"Send queued messages\" from "
3840 "the main window to retry."));
3841 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3842 compose_allow_user_actions (compose, TRUE);
3843 compose->modified = TRUE;
3844 compose->sending = FALSE;
3852 compose_allow_user_actions (compose, TRUE);
3853 compose->sending = FALSE;
3854 compose->modified = TRUE;
3859 static gboolean compose_use_attach(Compose *compose)
3861 GtkTreeModel *model = gtk_tree_view_get_model
3862 (GTK_TREE_VIEW(compose->attach_clist));
3863 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3866 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3869 gchar buf[BUFFSIZE];
3871 gboolean first_to_address;
3872 gboolean first_cc_address;
3874 ComposeHeaderEntry *headerentry;
3875 const gchar *headerentryname;
3879 debug_print("Writing redirect header\n");
3881 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3882 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3884 first_to_address = TRUE;
3885 for (list = compose->header_list; list; list = list->next) {
3886 headerentry = ((ComposeHeaderEntry *)list->data);
3887 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3889 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3890 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3891 Xstrdup_a(str, entstr, return -1);
3893 if (str[0] != '\0') {
3894 compose_convert_header
3895 (compose, buf, sizeof(buf), str,
3896 strlen("Resent-To") + 2, TRUE);
3898 if (first_to_address) {
3899 fprintf(fp, "Resent-To: ");
3900 first_to_address = FALSE;
3904 fprintf(fp, "%s", buf);
3908 if (!first_to_address) {
3912 first_cc_address = TRUE;
3913 for (list = compose->header_list; list; list = list->next) {
3914 headerentry = ((ComposeHeaderEntry *)list->data);
3915 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3917 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3918 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3919 Xstrdup_a(str, strg, return -1);
3921 if (str[0] != '\0') {
3922 compose_convert_header
3923 (compose, buf, sizeof(buf), str,
3924 strlen("Resent-Cc") + 2, TRUE);
3926 if (first_cc_address) {
3927 fprintf(fp, "Resent-Cc: ");
3928 first_cc_address = FALSE;
3932 fprintf(fp, "%s", buf);
3936 if (!first_cc_address) {
3943 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3945 gchar buf[BUFFSIZE];
3947 const gchar *entstr;
3948 /* struct utsname utsbuf; */
3950 g_return_val_if_fail(fp != NULL, -1);
3951 g_return_val_if_fail(compose->account != NULL, -1);
3952 g_return_val_if_fail(compose->account->address != NULL, -1);
3955 get_rfc822_date(buf, sizeof(buf));
3956 fprintf(fp, "Resent-Date: %s\n", buf);
3959 if (compose->account->name && *compose->account->name) {
3960 compose_convert_header
3961 (compose, buf, sizeof(buf), compose->account->name,
3962 strlen("From: "), TRUE);
3963 fprintf(fp, "Resent-From: %s <%s>\n",
3964 buf, compose->account->address);
3966 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3969 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3970 if (*entstr != '\0') {
3971 Xstrdup_a(str, entstr, return -1);
3974 compose_convert_header(compose, buf, sizeof(buf), str,
3975 strlen("Subject: "), FALSE);
3976 fprintf(fp, "Subject: %s\n", buf);
3980 /* Resent-Message-ID */
3981 if (compose->account->gen_msgid) {
3982 generate_msgid(buf, sizeof(buf));
3983 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3984 compose->msgid = g_strdup(buf);
3987 compose_redirect_write_headers_from_headerlist(compose, fp);
3989 /* separator between header and body */
3995 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3999 gchar buf[BUFFSIZE];
4001 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4002 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4006 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4007 /* should filter returnpath, delivered-to */
4008 if (g_ascii_strncasecmp(buf, "Return-Path:",
4009 strlen("Return-Path:")) == 0 ||
4010 g_ascii_strncasecmp(buf, "Delivered-To:",
4011 strlen("Delivered-To:")) == 0 ||
4012 g_ascii_strncasecmp(buf, "Received:",
4013 strlen("Received:")) == 0 ||
4014 g_ascii_strncasecmp(buf, "Subject:",
4015 strlen("Subject:")) == 0 ||
4016 g_ascii_strncasecmp(buf, "X-UIDL:",
4017 strlen("X-UIDL:")) == 0)
4020 if (fputs(buf, fdest) == -1)
4023 if (!prefs_common.redirect_keep_from) {
4024 if (g_ascii_strncasecmp(buf, "From:",
4025 strlen("From:")) == 0) {
4026 fputs(" (by way of ", fdest);
4027 if (compose->account->name
4028 && *compose->account->name) {
4029 compose_convert_header
4030 (compose, buf, sizeof(buf),
4031 compose->account->name,
4034 fprintf(fdest, "%s <%s>",
4036 compose->account->address);
4038 fprintf(fdest, "%s",
4039 compose->account->address);
4044 if (fputs("\n", fdest) == -1)
4048 compose_redirect_write_headers(compose, fdest);
4050 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4051 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4064 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4066 GtkTextBuffer *buffer;
4067 GtkTextIter start, end;
4070 const gchar *out_codeset;
4071 EncodingType encoding;
4072 MimeInfo *mimemsg, *mimetext;
4075 /* create message MimeInfo */
4076 mimemsg = procmime_mimeinfo_new();
4077 mimemsg->type = MIMETYPE_MESSAGE;
4078 mimemsg->subtype = g_strdup("rfc822");
4079 mimemsg->content = MIMECONTENT_MEM;
4080 mimemsg->tmp = TRUE; /* must free content later */
4081 mimemsg->data.mem = compose_get_header(compose);
4083 /* Create text part MimeInfo */
4084 /* get all composed text */
4085 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4086 gtk_text_buffer_get_start_iter(buffer, &start);
4087 gtk_text_buffer_get_end_iter(buffer, &end);
4088 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4089 if (is_ascii_str(chars)) {
4092 out_codeset = CS_US_ASCII;
4093 encoding = ENC_7BIT;
4095 const gchar *src_codeset = CS_INTERNAL;
4097 out_codeset = conv_get_charset_str(compose->out_encoding);
4100 gchar *test_conv_global_out = NULL;
4101 gchar *test_conv_reply = NULL;
4103 /* automatic mode. be automatic. */
4104 codeconv_set_strict(TRUE);
4106 out_codeset = conv_get_outgoing_charset_str();
4108 debug_print("trying to convert to %s\n", out_codeset);
4109 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4112 if (!test_conv_global_out && compose->orig_charset
4113 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4114 out_codeset = compose->orig_charset;
4115 debug_print("failure; trying to convert to %s\n", out_codeset);
4116 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4119 if (!test_conv_global_out && !test_conv_reply) {
4121 out_codeset = CS_INTERNAL;
4122 debug_print("failure; finally using %s\n", out_codeset);
4124 g_free(test_conv_global_out);
4125 g_free(test_conv_reply);
4126 codeconv_set_strict(FALSE);
4129 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4130 out_codeset = CS_ISO_8859_1;
4132 if (prefs_common.encoding_method == CTE_BASE64)
4133 encoding = ENC_BASE64;
4134 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4135 encoding = ENC_QUOTED_PRINTABLE;
4136 else if (prefs_common.encoding_method == CTE_8BIT)
4137 encoding = ENC_8BIT;
4139 encoding = procmime_get_encoding_for_charset(out_codeset);
4141 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4142 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4144 if (action == COMPOSE_WRITE_FOR_SEND) {
4145 codeconv_set_strict(TRUE);
4146 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4147 codeconv_set_strict(FALSE);
4153 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4154 "to the specified %s charset.\n"
4155 "Send it as %s?"), out_codeset, src_codeset);
4156 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4157 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4160 if (aval != G_ALERTALTERNATE) {
4165 out_codeset = src_codeset;
4171 out_codeset = src_codeset;
4177 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4178 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4179 strstr(buf, "\nFrom ") != NULL) {
4180 encoding = ENC_QUOTED_PRINTABLE;
4184 mimetext = procmime_mimeinfo_new();
4185 mimetext->content = MIMECONTENT_MEM;
4186 mimetext->tmp = TRUE; /* must free content later */
4187 mimetext->data.mem = buf;
4188 mimetext->type = MIMETYPE_TEXT;
4189 mimetext->subtype = g_strdup("plain");
4190 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4191 g_strdup(out_codeset));
4192 /* protect trailing spaces when signing message */
4193 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4194 privacy_system_can_sign(compose->privacy_system)) {
4195 encoding = ENC_QUOTED_PRINTABLE;
4198 /* check for line length limit */
4199 if (action == COMPOSE_WRITE_FOR_SEND &&
4200 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4201 check_line_length(buf, 1000, &line) < 0) {
4205 msg = g_strdup_printf
4206 (_("Line %d exceeds the line length limit (998 bytes).\n"
4207 "The contents of the message might be broken on the way to the delivery.\n"
4209 "Send it anyway?"), line + 1);
4210 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4212 if (aval != G_ALERTALTERNATE) {
4217 if (encoding != ENC_UNKNOWN)
4218 procmime_encode_content(mimetext, encoding);
4220 /* append attachment parts */
4221 if (compose_use_attach(compose)) {
4222 MimeInfo *mimempart;
4223 gchar *boundary = NULL;
4224 mimempart = procmime_mimeinfo_new();
4225 mimempart->content = MIMECONTENT_EMPTY;
4226 mimempart->type = MIMETYPE_MULTIPART;
4227 mimempart->subtype = g_strdup("mixed");
4232 boundary = generate_mime_boundary(NULL);
4233 } while (strstr(buf, boundary) != NULL);
4235 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4238 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4240 g_node_append(mimempart->node, mimetext->node);
4241 g_node_append(mimemsg->node, mimempart->node);
4243 compose_add_attachments(compose, mimempart);
4245 g_node_append(mimemsg->node, mimetext->node);
4247 /* sign message if sending */
4248 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4249 privacy_system_can_sign(compose->privacy_system))
4250 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4253 procmime_write_mimeinfo(mimemsg, fp);
4255 procmime_mimeinfo_free_all(mimemsg);
4260 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4262 GtkTextBuffer *buffer;
4263 GtkTextIter start, end;
4268 if ((fp = g_fopen(file, "wb")) == NULL) {
4269 FILE_OP_ERROR(file, "fopen");
4273 /* chmod for security */
4274 if (change_file_mode_rw(fp, file) < 0) {
4275 FILE_OP_ERROR(file, "chmod");
4276 g_warning("can't change file mode\n");
4279 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4280 gtk_text_buffer_get_start_iter(buffer, &start);
4281 gtk_text_buffer_get_end_iter(buffer, &end);
4282 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4284 chars = conv_codeset_strdup
4285 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4288 if (!chars) return -1;
4291 len = strlen(chars);
4292 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4293 FILE_OP_ERROR(file, "fwrite");
4302 if (fclose(fp) == EOF) {
4303 FILE_OP_ERROR(file, "fclose");
4310 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4313 MsgInfo *msginfo = compose->targetinfo;
4315 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4316 if (!msginfo) return -1;
4318 if (!force && MSG_IS_LOCKED(msginfo->flags))
4321 item = msginfo->folder;
4322 g_return_val_if_fail(item != NULL, -1);
4324 if (procmsg_msg_exist(msginfo) &&
4325 (folder_has_parent_of_type(item, F_QUEUE) ||
4326 folder_has_parent_of_type(item, F_DRAFT)
4327 || msginfo == compose->autosaved_draft)) {
4328 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4329 g_warning("can't remove the old message\n");
4337 void compose_remove_draft(Compose *compose)
4340 MsgInfo *msginfo = compose->targetinfo;
4341 drafts = account_get_special_folder(compose->account, F_DRAFT);
4343 if (procmsg_msg_exist(msginfo)) {
4344 folder_item_remove_msg(drafts, msginfo->msgnum);
4349 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4351 return compose_queue_sub (compose, msgnum, item, FALSE);
4353 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4360 static gboolean lock = FALSE;
4361 PrefsAccount *mailac = NULL, *newsac = NULL;
4363 debug_print("queueing message...\n");
4364 g_return_val_if_fail(compose->account != NULL, -1);
4368 if (compose_check_entries(compose, check_subject) == FALSE) {
4373 if (!compose->to_list && !compose->newsgroup_list) {
4374 g_warning("can't get recipient list.");
4379 if (compose->to_list) {
4380 if (compose->account->protocol != A_NNTP)
4381 mailac = compose->account;
4382 else if (cur_account && cur_account->protocol != A_NNTP)
4383 mailac = cur_account;
4384 else if (!(mailac = compose_current_mail_account())) {
4386 alertpanel_error(_("No account for sending mails available!"));
4391 if (compose->newsgroup_list) {
4392 if (compose->account->protocol == A_NNTP)
4393 newsac = compose->account;
4394 else if (!newsac->protocol != A_NNTP) {
4396 alertpanel_error(_("No account for posting news available!"));
4401 /* write queue header */
4402 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4403 G_DIR_SEPARATOR, compose);
4404 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4405 FILE_OP_ERROR(tmp, "fopen");
4410 if (change_file_mode_rw(fp, tmp) < 0) {
4411 FILE_OP_ERROR(tmp, "chmod");
4412 g_warning("can't change file mode\n");
4415 /* queueing variables */
4416 fprintf(fp, "AF:\n");
4417 fprintf(fp, "NF:0\n");
4418 fprintf(fp, "PS:10\n");
4419 fprintf(fp, "SRH:1\n");
4420 fprintf(fp, "SFN:\n");
4421 fprintf(fp, "DSR:\n");
4423 fprintf(fp, "MID:<%s>\n", compose->msgid);
4425 fprintf(fp, "MID:\n");
4426 fprintf(fp, "CFG:\n");
4427 fprintf(fp, "PT:0\n");
4428 fprintf(fp, "S:%s\n", compose->account->address);
4429 fprintf(fp, "RQ:\n");
4431 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4433 fprintf(fp, "SSV:\n");
4435 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4437 fprintf(fp, "NSV:\n");
4438 fprintf(fp, "SSH:\n");
4439 /* write recepient list */
4440 if (compose->to_list) {
4441 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4442 for (cur = compose->to_list->next; cur != NULL;
4444 fprintf(fp, ",<%s>", (gchar *)cur->data);
4447 /* write newsgroup list */
4448 if (compose->newsgroup_list) {
4450 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4451 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4452 fprintf(fp, ",%s", (gchar *)cur->data);
4455 /* Sylpheed account IDs */
4457 fprintf(fp, "MAID:%d\n", mailac->account_id);
4459 fprintf(fp, "NAID:%d\n", newsac->account_id);
4461 if (compose->privacy_system != NULL) {
4462 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4463 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4464 if (compose->use_encryption) {
4467 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4468 if (encdata != NULL) {
4469 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4470 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4471 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4473 } /* else we finally dont want to encrypt */
4475 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4476 /* and if encdata was null, it means there's been a problem in
4483 /* Save copy folder */
4484 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4485 gchar *savefolderid;
4487 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4488 fprintf(fp, "SCF:%s\n", savefolderid);
4489 g_free(savefolderid);
4491 /* Save copy folder */
4492 if (compose->return_receipt) {
4493 fprintf(fp, "RRCPT:1\n");
4495 /* Message-ID of message replying to */
4496 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4499 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4500 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4503 /* Message-ID of message forwarding to */
4504 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4507 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4508 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4513 if (compose->redirect_filename != NULL) {
4514 if (compose_redirect_write_to_file(compose, fp) < 0) {
4523 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4528 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4532 if (fclose(fp) == EOF) {
4533 FILE_OP_ERROR(tmp, "fclose");
4539 queue = account_get_special_folder(compose->account, F_QUEUE);
4541 g_warning("can't find queue folder\n");
4546 folder_item_scan(queue);
4547 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4548 g_warning("can't queue the message\n");
4556 if (compose->mode == COMPOSE_REEDIT) {
4557 compose_remove_reedit_target(compose, FALSE);
4560 if ((msgnum != NULL) && (item != NULL)) {
4568 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4571 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4573 struct stat statbuf;
4574 gchar *type, *subtype;
4575 GtkTreeModel *model;
4578 model = gtk_tree_view_get_model(tree_view);
4580 if (!gtk_tree_model_get_iter_first(model, &iter))
4583 gtk_tree_model_get(model, &iter,
4587 mimepart = procmime_mimeinfo_new();
4588 mimepart->content = MIMECONTENT_FILE;
4589 mimepart->data.filename = g_strdup(ainfo->file);
4590 mimepart->tmp = FALSE; /* or we destroy our attachment */
4591 mimepart->offset = 0;
4593 stat(ainfo->file, &statbuf);
4594 mimepart->length = statbuf.st_size;
4596 type = g_strdup(ainfo->content_type);
4598 if (!strchr(type, '/')) {
4600 type = g_strdup("application/octet-stream");
4603 subtype = strchr(type, '/') + 1;
4604 *(subtype - 1) = '\0';
4605 mimepart->type = procmime_get_media_type(type);
4606 mimepart->subtype = g_strdup(subtype);
4609 if (mimepart->type == MIMETYPE_MESSAGE &&
4610 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4611 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4613 g_hash_table_insert(mimepart->typeparameters,
4614 g_strdup("name"), g_strdup(ainfo->name));
4615 g_hash_table_insert(mimepart->dispositionparameters,
4616 g_strdup("filename"), g_strdup(ainfo->name));
4617 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4620 if (compose->use_signing) {
4621 if (ainfo->encoding == ENC_7BIT)
4622 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4623 else if (ainfo->encoding == ENC_8BIT)
4624 ainfo->encoding = ENC_BASE64;
4627 procmime_encode_content(mimepart, ainfo->encoding);
4629 g_node_append(parent->node, mimepart->node);
4630 } while (gtk_tree_model_iter_next(model, &iter));
4633 #define QUOTE_IF_REQUIRED(out, str) \
4635 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4639 len = strlen(str) + 3; \
4640 if ((__tmp = alloca(len)) == NULL) { \
4641 g_warning("can't allocate memory\n"); \
4642 g_string_free(header, TRUE); \
4645 g_snprintf(__tmp, len, "\"%s\"", str); \
4650 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4651 g_warning("can't allocate memory\n"); \
4652 g_string_free(header, TRUE); \
4655 strcpy(__tmp, str); \
4661 #define IS_IN_CUSTOM_HEADER(header) \
4662 (compose->account->add_customhdr && \
4663 custom_header_find(compose->account->customhdr_list, header) != NULL)
4665 static void compose_add_headerfield_from_headerlist(Compose *compose,
4667 const gchar *fieldname,
4668 const gchar *seperator)
4670 gchar *str, *fieldname_w_colon, *trans_fieldname;
4671 gboolean add_field = FALSE;
4673 ComposeHeaderEntry *headerentry;
4674 const gchar * headerentryname;
4677 if (IS_IN_CUSTOM_HEADER(fieldname))
4680 debug_print("Adding %s-fields\n", fieldname);
4682 fieldstr = g_string_sized_new(64);
4684 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4685 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4687 for (list = compose->header_list; list; list = list->next) {
4688 headerentry = ((ComposeHeaderEntry *)list->data);
4689 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4691 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4692 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4694 if (str[0] != '\0') {
4696 g_string_append(fieldstr, seperator);
4697 g_string_append(fieldstr, str);
4706 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4707 compose_convert_header
4708 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4709 strlen(fieldname) + 2, TRUE);
4710 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4714 g_free(fieldname_w_colon);
4715 g_string_free(fieldstr, TRUE);
4720 static gchar *compose_get_header(Compose *compose)
4722 gchar buf[BUFFSIZE];
4723 const gchar *entry_str;
4727 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4730 g_return_val_if_fail(compose->account != NULL, NULL);
4731 g_return_val_if_fail(compose->account->address != NULL, NULL);
4733 header = g_string_sized_new(64);
4736 if (compose->account->add_date) {
4737 get_rfc822_date(buf, sizeof(buf));
4738 g_string_append_printf(header, "Date: %s\n", buf);
4742 if (compose->account->name && *compose->account->name) {
4743 compose_convert_header
4744 (compose, buf, sizeof(buf), compose->account->name,
4745 strlen("From: "), TRUE);
4746 QUOTE_IF_REQUIRED(name, buf);
4747 g_string_append_printf(header, "From: %s <%s>\n",
4748 name, compose->account->address);
4750 g_string_append_printf(header, "From: %s\n", compose->account->address);
4753 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4756 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4759 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4762 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4765 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4767 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4770 compose_convert_header(compose, buf, sizeof(buf), str,
4771 strlen("Subject: "), FALSE);
4772 g_string_append_printf(header, "Subject: %s\n", buf);
4778 if (compose->account->gen_msgid) {
4779 generate_msgid(buf, sizeof(buf));
4780 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4781 compose->msgid = g_strdup(buf);
4784 if (compose->remove_references == FALSE) {
4786 if (compose->inreplyto && compose->to_list)
4787 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4790 if (compose->references)
4791 g_string_append_printf(header, "References: %s\n", compose->references);
4795 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4798 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4801 if (compose->account->organization &&
4802 strlen(compose->account->organization) &&
4803 !IS_IN_CUSTOM_HEADER("Organization")) {
4804 compose_convert_header(compose, buf, sizeof(buf),
4805 compose->account->organization,
4806 strlen("Organization: "), FALSE);
4807 g_string_append_printf(header, "Organization: %s\n", buf);
4810 /* Program version and system info */
4811 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4812 !compose->newsgroup_list) {
4813 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4815 gtk_major_version, gtk_minor_version, gtk_micro_version,
4818 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4819 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4821 gtk_major_version, gtk_minor_version, gtk_micro_version,
4825 /* custom headers */
4826 if (compose->account->add_customhdr) {
4829 for (cur = compose->account->customhdr_list; cur != NULL;
4831 CustomHeader *chdr = (CustomHeader *)cur->data;
4833 if (custom_header_is_allowed(chdr->name)) {
4834 compose_convert_header
4835 (compose, buf, sizeof(buf),
4836 chdr->value ? chdr->value : "",
4837 strlen(chdr->name) + 2, FALSE);
4838 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4844 switch (compose->priority) {
4845 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4846 "X-Priority: 1 (Highest)\n");
4848 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4849 "X-Priority: 2 (High)\n");
4851 case PRIORITY_NORMAL: break;
4852 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4853 "X-Priority: 4 (Low)\n");
4855 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4856 "X-Priority: 5 (Lowest)\n");
4858 default: debug_print("compose: priority unknown : %d\n",
4862 /* Request Return Receipt */
4863 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4864 if (compose->return_receipt) {
4865 if (compose->account->name
4866 && *compose->account->name) {
4867 compose_convert_header(compose, buf, sizeof(buf),
4868 compose->account->name,
4869 strlen("Disposition-Notification-To: "),
4871 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4873 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4877 /* get special headers */
4878 for (list = compose->header_list; list; list = list->next) {
4879 ComposeHeaderEntry *headerentry;
4882 gchar *headername_wcolon;
4883 gchar *headername_trans;
4886 gboolean standard_header = FALSE;
4888 headerentry = ((ComposeHeaderEntry *)list->data);
4890 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4891 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4896 if (!strstr(tmp, ":")) {
4897 headername_wcolon = g_strconcat(tmp, ":", NULL);
4898 headername = g_strdup(tmp);
4900 headername_wcolon = g_strdup(tmp);
4901 headername = g_strdup(strtok(tmp, ":"));
4905 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4906 Xstrdup_a(headervalue, entry_str, return NULL);
4907 subst_char(headervalue, '\r', ' ');
4908 subst_char(headervalue, '\n', ' ');
4909 string = std_headers;
4910 while (*string != NULL) {
4911 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4912 if (!strcmp(headername_trans,headername_wcolon))
4913 standard_header = TRUE;
4916 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4917 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4920 g_free(headername_wcolon);
4924 g_string_free(header, FALSE);
4929 #undef IS_IN_CUSTOM_HEADER
4931 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4932 gint header_len, gboolean addr_field)
4934 gchar *tmpstr = NULL;
4935 const gchar *out_codeset = NULL;
4937 g_return_if_fail(src != NULL);
4938 g_return_if_fail(dest != NULL);
4940 if (len < 1) return;
4942 tmpstr = g_strdup(src);
4944 subst_char(tmpstr, '\n', ' ');
4945 subst_char(tmpstr, '\r', ' ');
4948 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4949 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4950 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4955 codeconv_set_strict(TRUE);
4956 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4957 conv_get_charset_str(compose->out_encoding));
4958 codeconv_set_strict(FALSE);
4960 if (!dest || *dest == '\0') {
4961 gchar *test_conv_global_out = NULL;
4962 gchar *test_conv_reply = NULL;
4964 /* automatic mode. be automatic. */
4965 codeconv_set_strict(TRUE);
4967 out_codeset = conv_get_outgoing_charset_str();
4969 debug_print("trying to convert to %s\n", out_codeset);
4970 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4973 if (!test_conv_global_out && compose->orig_charset) {
4974 out_codeset = compose->orig_charset;
4975 debug_print("failure; trying to convert to %s\n", out_codeset);
4976 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4979 if (!test_conv_global_out && !test_conv_reply) {
4981 out_codeset = CS_INTERNAL;
4982 debug_print("finally using %s\n", out_codeset);
4984 g_free(test_conv_global_out);
4985 g_free(test_conv_reply);
4986 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4988 codeconv_set_strict(FALSE);
4993 static void compose_create_header_entry(Compose *compose)
4995 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4999 GList *combo_list = NULL;
5001 const gchar *header = NULL;
5002 ComposeHeaderEntry *headerentry;
5003 gboolean standard_header = FALSE;
5005 headerentry = g_new0(ComposeHeaderEntry, 1);
5008 combo = gtk_combo_new();
5010 while(*string != NULL) {
5011 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5014 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5015 g_list_free(combo_list);
5016 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5017 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5018 G_CALLBACK(compose_grab_focus_cb), compose);
5019 gtk_widget_show(combo);
5020 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5021 if (compose->header_last) {
5022 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5024 while (*string != NULL) {
5025 if (!strcmp(*string, last_header_entry))
5026 standard_header = TRUE;
5029 if (standard_header)
5030 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5032 if (!compose->header_last || !standard_header) {
5033 switch(compose->account->protocol) {
5035 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5038 header = prefs_common.trans_hdr ? _("To:") : "To:";
5043 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5045 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5046 G_CALLBACK(compose_grab_focus_cb), compose);
5049 entry = gtk_entry_new();
5050 gtk_widget_show(entry);
5051 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);
5053 g_signal_connect(G_OBJECT(entry), "key-press-event",
5054 G_CALLBACK(compose_headerentry_key_press_event_cb),
5056 g_signal_connect(G_OBJECT(entry), "changed",
5057 G_CALLBACK(compose_headerentry_changed_cb),
5059 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5060 G_CALLBACK(compose_grab_focus_cb), compose);
5063 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5064 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5065 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5066 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5067 G_CALLBACK(compose_header_drag_received_cb),
5069 g_signal_connect(G_OBJECT(entry), "drag-drop",
5070 G_CALLBACK(compose_drag_drop),
5073 address_completion_register_entry(GTK_ENTRY(entry));
5075 headerentry->compose = compose;
5076 headerentry->combo = combo;
5077 headerentry->entry = entry;
5078 headerentry->headernum = compose->header_nextrow;
5080 compose->header_nextrow++;
5081 compose->header_last = headerentry;
5084 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5086 ComposeHeaderEntry *last_header;
5088 last_header = compose->header_last;
5090 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5091 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5094 static GtkWidget *compose_create_header(Compose *compose)
5098 GtkWidget *from_optmenu_hbox;
5099 GtkWidget *header_scrolledwin;
5100 GtkWidget *header_table;
5104 /* header labels and entries */
5105 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5106 gtk_widget_show(header_scrolledwin);
5107 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5109 header_table = gtk_table_new(2, 2, FALSE);
5110 gtk_widget_show(header_table);
5111 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5112 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5113 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5116 /* option menu for selecting accounts */
5117 hbox = gtk_hbox_new(FALSE, 0);
5118 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5119 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5120 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5122 from_optmenu_hbox = compose_account_option_menu_create(compose);
5123 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5124 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5127 compose->header_table = header_table;
5128 compose->header_list = NULL;
5129 compose->header_nextrow = count;
5131 compose_create_header_entry(compose);
5133 compose->table = NULL;
5135 return header_scrolledwin ;
5138 GtkWidget *compose_create_attach(Compose *compose)
5140 GtkWidget *attach_scrwin;
5141 GtkWidget *attach_clist;
5143 GtkListStore *store;
5144 GtkCellRenderer *renderer;
5145 GtkTreeViewColumn *column;
5146 GtkTreeSelection *selection;
5148 /* attachment list */
5149 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5150 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5151 GTK_POLICY_AUTOMATIC,
5152 GTK_POLICY_AUTOMATIC);
5153 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5155 store = gtk_list_store_new(N_ATTACH_COLS,
5160 G_TYPE_AUTO_POINTER,
5162 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5163 (GTK_TREE_MODEL(store)));
5164 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5165 g_object_unref(store);
5167 renderer = gtk_cell_renderer_text_new();
5168 column = gtk_tree_view_column_new_with_attributes
5169 (_("Mime type"), renderer, "text",
5170 COL_MIMETYPE, NULL);
5171 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5173 renderer = gtk_cell_renderer_text_new();
5174 column = gtk_tree_view_column_new_with_attributes
5175 (_("Size"), renderer, "text",
5177 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5179 renderer = gtk_cell_renderer_text_new();
5180 column = gtk_tree_view_column_new_with_attributes
5181 (_("Name"), renderer, "text",
5183 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5185 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5186 prefs_common.enable_rules_hint);
5187 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5188 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5190 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5191 G_CALLBACK(attach_selected), compose);
5192 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5193 G_CALLBACK(attach_button_pressed), compose);
5194 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5195 G_CALLBACK(attach_key_pressed), compose);
5198 gtk_drag_dest_set(attach_clist,
5199 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5200 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5201 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5202 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5203 G_CALLBACK(compose_attach_drag_received_cb),
5205 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5206 G_CALLBACK(compose_drag_drop),
5209 compose->attach_scrwin = attach_scrwin;
5210 compose->attach_clist = attach_clist;
5212 return attach_scrwin;
5215 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5216 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5218 static GtkWidget *compose_create_others(Compose *compose)
5221 GtkWidget *savemsg_checkbtn;
5222 GtkWidget *savemsg_entry;
5223 GtkWidget *savemsg_select;
5226 gchar *folderidentifier;
5228 /* Table for settings */
5229 table = gtk_table_new(3, 1, FALSE);
5230 gtk_widget_show(table);
5231 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5234 /* Save Message to folder */
5235 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5236 gtk_widget_show(savemsg_checkbtn);
5237 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5238 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5239 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5241 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5242 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5244 savemsg_entry = gtk_entry_new();
5245 gtk_widget_show(savemsg_entry);
5246 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5247 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5248 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5249 G_CALLBACK(compose_grab_focus_cb), compose);
5250 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5251 folderidentifier = folder_item_get_identifier(account_get_special_folder
5252 (compose->account, F_OUTBOX));
5253 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5254 g_free(folderidentifier);
5257 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5258 gtk_widget_show(savemsg_select);
5259 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5260 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5261 G_CALLBACK(compose_savemsg_select_cb),
5266 compose->savemsg_checkbtn = savemsg_checkbtn;
5267 compose->savemsg_entry = savemsg_entry;
5272 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5274 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5275 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5278 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5283 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5286 path = folder_item_get_identifier(dest);
5288 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5292 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5295 #define BLOCK_WRAP() { \
5296 prev_autowrap = compose->autowrap; \
5297 buffer = gtk_text_view_get_buffer( \
5298 GTK_TEXT_VIEW(compose->text)); \
5299 compose->autowrap = FALSE; \
5301 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5302 G_CALLBACK(compose_changed_cb), \
5304 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5305 G_CALLBACK(text_inserted), \
5308 #define UNBLOCK_WRAP() { \
5309 compose->autowrap = prev_autowrap; \
5310 if (compose->autowrap) \
5311 compose_wrap_all(compose); \
5313 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5314 G_CALLBACK(compose_changed_cb), \
5316 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5317 G_CALLBACK(text_inserted), \
5322 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5326 GtkTextBuffer *buffer;
5328 if (event->button == 3) {
5330 GtkTextIter sel_start, sel_end;
5331 gboolean stuff_selected;
5333 /* move the cursor to allow GtkAspell to check the word
5334 * under the mouse */
5335 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5336 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5338 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5341 stuff_selected = gtk_text_buffer_get_selection_bounds(
5342 GTK_TEXT_VIEW(text)->buffer,
5343 &sel_start, &sel_end);
5345 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5346 /* reselect stuff */
5348 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5349 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5350 &sel_start, &sel_end);
5352 return FALSE; /* pass the event so that the right-click goes through */
5355 if (event->button == 2) {
5357 entry_paste_clipboard(compose, compose->focused_editable,
5358 prefs_common.linewrap_pastes,
5359 GDK_SELECTION_PRIMARY);
5366 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5372 GtkWidget *handlebox;
5374 GtkWidget *notebook;
5379 GtkWidget *subject_hbox;
5380 GtkWidget *subject_frame;
5381 GtkWidget *subject_entry;
5385 GtkWidget *edit_vbox;
5386 GtkWidget *ruler_hbox;
5388 GtkWidget *scrolledwin;
5390 GtkTextBuffer *buffer;
5391 GtkClipboard *clipboard;
5393 UndoMain *undostruct;
5395 gchar *titles[N_ATTACH_COLS];
5396 guint n_menu_entries;
5399 gboolean success[1];
5400 GtkWidget *popupmenu;
5401 GtkItemFactory *popupfactory;
5402 GtkItemFactory *ifactory;
5403 GtkWidget *tmpl_menu;
5405 GtkWidget *menuitem;
5408 GtkAspell * gtkaspell = NULL;
5411 static GdkGeometry geometry;
5413 g_return_val_if_fail(account != NULL, NULL);
5415 debug_print("Creating compose window...\n");
5416 compose = g_new0(Compose, 1);
5418 titles[COL_MIMETYPE] = _("MIME type");
5419 titles[COL_SIZE] = _("Size");
5420 titles[COL_NAME] = _("Name");
5422 compose->account = account;
5424 compose->mutex = g_mutex_new();
5425 compose->set_cursor_pos = -1;
5427 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5428 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5429 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5431 if (!geometry.max_width) {
5432 geometry.max_width = gdk_screen_width();
5433 geometry.max_height = gdk_screen_height();
5436 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5437 &geometry, GDK_HINT_MAX_SIZE);
5438 if (!geometry.min_width) {
5439 geometry.min_width = 600;
5440 geometry.min_height = 480;
5442 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5443 &geometry, GDK_HINT_MIN_SIZE);
5444 gtk_widget_set_uposition(window, prefs_common.compose_x,
5445 prefs_common.compose_y);
5447 g_signal_connect(G_OBJECT(window), "delete_event",
5448 G_CALLBACK(compose_delete_cb), compose);
5449 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5450 gtk_widget_realize(window);
5452 gtkut_widget_set_composer_icon(window);
5454 vbox = gtk_vbox_new(FALSE, 0);
5455 gtk_container_add(GTK_CONTAINER(window), vbox);
5457 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5458 menubar = menubar_create(window, compose_entries,
5459 n_menu_entries, "<Compose>", compose);
5460 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5462 if (prefs_common.toolbar_detachable) {
5463 handlebox = gtk_handle_box_new();
5465 handlebox = gtk_hbox_new(FALSE, 0);
5467 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5469 gtk_widget_realize(handlebox);
5470 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5473 vbox2 = gtk_vbox_new(FALSE, 2);
5474 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5475 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5478 notebook = gtk_notebook_new();
5479 gtk_widget_set_size_request(notebook, -1, 130);
5480 gtk_widget_show(notebook);
5482 /* header labels and entries */
5483 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5484 compose_create_header(compose),
5485 gtk_label_new_with_mnemonic(_("Hea_der")));
5486 /* attachment list */
5487 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5488 compose_create_attach(compose),
5489 gtk_label_new_with_mnemonic(_("_Attachments")));
5491 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5492 compose_create_others(compose),
5493 gtk_label_new_with_mnemonic(_("Othe_rs")));
5496 subject_hbox = gtk_hbox_new(FALSE, 0);
5497 gtk_widget_show(subject_hbox);
5499 subject_frame = gtk_frame_new(NULL);
5500 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5501 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5502 gtk_widget_show(subject_frame);
5504 subject = gtk_hbox_new(FALSE, 0);
5505 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5506 gtk_widget_show(subject);
5508 label = gtk_label_new(_("Subject:"));
5509 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5510 gtk_widget_show(label);
5512 subject_entry = gtk_entry_new();
5513 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5514 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5515 G_CALLBACK(compose_grab_focus_cb), compose);
5516 gtk_widget_show(subject_entry);
5517 compose->subject_entry = subject_entry;
5518 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5520 edit_vbox = gtk_vbox_new(FALSE, 0);
5522 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5525 ruler_hbox = gtk_hbox_new(FALSE, 0);
5526 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5528 ruler = gtk_shruler_new();
5529 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5530 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5534 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5535 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5536 GTK_POLICY_AUTOMATIC,
5537 GTK_POLICY_AUTOMATIC);
5538 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5540 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5541 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5543 text = gtk_text_view_new();
5544 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5545 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5546 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5547 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5548 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5550 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5552 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5553 G_CALLBACK(compose_edit_size_alloc),
5555 g_signal_connect(G_OBJECT(buffer), "changed",
5556 G_CALLBACK(compose_changed_cb), compose);
5557 g_signal_connect(G_OBJECT(text), "grab_focus",
5558 G_CALLBACK(compose_grab_focus_cb), compose);
5559 g_signal_connect(G_OBJECT(buffer), "insert_text",
5560 G_CALLBACK(text_inserted), compose);
5561 g_signal_connect(G_OBJECT(text), "button_press_event",
5562 G_CALLBACK(text_clicked), compose);
5563 g_signal_connect(G_OBJECT(subject_entry), "changed",
5564 G_CALLBACK(compose_changed_cb), compose);
5567 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5568 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5569 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5570 g_signal_connect(G_OBJECT(text), "drag_data_received",
5571 G_CALLBACK(compose_insert_drag_received_cb),
5573 g_signal_connect(G_OBJECT(text), "drag-drop",
5574 G_CALLBACK(compose_drag_drop),
5576 gtk_widget_show_all(vbox);
5578 /* pane between attach clist and text */
5579 paned = gtk_vpaned_new();
5580 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5581 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5582 gtk_paned_add1(GTK_PANED(paned), notebook);
5583 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5584 gtk_widget_show_all(paned);
5587 if (prefs_common.textfont) {
5588 PangoFontDescription *font_desc;
5590 font_desc = pango_font_description_from_string
5591 (prefs_common.textfont);
5593 gtk_widget_modify_font(text, font_desc);
5594 pango_font_description_free(font_desc);
5598 color[0] = quote_color;
5599 cmap = gdk_drawable_get_colormap(window->window);
5600 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5601 if (success[0] == FALSE) {
5604 g_warning("Compose: color allocation failed.\n");
5605 style = gtk_widget_get_style(text);
5606 quote_color = style->black;
5609 n_entries = sizeof(compose_popup_entries) /
5610 sizeof(compose_popup_entries[0]);
5611 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5612 "<Compose>", &popupfactory,
5615 ifactory = gtk_item_factory_from_widget(menubar);
5616 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5617 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5618 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5620 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5622 undostruct = undo_init(text);
5623 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5626 address_completion_start(window);
5628 compose->window = window;
5629 compose->vbox = vbox;
5630 compose->menubar = menubar;
5631 compose->handlebox = handlebox;
5633 compose->vbox2 = vbox2;
5635 compose->paned = paned;
5637 compose->edit_vbox = edit_vbox;
5638 compose->ruler_hbox = ruler_hbox;
5639 compose->ruler = ruler;
5640 compose->scrolledwin = scrolledwin;
5641 compose->text = text;
5643 compose->focused_editable = NULL;
5645 compose->popupmenu = popupmenu;
5646 compose->popupfactory = popupfactory;
5648 compose->tmpl_menu = tmpl_menu;
5650 compose->mode = mode;
5652 compose->targetinfo = NULL;
5653 compose->replyinfo = NULL;
5654 compose->fwdinfo = NULL;
5656 compose->replyto = NULL;
5658 compose->bcc = NULL;
5659 compose->followup_to = NULL;
5661 compose->ml_post = NULL;
5663 compose->inreplyto = NULL;
5664 compose->references = NULL;
5665 compose->msgid = NULL;
5666 compose->boundary = NULL;
5668 compose->autowrap = prefs_common.autowrap;
5670 compose->use_signing = FALSE;
5671 compose->use_encryption = FALSE;
5672 compose->privacy_system = NULL;
5674 compose->modified = FALSE;
5676 compose->return_receipt = FALSE;
5678 compose->to_list = NULL;
5679 compose->newsgroup_list = NULL;
5681 compose->undostruct = undostruct;
5683 compose->sig_str = NULL;
5685 compose->exteditor_file = NULL;
5686 compose->exteditor_pid = -1;
5687 compose->exteditor_tag = -1;
5688 compose->draft_timeout_tag = -1;
5691 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5692 if (mode != COMPOSE_REDIRECT) {
5693 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5694 strcmp(prefs_common.dictionary, _("None"))) {
5695 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5696 prefs_common.dictionary,
5697 conv_get_locale_charset_str(),
5698 prefs_common.misspelled_col,
5699 prefs_common.check_while_typing,
5700 prefs_common.use_alternate,
5701 GTK_TEXT_VIEW(text),
5702 GTK_WINDOW(compose->window));
5704 alertpanel_error(_("Spell checker could not "
5706 gtkaspell_checkers_strerror());
5707 gtkaspell_checkers_reset_error();
5709 if (!gtkaspell_set_sug_mode(gtkaspell,
5710 prefs_common.aspell_sugmode)) {
5711 debug_print("Aspell: could not set "
5712 "suggestion mode %s\n",
5713 gtkaspell_checkers_strerror());
5714 gtkaspell_checkers_reset_error();
5717 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5721 compose->gtkaspell = gtkaspell;
5724 compose_select_account(compose, account, TRUE);
5726 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5727 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5728 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5730 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5731 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5733 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5734 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5737 if (account->protocol != A_NNTP)
5738 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5740 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5742 addressbook_set_target_compose(compose);
5744 if (mode != COMPOSE_REDIRECT)
5745 compose_set_template_menu(compose);
5747 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5748 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5751 compose_list = g_list_append(compose_list, compose);
5753 if (!prefs_common.show_ruler)
5754 gtk_widget_hide(ruler_hbox);
5756 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5757 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5758 prefs_common.show_ruler);
5761 compose->priority = PRIORITY_NORMAL;
5762 compose_update_priority_menu_item(compose);
5764 compose_set_out_encoding(compose);
5767 compose_update_actions_menu(compose);
5769 /* Privacy Systems menu */
5770 compose_update_privacy_systems_menu(compose);
5772 activate_privacy_system(compose, account, TRUE);
5773 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5774 gtk_widget_show(window);
5779 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5785 gint num = 0, def_menu = 0;
5787 accounts = account_get_list();
5788 g_return_val_if_fail(accounts != NULL, NULL);
5790 hbox = gtk_hbox_new(FALSE, 0);
5791 optmenu = gtk_option_menu_new();
5792 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5793 menu = gtk_menu_new();
5795 for (; accounts != NULL; accounts = accounts->next, num++) {
5796 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5797 GtkWidget *menuitem;
5800 if (ac == compose->account) def_menu = num;
5803 name = g_strdup_printf("%s: %s <%s>",
5805 ac->name, ac->address);
5807 name = g_strdup_printf("%s: %s",
5808 ac->account_name, ac->address);
5809 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5811 g_signal_connect(G_OBJECT(menuitem), "activate",
5812 G_CALLBACK(account_activated),
5816 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5817 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5822 static void compose_set_priority_cb(gpointer data,
5826 Compose *compose = (Compose *) data;
5827 compose->priority = action;
5830 static void compose_update_priority_menu_item(Compose * compose)
5832 GtkItemFactory *ifactory;
5833 GtkWidget *menuitem = NULL;
5835 ifactory = gtk_item_factory_from_widget(compose->menubar);
5837 switch (compose->priority) {
5838 case PRIORITY_HIGHEST:
5839 menuitem = gtk_item_factory_get_item
5840 (ifactory, "/Options/Priority/Highest");
5843 menuitem = gtk_item_factory_get_item
5844 (ifactory, "/Options/Priority/High");
5846 case PRIORITY_NORMAL:
5847 menuitem = gtk_item_factory_get_item
5848 (ifactory, "/Options/Priority/Normal");
5851 menuitem = gtk_item_factory_get_item
5852 (ifactory, "/Options/Priority/Low");
5854 case PRIORITY_LOWEST:
5855 menuitem = gtk_item_factory_get_item
5856 (ifactory, "/Options/Priority/Lowest");
5859 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5862 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5864 Compose *compose = (Compose *) data;
5866 GtkItemFactory *ifactory;
5867 gboolean can_sign = FALSE, can_encrypt = FALSE;
5869 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5871 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5874 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5875 g_free(compose->privacy_system);
5876 compose->privacy_system = NULL;
5877 if (systemid != NULL) {
5878 compose->privacy_system = g_strdup(systemid);
5880 can_sign = privacy_system_can_sign(systemid);
5881 can_encrypt = privacy_system_can_encrypt(systemid);
5884 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5886 ifactory = gtk_item_factory_from_widget(compose->menubar);
5887 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5888 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5891 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5893 static gchar *branch_path = "/Options/Privacy System";
5894 GtkItemFactory *ifactory;
5895 GtkWidget *menuitem = NULL;
5897 gboolean can_sign = FALSE, can_encrypt = FALSE;
5898 gboolean found = FALSE;
5900 ifactory = gtk_item_factory_from_widget(compose->menubar);
5902 if (compose->privacy_system != NULL) {
5905 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5906 g_return_if_fail(menuitem != NULL);
5908 amenu = GTK_MENU_SHELL(menuitem)->children;
5910 while (amenu != NULL) {
5911 GList *alist = amenu->next;
5913 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5914 if (systemid != NULL) {
5915 if (strcmp(systemid, compose->privacy_system) == 0) {
5916 menuitem = GTK_WIDGET(amenu->data);
5918 can_sign = privacy_system_can_sign(systemid);
5919 can_encrypt = privacy_system_can_encrypt(systemid);
5923 } else if (strlen(compose->privacy_system) == 0) {
5924 menuitem = GTK_WIDGET(amenu->data);
5927 can_encrypt = FALSE;
5934 if (menuitem != NULL)
5935 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5937 if (warn && !found && strlen(compose->privacy_system)) {
5938 gchar *tmp = g_strdup_printf(
5939 _("The privacy system '%s' cannot be loaded. You "
5940 "will not be able to sign or encrypt this message."),
5941 compose->privacy_system);
5942 alertpanel_warning(tmp);
5947 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5948 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5951 static void compose_set_out_encoding(Compose *compose)
5953 GtkItemFactoryEntry *entry;
5954 GtkItemFactory *ifactory;
5955 CharSet out_encoding;
5956 gchar *path, *p, *q;
5959 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5960 ifactory = gtk_item_factory_from_widget(compose->menubar);
5962 for (entry = compose_entries; entry->callback != compose_address_cb;
5964 if (entry->callback == compose_set_encoding_cb &&
5965 (CharSet)entry->callback_action == out_encoding) {
5966 p = q = path = g_strdup(entry->path);
5978 item = gtk_item_factory_get_item(ifactory, path);
5979 gtk_widget_activate(item);
5986 static void compose_set_template_menu(Compose *compose)
5988 GSList *tmpl_list, *cur;
5992 tmpl_list = template_get_config();
5994 menu = gtk_menu_new();
5996 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5997 Template *tmpl = (Template *)cur->data;
5999 item = gtk_menu_item_new_with_label(tmpl->name);
6000 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6001 g_signal_connect(G_OBJECT(item), "activate",
6002 G_CALLBACK(compose_template_activate_cb),
6004 g_object_set_data(G_OBJECT(item), "template", tmpl);
6005 gtk_widget_show(item);
6008 gtk_widget_show(menu);
6009 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6012 void compose_update_actions_menu(Compose *compose)
6014 GtkItemFactory *ifactory;
6016 ifactory = gtk_item_factory_from_widget(compose->menubar);
6017 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6020 void compose_update_privacy_systems_menu(Compose *compose)
6022 static gchar *branch_path = "/Options/Privacy System";
6023 GtkItemFactory *ifactory;
6024 GtkWidget *menuitem;
6025 GSList *systems, *cur;
6028 GtkWidget *system_none;
6031 ifactory = gtk_item_factory_from_widget(compose->menubar);
6033 /* remove old entries */
6034 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6035 g_return_if_fail(menuitem != NULL);
6037 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6038 while (amenu != NULL) {
6039 GList *alist = amenu->next;
6040 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6044 system_none = gtk_item_factory_get_widget(ifactory,
6045 "/Options/Privacy System/None");
6047 g_signal_connect(G_OBJECT(system_none), "activate",
6048 G_CALLBACK(compose_set_privacy_system_cb), compose);
6050 systems = privacy_get_system_ids();
6051 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6052 gchar *systemid = cur->data;
6054 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6055 widget = gtk_radio_menu_item_new_with_label(group,
6056 privacy_system_get_name(systemid));
6057 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6058 g_strdup(systemid), g_free);
6059 g_signal_connect(G_OBJECT(widget), "activate",
6060 G_CALLBACK(compose_set_privacy_system_cb), compose);
6062 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6063 gtk_widget_show(widget);
6066 g_slist_free(systems);
6069 void compose_reflect_prefs_all(void)
6074 for (cur = compose_list; cur != NULL; cur = cur->next) {
6075 compose = (Compose *)cur->data;
6076 compose_set_template_menu(compose);
6080 void compose_reflect_prefs_pixmap_theme(void)
6085 for (cur = compose_list; cur != NULL; cur = cur->next) {
6086 compose = (Compose *)cur->data;
6087 toolbar_update(TOOLBAR_COMPOSE, compose);
6091 static void compose_template_apply(Compose *compose, Template *tmpl,
6095 GtkTextBuffer *buffer;
6099 gchar *parsed_str = NULL;
6100 gint cursor_pos = 0;
6103 /* process the body */
6105 text = GTK_TEXT_VIEW(compose->text);
6106 buffer = gtk_text_view_get_buffer(text);
6109 gtk_text_buffer_set_text(buffer, "", -1);
6111 mark = gtk_text_buffer_get_insert(buffer);
6112 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6115 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6116 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6119 if (prefs_common.quotemark && *prefs_common.quotemark)
6120 qmark = prefs_common.quotemark;
6124 if (compose->replyinfo != NULL)
6125 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6126 tmpl->value, qmark, NULL, FALSE);
6127 else if (compose->fwdinfo != NULL)
6128 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6129 tmpl->value, qmark, NULL, FALSE);
6134 if (replace && parsed_str && compose->account->auto_sig)
6135 compose_insert_sig(compose, FALSE);
6137 if (replace && parsed_str) {
6138 gtk_text_buffer_get_start_iter(buffer, &iter);
6139 gtk_text_buffer_place_cursor(buffer, &iter);
6143 cursor_pos = quote_fmt_get_cursor_pos();
6144 compose->set_cursor_pos = cursor_pos;
6145 if (cursor_pos == -1)
6147 gtk_text_buffer_get_start_iter(buffer, &iter);
6148 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6149 gtk_text_buffer_place_cursor(buffer, &iter);
6152 /* process the other fields */
6153 compose_template_apply_fields(compose, tmpl);
6155 compose_changed_cb(NULL, compose);
6158 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6160 static MsgInfo dummyinfo;
6161 MsgInfo *msginfo = NULL;
6164 if (compose->replyinfo != NULL)
6165 msginfo = compose->replyinfo;
6166 else if (compose->fwdinfo != NULL)
6167 msginfo = compose->fwdinfo;
6169 msginfo = &dummyinfo;
6171 if (tmpl->to && *tmpl->to != '\0') {
6172 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6173 quote_fmt_scan_string(tmpl->to);
6176 buf = quote_fmt_get_buffer();
6178 alertpanel_error(_("Message To format error."));
6180 compose_entry_append(compose, buf, COMPOSE_TO);
6184 if (tmpl->cc && *tmpl->cc != '\0') {
6185 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6186 quote_fmt_scan_string(tmpl->cc);
6189 buf = quote_fmt_get_buffer();
6191 alertpanel_error(_("Message Cc format error."));
6193 compose_entry_append(compose, buf, COMPOSE_CC);
6197 if (tmpl->bcc && *tmpl->bcc != '\0') {
6198 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6199 quote_fmt_scan_string(tmpl->bcc);
6202 buf = quote_fmt_get_buffer();
6204 alertpanel_error(_("Message Bcc format error."));
6206 compose_entry_append(compose, buf, COMPOSE_BCC);
6210 /* process the subject */
6211 if (tmpl->subject && *tmpl->subject != '\0') {
6212 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6213 quote_fmt_scan_string(tmpl->subject);
6216 buf = quote_fmt_get_buffer();
6218 alertpanel_error(_("Message subject format error."));
6220 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6225 static void compose_destroy(Compose *compose)
6227 compose_list = g_list_remove(compose_list, compose);
6229 /* NOTE: address_completion_end() does nothing with the window
6230 * however this may change. */
6231 address_completion_end(compose->window);
6233 slist_free_strings(compose->to_list);
6234 g_slist_free(compose->to_list);
6235 slist_free_strings(compose->newsgroup_list);
6236 g_slist_free(compose->newsgroup_list);
6237 slist_free_strings(compose->header_list);
6238 g_slist_free(compose->header_list);
6240 procmsg_msginfo_free(compose->targetinfo);
6241 procmsg_msginfo_free(compose->replyinfo);
6242 procmsg_msginfo_free(compose->fwdinfo);
6244 g_free(compose->replyto);
6245 g_free(compose->cc);
6246 g_free(compose->bcc);
6247 g_free(compose->newsgroups);
6248 g_free(compose->followup_to);
6250 g_free(compose->ml_post);
6252 g_free(compose->inreplyto);
6253 g_free(compose->references);
6254 g_free(compose->msgid);
6255 g_free(compose->boundary);
6257 if (compose->redirect_filename)
6258 g_free(compose->redirect_filename);
6259 if (compose->undostruct)
6260 undo_destroy(compose->undostruct);
6262 g_free(compose->sig_str);
6264 g_free(compose->exteditor_file);
6266 g_free(compose->orig_charset);
6268 g_free(compose->privacy_system);
6270 if (addressbook_get_target_compose() == compose)
6271 addressbook_set_target_compose(NULL);
6274 if (compose->gtkaspell) {
6275 gtkaspell_delete(compose->gtkaspell);
6276 compose->gtkaspell = NULL;
6280 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6281 prefs_common.compose_height = compose->window->allocation.height;
6283 if (!gtk_widget_get_parent(compose->paned))
6284 gtk_widget_destroy(compose->paned);
6285 gtk_widget_destroy(compose->popupmenu);
6287 gtk_widget_destroy(compose->window);
6288 toolbar_destroy(compose->toolbar);
6289 g_free(compose->toolbar);
6290 g_mutex_free(compose->mutex);
6294 static void compose_attach_info_free(AttachInfo *ainfo)
6296 g_free(ainfo->file);
6297 g_free(ainfo->content_type);
6298 g_free(ainfo->name);
6302 static void compose_attach_remove_selected(Compose *compose)
6304 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6305 GtkTreeSelection *selection;
6307 GtkTreeModel *model;
6309 selection = gtk_tree_view_get_selection(tree_view);
6310 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6315 for (cur = sel; cur != NULL; cur = cur->next) {
6316 GtkTreePath *path = cur->data;
6317 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6320 gtk_tree_path_free(path);
6323 for (cur = sel; cur != NULL; cur = cur->next) {
6324 GtkTreeRowReference *ref = cur->data;
6325 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6328 if (gtk_tree_model_get_iter(model, &iter, path))
6329 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6331 gtk_tree_path_free(path);
6332 gtk_tree_row_reference_free(ref);
6338 static struct _AttachProperty
6341 GtkWidget *mimetype_entry;
6342 GtkWidget *encoding_optmenu;
6343 GtkWidget *path_entry;
6344 GtkWidget *filename_entry;
6346 GtkWidget *cancel_btn;
6349 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6351 gtk_tree_path_free((GtkTreePath *)ptr);
6354 static void compose_attach_property(Compose *compose)
6356 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6358 GtkOptionMenu *optmenu;
6359 GtkTreeSelection *selection;
6361 GtkTreeModel *model;
6364 static gboolean cancelled;
6366 /* only if one selected */
6367 selection = gtk_tree_view_get_selection(tree_view);
6368 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6371 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6375 path = (GtkTreePath *) sel->data;
6376 gtk_tree_model_get_iter(model, &iter, path);
6377 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6380 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6386 if (!attach_prop.window)
6387 compose_attach_property_create(&cancelled);
6388 gtk_widget_grab_focus(attach_prop.ok_btn);
6389 gtk_widget_show(attach_prop.window);
6390 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6392 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6393 if (ainfo->encoding == ENC_UNKNOWN)
6394 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6395 GINT_TO_POINTER(ENC_BASE64));
6397 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6398 GINT_TO_POINTER(ainfo->encoding));
6400 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6401 ainfo->content_type ? ainfo->content_type : "");
6402 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6403 ainfo->file ? ainfo->file : "");
6404 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6405 ainfo->name ? ainfo->name : "");
6408 const gchar *entry_text;
6410 gchar *cnttype = NULL;
6414 GtkWidget *menuitem;
6419 gtk_widget_hide(attach_prop.window);
6424 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6425 if (*entry_text != '\0') {
6428 text = g_strstrip(g_strdup(entry_text));
6429 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6430 cnttype = g_strdup(text);
6433 alertpanel_error(_("Invalid MIME type."));
6439 menu = gtk_option_menu_get_menu(optmenu);
6440 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6441 ainfo->encoding = GPOINTER_TO_INT
6442 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6444 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6445 if (*entry_text != '\0') {
6446 if (is_file_exist(entry_text) &&
6447 (size = get_file_size(entry_text)) > 0)
6448 file = g_strdup(entry_text);
6451 (_("File doesn't exist or is empty."));
6457 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6458 if (*entry_text != '\0') {
6459 g_free(ainfo->name);
6460 ainfo->name = g_strdup(entry_text);
6464 g_free(ainfo->content_type);
6465 ainfo->content_type = cnttype;
6468 g_free(ainfo->file);
6474 /* update tree store */
6475 text = to_human_readable(ainfo->size);
6476 gtk_tree_model_get_iter(model, &iter, path);
6477 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6478 COL_MIMETYPE, ainfo->content_type,
6480 COL_NAME, ainfo->name,
6486 gtk_tree_path_free(path);
6489 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6491 label = gtk_label_new(str); \
6492 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6493 GTK_FILL, 0, 0, 0); \
6494 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6496 entry = gtk_entry_new(); \
6497 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6498 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6501 static void compose_attach_property_create(gboolean *cancelled)
6507 GtkWidget *mimetype_entry;
6510 GtkWidget *optmenu_menu;
6511 GtkWidget *menuitem;
6512 GtkWidget *path_entry;
6513 GtkWidget *filename_entry;
6516 GtkWidget *cancel_btn;
6517 GList *mime_type_list, *strlist;
6519 debug_print("Creating attach_property window...\n");
6521 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6522 gtk_widget_set_size_request(window, 480, -1);
6523 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6524 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6525 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6526 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6527 g_signal_connect(G_OBJECT(window), "delete_event",
6528 G_CALLBACK(attach_property_delete_event),
6530 g_signal_connect(G_OBJECT(window), "key_press_event",
6531 G_CALLBACK(attach_property_key_pressed),
6534 vbox = gtk_vbox_new(FALSE, 8);
6535 gtk_container_add(GTK_CONTAINER(window), vbox);
6537 table = gtk_table_new(4, 2, FALSE);
6538 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6539 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6540 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6542 label = gtk_label_new(_("MIME type"));
6543 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6545 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6546 mimetype_entry = gtk_combo_new();
6547 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6548 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6550 /* stuff with list */
6551 mime_type_list = procmime_get_mime_type_list();
6553 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6554 MimeType *type = (MimeType *) mime_type_list->data;
6557 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6559 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6562 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6563 (GCompareFunc)strcmp2);
6566 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6568 for (mime_type_list = strlist; mime_type_list != NULL;
6569 mime_type_list = mime_type_list->next)
6570 g_free(mime_type_list->data);
6571 g_list_free(strlist);
6573 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6575 label = gtk_label_new(_("Encoding"));
6576 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6578 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6580 hbox = gtk_hbox_new(FALSE, 0);
6581 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6582 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6584 optmenu = gtk_option_menu_new();
6585 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6587 optmenu_menu = gtk_menu_new();
6588 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6589 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6590 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6591 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6592 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6593 ENC_QUOTED_PRINTABLE);
6594 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6596 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6598 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6600 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6601 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6603 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6604 &ok_btn, GTK_STOCK_OK,
6606 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6607 gtk_widget_grab_default(ok_btn);
6609 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6610 G_CALLBACK(attach_property_ok),
6612 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6613 G_CALLBACK(attach_property_cancel),
6616 gtk_widget_show_all(vbox);
6618 attach_prop.window = window;
6619 attach_prop.mimetype_entry = mimetype_entry;
6620 attach_prop.encoding_optmenu = optmenu;
6621 attach_prop.path_entry = path_entry;
6622 attach_prop.filename_entry = filename_entry;
6623 attach_prop.ok_btn = ok_btn;
6624 attach_prop.cancel_btn = cancel_btn;
6627 #undef SET_LABEL_AND_ENTRY
6629 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6635 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6641 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6642 gboolean *cancelled)
6650 static gboolean attach_property_key_pressed(GtkWidget *widget,
6652 gboolean *cancelled)
6654 if (event && event->keyval == GDK_Escape) {
6661 static void compose_exec_ext_editor(Compose *compose)
6668 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6669 G_DIR_SEPARATOR, compose);
6671 if (pipe(pipe_fds) < 0) {
6677 if ((pid = fork()) < 0) {
6684 /* close the write side of the pipe */
6687 compose->exteditor_file = g_strdup(tmp);
6688 compose->exteditor_pid = pid;
6690 compose_set_ext_editor_sensitive(compose, FALSE);
6692 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6693 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6697 } else { /* process-monitoring process */
6703 /* close the read side of the pipe */
6706 if (compose_write_body_to_file(compose, tmp) < 0) {
6707 fd_write_all(pipe_fds[1], "2\n", 2);
6711 pid_ed = compose_exec_ext_editor_real(tmp);
6713 fd_write_all(pipe_fds[1], "1\n", 2);
6717 /* wait until editor is terminated */
6718 waitpid(pid_ed, NULL, 0);
6720 fd_write_all(pipe_fds[1], "0\n", 2);
6727 #endif /* G_OS_UNIX */
6731 static gint compose_exec_ext_editor_real(const gchar *file)
6738 g_return_val_if_fail(file != NULL, -1);
6740 if ((pid = fork()) < 0) {
6745 if (pid != 0) return pid;
6747 /* grandchild process */
6749 if (setpgid(0, getppid()))
6752 if (prefs_common.ext_editor_cmd &&
6753 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6754 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6755 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6757 if (prefs_common.ext_editor_cmd)
6758 g_warning("External editor command line is invalid: '%s'\n",
6759 prefs_common.ext_editor_cmd);
6760 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
6763 cmdline = strsplit_with_quote(buf, " ", 1024);
6764 execvp(cmdline[0], cmdline);
6767 g_strfreev(cmdline);
6772 static gboolean compose_ext_editor_kill(Compose *compose)
6774 pid_t pgid = compose->exteditor_pid * -1;
6777 ret = kill(pgid, 0);
6779 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6783 msg = g_strdup_printf
6784 (_("The external editor is still working.\n"
6785 "Force terminating the process?\n"
6786 "process group id: %d"), -pgid);
6787 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
6788 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
6792 if (val == G_ALERTALTERNATE) {
6793 g_source_remove(compose->exteditor_tag);
6794 g_io_channel_shutdown(compose->exteditor_ch,
6796 g_io_channel_unref(compose->exteditor_ch);
6798 if (kill(pgid, SIGTERM) < 0) perror("kill");
6799 waitpid(compose->exteditor_pid, NULL, 0);
6801 g_warning("Terminated process group id: %d", -pgid);
6802 g_warning("Temporary file: %s",
6803 compose->exteditor_file);
6805 compose_set_ext_editor_sensitive(compose, TRUE);
6807 g_free(compose->exteditor_file);
6808 compose->exteditor_file = NULL;
6809 compose->exteditor_pid = -1;
6810 compose->exteditor_ch = NULL;
6811 compose->exteditor_tag = -1;
6819 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6823 Compose *compose = (Compose *)data;
6826 debug_print(_("Compose: input from monitoring process\n"));
6828 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6830 g_io_channel_shutdown(source, FALSE, NULL);
6831 g_io_channel_unref(source);
6833 waitpid(compose->exteditor_pid, NULL, 0);
6835 if (buf[0] == '0') { /* success */
6836 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6837 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6839 gtk_text_buffer_set_text(buffer, "", -1);
6840 compose_insert_file(compose, compose->exteditor_file);
6841 compose_changed_cb(NULL, compose);
6843 if (g_unlink(compose->exteditor_file) < 0)
6844 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6845 } else if (buf[0] == '1') { /* failed */
6846 g_warning("Couldn't exec external editor\n");
6847 if (g_unlink(compose->exteditor_file) < 0)
6848 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6849 } else if (buf[0] == '2') {
6850 g_warning("Couldn't write to file\n");
6851 } else if (buf[0] == '3') {
6852 g_warning("Pipe read failed\n");
6855 compose_set_ext_editor_sensitive(compose, TRUE);
6857 g_free(compose->exteditor_file);
6858 compose->exteditor_file = NULL;
6859 compose->exteditor_pid = -1;
6860 compose->exteditor_ch = NULL;
6861 compose->exteditor_tag = -1;
6866 static void compose_set_ext_editor_sensitive(Compose *compose,
6869 GtkItemFactory *ifactory;
6871 ifactory = gtk_item_factory_from_widget(compose->menubar);
6873 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6874 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6875 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6876 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6877 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6878 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6879 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6882 gtk_widget_set_sensitive(compose->text, sensitive);
6883 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6884 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6885 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6886 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6887 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6888 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6889 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6890 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6892 #endif /* G_OS_UNIX */
6895 * compose_undo_state_changed:
6897 * Change the sensivity of the menuentries undo and redo
6899 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6900 gint redo_state, gpointer data)
6902 GtkWidget *widget = GTK_WIDGET(data);
6903 GtkItemFactory *ifactory;
6905 g_return_if_fail(widget != NULL);
6907 ifactory = gtk_item_factory_from_widget(widget);
6909 switch (undo_state) {
6910 case UNDO_STATE_TRUE:
6911 if (!undostruct->undo_state) {
6912 undostruct->undo_state = TRUE;
6913 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6916 case UNDO_STATE_FALSE:
6917 if (undostruct->undo_state) {
6918 undostruct->undo_state = FALSE;
6919 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6922 case UNDO_STATE_UNCHANGED:
6924 case UNDO_STATE_REFRESH:
6925 menu_set_sensitive(ifactory, "/Edit/Undo",
6926 undostruct->undo_state);
6929 g_warning("Undo state not recognized");
6933 switch (redo_state) {
6934 case UNDO_STATE_TRUE:
6935 if (!undostruct->redo_state) {
6936 undostruct->redo_state = TRUE;
6937 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6940 case UNDO_STATE_FALSE:
6941 if (undostruct->redo_state) {
6942 undostruct->redo_state = FALSE;
6943 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6946 case UNDO_STATE_UNCHANGED:
6948 case UNDO_STATE_REFRESH:
6949 menu_set_sensitive(ifactory, "/Edit/Redo",
6950 undostruct->redo_state);
6953 g_warning("Redo state not recognized");
6958 /* callback functions */
6960 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6961 * includes "non-client" (windows-izm) in calculation, so this calculation
6962 * may not be accurate.
6964 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6965 GtkAllocation *allocation,
6966 GtkSHRuler *shruler)
6968 if (prefs_common.show_ruler) {
6969 gint char_width = 0, char_height = 0;
6970 gint line_width_in_chars;
6972 gtkut_get_font_size(GTK_WIDGET(widget),
6973 &char_width, &char_height);
6974 line_width_in_chars =
6975 (allocation->width - allocation->x) / char_width;
6977 /* got the maximum */
6978 gtk_ruler_set_range(GTK_RULER(shruler),
6979 0.0, line_width_in_chars, 0,
6980 /*line_width_in_chars*/ char_width);
6986 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6988 Compose *compose = (Compose *)data;
6991 gchar *folderidentifier;
6993 ac = account_find_from_id(
6994 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6995 g_return_if_fail(ac != NULL);
6997 if (ac != compose->account)
6998 compose_select_account(compose, ac, FALSE);
7000 /* Set message save folder */
7001 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7002 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7004 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7005 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7007 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7008 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7009 folderidentifier = folder_item_get_identifier(account_get_special_folder
7010 (compose->account, F_OUTBOX));
7011 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7012 g_free(folderidentifier);
7016 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7017 GtkTreeViewColumn *column, Compose *compose)
7019 compose_attach_property(compose);
7022 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7025 Compose *compose = (Compose *)data;
7026 GtkTreeSelection *attach_selection;
7027 gint attach_nr_selected;
7028 GtkItemFactory *ifactory;
7030 if (!event) return FALSE;
7032 if (event->button == 3) {
7033 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7034 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7035 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7037 if (attach_nr_selected > 0)
7039 menu_set_sensitive(ifactory, "/Remove", TRUE);
7040 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7042 menu_set_sensitive(ifactory, "/Remove", FALSE);
7043 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7046 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7047 NULL, NULL, event->button, event->time);
7054 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7057 Compose *compose = (Compose *)data;
7059 if (!event) return FALSE;
7061 switch (event->keyval) {
7063 compose_attach_remove_selected(compose);
7069 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7071 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7072 toolbar_comp_set_sensitive(compose, allow);
7073 menu_set_sensitive(ifactory, "/Message", allow);
7074 menu_set_sensitive(ifactory, "/Edit", allow);
7076 menu_set_sensitive(ifactory, "/Spelling", allow);
7078 menu_set_sensitive(ifactory, "/Options", allow);
7079 menu_set_sensitive(ifactory, "/Tools", allow);
7080 menu_set_sensitive(ifactory, "/Help", allow);
7082 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7086 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7088 Compose *compose = (Compose *)data;
7090 if (prefs_common.work_offline && !inc_offline_should_override())
7093 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7094 gtk_timeout_remove(compose->draft_timeout_tag);
7095 compose->draft_timeout_tag = -1;
7098 compose_send(compose);
7101 static void compose_send_later_cb(gpointer data, guint action,
7104 Compose *compose = (Compose *)data;
7107 val = compose_queue_sub(compose, NULL, NULL, TRUE);
7109 compose_close(compose);
7110 else if (val == -2) {
7111 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7115 void compose_draft (gpointer data)
7117 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7120 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7122 Compose *compose = (Compose *)data;
7126 MsgFlags flag = {0, 0};
7127 static gboolean lock = FALSE;
7128 MsgInfo *newmsginfo;
7130 gboolean target_locked = FALSE;
7134 draft = account_get_special_folder(compose->account, F_DRAFT);
7135 g_return_if_fail(draft != NULL);
7137 if (!g_mutex_trylock(compose->mutex)) {
7138 /* we don't want to lock the mutex once it's available,
7139 * because as the only other part of compose.c locking
7140 * it is compose_close - which means once unlocked,
7141 * the compose struct will be freed */
7142 debug_print("couldn't lock mutex, probably sending\n");
7148 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7149 G_DIR_SEPARATOR, compose);
7150 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7151 FILE_OP_ERROR(tmp, "fopen");
7155 /* chmod for security */
7156 if (change_file_mode_rw(fp, tmp) < 0) {
7157 FILE_OP_ERROR(tmp, "chmod");
7158 g_warning("can't change file mode\n");
7161 /* Save draft infos */
7162 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7163 fprintf(fp, "S:%s\n", compose->account->address);
7164 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7165 gchar *savefolderid;
7167 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7168 fprintf(fp, "SCF:%s\n", savefolderid);
7169 g_free(savefolderid);
7171 if (compose->return_receipt) {
7172 fprintf(fp, "RRCPT:1\n");
7174 if (compose->privacy_system) {
7175 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7176 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7177 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7181 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7189 if (compose->targetinfo) {
7190 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7191 flag.perm_flags = target_locked?MSG_LOCKED:0;
7193 flag.tmp_flags = MSG_DRAFT;
7195 folder_item_scan(draft);
7196 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7199 if (action != COMPOSE_AUTO_SAVE)
7200 alertpanel_error(_("Could not save draft."));
7204 draft->mtime = 0; /* force updating */
7206 if (compose->mode == COMPOSE_REEDIT) {
7207 compose_remove_reedit_target(compose, TRUE);
7210 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7212 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7214 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7216 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7217 if (compose_use_attach(compose))
7218 procmsg_msginfo_set_flags(newmsginfo, 0,
7219 MSG_HAS_ATTACHMENT);
7221 procmsg_msginfo_free(newmsginfo);
7224 folder_item_scan(draft);
7226 if (action == COMPOSE_QUIT_EDITING) {
7228 g_mutex_unlock(compose->mutex); /* must be done before closing */
7229 compose_close(compose);
7235 path = folder_item_fetch_msg(draft, msgnum);
7237 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7240 if (g_stat(path, &s) < 0) {
7241 FILE_OP_ERROR(path, "stat");
7247 procmsg_msginfo_free(compose->targetinfo);
7248 compose->targetinfo = procmsg_msginfo_new();
7249 compose->targetinfo->msgnum = msgnum;
7250 compose->targetinfo->size = s.st_size;
7251 compose->targetinfo->mtime = s.st_mtime;
7252 compose->targetinfo->folder = draft;
7254 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7255 compose->mode = COMPOSE_REEDIT;
7257 if (action == COMPOSE_AUTO_SAVE) {
7258 compose->autosaved_draft = compose->targetinfo;
7260 compose->modified = FALSE;
7261 compose_set_title(compose);
7265 g_mutex_unlock(compose->mutex);
7268 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7270 Compose *compose = (Compose *)data;
7273 if (compose->redirect_filename != NULL)
7276 file_list = filesel_select_multiple_files_open(_("Select file"));
7281 for ( tmp = file_list; tmp; tmp = tmp->next) {
7282 gchar *file = (gchar *) tmp->data;
7283 gchar *utf8_filename = conv_filename_to_utf8(file);
7284 compose_attach_append(compose, file, utf8_filename, NULL);
7285 compose_changed_cb(NULL, compose);
7287 g_free(utf8_filename);
7289 g_list_free(file_list);
7293 static void compose_insert_file_cb(gpointer data, guint action,
7296 Compose *compose = (Compose *)data;
7299 file_list = filesel_select_multiple_files_open(_("Select file"));
7304 for ( tmp = file_list; tmp; tmp = tmp->next) {
7305 gchar *file = (gchar *) tmp->data;
7306 gchar *filedup = g_strdup(file);
7307 gchar *shortfile = g_path_get_basename(filedup);
7308 ComposeInsertResult res;
7310 res = compose_insert_file(compose, file);
7311 if (res == COMPOSE_INSERT_READ_ERROR) {
7312 alertpanel_error(_("File '%s' could not be read."), shortfile);
7313 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7314 alertpanel_error(_("File '%s' contained invalid characters\n"
7315 "for the current encoding, insertion may be incorrect."), shortfile);
7321 g_list_free(file_list);
7325 static void compose_insert_sig_cb(gpointer data, guint action,
7328 Compose *compose = (Compose *)data;
7330 compose_insert_sig(compose, FALSE);
7333 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7337 Compose *compose = (Compose *)data;
7339 gtkut_widget_get_uposition(widget, &x, &y);
7340 prefs_common.compose_x = x;
7341 prefs_common.compose_y = y;
7343 if (compose->sending)
7345 compose_close_cb(compose, 0, NULL);
7349 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7351 Compose *compose = (Compose *)data;
7355 if (compose->exteditor_tag != -1) {
7356 if (!compose_ext_editor_kill(compose))
7361 if (compose->modified) {
7362 val = alertpanel(_("Discard message"),
7363 _("This message has been modified. Discard it?"),
7364 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7367 case G_ALERTDEFAULT:
7368 if (prefs_common.autosave)
7369 compose_remove_draft(compose);
7371 case G_ALERTALTERNATE:
7372 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7379 compose_close(compose);
7382 static void compose_set_encoding_cb(gpointer data, guint action,
7385 Compose *compose = (Compose *)data;
7387 if (GTK_CHECK_MENU_ITEM(widget)->active)
7388 compose->out_encoding = (CharSet)action;
7391 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7393 Compose *compose = (Compose *)data;
7395 addressbook_open(compose);
7398 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7400 Compose *compose = (Compose *)data;
7405 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7406 g_return_if_fail(tmpl != NULL);
7408 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7410 val = alertpanel(_("Apply template"), msg,
7411 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7414 if (val == G_ALERTDEFAULT)
7415 compose_template_apply(compose, tmpl, TRUE);
7416 else if (val == G_ALERTALTERNATE)
7417 compose_template_apply(compose, tmpl, FALSE);
7420 static void compose_ext_editor_cb(gpointer data, guint action,
7423 Compose *compose = (Compose *)data;
7425 compose_exec_ext_editor(compose);
7428 static void compose_undo_cb(Compose *compose)
7430 gboolean prev_autowrap = compose->autowrap;
7432 compose->autowrap = FALSE;
7433 undo_undo(compose->undostruct);
7434 compose->autowrap = prev_autowrap;
7437 static void compose_redo_cb(Compose *compose)
7439 gboolean prev_autowrap = compose->autowrap;
7441 compose->autowrap = FALSE;
7442 undo_redo(compose->undostruct);
7443 compose->autowrap = prev_autowrap;
7446 static void entry_cut_clipboard(GtkWidget *entry)
7448 if (GTK_IS_EDITABLE(entry))
7449 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7450 else if (GTK_IS_TEXT_VIEW(entry))
7451 gtk_text_buffer_cut_clipboard(
7452 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7453 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7457 static void entry_copy_clipboard(GtkWidget *entry)
7459 if (GTK_IS_EDITABLE(entry))
7460 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7461 else if (GTK_IS_TEXT_VIEW(entry))
7462 gtk_text_buffer_copy_clipboard(
7463 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7464 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7467 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7468 gboolean wrap, GdkAtom clip)
7470 if (GTK_IS_TEXT_VIEW(entry)) {
7471 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7472 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7473 GtkTextIter start_iter, end_iter;
7476 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7478 if (contents == NULL)
7481 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7482 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7484 start = gtk_text_iter_get_offset(&start_iter);
7486 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7489 end = start + strlen(contents);
7490 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7491 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7492 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7493 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7494 mark_start = gtk_text_buffer_get_insert(buffer);
7495 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7496 gtk_text_iter_backward_char(&start_iter);
7497 compose_beautify_paragraph(compose, &start_iter, TRUE);
7500 } else if (GTK_IS_EDITABLE(entry))
7501 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7505 static void entry_allsel(GtkWidget *entry)
7507 if (GTK_IS_EDITABLE(entry))
7508 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7509 else if (GTK_IS_TEXT_VIEW(entry)) {
7510 GtkTextIter startiter, enditer;
7511 GtkTextBuffer *textbuf;
7513 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7514 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7515 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7517 gtk_text_buffer_move_mark_by_name(textbuf,
7518 "selection_bound", &startiter);
7519 gtk_text_buffer_move_mark_by_name(textbuf,
7520 "insert", &enditer);
7524 static void compose_cut_cb(Compose *compose)
7526 if (compose->focused_editable &&
7527 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7528 entry_cut_clipboard(compose->focused_editable);
7531 static void compose_copy_cb(Compose *compose)
7533 if (compose->focused_editable &&
7534 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7535 entry_copy_clipboard(compose->focused_editable);
7538 static void compose_paste_cb(Compose *compose)
7541 GtkTextBuffer *buffer;
7543 if (compose->focused_editable &&
7544 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7545 entry_paste_clipboard(compose, compose->focused_editable,
7546 prefs_common.linewrap_pastes,
7547 GDK_SELECTION_CLIPBOARD);
7551 static void compose_paste_as_quote_cb(Compose *compose)
7553 gint wrap_quote = prefs_common.linewrap_quote;
7554 if (compose->focused_editable &&
7555 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7556 /* let text_insert() (called directly or at a later time
7557 * after the gtk_editable_paste_clipboard) know that
7558 * text is to be inserted as a quotation. implemented
7559 * by using a simple refcount... */
7560 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7561 G_OBJECT(compose->focused_editable),
7562 "paste_as_quotation"));
7563 g_object_set_data(G_OBJECT(compose->focused_editable),
7564 "paste_as_quotation",
7565 GINT_TO_POINTER(paste_as_quotation + 1));
7566 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7567 entry_paste_clipboard(compose, compose->focused_editable,
7568 prefs_common.linewrap_pastes,
7569 GDK_SELECTION_CLIPBOARD);
7570 prefs_common.linewrap_quote = wrap_quote;
7574 static void compose_paste_no_wrap_cb(Compose *compose)
7577 GtkTextBuffer *buffer;
7579 if (compose->focused_editable &&
7580 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7581 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7582 GDK_SELECTION_CLIPBOARD);
7586 static void compose_paste_wrap_cb(Compose *compose)
7589 GtkTextBuffer *buffer;
7591 if (compose->focused_editable &&
7592 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7593 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7594 GDK_SELECTION_CLIPBOARD);
7598 static void compose_allsel_cb(Compose *compose)
7600 if (compose->focused_editable &&
7601 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7602 entry_allsel(compose->focused_editable);
7605 static void textview_move_beginning_of_line (GtkTextView *text)
7607 GtkTextBuffer *buffer;
7611 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7613 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7614 mark = gtk_text_buffer_get_insert(buffer);
7615 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7616 gtk_text_iter_set_line_offset(&ins, 0);
7617 gtk_text_buffer_place_cursor(buffer, &ins);
7620 static void textview_move_forward_character (GtkTextView *text)
7622 GtkTextBuffer *buffer;
7626 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7628 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7629 mark = gtk_text_buffer_get_insert(buffer);
7630 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7631 if (gtk_text_iter_forward_cursor_position(&ins))
7632 gtk_text_buffer_place_cursor(buffer, &ins);
7635 static void textview_move_backward_character (GtkTextView *text)
7637 GtkTextBuffer *buffer;
7641 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7643 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7644 mark = gtk_text_buffer_get_insert(buffer);
7645 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7646 if (gtk_text_iter_backward_cursor_position(&ins))
7647 gtk_text_buffer_place_cursor(buffer, &ins);
7650 static void textview_move_forward_word (GtkTextView *text)
7652 GtkTextBuffer *buffer;
7657 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7659 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7660 mark = gtk_text_buffer_get_insert(buffer);
7661 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7662 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7663 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7664 gtk_text_iter_backward_word_start(&ins);
7665 gtk_text_buffer_place_cursor(buffer, &ins);
7669 static void textview_move_backward_word (GtkTextView *text)
7671 GtkTextBuffer *buffer;
7676 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7678 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7679 mark = gtk_text_buffer_get_insert(buffer);
7680 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7681 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7682 if (gtk_text_iter_backward_word_starts(&ins, 1))
7683 gtk_text_buffer_place_cursor(buffer, &ins);
7686 static void textview_move_end_of_line (GtkTextView *text)
7688 GtkTextBuffer *buffer;
7692 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7694 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7695 mark = gtk_text_buffer_get_insert(buffer);
7696 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7697 if (gtk_text_iter_forward_to_line_end(&ins))
7698 gtk_text_buffer_place_cursor(buffer, &ins);
7701 static void textview_move_next_line (GtkTextView *text)
7703 GtkTextBuffer *buffer;
7708 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7710 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7711 mark = gtk_text_buffer_get_insert(buffer);
7712 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7713 offset = gtk_text_iter_get_line_offset(&ins);
7714 if (gtk_text_iter_forward_line(&ins)) {
7715 gtk_text_iter_set_line_offset(&ins, offset);
7716 gtk_text_buffer_place_cursor(buffer, &ins);
7720 static void textview_move_previous_line (GtkTextView *text)
7722 GtkTextBuffer *buffer;
7727 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7729 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7730 mark = gtk_text_buffer_get_insert(buffer);
7731 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7732 offset = gtk_text_iter_get_line_offset(&ins);
7733 if (gtk_text_iter_backward_line(&ins)) {
7734 gtk_text_iter_set_line_offset(&ins, offset);
7735 gtk_text_buffer_place_cursor(buffer, &ins);
7739 static void textview_delete_forward_character (GtkTextView *text)
7741 GtkTextBuffer *buffer;
7743 GtkTextIter ins, end_iter;
7745 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7747 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7748 mark = gtk_text_buffer_get_insert(buffer);
7749 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7751 if (gtk_text_iter_forward_char(&end_iter)) {
7752 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7756 static void textview_delete_backward_character (GtkTextView *text)
7758 GtkTextBuffer *buffer;
7760 GtkTextIter ins, end_iter;
7762 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7764 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7765 mark = gtk_text_buffer_get_insert(buffer);
7766 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7768 if (gtk_text_iter_backward_char(&end_iter)) {
7769 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7773 static void textview_delete_forward_word (GtkTextView *text)
7775 GtkTextBuffer *buffer;
7777 GtkTextIter ins, end_iter;
7779 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7781 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7782 mark = gtk_text_buffer_get_insert(buffer);
7783 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7785 if (gtk_text_iter_forward_word_end(&end_iter)) {
7786 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7790 static void textview_delete_backward_word (GtkTextView *text)
7792 GtkTextBuffer *buffer;
7794 GtkTextIter ins, end_iter;
7796 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7798 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7799 mark = gtk_text_buffer_get_insert(buffer);
7800 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7802 if (gtk_text_iter_backward_word_start(&end_iter)) {
7803 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7807 static void textview_delete_line (GtkTextView *text)
7809 GtkTextBuffer *buffer;
7811 GtkTextIter ins, start_iter, end_iter;
7814 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7816 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7817 mark = gtk_text_buffer_get_insert(buffer);
7818 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7821 gtk_text_iter_set_line_offset(&start_iter, 0);
7824 if (gtk_text_iter_ends_line(&end_iter))
7825 found = gtk_text_iter_forward_char(&end_iter);
7827 found = gtk_text_iter_forward_to_line_end(&end_iter);
7830 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7833 static void textview_delete_to_line_end (GtkTextView *text)
7835 GtkTextBuffer *buffer;
7837 GtkTextIter ins, end_iter;
7840 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7842 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7843 mark = gtk_text_buffer_get_insert(buffer);
7844 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7846 if (gtk_text_iter_ends_line(&end_iter))
7847 found = gtk_text_iter_forward_char(&end_iter);
7849 found = gtk_text_iter_forward_to_line_end(&end_iter);
7851 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7854 static void compose_advanced_action_cb(Compose *compose,
7855 ComposeCallAdvancedAction action)
7857 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7859 void (*do_action) (GtkTextView *text);
7860 } action_table[] = {
7861 {textview_move_beginning_of_line},
7862 {textview_move_forward_character},
7863 {textview_move_backward_character},
7864 {textview_move_forward_word},
7865 {textview_move_backward_word},
7866 {textview_move_end_of_line},
7867 {textview_move_next_line},
7868 {textview_move_previous_line},
7869 {textview_delete_forward_character},
7870 {textview_delete_backward_character},
7871 {textview_delete_forward_word},
7872 {textview_delete_backward_word},
7873 {textview_delete_line},
7874 {NULL}, /* gtk_stext_delete_line_n */
7875 {textview_delete_to_line_end}
7878 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7880 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7881 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7882 if (action_table[action].do_action)
7883 action_table[action].do_action(text);
7885 g_warning("Not implemented yet.");
7889 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7893 if (GTK_IS_EDITABLE(widget)) {
7894 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7895 gtk_editable_set_position(GTK_EDITABLE(widget),
7898 if (widget->parent && widget->parent->parent
7899 && widget->parent->parent->parent) {
7900 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7901 gint y = widget->allocation.y;
7902 gint height = widget->allocation.height;
7903 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7904 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7906 if (y < (int)shown->value) {
7907 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7909 if (y + height > (int)shown->value + (int)shown->page_size) {
7910 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7911 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7912 y + height - (int)shown->page_size - 1);
7914 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7915 (int)shown->upper - (int)shown->page_size - 1);
7922 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7923 compose->focused_editable = widget;
7926 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7928 compose->modified = TRUE;
7929 compose_set_title(compose);
7932 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7934 Compose *compose = (Compose *)data;
7937 compose_wrap_all_full(compose, TRUE);
7939 compose_beautify_paragraph(compose, NULL, TRUE);
7942 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
7944 Compose *compose = (Compose *)data;
7946 message_search_compose(compose);
7949 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7952 Compose *compose = (Compose *)data;
7953 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7954 if (compose->autowrap)
7955 compose_wrap_all_full(compose, TRUE);
7956 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7959 static void compose_toggle_sign_cb(gpointer data, guint action,
7962 Compose *compose = (Compose *)data;
7964 if (GTK_CHECK_MENU_ITEM(widget)->active)
7965 compose->use_signing = TRUE;
7967 compose->use_signing = FALSE;
7970 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7973 Compose *compose = (Compose *)data;
7975 if (GTK_CHECK_MENU_ITEM(widget)->active)
7976 compose->use_encryption = TRUE;
7978 compose->use_encryption = FALSE;
7981 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7983 g_free(compose->privacy_system);
7985 compose->privacy_system = g_strdup(account->default_privacy_system);
7986 compose_update_privacy_system_menu_item(compose, warn);
7989 static void compose_toggle_ruler_cb(gpointer data, guint action,
7992 Compose *compose = (Compose *)data;
7994 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7995 gtk_widget_show(compose->ruler_hbox);
7996 prefs_common.show_ruler = TRUE;
7998 gtk_widget_hide(compose->ruler_hbox);
7999 gtk_widget_queue_resize(compose->edit_vbox);
8000 prefs_common.show_ruler = FALSE;
8004 static void compose_attach_drag_received_cb (GtkWidget *widget,
8005 GdkDragContext *context,
8008 GtkSelectionData *data,
8013 Compose *compose = (Compose *)user_data;
8016 if (gdk_atom_name(data->type) &&
8017 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8018 && gtk_drag_get_source_widget(context) !=
8019 mainwindow_get_mainwindow()->summaryview->ctree) {
8020 list = uri_list_extract_filenames((const gchar *)data->data);
8021 for (tmp = list; tmp != NULL; tmp = tmp->next)
8022 compose_attach_append
8023 (compose, (const gchar *)tmp->data,
8024 (const gchar *)tmp->data, NULL);
8025 if (list) compose_changed_cb(NULL, compose);
8026 list_free_strings(list);
8028 } else if (gtk_drag_get_source_widget(context)
8029 == mainwindow_get_mainwindow()->summaryview->ctree) {
8030 /* comes from our summaryview */
8031 SummaryView * summaryview = NULL;
8032 GSList * list = NULL, *cur = NULL;
8034 if (mainwindow_get_mainwindow())
8035 summaryview = mainwindow_get_mainwindow()->summaryview;
8038 list = summary_get_selected_msg_list(summaryview);
8040 for (cur = list; cur; cur = cur->next) {
8041 MsgInfo *msginfo = (MsgInfo *)cur->data;
8044 file = procmsg_get_message_file_full(msginfo,
8047 compose_attach_append(compose, (const gchar *)file,
8048 (const gchar *)file, "message/rfc822");
8056 static gboolean compose_drag_drop(GtkWidget *widget,
8057 GdkDragContext *drag_context,
8059 guint time, gpointer user_data)
8061 /* not handling this signal makes compose_insert_drag_received_cb
8066 static void compose_insert_drag_received_cb (GtkWidget *widget,
8067 GdkDragContext *drag_context,
8070 GtkSelectionData *data,
8075 Compose *compose = (Compose *)user_data;
8078 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8080 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8081 list = uri_list_extract_filenames((const gchar *)data->data);
8082 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8083 compose_insert_file(compose, (const gchar *)tmp->data);
8085 list_free_strings(list);
8087 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8090 #if GTK_CHECK_VERSION(2, 8, 0)
8091 /* do nothing, handled by GTK */
8093 gchar *tmpfile = get_tmp_file();
8094 str_write_to_file((const gchar *)data->data, tmpfile);
8095 compose_insert_file(compose, tmpfile);
8098 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8102 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8105 static void compose_header_drag_received_cb (GtkWidget *widget,
8106 GdkDragContext *drag_context,
8109 GtkSelectionData *data,
8114 GtkEditable *entry = (GtkEditable *)user_data;
8115 gchar *email = (gchar *)data->data;
8117 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8120 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8121 gchar *decoded=g_new(gchar, strlen(email));
8124 email += strlen("mailto:");
8125 decode_uri(decoded, email); /* will fit */
8126 gtk_editable_delete_text(entry, 0, -1);
8127 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8128 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8132 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8135 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8138 Compose *compose = (Compose *)data;
8140 if (GTK_CHECK_MENU_ITEM(widget)->active)
8141 compose->return_receipt = TRUE;
8143 compose->return_receipt = FALSE;
8146 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8149 Compose *compose = (Compose *)data;
8151 if (GTK_CHECK_MENU_ITEM(widget)->active)
8152 compose->remove_references = TRUE;
8154 compose->remove_references = FALSE;
8157 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8159 ComposeHeaderEntry *headerentry)
8161 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8162 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8163 !(event->state & GDK_MODIFIER_MASK) &&
8164 (event->keyval == GDK_BackSpace) &&
8165 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8166 gtk_container_remove
8167 (GTK_CONTAINER(headerentry->compose->header_table),
8168 headerentry->combo);
8169 gtk_container_remove
8170 (GTK_CONTAINER(headerentry->compose->header_table),
8171 headerentry->entry);
8172 headerentry->compose->header_list =
8173 g_slist_remove(headerentry->compose->header_list,
8175 g_free(headerentry);
8176 } else if (event->keyval == GDK_Tab) {
8177 if (headerentry->compose->header_last == headerentry) {
8178 /* Override default next focus, and give it to subject_entry
8179 * instead of notebook tabs
8181 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8182 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8189 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8190 ComposeHeaderEntry *headerentry)
8192 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8193 headerentry->compose->header_list =
8194 g_slist_append(headerentry->compose->header_list,
8197 compose_create_header_entry(headerentry->compose);
8198 g_signal_handlers_disconnect_matched
8199 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8200 0, 0, NULL, NULL, headerentry);
8202 /* Automatically scroll down */
8203 compose_show_first_last_header(headerentry->compose, FALSE);
8209 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8211 GtkAdjustment *vadj;
8213 g_return_if_fail(compose);
8214 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8215 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8217 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8218 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8221 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8222 const gchar *text, gint len, Compose *compose)
8224 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8225 (G_OBJECT(compose->text), "paste_as_quotation"));
8228 g_return_if_fail(text != NULL);
8230 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8231 G_CALLBACK(text_inserted),
8233 if (paste_as_quotation) {
8240 new_text = g_strndup(text, len);
8241 if (prefs_common.quotemark && *prefs_common.quotemark)
8242 qmark = prefs_common.quotemark;
8246 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8247 gtk_text_buffer_place_cursor(buffer, iter);
8249 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8251 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8252 GINT_TO_POINTER(paste_as_quotation - 1));
8254 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8255 gtk_text_buffer_place_cursor(buffer, iter);
8257 if (strcmp(text, "\n") || automatic_break
8258 || gtk_text_iter_starts_line(iter))
8259 gtk_text_buffer_insert(buffer, iter, text, len);
8261 debug_print("insert nowrap \\n\n");
8262 gtk_text_buffer_insert_with_tags_by_name(buffer,
8263 iter, text, len, "no_join", NULL);
8267 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8269 compose_beautify_paragraph(compose, iter, FALSE);
8271 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8272 gtk_text_buffer_delete_mark(buffer, mark);
8274 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8275 G_CALLBACK(text_inserted),
8277 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8279 if (prefs_common.autosave &&
8280 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8281 compose->draft_timeout_tag = gtk_timeout_add
8282 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8284 static gint compose_defer_auto_save_draft(Compose *compose)
8286 compose->draft_timeout_tag = -1;
8287 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8292 static void compose_check_all(Compose *compose)
8294 if (compose->gtkaspell)
8295 gtkaspell_check_all(compose->gtkaspell);
8298 static void compose_highlight_all(Compose *compose)
8300 if (compose->gtkaspell)
8301 gtkaspell_highlight_all(compose->gtkaspell);
8304 static void compose_check_backwards(Compose *compose)
8306 if (compose->gtkaspell)
8307 gtkaspell_check_backwards(compose->gtkaspell);
8309 GtkItemFactory *ifactory;
8310 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8311 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8312 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8316 static void compose_check_forwards_go(Compose *compose)
8318 if (compose->gtkaspell)
8319 gtkaspell_check_forwards_go(compose->gtkaspell);
8321 GtkItemFactory *ifactory;
8322 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8323 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8324 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8330 *\brief Guess originating forward account from MsgInfo and several
8331 * "common preference" settings. Return NULL if no guess.
8333 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8335 PrefsAccount *account = NULL;
8337 g_return_val_if_fail(msginfo, NULL);
8338 g_return_val_if_fail(msginfo->folder, NULL);
8339 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8341 if (msginfo->folder->prefs->enable_default_account)
8342 account = account_find_from_id(msginfo->folder->prefs->default_account);
8345 account = msginfo->folder->folder->account;
8347 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8349 Xstrdup_a(to, msginfo->to, return NULL);
8350 extract_address(to);
8351 account = account_find_from_address(to);
8354 if (!account && prefs_common.forward_account_autosel) {
8356 if (!procheader_get_header_from_msginfo
8357 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8358 extract_address(cc);
8359 account = account_find_from_address(cc);
8366 static gboolean compose_close(Compose *compose)
8370 if (!g_mutex_trylock(compose->mutex)) {
8371 /* we have to wait for the (possibly deferred by auto-save)
8372 * drafting to be done, before destroying the compose under
8374 debug_print("waiting for drafting to finish...\n");
8375 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8378 g_return_val_if_fail(compose, FALSE);
8379 gtkut_widget_get_uposition(compose->window, &x, &y);
8380 prefs_common.compose_x = x;
8381 prefs_common.compose_y = y;
8382 g_mutex_unlock(compose->mutex);
8383 compose_destroy(compose);
8388 * Add entry field for each address in list.
8389 * \param compose E-Mail composition object.
8390 * \param listAddress List of (formatted) E-Mail addresses.
8392 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8397 addr = ( gchar * ) node->data;
8398 compose_entry_append( compose, addr, COMPOSE_TO );
8399 node = g_list_next( node );
8403 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8407 GSList *new_msglist = NULL;
8408 MsgInfo *tmp_msginfo = NULL;
8409 gboolean originally_enc = FALSE;
8410 Compose *compose = NULL;
8412 g_return_if_fail(msgview != NULL);
8414 g_return_if_fail(msginfo_list != NULL);
8416 if (g_slist_length(msginfo_list) == 1) {
8417 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8418 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8420 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8421 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8422 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8423 orig_msginfo, mimeinfo);
8424 if (tmp_msginfo != NULL) {
8425 new_msglist = g_slist_append(NULL, tmp_msginfo);
8426 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8427 originally_enc = TRUE;
8433 body = messageview_get_selection(msgview);
8436 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8437 procmsg_msginfo_free(tmp_msginfo);
8438 g_slist_free(new_msglist);
8440 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8442 if (originally_enc) {
8443 compose_force_encryption(compose, compose->account, FALSE);
8449 void compose_set_position(Compose *compose, gint pos)
8451 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8453 gtkut_text_view_set_position(text, pos);
8456 gboolean compose_search_string(Compose *compose,
8457 const gchar *str, gboolean case_sens)
8459 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8461 return gtkut_text_view_search_string(text, str, case_sens);
8464 gboolean compose_search_string_backward(Compose *compose,
8465 const gchar *str, gboolean case_sens)
8467 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8469 return gtkut_text_view_search_string_backward(text, str, case_sens);