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,
202 static GtkWidget *compose_account_option_menu_create
204 static void compose_set_out_encoding (Compose *compose);
205 static void compose_set_template_menu (Compose *compose);
206 static void compose_template_apply (Compose *compose,
209 static void compose_destroy (Compose *compose);
211 static void compose_entries_set (Compose *compose,
212 const gchar *mailto);
213 static gint compose_parse_header (Compose *compose,
215 static gchar *compose_parse_references (const gchar *ref,
218 static gchar *compose_quote_fmt (Compose *compose,
225 static void compose_reply_set_entry (Compose *compose,
231 followup_and_reply_to);
232 static void compose_reedit_set_entry (Compose *compose,
235 static void compose_insert_sig (Compose *compose,
237 static gchar *compose_get_signature_str (Compose *compose);
238 static ComposeInsertResult compose_insert_file (Compose *compose,
241 static void compose_attach_append (Compose *compose,
244 const gchar *content_type);
245 static void compose_attach_parts (Compose *compose,
248 static void compose_beautify_paragraph (Compose *compose,
249 GtkTextIter *par_iter,
251 static void compose_wrap_all (Compose *compose);
252 static void compose_wrap_all_full (Compose *compose,
255 static void compose_set_title (Compose *compose);
256 static void compose_select_account (Compose *compose,
257 PrefsAccount *account,
260 static PrefsAccount *compose_current_mail_account(void);
261 /* static gint compose_send (Compose *compose); */
262 static gboolean compose_check_for_valid_recipient
264 static gboolean compose_check_entries (Compose *compose,
265 gboolean check_subject);
266 static gint compose_write_to_file (Compose *compose,
269 static gint compose_write_body_to_file (Compose *compose,
271 static gint compose_remove_reedit_target (Compose *compose,
273 void compose_remove_draft (Compose *compose);
274 static gint compose_queue (Compose *compose,
278 static gint compose_queue_sub (Compose *compose,
282 gboolean check_subject);
283 static void compose_add_attachments (Compose *compose,
285 static gchar *compose_get_header (Compose *compose);
287 static void compose_convert_header (Compose *compose,
292 gboolean addr_field);
294 static void compose_attach_info_free (AttachInfo *ainfo);
295 static void compose_attach_remove_selected (Compose *compose);
297 static void compose_attach_property (Compose *compose);
298 static void compose_attach_property_create (gboolean *cancelled);
299 static void attach_property_ok (GtkWidget *widget,
300 gboolean *cancelled);
301 static void attach_property_cancel (GtkWidget *widget,
302 gboolean *cancelled);
303 static gint attach_property_delete_event (GtkWidget *widget,
305 gboolean *cancelled);
306 static gboolean attach_property_key_pressed (GtkWidget *widget,
308 gboolean *cancelled);
310 static void compose_exec_ext_editor (Compose *compose);
312 static gint compose_exec_ext_editor_real (const gchar *file);
313 static gboolean compose_ext_editor_kill (Compose *compose);
314 static gboolean compose_input_cb (GIOChannel *source,
315 GIOCondition condition,
317 static void compose_set_ext_editor_sensitive (Compose *compose,
319 #endif /* G_OS_UNIX */
321 static void compose_undo_state_changed (UndoMain *undostruct,
326 static void compose_create_header_entry (Compose *compose);
327 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
328 static void compose_update_priority_menu_item(Compose * compose);
330 static void compose_add_field_list ( Compose *compose,
331 GList *listAddress );
333 /* callback functions */
335 static gboolean compose_edit_size_alloc (GtkEditable *widget,
336 GtkAllocation *allocation,
337 GtkSHRuler *shruler);
338 static void account_activated (GtkMenuItem *menuitem,
340 static void attach_selected (GtkTreeView *tree_view,
341 GtkTreePath *tree_path,
342 GtkTreeViewColumn *column,
344 static gboolean attach_button_pressed (GtkWidget *widget,
345 GdkEventButton *event,
347 static gboolean attach_key_pressed (GtkWidget *widget,
351 static void compose_send_cb (gpointer data,
354 static void compose_send_later_cb (gpointer data,
358 static void compose_draft_cb (gpointer data,
362 static void compose_attach_cb (gpointer data,
365 static void compose_insert_file_cb (gpointer data,
368 static void compose_insert_sig_cb (gpointer data,
372 static void compose_close_cb (gpointer data,
376 static void compose_set_encoding_cb (gpointer data,
380 static void compose_address_cb (gpointer data,
383 static void compose_template_activate_cb(GtkWidget *widget,
386 static void compose_ext_editor_cb (gpointer data,
390 static gint compose_delete_cb (GtkWidget *widget,
394 static void compose_undo_cb (Compose *compose);
395 static void compose_redo_cb (Compose *compose);
396 static void compose_cut_cb (Compose *compose);
397 static void compose_copy_cb (Compose *compose);
398 static void compose_paste_cb (Compose *compose);
399 static void compose_paste_as_quote_cb (Compose *compose);
400 static void compose_paste_no_wrap_cb (Compose *compose);
401 static void compose_paste_wrap_cb (Compose *compose);
402 static void compose_allsel_cb (Compose *compose);
404 static void compose_advanced_action_cb (Compose *compose,
405 ComposeCallAdvancedAction action);
407 static void compose_grab_focus_cb (GtkWidget *widget,
410 static void compose_changed_cb (GtkTextBuffer *textbuf,
413 static void compose_wrap_cb (gpointer data,
416 static void compose_find_cb (gpointer data,
419 static void compose_toggle_autowrap_cb (gpointer data,
423 static void compose_toggle_ruler_cb (gpointer data,
426 static void compose_toggle_sign_cb (gpointer data,
429 static void compose_toggle_encrypt_cb (gpointer data,
432 static void compose_set_privacy_system_cb(GtkWidget *widget,
434 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
435 static void activate_privacy_system (Compose *compose,
436 PrefsAccount *account,
438 static void compose_use_signing(Compose *compose, gboolean use_signing);
439 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
440 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
442 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
444 static void compose_set_priority_cb (gpointer data,
448 static void compose_attach_drag_received_cb (GtkWidget *widget,
449 GdkDragContext *drag_context,
452 GtkSelectionData *data,
456 static void compose_insert_drag_received_cb (GtkWidget *widget,
457 GdkDragContext *drag_context,
460 GtkSelectionData *data,
464 static void compose_header_drag_received_cb (GtkWidget *widget,
465 GdkDragContext *drag_context,
468 GtkSelectionData *data,
473 static gboolean compose_drag_drop (GtkWidget *widget,
474 GdkDragContext *drag_context,
476 guint time, gpointer user_data);
478 static void text_inserted (GtkTextBuffer *buffer,
483 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
484 gboolean to_all, gboolean to_ml,
486 gboolean followup_and_reply_to,
489 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
490 ComposeHeaderEntry *headerentry);
491 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
493 ComposeHeaderEntry *headerentry);
495 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
497 static void compose_allow_user_actions (Compose *compose, gboolean allow);
500 static void compose_check_all (Compose *compose);
501 static void compose_highlight_all (Compose *compose);
502 static void compose_check_backwards (Compose *compose);
503 static void compose_check_forwards_go (Compose *compose);
506 static gint compose_defer_auto_save_draft (Compose *compose);
507 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
509 static gboolean compose_close (Compose *compose);
511 static GtkItemFactoryEntry compose_popup_entries[] =
513 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
514 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
515 {N_("/---"), NULL, NULL, 0, "<Separator>"},
516 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
519 static GtkItemFactoryEntry compose_entries[] =
521 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
522 {N_("/_Message/_Send"), "<control>Return",
523 compose_send_cb, 0, NULL},
524 {N_("/_Message/Send _later"), "<shift><control>S",
525 compose_send_later_cb, 0, NULL},
526 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
528 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
529 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Save"),
532 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
533 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
536 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
537 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
538 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
539 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
540 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
541 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
542 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
543 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
544 {N_("/_Edit/Special paste/as _quotation"),
545 NULL, compose_paste_as_quote_cb, 0, NULL},
546 {N_("/_Edit/Special paste/_wrapped"),
547 NULL, compose_paste_wrap_cb, 0, NULL},
548 {N_("/_Edit/Special paste/_unwrapped"),
549 NULL, compose_paste_no_wrap_cb, 0, NULL},
550 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
551 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
552 {N_("/_Edit/A_dvanced/Move a character backward"),
554 compose_advanced_action_cb,
555 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
557 {N_("/_Edit/A_dvanced/Move a character forward"),
559 compose_advanced_action_cb,
560 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
562 {N_("/_Edit/A_dvanced/Move a word backward"),
564 compose_advanced_action_cb,
565 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
567 {N_("/_Edit/A_dvanced/Move a word forward"),
569 compose_advanced_action_cb,
570 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
572 {N_("/_Edit/A_dvanced/Move to beginning of line"),
573 NULL, /* "<control>A" */
574 compose_advanced_action_cb,
575 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
577 {N_("/_Edit/A_dvanced/Move to end of line"),
579 compose_advanced_action_cb,
580 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
582 {N_("/_Edit/A_dvanced/Move to previous line"),
584 compose_advanced_action_cb,
585 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
587 {N_("/_Edit/A_dvanced/Move to next line"),
589 compose_advanced_action_cb,
590 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
592 {N_("/_Edit/A_dvanced/Delete a character backward"),
594 compose_advanced_action_cb,
595 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
597 {N_("/_Edit/A_dvanced/Delete a character forward"),
599 compose_advanced_action_cb,
600 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
602 {N_("/_Edit/A_dvanced/Delete a word backward"),
603 NULL, /* "<control>W" */
604 compose_advanced_action_cb,
605 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
607 {N_("/_Edit/A_dvanced/Delete a word forward"),
608 NULL, /* "<alt>D", */
609 compose_advanced_action_cb,
610 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
612 {N_("/_Edit/A_dvanced/Delete line"),
614 compose_advanced_action_cb,
615 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
617 {N_("/_Edit/A_dvanced/Delete entire line"),
619 compose_advanced_action_cb,
620 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
622 {N_("/_Edit/A_dvanced/Delete to end of line"),
624 compose_advanced_action_cb,
625 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
627 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
629 "<control>F", compose_find_cb, 0, NULL},
630 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_Edit/_Wrap current paragraph"),
632 "<control>L", compose_wrap_cb, 0, NULL},
633 {N_("/_Edit/Wrap all long _lines"),
634 "<control><alt>L", compose_wrap_cb, 1, NULL},
635 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
636 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_Edit/Edit with e_xternal editor"),
638 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
640 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Spelling/_Check all or check selection"),
642 NULL, compose_check_all, 0, NULL},
643 {N_("/_Spelling/_Highlight all misspelled words"),
644 NULL, compose_highlight_all, 0, NULL},
645 {N_("/_Spelling/Check _backwards misspelled word"),
646 NULL, compose_check_backwards , 0, NULL},
647 {N_("/_Spelling/_Forward to next misspelled word"),
648 NULL, compose_check_forwards_go, 0, NULL},
650 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
651 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
652 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
653 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
654 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
655 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
656 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
657 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
658 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
660 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
661 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
662 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
664 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
665 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
666 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
668 #define ENC_ACTION(action) \
669 NULL, compose_set_encoding_cb, action, \
670 "/Options/Character encoding/Automatic"
672 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
673 {N_("/_Options/Character _encoding/_Automatic"),
674 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
675 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
677 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
678 ENC_ACTION(C_US_ASCII)},
679 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
680 ENC_ACTION(C_UTF_8)},
681 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
683 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
684 ENC_ACTION(C_ISO_8859_1)},
685 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
686 ENC_ACTION(C_ISO_8859_15)},
687 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
688 ENC_ACTION(C_WINDOWS_1252)},
689 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
691 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
692 ENC_ACTION(C_ISO_8859_2)},
693 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
695 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
696 ENC_ACTION(C_ISO_8859_13)},
697 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
698 ENC_ACTION(C_ISO_8859_4)},
699 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
701 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
702 ENC_ACTION(C_ISO_8859_7)},
703 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
705 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
706 ENC_ACTION(C_ISO_8859_8)},
707 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
708 ENC_ACTION(C_WINDOWS_1255)},
709 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
711 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
712 ENC_ACTION(C_ISO_8859_6)},
713 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
714 ENC_ACTION(C_CP1256)},
715 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
717 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
718 ENC_ACTION(C_ISO_8859_9)},
719 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
721 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
722 ENC_ACTION(C_ISO_8859_5)},
723 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
724 ENC_ACTION(C_KOI8_R)},
725 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
726 ENC_ACTION(C_KOI8_U)},
727 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
728 ENC_ACTION(C_WINDOWS_1251)},
729 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
731 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
732 ENC_ACTION(C_ISO_2022_JP)},
733 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
735 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
736 ENC_ACTION(C_GB2312)},
737 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
739 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
741 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
742 ENC_ACTION(C_EUC_TW)},
743 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
745 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
746 ENC_ACTION(C_EUC_KR)},
747 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
749 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
750 ENC_ACTION(C_TIS_620)},
751 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
752 ENC_ACTION(C_WINDOWS_874)},
754 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
755 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
756 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
757 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
759 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
760 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
763 static GtkTargetEntry compose_mime_types[] =
765 {"text/uri-list", 0, 0},
766 {"text/plain", 0, 0},
770 static gboolean compose_put_existing_to_front(MsgInfo *info)
772 GList *compose_list = compose_get_compose_list();
776 for (elem = compose_list; elem != NULL && elem->data != NULL;
778 Compose *c = (Compose*)elem->data;
780 if (!c->targetinfo || !c->targetinfo->msgid ||
784 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
785 gtkut_window_popup(c->window);
793 static GdkColor quote_color =
794 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
796 static GdkColor signature_color = {
803 static GdkColor uri_color = {
810 static void compose_create_tags(GtkTextView *text, Compose *compose)
812 GtkTextBuffer *buffer;
813 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
815 buffer = gtk_text_view_get_buffer(text);
817 if (prefs_common.enable_color) {
818 /* grab the quote colors, converting from an int to a GdkColor */
819 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
821 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
823 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
826 signature_color = quote_color = uri_color = black;
829 gtk_text_buffer_create_tag(buffer, "quote",
830 "foreground-gdk", "e_color,
832 gtk_text_buffer_create_tag(buffer, "signature",
833 "foreground-gdk", &signature_color,
835 gtk_text_buffer_create_tag(buffer, "link",
836 "foreground-gdk", &uri_color,
838 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
839 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
842 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
843 GPtrArray *attach_files)
845 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
848 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
850 return compose_generic_new(account, NULL, item, NULL, NULL);
853 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
855 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
858 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
859 GPtrArray *attach_files, GList *listAddress )
862 GtkTextView *textview;
863 GtkTextBuffer *textbuf;
865 GtkItemFactory *ifactory;
867 if (item && item->prefs && item->prefs->enable_default_account)
868 account = account_find_from_id(item->prefs->default_account);
870 if (!account) account = cur_account;
871 g_return_val_if_fail(account != NULL, NULL);
873 compose = compose_create(account, COMPOSE_NEW, FALSE);
874 ifactory = gtk_item_factory_from_widget(compose->menubar);
876 compose->replyinfo = NULL;
877 compose->fwdinfo = NULL;
879 textview = GTK_TEXT_VIEW(compose->text);
880 textbuf = gtk_text_view_get_buffer(textview);
881 compose_create_tags(textview, compose);
883 undo_block(compose->undostruct);
885 if (item && item->prefs && item->prefs->enable_default_dictionary &&
887 gtkaspell_change_dict(compose->gtkaspell,
888 item->prefs->default_dictionary);
891 if (account->auto_sig)
892 compose_insert_sig(compose, FALSE);
893 gtk_text_buffer_get_start_iter(textbuf, &iter);
894 gtk_text_buffer_place_cursor(textbuf, &iter);
896 if (account->protocol != A_NNTP) {
897 if (mailto && *mailto != '\0') {
898 compose_entries_set(compose, mailto);
900 } else if (item && item->prefs->enable_default_to) {
901 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
902 compose_entry_mark_default_to(compose, item->prefs->default_to);
904 if (item && item->ret_rcpt) {
905 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
909 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
911 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
914 * CLAWS: just don't allow return receipt request, even if the user
915 * may want to send an email. simple but foolproof.
917 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
919 compose_add_field_list( compose, listAddress );
925 for (i = 0; i < attach_files->len; i++) {
926 file = g_ptr_array_index(attach_files, i);
927 compose_attach_append(compose, file, file, NULL);
931 compose_show_first_last_header(compose, TRUE);
933 /* Set save folder */
934 if (item && item->prefs && item->prefs->save_copy_to_folder) {
935 gchar *folderidentifier;
937 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
938 folderidentifier = folder_item_get_identifier(item);
939 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
940 g_free(folderidentifier);
943 gtk_widget_grab_focus(compose->header_last->entry);
945 undo_unblock(compose->undostruct);
947 if (prefs_common.auto_exteditor)
948 compose_exec_ext_editor(compose);
950 compose->modified = FALSE;
951 compose_set_title(compose);
955 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
956 gboolean override_pref)
958 gchar *privacy = NULL;
960 g_return_if_fail(compose != NULL);
961 g_return_if_fail(account != NULL);
963 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
966 if (account->default_privacy_system
967 && strlen(account->default_privacy_system)) {
968 privacy = account->default_privacy_system;
970 GSList *privacy_avail = privacy_get_system_ids();
971 if (privacy_avail && g_slist_length(privacy_avail)) {
972 privacy = (gchar *)(privacy_avail->data);
975 if (privacy != NULL) {
976 compose->privacy_system = g_strdup(privacy);
977 compose_update_privacy_system_menu_item(compose, FALSE);
978 compose_use_encryption(compose, TRUE);
982 static void compose_force_signing(Compose *compose, PrefsAccount *account)
984 gchar *privacy = NULL;
986 if (account->default_privacy_system
987 && strlen(account->default_privacy_system)) {
988 privacy = account->default_privacy_system;
990 GSList *privacy_avail = privacy_get_system_ids();
991 if (privacy_avail && g_slist_length(privacy_avail)) {
992 privacy = (gchar *)(privacy_avail->data);
995 if (privacy != NULL) {
996 compose->privacy_system = g_strdup(privacy);
997 compose_update_privacy_system_menu_item(compose, FALSE);
998 compose_use_signing(compose, TRUE);
1002 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1006 Compose *compose = NULL;
1007 g_return_val_if_fail(msginfo_list != NULL, NULL);
1009 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1010 g_return_val_if_fail(msginfo != NULL, NULL);
1012 list_len = g_slist_length(msginfo_list);
1016 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1017 FALSE, prefs_common.default_reply_list, FALSE, body);
1019 case COMPOSE_REPLY_WITH_QUOTE:
1020 compose = compose_reply(msginfo, TRUE,
1021 FALSE, prefs_common.default_reply_list, FALSE, body);
1023 case COMPOSE_REPLY_WITHOUT_QUOTE:
1024 compose = compose_reply(msginfo, FALSE,
1025 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1027 case COMPOSE_REPLY_TO_SENDER:
1028 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1029 FALSE, FALSE, TRUE, body);
1031 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1032 compose = compose_followup_and_reply_to(msginfo,
1033 prefs_common.reply_with_quote,
1034 FALSE, FALSE, body);
1036 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1037 compose = compose_reply(msginfo, TRUE,
1038 FALSE, FALSE, TRUE, body);
1040 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1041 compose = compose_reply(msginfo, FALSE,
1042 FALSE, FALSE, TRUE, NULL);
1044 case COMPOSE_REPLY_TO_ALL:
1045 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1046 TRUE, FALSE, FALSE, body);
1048 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1049 compose = compose_reply(msginfo, TRUE,
1050 TRUE, FALSE, FALSE, body);
1052 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1053 compose = compose_reply(msginfo, FALSE,
1054 TRUE, FALSE, FALSE, NULL);
1056 case COMPOSE_REPLY_TO_LIST:
1057 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1058 FALSE, TRUE, FALSE, body);
1060 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1061 compose = compose_reply(msginfo, TRUE,
1062 FALSE, TRUE, FALSE, body);
1064 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1065 compose = compose_reply(msginfo, FALSE,
1066 FALSE, TRUE, FALSE, NULL);
1068 case COMPOSE_FORWARD:
1069 if (prefs_common.forward_as_attachment) {
1070 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1073 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1077 case COMPOSE_FORWARD_INLINE:
1078 /* check if we reply to more than one Message */
1079 if (list_len == 1) {
1080 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1083 /* more messages FALL THROUGH */
1084 case COMPOSE_FORWARD_AS_ATTACH:
1085 compose = compose_forward_multiple(NULL, msginfo_list);
1087 case COMPOSE_REDIRECT:
1088 compose = compose_redirect(NULL, msginfo, FALSE);
1091 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1096 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1097 gboolean to_ml, gboolean to_sender,
1100 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1101 to_sender, FALSE, body);
1104 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1109 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1110 to_sender, TRUE, body);
1113 static void compose_extract_original_charset(Compose *compose)
1115 MsgInfo *info = NULL;
1116 if (compose->replyinfo) {
1117 info = compose->replyinfo;
1118 } else if (compose->fwdinfo) {
1119 info = compose->fwdinfo;
1120 } else if (compose->targetinfo) {
1121 info = compose->targetinfo;
1124 MimeInfo *mimeinfo = procmime_scan_message(info);
1125 MimeInfo *partinfo = mimeinfo;
1126 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1127 partinfo = procmime_mimeinfo_next(partinfo);
1129 compose->orig_charset =
1130 g_strdup(procmime_mimeinfo_get_parameter(
1131 partinfo, "charset"));
1133 procmime_mimeinfo_free_all(mimeinfo);
1137 #define SIGNAL_BLOCK(buffer) { \
1138 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1139 G_CALLBACK(compose_changed_cb), \
1141 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1142 G_CALLBACK(text_inserted), \
1146 #define SIGNAL_UNBLOCK(buffer) { \
1147 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1148 G_CALLBACK(compose_changed_cb), \
1150 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1151 G_CALLBACK(text_inserted), \
1155 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1156 gboolean to_all, gboolean to_ml,
1158 gboolean followup_and_reply_to,
1161 GtkItemFactory *ifactory;
1163 PrefsAccount *account = NULL;
1164 PrefsAccount *reply_account;
1165 GtkTextView *textview;
1166 GtkTextBuffer *textbuf;
1168 g_return_val_if_fail(msginfo != NULL, NULL);
1169 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1171 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1173 g_return_val_if_fail(account != NULL, NULL);
1175 if (to_sender && account->protocol == A_NNTP &&
1176 !followup_and_reply_to) {
1178 account_find_from_address(account->address);
1180 reply_account = compose_current_mail_account();
1184 reply_account = account;
1186 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1187 ifactory = gtk_item_factory_from_widget(compose->menubar);
1189 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1190 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1192 compose->updating = TRUE;
1193 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1194 if (!compose->replyinfo)
1195 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1196 compose->updating = FALSE;
1198 if (compose->deferred_destroy) {
1199 compose_destroy(compose);
1203 compose_extract_original_charset(compose);
1205 if (msginfo->folder && msginfo->folder->ret_rcpt)
1206 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1208 /* Set save folder */
1209 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1210 gchar *folderidentifier;
1212 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1213 folderidentifier = folder_item_get_identifier(msginfo->folder);
1214 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1215 g_free(folderidentifier);
1218 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1219 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1220 to_sender, followup_and_reply_to);
1221 compose_show_first_last_header(compose, TRUE);
1223 textview = (GTK_TEXT_VIEW(compose->text));
1224 textbuf = gtk_text_view_get_buffer(textview);
1225 compose_create_tags(textview, compose);
1227 undo_block(compose->undostruct);
1229 if (msginfo->folder && msginfo->folder->prefs &&
1230 msginfo->folder->prefs &&
1231 msginfo->folder->prefs->enable_default_dictionary &&
1233 gtkaspell_change_dict(compose->gtkaspell,
1234 msginfo->folder->prefs->default_dictionary);
1240 if (prefs_common.quotemark && *prefs_common.quotemark)
1241 qmark = prefs_common.quotemark;
1245 compose_quote_fmt(compose, compose->replyinfo,
1246 prefs_common.quotefmt,
1247 qmark, body, FALSE);
1249 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1250 compose_force_encryption(compose, account, FALSE);
1253 SIGNAL_BLOCK(textbuf);
1255 if (account->auto_sig)
1256 compose_insert_sig(compose, FALSE);
1258 compose_wrap_all(compose);
1260 SIGNAL_UNBLOCK(textbuf);
1262 gtk_widget_grab_focus(compose->text);
1264 undo_unblock(compose->undostruct);
1266 if (prefs_common.auto_exteditor)
1267 compose_exec_ext_editor(compose);
1269 compose->modified = FALSE;
1270 compose_set_title(compose);
1274 #define INSERT_FW_HEADER(var, hdr) \
1275 if (msginfo->var && *msginfo->var) { \
1276 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1277 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1278 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1281 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1282 gboolean as_attach, const gchar *body,
1283 gboolean no_extedit,
1287 GtkTextView *textview;
1288 GtkTextBuffer *textbuf;
1291 g_return_val_if_fail(msginfo != NULL, NULL);
1292 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1295 !(account = compose_guess_forward_account_from_msginfo
1297 account = cur_account;
1299 compose = compose_create(account, COMPOSE_FORWARD, batch);
1301 compose->updating = TRUE;
1302 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1303 if (!compose->fwdinfo)
1304 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1305 compose->updating = FALSE;
1307 if (compose->deferred_destroy) {
1308 compose_destroy(compose);
1312 compose_extract_original_charset(compose);
1314 if (msginfo->subject && *msginfo->subject) {
1315 gchar *buf, *buf2, *p;
1317 buf = p = g_strdup(msginfo->subject);
1318 p += subject_get_prefix_length(p);
1319 memmove(buf, p, strlen(p) + 1);
1321 buf2 = g_strdup_printf("Fw: %s", buf);
1322 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1328 textview = GTK_TEXT_VIEW(compose->text);
1329 textbuf = gtk_text_view_get_buffer(textview);
1330 compose_create_tags(textview, compose);
1332 undo_block(compose->undostruct);
1336 msgfile = procmsg_get_message_file_path(msginfo);
1337 if (!is_file_exist(msgfile))
1338 g_warning("%s: file not exist\n", msgfile);
1340 compose_attach_append(compose, msgfile, msgfile,
1346 MsgInfo *full_msginfo;
1348 compose->updating = TRUE;
1349 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1351 full_msginfo = procmsg_msginfo_copy(msginfo);
1352 compose->updating = FALSE;
1354 if (compose->deferred_destroy) {
1355 compose_destroy(compose);
1359 if (prefs_common.fw_quotemark &&
1360 *prefs_common.fw_quotemark)
1361 qmark = prefs_common.fw_quotemark;
1365 compose_quote_fmt(compose, full_msginfo,
1366 prefs_common.fw_quotefmt,
1367 qmark, body, FALSE);
1368 compose_attach_parts(compose, msginfo);
1370 procmsg_msginfo_free(full_msginfo);
1373 SIGNAL_BLOCK(textbuf);
1375 if (account->auto_sig)
1376 compose_insert_sig(compose, FALSE);
1378 compose_wrap_all(compose);
1380 SIGNAL_UNBLOCK(textbuf);
1382 gtk_text_buffer_get_start_iter(textbuf, &iter);
1383 gtk_text_buffer_place_cursor(textbuf, &iter);
1385 gtk_widget_grab_focus(compose->header_last->entry);
1387 if (!no_extedit && prefs_common.auto_exteditor)
1388 compose_exec_ext_editor(compose);
1391 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1392 gchar *folderidentifier;
1394 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1395 folderidentifier = folder_item_get_identifier(msginfo->folder);
1396 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1397 g_free(folderidentifier);
1400 undo_unblock(compose->undostruct);
1402 compose->modified = FALSE;
1403 compose_set_title(compose);
1407 #undef INSERT_FW_HEADER
1409 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1412 GtkTextView *textview;
1413 GtkTextBuffer *textbuf;
1417 gboolean single_mail = TRUE;
1419 g_return_val_if_fail(msginfo_list != NULL, NULL);
1421 if (g_slist_length(msginfo_list) > 1)
1422 single_mail = FALSE;
1424 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1425 if (((MsgInfo *)msginfo->data)->folder == NULL)
1428 /* guess account from first selected message */
1430 !(account = compose_guess_forward_account_from_msginfo
1431 (msginfo_list->data)))
1432 account = cur_account;
1434 g_return_val_if_fail(account != NULL, NULL);
1436 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1437 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1438 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1441 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1443 textview = GTK_TEXT_VIEW(compose->text);
1444 textbuf = gtk_text_view_get_buffer(textview);
1445 compose_create_tags(textview, compose);
1447 undo_block(compose->undostruct);
1448 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1449 compose->updating = TRUE;
1450 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1451 compose->updating = FALSE;
1452 if (compose->deferred_destroy) {
1453 compose_destroy(compose);
1457 if (!is_file_exist(msgfile))
1458 g_warning("%s: file not exist\n", msgfile);
1460 compose_attach_append(compose, msgfile, msgfile,
1466 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1467 if (info->subject && *info->subject) {
1468 gchar *buf, *buf2, *p;
1470 buf = p = g_strdup(info->subject);
1471 p += subject_get_prefix_length(p);
1472 memmove(buf, p, strlen(p) + 1);
1474 buf2 = g_strdup_printf("Fw: %s", buf);
1475 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1481 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1482 _("Fw: multiple emails"));
1485 SIGNAL_BLOCK(textbuf);
1487 if (account->auto_sig)
1488 compose_insert_sig(compose, FALSE);
1490 compose_wrap_all(compose);
1492 SIGNAL_UNBLOCK(textbuf);
1494 gtk_text_buffer_get_start_iter(textbuf, &iter);
1495 gtk_text_buffer_place_cursor(textbuf, &iter);
1497 gtk_widget_grab_focus(compose->header_last->entry);
1498 undo_unblock(compose->undostruct);
1499 compose->modified = FALSE;
1500 compose_set_title(compose);
1504 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1506 GtkTextIter start = *iter;
1507 GtkTextIter end_iter;
1508 int start_pos = gtk_text_iter_get_offset(&start);
1510 if (!compose->account->sig_sep)
1513 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1514 start_pos+strlen(compose->account->sig_sep));
1516 /* check sig separator */
1517 str = gtk_text_iter_get_text(&start, &end_iter);
1518 if (!strcmp(str, compose->account->sig_sep)) {
1520 /* check end of line (\n) */
1521 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1522 start_pos+strlen(compose->account->sig_sep));
1523 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1524 start_pos+strlen(compose->account->sig_sep)+1);
1525 tmp = gtk_text_iter_get_text(&start, &end_iter);
1526 if (!strcmp(tmp,"\n")) {
1538 static void compose_colorize_signature(Compose *compose)
1540 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1542 GtkTextIter end_iter;
1543 gtk_text_buffer_get_start_iter(buffer, &iter);
1544 while (gtk_text_iter_forward_line(&iter))
1545 if (compose_is_sig_separator(compose, buffer, &iter)) {
1546 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1547 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1551 void compose_reedit(MsgInfo *msginfo)
1553 Compose *compose = NULL;
1554 PrefsAccount *account = NULL;
1555 GtkTextView *textview;
1556 GtkTextBuffer *textbuf;
1560 gchar buf[BUFFSIZE];
1561 gboolean use_signing = FALSE;
1562 gboolean use_encryption = FALSE;
1563 gchar *privacy_system = NULL;
1565 g_return_if_fail(msginfo != NULL);
1566 g_return_if_fail(msginfo->folder != NULL);
1568 if (compose_put_existing_to_front(msginfo)) {
1572 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1573 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1574 gchar queueheader_buf[BUFFSIZE];
1577 /* Select Account from queue headers */
1578 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1579 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1580 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1581 account = account_find_from_id(id);
1583 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1584 sizeof(queueheader_buf), "NAID:")) {
1585 id = atoi(&queueheader_buf[strlen("NAID:")]);
1586 account = account_find_from_id(id);
1588 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1589 sizeof(queueheader_buf), "MAID:")) {
1590 id = atoi(&queueheader_buf[strlen("MAID:")]);
1591 account = account_find_from_id(id);
1593 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1594 sizeof(queueheader_buf), "S:")) {
1595 account = account_find_from_address(queueheader_buf);
1597 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1598 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1599 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1600 use_signing = param;
1603 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1604 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1605 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1606 use_encryption = param;
1608 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1609 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1610 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1612 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1613 sizeof(queueheader_buf), "X-Priority: ")) {
1614 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1615 compose->priority = param;
1618 account = msginfo->folder->folder->account;
1621 if (!account && prefs_common.reedit_account_autosel) {
1622 gchar from[BUFFSIZE];
1623 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1624 extract_address(from);
1625 account = account_find_from_address(from);
1629 account = cur_account;
1631 g_return_if_fail(account != NULL);
1633 compose = compose_create(account, COMPOSE_REEDIT, FALSE);
1634 if (privacy_system != NULL) {
1635 compose->privacy_system = privacy_system;
1636 compose_use_signing(compose, use_signing);
1637 compose_use_encryption(compose, use_encryption);
1638 compose_update_privacy_system_menu_item(compose, FALSE);
1640 activate_privacy_system(compose, account, FALSE);
1643 compose->updating = TRUE;
1644 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1645 compose->updating = FALSE;
1647 if (compose->deferred_destroy) {
1648 compose_destroy(compose);
1652 compose_extract_original_charset(compose);
1654 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1655 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1656 gchar queueheader_buf[BUFFSIZE];
1658 /* Set message save folder */
1659 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1662 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1663 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1664 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1666 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1667 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1669 GtkItemFactory *ifactory;
1670 ifactory = gtk_item_factory_from_widget(compose->menubar);
1671 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1676 if (compose_parse_header(compose, msginfo) < 0) {
1679 compose_reedit_set_entry(compose, msginfo);
1681 textview = GTK_TEXT_VIEW(compose->text);
1682 textbuf = gtk_text_view_get_buffer(textview);
1683 compose_create_tags(textview, compose);
1685 mark = gtk_text_buffer_get_insert(textbuf);
1686 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1688 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1689 G_CALLBACK(compose_changed_cb),
1692 if (procmime_msginfo_is_encrypted(msginfo)) {
1693 fp = procmime_get_first_encrypted_text_content(msginfo);
1695 compose_force_encryption(compose, account, TRUE);
1698 fp = procmime_get_first_text_content(msginfo);
1701 g_warning("Can't get text part\n");
1705 gboolean prev_autowrap = compose->autowrap;
1707 compose->autowrap = FALSE;
1708 while (fgets(buf, sizeof(buf), fp) != NULL) {
1710 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1712 compose_wrap_all_full(compose, FALSE);
1713 compose->autowrap = prev_autowrap;
1717 compose_attach_parts(compose, msginfo);
1719 compose_colorize_signature(compose);
1721 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1722 G_CALLBACK(compose_changed_cb),
1725 gtk_widget_grab_focus(compose->text);
1727 if (prefs_common.auto_exteditor) {
1728 compose_exec_ext_editor(compose);
1730 compose->modified = FALSE;
1731 compose_set_title(compose);
1734 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1739 GtkItemFactory *ifactory;
1742 g_return_val_if_fail(msginfo != NULL, NULL);
1745 account = account_get_reply_account(msginfo,
1746 prefs_common.reply_account_autosel);
1747 g_return_val_if_fail(account != NULL, NULL);
1749 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1750 ifactory = gtk_item_factory_from_widget(compose->menubar);
1751 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1752 compose->replyinfo = NULL;
1753 compose->fwdinfo = NULL;
1755 compose_show_first_last_header(compose, TRUE);
1757 gtk_widget_grab_focus(compose->header_last->entry);
1759 compose->updating = TRUE;
1760 filename = procmsg_get_message_file_path(msginfo);
1761 compose->updating = FALSE;
1763 if (compose->deferred_destroy) {
1764 compose_destroy(compose);
1769 if (filename == NULL)
1772 compose->redirect_filename = filename;
1774 /* Set save folder */
1775 item = msginfo->folder;
1776 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1777 gchar *folderidentifier;
1779 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1780 folderidentifier = folder_item_get_identifier(item);
1781 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1782 g_free(folderidentifier);
1785 compose_attach_parts(compose, msginfo);
1787 if (msginfo->subject)
1788 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1790 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1792 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1793 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1795 compose_colorize_signature(compose);
1797 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1798 menu_set_sensitive(ifactory, "/Add...", FALSE);
1799 menu_set_sensitive(ifactory, "/Remove", FALSE);
1800 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1802 ifactory = gtk_item_factory_from_widget(compose->menubar);
1803 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1804 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1805 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1806 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1807 menu_set_sensitive(ifactory, "/Edit", FALSE);
1808 menu_set_sensitive(ifactory, "/Options", FALSE);
1809 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1810 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1812 if (compose->toolbar->draft_btn)
1813 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1814 if (compose->toolbar->insert_btn)
1815 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1816 if (compose->toolbar->attach_btn)
1817 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1818 if (compose->toolbar->sig_btn)
1819 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1820 if (compose->toolbar->exteditor_btn)
1821 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1822 if (compose->toolbar->linewrap_current_btn)
1823 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1824 if (compose->toolbar->linewrap_all_btn)
1825 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1827 compose->modified = FALSE;
1828 compose_set_title(compose);
1832 GList *compose_get_compose_list(void)
1834 return compose_list;
1837 void compose_entry_append(Compose *compose, const gchar *address,
1838 ComposeEntryType type)
1842 gboolean in_quote = FALSE;
1843 if (!address || *address == '\0') return;
1850 header = N_("Bcc:");
1852 case COMPOSE_REPLYTO:
1853 header = N_("Reply-To:");
1855 case COMPOSE_NEWSGROUPS:
1856 header = N_("Newsgroups:");
1858 case COMPOSE_FOLLOWUPTO:
1859 header = N_( "Followup-To:");
1866 header = prefs_common.trans_hdr ? gettext(header) : header;
1868 cur = begin = (gchar *)address;
1870 /* we separate the line by commas, but not if we're inside a quoted
1872 while (*cur != '\0') {
1874 in_quote = !in_quote;
1875 if (*cur == ',' && !in_quote) {
1876 gchar *tmp = g_strdup(begin);
1878 tmp[cur-begin]='\0';
1883 compose_add_header_entry(compose, header, tmp);
1890 gchar *tmp = g_strdup(begin);
1892 tmp[cur-begin]='\0';
1897 compose_add_header_entry(compose, header, tmp);
1902 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1904 static GdkColor yellow;
1905 static GdkColor black;
1906 static gboolean yellow_initialised = FALSE;
1910 if (!yellow_initialised) {
1911 gdk_color_parse("#f5f6be", &yellow);
1912 gdk_color_parse("#000000", &black);
1913 yellow_initialised = gdk_colormap_alloc_color(
1914 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
1915 yellow_initialised &= gdk_colormap_alloc_color(
1916 gdk_colormap_get_system(), &black, FALSE, TRUE);
1919 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1920 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1921 if (gtk_entry_get_text(entry) &&
1922 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1923 if (yellow_initialised) {
1924 gtk_widget_modify_base(
1925 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1926 GTK_STATE_NORMAL, &yellow);
1927 gtk_widget_modify_text(
1928 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1929 GTK_STATE_NORMAL, &black);
1935 void compose_toolbar_cb(gint action, gpointer data)
1937 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1938 Compose *compose = (Compose*)toolbar_item->parent;
1940 g_return_if_fail(compose != NULL);
1944 compose_send_cb(compose, 0, NULL);
1947 compose_send_later_cb(compose, 0, NULL);
1950 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1953 compose_insert_file_cb(compose, 0, NULL);
1956 compose_attach_cb(compose, 0, NULL);
1959 compose_insert_sig(compose, FALSE);
1962 compose_ext_editor_cb(compose, 0, NULL);
1964 case A_LINEWRAP_CURRENT:
1965 compose_beautify_paragraph(compose, NULL, TRUE);
1967 case A_LINEWRAP_ALL:
1968 compose_wrap_all_full(compose, TRUE);
1971 compose_address_cb(compose, 0, NULL);
1974 case A_CHECK_SPELLING:
1975 compose_check_all(compose);
1983 static void compose_entries_set(Compose *compose, const gchar *mailto)
1987 gchar *subject = NULL;
1992 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1995 compose_entry_append(compose, to, COMPOSE_TO);
1997 compose_entry_append(compose, cc, COMPOSE_CC);
1999 if (!g_utf8_validate (subject, -1, NULL)) {
2000 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2001 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2004 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2008 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2009 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2012 gboolean prev_autowrap = compose->autowrap;
2014 compose->autowrap = FALSE;
2016 mark = gtk_text_buffer_get_insert(buffer);
2017 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2019 if (!g_utf8_validate (body, -1, NULL)) {
2020 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2021 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2024 gtk_text_buffer_insert(buffer, &iter, body, -1);
2026 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2028 compose->autowrap = prev_autowrap;
2029 if (compose->autowrap)
2030 compose_wrap_all(compose);
2039 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2041 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2042 {"Cc:", NULL, TRUE},
2043 {"References:", NULL, FALSE},
2044 {"Bcc:", NULL, TRUE},
2045 {"Newsgroups:", NULL, TRUE},
2046 {"Followup-To:", NULL, TRUE},
2047 {"List-Post:", NULL, FALSE},
2048 {"X-Priority:", NULL, FALSE},
2049 {NULL, NULL, FALSE}};
2065 g_return_val_if_fail(msginfo != NULL, -1);
2067 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2068 procheader_get_header_fields(fp, hentry);
2071 if (hentry[H_REPLY_TO].body != NULL) {
2072 if (hentry[H_REPLY_TO].body[0] != '\0') {
2074 conv_unmime_header(hentry[H_REPLY_TO].body,
2077 g_free(hentry[H_REPLY_TO].body);
2078 hentry[H_REPLY_TO].body = NULL;
2080 if (hentry[H_CC].body != NULL) {
2081 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2082 g_free(hentry[H_CC].body);
2083 hentry[H_CC].body = NULL;
2085 if (hentry[H_REFERENCES].body != NULL) {
2086 if (compose->mode == COMPOSE_REEDIT)
2087 compose->references = hentry[H_REFERENCES].body;
2089 compose->references = compose_parse_references
2090 (hentry[H_REFERENCES].body, msginfo->msgid);
2091 g_free(hentry[H_REFERENCES].body);
2093 hentry[H_REFERENCES].body = NULL;
2095 if (hentry[H_BCC].body != NULL) {
2096 if (compose->mode == COMPOSE_REEDIT)
2098 conv_unmime_header(hentry[H_BCC].body, NULL);
2099 g_free(hentry[H_BCC].body);
2100 hentry[H_BCC].body = NULL;
2102 if (hentry[H_NEWSGROUPS].body != NULL) {
2103 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2104 hentry[H_NEWSGROUPS].body = NULL;
2106 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2107 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2108 compose->followup_to =
2109 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2112 g_free(hentry[H_FOLLOWUP_TO].body);
2113 hentry[H_FOLLOWUP_TO].body = NULL;
2115 if (hentry[H_LIST_POST].body != NULL) {
2118 extract_address(hentry[H_LIST_POST].body);
2119 if (hentry[H_LIST_POST].body[0] != '\0') {
2120 scan_mailto_url(hentry[H_LIST_POST].body,
2121 &to, NULL, NULL, NULL, NULL);
2123 g_free(compose->ml_post);
2124 compose->ml_post = to;
2127 g_free(hentry[H_LIST_POST].body);
2128 hentry[H_LIST_POST].body = NULL;
2131 /* CLAWS - X-Priority */
2132 if (compose->mode == COMPOSE_REEDIT)
2133 if (hentry[H_X_PRIORITY].body != NULL) {
2136 priority = atoi(hentry[H_X_PRIORITY].body);
2137 g_free(hentry[H_X_PRIORITY].body);
2139 hentry[H_X_PRIORITY].body = NULL;
2141 if (priority < PRIORITY_HIGHEST ||
2142 priority > PRIORITY_LOWEST)
2143 priority = PRIORITY_NORMAL;
2145 compose->priority = priority;
2148 if (compose->mode == COMPOSE_REEDIT) {
2149 if (msginfo->inreplyto && *msginfo->inreplyto)
2150 compose->inreplyto = g_strdup(msginfo->inreplyto);
2154 if (msginfo->msgid && *msginfo->msgid)
2155 compose->inreplyto = g_strdup(msginfo->msgid);
2157 if (!compose->references) {
2158 if (msginfo->msgid && *msginfo->msgid) {
2159 if (msginfo->inreplyto && *msginfo->inreplyto)
2160 compose->references =
2161 g_strdup_printf("<%s>\n\t<%s>",
2165 compose->references =
2166 g_strconcat("<", msginfo->msgid, ">",
2168 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2169 compose->references =
2170 g_strconcat("<", msginfo->inreplyto, ">",
2178 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2180 GSList *ref_id_list, *cur;
2184 ref_id_list = references_list_append(NULL, ref);
2185 if (!ref_id_list) return NULL;
2186 if (msgid && *msgid)
2187 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2192 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2193 /* "<" + Message-ID + ">" + CR+LF+TAB */
2194 len += strlen((gchar *)cur->data) + 5;
2196 if (len > MAX_REFERENCES_LEN) {
2197 /* remove second message-ID */
2198 if (ref_id_list && ref_id_list->next &&
2199 ref_id_list->next->next) {
2200 g_free(ref_id_list->next->data);
2201 ref_id_list = g_slist_remove
2202 (ref_id_list, ref_id_list->next->data);
2204 slist_free_strings(ref_id_list);
2205 g_slist_free(ref_id_list);
2212 new_ref = g_string_new("");
2213 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2214 if (new_ref->len > 0)
2215 g_string_append(new_ref, "\n\t");
2216 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2219 slist_free_strings(ref_id_list);
2220 g_slist_free(ref_id_list);
2222 new_ref_str = new_ref->str;
2223 g_string_free(new_ref, FALSE);
2228 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2229 const gchar *fmt, const gchar *qmark,
2230 const gchar *body, gboolean rewrap)
2232 static MsgInfo dummyinfo;
2233 gchar *quote_str = NULL;
2235 gboolean prev_autowrap;
2236 const gchar *trimmed_body = body;
2237 gint cursor_pos = -1;
2238 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2239 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2244 SIGNAL_BLOCK(buffer);
2247 msginfo = &dummyinfo;
2249 if (qmark != NULL) {
2250 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2251 quote_fmt_scan_string(qmark);
2254 buf = quote_fmt_get_buffer();
2256 alertpanel_error(_("Quote mark format error."));
2258 Xstrdup_a(quote_str, buf, goto error)
2261 if (fmt && *fmt != '\0') {
2262 while (trimmed_body && strlen(trimmed_body) > 1
2263 && trimmed_body[0]=='\n')
2266 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2267 quote_fmt_scan_string(fmt);
2270 buf = quote_fmt_get_buffer();
2272 alertpanel_error(_("Message reply/forward format error."));
2278 prev_autowrap = compose->autowrap;
2279 compose->autowrap = FALSE;
2281 mark = gtk_text_buffer_get_insert(buffer);
2282 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2283 if (g_utf8_validate(buf, -1, NULL)) {
2284 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2286 gchar *tmpout = NULL;
2287 tmpout = conv_codeset_strdup
2288 (buf, conv_get_locale_charset_str_no_utf8(),
2290 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2292 tmpout = g_malloc(strlen(buf)*2+1);
2293 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2295 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2299 cursor_pos = quote_fmt_get_cursor_pos();
2300 compose->set_cursor_pos = cursor_pos;
2301 if (cursor_pos == -1) {
2304 gtk_text_buffer_get_start_iter(buffer, &iter);
2305 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2306 gtk_text_buffer_place_cursor(buffer, &iter);
2308 compose->autowrap = prev_autowrap;
2309 if (compose->autowrap && rewrap)
2310 compose_wrap_all(compose);
2317 SIGNAL_UNBLOCK(buffer);
2323 /* if ml_post is of type addr@host and from is of type
2324 * addr-anything@host, return TRUE
2326 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2328 gchar *left_ml = NULL;
2329 gchar *right_ml = NULL;
2330 gchar *left_from = NULL;
2331 gchar *right_from = NULL;
2332 gboolean result = FALSE;
2334 if (!ml_post || !from)
2337 left_ml = g_strdup(ml_post);
2338 if (strstr(left_ml, "@")) {
2339 right_ml = strstr(left_ml, "@")+1;
2340 *(strstr(left_ml, "@")) = '\0';
2343 left_from = g_strdup(from);
2344 if (strstr(left_from, "@")) {
2345 right_from = strstr(left_from, "@")+1;
2346 *(strstr(left_from, "@")) = '\0';
2349 if (left_ml && left_from && right_ml && right_from
2350 && !strncmp(left_from, left_ml, strlen(left_ml))
2351 && !strcmp(right_from, right_ml)) {
2360 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2362 gchar *my_addr1, *my_addr2;
2364 if (!addr1 || !addr2)
2367 Xstrdup_a(my_addr1, addr1, return FALSE);
2368 Xstrdup_a(my_addr2, addr2, return FALSE);
2370 extract_address(my_addr1);
2371 extract_address(my_addr2);
2373 return !strcmp(my_addr1, my_addr2);
2376 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2377 gboolean to_all, gboolean to_ml,
2379 gboolean followup_and_reply_to)
2381 GSList *cc_list = NULL;
2384 gchar *replyto = NULL;
2385 GHashTable *to_table;
2387 gboolean reply_to_ml = FALSE;
2388 gboolean default_reply_to = FALSE;
2390 g_return_if_fail(compose->account != NULL);
2391 g_return_if_fail(msginfo != NULL);
2393 reply_to_ml = to_ml && compose->ml_post;
2395 default_reply_to = msginfo->folder &&
2396 msginfo->folder->prefs->enable_default_reply_to;
2398 if (compose->account->protocol != A_NNTP) {
2399 if (reply_to_ml && !default_reply_to) {
2401 gboolean is_subscr = is_subscription(compose->ml_post,
2404 /* normal answer to ml post with a reply-to */
2405 compose_entry_append(compose,
2408 if (compose->replyto
2409 && !same_address(compose->ml_post, compose->replyto))
2410 compose_entry_append(compose,
2414 /* answer to subscription confirmation */
2415 if (compose->replyto)
2416 compose_entry_append(compose,
2419 else if (msginfo->from)
2420 compose_entry_append(compose,
2425 else if (!(to_all || to_sender) && default_reply_to) {
2426 compose_entry_append(compose,
2427 msginfo->folder->prefs->default_reply_to,
2429 compose_entry_mark_default_to(compose,
2430 msginfo->folder->prefs->default_reply_to);
2435 Xstrdup_a(tmp1, msginfo->from, return);
2436 extract_address(tmp1);
2437 if (to_all || to_sender ||
2438 !account_find_from_address(tmp1))
2439 compose_entry_append(compose,
2440 (compose->replyto && !to_sender)
2441 ? compose->replyto :
2442 msginfo->from ? msginfo->from : "",
2444 else if (!to_all && !to_sender) {
2445 /* reply to the last list of recipients */
2446 compose_entry_append(compose,
2447 msginfo->to ? msginfo->to : "",
2449 compose_entry_append(compose,
2450 msginfo->cc ? msginfo->cc : "",
2455 if (to_sender || (compose->followup_to &&
2456 !strncmp(compose->followup_to, "poster", 6)))
2457 compose_entry_append
2459 (compose->replyto ? compose->replyto :
2460 msginfo->from ? msginfo->from : ""),
2463 else if (followup_and_reply_to || to_all) {
2464 compose_entry_append
2466 (compose->replyto ? compose->replyto :
2467 msginfo->from ? msginfo->from : ""),
2470 compose_entry_append
2472 compose->followup_to ? compose->followup_to :
2473 compose->newsgroups ? compose->newsgroups : "",
2474 COMPOSE_NEWSGROUPS);
2477 compose_entry_append
2479 compose->followup_to ? compose->followup_to :
2480 compose->newsgroups ? compose->newsgroups : "",
2481 COMPOSE_NEWSGROUPS);
2484 if (msginfo->subject && *msginfo->subject) {
2488 buf = p = g_strdup(msginfo->subject);
2489 p += subject_get_prefix_length(p);
2490 memmove(buf, p, strlen(p) + 1);
2492 buf2 = g_strdup_printf("Re: %s", buf);
2493 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2498 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2500 if (to_ml && compose->ml_post) return;
2501 if (!to_all || compose->account->protocol == A_NNTP) return;
2503 if (compose->replyto) {
2504 Xstrdup_a(replyto, compose->replyto, return);
2505 extract_address(replyto);
2507 if (msginfo->from) {
2508 Xstrdup_a(from, msginfo->from, return);
2509 extract_address(from);
2512 if (replyto && from)
2513 cc_list = address_list_append_with_comments(cc_list, from);
2514 if (to_all && msginfo->folder &&
2515 msginfo->folder->prefs->enable_default_reply_to)
2516 cc_list = address_list_append_with_comments(cc_list,
2517 msginfo->folder->prefs->default_reply_to);
2518 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2519 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2521 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2523 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2524 if (compose->account)
2525 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2526 GINT_TO_POINTER(1));
2528 /* remove address on To: and that of current account */
2529 for (cur = cc_list; cur != NULL; ) {
2530 GSList *next = cur->next;
2533 addr = g_strdup(cur->data);
2534 extract_address(addr);
2536 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2537 cc_list = g_slist_remove(cc_list, cur->data);
2539 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2543 hash_free_strings(to_table);
2544 g_hash_table_destroy(to_table);
2547 for (cur = cc_list; cur != NULL; cur = cur->next)
2548 compose_entry_append(compose, (gchar *)cur->data,
2550 slist_free_strings(cc_list);
2551 g_slist_free(cc_list);
2556 #define SET_ENTRY(entry, str) \
2559 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2562 #define SET_ADDRESS(type, str) \
2565 compose_entry_append(compose, str, type); \
2568 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2570 g_return_if_fail(msginfo != NULL);
2572 SET_ENTRY(subject_entry, msginfo->subject);
2573 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2574 SET_ADDRESS(COMPOSE_CC, compose->cc);
2575 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2576 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2577 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2578 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2580 compose_update_priority_menu_item(compose);
2581 compose_update_privacy_system_menu_item(compose, FALSE);
2582 compose_show_first_last_header(compose, TRUE);
2588 static void compose_insert_sig(Compose *compose, gboolean replace)
2590 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2591 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2593 GtkTextIter iter, iter_end;
2595 gboolean prev_autowrap;
2598 g_return_if_fail(compose->account != NULL);
2600 prev_autowrap = compose->autowrap;
2601 compose->autowrap = FALSE;
2603 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2604 G_CALLBACK(compose_changed_cb),
2607 mark = gtk_text_buffer_get_insert(buffer);
2608 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2609 cur_pos = gtk_text_iter_get_offset (&iter);
2611 gtk_text_buffer_get_end_iter(buffer, &iter);
2613 if (replace && compose->sig_str) {
2615 GtkTextIter first_iter, start_iter, end_iter;
2617 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2619 if (compose->sig_str[0] == '\0')
2622 found = gtk_text_iter_forward_search(&first_iter,
2624 GTK_TEXT_SEARCH_TEXT_ONLY,
2625 &start_iter, &end_iter,
2629 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2634 g_free(compose->sig_str);
2635 compose->sig_str = compose_get_signature_str(compose);
2636 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2637 compose->sig_str = g_strdup("");
2639 cur_pos = gtk_text_iter_get_offset(&iter);
2640 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2642 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2643 gtk_text_iter_forward_char(&iter);
2644 gtk_text_iter_forward_char(&iter);
2645 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2646 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2648 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2649 cur_pos = gtk_text_buffer_get_char_count (buffer);
2651 /* put the cursor where it should be
2652 * either where the quote_fmt says, either before the signature */
2653 if (compose->set_cursor_pos < 0)
2654 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2656 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2657 compose->set_cursor_pos);
2659 gtk_text_buffer_place_cursor(buffer, &iter);
2660 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2661 G_CALLBACK(compose_changed_cb),
2664 compose->autowrap = prev_autowrap;
2665 if (compose->autowrap)
2666 compose_wrap_all(compose);
2669 static gchar *compose_get_signature_str(Compose *compose)
2671 gchar *sig_body = NULL;
2672 gchar *sig_str = NULL;
2673 gchar *utf8_sig_str = NULL;
2675 g_return_val_if_fail(compose->account != NULL, NULL);
2677 if (!compose->account->sig_path)
2680 if (compose->account->sig_type == SIG_FILE) {
2681 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2682 g_warning("can't open signature file: %s\n",
2683 compose->account->sig_path);
2688 if (compose->account->sig_type == SIG_COMMAND)
2689 sig_body = get_command_output(compose->account->sig_path);
2693 tmp = file_read_to_str(compose->account->sig_path);
2696 sig_body = normalize_newlines(tmp);
2700 if (compose->account->sig_sep) {
2701 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2705 sig_str = g_strconcat("\n\n", sig_body, NULL);
2708 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2709 utf8_sig_str = sig_str;
2711 utf8_sig_str = conv_codeset_strdup
2712 (sig_str, conv_get_locale_charset_str_no_utf8(),
2718 return utf8_sig_str;
2721 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2724 GtkTextBuffer *buffer;
2727 const gchar *cur_encoding;
2728 gchar buf[BUFFSIZE];
2731 gboolean prev_autowrap;
2732 gboolean badtxt = FALSE;
2734 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2736 if ((fp = g_fopen(file, "rb")) == NULL) {
2737 FILE_OP_ERROR(file, "fopen");
2738 return COMPOSE_INSERT_READ_ERROR;
2741 prev_autowrap = compose->autowrap;
2742 compose->autowrap = FALSE;
2744 text = GTK_TEXT_VIEW(compose->text);
2745 buffer = gtk_text_view_get_buffer(text);
2746 mark = gtk_text_buffer_get_insert(buffer);
2747 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2749 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2750 G_CALLBACK(text_inserted),
2753 cur_encoding = conv_get_locale_charset_str();
2755 while (fgets(buf, sizeof(buf), fp) != NULL) {
2758 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2759 str = g_strdup(buf);
2761 str = conv_codeset_strdup
2762 (buf, cur_encoding, CS_INTERNAL);
2765 /* strip <CR> if DOS/Windows file,
2766 replace <CR> with <LF> if Macintosh file. */
2769 if (len > 0 && str[len - 1] != '\n') {
2771 if (str[len] == '\r') str[len] = '\n';
2774 gtk_text_buffer_insert(buffer, &iter, str, -1);
2778 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2779 G_CALLBACK(text_inserted),
2781 compose->autowrap = prev_autowrap;
2782 if (compose->autowrap)
2783 compose_wrap_all(compose);
2788 return COMPOSE_INSERT_INVALID_CHARACTER;
2790 return COMPOSE_INSERT_SUCCESS;
2793 static void compose_attach_append(Compose *compose, const gchar *file,
2794 const gchar *filename,
2795 const gchar *content_type)
2803 GtkListStore *store;
2805 gboolean has_binary = FALSE;
2807 if (!is_file_exist(file)) {
2808 g_warning("File %s doesn't exist\n", filename);
2811 if ((size = get_file_size(file)) < 0) {
2812 g_warning("Can't get file size of %s\n", filename);
2816 alertpanel_notice(_("File %s is empty."), filename);
2819 if ((fp = g_fopen(file, "rb")) == NULL) {
2820 alertpanel_error(_("Can't read %s."), filename);
2825 ainfo = g_new0(AttachInfo, 1);
2826 auto_ainfo = g_auto_pointer_new_with_free
2827 (ainfo, (GFreeFunc) compose_attach_info_free);
2828 ainfo->file = g_strdup(file);
2831 ainfo->content_type = g_strdup(content_type);
2832 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2834 MsgFlags flags = {0, 0};
2836 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2837 ainfo->encoding = ENC_7BIT;
2839 ainfo->encoding = ENC_8BIT;
2841 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2842 if (msginfo && msginfo->subject)
2843 name = g_strdup(msginfo->subject);
2845 name = g_path_get_basename(filename ? filename : file);
2847 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2849 procmsg_msginfo_free(msginfo);
2851 if (!g_ascii_strncasecmp(content_type, "text", 4))
2852 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2854 ainfo->encoding = ENC_BASE64;
2855 name = g_path_get_basename(filename ? filename : file);
2856 ainfo->name = g_strdup(name);
2860 ainfo->content_type = procmime_get_mime_type(file);
2861 if (!ainfo->content_type) {
2862 ainfo->content_type =
2863 g_strdup("application/octet-stream");
2864 ainfo->encoding = ENC_BASE64;
2865 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2867 procmime_get_encoding_for_text_file(file, &has_binary);
2869 ainfo->encoding = ENC_BASE64;
2870 name = g_path_get_basename(filename ? filename : file);
2871 ainfo->name = g_strdup(name);
2875 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2876 g_free(ainfo->content_type);
2877 ainfo->content_type = g_strdup("application/octet-stream");
2881 size_text = to_human_readable(size);
2883 store = GTK_LIST_STORE(gtk_tree_view_get_model
2884 (GTK_TREE_VIEW(compose->attach_clist)));
2886 gtk_list_store_append(store, &iter);
2887 gtk_list_store_set(store, &iter,
2888 COL_MIMETYPE, ainfo->content_type,
2889 COL_SIZE, size_text,
2890 COL_NAME, ainfo->name,
2892 COL_AUTODATA, auto_ainfo,
2895 g_auto_pointer_free(auto_ainfo);
2898 static void compose_use_signing(Compose *compose, gboolean use_signing)
2900 GtkItemFactory *ifactory;
2901 GtkWidget *menuitem = NULL;
2903 compose->use_signing = use_signing;
2904 ifactory = gtk_item_factory_from_widget(compose->menubar);
2905 menuitem = gtk_item_factory_get_item
2906 (ifactory, "/Options/Sign");
2907 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2911 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2913 GtkItemFactory *ifactory;
2914 GtkWidget *menuitem = NULL;
2916 compose->use_encryption = use_encryption;
2917 ifactory = gtk_item_factory_from_widget(compose->menubar);
2918 menuitem = gtk_item_factory_get_item
2919 (ifactory, "/Options/Encrypt");
2921 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2925 #define NEXT_PART_NOT_CHILD(info) \
2927 node = info->node; \
2928 while (node->children) \
2929 node = g_node_last_child(node); \
2930 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2933 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2937 MimeInfo *firsttext = NULL;
2938 MimeInfo *encrypted = NULL;
2941 const gchar *partname = NULL;
2943 mimeinfo = procmime_scan_message(msginfo);
2944 if (!mimeinfo) return;
2946 if (mimeinfo->node->children == NULL) {
2947 procmime_mimeinfo_free_all(mimeinfo);
2951 /* find first content part */
2952 child = (MimeInfo *) mimeinfo->node->children->data;
2953 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2954 child = (MimeInfo *)child->node->children->data;
2956 if (child->type == MIMETYPE_TEXT) {
2958 debug_print("First text part found\n");
2959 } else if (compose->mode == COMPOSE_REEDIT &&
2960 child->type == MIMETYPE_APPLICATION &&
2961 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2962 encrypted = (MimeInfo *)child->node->parent->data;
2965 child = (MimeInfo *) mimeinfo->node->children->data;
2966 while (child != NULL) {
2967 if (child == encrypted) {
2968 /* skip this part of tree */
2969 NEXT_PART_NOT_CHILD(child);
2973 if (child->type == MIMETYPE_MULTIPART) {
2974 /* get the actual content */
2975 child = procmime_mimeinfo_next(child);
2979 if (child == firsttext) {
2980 child = procmime_mimeinfo_next(child);
2984 outfile = procmime_get_tmp_file_name(child);
2985 if (procmime_get_part(outfile, child) < 0)
2986 g_warning("Can't get the part of multipart message.");
2988 gchar *content_type;
2990 content_type = procmime_get_content_type_str(child->type, child->subtype);
2992 /* if we meet a pgp signature, we don't attach it, but
2993 * we force signing. */
2994 if (strcmp(content_type, "application/pgp-signature")) {
2995 partname = procmime_mimeinfo_get_parameter(child, "filename");
2996 if (partname == NULL)
2997 partname = procmime_mimeinfo_get_parameter(child, "name");
2998 if (partname == NULL)
3000 compose_attach_append(compose, outfile,
3001 partname, content_type);
3003 compose_force_signing(compose, compose->account);
3005 g_free(content_type);
3008 NEXT_PART_NOT_CHILD(child);
3010 procmime_mimeinfo_free_all(mimeinfo);
3013 #undef NEXT_PART_NOT_CHILD
3018 WAIT_FOR_INDENT_CHAR,
3019 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3022 /* return indent length, we allow:
3023 indent characters followed by indent characters or spaces/tabs,
3024 alphabets and numbers immediately followed by indent characters,
3025 and the repeating sequences of the above
3026 If quote ends with multiple spaces, only the first one is included. */
3027 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3028 const GtkTextIter *start, gint *len)
3030 GtkTextIter iter = *start;
3034 IndentState state = WAIT_FOR_INDENT_CHAR;
3037 gint alnum_count = 0;
3038 gint space_count = 0;
3041 if (prefs_common.quote_chars == NULL) {
3045 while (!gtk_text_iter_ends_line(&iter)) {
3046 wc = gtk_text_iter_get_char(&iter);
3047 if (g_unichar_iswide(wc))
3049 clen = g_unichar_to_utf8(wc, ch);
3053 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3054 is_space = g_unichar_isspace(wc);
3056 if (state == WAIT_FOR_INDENT_CHAR) {
3057 if (!is_indent && !g_unichar_isalnum(wc))
3060 quote_len += alnum_count + space_count + 1;
3061 alnum_count = space_count = 0;
3062 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3065 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3066 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3070 else if (is_indent) {
3071 quote_len += alnum_count + space_count + 1;
3072 alnum_count = space_count = 0;
3075 state = WAIT_FOR_INDENT_CHAR;
3079 gtk_text_iter_forward_char(&iter);
3082 if (quote_len > 0 && space_count > 0)
3088 if (quote_len > 0) {
3090 gtk_text_iter_forward_chars(&iter, quote_len);
3091 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3097 /* return TRUE if the line is itemized */
3098 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3099 const GtkTextIter *start)
3101 GtkTextIter iter = *start;
3106 if (gtk_text_iter_ends_line(&iter))
3110 wc = gtk_text_iter_get_char(&iter);
3111 if (!g_unichar_isspace(wc))
3113 gtk_text_iter_forward_char(&iter);
3114 if (gtk_text_iter_ends_line(&iter))
3118 clen = g_unichar_to_utf8(wc, ch);
3122 if (!strchr("*-+", ch[0]))
3125 gtk_text_iter_forward_char(&iter);
3126 if (gtk_text_iter_ends_line(&iter))
3128 wc = gtk_text_iter_get_char(&iter);
3129 if (g_unichar_isspace(wc))
3135 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3136 const GtkTextIter *start,
3137 GtkTextIter *break_pos,
3141 GtkTextIter iter = *start, line_end = *start;
3142 PangoLogAttr *attrs;
3149 gboolean can_break = FALSE;
3150 gboolean do_break = FALSE;
3151 gboolean was_white = FALSE;
3152 gboolean prev_dont_break = FALSE;
3154 gtk_text_iter_forward_to_line_end(&line_end);
3155 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3156 len = g_utf8_strlen(str, -1);
3157 /* g_print("breaking line: %d: %s (len = %d)\n",
3158 gtk_text_iter_get_line(&iter), str, len); */
3159 attrs = g_new(PangoLogAttr, len + 1);
3161 pango_default_break(str, -1, NULL, attrs, len + 1);
3165 /* skip quote and leading spaces */
3166 for (i = 0; *p != '\0' && i < len; i++) {
3169 wc = g_utf8_get_char(p);
3170 if (i >= quote_len && !g_unichar_isspace(wc))
3172 if (g_unichar_iswide(wc))
3174 else if (*p == '\t')
3178 p = g_utf8_next_char(p);
3181 for (; *p != '\0' && i < len; i++) {
3182 PangoLogAttr *attr = attrs + i;
3186 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3189 was_white = attr->is_white;
3191 /* don't wrap URI */
3192 if ((uri_len = get_uri_len(p)) > 0) {
3194 if (pos > 0 && col > max_col) {
3204 wc = g_utf8_get_char(p);
3205 if (g_unichar_iswide(wc)) {
3207 if (prev_dont_break && can_break && attr->is_line_break)
3209 } else if (*p == '\t')
3213 if (pos > 0 && col > max_col) {
3218 if (*p == '-' || *p == '/')
3219 prev_dont_break = TRUE;
3221 prev_dont_break = FALSE;
3223 p = g_utf8_next_char(p);
3227 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3232 *break_pos = *start;
3233 gtk_text_iter_set_line_offset(break_pos, pos);
3238 static gboolean compose_join_next_line(Compose *compose,
3239 GtkTextBuffer *buffer,
3241 const gchar *quote_str)
3243 GtkTextIter iter_ = *iter, cur, prev, next, end;
3244 PangoLogAttr attrs[3];
3246 gchar *next_quote_str;
3249 gboolean keep_cursor = FALSE;
3251 if (!gtk_text_iter_forward_line(&iter_) ||
3252 gtk_text_iter_ends_line(&iter_))
3255 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3257 if ((quote_str || next_quote_str) &&
3258 strcmp2(quote_str, next_quote_str) != 0) {
3259 g_free(next_quote_str);
3262 g_free(next_quote_str);
3265 if (quote_len > 0) {
3266 gtk_text_iter_forward_chars(&end, quote_len);
3267 if (gtk_text_iter_ends_line(&end))
3271 /* don't join itemized lines */
3272 if (compose_is_itemized(buffer, &end))
3275 /* don't join signature separator */
3276 if (compose_is_sig_separator(compose, buffer, &iter_))
3279 /* delete quote str */
3281 gtk_text_buffer_delete(buffer, &iter_, &end);
3283 /* don't join line breaks put by the user */
3285 gtk_text_iter_backward_char(&cur);
3286 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3287 gtk_text_iter_forward_char(&cur);
3291 gtk_text_iter_forward_char(&cur);
3292 /* delete linebreak and extra spaces */
3293 while (gtk_text_iter_backward_char(&cur)) {
3294 wc1 = gtk_text_iter_get_char(&cur);
3295 if (!g_unichar_isspace(wc1))
3300 while (!gtk_text_iter_ends_line(&cur)) {
3301 wc1 = gtk_text_iter_get_char(&cur);
3302 if (!g_unichar_isspace(wc1))
3304 gtk_text_iter_forward_char(&cur);
3307 if (!gtk_text_iter_equal(&prev, &next)) {
3310 mark = gtk_text_buffer_get_insert(buffer);
3311 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3312 if (gtk_text_iter_equal(&prev, &cur))
3314 gtk_text_buffer_delete(buffer, &prev, &next);
3318 /* insert space if required */
3319 gtk_text_iter_backward_char(&prev);
3320 wc1 = gtk_text_iter_get_char(&prev);
3321 wc2 = gtk_text_iter_get_char(&next);
3322 gtk_text_iter_forward_char(&next);
3323 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3324 pango_default_break(str, -1, NULL, attrs, 3);
3325 if (!attrs[1].is_line_break ||
3326 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3327 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3329 gtk_text_iter_backward_char(&iter_);
3330 gtk_text_buffer_place_cursor(buffer, &iter_);
3339 #define ADD_TXT_POS(bp_, ep_, pti_) \
3340 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3341 last = last->next; \
3342 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3343 last->next = NULL; \
3345 g_warning("alloc error scanning URIs\n"); \
3348 static gboolean automatic_break = FALSE;
3349 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3351 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3352 GtkTextBuffer *buffer;
3353 GtkTextIter iter, break_pos, end_of_line;
3354 gchar *quote_str = NULL;
3356 gboolean wrap_quote = prefs_common.linewrap_quote;
3357 gboolean prev_autowrap = compose->autowrap;
3358 gint startq_offset = -1, noq_offset = -1;
3359 gint uri_start = -1, uri_stop = -1;
3360 gint nouri_start = -1, nouri_stop = -1;
3361 gint num_blocks = 0;
3363 compose->autowrap = FALSE;
3365 buffer = gtk_text_view_get_buffer(text);
3366 undo_wrapping(compose->undostruct, TRUE);
3371 mark = gtk_text_buffer_get_insert(buffer);
3372 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3375 /* move to paragraph start */
3376 gtk_text_iter_set_line_offset(&iter, 0);
3377 if (gtk_text_iter_ends_line(&iter)) {
3378 while (gtk_text_iter_ends_line(&iter) &&
3379 gtk_text_iter_forward_line(&iter))
3382 while (gtk_text_iter_backward_line(&iter)) {
3383 if (gtk_text_iter_ends_line(&iter)) {
3384 gtk_text_iter_forward_line(&iter);
3390 /* go until paragraph end (empty line) */
3392 while (!gtk_text_iter_ends_line(&iter)) {
3393 gchar *scanpos = NULL;
3394 /* parse table - in order of priority */
3396 const gchar *needle; /* token */
3398 /* token search function */
3399 gchar *(*search) (const gchar *haystack,
3400 const gchar *needle);
3401 /* part parsing function */
3402 gboolean (*parse) (const gchar *start,
3403 const gchar *scanpos,
3407 /* part to URI function */
3408 gchar *(*build_uri) (const gchar *bp,
3412 static struct table parser[] = {
3413 {"http://", strcasestr, get_uri_part, make_uri_string},
3414 {"https://", strcasestr, get_uri_part, make_uri_string},
3415 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3416 {"www.", strcasestr, get_uri_part, make_http_string},
3417 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3418 {"@", strcasestr, get_email_part, make_email_string}
3420 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3421 gint last_index = PARSE_ELEMS;
3423 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3426 if (!prev_autowrap && num_blocks == 0) {
3428 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3429 G_CALLBACK(text_inserted),
3432 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3435 uri_start = uri_stop = -1;
3437 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3441 if (startq_offset == -1) {
3442 startq_offset = gtk_text_iter_get_offset(&iter);
3446 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3447 if (startq_offset == -1)
3448 startq_offset = gtk_text_iter_get_offset(&iter);
3450 if (startq_offset == -1)
3451 noq_offset = gtk_text_iter_get_offset(&iter);
3454 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3457 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3458 prefs_common.linewrap_len,
3460 GtkTextIter prev, next, cur;
3462 if (prev_autowrap != FALSE || force) {
3463 automatic_break = TRUE;
3464 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3465 automatic_break = FALSE;
3466 } else if (quote_str && wrap_quote) {
3467 automatic_break = TRUE;
3468 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3469 automatic_break = FALSE;
3472 /* remove trailing spaces */
3474 gtk_text_iter_backward_char(&cur);
3476 while (!gtk_text_iter_starts_line(&cur)) {
3479 gtk_text_iter_backward_char(&cur);
3480 wc = gtk_text_iter_get_char(&cur);
3481 if (!g_unichar_isspace(wc))
3485 if (!gtk_text_iter_equal(&prev, &next)) {
3486 gtk_text_buffer_delete(buffer, &prev, &next);
3488 gtk_text_iter_forward_char(&break_pos);
3492 gtk_text_buffer_insert(buffer, &break_pos,
3496 compose_join_next_line(compose, buffer, &iter, quote_str);
3498 /* move iter to current line start */
3499 gtk_text_iter_set_line_offset(&iter, 0);
3506 /* move iter to next line start */
3511 if (!prev_autowrap && num_blocks > 0) {
3513 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3514 G_CALLBACK(text_inserted),
3518 while (!gtk_text_iter_ends_line(&end_of_line)) {
3519 gtk_text_iter_forward_char(&end_of_line);
3521 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3523 nouri_start = gtk_text_iter_get_offset(&iter);
3524 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3526 walk_pos = gtk_text_iter_get_offset(&iter);
3527 /* FIXME: this looks phony. scanning for anything in the parse table */
3528 for (n = 0; n < PARSE_ELEMS; n++) {
3531 tmp = parser[n].search(walk, parser[n].needle);
3533 if (scanpos == NULL || tmp < scanpos) {
3542 /* check if URI can be parsed */
3543 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3544 (const gchar **)&ep, FALSE)
3545 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3549 strlen(parser[last_index].needle);
3552 uri_start = walk_pos + (bp - o_walk);
3553 uri_stop = walk_pos + (ep - o_walk);
3557 gtk_text_iter_forward_line(&iter);
3560 if (startq_offset != -1) {
3561 GtkTextIter startquote, endquote;
3562 gtk_text_buffer_get_iter_at_offset(
3563 buffer, &startquote, startq_offset);
3565 gtk_text_buffer_apply_tag_by_name(
3566 buffer, "quote", &startquote, &endquote);
3568 } else if (noq_offset != -1) {
3569 GtkTextIter startnoquote, endnoquote;
3570 gtk_text_buffer_get_iter_at_offset(
3571 buffer, &startnoquote, noq_offset);
3573 gtk_text_buffer_remove_tag_by_name(
3574 buffer, "quote", &startnoquote, &endnoquote);
3579 GtkTextIter nouri_start_iter, nouri_end_iter;
3580 gtk_text_buffer_get_iter_at_offset(
3581 buffer, &nouri_start_iter, nouri_start);
3582 gtk_text_buffer_get_iter_at_offset(
3583 buffer, &nouri_end_iter, nouri_stop);
3584 gtk_text_buffer_remove_tag_by_name(
3585 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3587 if (uri_start > 0 && uri_stop > 0) {
3588 GtkTextIter uri_start_iter, uri_end_iter;
3589 gtk_text_buffer_get_iter_at_offset(
3590 buffer, &uri_start_iter, uri_start);
3591 gtk_text_buffer_get_iter_at_offset(
3592 buffer, &uri_end_iter, uri_stop);
3593 gtk_text_buffer_apply_tag_by_name(
3594 buffer, "link", &uri_start_iter, &uri_end_iter);
3600 undo_wrapping(compose->undostruct, FALSE);
3601 compose->autowrap = prev_autowrap;
3604 void compose_action_cb(void *data)
3606 Compose *compose = (Compose *)data;
3607 compose_wrap_all(compose);
3610 static void compose_wrap_all(Compose *compose)
3612 compose_wrap_all_full(compose, FALSE);
3615 static void compose_wrap_all_full(Compose *compose, gboolean force)
3617 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3618 GtkTextBuffer *buffer;
3621 buffer = gtk_text_view_get_buffer(text);
3623 gtk_text_buffer_get_start_iter(buffer, &iter);
3624 while (!gtk_text_iter_is_end(&iter))
3625 compose_beautify_paragraph(compose, &iter, force);
3629 static void compose_set_title(Compose *compose)
3635 edited = compose->modified ? _(" [Edited]") : "";
3637 subject = gtk_editable_get_chars(
3638 GTK_EDITABLE(compose->subject_entry), 0, -1);
3640 if (subject && strlen(subject))
3641 str = g_strdup_printf(_("%s - Compose message%s"),
3644 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3645 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3651 * compose_current_mail_account:
3653 * Find a current mail account (the currently selected account, or the
3654 * default account, if a news account is currently selected). If a
3655 * mail account cannot be found, display an error message.
3657 * Return value: Mail account, or NULL if not found.
3659 static PrefsAccount *
3660 compose_current_mail_account(void)
3664 if (cur_account && cur_account->protocol != A_NNTP)
3667 ac = account_get_default();
3668 if (!ac || ac->protocol == A_NNTP) {
3669 alertpanel_error(_("Account for sending mail is not specified.\n"
3670 "Please select a mail account before sending."));
3677 static void compose_select_account(Compose *compose, PrefsAccount *account,
3680 GtkItemFactory *ifactory;
3682 g_return_if_fail(account != NULL);
3684 compose->account = account;
3686 compose_set_title(compose);
3688 ifactory = gtk_item_factory_from_widget(compose->menubar);
3690 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3691 menu_set_active(ifactory, "/Options/Sign", TRUE);
3693 menu_set_active(ifactory, "/Options/Sign", FALSE);
3694 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3695 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3697 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3699 activate_privacy_system(compose, account, FALSE);
3701 if (!init && compose->mode != COMPOSE_REDIRECT)
3702 compose_insert_sig(compose, TRUE);
3705 gboolean compose_check_for_valid_recipient(Compose *compose) {
3706 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3707 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3708 gboolean recipient_found = FALSE;
3712 /* free to and newsgroup list */
3713 slist_free_strings(compose->to_list);
3714 g_slist_free(compose->to_list);
3715 compose->to_list = NULL;
3717 slist_free_strings(compose->newsgroup_list);
3718 g_slist_free(compose->newsgroup_list);
3719 compose->newsgroup_list = NULL;
3721 /* search header entries for to and newsgroup entries */
3722 for (list = compose->header_list; list; list = list->next) {
3725 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3726 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3728 if (entry[0] != '\0') {
3729 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3730 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3731 compose->to_list = address_list_append(compose->to_list, entry);
3732 recipient_found = TRUE;
3735 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3736 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3737 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3738 recipient_found = TRUE;
3745 return recipient_found;
3748 static gboolean compose_check_for_set_recipients(Compose *compose)
3750 if (compose->account->set_autocc && compose->account->auto_cc) {
3751 gboolean found_other = FALSE;
3753 /* search header entries for to and newsgroup entries */
3754 for (list = compose->header_list; list; list = list->next) {
3757 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3758 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3760 if (strcmp(entry, compose->account->auto_cc)
3761 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3771 aval = alertpanel(_("Send"),
3772 _("The only recipient is the default CC address. Send anyway?"),
3773 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3774 if (aval != G_ALERTALTERNATE)
3778 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3779 gboolean found_other = FALSE;
3781 /* search header entries for to and newsgroup entries */
3782 for (list = compose->header_list; list; list = list->next) {
3785 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3786 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3788 if (strcmp(entry, compose->account->auto_cc)
3789 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3799 aval = alertpanel(_("Send"),
3800 _("The only recipient is the default BCC address. Send anyway?"),
3801 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3802 if (aval != G_ALERTALTERNATE)
3809 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3813 if (compose_check_for_valid_recipient(compose) == FALSE) {
3814 alertpanel_error(_("Recipient is not specified."));
3818 if (compose_check_for_set_recipients(compose) == FALSE) {
3822 if (!compose->batch) {
3823 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3824 if (*str == '\0' && check_subject == TRUE) {
3827 aval = alertpanel(_("Send"),
3828 _("Subject is empty. Send it anyway?"),
3829 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3830 if (aval != G_ALERTALTERNATE)
3838 gint compose_send(Compose *compose)
3843 gchar *msgpath = NULL;
3844 gboolean discard_window = FALSE;
3846 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
3847 || compose->batch == TRUE)
3848 discard_window = TRUE;
3850 compose_allow_user_actions (compose, FALSE);
3851 compose->sending = TRUE;
3853 if (compose_check_entries(compose, TRUE) == FALSE) {
3854 if (compose->batch) {
3855 gtk_widget_show_all(compose->window);
3860 val = compose_queue(compose, &msgnum, &folder, &msgpath);
3863 if (compose->batch) {
3864 gtk_widget_show_all(compose->window);
3867 alertpanel_error(_("Could not queue message for sending:\n\n"
3868 "Charset conversion failed."));
3869 } else if (val == -3) {
3870 alertpanel_error(_("Could not queue message for sending:\n\n"
3871 "Signature failed."));
3872 } else if (val == -2 && errno != 0) {
3873 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3875 alertpanel_error(_("Could not queue message for sending."));
3880 if (discard_window) {
3881 compose->sending = FALSE;
3882 compose_close(compose);
3883 /* No more compose access in the normal codepath
3884 * after this point! */
3889 if (!discard_window) {
3892 alertpanel_error(_("The message was queued but could not be "
3893 "sent.\nUse \"Send queued messages\" from "
3894 "the main window to retry."));
3898 if (msgpath == NULL) {
3899 msgpath = folder_item_fetch_msg(folder, msgnum);
3900 val = procmsg_send_message_queue(msgpath);
3903 val = procmsg_send_message_queue(msgpath);
3907 if (!discard_window) {
3908 compose->sending = FALSE;
3909 compose_allow_user_actions (compose, TRUE);
3911 folder_item_remove_msg(folder, msgnum);
3912 folder_item_scan(folder);
3917 folder_item_remove_msg(folder, msgnum);
3918 folder_item_scan(folder);
3919 if (!discard_window)
3920 compose_close(compose);
3922 if (!discard_window) {
3925 alertpanel_error(_("The message was queued but could not be "
3926 "sent.\nUse \"Send queued messages\" from "
3927 "the main window to retry."));
3934 compose_allow_user_actions (compose, TRUE);
3935 compose->sending = FALSE;
3936 compose->modified = TRUE;
3941 static gboolean compose_use_attach(Compose *compose)
3943 GtkTreeModel *model = gtk_tree_view_get_model
3944 (GTK_TREE_VIEW(compose->attach_clist));
3945 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3948 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3951 gchar buf[BUFFSIZE];
3953 gboolean first_to_address;
3954 gboolean first_cc_address;
3956 ComposeHeaderEntry *headerentry;
3957 const gchar *headerentryname;
3961 debug_print("Writing redirect header\n");
3963 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3964 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3966 first_to_address = TRUE;
3967 for (list = compose->header_list; list; list = list->next) {
3968 headerentry = ((ComposeHeaderEntry *)list->data);
3969 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3971 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3972 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3973 Xstrdup_a(str, entstr, return -1);
3975 if (str[0] != '\0') {
3976 compose_convert_header
3977 (compose, buf, sizeof(buf), str,
3978 strlen("Resent-To") + 2, TRUE);
3980 if (first_to_address) {
3981 fprintf(fp, "Resent-To: ");
3982 first_to_address = FALSE;
3986 fprintf(fp, "%s", buf);
3990 if (!first_to_address) {
3994 first_cc_address = TRUE;
3995 for (list = compose->header_list; list; list = list->next) {
3996 headerentry = ((ComposeHeaderEntry *)list->data);
3997 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3999 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4000 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4001 Xstrdup_a(str, strg, return -1);
4003 if (str[0] != '\0') {
4004 compose_convert_header
4005 (compose, buf, sizeof(buf), str,
4006 strlen("Resent-Cc") + 2, TRUE);
4008 if (first_cc_address) {
4009 fprintf(fp, "Resent-Cc: ");
4010 first_cc_address = FALSE;
4014 fprintf(fp, "%s", buf);
4018 if (!first_cc_address) {
4025 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4027 gchar buf[BUFFSIZE];
4029 const gchar *entstr;
4030 /* struct utsname utsbuf; */
4032 g_return_val_if_fail(fp != NULL, -1);
4033 g_return_val_if_fail(compose->account != NULL, -1);
4034 g_return_val_if_fail(compose->account->address != NULL, -1);
4037 get_rfc822_date(buf, sizeof(buf));
4038 fprintf(fp, "Resent-Date: %s\n", buf);
4041 if (compose->account->name && *compose->account->name) {
4042 compose_convert_header
4043 (compose, buf, sizeof(buf), compose->account->name,
4044 strlen("From: "), TRUE);
4045 fprintf(fp, "Resent-From: %s <%s>\n",
4046 buf, compose->account->address);
4048 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4051 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4052 if (*entstr != '\0') {
4053 Xstrdup_a(str, entstr, return -1);
4056 compose_convert_header(compose, buf, sizeof(buf), str,
4057 strlen("Subject: "), FALSE);
4058 fprintf(fp, "Subject: %s\n", buf);
4062 /* Resent-Message-ID */
4063 if (compose->account->gen_msgid) {
4064 generate_msgid(buf, sizeof(buf));
4065 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4066 compose->msgid = g_strdup(buf);
4069 compose_redirect_write_headers_from_headerlist(compose, fp);
4071 /* separator between header and body */
4077 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4081 gchar buf[BUFFSIZE];
4083 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4084 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4088 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4089 /* should filter returnpath, delivered-to */
4090 if (g_ascii_strncasecmp(buf, "Return-Path:",
4091 strlen("Return-Path:")) == 0 ||
4092 g_ascii_strncasecmp(buf, "Delivered-To:",
4093 strlen("Delivered-To:")) == 0 ||
4094 g_ascii_strncasecmp(buf, "Received:",
4095 strlen("Received:")) == 0 ||
4096 g_ascii_strncasecmp(buf, "Subject:",
4097 strlen("Subject:")) == 0 ||
4098 g_ascii_strncasecmp(buf, "X-UIDL:",
4099 strlen("X-UIDL:")) == 0)
4102 if (fputs(buf, fdest) == -1)
4105 if (!prefs_common.redirect_keep_from) {
4106 if (g_ascii_strncasecmp(buf, "From:",
4107 strlen("From:")) == 0) {
4108 fputs(" (by way of ", fdest);
4109 if (compose->account->name
4110 && *compose->account->name) {
4111 compose_convert_header
4112 (compose, buf, sizeof(buf),
4113 compose->account->name,
4116 fprintf(fdest, "%s <%s>",
4118 compose->account->address);
4120 fprintf(fdest, "%s",
4121 compose->account->address);
4126 if (fputs("\n", fdest) == -1)
4130 compose_redirect_write_headers(compose, fdest);
4132 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4133 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4146 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4148 GtkTextBuffer *buffer;
4149 GtkTextIter start, end;
4152 const gchar *out_codeset;
4153 EncodingType encoding;
4154 MimeInfo *mimemsg, *mimetext;
4157 /* create message MimeInfo */
4158 mimemsg = procmime_mimeinfo_new();
4159 mimemsg->type = MIMETYPE_MESSAGE;
4160 mimemsg->subtype = g_strdup("rfc822");
4161 mimemsg->content = MIMECONTENT_MEM;
4162 mimemsg->tmp = TRUE; /* must free content later */
4163 mimemsg->data.mem = compose_get_header(compose);
4165 /* Create text part MimeInfo */
4166 /* get all composed text */
4167 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4168 gtk_text_buffer_get_start_iter(buffer, &start);
4169 gtk_text_buffer_get_end_iter(buffer, &end);
4170 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4171 if (is_ascii_str(chars)) {
4174 out_codeset = CS_US_ASCII;
4175 encoding = ENC_7BIT;
4177 const gchar *src_codeset = CS_INTERNAL;
4179 out_codeset = conv_get_charset_str(compose->out_encoding);
4182 gchar *test_conv_global_out = NULL;
4183 gchar *test_conv_reply = NULL;
4185 /* automatic mode. be automatic. */
4186 codeconv_set_strict(TRUE);
4188 out_codeset = conv_get_outgoing_charset_str();
4190 debug_print("trying to convert to %s\n", out_codeset);
4191 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4194 if (!test_conv_global_out && compose->orig_charset
4195 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4196 out_codeset = compose->orig_charset;
4197 debug_print("failure; trying to convert to %s\n", out_codeset);
4198 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4201 if (!test_conv_global_out && !test_conv_reply) {
4203 out_codeset = CS_INTERNAL;
4204 debug_print("failure; finally using %s\n", out_codeset);
4206 g_free(test_conv_global_out);
4207 g_free(test_conv_reply);
4208 codeconv_set_strict(FALSE);
4211 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4212 out_codeset = CS_ISO_8859_1;
4214 if (prefs_common.encoding_method == CTE_BASE64)
4215 encoding = ENC_BASE64;
4216 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4217 encoding = ENC_QUOTED_PRINTABLE;
4218 else if (prefs_common.encoding_method == CTE_8BIT)
4219 encoding = ENC_8BIT;
4221 encoding = procmime_get_encoding_for_charset(out_codeset);
4223 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4224 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4226 if (action == COMPOSE_WRITE_FOR_SEND) {
4227 codeconv_set_strict(TRUE);
4228 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4229 codeconv_set_strict(FALSE);
4235 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4236 "to the specified %s charset.\n"
4237 "Send it as %s?"), out_codeset, src_codeset);
4238 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4239 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4242 if (aval != G_ALERTALTERNATE) {
4247 out_codeset = src_codeset;
4253 out_codeset = src_codeset;
4259 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4260 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4261 strstr(buf, "\nFrom ") != NULL) {
4262 encoding = ENC_QUOTED_PRINTABLE;
4266 mimetext = procmime_mimeinfo_new();
4267 mimetext->content = MIMECONTENT_MEM;
4268 mimetext->tmp = TRUE; /* must free content later */
4269 mimetext->data.mem = buf;
4270 mimetext->type = MIMETYPE_TEXT;
4271 mimetext->subtype = g_strdup("plain");
4272 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4273 g_strdup(out_codeset));
4274 /* protect trailing spaces when signing message */
4275 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4276 privacy_system_can_sign(compose->privacy_system)) {
4277 encoding = ENC_QUOTED_PRINTABLE;
4280 /* check for line length limit */
4281 if (action == COMPOSE_WRITE_FOR_SEND &&
4282 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4283 check_line_length(buf, 1000, &line) < 0) {
4287 msg = g_strdup_printf
4288 (_("Line %d exceeds the line length limit (998 bytes).\n"
4289 "The contents of the message might be broken on the way to the delivery.\n"
4291 "Send it anyway?"), line + 1);
4292 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4294 if (aval != G_ALERTALTERNATE) {
4299 if (encoding != ENC_UNKNOWN)
4300 procmime_encode_content(mimetext, encoding);
4302 /* append attachment parts */
4303 if (compose_use_attach(compose)) {
4304 MimeInfo *mimempart;
4305 gchar *boundary = NULL;
4306 mimempart = procmime_mimeinfo_new();
4307 mimempart->content = MIMECONTENT_EMPTY;
4308 mimempart->type = MIMETYPE_MULTIPART;
4309 mimempart->subtype = g_strdup("mixed");
4313 boundary = generate_mime_boundary(NULL);
4314 } while (strstr(buf, boundary) != NULL);
4316 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4319 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4321 g_node_append(mimempart->node, mimetext->node);
4322 g_node_append(mimemsg->node, mimempart->node);
4324 compose_add_attachments(compose, mimempart);
4326 g_node_append(mimemsg->node, mimetext->node);
4328 /* sign message if sending */
4329 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4330 privacy_system_can_sign(compose->privacy_system))
4331 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4334 procmime_write_mimeinfo(mimemsg, fp);
4336 procmime_mimeinfo_free_all(mimemsg);
4341 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4343 GtkTextBuffer *buffer;
4344 GtkTextIter start, end;
4349 if ((fp = g_fopen(file, "wb")) == NULL) {
4350 FILE_OP_ERROR(file, "fopen");
4354 /* chmod for security */
4355 if (change_file_mode_rw(fp, file) < 0) {
4356 FILE_OP_ERROR(file, "chmod");
4357 g_warning("can't change file mode\n");
4360 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4361 gtk_text_buffer_get_start_iter(buffer, &start);
4362 gtk_text_buffer_get_end_iter(buffer, &end);
4363 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4365 chars = conv_codeset_strdup
4366 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4369 if (!chars) return -1;
4372 len = strlen(chars);
4373 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4374 FILE_OP_ERROR(file, "fwrite");
4383 if (fclose(fp) == EOF) {
4384 FILE_OP_ERROR(file, "fclose");
4391 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4394 MsgInfo *msginfo = compose->targetinfo;
4396 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4397 if (!msginfo) return -1;
4399 if (!force && MSG_IS_LOCKED(msginfo->flags))
4402 item = msginfo->folder;
4403 g_return_val_if_fail(item != NULL, -1);
4405 if (procmsg_msg_exist(msginfo) &&
4406 (folder_has_parent_of_type(item, F_QUEUE) ||
4407 folder_has_parent_of_type(item, F_DRAFT)
4408 || msginfo == compose->autosaved_draft)) {
4409 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4410 g_warning("can't remove the old message\n");
4418 void compose_remove_draft(Compose *compose)
4421 MsgInfo *msginfo = compose->targetinfo;
4422 drafts = account_get_special_folder(compose->account, F_DRAFT);
4424 if (procmsg_msg_exist(msginfo)) {
4425 folder_item_remove_msg(drafts, msginfo->msgnum);
4430 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath)
4432 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE);
4434 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath, gboolean check_subject)
4441 static gboolean lock = FALSE;
4442 PrefsAccount *mailac = NULL, *newsac = NULL;
4444 debug_print("queueing message...\n");
4445 g_return_val_if_fail(compose->account != NULL, -1);
4449 if (compose_check_entries(compose, check_subject) == FALSE) {
4454 if (!compose->to_list && !compose->newsgroup_list) {
4455 g_warning("can't get recipient list.");
4460 if (compose->to_list) {
4461 if (compose->account->protocol != A_NNTP)
4462 mailac = compose->account;
4463 else if (cur_account && cur_account->protocol != A_NNTP)
4464 mailac = cur_account;
4465 else if (!(mailac = compose_current_mail_account())) {
4467 alertpanel_error(_("No account for sending mails available!"));
4472 if (compose->newsgroup_list) {
4473 if (compose->account->protocol == A_NNTP)
4474 newsac = compose->account;
4475 else if (!newsac->protocol != A_NNTP) {
4477 alertpanel_error(_("No account for posting news available!"));
4482 /* write queue header */
4483 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4484 G_DIR_SEPARATOR, compose);
4485 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4486 FILE_OP_ERROR(tmp, "fopen");
4491 if (change_file_mode_rw(fp, tmp) < 0) {
4492 FILE_OP_ERROR(tmp, "chmod");
4493 g_warning("can't change file mode\n");
4496 /* queueing variables */
4497 fprintf(fp, "AF:\n");
4498 fprintf(fp, "NF:0\n");
4499 fprintf(fp, "PS:10\n");
4500 fprintf(fp, "SRH:1\n");
4501 fprintf(fp, "SFN:\n");
4502 fprintf(fp, "DSR:\n");
4504 fprintf(fp, "MID:<%s>\n", compose->msgid);
4506 fprintf(fp, "MID:\n");
4507 fprintf(fp, "CFG:\n");
4508 fprintf(fp, "PT:0\n");
4509 fprintf(fp, "S:%s\n", compose->account->address);
4510 fprintf(fp, "RQ:\n");
4512 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4514 fprintf(fp, "SSV:\n");
4516 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4518 fprintf(fp, "NSV:\n");
4519 fprintf(fp, "SSH:\n");
4520 /* write recepient list */
4521 if (compose->to_list) {
4522 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4523 for (cur = compose->to_list->next; cur != NULL;
4525 fprintf(fp, ",<%s>", (gchar *)cur->data);
4528 /* write newsgroup list */
4529 if (compose->newsgroup_list) {
4531 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4532 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4533 fprintf(fp, ",%s", (gchar *)cur->data);
4536 /* Sylpheed account IDs */
4538 fprintf(fp, "MAID:%d\n", mailac->account_id);
4540 fprintf(fp, "NAID:%d\n", newsac->account_id);
4542 if (compose->privacy_system != NULL) {
4543 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4544 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4545 if (compose->use_encryption) {
4548 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4549 if (encdata != NULL) {
4550 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4551 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4552 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4554 } /* else we finally dont want to encrypt */
4556 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4557 /* and if encdata was null, it means there's been a problem in
4564 /* Save copy folder */
4565 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4566 gchar *savefolderid;
4568 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4569 fprintf(fp, "SCF:%s\n", savefolderid);
4570 g_free(savefolderid);
4572 /* Save copy folder */
4573 if (compose->return_receipt) {
4574 fprintf(fp, "RRCPT:1\n");
4576 /* Message-ID of message replying to */
4577 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4580 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4581 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4584 /* Message-ID of message forwarding to */
4585 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4588 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4589 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4594 if (compose->redirect_filename != NULL) {
4595 if (compose_redirect_write_to_file(compose, fp) < 0) {
4604 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4609 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4613 if (fclose(fp) == EOF) {
4614 FILE_OP_ERROR(tmp, "fclose");
4620 queue = account_get_special_folder(compose->account, F_QUEUE);
4622 g_warning("can't find queue folder\n");
4627 folder_item_scan(queue);
4628 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4629 g_warning("can't queue the message\n");
4635 if (msgpath == NULL) {
4641 if (compose->mode == COMPOSE_REEDIT) {
4642 compose_remove_reedit_target(compose, FALSE);
4645 if ((msgnum != NULL) && (item != NULL)) {
4653 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4656 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4658 struct stat statbuf;
4659 gchar *type, *subtype;
4660 GtkTreeModel *model;
4663 model = gtk_tree_view_get_model(tree_view);
4665 if (!gtk_tree_model_get_iter_first(model, &iter))
4668 gtk_tree_model_get(model, &iter,
4672 mimepart = procmime_mimeinfo_new();
4673 mimepart->content = MIMECONTENT_FILE;
4674 mimepart->data.filename = g_strdup(ainfo->file);
4675 mimepart->tmp = FALSE; /* or we destroy our attachment */
4676 mimepart->offset = 0;
4678 stat(ainfo->file, &statbuf);
4679 mimepart->length = statbuf.st_size;
4681 type = g_strdup(ainfo->content_type);
4683 if (!strchr(type, '/')) {
4685 type = g_strdup("application/octet-stream");
4688 subtype = strchr(type, '/') + 1;
4689 *(subtype - 1) = '\0';
4690 mimepart->type = procmime_get_media_type(type);
4691 mimepart->subtype = g_strdup(subtype);
4694 if (mimepart->type == MIMETYPE_MESSAGE &&
4695 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4696 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4698 g_hash_table_insert(mimepart->typeparameters,
4699 g_strdup("name"), g_strdup(ainfo->name));
4700 g_hash_table_insert(mimepart->dispositionparameters,
4701 g_strdup("filename"), g_strdup(ainfo->name));
4702 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4705 if (compose->use_signing) {
4706 if (ainfo->encoding == ENC_7BIT)
4707 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4708 else if (ainfo->encoding == ENC_8BIT)
4709 ainfo->encoding = ENC_BASE64;
4712 procmime_encode_content(mimepart, ainfo->encoding);
4714 g_node_append(parent->node, mimepart->node);
4715 } while (gtk_tree_model_iter_next(model, &iter));
4718 #define QUOTE_IF_REQUIRED(out, str) \
4720 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4724 len = strlen(str) + 3; \
4725 if ((__tmp = alloca(len)) == NULL) { \
4726 g_warning("can't allocate memory\n"); \
4727 g_string_free(header, TRUE); \
4730 g_snprintf(__tmp, len, "\"%s\"", str); \
4735 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4736 g_warning("can't allocate memory\n"); \
4737 g_string_free(header, TRUE); \
4740 strcpy(__tmp, str); \
4746 #define IS_IN_CUSTOM_HEADER(header) \
4747 (compose->account->add_customhdr && \
4748 custom_header_find(compose->account->customhdr_list, header) != NULL)
4750 static void compose_add_headerfield_from_headerlist(Compose *compose,
4752 const gchar *fieldname,
4753 const gchar *seperator)
4755 gchar *str, *fieldname_w_colon, *trans_fieldname;
4756 gboolean add_field = FALSE;
4758 ComposeHeaderEntry *headerentry;
4759 const gchar * headerentryname;
4762 if (IS_IN_CUSTOM_HEADER(fieldname))
4765 debug_print("Adding %s-fields\n", fieldname);
4767 fieldstr = g_string_sized_new(64);
4769 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4770 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4772 for (list = compose->header_list; list; list = list->next) {
4773 headerentry = ((ComposeHeaderEntry *)list->data);
4774 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4776 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4777 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4779 if (str[0] != '\0') {
4781 g_string_append(fieldstr, seperator);
4782 g_string_append(fieldstr, str);
4791 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4792 compose_convert_header
4793 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4794 strlen(fieldname) + 2, TRUE);
4795 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4799 g_free(fieldname_w_colon);
4800 g_string_free(fieldstr, TRUE);
4805 static gchar *compose_get_header(Compose *compose)
4807 gchar buf[BUFFSIZE];
4808 const gchar *entry_str;
4812 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4815 g_return_val_if_fail(compose->account != NULL, NULL);
4816 g_return_val_if_fail(compose->account->address != NULL, NULL);
4818 header = g_string_sized_new(64);
4821 if (compose->account->add_date) {
4822 get_rfc822_date(buf, sizeof(buf));
4823 g_string_append_printf(header, "Date: %s\n", buf);
4827 if (compose->account->name && *compose->account->name) {
4828 compose_convert_header
4829 (compose, buf, sizeof(buf), compose->account->name,
4830 strlen("From: "), TRUE);
4831 QUOTE_IF_REQUIRED(name, buf);
4832 g_string_append_printf(header, "From: %s <%s>\n",
4833 name, compose->account->address);
4835 g_string_append_printf(header, "From: %s\n", compose->account->address);
4838 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4841 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4844 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4847 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4850 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4852 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4855 compose_convert_header(compose, buf, sizeof(buf), str,
4856 strlen("Subject: "), FALSE);
4857 g_string_append_printf(header, "Subject: %s\n", buf);
4863 if (compose->account->gen_msgid) {
4864 generate_msgid(buf, sizeof(buf));
4865 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4866 compose->msgid = g_strdup(buf);
4869 if (compose->remove_references == FALSE) {
4871 if (compose->inreplyto && compose->to_list)
4872 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4875 if (compose->references)
4876 g_string_append_printf(header, "References: %s\n", compose->references);
4880 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4883 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4886 if (compose->account->organization &&
4887 strlen(compose->account->organization) &&
4888 !IS_IN_CUSTOM_HEADER("Organization")) {
4889 compose_convert_header(compose, buf, sizeof(buf),
4890 compose->account->organization,
4891 strlen("Organization: "), FALSE);
4892 g_string_append_printf(header, "Organization: %s\n", buf);
4895 /* Program version and system info */
4896 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4897 !compose->newsgroup_list) {
4898 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4900 gtk_major_version, gtk_minor_version, gtk_micro_version,
4903 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4904 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4906 gtk_major_version, gtk_minor_version, gtk_micro_version,
4910 /* custom headers */
4911 if (compose->account->add_customhdr) {
4914 for (cur = compose->account->customhdr_list; cur != NULL;
4916 CustomHeader *chdr = (CustomHeader *)cur->data;
4918 if (custom_header_is_allowed(chdr->name)) {
4919 compose_convert_header
4920 (compose, buf, sizeof(buf),
4921 chdr->value ? chdr->value : "",
4922 strlen(chdr->name) + 2, FALSE);
4923 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4929 switch (compose->priority) {
4930 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4931 "X-Priority: 1 (Highest)\n");
4933 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4934 "X-Priority: 2 (High)\n");
4936 case PRIORITY_NORMAL: break;
4937 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4938 "X-Priority: 4 (Low)\n");
4940 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4941 "X-Priority: 5 (Lowest)\n");
4943 default: debug_print("compose: priority unknown : %d\n",
4947 /* Request Return Receipt */
4948 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4949 if (compose->return_receipt) {
4950 if (compose->account->name
4951 && *compose->account->name) {
4952 compose_convert_header(compose, buf, sizeof(buf),
4953 compose->account->name,
4954 strlen("Disposition-Notification-To: "),
4956 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4958 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4962 /* get special headers */
4963 for (list = compose->header_list; list; list = list->next) {
4964 ComposeHeaderEntry *headerentry;
4967 gchar *headername_wcolon;
4968 gchar *headername_trans;
4971 gboolean standard_header = FALSE;
4973 headerentry = ((ComposeHeaderEntry *)list->data);
4975 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4976 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4981 if (!strstr(tmp, ":")) {
4982 headername_wcolon = g_strconcat(tmp, ":", NULL);
4983 headername = g_strdup(tmp);
4985 headername_wcolon = g_strdup(tmp);
4986 headername = g_strdup(strtok(tmp, ":"));
4990 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4991 Xstrdup_a(headervalue, entry_str, return NULL);
4992 subst_char(headervalue, '\r', ' ');
4993 subst_char(headervalue, '\n', ' ');
4994 string = std_headers;
4995 while (*string != NULL) {
4996 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4997 if (!strcmp(headername_trans,headername_wcolon))
4998 standard_header = TRUE;
5001 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5002 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5005 g_free(headername_wcolon);
5009 g_string_free(header, FALSE);
5014 #undef IS_IN_CUSTOM_HEADER
5016 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5017 gint header_len, gboolean addr_field)
5019 gchar *tmpstr = NULL;
5020 const gchar *out_codeset = NULL;
5022 g_return_if_fail(src != NULL);
5023 g_return_if_fail(dest != NULL);
5025 if (len < 1) return;
5027 tmpstr = g_strdup(src);
5029 subst_char(tmpstr, '\n', ' ');
5030 subst_char(tmpstr, '\r', ' ');
5033 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5034 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5035 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5040 codeconv_set_strict(TRUE);
5041 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5042 conv_get_charset_str(compose->out_encoding));
5043 codeconv_set_strict(FALSE);
5045 if (!dest || *dest == '\0') {
5046 gchar *test_conv_global_out = NULL;
5047 gchar *test_conv_reply = NULL;
5049 /* automatic mode. be automatic. */
5050 codeconv_set_strict(TRUE);
5052 out_codeset = conv_get_outgoing_charset_str();
5054 debug_print("trying to convert to %s\n", out_codeset);
5055 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5058 if (!test_conv_global_out && compose->orig_charset) {
5059 out_codeset = compose->orig_charset;
5060 debug_print("failure; trying to convert to %s\n", out_codeset);
5061 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5064 if (!test_conv_global_out && !test_conv_reply) {
5066 out_codeset = CS_INTERNAL;
5067 debug_print("finally using %s\n", out_codeset);
5069 g_free(test_conv_global_out);
5070 g_free(test_conv_reply);
5071 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5073 codeconv_set_strict(FALSE);
5078 static void compose_create_header_entry(Compose *compose)
5080 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5084 GList *combo_list = NULL;
5086 const gchar *header = NULL;
5087 ComposeHeaderEntry *headerentry;
5088 gboolean standard_header = FALSE;
5090 headerentry = g_new0(ComposeHeaderEntry, 1);
5093 combo = gtk_combo_new();
5095 while(*string != NULL) {
5096 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5099 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5100 g_list_free(combo_list);
5101 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5102 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5103 G_CALLBACK(compose_grab_focus_cb), compose);
5104 gtk_widget_show(combo);
5105 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5106 if (compose->header_last) {
5107 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5109 while (*string != NULL) {
5110 if (!strcmp(*string, last_header_entry))
5111 standard_header = TRUE;
5114 if (standard_header)
5115 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5117 if (!compose->header_last || !standard_header) {
5118 switch(compose->account->protocol) {
5120 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5123 header = prefs_common.trans_hdr ? _("To:") : "To:";
5128 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5130 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5131 G_CALLBACK(compose_grab_focus_cb), compose);
5134 entry = gtk_entry_new();
5135 gtk_widget_show(entry);
5136 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);
5138 g_signal_connect(G_OBJECT(entry), "key-press-event",
5139 G_CALLBACK(compose_headerentry_key_press_event_cb),
5141 g_signal_connect(G_OBJECT(entry), "changed",
5142 G_CALLBACK(compose_headerentry_changed_cb),
5144 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5145 G_CALLBACK(compose_grab_focus_cb), compose);
5148 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5149 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5150 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5151 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5152 G_CALLBACK(compose_header_drag_received_cb),
5154 g_signal_connect(G_OBJECT(entry), "drag-drop",
5155 G_CALLBACK(compose_drag_drop),
5158 address_completion_register_entry(GTK_ENTRY(entry));
5160 headerentry->compose = compose;
5161 headerentry->combo = combo;
5162 headerentry->entry = entry;
5163 headerentry->headernum = compose->header_nextrow;
5165 compose->header_nextrow++;
5166 compose->header_last = headerentry;
5169 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5171 ComposeHeaderEntry *last_header;
5173 last_header = compose->header_last;
5175 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5176 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5179 static GtkWidget *compose_create_header(Compose *compose)
5183 GtkWidget *from_optmenu_hbox;
5184 GtkWidget *header_scrolledwin;
5185 GtkWidget *header_table;
5189 /* header labels and entries */
5190 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5191 gtk_widget_show(header_scrolledwin);
5192 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5194 header_table = gtk_table_new(2, 2, FALSE);
5195 gtk_widget_show(header_table);
5196 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5197 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5198 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5201 /* option menu for selecting accounts */
5202 hbox = gtk_hbox_new(FALSE, 0);
5203 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5204 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5205 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5207 from_optmenu_hbox = compose_account_option_menu_create(compose);
5208 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5209 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5212 compose->header_table = header_table;
5213 compose->header_list = NULL;
5214 compose->header_nextrow = count;
5216 compose_create_header_entry(compose);
5218 compose->table = NULL;
5220 return header_scrolledwin ;
5223 GtkWidget *compose_create_attach(Compose *compose)
5225 GtkWidget *attach_scrwin;
5226 GtkWidget *attach_clist;
5228 GtkListStore *store;
5229 GtkCellRenderer *renderer;
5230 GtkTreeViewColumn *column;
5231 GtkTreeSelection *selection;
5233 /* attachment list */
5234 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5235 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5236 GTK_POLICY_AUTOMATIC,
5237 GTK_POLICY_AUTOMATIC);
5238 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5240 store = gtk_list_store_new(N_ATTACH_COLS,
5245 G_TYPE_AUTO_POINTER,
5247 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5248 (GTK_TREE_MODEL(store)));
5249 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5250 g_object_unref(store);
5252 renderer = gtk_cell_renderer_text_new();
5253 column = gtk_tree_view_column_new_with_attributes
5254 (_("Mime type"), renderer, "text",
5255 COL_MIMETYPE, NULL);
5256 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5258 renderer = gtk_cell_renderer_text_new();
5259 column = gtk_tree_view_column_new_with_attributes
5260 (_("Size"), renderer, "text",
5262 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5264 renderer = gtk_cell_renderer_text_new();
5265 column = gtk_tree_view_column_new_with_attributes
5266 (_("Name"), renderer, "text",
5268 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5270 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5271 prefs_common.enable_rules_hint);
5272 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5273 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5275 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5276 G_CALLBACK(attach_selected), compose);
5277 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5278 G_CALLBACK(attach_button_pressed), compose);
5279 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5280 G_CALLBACK(attach_key_pressed), compose);
5283 gtk_drag_dest_set(attach_clist,
5284 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5285 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5286 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5287 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5288 G_CALLBACK(compose_attach_drag_received_cb),
5290 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5291 G_CALLBACK(compose_drag_drop),
5294 compose->attach_scrwin = attach_scrwin;
5295 compose->attach_clist = attach_clist;
5297 return attach_scrwin;
5300 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5301 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5303 static GtkWidget *compose_create_others(Compose *compose)
5306 GtkWidget *savemsg_checkbtn;
5307 GtkWidget *savemsg_entry;
5308 GtkWidget *savemsg_select;
5311 gchar *folderidentifier;
5313 /* Table for settings */
5314 table = gtk_table_new(3, 1, FALSE);
5315 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5316 gtk_widget_show(table);
5317 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5320 /* Save Message to folder */
5321 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5322 gtk_widget_show(savemsg_checkbtn);
5323 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5324 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5325 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5327 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5328 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5330 savemsg_entry = gtk_entry_new();
5331 gtk_widget_show(savemsg_entry);
5332 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5333 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5334 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5335 G_CALLBACK(compose_grab_focus_cb), compose);
5336 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5337 folderidentifier = folder_item_get_identifier(account_get_special_folder
5338 (compose->account, F_OUTBOX));
5339 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5340 g_free(folderidentifier);
5343 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5344 gtk_widget_show(savemsg_select);
5345 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5346 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5347 G_CALLBACK(compose_savemsg_select_cb),
5352 compose->savemsg_checkbtn = savemsg_checkbtn;
5353 compose->savemsg_entry = savemsg_entry;
5358 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5360 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5361 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5364 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5369 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5372 path = folder_item_get_identifier(dest);
5374 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5378 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5379 GdkAtom clip, GtkTextIter *insert_place);
5381 #define BLOCK_WRAP() { \
5382 prev_autowrap = compose->autowrap; \
5383 buffer = gtk_text_view_get_buffer( \
5384 GTK_TEXT_VIEW(compose->text)); \
5385 compose->autowrap = FALSE; \
5387 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5388 G_CALLBACK(compose_changed_cb), \
5390 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5391 G_CALLBACK(text_inserted), \
5394 #define UNBLOCK_WRAP() { \
5395 compose->autowrap = prev_autowrap; \
5396 if (compose->autowrap) \
5397 compose_wrap_all(compose); \
5399 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5400 G_CALLBACK(compose_changed_cb), \
5402 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5403 G_CALLBACK(text_inserted), \
5408 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5412 GtkTextBuffer *buffer;
5414 if (event->button == 3) {
5416 GtkTextIter sel_start, sel_end;
5417 gboolean stuff_selected;
5419 /* move the cursor to allow GtkAspell to check the word
5420 * under the mouse */
5421 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5422 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5424 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5427 stuff_selected = gtk_text_buffer_get_selection_bounds(
5428 GTK_TEXT_VIEW(text)->buffer,
5429 &sel_start, &sel_end);
5431 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5432 /* reselect stuff */
5434 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5435 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5436 &sel_start, &sel_end);
5438 return FALSE; /* pass the event so that the right-click goes through */
5441 if (event->button == 2) {
5446 /* get the middle-click position to paste at the correct place */
5447 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5448 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5450 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5453 entry_paste_clipboard(compose, text,
5454 prefs_common.linewrap_pastes,
5455 GDK_SELECTION_PRIMARY, &iter);
5462 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5469 GtkWidget *handlebox;
5471 GtkWidget *notebook;
5476 GtkWidget *subject_hbox;
5477 GtkWidget *subject_frame;
5478 GtkWidget *subject_entry;
5482 GtkWidget *edit_vbox;
5483 GtkWidget *ruler_hbox;
5485 GtkWidget *scrolledwin;
5487 GtkTextBuffer *buffer;
5488 GtkClipboard *clipboard;
5490 UndoMain *undostruct;
5492 gchar *titles[N_ATTACH_COLS];
5493 guint n_menu_entries;
5496 gboolean success[1];
5497 GtkWidget *popupmenu;
5498 GtkItemFactory *popupfactory;
5499 GtkItemFactory *ifactory;
5500 GtkWidget *tmpl_menu;
5502 GtkWidget *menuitem;
5505 GtkAspell * gtkaspell = NULL;
5508 static GdkGeometry geometry;
5510 g_return_val_if_fail(account != NULL, NULL);
5512 debug_print("Creating compose window...\n");
5513 compose = g_new0(Compose, 1);
5515 titles[COL_MIMETYPE] = _("MIME type");
5516 titles[COL_SIZE] = _("Size");
5517 titles[COL_NAME] = _("Name");
5519 compose->batch = batch;
5520 compose->account = account;
5522 compose->mutex = g_mutex_new();
5523 compose->set_cursor_pos = -1;
5525 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5526 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5527 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5529 if (!geometry.max_width) {
5530 geometry.max_width = gdk_screen_width();
5531 geometry.max_height = gdk_screen_height();
5534 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5535 &geometry, GDK_HINT_MAX_SIZE);
5536 if (!geometry.min_width) {
5537 geometry.min_width = 600;
5538 geometry.min_height = 480;
5540 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5541 &geometry, GDK_HINT_MIN_SIZE);
5542 gtk_widget_set_uposition(window, prefs_common.compose_x,
5543 prefs_common.compose_y);
5545 g_signal_connect(G_OBJECT(window), "delete_event",
5546 G_CALLBACK(compose_delete_cb), compose);
5547 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5548 gtk_widget_realize(window);
5550 gtkut_widget_set_composer_icon(window);
5552 vbox = gtk_vbox_new(FALSE, 0);
5553 gtk_container_add(GTK_CONTAINER(window), vbox);
5555 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5556 menubar = menubar_create(window, compose_entries,
5557 n_menu_entries, "<Compose>", compose);
5558 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5560 if (prefs_common.toolbar_detachable) {
5561 handlebox = gtk_handle_box_new();
5563 handlebox = gtk_hbox_new(FALSE, 0);
5565 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5567 gtk_widget_realize(handlebox);
5568 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5571 vbox2 = gtk_vbox_new(FALSE, 2);
5572 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5573 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5576 notebook = gtk_notebook_new();
5577 gtk_widget_set_size_request(notebook, -1, 130);
5578 gtk_widget_show(notebook);
5580 /* header labels and entries */
5581 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5582 compose_create_header(compose),
5583 gtk_label_new_with_mnemonic(_("Hea_der")));
5584 /* attachment list */
5585 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5586 compose_create_attach(compose),
5587 gtk_label_new_with_mnemonic(_("_Attachments")));
5589 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5590 compose_create_others(compose),
5591 gtk_label_new_with_mnemonic(_("Othe_rs")));
5594 subject_hbox = gtk_hbox_new(FALSE, 0);
5595 gtk_widget_show(subject_hbox);
5597 subject_frame = gtk_frame_new(NULL);
5598 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5599 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5600 gtk_widget_show(subject_frame);
5602 subject = gtk_hbox_new(FALSE, 0);
5603 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5604 gtk_widget_show(subject);
5606 label = gtk_label_new(_("Subject:"));
5607 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5608 gtk_widget_show(label);
5610 subject_entry = gtk_entry_new();
5611 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5612 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5613 G_CALLBACK(compose_grab_focus_cb), compose);
5614 gtk_widget_show(subject_entry);
5615 compose->subject_entry = subject_entry;
5616 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5618 edit_vbox = gtk_vbox_new(FALSE, 0);
5620 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5623 ruler_hbox = gtk_hbox_new(FALSE, 0);
5624 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5626 ruler = gtk_shruler_new();
5627 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5628 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5632 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5633 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5634 GTK_POLICY_AUTOMATIC,
5635 GTK_POLICY_AUTOMATIC);
5636 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5638 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5639 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5641 text = gtk_text_view_new();
5642 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5643 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5644 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5645 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5646 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5648 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5650 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5651 G_CALLBACK(compose_edit_size_alloc),
5653 g_signal_connect(G_OBJECT(buffer), "changed",
5654 G_CALLBACK(compose_changed_cb), compose);
5655 g_signal_connect(G_OBJECT(text), "grab_focus",
5656 G_CALLBACK(compose_grab_focus_cb), compose);
5657 g_signal_connect(G_OBJECT(buffer), "insert_text",
5658 G_CALLBACK(text_inserted), compose);
5659 g_signal_connect(G_OBJECT(text), "button_press_event",
5660 G_CALLBACK(text_clicked), compose);
5661 g_signal_connect(G_OBJECT(subject_entry), "changed",
5662 G_CALLBACK(compose_changed_cb), compose);
5665 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5666 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5667 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5668 g_signal_connect(G_OBJECT(text), "drag_data_received",
5669 G_CALLBACK(compose_insert_drag_received_cb),
5671 g_signal_connect(G_OBJECT(text), "drag-drop",
5672 G_CALLBACK(compose_drag_drop),
5674 gtk_widget_show_all(vbox);
5676 /* pane between attach clist and text */
5677 paned = gtk_vpaned_new();
5678 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5679 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5680 gtk_paned_add1(GTK_PANED(paned), notebook);
5681 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5682 gtk_widget_show_all(paned);
5685 if (prefs_common.textfont) {
5686 PangoFontDescription *font_desc;
5688 font_desc = pango_font_description_from_string
5689 (prefs_common.textfont);
5691 gtk_widget_modify_font(text, font_desc);
5692 pango_font_description_free(font_desc);
5696 color[0] = quote_color;
5697 cmap = gdk_drawable_get_colormap(window->window);
5698 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5699 if (success[0] == FALSE) {
5702 g_warning("Compose: color allocation failed.\n");
5703 style = gtk_widget_get_style(text);
5704 quote_color = style->black;
5707 n_entries = sizeof(compose_popup_entries) /
5708 sizeof(compose_popup_entries[0]);
5709 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5710 "<Compose>", &popupfactory,
5713 ifactory = gtk_item_factory_from_widget(menubar);
5714 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5715 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5716 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5718 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5720 undostruct = undo_init(text);
5721 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5724 address_completion_start(window);
5726 compose->window = window;
5727 compose->vbox = vbox;
5728 compose->menubar = menubar;
5729 compose->handlebox = handlebox;
5731 compose->vbox2 = vbox2;
5733 compose->paned = paned;
5735 compose->edit_vbox = edit_vbox;
5736 compose->ruler_hbox = ruler_hbox;
5737 compose->ruler = ruler;
5738 compose->scrolledwin = scrolledwin;
5739 compose->text = text;
5741 compose->focused_editable = NULL;
5743 compose->popupmenu = popupmenu;
5744 compose->popupfactory = popupfactory;
5746 compose->tmpl_menu = tmpl_menu;
5748 compose->mode = mode;
5750 compose->targetinfo = NULL;
5751 compose->replyinfo = NULL;
5752 compose->fwdinfo = NULL;
5754 compose->replyto = NULL;
5756 compose->bcc = NULL;
5757 compose->followup_to = NULL;
5759 compose->ml_post = NULL;
5761 compose->inreplyto = NULL;
5762 compose->references = NULL;
5763 compose->msgid = NULL;
5764 compose->boundary = NULL;
5766 compose->autowrap = prefs_common.autowrap;
5768 compose->use_signing = FALSE;
5769 compose->use_encryption = FALSE;
5770 compose->privacy_system = NULL;
5772 compose->modified = FALSE;
5774 compose->return_receipt = FALSE;
5776 compose->to_list = NULL;
5777 compose->newsgroup_list = NULL;
5779 compose->undostruct = undostruct;
5781 compose->sig_str = NULL;
5783 compose->exteditor_file = NULL;
5784 compose->exteditor_pid = -1;
5785 compose->exteditor_tag = -1;
5786 compose->draft_timeout_tag = -1;
5789 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5790 if (mode != COMPOSE_REDIRECT) {
5791 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5792 strcmp(prefs_common.dictionary, "")) {
5793 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5794 prefs_common.dictionary,
5795 conv_get_locale_charset_str(),
5796 prefs_common.misspelled_col,
5797 prefs_common.check_while_typing,
5798 prefs_common.recheck_when_changing_dict,
5799 prefs_common.use_alternate,
5800 GTK_TEXT_VIEW(text),
5801 GTK_WINDOW(compose->window));
5803 alertpanel_error(_("Spell checker could not "
5805 gtkaspell_checkers_strerror());
5806 gtkaspell_checkers_reset_error();
5808 if (!gtkaspell_set_sug_mode(gtkaspell,
5809 prefs_common.aspell_sugmode)) {
5810 debug_print("Aspell: could not set "
5811 "suggestion mode %s\n",
5812 gtkaspell_checkers_strerror());
5813 gtkaspell_checkers_reset_error();
5816 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5820 compose->gtkaspell = gtkaspell;
5823 compose_select_account(compose, account, TRUE);
5825 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5826 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5827 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5829 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5830 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5832 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5833 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5836 if (account->protocol != A_NNTP)
5837 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5839 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5841 addressbook_set_target_compose(compose);
5843 if (mode != COMPOSE_REDIRECT)
5844 compose_set_template_menu(compose);
5846 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5847 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5850 compose_list = g_list_append(compose_list, compose);
5852 if (!prefs_common.show_ruler)
5853 gtk_widget_hide(ruler_hbox);
5855 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5856 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5857 prefs_common.show_ruler);
5860 compose->priority = PRIORITY_NORMAL;
5861 compose_update_priority_menu_item(compose);
5863 compose_set_out_encoding(compose);
5866 compose_update_actions_menu(compose);
5868 /* Privacy Systems menu */
5869 compose_update_privacy_systems_menu(compose);
5871 activate_privacy_system(compose, account, TRUE);
5872 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5874 gtk_widget_realize(window);
5876 gtk_widget_show(window);
5882 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5887 gint num = 0, def_menu = 0;
5889 accounts = account_get_list();
5890 g_return_val_if_fail(accounts != NULL, NULL);
5892 optmenu = gtk_option_menu_new();
5893 menu = gtk_menu_new();
5895 for (; accounts != NULL; accounts = accounts->next, num++) {
5896 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5897 GtkWidget *menuitem;
5900 if (ac == compose->account) def_menu = num;
5903 name = g_markup_printf_escaped("<i>%s</i> : %s <<b>%s</b>>",
5905 ac->name, ac->address);
5907 name = g_markup_printf_escaped("<i>%s</i> : <<b>%s</b>>",
5908 ac->account_name, ac->address);
5909 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5910 gtk_label_set_use_markup (
5911 GTK_LABEL (gtk_bin_get_child (GTK_BIN (menuitem))),
5914 g_signal_connect(G_OBJECT(menuitem), "activate",
5915 G_CALLBACK(account_activated),
5919 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5920 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5925 static void compose_set_priority_cb(gpointer data,
5929 Compose *compose = (Compose *) data;
5930 compose->priority = action;
5933 static void compose_update_priority_menu_item(Compose * compose)
5935 GtkItemFactory *ifactory;
5936 GtkWidget *menuitem = NULL;
5938 ifactory = gtk_item_factory_from_widget(compose->menubar);
5940 switch (compose->priority) {
5941 case PRIORITY_HIGHEST:
5942 menuitem = gtk_item_factory_get_item
5943 (ifactory, "/Options/Priority/Highest");
5946 menuitem = gtk_item_factory_get_item
5947 (ifactory, "/Options/Priority/High");
5949 case PRIORITY_NORMAL:
5950 menuitem = gtk_item_factory_get_item
5951 (ifactory, "/Options/Priority/Normal");
5954 menuitem = gtk_item_factory_get_item
5955 (ifactory, "/Options/Priority/Low");
5957 case PRIORITY_LOWEST:
5958 menuitem = gtk_item_factory_get_item
5959 (ifactory, "/Options/Priority/Lowest");
5962 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5965 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5967 Compose *compose = (Compose *) data;
5969 GtkItemFactory *ifactory;
5970 gboolean can_sign = FALSE, can_encrypt = FALSE;
5972 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5974 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5977 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5978 g_free(compose->privacy_system);
5979 compose->privacy_system = NULL;
5980 if (systemid != NULL) {
5981 compose->privacy_system = g_strdup(systemid);
5983 can_sign = privacy_system_can_sign(systemid);
5984 can_encrypt = privacy_system_can_encrypt(systemid);
5987 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5989 ifactory = gtk_item_factory_from_widget(compose->menubar);
5990 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5991 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5994 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5996 static gchar *branch_path = "/Options/Privacy System";
5997 GtkItemFactory *ifactory;
5998 GtkWidget *menuitem = NULL;
6000 gboolean can_sign = FALSE, can_encrypt = FALSE;
6001 gboolean found = FALSE;
6003 ifactory = gtk_item_factory_from_widget(compose->menubar);
6005 if (compose->privacy_system != NULL) {
6008 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6009 g_return_if_fail(menuitem != NULL);
6011 amenu = GTK_MENU_SHELL(menuitem)->children;
6013 while (amenu != NULL) {
6014 GList *alist = amenu->next;
6016 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6017 if (systemid != NULL) {
6018 if (strcmp(systemid, compose->privacy_system) == 0) {
6019 menuitem = GTK_WIDGET(amenu->data);
6021 can_sign = privacy_system_can_sign(systemid);
6022 can_encrypt = privacy_system_can_encrypt(systemid);
6026 } else if (strlen(compose->privacy_system) == 0) {
6027 menuitem = GTK_WIDGET(amenu->data);
6030 can_encrypt = FALSE;
6037 if (menuitem != NULL)
6038 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6040 if (warn && !found && strlen(compose->privacy_system)) {
6041 gchar *tmp = g_strdup_printf(
6042 _("The privacy system '%s' cannot be loaded. You "
6043 "will not be able to sign or encrypt this message."),
6044 compose->privacy_system);
6045 alertpanel_warning(tmp);
6050 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6051 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6054 static void compose_set_out_encoding(Compose *compose)
6056 GtkItemFactoryEntry *entry;
6057 GtkItemFactory *ifactory;
6058 CharSet out_encoding;
6059 gchar *path, *p, *q;
6062 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6063 ifactory = gtk_item_factory_from_widget(compose->menubar);
6065 for (entry = compose_entries; entry->callback != compose_address_cb;
6067 if (entry->callback == compose_set_encoding_cb &&
6068 (CharSet)entry->callback_action == out_encoding) {
6069 p = q = path = g_strdup(entry->path);
6081 item = gtk_item_factory_get_item(ifactory, path);
6082 gtk_widget_activate(item);
6089 static void compose_set_template_menu(Compose *compose)
6091 GSList *tmpl_list, *cur;
6095 tmpl_list = template_get_config();
6097 menu = gtk_menu_new();
6099 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6100 Template *tmpl = (Template *)cur->data;
6102 item = gtk_menu_item_new_with_label(tmpl->name);
6103 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6104 g_signal_connect(G_OBJECT(item), "activate",
6105 G_CALLBACK(compose_template_activate_cb),
6107 g_object_set_data(G_OBJECT(item), "template", tmpl);
6108 gtk_widget_show(item);
6111 gtk_widget_show(menu);
6112 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6115 void compose_update_actions_menu(Compose *compose)
6117 GtkItemFactory *ifactory;
6119 ifactory = gtk_item_factory_from_widget(compose->menubar);
6120 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6123 void compose_update_privacy_systems_menu(Compose *compose)
6125 static gchar *branch_path = "/Options/Privacy System";
6126 GtkItemFactory *ifactory;
6127 GtkWidget *menuitem;
6128 GSList *systems, *cur;
6131 GtkWidget *system_none;
6134 ifactory = gtk_item_factory_from_widget(compose->menubar);
6136 /* remove old entries */
6137 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6138 g_return_if_fail(menuitem != NULL);
6140 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6141 while (amenu != NULL) {
6142 GList *alist = amenu->next;
6143 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6147 system_none = gtk_item_factory_get_widget(ifactory,
6148 "/Options/Privacy System/None");
6150 g_signal_connect(G_OBJECT(system_none), "activate",
6151 G_CALLBACK(compose_set_privacy_system_cb), compose);
6153 systems = privacy_get_system_ids();
6154 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6155 gchar *systemid = cur->data;
6157 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6158 widget = gtk_radio_menu_item_new_with_label(group,
6159 privacy_system_get_name(systemid));
6160 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6161 g_strdup(systemid), g_free);
6162 g_signal_connect(G_OBJECT(widget), "activate",
6163 G_CALLBACK(compose_set_privacy_system_cb), compose);
6165 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6166 gtk_widget_show(widget);
6169 g_slist_free(systems);
6172 void compose_reflect_prefs_all(void)
6177 for (cur = compose_list; cur != NULL; cur = cur->next) {
6178 compose = (Compose *)cur->data;
6179 compose_set_template_menu(compose);
6183 void compose_reflect_prefs_pixmap_theme(void)
6188 for (cur = compose_list; cur != NULL; cur = cur->next) {
6189 compose = (Compose *)cur->data;
6190 toolbar_update(TOOLBAR_COMPOSE, compose);
6194 static void compose_template_apply(Compose *compose, Template *tmpl,
6198 GtkTextBuffer *buffer;
6202 gchar *parsed_str = NULL;
6203 gint cursor_pos = 0;
6206 /* process the body */
6208 text = GTK_TEXT_VIEW(compose->text);
6209 buffer = gtk_text_view_get_buffer(text);
6212 gtk_text_buffer_set_text(buffer, "", -1);
6214 mark = gtk_text_buffer_get_insert(buffer);
6215 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6218 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6219 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6222 if (prefs_common.quotemark && *prefs_common.quotemark)
6223 qmark = prefs_common.quotemark;
6227 if (compose->replyinfo != NULL)
6228 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6229 tmpl->value, qmark, NULL, FALSE);
6230 else if (compose->fwdinfo != NULL)
6231 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6232 tmpl->value, qmark, NULL, FALSE);
6237 if (replace && parsed_str && compose->account->auto_sig)
6238 compose_insert_sig(compose, FALSE);
6240 if (replace && parsed_str) {
6241 gtk_text_buffer_get_start_iter(buffer, &iter);
6242 gtk_text_buffer_place_cursor(buffer, &iter);
6246 cursor_pos = quote_fmt_get_cursor_pos();
6247 compose->set_cursor_pos = cursor_pos;
6248 if (cursor_pos == -1)
6250 gtk_text_buffer_get_start_iter(buffer, &iter);
6251 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6252 gtk_text_buffer_place_cursor(buffer, &iter);
6255 /* process the other fields */
6256 compose_template_apply_fields(compose, tmpl);
6258 compose_changed_cb(NULL, compose);
6261 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6263 static MsgInfo dummyinfo;
6264 MsgInfo *msginfo = NULL;
6267 if (compose->replyinfo != NULL)
6268 msginfo = compose->replyinfo;
6269 else if (compose->fwdinfo != NULL)
6270 msginfo = compose->fwdinfo;
6272 msginfo = &dummyinfo;
6274 if (tmpl->to && *tmpl->to != '\0') {
6275 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6276 quote_fmt_scan_string(tmpl->to);
6279 buf = quote_fmt_get_buffer();
6281 alertpanel_error(_("Message To format error."));
6283 compose_entry_append(compose, buf, COMPOSE_TO);
6287 if (tmpl->cc && *tmpl->cc != '\0') {
6288 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6289 quote_fmt_scan_string(tmpl->cc);
6292 buf = quote_fmt_get_buffer();
6294 alertpanel_error(_("Message Cc format error."));
6296 compose_entry_append(compose, buf, COMPOSE_CC);
6300 if (tmpl->bcc && *tmpl->bcc != '\0') {
6301 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6302 quote_fmt_scan_string(tmpl->bcc);
6305 buf = quote_fmt_get_buffer();
6307 alertpanel_error(_("Message Bcc format error."));
6309 compose_entry_append(compose, buf, COMPOSE_BCC);
6313 /* process the subject */
6314 if (tmpl->subject && *tmpl->subject != '\0') {
6315 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6316 quote_fmt_scan_string(tmpl->subject);
6319 buf = quote_fmt_get_buffer();
6321 alertpanel_error(_("Message subject format error."));
6323 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6328 static void compose_destroy(Compose *compose)
6330 compose_list = g_list_remove(compose_list, compose);
6332 if (compose->updating) {
6333 debug_print("danger, not destroying anything now\n");
6334 compose->deferred_destroy = TRUE;
6337 /* NOTE: address_completion_end() does nothing with the window
6338 * however this may change. */
6339 address_completion_end(compose->window);
6341 slist_free_strings(compose->to_list);
6342 g_slist_free(compose->to_list);
6343 slist_free_strings(compose->newsgroup_list);
6344 g_slist_free(compose->newsgroup_list);
6345 slist_free_strings(compose->header_list);
6346 g_slist_free(compose->header_list);
6348 procmsg_msginfo_free(compose->targetinfo);
6349 procmsg_msginfo_free(compose->replyinfo);
6350 procmsg_msginfo_free(compose->fwdinfo);
6352 g_free(compose->replyto);
6353 g_free(compose->cc);
6354 g_free(compose->bcc);
6355 g_free(compose->newsgroups);
6356 g_free(compose->followup_to);
6358 g_free(compose->ml_post);
6360 g_free(compose->inreplyto);
6361 g_free(compose->references);
6362 g_free(compose->msgid);
6363 g_free(compose->boundary);
6365 g_free(compose->redirect_filename);
6366 if (compose->undostruct)
6367 undo_destroy(compose->undostruct);
6369 g_free(compose->sig_str);
6371 g_free(compose->exteditor_file);
6373 g_free(compose->orig_charset);
6375 g_free(compose->privacy_system);
6377 if (addressbook_get_target_compose() == compose)
6378 addressbook_set_target_compose(NULL);
6381 if (compose->gtkaspell) {
6382 gtkaspell_delete(compose->gtkaspell);
6383 compose->gtkaspell = NULL;
6387 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6388 prefs_common.compose_height = compose->window->allocation.height;
6390 if (!gtk_widget_get_parent(compose->paned))
6391 gtk_widget_destroy(compose->paned);
6392 gtk_widget_destroy(compose->popupmenu);
6394 gtk_widget_destroy(compose->window);
6395 toolbar_destroy(compose->toolbar);
6396 g_free(compose->toolbar);
6397 g_mutex_free(compose->mutex);
6401 static void compose_attach_info_free(AttachInfo *ainfo)
6403 g_free(ainfo->file);
6404 g_free(ainfo->content_type);
6405 g_free(ainfo->name);
6409 static void compose_attach_remove_selected(Compose *compose)
6411 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6412 GtkTreeSelection *selection;
6414 GtkTreeModel *model;
6416 selection = gtk_tree_view_get_selection(tree_view);
6417 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6422 for (cur = sel; cur != NULL; cur = cur->next) {
6423 GtkTreePath *path = cur->data;
6424 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6427 gtk_tree_path_free(path);
6430 for (cur = sel; cur != NULL; cur = cur->next) {
6431 GtkTreeRowReference *ref = cur->data;
6432 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6435 if (gtk_tree_model_get_iter(model, &iter, path))
6436 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6438 gtk_tree_path_free(path);
6439 gtk_tree_row_reference_free(ref);
6445 static struct _AttachProperty
6448 GtkWidget *mimetype_entry;
6449 GtkWidget *encoding_optmenu;
6450 GtkWidget *path_entry;
6451 GtkWidget *filename_entry;
6453 GtkWidget *cancel_btn;
6456 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6458 gtk_tree_path_free((GtkTreePath *)ptr);
6461 static void compose_attach_property(Compose *compose)
6463 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6465 GtkOptionMenu *optmenu;
6466 GtkTreeSelection *selection;
6468 GtkTreeModel *model;
6471 static gboolean cancelled;
6473 /* only if one selected */
6474 selection = gtk_tree_view_get_selection(tree_view);
6475 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6478 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6482 path = (GtkTreePath *) sel->data;
6483 gtk_tree_model_get_iter(model, &iter, path);
6484 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6487 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6493 if (!attach_prop.window)
6494 compose_attach_property_create(&cancelled);
6495 gtk_widget_grab_focus(attach_prop.ok_btn);
6496 gtk_widget_show(attach_prop.window);
6497 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6499 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6500 if (ainfo->encoding == ENC_UNKNOWN)
6501 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6502 GINT_TO_POINTER(ENC_BASE64));
6504 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6505 GINT_TO_POINTER(ainfo->encoding));
6507 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6508 ainfo->content_type ? ainfo->content_type : "");
6509 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6510 ainfo->file ? ainfo->file : "");
6511 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6512 ainfo->name ? ainfo->name : "");
6515 const gchar *entry_text;
6517 gchar *cnttype = NULL;
6521 GtkWidget *menuitem;
6526 gtk_widget_hide(attach_prop.window);
6531 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6532 if (*entry_text != '\0') {
6535 text = g_strstrip(g_strdup(entry_text));
6536 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6537 cnttype = g_strdup(text);
6540 alertpanel_error(_("Invalid MIME type."));
6546 menu = gtk_option_menu_get_menu(optmenu);
6547 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6548 ainfo->encoding = GPOINTER_TO_INT
6549 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6551 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6552 if (*entry_text != '\0') {
6553 if (is_file_exist(entry_text) &&
6554 (size = get_file_size(entry_text)) > 0)
6555 file = g_strdup(entry_text);
6558 (_("File doesn't exist or is empty."));
6564 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6565 if (*entry_text != '\0') {
6566 g_free(ainfo->name);
6567 ainfo->name = g_strdup(entry_text);
6571 g_free(ainfo->content_type);
6572 ainfo->content_type = cnttype;
6575 g_free(ainfo->file);
6581 /* update tree store */
6582 text = to_human_readable(ainfo->size);
6583 gtk_tree_model_get_iter(model, &iter, path);
6584 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6585 COL_MIMETYPE, ainfo->content_type,
6587 COL_NAME, ainfo->name,
6593 gtk_tree_path_free(path);
6596 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6598 label = gtk_label_new(str); \
6599 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6600 GTK_FILL, 0, 0, 0); \
6601 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6603 entry = gtk_entry_new(); \
6604 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6605 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6608 static void compose_attach_property_create(gboolean *cancelled)
6614 GtkWidget *mimetype_entry;
6617 GtkWidget *optmenu_menu;
6618 GtkWidget *menuitem;
6619 GtkWidget *path_entry;
6620 GtkWidget *filename_entry;
6623 GtkWidget *cancel_btn;
6624 GList *mime_type_list, *strlist;
6626 debug_print("Creating attach_property window...\n");
6628 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6629 gtk_widget_set_size_request(window, 480, -1);
6630 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6631 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6632 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6633 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6634 g_signal_connect(G_OBJECT(window), "delete_event",
6635 G_CALLBACK(attach_property_delete_event),
6637 g_signal_connect(G_OBJECT(window), "key_press_event",
6638 G_CALLBACK(attach_property_key_pressed),
6641 vbox = gtk_vbox_new(FALSE, 8);
6642 gtk_container_add(GTK_CONTAINER(window), vbox);
6644 table = gtk_table_new(4, 2, FALSE);
6645 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6646 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6647 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6649 label = gtk_label_new(_("MIME type"));
6650 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6652 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6653 mimetype_entry = gtk_combo_new();
6654 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6655 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6657 /* stuff with list */
6658 mime_type_list = procmime_get_mime_type_list();
6660 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6661 MimeType *type = (MimeType *) mime_type_list->data;
6664 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6666 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6669 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6670 (GCompareFunc)strcmp2);
6673 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6675 for (mime_type_list = strlist; mime_type_list != NULL;
6676 mime_type_list = mime_type_list->next)
6677 g_free(mime_type_list->data);
6678 g_list_free(strlist);
6680 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6682 label = gtk_label_new(_("Encoding"));
6683 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6685 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6687 hbox = gtk_hbox_new(FALSE, 0);
6688 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6689 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6691 optmenu = gtk_option_menu_new();
6692 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6694 optmenu_menu = gtk_menu_new();
6695 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6696 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6697 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6698 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6699 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6700 ENC_QUOTED_PRINTABLE);
6701 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6703 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6705 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6707 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6708 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6710 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6711 &ok_btn, GTK_STOCK_OK,
6713 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6714 gtk_widget_grab_default(ok_btn);
6716 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6717 G_CALLBACK(attach_property_ok),
6719 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6720 G_CALLBACK(attach_property_cancel),
6723 gtk_widget_show_all(vbox);
6725 attach_prop.window = window;
6726 attach_prop.mimetype_entry = mimetype_entry;
6727 attach_prop.encoding_optmenu = optmenu;
6728 attach_prop.path_entry = path_entry;
6729 attach_prop.filename_entry = filename_entry;
6730 attach_prop.ok_btn = ok_btn;
6731 attach_prop.cancel_btn = cancel_btn;
6734 #undef SET_LABEL_AND_ENTRY
6736 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6742 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6748 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6749 gboolean *cancelled)
6757 static gboolean attach_property_key_pressed(GtkWidget *widget,
6759 gboolean *cancelled)
6761 if (event && event->keyval == GDK_Escape) {
6768 static void compose_exec_ext_editor(Compose *compose)
6775 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6776 G_DIR_SEPARATOR, compose);
6778 if (pipe(pipe_fds) < 0) {
6784 if ((pid = fork()) < 0) {
6791 /* close the write side of the pipe */
6794 compose->exteditor_file = g_strdup(tmp);
6795 compose->exteditor_pid = pid;
6797 compose_set_ext_editor_sensitive(compose, FALSE);
6799 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6800 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6804 } else { /* process-monitoring process */
6810 /* close the read side of the pipe */
6813 if (compose_write_body_to_file(compose, tmp) < 0) {
6814 fd_write_all(pipe_fds[1], "2\n", 2);
6818 pid_ed = compose_exec_ext_editor_real(tmp);
6820 fd_write_all(pipe_fds[1], "1\n", 2);
6824 /* wait until editor is terminated */
6825 waitpid(pid_ed, NULL, 0);
6827 fd_write_all(pipe_fds[1], "0\n", 2);
6834 #endif /* G_OS_UNIX */
6838 static gint compose_exec_ext_editor_real(const gchar *file)
6845 g_return_val_if_fail(file != NULL, -1);
6847 if ((pid = fork()) < 0) {
6852 if (pid != 0) return pid;
6854 /* grandchild process */
6856 if (setpgid(0, getppid()))
6859 if (prefs_common.ext_editor_cmd &&
6860 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6861 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6862 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6864 if (prefs_common.ext_editor_cmd)
6865 g_warning("External editor command line is invalid: '%s'\n",
6866 prefs_common.ext_editor_cmd);
6867 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
6870 cmdline = strsplit_with_quote(buf, " ", 1024);
6871 execvp(cmdline[0], cmdline);
6874 g_strfreev(cmdline);
6879 static gboolean compose_ext_editor_kill(Compose *compose)
6881 pid_t pgid = compose->exteditor_pid * -1;
6884 ret = kill(pgid, 0);
6886 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6890 msg = g_strdup_printf
6891 (_("The external editor is still working.\n"
6892 "Force terminating the process?\n"
6893 "process group id: %d"), -pgid);
6894 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
6895 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
6899 if (val == G_ALERTALTERNATE) {
6900 g_source_remove(compose->exteditor_tag);
6901 g_io_channel_shutdown(compose->exteditor_ch,
6903 g_io_channel_unref(compose->exteditor_ch);
6905 if (kill(pgid, SIGTERM) < 0) perror("kill");
6906 waitpid(compose->exteditor_pid, NULL, 0);
6908 g_warning("Terminated process group id: %d", -pgid);
6909 g_warning("Temporary file: %s",
6910 compose->exteditor_file);
6912 compose_set_ext_editor_sensitive(compose, TRUE);
6914 g_free(compose->exteditor_file);
6915 compose->exteditor_file = NULL;
6916 compose->exteditor_pid = -1;
6917 compose->exteditor_ch = NULL;
6918 compose->exteditor_tag = -1;
6926 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6930 Compose *compose = (Compose *)data;
6933 debug_print(_("Compose: input from monitoring process\n"));
6935 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6937 g_io_channel_shutdown(source, FALSE, NULL);
6938 g_io_channel_unref(source);
6940 waitpid(compose->exteditor_pid, NULL, 0);
6942 if (buf[0] == '0') { /* success */
6943 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6944 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6946 gtk_text_buffer_set_text(buffer, "", -1);
6947 compose_insert_file(compose, compose->exteditor_file);
6948 compose_changed_cb(NULL, compose);
6950 if (g_unlink(compose->exteditor_file) < 0)
6951 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6952 } else if (buf[0] == '1') { /* failed */
6953 g_warning("Couldn't exec external editor\n");
6954 if (g_unlink(compose->exteditor_file) < 0)
6955 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6956 } else if (buf[0] == '2') {
6957 g_warning("Couldn't write to file\n");
6958 } else if (buf[0] == '3') {
6959 g_warning("Pipe read failed\n");
6962 compose_set_ext_editor_sensitive(compose, TRUE);
6964 g_free(compose->exteditor_file);
6965 compose->exteditor_file = NULL;
6966 compose->exteditor_pid = -1;
6967 compose->exteditor_ch = NULL;
6968 compose->exteditor_tag = -1;
6973 static void compose_set_ext_editor_sensitive(Compose *compose,
6976 GtkItemFactory *ifactory;
6978 ifactory = gtk_item_factory_from_widget(compose->menubar);
6980 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6981 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6982 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6983 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6984 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6985 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6986 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6989 gtk_widget_set_sensitive(compose->text, sensitive);
6990 if (compose->toolbar->send_btn)
6991 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6992 if (compose->toolbar->sendl_btn)
6993 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6994 if (compose->toolbar->draft_btn)
6995 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6996 if (compose->toolbar->insert_btn)
6997 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6998 if (compose->toolbar->sig_btn)
6999 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7000 if (compose->toolbar->exteditor_btn)
7001 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7002 if (compose->toolbar->linewrap_current_btn)
7003 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7004 if (compose->toolbar->linewrap_all_btn)
7005 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7007 #endif /* G_OS_UNIX */
7010 * compose_undo_state_changed:
7012 * Change the sensivity of the menuentries undo and redo
7014 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7015 gint redo_state, gpointer data)
7017 GtkWidget *widget = GTK_WIDGET(data);
7018 GtkItemFactory *ifactory;
7020 g_return_if_fail(widget != NULL);
7022 ifactory = gtk_item_factory_from_widget(widget);
7024 switch (undo_state) {
7025 case UNDO_STATE_TRUE:
7026 if (!undostruct->undo_state) {
7027 undostruct->undo_state = TRUE;
7028 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7031 case UNDO_STATE_FALSE:
7032 if (undostruct->undo_state) {
7033 undostruct->undo_state = FALSE;
7034 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7037 case UNDO_STATE_UNCHANGED:
7039 case UNDO_STATE_REFRESH:
7040 menu_set_sensitive(ifactory, "/Edit/Undo",
7041 undostruct->undo_state);
7044 g_warning("Undo state not recognized");
7048 switch (redo_state) {
7049 case UNDO_STATE_TRUE:
7050 if (!undostruct->redo_state) {
7051 undostruct->redo_state = TRUE;
7052 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7055 case UNDO_STATE_FALSE:
7056 if (undostruct->redo_state) {
7057 undostruct->redo_state = FALSE;
7058 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7061 case UNDO_STATE_UNCHANGED:
7063 case UNDO_STATE_REFRESH:
7064 menu_set_sensitive(ifactory, "/Edit/Redo",
7065 undostruct->redo_state);
7068 g_warning("Redo state not recognized");
7073 /* callback functions */
7075 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7076 * includes "non-client" (windows-izm) in calculation, so this calculation
7077 * may not be accurate.
7079 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7080 GtkAllocation *allocation,
7081 GtkSHRuler *shruler)
7083 if (prefs_common.show_ruler) {
7084 gint char_width = 0, char_height = 0;
7085 gint line_width_in_chars;
7087 gtkut_get_font_size(GTK_WIDGET(widget),
7088 &char_width, &char_height);
7089 line_width_in_chars =
7090 (allocation->width - allocation->x) / char_width;
7092 /* got the maximum */
7093 gtk_ruler_set_range(GTK_RULER(shruler),
7094 0.0, line_width_in_chars, 0,
7095 /*line_width_in_chars*/ char_width);
7101 static void account_activated(GtkMenuItem *menuitem, gpointer data)
7103 Compose *compose = (Compose *)data;
7106 gchar *folderidentifier;
7108 ac = account_find_from_id(
7109 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
7110 g_return_if_fail(ac != NULL);
7112 if (ac != compose->account)
7113 compose_select_account(compose, ac, FALSE);
7115 /* Set message save folder */
7116 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7117 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7119 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7120 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7122 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7123 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7124 folderidentifier = folder_item_get_identifier(account_get_special_folder
7125 (compose->account, F_OUTBOX));
7126 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7127 g_free(folderidentifier);
7131 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7132 GtkTreeViewColumn *column, Compose *compose)
7134 compose_attach_property(compose);
7137 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7140 Compose *compose = (Compose *)data;
7141 GtkTreeSelection *attach_selection;
7142 gint attach_nr_selected;
7143 GtkItemFactory *ifactory;
7145 if (!event) return FALSE;
7147 if (event->button == 3) {
7148 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7149 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7150 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7152 if (attach_nr_selected > 0)
7154 menu_set_sensitive(ifactory, "/Remove", TRUE);
7155 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7157 menu_set_sensitive(ifactory, "/Remove", FALSE);
7158 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7161 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7162 NULL, NULL, event->button, event->time);
7169 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7172 Compose *compose = (Compose *)data;
7174 if (!event) return FALSE;
7176 switch (event->keyval) {
7178 compose_attach_remove_selected(compose);
7184 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7186 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7187 toolbar_comp_set_sensitive(compose, allow);
7188 menu_set_sensitive(ifactory, "/Message", allow);
7189 menu_set_sensitive(ifactory, "/Edit", allow);
7191 menu_set_sensitive(ifactory, "/Spelling", allow);
7193 menu_set_sensitive(ifactory, "/Options", allow);
7194 menu_set_sensitive(ifactory, "/Tools", allow);
7195 menu_set_sensitive(ifactory, "/Help", allow);
7197 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7201 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7203 Compose *compose = (Compose *)data;
7205 if (prefs_common.work_offline &&
7206 !inc_offline_should_override(
7207 _("Sylpheed-Claws needs network access in order "
7208 "to send this email.")))
7211 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7212 gtk_timeout_remove(compose->draft_timeout_tag);
7213 compose->draft_timeout_tag = -1;
7216 compose_send(compose);
7219 static void compose_send_later_cb(gpointer data, guint action,
7222 Compose *compose = (Compose *)data;
7225 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE);
7227 compose_close(compose);
7228 else if (val == -2) {
7229 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7230 } else if (val == -3) {
7231 alertpanel_error(_("Could not queue message for sending:\n\n"
7232 "Signature failed."));
7233 } else if (val == -4) {
7234 alertpanel_error(_("Could not queue message for sending:\n\n"
7235 "Charset conversion failed."));
7239 void compose_draft (gpointer data)
7241 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7244 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7246 Compose *compose = (Compose *)data;
7250 MsgFlags flag = {0, 0};
7251 static gboolean lock = FALSE;
7252 MsgInfo *newmsginfo;
7254 gboolean target_locked = FALSE;
7258 draft = account_get_special_folder(compose->account, F_DRAFT);
7259 g_return_if_fail(draft != NULL);
7261 if (!g_mutex_trylock(compose->mutex)) {
7262 /* we don't want to lock the mutex once it's available,
7263 * because as the only other part of compose.c locking
7264 * it is compose_close - which means once unlocked,
7265 * the compose struct will be freed */
7266 debug_print("couldn't lock mutex, probably sending\n");
7272 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7273 G_DIR_SEPARATOR, compose);
7274 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7275 FILE_OP_ERROR(tmp, "fopen");
7279 /* chmod for security */
7280 if (change_file_mode_rw(fp, tmp) < 0) {
7281 FILE_OP_ERROR(tmp, "chmod");
7282 g_warning("can't change file mode\n");
7285 /* Save draft infos */
7286 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7287 fprintf(fp, "S:%s\n", compose->account->address);
7288 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7289 gchar *savefolderid;
7291 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7292 fprintf(fp, "SCF:%s\n", savefolderid);
7293 g_free(savefolderid);
7295 if (compose->return_receipt) {
7296 fprintf(fp, "RRCPT:1\n");
7298 if (compose->privacy_system) {
7299 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7300 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7301 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7305 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7313 if (compose->targetinfo) {
7314 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7315 flag.perm_flags = target_locked?MSG_LOCKED:0;
7317 flag.tmp_flags = MSG_DRAFT;
7319 folder_item_scan(draft);
7320 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7323 if (action != COMPOSE_AUTO_SAVE)
7324 alertpanel_error(_("Could not save draft."));
7328 draft->mtime = 0; /* force updating */
7330 if (compose->mode == COMPOSE_REEDIT) {
7331 compose_remove_reedit_target(compose, TRUE);
7334 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7336 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7338 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7340 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7341 if (compose_use_attach(compose))
7342 procmsg_msginfo_set_flags(newmsginfo, 0,
7343 MSG_HAS_ATTACHMENT);
7345 procmsg_msginfo_free(newmsginfo);
7348 folder_item_scan(draft);
7350 if (action == COMPOSE_QUIT_EDITING) {
7352 g_mutex_unlock(compose->mutex); /* must be done before closing */
7353 compose_close(compose);
7359 path = folder_item_fetch_msg(draft, msgnum);
7361 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7364 if (g_stat(path, &s) < 0) {
7365 FILE_OP_ERROR(path, "stat");
7371 procmsg_msginfo_free(compose->targetinfo);
7372 compose->targetinfo = procmsg_msginfo_new();
7373 compose->targetinfo->msgnum = msgnum;
7374 compose->targetinfo->size = s.st_size;
7375 compose->targetinfo->mtime = s.st_mtime;
7376 compose->targetinfo->folder = draft;
7378 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7379 compose->mode = COMPOSE_REEDIT;
7381 if (action == COMPOSE_AUTO_SAVE) {
7382 compose->autosaved_draft = compose->targetinfo;
7384 compose->modified = FALSE;
7385 compose_set_title(compose);
7389 g_mutex_unlock(compose->mutex);
7392 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7394 Compose *compose = (Compose *)data;
7397 if (compose->redirect_filename != NULL)
7400 file_list = filesel_select_multiple_files_open(_("Select file"));
7405 for ( tmp = file_list; tmp; tmp = tmp->next) {
7406 gchar *file = (gchar *) tmp->data;
7407 gchar *utf8_filename = conv_filename_to_utf8(file);
7408 compose_attach_append(compose, file, utf8_filename, NULL);
7409 compose_changed_cb(NULL, compose);
7411 g_free(utf8_filename);
7413 g_list_free(file_list);
7417 static void compose_insert_file_cb(gpointer data, guint action,
7420 Compose *compose = (Compose *)data;
7423 file_list = filesel_select_multiple_files_open(_("Select file"));
7428 for ( tmp = file_list; tmp; tmp = tmp->next) {
7429 gchar *file = (gchar *) tmp->data;
7430 gchar *filedup = g_strdup(file);
7431 gchar *shortfile = g_path_get_basename(filedup);
7432 ComposeInsertResult res;
7434 res = compose_insert_file(compose, file);
7435 if (res == COMPOSE_INSERT_READ_ERROR) {
7436 alertpanel_error(_("File '%s' could not be read."), shortfile);
7437 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7438 alertpanel_error(_("File '%s' contained invalid characters\n"
7439 "for the current encoding, insertion may be incorrect."), shortfile);
7445 g_list_free(file_list);
7449 static void compose_insert_sig_cb(gpointer data, guint action,
7452 Compose *compose = (Compose *)data;
7454 compose_insert_sig(compose, FALSE);
7457 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7461 Compose *compose = (Compose *)data;
7463 gtkut_widget_get_uposition(widget, &x, &y);
7464 prefs_common.compose_x = x;
7465 prefs_common.compose_y = y;
7467 if (compose->sending)
7469 compose_close_cb(compose, 0, NULL);
7473 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7475 Compose *compose = (Compose *)data;
7479 if (compose->exteditor_tag != -1) {
7480 if (!compose_ext_editor_kill(compose))
7485 if (compose->modified) {
7486 val = alertpanel(_("Discard message"),
7487 _("This message has been modified. Discard it?"),
7488 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7491 case G_ALERTDEFAULT:
7492 if (prefs_common.autosave)
7493 compose_remove_draft(compose);
7495 case G_ALERTALTERNATE:
7496 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7503 compose_close(compose);
7506 static void compose_set_encoding_cb(gpointer data, guint action,
7509 Compose *compose = (Compose *)data;
7511 if (GTK_CHECK_MENU_ITEM(widget)->active)
7512 compose->out_encoding = (CharSet)action;
7515 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7517 Compose *compose = (Compose *)data;
7519 addressbook_open(compose);
7522 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7524 Compose *compose = (Compose *)data;
7529 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7530 g_return_if_fail(tmpl != NULL);
7532 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7534 val = alertpanel(_("Apply template"), msg,
7535 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7538 if (val == G_ALERTDEFAULT)
7539 compose_template_apply(compose, tmpl, TRUE);
7540 else if (val == G_ALERTALTERNATE)
7541 compose_template_apply(compose, tmpl, FALSE);
7544 static void compose_ext_editor_cb(gpointer data, guint action,
7547 Compose *compose = (Compose *)data;
7549 compose_exec_ext_editor(compose);
7552 static void compose_undo_cb(Compose *compose)
7554 gboolean prev_autowrap = compose->autowrap;
7556 compose->autowrap = FALSE;
7557 undo_undo(compose->undostruct);
7558 compose->autowrap = prev_autowrap;
7561 static void compose_redo_cb(Compose *compose)
7563 gboolean prev_autowrap = compose->autowrap;
7565 compose->autowrap = FALSE;
7566 undo_redo(compose->undostruct);
7567 compose->autowrap = prev_autowrap;
7570 static void entry_cut_clipboard(GtkWidget *entry)
7572 if (GTK_IS_EDITABLE(entry))
7573 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7574 else if (GTK_IS_TEXT_VIEW(entry))
7575 gtk_text_buffer_cut_clipboard(
7576 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7577 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7581 static void entry_copy_clipboard(GtkWidget *entry)
7583 if (GTK_IS_EDITABLE(entry))
7584 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7585 else if (GTK_IS_TEXT_VIEW(entry))
7586 gtk_text_buffer_copy_clipboard(
7587 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7588 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7591 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7592 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
7594 if (GTK_IS_TEXT_VIEW(entry)) {
7595 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7596 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7597 GtkTextIter start_iter, end_iter;
7600 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7602 if (contents == NULL)
7605 /* we shouldn't delete the selection when middle-click-pasting, or we
7606 * can't mid-click-paste our own selection */
7607 if (clip != GDK_SELECTION_PRIMARY)
7608 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7610 if (insert_place == NULL) {
7611 /* if insert_place isn't specified, insert at the cursor.
7612 * used for Ctrl-V pasting */
7613 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7614 start = gtk_text_iter_get_offset(&start_iter);
7615 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7617 /* if insert_place is specified, paste here.
7618 * used for mid-click-pasting */
7619 start = gtk_text_iter_get_offset(insert_place);
7620 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
7624 /* paste unwrapped: mark the paste so it's not wrapped later */
7625 end = start + strlen(contents);
7626 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7627 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7628 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7629 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7630 /* rewrap paragraph now (after a mid-click-paste) */
7631 mark_start = gtk_text_buffer_get_insert(buffer);
7632 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7633 gtk_text_iter_backward_char(&start_iter);
7634 compose_beautify_paragraph(compose, &start_iter, TRUE);
7637 } else if (GTK_IS_EDITABLE(entry))
7638 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7642 static void entry_allsel(GtkWidget *entry)
7644 if (GTK_IS_EDITABLE(entry))
7645 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7646 else if (GTK_IS_TEXT_VIEW(entry)) {
7647 GtkTextIter startiter, enditer;
7648 GtkTextBuffer *textbuf;
7650 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7651 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7652 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7654 gtk_text_buffer_move_mark_by_name(textbuf,
7655 "selection_bound", &startiter);
7656 gtk_text_buffer_move_mark_by_name(textbuf,
7657 "insert", &enditer);
7661 static void compose_cut_cb(Compose *compose)
7663 if (compose->focused_editable &&
7664 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7665 entry_cut_clipboard(compose->focused_editable);
7668 static void compose_copy_cb(Compose *compose)
7670 if (compose->focused_editable &&
7671 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7672 entry_copy_clipboard(compose->focused_editable);
7675 static void compose_paste_cb(Compose *compose)
7678 GtkTextBuffer *buffer;
7680 if (compose->focused_editable &&
7681 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7682 entry_paste_clipboard(compose, compose->focused_editable,
7683 prefs_common.linewrap_pastes,
7684 GDK_SELECTION_CLIPBOARD, NULL);
7688 static void compose_paste_as_quote_cb(Compose *compose)
7690 gint wrap_quote = prefs_common.linewrap_quote;
7691 if (compose->focused_editable &&
7692 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7693 /* let text_insert() (called directly or at a later time
7694 * after the gtk_editable_paste_clipboard) know that
7695 * text is to be inserted as a quotation. implemented
7696 * by using a simple refcount... */
7697 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7698 G_OBJECT(compose->focused_editable),
7699 "paste_as_quotation"));
7700 g_object_set_data(G_OBJECT(compose->focused_editable),
7701 "paste_as_quotation",
7702 GINT_TO_POINTER(paste_as_quotation + 1));
7703 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7704 entry_paste_clipboard(compose, compose->focused_editable,
7705 prefs_common.linewrap_pastes,
7706 GDK_SELECTION_CLIPBOARD, NULL);
7707 prefs_common.linewrap_quote = wrap_quote;
7711 static void compose_paste_no_wrap_cb(Compose *compose)
7714 GtkTextBuffer *buffer;
7716 if (compose->focused_editable &&
7717 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7718 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7719 GDK_SELECTION_CLIPBOARD, NULL);
7723 static void compose_paste_wrap_cb(Compose *compose)
7726 GtkTextBuffer *buffer;
7728 if (compose->focused_editable &&
7729 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7730 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7731 GDK_SELECTION_CLIPBOARD, NULL);
7735 static void compose_allsel_cb(Compose *compose)
7737 if (compose->focused_editable &&
7738 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7739 entry_allsel(compose->focused_editable);
7742 static void textview_move_beginning_of_line (GtkTextView *text)
7744 GtkTextBuffer *buffer;
7748 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7750 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7751 mark = gtk_text_buffer_get_insert(buffer);
7752 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7753 gtk_text_iter_set_line_offset(&ins, 0);
7754 gtk_text_buffer_place_cursor(buffer, &ins);
7757 static void textview_move_forward_character (GtkTextView *text)
7759 GtkTextBuffer *buffer;
7763 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7765 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7766 mark = gtk_text_buffer_get_insert(buffer);
7767 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7768 if (gtk_text_iter_forward_cursor_position(&ins))
7769 gtk_text_buffer_place_cursor(buffer, &ins);
7772 static void textview_move_backward_character (GtkTextView *text)
7774 GtkTextBuffer *buffer;
7778 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7780 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7781 mark = gtk_text_buffer_get_insert(buffer);
7782 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7783 if (gtk_text_iter_backward_cursor_position(&ins))
7784 gtk_text_buffer_place_cursor(buffer, &ins);
7787 static void textview_move_forward_word (GtkTextView *text)
7789 GtkTextBuffer *buffer;
7794 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7796 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7797 mark = gtk_text_buffer_get_insert(buffer);
7798 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7799 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7800 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7801 gtk_text_iter_backward_word_start(&ins);
7802 gtk_text_buffer_place_cursor(buffer, &ins);
7806 static void textview_move_backward_word (GtkTextView *text)
7808 GtkTextBuffer *buffer;
7813 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7815 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7816 mark = gtk_text_buffer_get_insert(buffer);
7817 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7818 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7819 if (gtk_text_iter_backward_word_starts(&ins, 1))
7820 gtk_text_buffer_place_cursor(buffer, &ins);
7823 static void textview_move_end_of_line (GtkTextView *text)
7825 GtkTextBuffer *buffer;
7829 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7831 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7832 mark = gtk_text_buffer_get_insert(buffer);
7833 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7834 if (gtk_text_iter_forward_to_line_end(&ins))
7835 gtk_text_buffer_place_cursor(buffer, &ins);
7838 static void textview_move_next_line (GtkTextView *text)
7840 GtkTextBuffer *buffer;
7845 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7847 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7848 mark = gtk_text_buffer_get_insert(buffer);
7849 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7850 offset = gtk_text_iter_get_line_offset(&ins);
7851 if (gtk_text_iter_forward_line(&ins)) {
7852 gtk_text_iter_set_line_offset(&ins, offset);
7853 gtk_text_buffer_place_cursor(buffer, &ins);
7857 static void textview_move_previous_line (GtkTextView *text)
7859 GtkTextBuffer *buffer;
7864 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7866 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7867 mark = gtk_text_buffer_get_insert(buffer);
7868 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7869 offset = gtk_text_iter_get_line_offset(&ins);
7870 if (gtk_text_iter_backward_line(&ins)) {
7871 gtk_text_iter_set_line_offset(&ins, offset);
7872 gtk_text_buffer_place_cursor(buffer, &ins);
7876 static void textview_delete_forward_character (GtkTextView *text)
7878 GtkTextBuffer *buffer;
7880 GtkTextIter ins, end_iter;
7882 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7884 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7885 mark = gtk_text_buffer_get_insert(buffer);
7886 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7888 if (gtk_text_iter_forward_char(&end_iter)) {
7889 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7893 static void textview_delete_backward_character (GtkTextView *text)
7895 GtkTextBuffer *buffer;
7897 GtkTextIter ins, end_iter;
7899 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7901 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7902 mark = gtk_text_buffer_get_insert(buffer);
7903 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7905 if (gtk_text_iter_backward_char(&end_iter)) {
7906 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7910 static void textview_delete_forward_word (GtkTextView *text)
7912 GtkTextBuffer *buffer;
7914 GtkTextIter ins, end_iter;
7916 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7918 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7919 mark = gtk_text_buffer_get_insert(buffer);
7920 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7922 if (gtk_text_iter_forward_word_end(&end_iter)) {
7923 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7927 static void textview_delete_backward_word (GtkTextView *text)
7929 GtkTextBuffer *buffer;
7931 GtkTextIter ins, end_iter;
7933 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7935 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7936 mark = gtk_text_buffer_get_insert(buffer);
7937 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7939 if (gtk_text_iter_backward_word_start(&end_iter)) {
7940 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7944 static void textview_delete_line (GtkTextView *text)
7946 GtkTextBuffer *buffer;
7948 GtkTextIter ins, start_iter, end_iter;
7951 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7953 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7954 mark = gtk_text_buffer_get_insert(buffer);
7955 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7958 gtk_text_iter_set_line_offset(&start_iter, 0);
7961 if (gtk_text_iter_ends_line(&end_iter))
7962 found = gtk_text_iter_forward_char(&end_iter);
7964 found = gtk_text_iter_forward_to_line_end(&end_iter);
7967 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7970 static void textview_delete_to_line_end (GtkTextView *text)
7972 GtkTextBuffer *buffer;
7974 GtkTextIter ins, end_iter;
7977 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7979 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7980 mark = gtk_text_buffer_get_insert(buffer);
7981 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7983 if (gtk_text_iter_ends_line(&end_iter))
7984 found = gtk_text_iter_forward_char(&end_iter);
7986 found = gtk_text_iter_forward_to_line_end(&end_iter);
7988 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7991 static void compose_advanced_action_cb(Compose *compose,
7992 ComposeCallAdvancedAction action)
7994 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7996 void (*do_action) (GtkTextView *text);
7997 } action_table[] = {
7998 {textview_move_beginning_of_line},
7999 {textview_move_forward_character},
8000 {textview_move_backward_character},
8001 {textview_move_forward_word},
8002 {textview_move_backward_word},
8003 {textview_move_end_of_line},
8004 {textview_move_next_line},
8005 {textview_move_previous_line},
8006 {textview_delete_forward_character},
8007 {textview_delete_backward_character},
8008 {textview_delete_forward_word},
8009 {textview_delete_backward_word},
8010 {textview_delete_line},
8011 {NULL}, /* gtk_stext_delete_line_n */
8012 {textview_delete_to_line_end}
8015 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8017 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8018 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8019 if (action_table[action].do_action)
8020 action_table[action].do_action(text);
8022 g_warning("Not implemented yet.");
8026 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8030 if (GTK_IS_EDITABLE(widget)) {
8031 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8032 gtk_editable_set_position(GTK_EDITABLE(widget),
8035 if (widget->parent && widget->parent->parent
8036 && widget->parent->parent->parent) {
8037 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8038 gint y = widget->allocation.y;
8039 gint height = widget->allocation.height;
8040 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8041 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8043 if (y < (int)shown->value) {
8044 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8046 if (y + height > (int)shown->value + (int)shown->page_size) {
8047 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8048 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8049 y + height - (int)shown->page_size - 1);
8051 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8052 (int)shown->upper - (int)shown->page_size - 1);
8059 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8060 compose->focused_editable = widget;
8063 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8065 compose->modified = TRUE;
8066 compose_set_title(compose);
8069 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8071 Compose *compose = (Compose *)data;
8074 compose_wrap_all_full(compose, TRUE);
8076 compose_beautify_paragraph(compose, NULL, TRUE);
8079 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8081 Compose *compose = (Compose *)data;
8083 message_search_compose(compose);
8086 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8089 Compose *compose = (Compose *)data;
8090 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8091 if (compose->autowrap)
8092 compose_wrap_all_full(compose, TRUE);
8093 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8096 static void compose_toggle_sign_cb(gpointer data, guint action,
8099 Compose *compose = (Compose *)data;
8101 if (GTK_CHECK_MENU_ITEM(widget)->active)
8102 compose->use_signing = TRUE;
8104 compose->use_signing = FALSE;
8107 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8110 Compose *compose = (Compose *)data;
8112 if (GTK_CHECK_MENU_ITEM(widget)->active)
8113 compose->use_encryption = TRUE;
8115 compose->use_encryption = FALSE;
8118 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8120 g_free(compose->privacy_system);
8122 compose->privacy_system = g_strdup(account->default_privacy_system);
8123 compose_update_privacy_system_menu_item(compose, warn);
8126 static void compose_toggle_ruler_cb(gpointer data, guint action,
8129 Compose *compose = (Compose *)data;
8131 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8132 gtk_widget_show(compose->ruler_hbox);
8133 prefs_common.show_ruler = TRUE;
8135 gtk_widget_hide(compose->ruler_hbox);
8136 gtk_widget_queue_resize(compose->edit_vbox);
8137 prefs_common.show_ruler = FALSE;
8141 static void compose_attach_drag_received_cb (GtkWidget *widget,
8142 GdkDragContext *context,
8145 GtkSelectionData *data,
8150 Compose *compose = (Compose *)user_data;
8153 if (gdk_atom_name(data->type) &&
8154 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8155 && gtk_drag_get_source_widget(context) !=
8156 mainwindow_get_mainwindow()->summaryview->ctree) {
8157 list = uri_list_extract_filenames((const gchar *)data->data);
8158 for (tmp = list; tmp != NULL; tmp = tmp->next)
8159 compose_attach_append
8160 (compose, (const gchar *)tmp->data,
8161 (const gchar *)tmp->data, NULL);
8162 if (list) compose_changed_cb(NULL, compose);
8163 list_free_strings(list);
8165 } else if (gtk_drag_get_source_widget(context)
8166 == mainwindow_get_mainwindow()->summaryview->ctree) {
8167 /* comes from our summaryview */
8168 SummaryView * summaryview = NULL;
8169 GSList * list = NULL, *cur = NULL;
8171 if (mainwindow_get_mainwindow())
8172 summaryview = mainwindow_get_mainwindow()->summaryview;
8175 list = summary_get_selected_msg_list(summaryview);
8177 for (cur = list; cur; cur = cur->next) {
8178 MsgInfo *msginfo = (MsgInfo *)cur->data;
8181 file = procmsg_get_message_file_full(msginfo,
8184 compose_attach_append(compose, (const gchar *)file,
8185 (const gchar *)file, "message/rfc822");
8193 static gboolean compose_drag_drop(GtkWidget *widget,
8194 GdkDragContext *drag_context,
8196 guint time, gpointer user_data)
8198 /* not handling this signal makes compose_insert_drag_received_cb
8203 static void compose_insert_drag_received_cb (GtkWidget *widget,
8204 GdkDragContext *drag_context,
8207 GtkSelectionData *data,
8212 Compose *compose = (Compose *)user_data;
8215 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8217 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8218 list = uri_list_extract_filenames((const gchar *)data->data);
8219 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8220 compose_insert_file(compose, (const gchar *)tmp->data);
8222 list_free_strings(list);
8224 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8227 #if GTK_CHECK_VERSION(2, 8, 0)
8228 /* do nothing, handled by GTK */
8230 gchar *tmpfile = get_tmp_file();
8231 str_write_to_file((const gchar *)data->data, tmpfile);
8232 compose_insert_file(compose, tmpfile);
8235 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8239 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8242 static void compose_header_drag_received_cb (GtkWidget *widget,
8243 GdkDragContext *drag_context,
8246 GtkSelectionData *data,
8251 GtkEditable *entry = (GtkEditable *)user_data;
8252 gchar *email = (gchar *)data->data;
8254 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8257 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8258 gchar *decoded=g_new(gchar, strlen(email));
8261 email += strlen("mailto:");
8262 decode_uri(decoded, email); /* will fit */
8263 gtk_editable_delete_text(entry, 0, -1);
8264 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8265 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8269 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8272 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8275 Compose *compose = (Compose *)data;
8277 if (GTK_CHECK_MENU_ITEM(widget)->active)
8278 compose->return_receipt = TRUE;
8280 compose->return_receipt = FALSE;
8283 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8286 Compose *compose = (Compose *)data;
8288 if (GTK_CHECK_MENU_ITEM(widget)->active)
8289 compose->remove_references = TRUE;
8291 compose->remove_references = FALSE;
8294 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8296 ComposeHeaderEntry *headerentry)
8298 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8299 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8300 !(event->state & GDK_MODIFIER_MASK) &&
8301 (event->keyval == GDK_BackSpace) &&
8302 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8303 gtk_container_remove
8304 (GTK_CONTAINER(headerentry->compose->header_table),
8305 headerentry->combo);
8306 gtk_container_remove
8307 (GTK_CONTAINER(headerentry->compose->header_table),
8308 headerentry->entry);
8309 headerentry->compose->header_list =
8310 g_slist_remove(headerentry->compose->header_list,
8312 g_free(headerentry);
8313 } else if (event->keyval == GDK_Tab) {
8314 if (headerentry->compose->header_last == headerentry) {
8315 /* Override default next focus, and give it to subject_entry
8316 * instead of notebook tabs
8318 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8319 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8326 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8327 ComposeHeaderEntry *headerentry)
8329 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8330 headerentry->compose->header_list =
8331 g_slist_append(headerentry->compose->header_list,
8334 compose_create_header_entry(headerentry->compose);
8335 g_signal_handlers_disconnect_matched
8336 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8337 0, 0, NULL, NULL, headerentry);
8339 /* Automatically scroll down */
8340 compose_show_first_last_header(headerentry->compose, FALSE);
8346 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8348 GtkAdjustment *vadj;
8350 g_return_if_fail(compose);
8351 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8352 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8354 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8355 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8358 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8359 const gchar *text, gint len, Compose *compose)
8361 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8362 (G_OBJECT(compose->text), "paste_as_quotation"));
8365 g_return_if_fail(text != NULL);
8367 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8368 G_CALLBACK(text_inserted),
8370 if (paste_as_quotation) {
8377 new_text = g_strndup(text, len);
8378 if (prefs_common.quotemark && *prefs_common.quotemark)
8379 qmark = prefs_common.quotemark;
8383 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8384 gtk_text_buffer_place_cursor(buffer, iter);
8386 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8388 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8389 GINT_TO_POINTER(paste_as_quotation - 1));
8391 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8392 gtk_text_buffer_place_cursor(buffer, iter);
8394 if (strcmp(text, "\n") || automatic_break
8395 || gtk_text_iter_starts_line(iter))
8396 gtk_text_buffer_insert(buffer, iter, text, len);
8398 debug_print("insert nowrap \\n\n");
8399 gtk_text_buffer_insert_with_tags_by_name(buffer,
8400 iter, text, len, "no_join", NULL);
8404 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8406 compose_beautify_paragraph(compose, iter, FALSE);
8408 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8409 gtk_text_buffer_delete_mark(buffer, mark);
8411 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8412 G_CALLBACK(text_inserted),
8414 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8416 if (prefs_common.autosave &&
8417 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8418 compose->draft_timeout_tag = gtk_timeout_add
8419 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8421 static gint compose_defer_auto_save_draft(Compose *compose)
8423 compose->draft_timeout_tag = -1;
8424 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8429 static void compose_check_all(Compose *compose)
8431 if (compose->gtkaspell)
8432 gtkaspell_check_all(compose->gtkaspell);
8435 static void compose_highlight_all(Compose *compose)
8437 if (compose->gtkaspell)
8438 gtkaspell_highlight_all(compose->gtkaspell);
8441 static void compose_check_backwards(Compose *compose)
8443 if (compose->gtkaspell)
8444 gtkaspell_check_backwards(compose->gtkaspell);
8446 GtkItemFactory *ifactory;
8447 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8448 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8449 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8453 static void compose_check_forwards_go(Compose *compose)
8455 if (compose->gtkaspell)
8456 gtkaspell_check_forwards_go(compose->gtkaspell);
8458 GtkItemFactory *ifactory;
8459 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8460 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8461 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8467 *\brief Guess originating forward account from MsgInfo and several
8468 * "common preference" settings. Return NULL if no guess.
8470 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8472 PrefsAccount *account = NULL;
8474 g_return_val_if_fail(msginfo, NULL);
8475 g_return_val_if_fail(msginfo->folder, NULL);
8476 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8478 if (msginfo->folder->prefs->enable_default_account)
8479 account = account_find_from_id(msginfo->folder->prefs->default_account);
8482 account = msginfo->folder->folder->account;
8484 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8486 Xstrdup_a(to, msginfo->to, return NULL);
8487 extract_address(to);
8488 account = account_find_from_address(to);
8491 if (!account && prefs_common.forward_account_autosel) {
8493 if (!procheader_get_header_from_msginfo
8494 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8495 extract_address(cc);
8496 account = account_find_from_address(cc);
8503 static gboolean compose_close(Compose *compose)
8507 if (!g_mutex_trylock(compose->mutex)) {
8508 /* we have to wait for the (possibly deferred by auto-save)
8509 * drafting to be done, before destroying the compose under
8511 debug_print("waiting for drafting to finish...\n");
8512 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8515 g_return_val_if_fail(compose, FALSE);
8516 gtkut_widget_get_uposition(compose->window, &x, &y);
8517 prefs_common.compose_x = x;
8518 prefs_common.compose_y = y;
8519 g_mutex_unlock(compose->mutex);
8520 compose_destroy(compose);
8525 * Add entry field for each address in list.
8526 * \param compose E-Mail composition object.
8527 * \param listAddress List of (formatted) E-Mail addresses.
8529 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8534 addr = ( gchar * ) node->data;
8535 compose_entry_append( compose, addr, COMPOSE_TO );
8536 node = g_list_next( node );
8540 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8544 GSList *new_msglist = NULL;
8545 MsgInfo *tmp_msginfo = NULL;
8546 gboolean originally_enc = FALSE;
8547 Compose *compose = NULL;
8549 g_return_if_fail(msgview != NULL);
8551 g_return_if_fail(msginfo_list != NULL);
8553 if (g_slist_length(msginfo_list) == 1) {
8554 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8555 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8557 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8558 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8559 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8560 orig_msginfo, mimeinfo);
8561 if (tmp_msginfo != NULL) {
8562 new_msglist = g_slist_append(NULL, tmp_msginfo);
8563 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8564 originally_enc = TRUE;
8570 body = messageview_get_selection(msgview);
8573 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8574 procmsg_msginfo_free(tmp_msginfo);
8575 g_slist_free(new_msglist);
8577 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8579 if (originally_enc) {
8580 compose_force_encryption(compose, compose->account, FALSE);
8586 void compose_set_position(Compose *compose, gint pos)
8588 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8590 gtkut_text_view_set_position(text, pos);
8593 gboolean compose_search_string(Compose *compose,
8594 const gchar *str, gboolean case_sens)
8596 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8598 return gtkut_text_view_search_string(text, str, case_sens);
8601 gboolean compose_search_string_backward(Compose *compose,
8602 const gchar *str, gboolean case_sens)
8604 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8606 return gtkut_text_view_search_string_backward(text, str, case_sens);