2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
123 #include "combobox.h"
135 #define N_ATTACH_COLS (N_COL_COLUMNS)
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
154 } ComposeCallAdvancedAction;
158 PRIORITY_HIGHEST = 1,
167 COMPOSE_INSERT_SUCCESS,
168 COMPOSE_INSERT_READ_ERROR,
169 COMPOSE_INSERT_INVALID_CHARACTER,
170 COMPOSE_INSERT_NO_FILE
171 } ComposeInsertResult;
175 COMPOSE_QUIT_EDITING,
176 COMPOSE_KEEP_EDITING,
178 } ComposeDraftAction;
182 COMPOSE_WRITE_FOR_SEND,
183 COMPOSE_WRITE_FOR_STORE
186 #define B64_LINE_SIZE 57
187 #define B64_BUFFSIZE 77
189 #define MAX_REFERENCES_LEN 999
191 static GList *compose_list = NULL;
193 Compose *compose_generic_new (PrefsAccount *account,
196 GPtrArray *attach_files,
197 GList *listAddress );
199 static Compose *compose_create (PrefsAccount *account,
203 static GtkWidget *compose_account_option_menu_create
205 static void compose_set_out_encoding (Compose *compose);
206 static void compose_set_template_menu (Compose *compose);
207 static void compose_template_apply (Compose *compose,
210 static void compose_destroy (Compose *compose);
212 static void compose_entries_set (Compose *compose,
213 const gchar *mailto);
214 static gint compose_parse_header (Compose *compose,
216 static gchar *compose_parse_references (const gchar *ref,
219 static gchar *compose_quote_fmt (Compose *compose,
225 const gchar *err_msg);
227 static void compose_reply_set_entry (Compose *compose,
233 followup_and_reply_to);
234 static void compose_reedit_set_entry (Compose *compose,
237 static void compose_insert_sig (Compose *compose,
239 static gchar *compose_get_signature_str (Compose *compose);
240 static ComposeInsertResult compose_insert_file (Compose *compose,
243 static gboolean compose_attach_append (Compose *compose,
246 const gchar *content_type);
247 static void compose_attach_parts (Compose *compose,
250 static void compose_beautify_paragraph (Compose *compose,
251 GtkTextIter *par_iter,
253 static void compose_wrap_all (Compose *compose);
254 static void compose_wrap_all_full (Compose *compose,
257 static void compose_set_title (Compose *compose);
258 static void compose_select_account (Compose *compose,
259 PrefsAccount *account,
262 static PrefsAccount *compose_current_mail_account(void);
263 /* static gint compose_send (Compose *compose); */
264 static gboolean compose_check_for_valid_recipient
266 static gboolean compose_check_entries (Compose *compose,
267 gboolean check_subject);
268 static gint compose_write_to_file (Compose *compose,
271 gboolean attach_parts);
272 static gint compose_write_body_to_file (Compose *compose,
274 static gint compose_remove_reedit_target (Compose *compose,
276 void compose_remove_draft (Compose *compose);
277 static gint compose_queue_sub (Compose *compose,
281 gboolean check_subject,
282 gboolean remove_reedit_target);
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_remove_header_entries(Compose *compose);
330 static void compose_update_priority_menu_item(Compose * compose);
332 static void compose_spell_menu_changed (void *data);
334 static void compose_add_field_list ( Compose *compose,
335 GList *listAddress );
337 /* callback functions */
339 static gboolean compose_edit_size_alloc (GtkEditable *widget,
340 GtkAllocation *allocation,
341 GtkSHRuler *shruler);
342 static void account_activated (GtkComboBox *optmenu,
344 static void attach_selected (GtkTreeView *tree_view,
345 GtkTreePath *tree_path,
346 GtkTreeViewColumn *column,
348 static gboolean attach_button_pressed (GtkWidget *widget,
349 GdkEventButton *event,
351 static gboolean attach_key_pressed (GtkWidget *widget,
355 static void compose_send_cb (gpointer data,
358 static void compose_send_later_cb (gpointer data,
362 static void compose_draft_cb (gpointer data,
366 static void compose_attach_cb (gpointer data,
369 static void compose_insert_file_cb (gpointer data,
372 static void compose_insert_sig_cb (gpointer data,
376 static void compose_close_cb (gpointer data,
380 static void compose_set_encoding_cb (gpointer data,
384 static void compose_address_cb (gpointer data,
387 static void compose_template_activate_cb(GtkWidget *widget,
390 static void compose_ext_editor_cb (gpointer data,
394 static gint compose_delete_cb (GtkWidget *widget,
398 static void compose_undo_cb (Compose *compose);
399 static void compose_redo_cb (Compose *compose);
400 static void compose_cut_cb (Compose *compose);
401 static void compose_copy_cb (Compose *compose);
402 static void compose_paste_cb (Compose *compose);
403 static void compose_paste_as_quote_cb (Compose *compose);
404 static void compose_paste_no_wrap_cb (Compose *compose);
405 static void compose_paste_wrap_cb (Compose *compose);
406 static void compose_allsel_cb (Compose *compose);
408 static void compose_advanced_action_cb (Compose *compose,
409 ComposeCallAdvancedAction action);
411 static void compose_grab_focus_cb (GtkWidget *widget,
414 static void compose_changed_cb (GtkTextBuffer *textbuf,
417 static void compose_wrap_cb (gpointer data,
420 static void compose_find_cb (gpointer data,
423 static void compose_toggle_autowrap_cb (gpointer data,
427 static void compose_toggle_ruler_cb (gpointer data,
430 static void compose_toggle_sign_cb (gpointer data,
433 static void compose_toggle_encrypt_cb (gpointer data,
436 static void compose_set_privacy_system_cb(GtkWidget *widget,
438 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
439 static void activate_privacy_system (Compose *compose,
440 PrefsAccount *account,
442 static void compose_use_signing(Compose *compose, gboolean use_signing);
443 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
444 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
446 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
448 static void compose_set_priority_cb (gpointer data,
451 static void compose_reply_change_mode (gpointer data,
455 static void compose_attach_drag_received_cb (GtkWidget *widget,
456 GdkDragContext *drag_context,
459 GtkSelectionData *data,
463 static void compose_insert_drag_received_cb (GtkWidget *widget,
464 GdkDragContext *drag_context,
467 GtkSelectionData *data,
471 static void compose_header_drag_received_cb (GtkWidget *widget,
472 GdkDragContext *drag_context,
475 GtkSelectionData *data,
480 static gboolean compose_drag_drop (GtkWidget *widget,
481 GdkDragContext *drag_context,
483 guint time, gpointer user_data);
485 static void text_inserted (GtkTextBuffer *buffer,
490 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
491 gboolean to_all, gboolean to_ml,
493 gboolean followup_and_reply_to,
496 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
497 ComposeHeaderEntry *headerentry);
498 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
500 ComposeHeaderEntry *headerentry);
502 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
504 static void compose_allow_user_actions (Compose *compose, gboolean allow);
507 static void compose_check_all (Compose *compose);
508 static void compose_highlight_all (Compose *compose);
509 static void compose_check_backwards (Compose *compose);
510 static void compose_check_forwards_go (Compose *compose);
513 static gint compose_defer_auto_save_draft (Compose *compose);
514 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
516 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
518 static GtkItemFactoryEntry compose_popup_entries[] =
520 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
521 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
522 {N_("/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
526 static GtkItemFactoryEntry compose_entries[] =
528 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
529 {N_("/_Message/_Send"), "<control>Return",
530 compose_send_cb, 0, NULL},
531 {N_("/_Message/Send _later"), "<shift><control>S",
532 compose_send_later_cb, 0, NULL},
533 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
535 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
536 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
537 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
538 {N_("/_Message/_Save"),
539 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
540 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
541 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
543 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
544 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
545 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
546 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
547 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
548 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
549 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
550 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
551 {N_("/_Edit/Special paste/as _quotation"),
552 NULL, compose_paste_as_quote_cb, 0, NULL},
553 {N_("/_Edit/Special paste/_wrapped"),
554 NULL, compose_paste_wrap_cb, 0, NULL},
555 {N_("/_Edit/Special paste/_unwrapped"),
556 NULL, compose_paste_no_wrap_cb, 0, NULL},
557 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
558 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
559 {N_("/_Edit/A_dvanced/Move a character backward"),
561 compose_advanced_action_cb,
562 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
564 {N_("/_Edit/A_dvanced/Move a character forward"),
566 compose_advanced_action_cb,
567 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
569 {N_("/_Edit/A_dvanced/Move a word backward"),
571 compose_advanced_action_cb,
572 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
574 {N_("/_Edit/A_dvanced/Move a word forward"),
576 compose_advanced_action_cb,
577 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
579 {N_("/_Edit/A_dvanced/Move to beginning of line"),
580 NULL, /* "<control>A" */
581 compose_advanced_action_cb,
582 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
584 {N_("/_Edit/A_dvanced/Move to end of line"),
586 compose_advanced_action_cb,
587 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
589 {N_("/_Edit/A_dvanced/Move to previous line"),
591 compose_advanced_action_cb,
592 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
594 {N_("/_Edit/A_dvanced/Move to next line"),
596 compose_advanced_action_cb,
597 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
599 {N_("/_Edit/A_dvanced/Delete a character backward"),
601 compose_advanced_action_cb,
602 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
604 {N_("/_Edit/A_dvanced/Delete a character forward"),
606 compose_advanced_action_cb,
607 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
609 {N_("/_Edit/A_dvanced/Delete a word backward"),
610 NULL, /* "<control>W" */
611 compose_advanced_action_cb,
612 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
614 {N_("/_Edit/A_dvanced/Delete a word forward"),
615 NULL, /* "<alt>D", */
616 compose_advanced_action_cb,
617 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
619 {N_("/_Edit/A_dvanced/Delete line"),
621 compose_advanced_action_cb,
622 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
624 {N_("/_Edit/A_dvanced/Delete entire line"),
626 compose_advanced_action_cb,
627 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
629 {N_("/_Edit/A_dvanced/Delete to end of line"),
631 compose_advanced_action_cb,
632 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
634 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
636 "<control>F", compose_find_cb, 0, NULL},
637 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
638 {N_("/_Edit/_Wrap current paragraph"),
639 "<control>L", compose_wrap_cb, 0, NULL},
640 {N_("/_Edit/Wrap all long _lines"),
641 "<control><alt>L", compose_wrap_cb, 1, NULL},
642 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
643 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
644 {N_("/_Edit/Edit with e_xternal editor"),
645 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
647 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
648 {N_("/_Spelling/_Check all or check selection"),
649 NULL, compose_check_all, 0, NULL},
650 {N_("/_Spelling/_Highlight all misspelled words"),
651 NULL, compose_highlight_all, 0, NULL},
652 {N_("/_Spelling/Check _backwards misspelled word"),
653 NULL, compose_check_backwards , 0, NULL},
654 {N_("/_Spelling/_Forward to next misspelled word"),
655 NULL, compose_check_forwards_go, 0, NULL},
656 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
657 {N_("/_Spelling/Options"),
658 NULL, NULL, 0, "<Branch>"},
660 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
661 {N_("/_Options/Reply _mode"), NULL, NULL, 0, "<Branch>"},
662 {N_("/_Options/Reply _mode/_Normal"), NULL, compose_reply_change_mode, COMPOSE_REPLY, "<RadioItem>"},
663 {N_("/_Options/Reply _mode/_All"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_ALL, "/Options/Reply mode/Normal"},
664 {N_("/_Options/Reply _mode/_Sender"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_SENDER, "/Options/Reply mode/Normal"},
665 {N_("/_Options/Reply _mode/_Mailing-list"), NULL, compose_reply_change_mode, COMPOSE_REPLY_TO_LIST, "/Options/Reply mode/Normal"},
666 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
667 {N_("/_Options/Privacy _System"), NULL, NULL, 0, "<Branch>"},
668 {N_("/_Options/Privacy _System/None"), NULL, NULL, 0, "<RadioItem>"},
669 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
670 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
671 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
672 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
673 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
674 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
675 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
676 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
677 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
678 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
679 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
680 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
681 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
682 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
684 #define ENC_ACTION(action) \
685 NULL, compose_set_encoding_cb, action, \
686 "/Options/Character encoding/Automatic"
688 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
689 {N_("/_Options/Character _encoding/_Automatic"),
690 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
691 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
693 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
694 ENC_ACTION(C_US_ASCII)},
695 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
696 ENC_ACTION(C_UTF_8)},
697 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
699 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
700 ENC_ACTION(C_ISO_8859_1)},
701 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
702 ENC_ACTION(C_ISO_8859_15)},
703 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
704 ENC_ACTION(C_WINDOWS_1252)},
705 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
707 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
708 ENC_ACTION(C_ISO_8859_2)},
709 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
711 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
712 ENC_ACTION(C_ISO_8859_13)},
713 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
714 ENC_ACTION(C_ISO_8859_4)},
715 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
717 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
718 ENC_ACTION(C_ISO_8859_7)},
719 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
721 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
722 ENC_ACTION(C_ISO_8859_8)},
723 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
724 ENC_ACTION(C_WINDOWS_1255)},
725 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
727 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
728 ENC_ACTION(C_ISO_8859_6)},
729 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
730 ENC_ACTION(C_CP1256)},
731 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
733 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
734 ENC_ACTION(C_ISO_8859_9)},
735 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
737 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
738 ENC_ACTION(C_ISO_8859_5)},
739 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
740 ENC_ACTION(C_KOI8_R)},
741 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
742 ENC_ACTION(C_KOI8_U)},
743 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
744 ENC_ACTION(C_WINDOWS_1251)},
745 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
747 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
748 ENC_ACTION(C_ISO_2022_JP)},
749 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
751 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
752 ENC_ACTION(C_GB2312)},
753 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
755 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
757 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
758 ENC_ACTION(C_EUC_TW)},
759 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
761 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
762 ENC_ACTION(C_EUC_KR)},
763 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
765 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
766 ENC_ACTION(C_TIS_620)},
767 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
768 ENC_ACTION(C_WINDOWS_874)},
770 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
771 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
772 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
773 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
774 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
775 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
776 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
779 static GtkTargetEntry compose_mime_types[] =
781 {"text/uri-list", 0, 0},
782 {"UTF8_STRING", 0, 0},
786 static gboolean compose_put_existing_to_front(MsgInfo *info)
788 GList *compose_list = compose_get_compose_list();
792 for (elem = compose_list; elem != NULL && elem->data != NULL;
794 Compose *c = (Compose*)elem->data;
796 if (!c->targetinfo || !c->targetinfo->msgid ||
800 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
801 gtkut_window_popup(c->window);
809 static GdkColor quote_color1 =
810 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
811 static GdkColor quote_color2 =
812 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
813 static GdkColor quote_color3 =
814 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
816 static GdkColor quote_bgcolor1 =
817 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
818 static GdkColor quote_bgcolor2 =
819 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
820 static GdkColor quote_bgcolor3 =
821 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
823 static GdkColor signature_color = {
830 static GdkColor uri_color = {
837 static void compose_create_tags(GtkTextView *text, Compose *compose)
839 GtkTextBuffer *buffer;
840 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
846 buffer = gtk_text_view_get_buffer(text);
848 if (prefs_common.enable_color) {
849 /* grab the quote colors, converting from an int to a GdkColor */
850 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
852 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
854 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
856 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
858 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
860 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
862 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
864 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
867 signature_color = quote_color1 = quote_color2 = quote_color3 =
868 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
871 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
872 gtk_text_buffer_create_tag(buffer, "quote0",
873 "foreground-gdk", "e_color1,
874 "paragraph-background-gdk", "e_bgcolor1,
876 gtk_text_buffer_create_tag(buffer, "quote1",
877 "foreground-gdk", "e_color2,
878 "paragraph-background-gdk", "e_bgcolor2,
880 gtk_text_buffer_create_tag(buffer, "quote2",
881 "foreground-gdk", "e_color3,
882 "paragraph-background-gdk", "e_bgcolor3,
885 gtk_text_buffer_create_tag(buffer, "quote0",
886 "foreground-gdk", "e_color1,
888 gtk_text_buffer_create_tag(buffer, "quote1",
889 "foreground-gdk", "e_color2,
891 gtk_text_buffer_create_tag(buffer, "quote2",
892 "foreground-gdk", "e_color3,
896 gtk_text_buffer_create_tag(buffer, "signature",
897 "foreground-gdk", &signature_color,
899 gtk_text_buffer_create_tag(buffer, "link",
900 "foreground-gdk", &uri_color,
902 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
903 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
905 color[0] = quote_color1;
906 color[1] = quote_color2;
907 color[2] = quote_color3;
908 color[3] = quote_bgcolor1;
909 color[4] = quote_bgcolor2;
910 color[5] = quote_bgcolor3;
911 color[6] = signature_color;
912 color[7] = uri_color;
913 cmap = gdk_drawable_get_colormap(compose->window->window);
914 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
916 for (i = 0; i < 8; i++) {
917 if (success[i] == FALSE) {
920 g_warning("Compose: color allocation failed.\n");
921 style = gtk_widget_get_style(GTK_WIDGET(text));
922 quote_color1 = quote_color2 = quote_color3 =
923 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
924 signature_color = uri_color = black;
929 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
930 GPtrArray *attach_files)
932 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
935 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item, const gchar *mailto)
937 return compose_generic_new(account, mailto, item, NULL, NULL);
940 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
942 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
945 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
946 GPtrArray *attach_files, GList *listAddress )
949 GtkTextView *textview;
950 GtkTextBuffer *textbuf;
952 GtkItemFactory *ifactory;
954 if (item && item->prefs && item->prefs->enable_default_account)
955 account = account_find_from_id(item->prefs->default_account);
957 if (!account) account = cur_account;
958 g_return_val_if_fail(account != NULL, NULL);
960 compose = compose_create(account, COMPOSE_NEW, FALSE);
962 ifactory = gtk_item_factory_from_widget(compose->menubar);
964 compose->replyinfo = NULL;
965 compose->fwdinfo = NULL;
967 textview = GTK_TEXT_VIEW(compose->text);
968 textbuf = gtk_text_view_get_buffer(textview);
969 compose_create_tags(textview, compose);
971 undo_block(compose->undostruct);
973 if (item && item->prefs && item->prefs->enable_default_dictionary &&
975 gtkaspell_change_dict(compose->gtkaspell,
976 item->prefs->default_dictionary);
977 compose_spell_menu_changed(compose);
980 if (account->auto_sig)
981 compose_insert_sig(compose, FALSE);
982 gtk_text_buffer_get_start_iter(textbuf, &iter);
983 gtk_text_buffer_place_cursor(textbuf, &iter);
985 if (account->protocol != A_NNTP) {
986 if (mailto && *mailto != '\0') {
987 compose_entries_set(compose, mailto);
989 } else if (item && item->prefs->enable_default_to) {
990 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
991 compose_entry_mark_default_to(compose, item->prefs->default_to);
993 if (item && item->ret_rcpt) {
994 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
998 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
999 } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
1000 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
1003 * CLAWS: just don't allow return receipt request, even if the user
1004 * may want to send an email. simple but foolproof.
1006 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1008 compose_add_field_list( compose, listAddress );
1010 if (prefs_common.compose_with_format) {
1011 MsgInfo* dummyinfo = NULL;
1013 if ( prefs_common.compose_subject_format
1014 && *prefs_common.compose_subject_format != '\0' )
1016 gchar *subject = NULL;
1020 dummyinfo = compose_msginfo_new_from_compose(compose);
1022 /* decode \-escape sequences in the internal representation of the quote format */
1023 tmp = malloc(strlen(prefs_common.compose_subject_format)+1);
1024 pref_get_unescaped_pref(tmp, prefs_common.compose_subject_format);
1026 subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
1027 quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account);
1028 quote_fmt_scan_string(tmp);
1031 buf = quote_fmt_get_buffer();
1033 alertpanel_error(_("New message subject format error."));
1035 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
1036 quote_fmt_reset_vartable();
1042 if ( prefs_common.compose_body_format
1043 && *prefs_common.compose_body_format != '\0' )
1046 GtkTextBuffer *buffer;
1047 GtkTextIter start, end;
1050 if ( dummyinfo == NULL )
1051 dummyinfo = compose_msginfo_new_from_compose(compose);
1053 text = GTK_TEXT_VIEW(compose->text);
1054 buffer = gtk_text_view_get_buffer(text);
1055 gtk_text_buffer_get_start_iter(buffer, &start);
1056 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
1057 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
1059 compose_quote_fmt(compose, dummyinfo,
1060 prefs_common.compose_body_format,
1062 _("New message body format error."));
1063 quote_fmt_reset_vartable();
1068 procmsg_msginfo_free( dummyinfo );
1075 for (i = 0; i < attach_files->len; i++) {
1076 file = g_ptr_array_index(attach_files, i);
1077 compose_attach_append(compose, file, file, NULL);
1081 compose_show_first_last_header(compose, TRUE);
1083 /* Set save folder */
1084 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1085 gchar *folderidentifier;
1087 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1088 folderidentifier = folder_item_get_identifier(item);
1089 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1090 g_free(folderidentifier);
1093 gtk_widget_grab_focus(compose->header_last->entry);
1095 undo_unblock(compose->undostruct);
1097 if (prefs_common.auto_exteditor)
1098 compose_exec_ext_editor(compose);
1100 compose->modified = FALSE;
1101 compose_set_title(compose);
1105 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1106 gboolean override_pref)
1108 gchar *privacy = NULL;
1110 g_return_if_fail(compose != NULL);
1111 g_return_if_fail(account != NULL);
1113 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1116 if (account->default_privacy_system
1117 && strlen(account->default_privacy_system)) {
1118 privacy = account->default_privacy_system;
1120 GSList *privacy_avail = privacy_get_system_ids();
1121 if (privacy_avail && g_slist_length(privacy_avail)) {
1122 privacy = (gchar *)(privacy_avail->data);
1125 if (privacy != NULL) {
1126 compose->privacy_system = g_strdup(privacy);
1127 compose_update_privacy_system_menu_item(compose, FALSE);
1128 compose_use_encryption(compose, TRUE);
1132 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1134 gchar *privacy = NULL;
1136 if (account->default_privacy_system
1137 && strlen(account->default_privacy_system)) {
1138 privacy = account->default_privacy_system;
1140 GSList *privacy_avail = privacy_get_system_ids();
1141 if (privacy_avail && g_slist_length(privacy_avail)) {
1142 privacy = (gchar *)(privacy_avail->data);
1145 if (privacy != NULL) {
1146 compose->privacy_system = g_strdup(privacy);
1147 compose_update_privacy_system_menu_item(compose, FALSE);
1148 compose_use_signing(compose, TRUE);
1152 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1156 Compose *compose = NULL;
1157 GtkItemFactory *ifactory = NULL;
1159 g_return_val_if_fail(msginfo_list != NULL, NULL);
1161 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1162 g_return_val_if_fail(msginfo != NULL, NULL);
1164 list_len = g_slist_length(msginfo_list);
1168 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1169 FALSE, prefs_common.default_reply_list, FALSE, body);
1171 case COMPOSE_REPLY_WITH_QUOTE:
1172 compose = compose_reply(msginfo, TRUE,
1173 FALSE, prefs_common.default_reply_list, FALSE, body);
1175 case COMPOSE_REPLY_WITHOUT_QUOTE:
1176 compose = compose_reply(msginfo, FALSE,
1177 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1179 case COMPOSE_REPLY_TO_SENDER:
1180 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1181 FALSE, FALSE, TRUE, body);
1183 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1184 compose = compose_followup_and_reply_to(msginfo,
1185 prefs_common.reply_with_quote,
1186 FALSE, FALSE, body);
1188 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1189 compose = compose_reply(msginfo, TRUE,
1190 FALSE, FALSE, TRUE, body);
1192 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1193 compose = compose_reply(msginfo, FALSE,
1194 FALSE, FALSE, TRUE, NULL);
1196 case COMPOSE_REPLY_TO_ALL:
1197 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1198 TRUE, FALSE, FALSE, body);
1200 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1201 compose = compose_reply(msginfo, TRUE,
1202 TRUE, FALSE, FALSE, body);
1204 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1205 compose = compose_reply(msginfo, FALSE,
1206 TRUE, FALSE, FALSE, NULL);
1208 case COMPOSE_REPLY_TO_LIST:
1209 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1210 FALSE, TRUE, FALSE, body);
1212 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1213 compose = compose_reply(msginfo, TRUE,
1214 FALSE, TRUE, FALSE, body);
1216 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1217 compose = compose_reply(msginfo, FALSE,
1218 FALSE, TRUE, FALSE, NULL);
1220 case COMPOSE_FORWARD:
1221 if (prefs_common.forward_as_attachment) {
1222 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1225 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1229 case COMPOSE_FORWARD_INLINE:
1230 /* check if we reply to more than one Message */
1231 if (list_len == 1) {
1232 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1235 /* more messages FALL THROUGH */
1236 case COMPOSE_FORWARD_AS_ATTACH:
1237 compose = compose_forward_multiple(NULL, msginfo_list);
1239 case COMPOSE_REDIRECT:
1240 compose = compose_redirect(NULL, msginfo, FALSE);
1243 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1246 ifactory = gtk_item_factory_from_widget(compose->menubar);
1248 compose->rmode = mode;
1249 switch (compose->rmode) {
1251 case COMPOSE_REPLY_WITH_QUOTE:
1252 case COMPOSE_REPLY_WITHOUT_QUOTE:
1253 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1254 debug_print("reply mode Normal\n");
1255 menu_set_active(ifactory, "/Options/Reply mode/Normal", TRUE);
1256 compose_reply_change_mode(compose, COMPOSE_REPLY, NULL); /* force update */
1258 case COMPOSE_REPLY_TO_SENDER:
1259 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1260 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1261 debug_print("reply mode Sender\n");
1262 menu_set_active(ifactory, "/Options/Reply mode/Sender", TRUE);
1264 case COMPOSE_REPLY_TO_ALL:
1265 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1266 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1267 debug_print("reply mode All\n");
1268 menu_set_active(ifactory, "/Options/Reply mode/All", TRUE);
1270 case COMPOSE_REPLY_TO_LIST:
1271 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1272 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1273 debug_print("reply mode List\n");
1274 menu_set_active(ifactory, "/Options/Reply mode/Mailing-list", TRUE);
1282 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1283 gboolean to_ml, gboolean to_sender,
1286 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1287 to_sender, FALSE, body);
1290 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1295 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1296 to_sender, TRUE, body);
1299 static void compose_extract_original_charset(Compose *compose)
1301 MsgInfo *info = NULL;
1302 if (compose->replyinfo) {
1303 info = compose->replyinfo;
1304 } else if (compose->fwdinfo) {
1305 info = compose->fwdinfo;
1306 } else if (compose->targetinfo) {
1307 info = compose->targetinfo;
1310 MimeInfo *mimeinfo = procmime_scan_message(info);
1311 MimeInfo *partinfo = mimeinfo;
1312 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1313 partinfo = procmime_mimeinfo_next(partinfo);
1315 compose->orig_charset =
1316 g_strdup(procmime_mimeinfo_get_parameter(
1317 partinfo, "charset"));
1319 procmime_mimeinfo_free_all(mimeinfo);
1323 #define SIGNAL_BLOCK(buffer) { \
1324 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1325 G_CALLBACK(compose_changed_cb), \
1327 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1328 G_CALLBACK(text_inserted), \
1332 #define SIGNAL_UNBLOCK(buffer) { \
1333 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1334 G_CALLBACK(compose_changed_cb), \
1336 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1337 G_CALLBACK(text_inserted), \
1341 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1342 gboolean to_all, gboolean to_ml,
1344 gboolean followup_and_reply_to,
1347 GtkItemFactory *ifactory;
1349 PrefsAccount *account = NULL;
1350 PrefsAccount *reply_account;
1351 GtkTextView *textview;
1352 GtkTextBuffer *textbuf;
1354 g_return_val_if_fail(msginfo != NULL, NULL);
1355 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1357 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1359 g_return_val_if_fail(account != NULL, NULL);
1361 if (to_sender && account->protocol == A_NNTP &&
1362 !followup_and_reply_to) {
1364 account_find_from_address(account->address);
1366 reply_account = compose_current_mail_account();
1370 reply_account = account;
1372 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1374 compose->updating = TRUE;
1376 ifactory = gtk_item_factory_from_widget(compose->menubar);
1378 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1379 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1381 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1382 if (!compose->replyinfo)
1383 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1385 compose_extract_original_charset(compose);
1387 if (msginfo->folder && msginfo->folder->ret_rcpt)
1388 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1390 /* Set save folder */
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 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1402 textview = (GTK_TEXT_VIEW(compose->text));
1403 textbuf = gtk_text_view_get_buffer(textview);
1404 compose_create_tags(textview, compose);
1406 undo_block(compose->undostruct);
1408 if (msginfo->folder && msginfo->folder->prefs &&
1409 msginfo->folder->prefs &&
1410 msginfo->folder->prefs->enable_default_dictionary &&
1412 gtkaspell_change_dict(compose->gtkaspell,
1413 msginfo->folder->prefs->default_dictionary);
1419 if (prefs_common.quotemark && *prefs_common.quotemark)
1420 qmark = prefs_common.quotemark;
1424 compose_quote_fmt(compose, compose->replyinfo,
1425 prefs_common.quotefmt,
1427 _("Message reply format error."));
1428 quote_fmt_reset_vartable();
1430 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1431 compose_force_encryption(compose, account, FALSE);
1434 SIGNAL_BLOCK(textbuf);
1436 if (account->auto_sig)
1437 compose_insert_sig(compose, FALSE);
1439 compose_wrap_all(compose);
1441 SIGNAL_UNBLOCK(textbuf);
1443 gtk_widget_grab_focus(compose->text);
1445 undo_unblock(compose->undostruct);
1447 if (prefs_common.auto_exteditor)
1448 compose_exec_ext_editor(compose);
1450 compose->modified = FALSE;
1451 compose_set_title(compose);
1453 compose->updating = FALSE;
1455 if (compose->deferred_destroy) {
1456 compose_destroy(compose);
1463 #define INSERT_FW_HEADER(var, hdr) \
1464 if (msginfo->var && *msginfo->var) { \
1465 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1466 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1467 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1470 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1471 gboolean as_attach, const gchar *body,
1472 gboolean no_extedit,
1476 GtkTextView *textview;
1477 GtkTextBuffer *textbuf;
1480 g_return_val_if_fail(msginfo != NULL, NULL);
1481 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1484 !(account = compose_guess_forward_account_from_msginfo
1486 account = cur_account;
1488 compose = compose_create(account, COMPOSE_FORWARD, batch);
1490 compose->updating = TRUE;
1491 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1492 if (!compose->fwdinfo)
1493 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1495 compose_extract_original_charset(compose);
1497 if (msginfo->subject && *msginfo->subject) {
1498 gchar *buf, *buf2, *p;
1500 buf = p = g_strdup(msginfo->subject);
1501 p += subject_get_prefix_length(p);
1502 memmove(buf, p, strlen(p) + 1);
1504 buf2 = g_strdup_printf("Fw: %s", buf);
1505 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1511 textview = GTK_TEXT_VIEW(compose->text);
1512 textbuf = gtk_text_view_get_buffer(textview);
1513 compose_create_tags(textview, compose);
1515 undo_block(compose->undostruct);
1519 msgfile = procmsg_get_message_file_path(msginfo);
1520 if (!is_file_exist(msgfile))
1521 g_warning("%s: file not exist\n", msgfile);
1523 compose_attach_append(compose, msgfile, msgfile,
1529 MsgInfo *full_msginfo;
1531 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1533 full_msginfo = procmsg_msginfo_copy(msginfo);
1535 if (prefs_common.fw_quotemark &&
1536 *prefs_common.fw_quotemark)
1537 qmark = prefs_common.fw_quotemark;
1541 compose_quote_fmt(compose, full_msginfo,
1542 prefs_common.fw_quotefmt,
1544 _("Message forward format error."));
1545 quote_fmt_reset_vartable();
1546 compose_attach_parts(compose, msginfo);
1548 procmsg_msginfo_free(full_msginfo);
1551 SIGNAL_BLOCK(textbuf);
1553 if (account->auto_sig)
1554 compose_insert_sig(compose, FALSE);
1556 compose_wrap_all(compose);
1558 SIGNAL_UNBLOCK(textbuf);
1560 gtk_text_buffer_get_start_iter(textbuf, &iter);
1561 gtk_text_buffer_place_cursor(textbuf, &iter);
1563 gtk_widget_grab_focus(compose->header_last->entry);
1565 if (!no_extedit && prefs_common.auto_exteditor)
1566 compose_exec_ext_editor(compose);
1569 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1570 gchar *folderidentifier;
1572 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1573 folderidentifier = folder_item_get_identifier(msginfo->folder);
1574 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1575 g_free(folderidentifier);
1578 undo_unblock(compose->undostruct);
1580 compose->modified = FALSE;
1581 compose_set_title(compose);
1583 compose->updating = FALSE;
1585 if (compose->deferred_destroy) {
1586 compose_destroy(compose);
1593 #undef INSERT_FW_HEADER
1595 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1598 GtkTextView *textview;
1599 GtkTextBuffer *textbuf;
1603 gboolean single_mail = TRUE;
1605 g_return_val_if_fail(msginfo_list != NULL, NULL);
1607 if (g_slist_length(msginfo_list) > 1)
1608 single_mail = FALSE;
1610 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1611 if (((MsgInfo *)msginfo->data)->folder == NULL)
1614 /* guess account from first selected message */
1616 !(account = compose_guess_forward_account_from_msginfo
1617 (msginfo_list->data)))
1618 account = cur_account;
1620 g_return_val_if_fail(account != NULL, NULL);
1622 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1623 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1624 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1627 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1629 compose->updating = TRUE;
1631 textview = GTK_TEXT_VIEW(compose->text);
1632 textbuf = gtk_text_view_get_buffer(textview);
1633 compose_create_tags(textview, compose);
1635 undo_block(compose->undostruct);
1636 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1637 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1639 if (!is_file_exist(msgfile))
1640 g_warning("%s: file not exist\n", msgfile);
1642 compose_attach_append(compose, msgfile, msgfile,
1648 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1649 if (info->subject && *info->subject) {
1650 gchar *buf, *buf2, *p;
1652 buf = p = g_strdup(info->subject);
1653 p += subject_get_prefix_length(p);
1654 memmove(buf, p, strlen(p) + 1);
1656 buf2 = g_strdup_printf("Fw: %s", buf);
1657 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1663 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1664 _("Fw: multiple emails"));
1667 SIGNAL_BLOCK(textbuf);
1669 if (account->auto_sig)
1670 compose_insert_sig(compose, FALSE);
1672 compose_wrap_all(compose);
1674 SIGNAL_UNBLOCK(textbuf);
1676 gtk_text_buffer_get_start_iter(textbuf, &iter);
1677 gtk_text_buffer_place_cursor(textbuf, &iter);
1679 gtk_widget_grab_focus(compose->header_last->entry);
1680 undo_unblock(compose->undostruct);
1681 compose->modified = FALSE;
1682 compose_set_title(compose);
1684 compose->updating = FALSE;
1686 if (compose->deferred_destroy) {
1687 compose_destroy(compose);
1694 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1696 GtkTextIter start = *iter;
1697 GtkTextIter end_iter;
1698 int start_pos = gtk_text_iter_get_offset(&start);
1700 if (!compose->account->sig_sep)
1703 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1704 start_pos+strlen(compose->account->sig_sep));
1706 /* check sig separator */
1707 str = gtk_text_iter_get_text(&start, &end_iter);
1708 if (!strcmp(str, compose->account->sig_sep)) {
1710 /* check end of line (\n) */
1711 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1712 start_pos+strlen(compose->account->sig_sep));
1713 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1714 start_pos+strlen(compose->account->sig_sep)+1);
1715 tmp = gtk_text_iter_get_text(&start, &end_iter);
1716 if (!strcmp(tmp,"\n")) {
1728 static void compose_colorize_signature(Compose *compose)
1730 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1732 GtkTextIter end_iter;
1733 gtk_text_buffer_get_start_iter(buffer, &iter);
1734 while (gtk_text_iter_forward_line(&iter))
1735 if (compose_is_sig_separator(compose, buffer, &iter)) {
1736 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1737 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1741 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1743 Compose *compose = NULL;
1744 PrefsAccount *account = NULL;
1745 GtkTextView *textview;
1746 GtkTextBuffer *textbuf;
1750 gchar buf[BUFFSIZE];
1751 gboolean use_signing = FALSE;
1752 gboolean use_encryption = FALSE;
1753 gchar *privacy_system = NULL;
1754 int priority = PRIORITY_NORMAL;
1755 MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
1757 g_return_val_if_fail(msginfo != NULL, NULL);
1758 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1760 if (compose_put_existing_to_front(msginfo)) {
1764 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1765 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1766 gchar queueheader_buf[BUFFSIZE];
1769 /* Select Account from queue headers */
1770 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1771 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1772 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1773 account = account_find_from_id(id);
1775 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1776 sizeof(queueheader_buf), "NAID:")) {
1777 id = atoi(&queueheader_buf[strlen("NAID:")]);
1778 account = account_find_from_id(id);
1780 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1781 sizeof(queueheader_buf), "MAID:")) {
1782 id = atoi(&queueheader_buf[strlen("MAID:")]);
1783 account = account_find_from_id(id);
1785 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1786 sizeof(queueheader_buf), "S:")) {
1787 account = account_find_from_address(queueheader_buf);
1789 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1790 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1791 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1792 use_signing = param;
1795 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1796 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1797 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1798 use_encryption = param;
1800 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1801 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1802 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1804 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1805 sizeof(queueheader_buf), "X-Priority: ")) {
1806 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1809 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1810 sizeof(queueheader_buf), "RMID:")) {
1811 gchar **tokens = g_strsplit(&queueheader_buf[strlen("RMID:")], "\t", 0);
1812 if (tokens[0] && tokens[1] && tokens[2]) {
1813 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1814 if (orig_item != NULL) {
1815 replyinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1820 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1821 sizeof(queueheader_buf), "FMID:")) {
1822 gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0);
1823 if (tokens[0] && tokens[1] && tokens[2]) {
1824 FolderItem *orig_item = folder_find_item_from_identifier(tokens[0]);
1825 if (orig_item != NULL) {
1826 fwdinfo = folder_item_get_msginfo_by_msgid(orig_item, tokens[2]);
1832 account = msginfo->folder->folder->account;
1835 if (!account && prefs_common.reedit_account_autosel) {
1836 gchar from[BUFFSIZE];
1837 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1838 extract_address(from);
1839 account = account_find_from_address(from);
1843 account = cur_account;
1845 g_return_val_if_fail(account != NULL, NULL);
1847 compose = compose_create(account, COMPOSE_REEDIT, batch);
1849 compose->replyinfo = replyinfo;
1850 compose->fwdinfo = fwdinfo;
1852 compose->updating = TRUE;
1853 compose->priority = priority;
1855 if (privacy_system != NULL) {
1856 compose->privacy_system = privacy_system;
1857 compose_use_signing(compose, use_signing);
1858 compose_use_encryption(compose, use_encryption);
1859 compose_update_privacy_system_menu_item(compose, FALSE);
1861 activate_privacy_system(compose, account, FALSE);
1864 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1866 compose_extract_original_charset(compose);
1868 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1869 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1870 gchar queueheader_buf[BUFFSIZE];
1872 /* Set message save folder */
1873 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1876 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1877 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1878 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1880 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1881 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1883 GtkItemFactory *ifactory;
1884 ifactory = gtk_item_factory_from_widget(compose->menubar);
1885 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1890 if (compose_parse_header(compose, msginfo) < 0) {
1891 compose->updating = FALSE;
1892 compose_destroy(compose);
1895 compose_reedit_set_entry(compose, msginfo);
1897 textview = GTK_TEXT_VIEW(compose->text);
1898 textbuf = gtk_text_view_get_buffer(textview);
1899 compose_create_tags(textview, compose);
1901 mark = gtk_text_buffer_get_insert(textbuf);
1902 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1904 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1905 G_CALLBACK(compose_changed_cb),
1908 if (procmime_msginfo_is_encrypted(msginfo)) {
1909 fp = procmime_get_first_encrypted_text_content(msginfo);
1911 compose_force_encryption(compose, account, TRUE);
1914 fp = procmime_get_first_text_content(msginfo);
1917 g_warning("Can't get text part\n");
1921 gboolean prev_autowrap = compose->autowrap;
1923 compose->autowrap = FALSE;
1924 while (fgets(buf, sizeof(buf), fp) != NULL) {
1926 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1928 compose_wrap_all_full(compose, FALSE);
1929 compose->autowrap = prev_autowrap;
1933 compose_attach_parts(compose, msginfo);
1935 compose_colorize_signature(compose);
1937 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1938 G_CALLBACK(compose_changed_cb),
1941 gtk_widget_grab_focus(compose->text);
1943 if (prefs_common.auto_exteditor) {
1944 compose_exec_ext_editor(compose);
1946 compose->modified = FALSE;
1947 compose_set_title(compose);
1949 compose->updating = FALSE;
1951 if (compose->deferred_destroy) {
1952 compose_destroy(compose);
1956 compose->sig_str = compose_get_signature_str(compose);
1961 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1966 GtkItemFactory *ifactory;
1969 g_return_val_if_fail(msginfo != NULL, NULL);
1972 account = account_get_reply_account(msginfo,
1973 prefs_common.reply_account_autosel);
1974 g_return_val_if_fail(account != NULL, NULL);
1976 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1978 compose->updating = TRUE;
1980 ifactory = gtk_item_factory_from_widget(compose->menubar);
1981 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1982 compose->replyinfo = NULL;
1983 compose->fwdinfo = NULL;
1985 compose_show_first_last_header(compose, TRUE);
1987 gtk_widget_grab_focus(compose->header_last->entry);
1989 filename = procmsg_get_message_file_path(msginfo);
1991 if (filename == NULL) {
1992 compose->updating = FALSE;
1993 compose_destroy(compose);
1998 compose->redirect_filename = filename;
2000 /* Set save folder */
2001 item = msginfo->folder;
2002 if (item && item->prefs && item->prefs->save_copy_to_folder) {
2003 gchar *folderidentifier;
2005 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
2006 folderidentifier = folder_item_get_identifier(item);
2007 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
2008 g_free(folderidentifier);
2011 compose_attach_parts(compose, msginfo);
2013 if (msginfo->subject)
2014 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
2016 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
2018 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE,
2019 _("Message redirect format error."));
2020 quote_fmt_reset_vartable();
2021 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
2023 compose_colorize_signature(compose);
2025 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
2026 menu_set_sensitive(ifactory, "/Add...", FALSE);
2027 menu_set_sensitive(ifactory, "/Remove", FALSE);
2028 menu_set_sensitive(ifactory, "/Properties...", FALSE);
2030 ifactory = gtk_item_factory_from_widget(compose->menubar);
2031 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
2032 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
2033 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
2034 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
2035 menu_set_sensitive(ifactory, "/Edit", FALSE);
2036 menu_set_sensitive(ifactory, "/Options", FALSE);
2037 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
2038 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
2040 if (compose->toolbar->draft_btn)
2041 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
2042 if (compose->toolbar->insert_btn)
2043 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
2044 if (compose->toolbar->attach_btn)
2045 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
2046 if (compose->toolbar->sig_btn)
2047 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
2048 if (compose->toolbar->exteditor_btn)
2049 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
2050 if (compose->toolbar->linewrap_current_btn)
2051 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
2052 if (compose->toolbar->linewrap_all_btn)
2053 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
2055 compose->modified = FALSE;
2056 compose_set_title(compose);
2057 compose->updating = FALSE;
2059 if (compose->deferred_destroy) {
2060 compose_destroy(compose);
2067 GList *compose_get_compose_list(void)
2069 return compose_list;
2072 void compose_entry_append(Compose *compose, const gchar *address,
2073 ComposeEntryType type)
2077 gboolean in_quote = FALSE;
2078 if (!address || *address == '\0') return;
2085 header = N_("Bcc:");
2087 case COMPOSE_REPLYTO:
2088 header = N_("Reply-To:");
2090 case COMPOSE_NEWSGROUPS:
2091 header = N_("Newsgroups:");
2093 case COMPOSE_FOLLOWUPTO:
2094 header = N_( "Followup-To:");
2101 header = prefs_common.trans_hdr ? gettext(header) : header;
2103 cur = begin = (gchar *)address;
2105 /* we separate the line by commas, but not if we're inside a quoted
2107 while (*cur != '\0') {
2109 in_quote = !in_quote;
2110 if (*cur == ',' && !in_quote) {
2111 gchar *tmp = g_strdup(begin);
2113 tmp[cur-begin]='\0';
2116 while (*tmp == ' ' || *tmp == '\t')
2118 compose_add_header_entry(compose, header, tmp);
2125 gchar *tmp = g_strdup(begin);
2127 tmp[cur-begin]='\0';
2130 while (*tmp == ' ' || *tmp == '\t')
2132 compose_add_header_entry(compose, header, tmp);
2137 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
2139 static GdkColor yellow;
2140 static GdkColor black;
2141 static gboolean yellow_initialised = FALSE;
2145 if (!yellow_initialised) {
2146 gdk_color_parse("#f5f6be", &yellow);
2147 gdk_color_parse("#000000", &black);
2148 yellow_initialised = gdk_colormap_alloc_color(
2149 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2150 yellow_initialised &= gdk_colormap_alloc_color(
2151 gdk_colormap_get_system(), &black, FALSE, TRUE);
2154 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2155 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2156 if (gtk_entry_get_text(entry) &&
2157 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2158 if (yellow_initialised) {
2159 gtk_widget_modify_base(
2160 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2161 GTK_STATE_NORMAL, &yellow);
2162 gtk_widget_modify_text(
2163 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2164 GTK_STATE_NORMAL, &black);
2170 void compose_toolbar_cb(gint action, gpointer data)
2172 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2173 Compose *compose = (Compose*)toolbar_item->parent;
2175 g_return_if_fail(compose != NULL);
2179 compose_send_cb(compose, 0, NULL);
2182 compose_send_later_cb(compose, 0, NULL);
2185 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2188 compose_insert_file_cb(compose, 0, NULL);
2191 compose_attach_cb(compose, 0, NULL);
2194 compose_insert_sig(compose, FALSE);
2197 compose_ext_editor_cb(compose, 0, NULL);
2199 case A_LINEWRAP_CURRENT:
2200 compose_beautify_paragraph(compose, NULL, TRUE);
2202 case A_LINEWRAP_ALL:
2203 compose_wrap_all_full(compose, TRUE);
2206 compose_address_cb(compose, 0, NULL);
2209 case A_CHECK_SPELLING:
2210 compose_check_all(compose);
2218 static void compose_entries_set(Compose *compose, const gchar *mailto)
2222 gchar *subject = NULL;
2226 gchar *attach = NULL;
2228 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body, &attach);
2231 compose_entry_append(compose, to, COMPOSE_TO);
2233 compose_entry_append(compose, cc, COMPOSE_CC);
2235 if (!g_utf8_validate (subject, -1, NULL)) {
2236 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2237 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2240 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2244 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2245 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2248 gboolean prev_autowrap = compose->autowrap;
2250 compose->autowrap = FALSE;
2252 mark = gtk_text_buffer_get_insert(buffer);
2253 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2255 if (!g_utf8_validate (body, -1, NULL)) {
2256 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2257 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2260 gtk_text_buffer_insert(buffer, &iter, body, -1);
2262 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2264 compose->autowrap = prev_autowrap;
2265 if (compose->autowrap)
2266 compose_wrap_all(compose);
2270 gchar *utf8_filename = conv_filename_to_utf8(attach);
2271 if (utf8_filename) {
2272 if (compose_attach_append(compose, attach, utf8_filename, NULL)) {
2273 alertpanel_notice(_("The file '%s' has been attached."), attach);
2275 g_free(utf8_filename);
2277 alertpanel_error(_("Couldn't attach a file (charset conversion failed)."));
2287 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2289 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2290 {"Cc:", NULL, TRUE},
2291 {"References:", NULL, FALSE},
2292 {"Bcc:", NULL, TRUE},
2293 {"Newsgroups:", NULL, TRUE},
2294 {"Followup-To:", NULL, TRUE},
2295 {"List-Post:", NULL, FALSE},
2296 {"X-Priority:", NULL, FALSE},
2297 {NULL, NULL, FALSE}};
2313 g_return_val_if_fail(msginfo != NULL, -1);
2315 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2316 procheader_get_header_fields(fp, hentry);
2319 if (hentry[H_REPLY_TO].body != NULL) {
2320 if (hentry[H_REPLY_TO].body[0] != '\0') {
2322 conv_unmime_header(hentry[H_REPLY_TO].body,
2325 g_free(hentry[H_REPLY_TO].body);
2326 hentry[H_REPLY_TO].body = NULL;
2328 if (hentry[H_CC].body != NULL) {
2329 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2330 g_free(hentry[H_CC].body);
2331 hentry[H_CC].body = NULL;
2333 if (hentry[H_REFERENCES].body != NULL) {
2334 if (compose->mode == COMPOSE_REEDIT)
2335 compose->references = hentry[H_REFERENCES].body;
2337 compose->references = compose_parse_references
2338 (hentry[H_REFERENCES].body, msginfo->msgid);
2339 g_free(hentry[H_REFERENCES].body);
2341 hentry[H_REFERENCES].body = NULL;
2343 if (hentry[H_BCC].body != NULL) {
2344 if (compose->mode == COMPOSE_REEDIT)
2346 conv_unmime_header(hentry[H_BCC].body, NULL);
2347 g_free(hentry[H_BCC].body);
2348 hentry[H_BCC].body = NULL;
2350 if (hentry[H_NEWSGROUPS].body != NULL) {
2351 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2352 hentry[H_NEWSGROUPS].body = NULL;
2354 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2355 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2356 compose->followup_to =
2357 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2360 g_free(hentry[H_FOLLOWUP_TO].body);
2361 hentry[H_FOLLOWUP_TO].body = NULL;
2363 if (hentry[H_LIST_POST].body != NULL) {
2366 extract_address(hentry[H_LIST_POST].body);
2367 if (hentry[H_LIST_POST].body[0] != '\0') {
2368 scan_mailto_url(hentry[H_LIST_POST].body,
2369 &to, NULL, NULL, NULL, NULL, NULL);
2371 g_free(compose->ml_post);
2372 compose->ml_post = to;
2375 g_free(hentry[H_LIST_POST].body);
2376 hentry[H_LIST_POST].body = NULL;
2379 /* CLAWS - X-Priority */
2380 if (compose->mode == COMPOSE_REEDIT)
2381 if (hentry[H_X_PRIORITY].body != NULL) {
2384 priority = atoi(hentry[H_X_PRIORITY].body);
2385 g_free(hentry[H_X_PRIORITY].body);
2387 hentry[H_X_PRIORITY].body = NULL;
2389 if (priority < PRIORITY_HIGHEST ||
2390 priority > PRIORITY_LOWEST)
2391 priority = PRIORITY_NORMAL;
2393 compose->priority = priority;
2396 if (compose->mode == COMPOSE_REEDIT) {
2397 if (msginfo->inreplyto && *msginfo->inreplyto)
2398 compose->inreplyto = g_strdup(msginfo->inreplyto);
2402 if (msginfo->msgid && *msginfo->msgid)
2403 compose->inreplyto = g_strdup(msginfo->msgid);
2405 if (!compose->references) {
2406 if (msginfo->msgid && *msginfo->msgid) {
2407 if (msginfo->inreplyto && *msginfo->inreplyto)
2408 compose->references =
2409 g_strdup_printf("<%s>\n\t<%s>",
2413 compose->references =
2414 g_strconcat("<", msginfo->msgid, ">",
2416 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2417 compose->references =
2418 g_strconcat("<", msginfo->inreplyto, ">",
2426 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2428 GSList *ref_id_list, *cur;
2432 ref_id_list = references_list_append(NULL, ref);
2433 if (!ref_id_list) return NULL;
2434 if (msgid && *msgid)
2435 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2440 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2441 /* "<" + Message-ID + ">" + CR+LF+TAB */
2442 len += strlen((gchar *)cur->data) + 5;
2444 if (len > MAX_REFERENCES_LEN) {
2445 /* remove second message-ID */
2446 if (ref_id_list && ref_id_list->next &&
2447 ref_id_list->next->next) {
2448 g_free(ref_id_list->next->data);
2449 ref_id_list = g_slist_remove
2450 (ref_id_list, ref_id_list->next->data);
2452 slist_free_strings(ref_id_list);
2453 g_slist_free(ref_id_list);
2460 new_ref = g_string_new("");
2461 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2462 if (new_ref->len > 0)
2463 g_string_append(new_ref, "\n\t");
2464 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2467 slist_free_strings(ref_id_list);
2468 g_slist_free(ref_id_list);
2470 new_ref_str = new_ref->str;
2471 g_string_free(new_ref, FALSE);
2476 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2477 const gchar *fmt, const gchar *qmark,
2478 const gchar *body, gboolean rewrap,
2479 const gchar *err_msg)
2481 MsgInfo* dummyinfo = NULL;
2482 gchar *quote_str = NULL;
2484 gboolean prev_autowrap;
2485 const gchar *trimmed_body = body;
2486 gint cursor_pos = -1;
2487 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2488 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2493 SIGNAL_BLOCK(buffer);
2496 dummyinfo = compose_msginfo_new_from_compose(compose);
2497 msginfo = dummyinfo;
2500 if (qmark != NULL) {
2501 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
2502 quote_fmt_scan_string(qmark);
2505 buf = quote_fmt_get_buffer();
2507 alertpanel_error(_("Quote mark format error."));
2509 Xstrdup_a(quote_str, buf, goto error)
2512 if (fmt && *fmt != '\0') {
2516 while (*trimmed_body == '\n')
2519 /* decode \-escape sequences in the internal representation of the quote format */
2520 tmp = malloc(strlen(fmt)+1);
2521 pref_get_unescaped_pref(tmp, fmt);
2523 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account);
2524 quote_fmt_scan_string(tmp);
2528 buf = quote_fmt_get_buffer();
2530 alertpanel_error(err_msg);
2536 prev_autowrap = compose->autowrap;
2537 compose->autowrap = FALSE;
2539 mark = gtk_text_buffer_get_insert(buffer);
2540 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2541 if (g_utf8_validate(buf, -1, NULL)) {
2542 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2544 gchar *tmpout = NULL;
2545 tmpout = conv_codeset_strdup
2546 (buf, conv_get_locale_charset_str_no_utf8(),
2548 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2550 tmpout = g_malloc(strlen(buf)*2+1);
2551 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2553 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2557 cursor_pos = quote_fmt_get_cursor_pos();
2558 compose->set_cursor_pos = cursor_pos;
2559 if (cursor_pos == -1) {
2562 gtk_text_buffer_get_start_iter(buffer, &iter);
2563 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2564 gtk_text_buffer_place_cursor(buffer, &iter);
2566 compose->autowrap = prev_autowrap;
2567 if (compose->autowrap && rewrap)
2568 compose_wrap_all(compose);
2575 SIGNAL_UNBLOCK(buffer);
2577 procmsg_msginfo_free( dummyinfo );
2582 /* if ml_post is of type addr@host and from is of type
2583 * addr-anything@host, return TRUE
2585 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2587 gchar *left_ml = NULL;
2588 gchar *right_ml = NULL;
2589 gchar *left_from = NULL;
2590 gchar *right_from = NULL;
2591 gboolean result = FALSE;
2593 if (!ml_post || !from)
2596 left_ml = g_strdup(ml_post);
2597 if (strstr(left_ml, "@")) {
2598 right_ml = strstr(left_ml, "@")+1;
2599 *(strstr(left_ml, "@")) = '\0';
2602 left_from = g_strdup(from);
2603 if (strstr(left_from, "@")) {
2604 right_from = strstr(left_from, "@")+1;
2605 *(strstr(left_from, "@")) = '\0';
2608 if (left_ml && left_from && right_ml && right_from
2609 && !strncmp(left_from, left_ml, strlen(left_ml))
2610 && !strcmp(right_from, right_ml)) {
2619 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2621 gchar *my_addr1, *my_addr2;
2623 if (!addr1 || !addr2)
2626 Xstrdup_a(my_addr1, addr1, return FALSE);
2627 Xstrdup_a(my_addr2, addr2, return FALSE);
2629 extract_address(my_addr1);
2630 extract_address(my_addr2);
2632 return !strcasecmp(my_addr1, my_addr2);
2635 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2636 gboolean to_all, gboolean to_ml,
2638 gboolean followup_and_reply_to)
2640 GSList *cc_list = NULL;
2643 gchar *replyto = NULL;
2644 GHashTable *to_table;
2646 gboolean reply_to_ml = FALSE;
2647 gboolean default_reply_to = FALSE;
2649 g_return_if_fail(compose->account != NULL);
2650 g_return_if_fail(msginfo != NULL);
2652 reply_to_ml = to_ml && compose->ml_post;
2654 default_reply_to = msginfo->folder &&
2655 msginfo->folder->prefs->enable_default_reply_to;
2657 if (compose->account->protocol != A_NNTP) {
2658 if (reply_to_ml && !default_reply_to) {
2660 gboolean is_subscr = is_subscription(compose->ml_post,
2663 /* normal answer to ml post with a reply-to */
2664 compose_entry_append(compose,
2667 if (compose->replyto
2668 && !same_address(compose->ml_post, compose->replyto))
2669 compose_entry_append(compose,
2673 /* answer to subscription confirmation */
2674 if (compose->replyto)
2675 compose_entry_append(compose,
2678 else if (msginfo->from)
2679 compose_entry_append(compose,
2684 else if (!(to_all || to_sender) && default_reply_to) {
2685 compose_entry_append(compose,
2686 msginfo->folder->prefs->default_reply_to,
2688 compose_entry_mark_default_to(compose,
2689 msginfo->folder->prefs->default_reply_to);
2694 Xstrdup_a(tmp1, msginfo->from, return);
2695 extract_address(tmp1);
2696 if (to_all || to_sender ||
2697 !account_find_from_address(tmp1))
2698 compose_entry_append(compose,
2699 (compose->replyto && !to_sender)
2700 ? compose->replyto :
2701 msginfo->from ? msginfo->from : "",
2703 else if (!to_all && !to_sender) {
2704 /* reply to the last list of recipients */
2705 compose_entry_append(compose,
2706 msginfo->to ? msginfo->to : "",
2708 compose_entry_append(compose,
2709 msginfo->cc ? msginfo->cc : "",
2714 if (to_sender || (compose->followup_to &&
2715 !strncmp(compose->followup_to, "poster", 6)))
2716 compose_entry_append
2718 (compose->replyto ? compose->replyto :
2719 msginfo->from ? msginfo->from : ""),
2722 else if (followup_and_reply_to || to_all) {
2723 compose_entry_append
2725 (compose->replyto ? compose->replyto :
2726 msginfo->from ? msginfo->from : ""),
2729 compose_entry_append
2731 compose->followup_to ? compose->followup_to :
2732 compose->newsgroups ? compose->newsgroups : "",
2733 COMPOSE_NEWSGROUPS);
2736 compose_entry_append
2738 compose->followup_to ? compose->followup_to :
2739 compose->newsgroups ? compose->newsgroups : "",
2740 COMPOSE_NEWSGROUPS);
2743 if (msginfo->subject && *msginfo->subject) {
2747 buf = p = g_strdup(msginfo->subject);
2748 p += subject_get_prefix_length(p);
2749 memmove(buf, p, strlen(p) + 1);
2751 buf2 = g_strdup_printf("Re: %s", buf);
2752 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2757 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2759 if (to_ml && compose->ml_post) return;
2760 if (!to_all || compose->account->protocol == A_NNTP) return;
2762 if (compose->replyto) {
2763 Xstrdup_a(replyto, compose->replyto, return);
2764 extract_address(replyto);
2766 if (msginfo->from) {
2767 Xstrdup_a(from, msginfo->from, return);
2768 extract_address(from);
2771 if (replyto && from)
2772 cc_list = address_list_append_with_comments(cc_list, from);
2773 if (to_all && msginfo->folder &&
2774 msginfo->folder->prefs->enable_default_reply_to)
2775 cc_list = address_list_append_with_comments(cc_list,
2776 msginfo->folder->prefs->default_reply_to);
2777 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2778 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2780 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2782 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2783 if (compose->account)
2784 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2785 GINT_TO_POINTER(1));
2787 /* remove address on To: and that of current account */
2788 for (cur = cc_list; cur != NULL; ) {
2789 GSList *next = cur->next;
2792 addr = g_strdup(cur->data);
2793 extract_address(addr);
2795 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2796 cc_list = g_slist_remove(cc_list, cur->data);
2798 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2802 hash_free_strings(to_table);
2803 g_hash_table_destroy(to_table);
2806 for (cur = cc_list; cur != NULL; cur = cur->next)
2807 compose_entry_append(compose, (gchar *)cur->data,
2809 slist_free_strings(cc_list);
2810 g_slist_free(cc_list);
2815 #define SET_ENTRY(entry, str) \
2818 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2821 #define SET_ADDRESS(type, str) \
2824 compose_entry_append(compose, str, type); \
2827 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2829 g_return_if_fail(msginfo != NULL);
2831 SET_ENTRY(subject_entry, msginfo->subject);
2832 SET_ENTRY(from_name, msginfo->from);
2833 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2834 SET_ADDRESS(COMPOSE_CC, compose->cc);
2835 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2836 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2837 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2838 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2840 compose_update_priority_menu_item(compose);
2841 compose_update_privacy_system_menu_item(compose, FALSE);
2842 compose_show_first_last_header(compose, TRUE);
2848 static void compose_insert_sig(Compose *compose, gboolean replace)
2850 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2851 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2853 GtkTextIter iter, iter_end;
2855 gchar *search = NULL;
2856 gboolean prev_autowrap;
2857 gboolean found = FALSE, shift = FALSE;
2860 g_return_if_fail(compose->account != NULL);
2862 prev_autowrap = compose->autowrap;
2863 compose->autowrap = FALSE;
2865 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2866 G_CALLBACK(compose_changed_cb),
2869 mark = gtk_text_buffer_get_insert(buffer);
2870 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2871 cur_pos = gtk_text_iter_get_offset (&iter);
2873 gtk_text_buffer_get_end_iter(buffer, &iter);
2875 search = compose->sig_str;
2877 if (replace && search) {
2878 GtkTextIter first_iter, start_iter, end_iter;
2880 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2882 if (compose->sig_str[0] == '\0')
2885 found = gtk_text_iter_forward_search(&first_iter,
2887 GTK_TEXT_SEARCH_TEXT_ONLY,
2888 &start_iter, &end_iter,
2892 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2896 if (replace && !found && search && strlen(search) > 2
2897 && search[0] == '\n' && search[1] == '\n') {
2903 g_free(compose->sig_str);
2904 compose->sig_str = compose_get_signature_str(compose);
2905 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2906 compose->sig_str = g_strdup("");
2908 cur_pos = gtk_text_iter_get_offset(&iter);
2910 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2912 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2914 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2915 gtk_text_iter_forward_char(&iter);
2916 gtk_text_iter_forward_char(&iter);
2917 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2918 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2920 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2921 cur_pos = gtk_text_buffer_get_char_count (buffer);
2923 /* put the cursor where it should be
2924 * either where the quote_fmt says, either before the signature */
2925 if (compose->set_cursor_pos < 0)
2926 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2928 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2929 compose->set_cursor_pos);
2931 gtk_text_buffer_place_cursor(buffer, &iter);
2932 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2933 G_CALLBACK(compose_changed_cb),
2936 compose->autowrap = prev_autowrap;
2937 if (compose->autowrap)
2938 compose_wrap_all(compose);
2941 static gchar *compose_get_signature_str(Compose *compose)
2943 gchar *sig_body = NULL;
2944 gchar *sig_str = NULL;
2945 gchar *utf8_sig_str = NULL;
2947 g_return_val_if_fail(compose->account != NULL, NULL);
2949 if (!compose->account->sig_path)
2952 if (compose->account->sig_type == SIG_FILE) {
2953 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2954 g_warning("can't open signature file: %s\n",
2955 compose->account->sig_path);
2960 if (compose->account->sig_type == SIG_COMMAND)
2961 sig_body = get_command_output(compose->account->sig_path);
2965 tmp = file_read_to_str(compose->account->sig_path);
2968 sig_body = normalize_newlines(tmp);
2972 if (compose->account->sig_sep) {
2973 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2977 sig_str = g_strconcat("\n\n", sig_body, NULL);
2980 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2981 utf8_sig_str = sig_str;
2983 utf8_sig_str = conv_codeset_strdup
2984 (sig_str, conv_get_locale_charset_str_no_utf8(),
2990 return utf8_sig_str;
2993 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2996 GtkTextBuffer *buffer;
2999 const gchar *cur_encoding;
3000 gchar buf[BUFFSIZE];
3003 gboolean prev_autowrap;
3004 gboolean badtxt = FALSE;
3006 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
3008 if ((fp = g_fopen(file, "rb")) == NULL) {
3009 FILE_OP_ERROR(file, "fopen");
3010 return COMPOSE_INSERT_READ_ERROR;
3013 prev_autowrap = compose->autowrap;
3014 compose->autowrap = FALSE;
3016 text = GTK_TEXT_VIEW(compose->text);
3017 buffer = gtk_text_view_get_buffer(text);
3018 mark = gtk_text_buffer_get_insert(buffer);
3019 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3021 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3022 G_CALLBACK(text_inserted),
3025 cur_encoding = conv_get_locale_charset_str_no_utf8();
3027 while (fgets(buf, sizeof(buf), fp) != NULL) {
3030 if (g_utf8_validate(buf, -1, NULL) == TRUE)
3031 str = g_strdup(buf);
3033 str = conv_codeset_strdup
3034 (buf, cur_encoding, CS_INTERNAL);
3037 /* strip <CR> if DOS/Windows file,
3038 replace <CR> with <LF> if Macintosh file. */
3041 if (len > 0 && str[len - 1] != '\n') {
3043 if (str[len] == '\r') str[len] = '\n';
3046 gtk_text_buffer_insert(buffer, &iter, str, -1);
3050 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3051 G_CALLBACK(text_inserted),
3053 compose->autowrap = prev_autowrap;
3054 if (compose->autowrap)
3055 compose_wrap_all(compose);
3060 return COMPOSE_INSERT_INVALID_CHARACTER;
3062 return COMPOSE_INSERT_SUCCESS;
3065 static gboolean compose_attach_append(Compose *compose, const gchar *file,
3066 const gchar *filename,
3067 const gchar *content_type)
3075 GtkListStore *store;
3077 gboolean has_binary = FALSE;
3079 if (!is_file_exist(file)) {
3080 alertpanel_error("File %s doesn't exist\n", filename);
3083 if ((size = get_file_size(file)) < 0) {
3084 alertpanel_error("Can't get file size of %s\n", filename);
3088 alertpanel_error(_("File %s is empty."), filename);
3091 if ((fp = g_fopen(file, "rb")) == NULL) {
3092 alertpanel_error(_("Can't read %s."), filename);
3097 ainfo = g_new0(AttachInfo, 1);
3098 auto_ainfo = g_auto_pointer_new_with_free
3099 (ainfo, (GFreeFunc) compose_attach_info_free);
3100 ainfo->file = g_strdup(file);
3103 ainfo->content_type = g_strdup(content_type);
3104 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
3106 MsgFlags flags = {0, 0};
3108 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
3109 ainfo->encoding = ENC_7BIT;
3111 ainfo->encoding = ENC_8BIT;
3113 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
3114 if (msginfo && msginfo->subject)
3115 name = g_strdup(msginfo->subject);
3117 name = g_path_get_basename(filename ? filename : file);
3119 ainfo->name = g_strdup_printf(_("Message: %s"), name);
3121 procmsg_msginfo_free(msginfo);
3123 if (!g_ascii_strncasecmp(content_type, "text", 4))
3124 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
3126 ainfo->encoding = ENC_BASE64;
3127 name = g_path_get_basename(filename ? filename : file);
3128 ainfo->name = g_strdup(name);
3132 ainfo->content_type = procmime_get_mime_type(file);
3133 if (!ainfo->content_type) {
3134 ainfo->content_type =
3135 g_strdup("application/octet-stream");
3136 ainfo->encoding = ENC_BASE64;
3137 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
3139 procmime_get_encoding_for_text_file(file, &has_binary);
3141 ainfo->encoding = ENC_BASE64;
3142 name = g_path_get_basename(filename ? filename : file);
3143 ainfo->name = g_strdup(name);
3147 if (ainfo->name != NULL
3148 && !strcmp(ainfo->name, ".")) {
3149 g_free(ainfo->name);
3153 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
3154 g_free(ainfo->content_type);
3155 ainfo->content_type = g_strdup("application/octet-stream");
3159 size_text = to_human_readable(size);
3161 store = GTK_LIST_STORE(gtk_tree_view_get_model
3162 (GTK_TREE_VIEW(compose->attach_clist)));
3164 gtk_list_store_append(store, &iter);
3165 gtk_list_store_set(store, &iter,
3166 COL_MIMETYPE, ainfo->content_type,
3167 COL_SIZE, size_text,
3168 COL_NAME, ainfo->name,
3170 COL_AUTODATA, auto_ainfo,
3173 g_auto_pointer_free(auto_ainfo);
3177 static void compose_use_signing(Compose *compose, gboolean use_signing)
3179 GtkItemFactory *ifactory;
3180 GtkWidget *menuitem = NULL;
3182 compose->use_signing = use_signing;
3183 ifactory = gtk_item_factory_from_widget(compose->menubar);
3184 menuitem = gtk_item_factory_get_item
3185 (ifactory, "/Options/Sign");
3186 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3190 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3192 GtkItemFactory *ifactory;
3193 GtkWidget *menuitem = NULL;
3195 compose->use_encryption = use_encryption;
3196 ifactory = gtk_item_factory_from_widget(compose->menubar);
3197 menuitem = gtk_item_factory_get_item
3198 (ifactory, "/Options/Encrypt");
3200 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3204 #define NEXT_PART_NOT_CHILD(info) \
3206 node = info->node; \
3207 while (node->children) \
3208 node = g_node_last_child(node); \
3209 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3212 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3216 MimeInfo *firsttext = NULL;
3217 MimeInfo *encrypted = NULL;
3220 const gchar *partname = NULL;
3222 mimeinfo = procmime_scan_message(msginfo);
3223 if (!mimeinfo) return;
3225 if (mimeinfo->node->children == NULL) {
3226 procmime_mimeinfo_free_all(mimeinfo);
3230 /* find first content part */
3231 child = (MimeInfo *) mimeinfo->node->children->data;
3232 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3233 child = (MimeInfo *)child->node->children->data;
3235 if (child->type == MIMETYPE_TEXT) {
3237 debug_print("First text part found\n");
3238 } else if (compose->mode == COMPOSE_REEDIT &&
3239 child->type == MIMETYPE_APPLICATION &&
3240 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3241 encrypted = (MimeInfo *)child->node->parent->data;
3244 child = (MimeInfo *) mimeinfo->node->children->data;
3245 while (child != NULL) {
3246 if (child == encrypted) {
3247 /* skip this part of tree */
3248 NEXT_PART_NOT_CHILD(child);
3252 if (child->type == MIMETYPE_MULTIPART) {
3253 /* get the actual content */
3254 child = procmime_mimeinfo_next(child);
3258 if (child == firsttext) {
3259 child = procmime_mimeinfo_next(child);
3263 outfile = procmime_get_tmp_file_name(child);
3264 if (procmime_get_part(outfile, child) < 0)
3265 g_warning("Can't get the part of multipart message.");
3267 gchar *content_type;
3269 content_type = procmime_get_content_type_str(child->type, child->subtype);
3271 /* if we meet a pgp signature, we don't attach it, but
3272 * we force signing. */
3273 if (strcmp(content_type, "application/pgp-signature")) {
3274 partname = procmime_mimeinfo_get_parameter(child, "filename");
3275 if (partname == NULL)
3276 partname = procmime_mimeinfo_get_parameter(child, "name");
3277 if (partname == NULL)
3279 compose_attach_append(compose, outfile,
3280 partname, content_type);
3282 compose_force_signing(compose, compose->account);
3284 g_free(content_type);
3287 NEXT_PART_NOT_CHILD(child);
3289 procmime_mimeinfo_free_all(mimeinfo);
3292 #undef NEXT_PART_NOT_CHILD
3297 WAIT_FOR_INDENT_CHAR,
3298 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3301 /* return indent length, we allow:
3302 indent characters followed by indent characters or spaces/tabs,
3303 alphabets and numbers immediately followed by indent characters,
3304 and the repeating sequences of the above
3305 If quote ends with multiple spaces, only the first one is included. */
3306 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3307 const GtkTextIter *start, gint *len)
3309 GtkTextIter iter = *start;
3313 IndentState state = WAIT_FOR_INDENT_CHAR;
3316 gint alnum_count = 0;
3317 gint space_count = 0;
3320 if (prefs_common.quote_chars == NULL) {
3324 while (!gtk_text_iter_ends_line(&iter)) {
3325 wc = gtk_text_iter_get_char(&iter);
3326 if (g_unichar_iswide(wc))
3328 clen = g_unichar_to_utf8(wc, ch);
3332 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3333 is_space = g_unichar_isspace(wc);
3335 if (state == WAIT_FOR_INDENT_CHAR) {
3336 if (!is_indent && !g_unichar_isalnum(wc))
3339 quote_len += alnum_count + space_count + 1;
3340 alnum_count = space_count = 0;
3341 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3344 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3345 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3349 else if (is_indent) {
3350 quote_len += alnum_count + space_count + 1;
3351 alnum_count = space_count = 0;
3354 state = WAIT_FOR_INDENT_CHAR;
3358 gtk_text_iter_forward_char(&iter);
3361 if (quote_len > 0 && space_count > 0)
3367 if (quote_len > 0) {
3369 gtk_text_iter_forward_chars(&iter, quote_len);
3370 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3376 /* return TRUE if the line is itemized */
3377 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3378 const GtkTextIter *start)
3380 GtkTextIter iter = *start;
3385 if (gtk_text_iter_ends_line(&iter))
3389 wc = gtk_text_iter_get_char(&iter);
3390 if (!g_unichar_isspace(wc))
3392 gtk_text_iter_forward_char(&iter);
3393 if (gtk_text_iter_ends_line(&iter))
3397 clen = g_unichar_to_utf8(wc, ch);
3401 if (!strchr("*-+", ch[0]))
3404 gtk_text_iter_forward_char(&iter);
3405 if (gtk_text_iter_ends_line(&iter))
3407 wc = gtk_text_iter_get_char(&iter);
3408 if (g_unichar_isspace(wc))
3414 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3415 const GtkTextIter *start,
3416 GtkTextIter *break_pos,
3420 GtkTextIter iter = *start, line_end = *start;
3421 PangoLogAttr *attrs;
3428 gboolean can_break = FALSE;
3429 gboolean do_break = FALSE;
3430 gboolean was_white = FALSE;
3431 gboolean prev_dont_break = FALSE;
3433 gtk_text_iter_forward_to_line_end(&line_end);
3434 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3435 len = g_utf8_strlen(str, -1);
3436 /* g_print("breaking line: %d: %s (len = %d)\n",
3437 gtk_text_iter_get_line(&iter), str, len); */
3438 attrs = g_new(PangoLogAttr, len + 1);
3440 pango_default_break(str, -1, NULL, attrs, len + 1);
3444 /* skip quote and leading spaces */
3445 for (i = 0; *p != '\0' && i < len; i++) {
3448 wc = g_utf8_get_char(p);
3449 if (i >= quote_len && !g_unichar_isspace(wc))
3451 if (g_unichar_iswide(wc))
3453 else if (*p == '\t')
3457 p = g_utf8_next_char(p);
3460 for (; *p != '\0' && i < len; i++) {
3461 PangoLogAttr *attr = attrs + i;
3465 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3468 was_white = attr->is_white;
3470 /* don't wrap URI */
3471 if ((uri_len = get_uri_len(p)) > 0) {
3473 if (pos > 0 && col > max_col) {
3483 wc = g_utf8_get_char(p);
3484 if (g_unichar_iswide(wc)) {
3486 if (prev_dont_break && can_break && attr->is_line_break)
3488 } else if (*p == '\t')
3492 if (pos > 0 && col > max_col) {
3497 if (*p == '-' || *p == '/')
3498 prev_dont_break = TRUE;
3500 prev_dont_break = FALSE;
3502 p = g_utf8_next_char(p);
3506 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3511 *break_pos = *start;
3512 gtk_text_iter_set_line_offset(break_pos, pos);
3517 static gboolean compose_join_next_line(Compose *compose,
3518 GtkTextBuffer *buffer,
3520 const gchar *quote_str)
3522 GtkTextIter iter_ = *iter, cur, prev, next, end;
3523 PangoLogAttr attrs[3];
3525 gchar *next_quote_str;
3528 gboolean keep_cursor = FALSE;
3530 if (!gtk_text_iter_forward_line(&iter_) ||
3531 gtk_text_iter_ends_line(&iter_))
3534 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3536 if ((quote_str || next_quote_str) &&
3537 strcmp2(quote_str, next_quote_str) != 0) {
3538 g_free(next_quote_str);
3541 g_free(next_quote_str);
3544 if (quote_len > 0) {
3545 gtk_text_iter_forward_chars(&end, quote_len);
3546 if (gtk_text_iter_ends_line(&end))
3550 /* don't join itemized lines */
3551 if (compose_is_itemized(buffer, &end))
3554 /* don't join signature separator */
3555 if (compose_is_sig_separator(compose, buffer, &iter_))
3558 /* delete quote str */
3560 gtk_text_buffer_delete(buffer, &iter_, &end);
3562 /* don't join line breaks put by the user */
3564 gtk_text_iter_backward_char(&cur);
3565 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3566 gtk_text_iter_forward_char(&cur);
3570 gtk_text_iter_forward_char(&cur);
3571 /* delete linebreak and extra spaces */
3572 while (gtk_text_iter_backward_char(&cur)) {
3573 wc1 = gtk_text_iter_get_char(&cur);
3574 if (!g_unichar_isspace(wc1))
3579 while (!gtk_text_iter_ends_line(&cur)) {
3580 wc1 = gtk_text_iter_get_char(&cur);
3581 if (!g_unichar_isspace(wc1))
3583 gtk_text_iter_forward_char(&cur);
3586 if (!gtk_text_iter_equal(&prev, &next)) {
3589 mark = gtk_text_buffer_get_insert(buffer);
3590 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3591 if (gtk_text_iter_equal(&prev, &cur))
3593 gtk_text_buffer_delete(buffer, &prev, &next);
3597 /* insert space if required */
3598 gtk_text_iter_backward_char(&prev);
3599 wc1 = gtk_text_iter_get_char(&prev);
3600 wc2 = gtk_text_iter_get_char(&next);
3601 gtk_text_iter_forward_char(&next);
3602 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3603 pango_default_break(str, -1, NULL, attrs, 3);
3604 if (!attrs[1].is_line_break ||
3605 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3606 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3608 gtk_text_iter_backward_char(&iter_);
3609 gtk_text_buffer_place_cursor(buffer, &iter_);
3618 #define ADD_TXT_POS(bp_, ep_, pti_) \
3619 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3620 last = last->next; \
3621 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3622 last->next = NULL; \
3624 g_warning("alloc error scanning URIs\n"); \
3627 static gboolean automatic_break = FALSE;
3628 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3630 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3631 GtkTextBuffer *buffer;
3632 GtkTextIter iter, break_pos, end_of_line;
3633 gchar *quote_str = NULL;
3635 gboolean wrap_quote = prefs_common.linewrap_quote;
3636 gboolean prev_autowrap = compose->autowrap;
3637 gint startq_offset = -1, noq_offset = -1;
3638 gint uri_start = -1, uri_stop = -1;
3639 gint nouri_start = -1, nouri_stop = -1;
3640 gint num_blocks = 0;
3641 gint quotelevel = -1;
3643 compose->autowrap = FALSE;
3645 buffer = gtk_text_view_get_buffer(text);
3646 undo_wrapping(compose->undostruct, TRUE);
3651 mark = gtk_text_buffer_get_insert(buffer);
3652 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3655 /* move to paragraph start */
3656 gtk_text_iter_set_line_offset(&iter, 0);
3657 if (gtk_text_iter_ends_line(&iter)) {
3658 while (gtk_text_iter_ends_line(&iter) &&
3659 gtk_text_iter_forward_line(&iter))
3662 while (gtk_text_iter_backward_line(&iter)) {
3663 if (gtk_text_iter_ends_line(&iter)) {
3664 gtk_text_iter_forward_line(&iter);
3670 /* go until paragraph end (empty line) */
3672 while (!gtk_text_iter_ends_line(&iter)) {
3673 gchar *scanpos = NULL;
3674 /* parse table - in order of priority */
3676 const gchar *needle; /* token */
3678 /* token search function */
3679 gchar *(*search) (const gchar *haystack,
3680 const gchar *needle);
3681 /* part parsing function */
3682 gboolean (*parse) (const gchar *start,
3683 const gchar *scanpos,
3687 /* part to URI function */
3688 gchar *(*build_uri) (const gchar *bp,
3692 static struct table parser[] = {
3693 {"http://", strcasestr, get_uri_part, make_uri_string},
3694 {"https://", strcasestr, get_uri_part, make_uri_string},
3695 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3696 {"sftp://", strcasestr, get_uri_part, make_uri_string},
3697 {"www.", strcasestr, get_uri_part, make_http_string},
3698 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3699 {"@", strcasestr, get_email_part, make_email_string}
3701 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3702 gint last_index = PARSE_ELEMS;
3704 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3707 if (!prev_autowrap && num_blocks == 0) {
3709 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3710 G_CALLBACK(text_inserted),
3713 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3716 uri_start = uri_stop = -1;
3718 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3722 if (startq_offset == -1) {
3723 startq_offset = gtk_text_iter_get_offset(&iter);
3727 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3728 if (startq_offset == -1)
3729 startq_offset = gtk_text_iter_get_offset(&iter);
3730 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3731 if (quotelevel > 2) {
3732 /* recycle colors */
3733 if (prefs_common.recycle_quote_colors)
3739 if (startq_offset == -1)
3740 noq_offset = gtk_text_iter_get_offset(&iter);
3744 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3747 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3748 prefs_common.linewrap_len,
3750 GtkTextIter prev, next, cur;
3752 if (prev_autowrap != FALSE || force) {
3753 automatic_break = TRUE;
3754 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3755 automatic_break = FALSE;
3756 } else if (quote_str && wrap_quote) {
3757 automatic_break = TRUE;
3758 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3759 automatic_break = FALSE;
3762 /* remove trailing spaces */
3764 gtk_text_iter_backward_char(&cur);
3766 while (!gtk_text_iter_starts_line(&cur)) {
3769 gtk_text_iter_backward_char(&cur);
3770 wc = gtk_text_iter_get_char(&cur);
3771 if (!g_unichar_isspace(wc))
3775 if (!gtk_text_iter_equal(&prev, &next)) {
3776 gtk_text_buffer_delete(buffer, &prev, &next);
3778 gtk_text_iter_forward_char(&break_pos);
3782 gtk_text_buffer_insert(buffer, &break_pos,
3786 compose_join_next_line(compose, buffer, &iter, quote_str);
3788 /* move iter to current line start */
3789 gtk_text_iter_set_line_offset(&iter, 0);
3796 /* move iter to next line start */
3801 if (!prev_autowrap && num_blocks > 0) {
3803 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3804 G_CALLBACK(text_inserted),
3808 while (!gtk_text_iter_ends_line(&end_of_line)) {
3809 gtk_text_iter_forward_char(&end_of_line);
3811 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3813 nouri_start = gtk_text_iter_get_offset(&iter);
3814 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3816 walk_pos = gtk_text_iter_get_offset(&iter);
3817 /* FIXME: this looks phony. scanning for anything in the parse table */
3818 for (n = 0; n < PARSE_ELEMS; n++) {
3821 tmp = parser[n].search(walk, parser[n].needle);
3823 if (scanpos == NULL || tmp < scanpos) {
3832 /* check if URI can be parsed */
3833 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3834 (const gchar **)&ep, FALSE)
3835 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3839 strlen(parser[last_index].needle);
3842 uri_start = walk_pos + (bp - o_walk);
3843 uri_stop = walk_pos + (ep - o_walk);
3847 gtk_text_iter_forward_line(&iter);
3850 if (startq_offset != -1) {
3851 GtkTextIter startquote, endquote;
3852 gtk_text_buffer_get_iter_at_offset(
3853 buffer, &startquote, startq_offset);
3855 switch (quotelevel) {
3856 case 0: gtk_text_buffer_apply_tag_by_name(
3857 buffer, "quote0", &startquote, &endquote);
3859 case 1: gtk_text_buffer_apply_tag_by_name(
3860 buffer, "quote1", &startquote, &endquote);
3862 case 2: gtk_text_buffer_apply_tag_by_name(
3863 buffer, "quote2", &startquote, &endquote);
3867 } else if (noq_offset != -1) {
3868 GtkTextIter startnoquote, endnoquote;
3869 gtk_text_buffer_get_iter_at_offset(
3870 buffer, &startnoquote, noq_offset);
3872 gtk_text_buffer_remove_tag_by_name(
3873 buffer, "quote0", &startnoquote, &endnoquote);
3874 gtk_text_buffer_remove_tag_by_name(
3875 buffer, "quote1", &startnoquote, &endnoquote);
3876 gtk_text_buffer_remove_tag_by_name(
3877 buffer, "quote2", &startnoquote, &endnoquote);
3882 GtkTextIter nouri_start_iter, nouri_end_iter;
3883 gtk_text_buffer_get_iter_at_offset(
3884 buffer, &nouri_start_iter, nouri_start);
3885 gtk_text_buffer_get_iter_at_offset(
3886 buffer, &nouri_end_iter, nouri_stop);
3887 gtk_text_buffer_remove_tag_by_name(
3888 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3890 if (uri_start > 0 && uri_stop > 0) {
3891 GtkTextIter uri_start_iter, uri_end_iter;
3892 gtk_text_buffer_get_iter_at_offset(
3893 buffer, &uri_start_iter, uri_start);
3894 gtk_text_buffer_get_iter_at_offset(
3895 buffer, &uri_end_iter, uri_stop);
3896 gtk_text_buffer_apply_tag_by_name(
3897 buffer, "link", &uri_start_iter, &uri_end_iter);
3903 undo_wrapping(compose->undostruct, FALSE);
3904 compose->autowrap = prev_autowrap;
3907 void compose_action_cb(void *data)
3909 Compose *compose = (Compose *)data;
3910 compose_wrap_all(compose);
3913 static void compose_wrap_all(Compose *compose)
3915 compose_wrap_all_full(compose, FALSE);
3918 static void compose_wrap_all_full(Compose *compose, gboolean force)
3920 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3921 GtkTextBuffer *buffer;
3924 buffer = gtk_text_view_get_buffer(text);
3926 gtk_text_buffer_get_start_iter(buffer, &iter);
3927 while (!gtk_text_iter_is_end(&iter))
3928 compose_beautify_paragraph(compose, &iter, force);
3932 static void compose_set_title(Compose *compose)
3938 edited = compose->modified ? _(" [Edited]") : "";
3940 subject = gtk_editable_get_chars(
3941 GTK_EDITABLE(compose->subject_entry), 0, -1);
3943 if (subject && strlen(subject))
3944 str = g_strdup_printf(_("%s - Compose message%s"),
3947 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3948 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3954 * compose_current_mail_account:
3956 * Find a current mail account (the currently selected account, or the
3957 * default account, if a news account is currently selected). If a
3958 * mail account cannot be found, display an error message.
3960 * Return value: Mail account, or NULL if not found.
3962 static PrefsAccount *
3963 compose_current_mail_account(void)
3967 if (cur_account && cur_account->protocol != A_NNTP)
3970 ac = account_get_default();
3971 if (!ac || ac->protocol == A_NNTP) {
3972 alertpanel_error(_("Account for sending mail is not specified.\n"
3973 "Please select a mail account before sending."));
3980 #define QUOTE_IF_REQUIRED(out, str) \
3982 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3986 len = strlen(str) + 3; \
3987 if ((__tmp = alloca(len)) == NULL) { \
3988 g_warning("can't allocate memory\n"); \
3989 g_string_free(header, TRUE); \
3992 g_snprintf(__tmp, len, "\"%s\"", str); \
3997 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3998 g_warning("can't allocate memory\n"); \
3999 g_string_free(header, TRUE); \
4002 strcpy(__tmp, str); \
4008 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
4010 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4014 len = strlen(str) + 3; \
4015 if ((__tmp = alloca(len)) == NULL) { \
4016 g_warning("can't allocate memory\n"); \
4019 g_snprintf(__tmp, len, "\"%s\"", str); \
4024 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4025 g_warning("can't allocate memory\n"); \
4028 strcpy(__tmp, str); \
4034 static void compose_select_account(Compose *compose, PrefsAccount *account,
4037 GtkItemFactory *ifactory;
4040 g_return_if_fail(account != NULL);
4042 compose->account = account;
4044 if (account->name && *account->name) {
4046 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
4047 from = g_strdup_printf("%s <%s>",
4048 buf, account->address);
4049 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
4051 from = g_strdup_printf("<%s>",
4053 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
4058 compose_set_title(compose);
4060 ifactory = gtk_item_factory_from_widget(compose->menubar);
4062 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
4063 menu_set_active(ifactory, "/Options/Sign", TRUE);
4065 menu_set_active(ifactory, "/Options/Sign", FALSE);
4066 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
4067 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
4069 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
4071 activate_privacy_system(compose, account, FALSE);
4073 if (!init && compose->mode != COMPOSE_REDIRECT) {
4074 undo_block(compose->undostruct);
4075 compose_insert_sig(compose, TRUE);
4076 undo_unblock(compose->undostruct);
4080 gboolean compose_check_for_valid_recipient(Compose *compose) {
4081 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
4082 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
4083 gboolean recipient_found = FALSE;
4087 /* free to and newsgroup list */
4088 slist_free_strings(compose->to_list);
4089 g_slist_free(compose->to_list);
4090 compose->to_list = NULL;
4092 slist_free_strings(compose->newsgroup_list);
4093 g_slist_free(compose->newsgroup_list);
4094 compose->newsgroup_list = NULL;
4096 /* search header entries for to and newsgroup entries */
4097 for (list = compose->header_list; list; list = list->next) {
4100 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4101 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4103 if (entry[0] != '\0') {
4104 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
4105 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
4106 compose->to_list = address_list_append(compose->to_list, entry);
4107 recipient_found = TRUE;
4110 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
4111 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
4112 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
4113 recipient_found = TRUE;
4120 return recipient_found;
4123 static gboolean compose_check_for_set_recipients(Compose *compose)
4125 if (compose->account->set_autocc && compose->account->auto_cc) {
4126 gboolean found_other = FALSE;
4128 /* search header entries for to and newsgroup entries */
4129 for (list = compose->header_list; list; list = list->next) {
4132 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4133 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4135 if (strcmp(entry, compose->account->auto_cc)
4136 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
4146 if (compose->batch) {
4147 gtk_widget_show_all(compose->window);
4149 aval = alertpanel(_("Send"),
4150 _("The only recipient is the default CC address. Send anyway?"),
4151 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4152 if (aval != G_ALERTALTERNATE)
4156 if (compose->account->set_autobcc && compose->account->auto_bcc) {
4157 gboolean found_other = FALSE;
4159 /* search header entries for to and newsgroup entries */
4160 for (list = compose->header_list; list; list = list->next) {
4163 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
4164 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
4166 if (strcmp(entry, compose->account->auto_bcc)
4167 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
4177 if (compose->batch) {
4178 gtk_widget_show_all(compose->window);
4180 aval = alertpanel(_("Send"),
4181 _("The only recipient is the default BCC address. Send anyway?"),
4182 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4183 if (aval != G_ALERTALTERNATE)
4190 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
4194 if (compose_check_for_valid_recipient(compose) == FALSE) {
4195 if (compose->batch) {
4196 gtk_widget_show_all(compose->window);
4198 alertpanel_error(_("Recipient is not specified."));
4202 if (compose_check_for_set_recipients(compose) == FALSE) {
4206 if (!compose->batch) {
4207 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4208 if (*str == '\0' && check_subject == TRUE) {
4211 aval = alertpanel(_("Send"),
4212 _("Subject is empty. Send it anyway?"),
4213 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4214 if (aval != G_ALERTALTERNATE)
4222 gint compose_send(Compose *compose)
4225 FolderItem *folder = NULL;
4227 gchar *msgpath = NULL;
4228 gboolean discard_window = FALSE;
4229 gchar *errstr = NULL;
4230 gchar *tmsgid = NULL;
4231 MainWindow *mainwin = mainwindow_get_mainwindow();
4233 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4234 || compose->batch == TRUE)
4235 discard_window = TRUE;
4237 compose_allow_user_actions (compose, FALSE);
4238 compose->sending = TRUE;
4240 if (compose_check_entries(compose, TRUE) == FALSE) {
4241 if (compose->batch) {
4242 gtk_widget_show_all(compose->window);
4248 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
4251 if (compose->batch) {
4252 gtk_widget_show_all(compose->window);
4255 alertpanel_error(_("Could not queue message for sending:\n\n"
4256 "Charset conversion failed."));
4257 } else if (val == -5) {
4258 alertpanel_error(_("Could not queue message for sending:\n\n"
4259 "Couldn't get recipient encryption key."));
4260 } else if (val == -3) {
4261 if (privacy_peek_error())
4262 alertpanel_error(_("Could not queue message for sending:\n\n"
4263 "Signature failed: %s"), privacy_get_error());
4264 } else if (val == -2 && errno != 0) {
4265 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4267 alertpanel_error(_("Could not queue message for sending."));
4272 tmsgid = g_strdup(compose->msgid);
4273 if (discard_window) {
4274 compose->sending = FALSE;
4275 compose_close(compose);
4276 /* No more compose access in the normal codepath
4277 * after this point! */
4282 alertpanel_error(_("The message was queued but could not be "
4283 "sent.\nUse \"Send queued messages\" from "
4284 "the main window to retry."));
4285 if (!discard_window) {
4292 if (msgpath == NULL) {
4293 msgpath = folder_item_fetch_msg(folder, msgnum);
4294 val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum);
4297 val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum);
4301 if (!discard_window) {
4302 compose->sending = FALSE;
4303 compose_allow_user_actions (compose, TRUE);
4305 folder_item_remove_msg(folder, msgnum);
4306 folder_item_scan(folder);
4308 /* make sure we delete that */
4309 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
4311 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
4312 folder_item_remove_msg(folder, tmp->msgnum);
4313 procmsg_msginfo_free(tmp);
4320 folder_item_remove_msg(folder, msgnum);
4321 folder_item_scan(folder);
4323 /* make sure we delete that */
4324 MsgInfo *tmp = folder_item_get_msginfo_by_msgid(folder, tmsgid);
4326 debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
4327 folder_item_remove_msg(folder, tmp->msgnum);
4328 procmsg_msginfo_free(tmp);
4331 if (!discard_window)
4332 compose_close(compose);
4335 gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
4336 "the main window to retry."), errstr);
4338 alertpanel_error_log(tmp);
4341 alertpanel_error_log(_("The message was queued but could not be "
4342 "sent.\nUse \"Send queued messages\" from "
4343 "the main window to retry."));
4345 if (!discard_window) {
4354 toolbar_main_set_sensitive(mainwin);
4355 main_window_set_menu_sensitive(mainwin);
4361 compose_allow_user_actions (compose, TRUE);
4362 compose->sending = FALSE;
4363 compose->modified = TRUE;
4364 toolbar_main_set_sensitive(mainwin);
4365 main_window_set_menu_sensitive(mainwin);
4370 static gboolean compose_use_attach(Compose *compose)
4372 GtkTreeModel *model = gtk_tree_view_get_model
4373 (GTK_TREE_VIEW(compose->attach_clist));
4374 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4377 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4380 gchar buf[BUFFSIZE];
4382 gboolean first_to_address;
4383 gboolean first_cc_address;
4385 ComposeHeaderEntry *headerentry;
4386 const gchar *headerentryname;
4390 debug_print("Writing redirect header\n");
4392 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4393 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4395 first_to_address = TRUE;
4396 for (list = compose->header_list; list; list = list->next) {
4397 headerentry = ((ComposeHeaderEntry *)list->data);
4398 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4400 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4401 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4402 Xstrdup_a(str, entstr, return -1);
4404 if (str[0] != '\0') {
4405 compose_convert_header
4406 (compose, buf, sizeof(buf), str,
4407 strlen("Resent-To") + 2, TRUE);
4409 if (first_to_address) {
4410 fprintf(fp, "Resent-To: ");
4411 first_to_address = FALSE;
4415 fprintf(fp, "%s", buf);
4419 if (!first_to_address) {
4423 first_cc_address = TRUE;
4424 for (list = compose->header_list; list; list = list->next) {
4425 headerentry = ((ComposeHeaderEntry *)list->data);
4426 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4428 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4429 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4430 Xstrdup_a(str, strg, return -1);
4432 if (str[0] != '\0') {
4433 compose_convert_header
4434 (compose, buf, sizeof(buf), str,
4435 strlen("Resent-Cc") + 2, TRUE);
4437 if (first_cc_address) {
4438 fprintf(fp, "Resent-Cc: ");
4439 first_cc_address = FALSE;
4443 fprintf(fp, "%s", buf);
4447 if (!first_cc_address) {
4454 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4456 gchar buf[BUFFSIZE];
4458 const gchar *entstr;
4459 /* struct utsname utsbuf; */
4461 g_return_val_if_fail(fp != NULL, -1);
4462 g_return_val_if_fail(compose->account != NULL, -1);
4463 g_return_val_if_fail(compose->account->address != NULL, -1);
4466 get_rfc822_date(buf, sizeof(buf));
4467 fprintf(fp, "Resent-Date: %s\n", buf);
4470 if (compose->account->name && *compose->account->name) {
4471 compose_convert_header
4472 (compose, buf, sizeof(buf), compose->account->name,
4473 strlen("From: "), TRUE);
4474 fprintf(fp, "Resent-From: %s <%s>\n",
4475 buf, compose->account->address);
4477 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4480 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4481 if (*entstr != '\0') {
4482 Xstrdup_a(str, entstr, return -1);
4485 compose_convert_header(compose, buf, sizeof(buf), str,
4486 strlen("Subject: "), FALSE);
4487 fprintf(fp, "Subject: %s\n", buf);
4491 /* Resent-Message-ID */
4492 if (compose->account->gen_msgid) {
4493 generate_msgid(buf, sizeof(buf));
4494 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4495 compose->msgid = g_strdup(buf);
4498 compose_redirect_write_headers_from_headerlist(compose, fp);
4500 /* separator between header and body */
4506 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4510 gchar buf[BUFFSIZE];
4512 gboolean skip = FALSE;
4513 gchar *not_included[]={
4514 "Return-Path:", "Delivered-To:", "Received:",
4515 "Subject:", "X-UIDL:", "AF:",
4516 "NF:", "PS:", "SRH:",
4517 "SFN:", "DSR:", "MID:",
4518 "CFG:", "PT:", "S:",
4519 "RQ:", "SSV:", "NSV:",
4520 "SSH:", "R:", "MAID:",
4521 "NAID:", "RMID:", "FMID:",
4522 "SCF:", "RRCPT:", "NG:",
4523 "X-Sylpheed-Privacy", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt",
4524 "X-Sylpheed-End-Special-Headers:",
4527 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4528 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4532 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4534 for (i = 0; not_included[i] != NULL; i++) {
4535 if (g_ascii_strncasecmp(buf, not_included[i],
4536 strlen(not_included[i])) == 0) {
4543 if (fputs(buf, fdest) == -1)
4546 if (!prefs_common.redirect_keep_from) {
4547 if (g_ascii_strncasecmp(buf, "From:",
4548 strlen("From:")) == 0) {
4549 fputs(" (by way of ", fdest);
4550 if (compose->account->name
4551 && *compose->account->name) {
4552 compose_convert_header
4553 (compose, buf, sizeof(buf),
4554 compose->account->name,
4557 fprintf(fdest, "%s <%s>",
4559 compose->account->address);
4561 fprintf(fdest, "%s",
4562 compose->account->address);
4567 if (fputs("\n", fdest) == -1)
4571 compose_redirect_write_headers(compose, fdest);
4573 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4574 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4587 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
4589 GtkTextBuffer *buffer;
4590 GtkTextIter start, end;
4593 const gchar *out_codeset;
4594 EncodingType encoding;
4595 MimeInfo *mimemsg, *mimetext;
4598 if (action == COMPOSE_WRITE_FOR_SEND)
4599 attach_parts = TRUE;
4601 /* create message MimeInfo */
4602 mimemsg = procmime_mimeinfo_new();
4603 mimemsg->type = MIMETYPE_MESSAGE;
4604 mimemsg->subtype = g_strdup("rfc822");
4605 mimemsg->content = MIMECONTENT_MEM;
4606 mimemsg->tmp = TRUE; /* must free content later */
4607 mimemsg->data.mem = compose_get_header(compose);
4609 /* Create text part MimeInfo */
4610 /* get all composed text */
4611 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4612 gtk_text_buffer_get_start_iter(buffer, &start);
4613 gtk_text_buffer_get_end_iter(buffer, &end);
4614 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4615 if (is_ascii_str(chars)) {
4618 out_codeset = CS_US_ASCII;
4619 encoding = ENC_7BIT;
4621 const gchar *src_codeset = CS_INTERNAL;
4623 out_codeset = conv_get_charset_str(compose->out_encoding);
4626 gchar *test_conv_global_out = NULL;
4627 gchar *test_conv_reply = NULL;
4629 /* automatic mode. be automatic. */
4630 codeconv_set_strict(TRUE);
4632 out_codeset = conv_get_outgoing_charset_str();
4634 debug_print("trying to convert to %s\n", out_codeset);
4635 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4638 if (!test_conv_global_out && compose->orig_charset
4639 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4640 out_codeset = compose->orig_charset;
4641 debug_print("failure; trying to convert to %s\n", out_codeset);
4642 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4645 if (!test_conv_global_out && !test_conv_reply) {
4647 out_codeset = CS_INTERNAL;
4648 debug_print("failure; finally using %s\n", out_codeset);
4650 g_free(test_conv_global_out);
4651 g_free(test_conv_reply);
4652 codeconv_set_strict(FALSE);
4655 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4656 out_codeset = CS_ISO_8859_1;
4658 if (prefs_common.encoding_method == CTE_BASE64)
4659 encoding = ENC_BASE64;
4660 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4661 encoding = ENC_QUOTED_PRINTABLE;
4662 else if (prefs_common.encoding_method == CTE_8BIT)
4663 encoding = ENC_8BIT;
4665 encoding = procmime_get_encoding_for_charset(out_codeset);
4667 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4668 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4670 if (action == COMPOSE_WRITE_FOR_SEND) {
4671 codeconv_set_strict(TRUE);
4672 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4673 codeconv_set_strict(FALSE);
4679 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4680 "to the specified %s charset.\n"
4681 "Send it as %s?"), out_codeset, src_codeset);
4682 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4683 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4686 if (aval != G_ALERTALTERNATE) {
4691 out_codeset = src_codeset;
4697 out_codeset = src_codeset;
4703 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4704 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4705 strstr(buf, "\nFrom ") != NULL) {
4706 encoding = ENC_QUOTED_PRINTABLE;
4710 mimetext = procmime_mimeinfo_new();
4711 mimetext->content = MIMECONTENT_MEM;
4712 mimetext->tmp = TRUE; /* must free content later */
4713 /* dup'ed because procmime_encode_content can turn it into a tmpfile
4714 * and free the data, which we need later. */
4715 mimetext->data.mem = g_strdup(buf);
4716 mimetext->type = MIMETYPE_TEXT;
4717 mimetext->subtype = g_strdup("plain");
4718 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4719 g_strdup(out_codeset));
4721 /* protect trailing spaces when signing message */
4722 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4723 privacy_system_can_sign(compose->privacy_system)) {
4724 encoding = ENC_QUOTED_PRINTABLE;
4727 debug_print("main text: %d bytes encoded as %s in %d\n",
4728 strlen(buf), out_codeset, encoding);
4730 /* check for line length limit */
4731 if (action == COMPOSE_WRITE_FOR_SEND &&
4732 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4733 check_line_length(buf, 1000, &line) < 0) {
4737 msg = g_strdup_printf
4738 (_("Line %d exceeds the line length limit (998 bytes).\n"
4739 "The contents of the message might be broken on the way to the delivery.\n"
4741 "Send it anyway?"), line + 1);
4742 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4744 if (aval != G_ALERTALTERNATE) {
4750 if (encoding != ENC_UNKNOWN)
4751 procmime_encode_content(mimetext, encoding);
4753 /* append attachment parts */
4754 if (compose_use_attach(compose) && attach_parts) {
4755 MimeInfo *mimempart;
4756 gchar *boundary = NULL;
4757 mimempart = procmime_mimeinfo_new();
4758 mimempart->content = MIMECONTENT_EMPTY;
4759 mimempart->type = MIMETYPE_MULTIPART;
4760 mimempart->subtype = g_strdup("mixed");
4764 boundary = generate_mime_boundary(NULL);
4765 } while (strstr(buf, boundary) != NULL);
4767 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4770 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4772 g_node_append(mimempart->node, mimetext->node);
4773 g_node_append(mimemsg->node, mimempart->node);
4775 compose_add_attachments(compose, mimempart);
4777 g_node_append(mimemsg->node, mimetext->node);
4781 /* sign message if sending */
4782 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4783 privacy_system_can_sign(compose->privacy_system))
4784 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4787 procmime_write_mimeinfo(mimemsg, fp);
4789 procmime_mimeinfo_free_all(mimemsg);
4794 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4796 GtkTextBuffer *buffer;
4797 GtkTextIter start, end;
4802 if ((fp = g_fopen(file, "wb")) == NULL) {
4803 FILE_OP_ERROR(file, "fopen");
4807 /* chmod for security */
4808 if (change_file_mode_rw(fp, file) < 0) {
4809 FILE_OP_ERROR(file, "chmod");
4810 g_warning("can't change file mode\n");
4813 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4814 gtk_text_buffer_get_start_iter(buffer, &start);
4815 gtk_text_buffer_get_end_iter(buffer, &end);
4816 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4818 chars = conv_codeset_strdup
4819 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4822 if (!chars) return -1;
4825 len = strlen(chars);
4826 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4827 FILE_OP_ERROR(file, "fwrite");
4836 if (fclose(fp) == EOF) {
4837 FILE_OP_ERROR(file, "fclose");
4844 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4847 MsgInfo *msginfo = compose->targetinfo;
4849 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4850 if (!msginfo) return -1;
4852 if (!force && MSG_IS_LOCKED(msginfo->flags))
4855 item = msginfo->folder;
4856 g_return_val_if_fail(item != NULL, -1);
4858 if (procmsg_msg_exist(msginfo) &&
4859 (folder_has_parent_of_type(item, F_QUEUE) ||
4860 folder_has_parent_of_type(item, F_DRAFT)
4861 || msginfo == compose->autosaved_draft)) {
4862 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4863 g_warning("can't remove the old message\n");
4871 void compose_remove_draft(Compose *compose)
4874 MsgInfo *msginfo = compose->targetinfo;
4875 drafts = account_get_special_folder(compose->account, F_DRAFT);
4877 if (procmsg_msg_exist(msginfo)) {
4878 folder_item_remove_msg(drafts, msginfo->msgnum);
4883 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
4884 gboolean remove_reedit_target)
4886 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
4888 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
4889 gchar **msgpath, gboolean check_subject,
4890 gboolean remove_reedit_target)
4897 static gboolean lock = FALSE;
4898 PrefsAccount *mailac = NULL, *newsac = NULL;
4900 debug_print("queueing message...\n");
4901 g_return_val_if_fail(compose->account != NULL, -1);
4905 if (compose_check_entries(compose, check_subject) == FALSE) {
4907 if (compose->batch) {
4908 gtk_widget_show_all(compose->window);
4913 if (!compose->to_list && !compose->newsgroup_list) {
4914 g_warning("can't get recipient list.");
4919 if (compose->to_list) {
4920 if (compose->account->protocol != A_NNTP)
4921 mailac = compose->account;
4922 else if (cur_account && cur_account->protocol != A_NNTP)
4923 mailac = cur_account;
4924 else if (!(mailac = compose_current_mail_account())) {
4926 alertpanel_error(_("No account for sending mails available!"));
4931 if (compose->newsgroup_list) {
4932 if (compose->account->protocol == A_NNTP)
4933 newsac = compose->account;
4934 else if (!newsac->protocol != A_NNTP) {
4936 alertpanel_error(_("No account for posting news available!"));
4941 /* write queue header */
4942 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4943 G_DIR_SEPARATOR, compose);
4944 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4945 FILE_OP_ERROR(tmp, "fopen");
4951 if (change_file_mode_rw(fp, tmp) < 0) {
4952 FILE_OP_ERROR(tmp, "chmod");
4953 g_warning("can't change file mode\n");
4956 /* queueing variables */
4957 fprintf(fp, "AF:\n");
4958 fprintf(fp, "NF:0\n");
4959 fprintf(fp, "PS:10\n");
4960 fprintf(fp, "SRH:1\n");
4961 fprintf(fp, "SFN:\n");
4962 fprintf(fp, "DSR:\n");
4964 fprintf(fp, "MID:<%s>\n", compose->msgid);
4966 fprintf(fp, "MID:\n");
4967 fprintf(fp, "CFG:\n");
4968 fprintf(fp, "PT:0\n");
4969 fprintf(fp, "S:%s\n", compose->account->address);
4970 fprintf(fp, "RQ:\n");
4972 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4974 fprintf(fp, "SSV:\n");
4976 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4978 fprintf(fp, "NSV:\n");
4979 fprintf(fp, "SSH:\n");
4980 /* write recepient list */
4981 if (compose->to_list) {
4982 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4983 for (cur = compose->to_list->next; cur != NULL;
4985 fprintf(fp, ",<%s>", (gchar *)cur->data);
4988 /* write newsgroup list */
4989 if (compose->newsgroup_list) {
4991 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4992 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4993 fprintf(fp, ",%s", (gchar *)cur->data);
4996 /* Sylpheed account IDs */
4998 fprintf(fp, "MAID:%d\n", mailac->account_id);
5000 fprintf(fp, "NAID:%d\n", newsac->account_id);
5003 if (compose->privacy_system != NULL) {
5004 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
5005 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
5006 if (compose->use_encryption) {
5008 if (mailac && mailac->encrypt_to_self) {
5009 GSList *tmp_list = g_slist_copy(compose->to_list);
5010 tmp_list = g_slist_append(tmp_list, compose->account->address);
5011 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
5012 g_slist_free(tmp_list);
5014 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
5016 if (encdata != NULL) {
5017 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
5018 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
5019 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
5021 } /* else we finally dont want to encrypt */
5023 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
5024 /* and if encdata was null, it means there's been a problem in
5036 /* Save copy folder */
5037 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
5038 gchar *savefolderid;
5040 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
5041 fprintf(fp, "SCF:%s\n", savefolderid);
5042 g_free(savefolderid);
5044 /* Save copy folder */
5045 if (compose->return_receipt) {
5046 fprintf(fp, "RRCPT:1\n");
5048 /* Message-ID of message replying to */
5049 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
5052 folderid = folder_item_get_identifier(compose->replyinfo->folder);
5053 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
5056 /* Message-ID of message forwarding to */
5057 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
5060 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
5061 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
5065 /* end of headers */
5066 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
5068 if (compose->redirect_filename != NULL) {
5069 if (compose_redirect_write_to_file(compose, fp) < 0) {
5078 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
5083 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
5087 if (fclose(fp) == EOF) {
5088 FILE_OP_ERROR(tmp, "fclose");
5095 if (item && *item) {
5098 queue = account_get_special_folder(compose->account, F_QUEUE);
5101 g_warning("can't find queue folder\n");
5107 folder_item_scan(queue);
5108 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
5109 g_warning("can't queue the message\n");
5116 if (msgpath == NULL) {
5122 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
5123 compose_remove_reedit_target(compose, FALSE);
5126 if ((msgnum != NULL) && (item != NULL)) {
5134 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
5137 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5139 struct stat statbuf;
5140 gchar *type, *subtype;
5141 GtkTreeModel *model;
5144 model = gtk_tree_view_get_model(tree_view);
5146 if (!gtk_tree_model_get_iter_first(model, &iter))
5149 gtk_tree_model_get(model, &iter,
5153 mimepart = procmime_mimeinfo_new();
5154 mimepart->content = MIMECONTENT_FILE;
5155 mimepart->data.filename = g_strdup(ainfo->file);
5156 mimepart->tmp = FALSE; /* or we destroy our attachment */
5157 mimepart->offset = 0;
5159 stat(ainfo->file, &statbuf);
5160 mimepart->length = statbuf.st_size;
5162 type = g_strdup(ainfo->content_type);
5164 if (!strchr(type, '/')) {
5166 type = g_strdup("application/octet-stream");
5169 subtype = strchr(type, '/') + 1;
5170 *(subtype - 1) = '\0';
5171 mimepart->type = procmime_get_media_type(type);
5172 mimepart->subtype = g_strdup(subtype);
5175 if (mimepart->type == MIMETYPE_MESSAGE &&
5176 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
5177 mimepart->disposition = DISPOSITIONTYPE_INLINE;
5180 g_hash_table_insert(mimepart->typeparameters,
5181 g_strdup("name"), g_strdup(ainfo->name));
5182 g_hash_table_insert(mimepart->dispositionparameters,
5183 g_strdup("filename"), g_strdup(ainfo->name));
5184 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
5188 if (compose->use_signing) {
5189 if (ainfo->encoding == ENC_7BIT)
5190 ainfo->encoding = ENC_QUOTED_PRINTABLE;
5191 else if (ainfo->encoding == ENC_8BIT)
5192 ainfo->encoding = ENC_BASE64;
5195 procmime_encode_content(mimepart, ainfo->encoding);
5197 g_node_append(parent->node, mimepart->node);
5198 } while (gtk_tree_model_iter_next(model, &iter));
5201 #define IS_IN_CUSTOM_HEADER(header) \
5202 (compose->account->add_customhdr && \
5203 custom_header_find(compose->account->customhdr_list, header) != NULL)
5205 static void compose_add_headerfield_from_headerlist(Compose *compose,
5207 const gchar *fieldname,
5208 const gchar *seperator)
5210 gchar *str, *fieldname_w_colon, *trans_fieldname;
5211 gboolean add_field = FALSE;
5213 ComposeHeaderEntry *headerentry;
5214 const gchar * headerentryname;
5217 if (IS_IN_CUSTOM_HEADER(fieldname))
5220 debug_print("Adding %s-fields\n", fieldname);
5222 fieldstr = g_string_sized_new(64);
5224 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
5225 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
5227 for (list = compose->header_list; list; list = list->next) {
5228 headerentry = ((ComposeHeaderEntry *)list->data);
5229 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
5231 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
5232 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
5234 if (str[0] != '\0') {
5236 g_string_append(fieldstr, seperator);
5237 g_string_append(fieldstr, str);
5246 buf = g_new0(gchar, fieldstr->len * 4 + 256);
5247 compose_convert_header
5248 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
5249 strlen(fieldname) + 2, TRUE);
5250 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
5254 g_free(fieldname_w_colon);
5255 g_string_free(fieldstr, TRUE);
5260 static gchar *compose_get_header(Compose *compose)
5262 gchar buf[BUFFSIZE];
5263 const gchar *entry_str;
5267 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5269 gchar *from_name = NULL, *from_address = NULL;
5272 g_return_val_if_fail(compose->account != NULL, NULL);
5273 g_return_val_if_fail(compose->account->address != NULL, NULL);
5275 header = g_string_sized_new(64);
5278 get_rfc822_date(buf, sizeof(buf));
5279 g_string_append_printf(header, "Date: %s\n", buf);
5283 if (compose->account->name && *compose->account->name) {
5285 QUOTE_IF_REQUIRED(buf, compose->account->name);
5286 tmp = g_strdup_printf("%s <%s>",
5287 buf, compose->account->address);
5289 tmp = g_strdup_printf("%s",
5290 compose->account->address);
5292 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5293 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5295 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5296 from_address = g_strdup(compose->account->address);
5298 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5299 /* extract name and address */
5300 if (strstr(spec, " <") && strstr(spec, ">")) {
5301 from_address = g_strdup(strrchr(spec, '<')+1);
5302 *(strrchr(from_address, '>')) = '\0';
5303 from_name = g_strdup(spec);
5304 *(strrchr(from_name, '<')) = '\0';
5307 from_address = g_strdup(spec);
5314 if (from_name && *from_name) {
5315 compose_convert_header
5316 (compose, buf, sizeof(buf), from_name,
5317 strlen("From: "), TRUE);
5318 QUOTE_IF_REQUIRED(name, buf);
5320 g_string_append_printf(header, "From: %s <%s>\n",
5321 name, from_address);
5323 g_string_append_printf(header, "From: %s\n", from_address);
5326 g_free(from_address);
5329 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5332 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5335 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5338 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5341 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5343 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5346 compose_convert_header(compose, buf, sizeof(buf), str,
5347 strlen("Subject: "), FALSE);
5348 g_string_append_printf(header, "Subject: %s\n", buf);
5354 if (compose->account->gen_msgid) {
5355 generate_msgid(buf, sizeof(buf));
5356 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5357 compose->msgid = g_strdup(buf);
5360 if (compose->remove_references == FALSE) {
5362 if (compose->inreplyto && compose->to_list)
5363 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5366 if (compose->references)
5367 g_string_append_printf(header, "References: %s\n", compose->references);
5371 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5374 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5377 if (compose->account->organization &&
5378 strlen(compose->account->organization) &&
5379 !IS_IN_CUSTOM_HEADER("Organization")) {
5380 compose_convert_header(compose, buf, sizeof(buf),
5381 compose->account->organization,
5382 strlen("Organization: "), FALSE);
5383 g_string_append_printf(header, "Organization: %s\n", buf);
5386 /* Program version and system info */
5387 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5388 !compose->newsgroup_list) {
5389 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5391 gtk_major_version, gtk_minor_version, gtk_micro_version,
5394 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5395 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5397 gtk_major_version, gtk_minor_version, gtk_micro_version,
5401 /* custom headers */
5402 if (compose->account->add_customhdr) {
5405 for (cur = compose->account->customhdr_list; cur != NULL;
5407 CustomHeader *chdr = (CustomHeader *)cur->data;
5409 if (custom_header_is_allowed(chdr->name)) {
5410 compose_convert_header
5411 (compose, buf, sizeof(buf),
5412 chdr->value ? chdr->value : "",
5413 strlen(chdr->name) + 2, FALSE);
5414 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5420 switch (compose->priority) {
5421 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5422 "X-Priority: 1 (Highest)\n");
5424 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5425 "X-Priority: 2 (High)\n");
5427 case PRIORITY_NORMAL: break;
5428 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5429 "X-Priority: 4 (Low)\n");
5431 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5432 "X-Priority: 5 (Lowest)\n");
5434 default: debug_print("compose: priority unknown : %d\n",
5438 /* Request Return Receipt */
5439 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5440 if (compose->return_receipt) {
5441 if (compose->account->name
5442 && *compose->account->name) {
5443 compose_convert_header(compose, buf, sizeof(buf),
5444 compose->account->name,
5445 strlen("Disposition-Notification-To: "),
5447 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5449 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5453 /* get special headers */
5454 for (list = compose->header_list; list; list = list->next) {
5455 ComposeHeaderEntry *headerentry;
5458 gchar *headername_wcolon;
5459 gchar *headername_trans;
5462 gboolean standard_header = FALSE;
5464 headerentry = ((ComposeHeaderEntry *)list->data);
5466 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5467 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5472 if (!strstr(tmp, ":")) {
5473 headername_wcolon = g_strconcat(tmp, ":", NULL);
5474 headername = g_strdup(tmp);
5476 headername_wcolon = g_strdup(tmp);
5477 headername = g_strdup(strtok(tmp, ":"));
5481 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5482 Xstrdup_a(headervalue, entry_str, return NULL);
5483 subst_char(headervalue, '\r', ' ');
5484 subst_char(headervalue, '\n', ' ');
5485 string = std_headers;
5486 while (*string != NULL) {
5487 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5488 if (!strcmp(headername_trans,headername_wcolon))
5489 standard_header = TRUE;
5492 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5493 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5496 g_free(headername_wcolon);
5500 g_string_free(header, FALSE);
5505 #undef IS_IN_CUSTOM_HEADER
5507 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5508 gint header_len, gboolean addr_field)
5510 gchar *tmpstr = NULL;
5511 const gchar *out_codeset = NULL;
5513 g_return_if_fail(src != NULL);
5514 g_return_if_fail(dest != NULL);
5516 if (len < 1) return;
5518 tmpstr = g_strdup(src);
5520 subst_char(tmpstr, '\n', ' ');
5521 subst_char(tmpstr, '\r', ' ');
5524 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5525 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5526 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5531 codeconv_set_strict(TRUE);
5532 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5533 conv_get_charset_str(compose->out_encoding));
5534 codeconv_set_strict(FALSE);
5536 if (!dest || *dest == '\0') {
5537 gchar *test_conv_global_out = NULL;
5538 gchar *test_conv_reply = NULL;
5540 /* automatic mode. be automatic. */
5541 codeconv_set_strict(TRUE);
5543 out_codeset = conv_get_outgoing_charset_str();
5545 debug_print("trying to convert to %s\n", out_codeset);
5546 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5549 if (!test_conv_global_out && compose->orig_charset
5550 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5551 out_codeset = compose->orig_charset;
5552 debug_print("failure; trying to convert to %s\n", out_codeset);
5553 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5556 if (!test_conv_global_out && !test_conv_reply) {
5558 out_codeset = CS_INTERNAL;
5559 debug_print("finally using %s\n", out_codeset);
5561 g_free(test_conv_global_out);
5562 g_free(test_conv_reply);
5563 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5565 codeconv_set_strict(FALSE);
5570 static void compose_create_header_entry(Compose *compose)
5572 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5576 GList *combo_list = NULL;
5578 const gchar *header = NULL;
5579 ComposeHeaderEntry *headerentry;
5580 gboolean standard_header = FALSE;
5582 headerentry = g_new0(ComposeHeaderEntry, 1);
5585 combo = gtk_combo_new();
5587 while(*string != NULL) {
5588 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5591 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5592 g_list_free(combo_list);
5593 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5594 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5595 G_CALLBACK(compose_grab_focus_cb), compose);
5596 gtk_widget_show(combo);
5597 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5598 if (compose->header_last) {
5599 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5601 while (*string != NULL) {
5602 if (!strcmp(*string, last_header_entry))
5603 standard_header = TRUE;
5606 if (standard_header)
5607 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5609 if (!compose->header_last || !standard_header) {
5610 switch(compose->account->protocol) {
5612 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5615 header = prefs_common.trans_hdr ? _("To:") : "To:";
5620 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5622 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5623 G_CALLBACK(compose_grab_focus_cb), compose);
5626 entry = gtk_entry_new();
5627 gtk_widget_show(entry);
5628 gtk_tooltips_set_tip(compose->tooltips, entry,
5629 _("Use <tab> to autocomplete from addressbook"), NULL);
5630 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);
5632 g_signal_connect(G_OBJECT(entry), "key-press-event",
5633 G_CALLBACK(compose_headerentry_key_press_event_cb),
5635 g_signal_connect(G_OBJECT(entry), "changed",
5636 G_CALLBACK(compose_headerentry_changed_cb),
5638 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5639 G_CALLBACK(compose_grab_focus_cb), compose);
5642 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5643 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5644 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5645 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5646 G_CALLBACK(compose_header_drag_received_cb),
5648 g_signal_connect(G_OBJECT(entry), "drag-drop",
5649 G_CALLBACK(compose_drag_drop),
5652 address_completion_register_entry(GTK_ENTRY(entry), TRUE);
5654 headerentry->compose = compose;
5655 headerentry->combo = combo;
5656 headerentry->entry = entry;
5657 headerentry->headernum = compose->header_nextrow;
5659 compose->header_nextrow++;
5660 compose->header_last = headerentry;
5663 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5665 ComposeHeaderEntry *last_header;
5667 last_header = compose->header_last;
5669 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5670 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5673 static void compose_remove_header_entries(Compose *compose)
5676 for (list = compose->header_list; list; list = list->next) {
5677 ComposeHeaderEntry *headerentry =
5678 (ComposeHeaderEntry *)list->data;
5679 gtk_widget_destroy(headerentry->combo);
5680 gtk_widget_destroy(headerentry->entry);
5681 g_free(headerentry);
5683 g_slist_free(compose->header_list);
5684 compose->header_list = NULL;
5685 compose->header_nextrow = 1;
5686 compose_create_header_entry(compose);
5689 static GtkWidget *compose_create_header(Compose *compose)
5691 GtkWidget *from_optmenu_hbox;
5692 GtkWidget *header_scrolledwin;
5693 GtkWidget *header_table;
5697 /* header labels and entries */
5698 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5699 gtk_widget_show(header_scrolledwin);
5700 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5702 header_table = gtk_table_new(2, 2, FALSE);
5703 gtk_widget_show(header_table);
5704 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5705 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5706 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5709 /* option menu for selecting accounts */
5710 from_optmenu_hbox = compose_account_option_menu_create(compose);
5711 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5712 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5715 compose->header_table = header_table;
5716 compose->header_list = NULL;
5717 compose->header_nextrow = count;
5719 compose_create_header_entry(compose);
5721 compose->table = NULL;
5723 return header_scrolledwin ;
5726 GtkWidget *compose_create_attach(Compose *compose)
5728 GtkWidget *attach_scrwin;
5729 GtkWidget *attach_clist;
5731 GtkListStore *store;
5732 GtkCellRenderer *renderer;
5733 GtkTreeViewColumn *column;
5734 GtkTreeSelection *selection;
5736 /* attachment list */
5737 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5738 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5739 GTK_POLICY_AUTOMATIC,
5740 GTK_POLICY_AUTOMATIC);
5741 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5743 store = gtk_list_store_new(N_ATTACH_COLS,
5748 G_TYPE_AUTO_POINTER,
5750 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5751 (GTK_TREE_MODEL(store)));
5752 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5753 g_object_unref(store);
5755 renderer = gtk_cell_renderer_text_new();
5756 column = gtk_tree_view_column_new_with_attributes
5757 (_("Mime type"), renderer, "text",
5758 COL_MIMETYPE, NULL);
5759 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5761 renderer = gtk_cell_renderer_text_new();
5762 column = gtk_tree_view_column_new_with_attributes
5763 (_("Size"), renderer, "text",
5765 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5767 renderer = gtk_cell_renderer_text_new();
5768 column = gtk_tree_view_column_new_with_attributes
5769 (_("Name"), renderer, "text",
5771 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5773 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5774 prefs_common.use_stripes_everywhere);
5775 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5776 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5778 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5779 G_CALLBACK(attach_selected), compose);
5780 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5781 G_CALLBACK(attach_button_pressed), compose);
5782 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5783 G_CALLBACK(attach_key_pressed), compose);
5786 gtk_drag_dest_set(attach_clist,
5787 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5788 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5789 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5790 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5791 G_CALLBACK(compose_attach_drag_received_cb),
5793 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5794 G_CALLBACK(compose_drag_drop),
5797 compose->attach_scrwin = attach_scrwin;
5798 compose->attach_clist = attach_clist;
5800 return attach_scrwin;
5803 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5804 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5806 static GtkWidget *compose_create_others(Compose *compose)
5809 GtkWidget *savemsg_checkbtn;
5810 GtkWidget *savemsg_entry;
5811 GtkWidget *savemsg_select;
5814 gchar *folderidentifier;
5816 /* Table for settings */
5817 table = gtk_table_new(3, 1, FALSE);
5818 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5819 gtk_widget_show(table);
5820 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5823 /* Save Message to folder */
5824 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5825 gtk_widget_show(savemsg_checkbtn);
5826 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5827 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5828 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5830 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5831 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5833 savemsg_entry = gtk_entry_new();
5834 gtk_widget_show(savemsg_entry);
5835 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5836 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5837 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5838 G_CALLBACK(compose_grab_focus_cb), compose);
5839 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5840 folderidentifier = folder_item_get_identifier(account_get_special_folder
5841 (compose->account, F_OUTBOX));
5842 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5843 g_free(folderidentifier);
5846 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5847 gtk_widget_show(savemsg_select);
5848 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5849 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5850 G_CALLBACK(compose_savemsg_select_cb),
5855 compose->savemsg_checkbtn = savemsg_checkbtn;
5856 compose->savemsg_entry = savemsg_entry;
5861 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5863 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5864 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5867 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5872 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5875 path = folder_item_get_identifier(dest);
5877 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5881 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5882 GdkAtom clip, GtkTextIter *insert_place);
5884 #define BLOCK_WRAP() { \
5885 prev_autowrap = compose->autowrap; \
5886 buffer = gtk_text_view_get_buffer( \
5887 GTK_TEXT_VIEW(compose->text)); \
5888 compose->autowrap = FALSE; \
5890 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5891 G_CALLBACK(compose_changed_cb), \
5893 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5894 G_CALLBACK(text_inserted), \
5897 #define UNBLOCK_WRAP() { \
5898 compose->autowrap = prev_autowrap; \
5899 if (compose->autowrap) \
5900 compose_wrap_all(compose); \
5902 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5903 G_CALLBACK(compose_changed_cb), \
5905 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5906 G_CALLBACK(text_inserted), \
5911 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5915 GtkTextBuffer *buffer;
5917 if (event->button == 3) {
5919 GtkTextIter sel_start, sel_end;
5920 gboolean stuff_selected;
5922 /* move the cursor to allow GtkAspell to check the word
5923 * under the mouse */
5924 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5925 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5927 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5930 stuff_selected = gtk_text_buffer_get_selection_bounds(
5931 GTK_TEXT_VIEW(text)->buffer,
5932 &sel_start, &sel_end);
5934 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5935 /* reselect stuff */
5937 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5938 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5939 &sel_start, &sel_end);
5941 return FALSE; /* pass the event so that the right-click goes through */
5944 if (event->button == 2) {
5949 /* get the middle-click position to paste at the correct place */
5950 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5951 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5953 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5956 entry_paste_clipboard(compose, text,
5957 prefs_common.linewrap_pastes,
5958 GDK_SELECTION_PRIMARY, &iter);
5966 static void compose_spell_menu_changed(void *data)
5968 Compose *compose = (Compose *)data;
5970 GtkWidget *menuitem;
5971 GtkWidget *parent_item;
5972 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5973 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5976 if (compose->gtkaspell == NULL)
5979 parent_item = gtk_item_factory_get_item(ifactory,
5980 "/Spelling/Options");
5982 /* setting the submenu removes /Spelling/Options from the factory
5983 * so we need to save it */
5985 if (parent_item == NULL) {
5986 parent_item = compose->aspell_options_menu;
5987 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5989 compose->aspell_options_menu = parent_item;
5991 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5993 spell_menu = g_slist_reverse(spell_menu);
5994 for (items = spell_menu;
5995 items; items = items->next) {
5996 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
5997 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5998 gtk_widget_show(GTK_WIDGET(menuitem));
6000 g_slist_free(spell_menu);
6002 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
6007 static gboolean compose_force_window_origin = TRUE;
6008 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
6015 GtkWidget *handlebox;
6017 GtkWidget *notebook;
6022 GtkWidget *subject_hbox;
6023 GtkWidget *subject_frame;
6024 GtkWidget *subject_entry;
6028 GtkWidget *edit_vbox;
6029 GtkWidget *ruler_hbox;
6031 GtkWidget *scrolledwin;
6033 GtkTextBuffer *buffer;
6034 GtkClipboard *clipboard;
6036 UndoMain *undostruct;
6038 gchar *titles[N_ATTACH_COLS];
6039 guint n_menu_entries;
6040 GtkWidget *popupmenu;
6041 GtkItemFactory *popupfactory;
6042 GtkItemFactory *ifactory;
6043 GtkWidget *tmpl_menu;
6045 GtkWidget *menuitem;
6048 GtkAspell * gtkaspell = NULL;
6051 static GdkGeometry geometry;
6053 g_return_val_if_fail(account != NULL, NULL);
6055 debug_print("Creating compose window...\n");
6056 compose = g_new0(Compose, 1);
6058 titles[COL_MIMETYPE] = _("MIME type");
6059 titles[COL_SIZE] = _("Size");
6060 titles[COL_NAME] = _("Name");
6062 compose->batch = batch;
6063 compose->account = account;
6065 compose->mutex = g_mutex_new();
6066 compose->set_cursor_pos = -1;
6068 compose->tooltips = gtk_tooltips_new();
6070 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6071 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
6072 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
6074 if (!geometry.max_width) {
6075 geometry.max_width = gdk_screen_width();
6076 geometry.max_height = gdk_screen_height();
6079 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
6080 &geometry, GDK_HINT_MAX_SIZE);
6081 if (!geometry.min_width) {
6082 geometry.min_width = 600;
6083 geometry.min_height = 480;
6085 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
6086 &geometry, GDK_HINT_MIN_SIZE);
6088 if (compose_force_window_origin)
6089 gtk_widget_set_uposition(window, prefs_common.compose_x,
6090 prefs_common.compose_y);
6092 g_signal_connect(G_OBJECT(window), "delete_event",
6093 G_CALLBACK(compose_delete_cb), compose);
6094 MANAGE_WINDOW_SIGNALS_CONNECT(window);
6095 gtk_widget_realize(window);
6097 gtkut_widget_set_composer_icon(window);
6099 vbox = gtk_vbox_new(FALSE, 0);
6100 gtk_container_add(GTK_CONTAINER(window), vbox);
6102 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
6103 menubar = menubar_create(window, compose_entries,
6104 n_menu_entries, "<Compose>", compose);
6105 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
6107 if (prefs_common.toolbar_detachable) {
6108 handlebox = gtk_handle_box_new();
6110 handlebox = gtk_hbox_new(FALSE, 0);
6112 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
6114 gtk_widget_realize(handlebox);
6115 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
6118 vbox2 = gtk_vbox_new(FALSE, 2);
6119 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
6120 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
6123 notebook = gtk_notebook_new();
6124 gtk_widget_set_size_request(notebook, -1, 130);
6125 gtk_widget_show(notebook);
6127 /* header labels and entries */
6128 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6129 compose_create_header(compose),
6130 gtk_label_new_with_mnemonic(_("Hea_der")));
6131 /* attachment list */
6132 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6133 compose_create_attach(compose),
6134 gtk_label_new_with_mnemonic(_("_Attachments")));
6136 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
6137 compose_create_others(compose),
6138 gtk_label_new_with_mnemonic(_("Othe_rs")));
6141 subject_hbox = gtk_hbox_new(FALSE, 0);
6142 gtk_widget_show(subject_hbox);
6144 subject_frame = gtk_frame_new(NULL);
6145 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
6146 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
6147 gtk_widget_show(subject_frame);
6149 subject = gtk_hbox_new(FALSE, 0);
6150 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
6151 gtk_widget_show(subject);
6153 label = gtk_label_new(_("Subject:"));
6154 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
6155 gtk_widget_show(label);
6157 subject_entry = gtk_entry_new();
6158 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
6159 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
6160 G_CALLBACK(compose_grab_focus_cb), compose);
6161 gtk_widget_show(subject_entry);
6162 compose->subject_entry = subject_entry;
6163 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
6165 edit_vbox = gtk_vbox_new(FALSE, 0);
6167 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
6170 ruler_hbox = gtk_hbox_new(FALSE, 0);
6171 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
6173 ruler = gtk_shruler_new();
6174 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
6175 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
6179 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
6180 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
6181 GTK_POLICY_AUTOMATIC,
6182 GTK_POLICY_AUTOMATIC);
6183 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
6185 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
6186 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
6188 text = gtk_text_view_new();
6189 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6190 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
6191 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
6192 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
6193 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
6195 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
6197 g_signal_connect_after(G_OBJECT(text), "size_allocate",
6198 G_CALLBACK(compose_edit_size_alloc),
6200 g_signal_connect(G_OBJECT(buffer), "changed",
6201 G_CALLBACK(compose_changed_cb), compose);
6202 g_signal_connect(G_OBJECT(text), "grab_focus",
6203 G_CALLBACK(compose_grab_focus_cb), compose);
6204 g_signal_connect(G_OBJECT(buffer), "insert_text",
6205 G_CALLBACK(text_inserted), compose);
6206 g_signal_connect(G_OBJECT(text), "button_press_event",
6207 G_CALLBACK(text_clicked), compose);
6208 g_signal_connect(G_OBJECT(subject_entry), "changed",
6209 G_CALLBACK(compose_changed_cb), compose);
6212 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
6213 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
6214 GDK_ACTION_COPY | GDK_ACTION_MOVE);
6215 g_signal_connect(G_OBJECT(text), "drag_data_received",
6216 G_CALLBACK(compose_insert_drag_received_cb),
6218 g_signal_connect(G_OBJECT(text), "drag-drop",
6219 G_CALLBACK(compose_drag_drop),
6221 gtk_widget_show_all(vbox);
6223 /* pane between attach clist and text */
6224 paned = gtk_vpaned_new();
6225 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
6226 gtk_container_add(GTK_CONTAINER(vbox2), paned);
6227 gtk_paned_add1(GTK_PANED(paned), notebook);
6228 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
6229 gtk_widget_show_all(paned);
6232 if (prefs_common.textfont) {
6233 PangoFontDescription *font_desc;
6235 font_desc = pango_font_description_from_string
6236 (prefs_common.textfont);
6238 gtk_widget_modify_font(text, font_desc);
6239 pango_font_description_free(font_desc);
6243 n_entries = sizeof(compose_popup_entries) /
6244 sizeof(compose_popup_entries[0]);
6245 popupmenu = menu_create_items(compose_popup_entries, n_entries,
6246 "<Compose>", &popupfactory,
6249 ifactory = gtk_item_factory_from_widget(menubar);
6250 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6251 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6252 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
6254 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6256 undostruct = undo_init(text);
6257 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
6260 address_completion_start(window);
6262 compose->window = window;
6263 compose->vbox = vbox;
6264 compose->menubar = menubar;
6265 compose->handlebox = handlebox;
6267 compose->vbox2 = vbox2;
6269 compose->paned = paned;
6271 compose->edit_vbox = edit_vbox;
6272 compose->ruler_hbox = ruler_hbox;
6273 compose->ruler = ruler;
6274 compose->scrolledwin = scrolledwin;
6275 compose->text = text;
6277 compose->focused_editable = NULL;
6279 compose->popupmenu = popupmenu;
6280 compose->popupfactory = popupfactory;
6282 compose->tmpl_menu = tmpl_menu;
6284 compose->mode = mode;
6285 compose->rmode = mode;
6287 compose->targetinfo = NULL;
6288 compose->replyinfo = NULL;
6289 compose->fwdinfo = NULL;
6291 compose->replyto = NULL;
6293 compose->bcc = NULL;
6294 compose->followup_to = NULL;
6296 compose->ml_post = NULL;
6298 compose->inreplyto = NULL;
6299 compose->references = NULL;
6300 compose->msgid = NULL;
6301 compose->boundary = NULL;
6303 compose->autowrap = prefs_common.autowrap;
6305 compose->use_signing = FALSE;
6306 compose->use_encryption = FALSE;
6307 compose->privacy_system = NULL;
6309 compose->modified = FALSE;
6311 compose->return_receipt = FALSE;
6313 compose->to_list = NULL;
6314 compose->newsgroup_list = NULL;
6316 compose->undostruct = undostruct;
6318 compose->sig_str = NULL;
6320 compose->exteditor_file = NULL;
6321 compose->exteditor_pid = -1;
6322 compose->exteditor_tag = -1;
6323 compose->draft_timeout_tag = -1;
6326 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6327 if (mode != COMPOSE_REDIRECT) {
6328 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6329 strcmp(prefs_common.dictionary, "")) {
6330 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6331 prefs_common.dictionary,
6332 conv_get_locale_charset_str(),
6333 prefs_common.misspelled_col,
6334 prefs_common.check_while_typing,
6335 prefs_common.recheck_when_changing_dict,
6336 prefs_common.use_alternate,
6337 GTK_TEXT_VIEW(text),
6338 GTK_WINDOW(compose->window),
6339 compose_spell_menu_changed,
6342 alertpanel_error(_("Spell checker could not "
6344 gtkaspell_checkers_strerror());
6345 gtkaspell_checkers_reset_error();
6347 if (!gtkaspell_set_sug_mode(gtkaspell,
6348 prefs_common.aspell_sugmode)) {
6349 debug_print("Aspell: could not set "
6350 "suggestion mode %s\n",
6351 gtkaspell_checkers_strerror());
6352 gtkaspell_checkers_reset_error();
6355 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6359 compose->gtkaspell = gtkaspell;
6360 compose_spell_menu_changed(compose);
6363 compose_select_account(compose, account, TRUE);
6365 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6366 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6367 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6369 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6370 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6372 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6373 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6375 menu_set_sensitive(ifactory, "/Options/Reply mode", compose->mode == COMPOSE_REPLY);
6377 if (account->protocol != A_NNTP)
6378 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6380 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6382 addressbook_set_target_compose(compose);
6384 if (mode != COMPOSE_REDIRECT)
6385 compose_set_template_menu(compose);
6387 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6388 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6391 compose_list = g_list_append(compose_list, compose);
6393 if (!prefs_common.show_ruler)
6394 gtk_widget_hide(ruler_hbox);
6396 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6397 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6398 prefs_common.show_ruler);
6401 compose->priority = PRIORITY_NORMAL;
6402 compose_update_priority_menu_item(compose);
6404 compose_set_out_encoding(compose);
6407 compose_update_actions_menu(compose);
6409 /* Privacy Systems menu */
6410 compose_update_privacy_systems_menu(compose);
6412 activate_privacy_system(compose, account, TRUE);
6413 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6415 gtk_widget_realize(window);
6417 gtk_widget_show(window);
6423 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6428 GtkWidget *optmenubox;
6431 GtkWidget *from_name = NULL;
6433 gint num = 0, def_menu = 0;
6435 accounts = account_get_list();
6436 g_return_val_if_fail(accounts != NULL, NULL);
6438 optmenubox = gtk_event_box_new();
6439 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
6440 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
6442 hbox = gtk_hbox_new(FALSE, 6);
6443 from_name = gtk_entry_new();
6445 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6446 G_CALLBACK(compose_grab_focus_cb), compose);
6448 for (; accounts != NULL; accounts = accounts->next, num++) {
6449 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6450 gchar *name, *from = NULL;
6452 if (ac == compose->account) def_menu = num;
6454 name = g_markup_printf_escaped(_("From: <i>%s</i>"),
6457 if (ac == compose->account) {
6458 if (ac->name && *ac->name) {
6460 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6461 from = g_strdup_printf("%s <%s>",
6463 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6465 from = g_strdup_printf("%s",
6467 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6470 COMBOBOX_ADD(menu, name, ac->account_id);
6475 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
6477 g_signal_connect(G_OBJECT(optmenu), "changed",
6478 G_CALLBACK(account_activated),
6481 gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
6482 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6484 gtk_tooltips_set_tip(compose->tooltips, optmenubox,
6485 _("Account to use for this email"), NULL);
6486 gtk_tooltips_set_tip(compose->tooltips, from_name,
6487 _("Sender address to be used"), NULL);
6489 compose->from_name = from_name;
6494 static void compose_set_priority_cb(gpointer data,
6498 Compose *compose = (Compose *) data;
6499 compose->priority = action;
6502 static void compose_reply_change_mode(gpointer data,
6506 Compose *compose = (Compose *) data;
6507 gboolean was_modified = compose->modified;
6509 gboolean all = FALSE, ml = FALSE, sender = FALSE, followup = FALSE;
6510 if (compose->mode != COMPOSE_REPLY)
6512 g_return_if_fail(compose->replyinfo != NULL);
6514 if (action == COMPOSE_REPLY && prefs_common.default_reply_list)
6516 if (action == COMPOSE_REPLY && compose->rmode == COMPOSE_FOLLOWUP_AND_REPLY_TO)
6518 if (action == COMPOSE_REPLY_TO_ALL)
6520 if (action == COMPOSE_REPLY_TO_SENDER)
6522 if (action == COMPOSE_REPLY_TO_LIST)
6525 compose_remove_header_entries(compose);
6526 compose_reply_set_entry(compose, compose->replyinfo, all, ml, sender, followup);
6527 compose_show_first_last_header(compose, TRUE);
6528 compose->modified = was_modified;
6529 compose_set_title(compose);
6532 static void compose_update_priority_menu_item(Compose * compose)
6534 GtkItemFactory *ifactory;
6535 GtkWidget *menuitem = NULL;
6537 ifactory = gtk_item_factory_from_widget(compose->menubar);
6539 switch (compose->priority) {
6540 case PRIORITY_HIGHEST:
6541 menuitem = gtk_item_factory_get_item
6542 (ifactory, "/Options/Priority/Highest");
6545 menuitem = gtk_item_factory_get_item
6546 (ifactory, "/Options/Priority/High");
6548 case PRIORITY_NORMAL:
6549 menuitem = gtk_item_factory_get_item
6550 (ifactory, "/Options/Priority/Normal");
6553 menuitem = gtk_item_factory_get_item
6554 (ifactory, "/Options/Priority/Low");
6556 case PRIORITY_LOWEST:
6557 menuitem = gtk_item_factory_get_item
6558 (ifactory, "/Options/Priority/Lowest");
6561 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6564 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6566 Compose *compose = (Compose *) data;
6568 GtkItemFactory *ifactory;
6569 gboolean can_sign = FALSE, can_encrypt = FALSE;
6571 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6573 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6576 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6577 g_free(compose->privacy_system);
6578 compose->privacy_system = NULL;
6579 if (systemid != NULL) {
6580 compose->privacy_system = g_strdup(systemid);
6582 can_sign = privacy_system_can_sign(systemid);
6583 can_encrypt = privacy_system_can_encrypt(systemid);
6586 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6588 ifactory = gtk_item_factory_from_widget(compose->menubar);
6589 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6590 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6593 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6595 static gchar *branch_path = "/Options/Privacy System";
6596 GtkItemFactory *ifactory;
6597 GtkWidget *menuitem = NULL;
6599 gboolean can_sign = FALSE, can_encrypt = FALSE;
6600 gboolean found = FALSE;
6602 ifactory = gtk_item_factory_from_widget(compose->menubar);
6604 if (compose->privacy_system != NULL) {
6607 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6608 g_return_if_fail(menuitem != NULL);
6610 amenu = GTK_MENU_SHELL(menuitem)->children;
6612 while (amenu != NULL) {
6613 GList *alist = amenu->next;
6615 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6616 if (systemid != NULL) {
6617 if (strcmp(systemid, compose->privacy_system) == 0) {
6618 menuitem = GTK_WIDGET(amenu->data);
6620 can_sign = privacy_system_can_sign(systemid);
6621 can_encrypt = privacy_system_can_encrypt(systemid);
6625 } else if (strlen(compose->privacy_system) == 0) {
6626 menuitem = GTK_WIDGET(amenu->data);
6629 can_encrypt = FALSE;
6636 if (menuitem != NULL)
6637 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6639 if (warn && !found && strlen(compose->privacy_system)) {
6640 gchar *tmp = g_strdup_printf(
6641 _("The privacy system '%s' cannot be loaded. You "
6642 "will not be able to sign or encrypt this message."),
6643 compose->privacy_system);
6644 alertpanel_warning(tmp);
6649 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6650 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6653 static void compose_set_out_encoding(Compose *compose)
6655 GtkItemFactoryEntry *entry;
6656 GtkItemFactory *ifactory;
6657 CharSet out_encoding;
6658 gchar *path, *p, *q;
6661 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6662 ifactory = gtk_item_factory_from_widget(compose->menubar);
6664 for (entry = compose_entries; entry->callback != compose_address_cb;
6666 if (entry->callback == compose_set_encoding_cb &&
6667 (CharSet)entry->callback_action == out_encoding) {
6668 p = q = path = g_strdup(entry->path);
6680 item = gtk_item_factory_get_item(ifactory, path);
6681 gtk_widget_activate(item);
6688 static void compose_set_template_menu(Compose *compose)
6690 GSList *tmpl_list, *cur;
6694 tmpl_list = template_get_config();
6696 menu = gtk_menu_new();
6698 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6699 Template *tmpl = (Template *)cur->data;
6701 item = gtk_menu_item_new_with_label(tmpl->name);
6702 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6703 g_signal_connect(G_OBJECT(item), "activate",
6704 G_CALLBACK(compose_template_activate_cb),
6706 g_object_set_data(G_OBJECT(item), "template", tmpl);
6707 gtk_widget_show(item);
6710 gtk_widget_show(menu);
6711 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6714 void compose_update_actions_menu(Compose *compose)
6716 GtkItemFactory *ifactory;
6718 ifactory = gtk_item_factory_from_widget(compose->menubar);
6719 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6722 void compose_update_privacy_systems_menu(Compose *compose)
6724 static gchar *branch_path = "/Options/Privacy System";
6725 GtkItemFactory *ifactory;
6726 GtkWidget *menuitem;
6727 GSList *systems, *cur;
6730 GtkWidget *system_none;
6733 ifactory = gtk_item_factory_from_widget(compose->menubar);
6735 /* remove old entries */
6736 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6737 g_return_if_fail(menuitem != NULL);
6739 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6740 while (amenu != NULL) {
6741 GList *alist = amenu->next;
6742 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6746 system_none = gtk_item_factory_get_widget(ifactory,
6747 "/Options/Privacy System/None");
6749 g_signal_connect(G_OBJECT(system_none), "activate",
6750 G_CALLBACK(compose_set_privacy_system_cb), compose);
6752 systems = privacy_get_system_ids();
6753 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6754 gchar *systemid = cur->data;
6756 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6757 widget = gtk_radio_menu_item_new_with_label(group,
6758 privacy_system_get_name(systemid));
6759 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6760 g_strdup(systemid), g_free);
6761 g_signal_connect(G_OBJECT(widget), "activate",
6762 G_CALLBACK(compose_set_privacy_system_cb), compose);
6764 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6765 gtk_widget_show(widget);
6768 g_slist_free(systems);
6771 void compose_reflect_prefs_all(void)
6776 for (cur = compose_list; cur != NULL; cur = cur->next) {
6777 compose = (Compose *)cur->data;
6778 compose_set_template_menu(compose);
6782 void compose_reflect_prefs_pixmap_theme(void)
6787 for (cur = compose_list; cur != NULL; cur = cur->next) {
6788 compose = (Compose *)cur->data;
6789 toolbar_update(TOOLBAR_COMPOSE, compose);
6793 static void compose_template_apply(Compose *compose, Template *tmpl,
6797 GtkTextBuffer *buffer;
6801 gchar *parsed_str = NULL;
6802 gint cursor_pos = 0;
6803 const gchar *err_msg = _("Template body format error.");
6806 /* process the body */
6808 text = GTK_TEXT_VIEW(compose->text);
6809 buffer = gtk_text_view_get_buffer(text);
6812 if (prefs_common.quotemark && *prefs_common.quotemark)
6813 qmark = prefs_common.quotemark;
6817 if (compose->replyinfo != NULL) {
6820 gtk_text_buffer_set_text(buffer, "", -1);
6821 mark = gtk_text_buffer_get_insert(buffer);
6822 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6824 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6825 tmpl->value, qmark, NULL, FALSE, err_msg);
6827 } else if (compose->fwdinfo != NULL) {
6830 gtk_text_buffer_set_text(buffer, "", -1);
6831 mark = gtk_text_buffer_get_insert(buffer);
6832 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6834 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6835 tmpl->value, qmark, NULL, FALSE, err_msg);
6838 MsgInfo* dummyinfo = compose_msginfo_new_from_compose(compose);
6840 GtkTextIter start, end;
6843 gtk_text_buffer_get_start_iter(buffer, &start);
6844 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
6845 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
6847 /* clear the buffer now */
6849 gtk_text_buffer_set_text(buffer, "", -1);
6851 parsed_str = compose_quote_fmt(compose, dummyinfo,
6852 tmpl->value, qmark, tmp, FALSE, err_msg);
6853 procmsg_msginfo_free( dummyinfo );
6859 gtk_text_buffer_set_text(buffer, "", -1);
6860 mark = gtk_text_buffer_get_insert(buffer);
6861 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6864 if (replace && parsed_str && compose->account->auto_sig)
6865 compose_insert_sig(compose, FALSE);
6867 if (replace && parsed_str) {
6868 gtk_text_buffer_get_start_iter(buffer, &iter);
6869 gtk_text_buffer_place_cursor(buffer, &iter);
6873 cursor_pos = quote_fmt_get_cursor_pos();
6874 compose->set_cursor_pos = cursor_pos;
6875 if (cursor_pos == -1)
6877 gtk_text_buffer_get_start_iter(buffer, &iter);
6878 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6879 gtk_text_buffer_place_cursor(buffer, &iter);
6882 /* process the other fields */
6884 compose_template_apply_fields(compose, tmpl);
6885 quote_fmt_reset_vartable();
6886 compose_changed_cb(NULL, compose);
6889 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6891 MsgInfo* dummyinfo = NULL;
6892 MsgInfo *msginfo = NULL;
6895 if (compose->replyinfo != NULL)
6896 msginfo = compose->replyinfo;
6897 else if (compose->fwdinfo != NULL)
6898 msginfo = compose->fwdinfo;
6900 dummyinfo = compose_msginfo_new_from_compose(compose);
6901 msginfo = dummyinfo;
6904 if (tmpl->to && *tmpl->to != '\0') {
6905 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6906 quote_fmt_scan_string(tmpl->to);
6909 buf = quote_fmt_get_buffer();
6911 alertpanel_error(_("Message To format error."));
6913 compose_entry_append(compose, buf, COMPOSE_TO);
6917 if (tmpl->cc && *tmpl->cc != '\0') {
6918 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6919 quote_fmt_scan_string(tmpl->cc);
6922 buf = quote_fmt_get_buffer();
6924 alertpanel_error(_("Message Cc format error."));
6926 compose_entry_append(compose, buf, COMPOSE_CC);
6930 if (tmpl->bcc && *tmpl->bcc != '\0') {
6931 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6932 quote_fmt_scan_string(tmpl->bcc);
6935 buf = quote_fmt_get_buffer();
6937 alertpanel_error(_("Message Bcc format error."));
6939 compose_entry_append(compose, buf, COMPOSE_BCC);
6943 /* process the subject */
6944 if (tmpl->subject && *tmpl->subject != '\0') {
6945 quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
6946 quote_fmt_scan_string(tmpl->subject);
6949 buf = quote_fmt_get_buffer();
6951 alertpanel_error(_("Message subject format error."));
6953 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6957 procmsg_msginfo_free( dummyinfo );
6960 static void compose_destroy(Compose *compose)
6962 GtkTextBuffer *buffer;
6963 GtkClipboard *clipboard;
6965 compose_list = g_list_remove(compose_list, compose);
6967 if (compose->updating) {
6968 debug_print("danger, not destroying anything now\n");
6969 compose->deferred_destroy = TRUE;
6972 /* NOTE: address_completion_end() does nothing with the window
6973 * however this may change. */
6974 address_completion_end(compose->window);
6976 slist_free_strings(compose->to_list);
6977 g_slist_free(compose->to_list);
6978 slist_free_strings(compose->newsgroup_list);
6979 g_slist_free(compose->newsgroup_list);
6980 slist_free_strings(compose->header_list);
6981 g_slist_free(compose->header_list);
6983 procmsg_msginfo_free(compose->targetinfo);
6984 procmsg_msginfo_free(compose->replyinfo);
6985 procmsg_msginfo_free(compose->fwdinfo);
6987 g_free(compose->replyto);
6988 g_free(compose->cc);
6989 g_free(compose->bcc);
6990 g_free(compose->newsgroups);
6991 g_free(compose->followup_to);
6993 g_free(compose->ml_post);
6995 g_free(compose->inreplyto);
6996 g_free(compose->references);
6997 g_free(compose->msgid);
6998 g_free(compose->boundary);
7000 g_free(compose->redirect_filename);
7001 if (compose->undostruct)
7002 undo_destroy(compose->undostruct);
7004 g_free(compose->sig_str);
7006 g_free(compose->exteditor_file);
7008 g_free(compose->orig_charset);
7010 g_free(compose->privacy_system);
7012 if (addressbook_get_target_compose() == compose)
7013 addressbook_set_target_compose(NULL);
7016 if (compose->gtkaspell) {
7017 gtkaspell_delete(compose->gtkaspell);
7018 compose->gtkaspell = NULL;
7022 prefs_common.compose_width = compose->scrolledwin->allocation.width;
7023 prefs_common.compose_height = compose->window->allocation.height;
7025 if (!gtk_widget_get_parent(compose->paned))
7026 gtk_widget_destroy(compose->paned);
7027 gtk_widget_destroy(compose->popupmenu);
7029 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
7030 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
7031 gtk_text_buffer_remove_selection_clipboard(buffer, clipboard);
7033 gtk_widget_destroy(compose->window);
7034 toolbar_destroy(compose->toolbar);
7035 g_free(compose->toolbar);
7036 g_mutex_free(compose->mutex);
7040 static void compose_attach_info_free(AttachInfo *ainfo)
7042 g_free(ainfo->file);
7043 g_free(ainfo->content_type);
7044 g_free(ainfo->name);
7048 static void compose_attach_remove_selected(Compose *compose)
7050 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
7051 GtkTreeSelection *selection;
7053 GtkTreeModel *model;
7055 selection = gtk_tree_view_get_selection(tree_view);
7056 sel = gtk_tree_selection_get_selected_rows(selection, &model);
7061 for (cur = sel; cur != NULL; cur = cur->next) {
7062 GtkTreePath *path = cur->data;
7063 GtkTreeRowReference *ref = gtk_tree_row_reference_new
7066 gtk_tree_path_free(path);
7069 for (cur = sel; cur != NULL; cur = cur->next) {
7070 GtkTreeRowReference *ref = cur->data;
7071 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
7074 if (gtk_tree_model_get_iter(model, &iter, path))
7075 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
7077 gtk_tree_path_free(path);
7078 gtk_tree_row_reference_free(ref);
7084 static struct _AttachProperty
7087 GtkWidget *mimetype_entry;
7088 GtkWidget *encoding_optmenu;
7089 GtkWidget *path_entry;
7090 GtkWidget *filename_entry;
7092 GtkWidget *cancel_btn;
7095 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
7097 gtk_tree_path_free((GtkTreePath *)ptr);
7100 static void compose_attach_property(Compose *compose)
7102 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
7104 GtkComboBox *optmenu;
7105 GtkTreeSelection *selection;
7107 GtkTreeModel *model;
7110 static gboolean cancelled;
7112 /* only if one selected */
7113 selection = gtk_tree_view_get_selection(tree_view);
7114 if (gtk_tree_selection_count_selected_rows(selection) != 1)
7117 sel = gtk_tree_selection_get_selected_rows(selection, &model);
7121 path = (GtkTreePath *) sel->data;
7122 gtk_tree_model_get_iter(model, &iter, path);
7123 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
7126 g_list_foreach(sel, gtk_tree_path_free_, NULL);
7132 if (!attach_prop.window)
7133 compose_attach_property_create(&cancelled);
7134 gtk_widget_grab_focus(attach_prop.ok_btn);
7135 gtk_widget_show(attach_prop.window);
7136 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
7138 optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
7139 if (ainfo->encoding == ENC_UNKNOWN)
7140 combobox_select_by_data(optmenu, ENC_BASE64);
7142 combobox_select_by_data(optmenu, ainfo->encoding);
7144 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
7145 ainfo->content_type ? ainfo->content_type : "");
7146 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
7147 ainfo->file ? ainfo->file : "");
7148 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
7149 ainfo->name ? ainfo->name : "");
7152 const gchar *entry_text;
7154 gchar *cnttype = NULL;
7161 gtk_widget_hide(attach_prop.window);
7166 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
7167 if (*entry_text != '\0') {
7170 text = g_strstrip(g_strdup(entry_text));
7171 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
7172 cnttype = g_strdup(text);
7175 alertpanel_error(_("Invalid MIME type."));
7181 ainfo->encoding = combobox_get_active_data(optmenu);
7183 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
7184 if (*entry_text != '\0') {
7185 if (is_file_exist(entry_text) &&
7186 (size = get_file_size(entry_text)) > 0)
7187 file = g_strdup(entry_text);
7190 (_("File doesn't exist or is empty."));
7196 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
7197 if (*entry_text != '\0') {
7198 g_free(ainfo->name);
7199 ainfo->name = g_strdup(entry_text);
7203 g_free(ainfo->content_type);
7204 ainfo->content_type = cnttype;
7207 g_free(ainfo->file);
7213 /* update tree store */
7214 text = to_human_readable(ainfo->size);
7215 gtk_tree_model_get_iter(model, &iter, path);
7216 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
7217 COL_MIMETYPE, ainfo->content_type,
7219 COL_NAME, ainfo->name,
7225 gtk_tree_path_free(path);
7228 #define SET_LABEL_AND_ENTRY(str, entry, top) \
7230 label = gtk_label_new(str); \
7231 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
7232 GTK_FILL, 0, 0, 0); \
7233 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
7235 entry = gtk_entry_new(); \
7236 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
7237 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
7240 static void compose_attach_property_create(gboolean *cancelled)
7246 GtkWidget *mimetype_entry;
7249 GtkListStore *optmenu_menu;
7250 GtkWidget *path_entry;
7251 GtkWidget *filename_entry;
7254 GtkWidget *cancel_btn;
7255 GList *mime_type_list, *strlist;
7258 debug_print("Creating attach_property window...\n");
7260 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
7261 gtk_widget_set_size_request(window, 480, -1);
7262 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
7263 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
7264 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
7265 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
7266 g_signal_connect(G_OBJECT(window), "delete_event",
7267 G_CALLBACK(attach_property_delete_event),
7269 g_signal_connect(G_OBJECT(window), "key_press_event",
7270 G_CALLBACK(attach_property_key_pressed),
7273 vbox = gtk_vbox_new(FALSE, 8);
7274 gtk_container_add(GTK_CONTAINER(window), vbox);
7276 table = gtk_table_new(4, 2, FALSE);
7277 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
7278 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
7279 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
7281 label = gtk_label_new(_("MIME type"));
7282 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
7284 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7285 mimetype_entry = gtk_combo_new();
7286 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
7287 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7289 /* stuff with list */
7290 mime_type_list = procmime_get_mime_type_list();
7292 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
7293 MimeType *type = (MimeType *) mime_type_list->data;
7296 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
7298 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
7301 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
7302 (GCompareFunc)strcmp2);
7305 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
7307 for (mime_type_list = strlist; mime_type_list != NULL;
7308 mime_type_list = mime_type_list->next)
7309 g_free(mime_type_list->data);
7310 g_list_free(strlist);
7312 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
7314 label = gtk_label_new(_("Encoding"));
7315 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
7317 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
7319 hbox = gtk_hbox_new(FALSE, 0);
7320 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
7321 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
7323 optmenu = gtkut_sc_combobox_create(NULL, TRUE);
7324 optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
7326 COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
7327 COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
7328 COMBOBOX_ADD(optmenu_menu, "quoted-printable", ENC_QUOTED_PRINTABLE);
7329 COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
7330 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
7332 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
7334 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
7335 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
7337 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
7338 &ok_btn, GTK_STOCK_OK,
7340 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
7341 gtk_widget_grab_default(ok_btn);
7343 g_signal_connect(G_OBJECT(ok_btn), "clicked",
7344 G_CALLBACK(attach_property_ok),
7346 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
7347 G_CALLBACK(attach_property_cancel),
7350 gtk_widget_show_all(vbox);
7352 attach_prop.window = window;
7353 attach_prop.mimetype_entry = mimetype_entry;
7354 attach_prop.encoding_optmenu = optmenu;
7355 attach_prop.path_entry = path_entry;
7356 attach_prop.filename_entry = filename_entry;
7357 attach_prop.ok_btn = ok_btn;
7358 attach_prop.cancel_btn = cancel_btn;
7361 #undef SET_LABEL_AND_ENTRY
7363 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7369 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7375 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7376 gboolean *cancelled)
7384 static gboolean attach_property_key_pressed(GtkWidget *widget,
7386 gboolean *cancelled)
7388 if (event && event->keyval == GDK_Escape) {
7395 static void compose_exec_ext_editor(Compose *compose)
7402 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7403 G_DIR_SEPARATOR, compose);
7405 if (pipe(pipe_fds) < 0) {
7411 if ((pid = fork()) < 0) {
7418 /* close the write side of the pipe */
7421 compose->exteditor_file = g_strdup(tmp);
7422 compose->exteditor_pid = pid;
7424 compose_set_ext_editor_sensitive(compose, FALSE);
7426 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7427 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7431 } else { /* process-monitoring process */
7437 /* close the read side of the pipe */
7440 if (compose_write_body_to_file(compose, tmp) < 0) {
7441 fd_write_all(pipe_fds[1], "2\n", 2);
7445 pid_ed = compose_exec_ext_editor_real(tmp);
7447 fd_write_all(pipe_fds[1], "1\n", 2);
7451 /* wait until editor is terminated */
7452 waitpid(pid_ed, NULL, 0);
7454 fd_write_all(pipe_fds[1], "0\n", 2);
7461 #endif /* G_OS_UNIX */
7465 static gint compose_exec_ext_editor_real(const gchar *file)
7472 g_return_val_if_fail(file != NULL, -1);
7474 if ((pid = fork()) < 0) {
7479 if (pid != 0) return pid;
7481 /* grandchild process */
7483 if (setpgid(0, getppid()))
7486 if (prefs_common.ext_editor_cmd &&
7487 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7488 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7489 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7491 if (prefs_common.ext_editor_cmd)
7492 g_warning("External editor command line is invalid: '%s'\n",
7493 prefs_common.ext_editor_cmd);
7494 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7497 cmdline = strsplit_with_quote(buf, " ", 1024);
7498 execvp(cmdline[0], cmdline);
7501 g_strfreev(cmdline);
7506 static gboolean compose_ext_editor_kill(Compose *compose)
7508 pid_t pgid = compose->exteditor_pid * -1;
7511 ret = kill(pgid, 0);
7513 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7517 msg = g_strdup_printf
7518 (_("The external editor is still working.\n"
7519 "Force terminating the process?\n"
7520 "process group id: %d"), -pgid);
7521 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7522 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7526 if (val == G_ALERTALTERNATE) {
7527 g_source_remove(compose->exteditor_tag);
7528 g_io_channel_shutdown(compose->exteditor_ch,
7530 g_io_channel_unref(compose->exteditor_ch);
7532 if (kill(pgid, SIGTERM) < 0) perror("kill");
7533 waitpid(compose->exteditor_pid, NULL, 0);
7535 g_warning("Terminated process group id: %d", -pgid);
7536 g_warning("Temporary file: %s",
7537 compose->exteditor_file);
7539 compose_set_ext_editor_sensitive(compose, TRUE);
7541 g_free(compose->exteditor_file);
7542 compose->exteditor_file = NULL;
7543 compose->exteditor_pid = -1;
7544 compose->exteditor_ch = NULL;
7545 compose->exteditor_tag = -1;
7553 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7557 Compose *compose = (Compose *)data;
7560 debug_print(_("Compose: input from monitoring process\n"));
7562 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7564 g_io_channel_shutdown(source, FALSE, NULL);
7565 g_io_channel_unref(source);
7567 waitpid(compose->exteditor_pid, NULL, 0);
7569 if (buf[0] == '0') { /* success */
7570 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7571 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7573 gtk_text_buffer_set_text(buffer, "", -1);
7574 compose_insert_file(compose, compose->exteditor_file);
7575 compose_changed_cb(NULL, compose);
7577 if (g_unlink(compose->exteditor_file) < 0)
7578 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7579 } else if (buf[0] == '1') { /* failed */
7580 g_warning("Couldn't exec external editor\n");
7581 if (g_unlink(compose->exteditor_file) < 0)
7582 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7583 } else if (buf[0] == '2') {
7584 g_warning("Couldn't write to file\n");
7585 } else if (buf[0] == '3') {
7586 g_warning("Pipe read failed\n");
7589 compose_set_ext_editor_sensitive(compose, TRUE);
7591 g_free(compose->exteditor_file);
7592 compose->exteditor_file = NULL;
7593 compose->exteditor_pid = -1;
7594 compose->exteditor_ch = NULL;
7595 compose->exteditor_tag = -1;
7600 static void compose_set_ext_editor_sensitive(Compose *compose,
7603 GtkItemFactory *ifactory;
7605 ifactory = gtk_item_factory_from_widget(compose->menubar);
7607 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7608 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7609 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7610 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7611 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7612 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7613 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7616 gtk_widget_set_sensitive(compose->text, sensitive);
7617 if (compose->toolbar->send_btn)
7618 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7619 if (compose->toolbar->sendl_btn)
7620 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7621 if (compose->toolbar->draft_btn)
7622 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7623 if (compose->toolbar->insert_btn)
7624 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7625 if (compose->toolbar->sig_btn)
7626 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7627 if (compose->toolbar->exteditor_btn)
7628 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7629 if (compose->toolbar->linewrap_current_btn)
7630 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7631 if (compose->toolbar->linewrap_all_btn)
7632 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7634 #endif /* G_OS_UNIX */
7637 * compose_undo_state_changed:
7639 * Change the sensivity of the menuentries undo and redo
7641 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7642 gint redo_state, gpointer data)
7644 GtkWidget *widget = GTK_WIDGET(data);
7645 GtkItemFactory *ifactory;
7647 g_return_if_fail(widget != NULL);
7649 ifactory = gtk_item_factory_from_widget(widget);
7651 switch (undo_state) {
7652 case UNDO_STATE_TRUE:
7653 if (!undostruct->undo_state) {
7654 undostruct->undo_state = TRUE;
7655 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7658 case UNDO_STATE_FALSE:
7659 if (undostruct->undo_state) {
7660 undostruct->undo_state = FALSE;
7661 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7664 case UNDO_STATE_UNCHANGED:
7666 case UNDO_STATE_REFRESH:
7667 menu_set_sensitive(ifactory, "/Edit/Undo",
7668 undostruct->undo_state);
7671 g_warning("Undo state not recognized");
7675 switch (redo_state) {
7676 case UNDO_STATE_TRUE:
7677 if (!undostruct->redo_state) {
7678 undostruct->redo_state = TRUE;
7679 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7682 case UNDO_STATE_FALSE:
7683 if (undostruct->redo_state) {
7684 undostruct->redo_state = FALSE;
7685 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7688 case UNDO_STATE_UNCHANGED:
7690 case UNDO_STATE_REFRESH:
7691 menu_set_sensitive(ifactory, "/Edit/Redo",
7692 undostruct->redo_state);
7695 g_warning("Redo state not recognized");
7700 /* callback functions */
7702 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7703 * includes "non-client" (windows-izm) in calculation, so this calculation
7704 * may not be accurate.
7706 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7707 GtkAllocation *allocation,
7708 GtkSHRuler *shruler)
7710 if (prefs_common.show_ruler) {
7711 gint char_width = 0, char_height = 0;
7712 gint line_width_in_chars;
7714 gtkut_get_font_size(GTK_WIDGET(widget),
7715 &char_width, &char_height);
7716 line_width_in_chars =
7717 (allocation->width - allocation->x) / char_width;
7719 /* got the maximum */
7720 gtk_ruler_set_range(GTK_RULER(shruler),
7721 0.0, line_width_in_chars, 0,
7722 /*line_width_in_chars*/ char_width);
7728 static void account_activated(GtkComboBox *optmenu, gpointer data)
7730 Compose *compose = (Compose *)data;
7733 gchar *folderidentifier;
7734 gint account_id = 0;
7738 /* Get ID of active account in the combo box */
7739 menu = gtk_combo_box_get_model(optmenu);
7740 gtk_combo_box_get_active_iter(optmenu, &iter);
7741 gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
7743 ac = account_find_from_id(account_id);
7744 g_return_if_fail(ac != NULL);
7746 if (ac != compose->account)
7747 compose_select_account(compose, ac, FALSE);
7749 /* Set message save folder */
7750 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7751 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7753 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7754 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7756 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7757 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7758 folderidentifier = folder_item_get_identifier(account_get_special_folder
7759 (compose->account, F_OUTBOX));
7760 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7761 g_free(folderidentifier);
7765 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7766 GtkTreeViewColumn *column, Compose *compose)
7768 compose_attach_property(compose);
7771 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7774 Compose *compose = (Compose *)data;
7775 GtkTreeSelection *attach_selection;
7776 gint attach_nr_selected;
7777 GtkItemFactory *ifactory;
7779 if (!event) return FALSE;
7781 if (event->button == 3) {
7782 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7783 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7784 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7786 if (attach_nr_selected > 0)
7788 menu_set_sensitive(ifactory, "/Remove", TRUE);
7789 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7791 menu_set_sensitive(ifactory, "/Remove", FALSE);
7792 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7795 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7796 NULL, NULL, event->button, event->time);
7803 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7806 Compose *compose = (Compose *)data;
7808 if (!event) return FALSE;
7810 switch (event->keyval) {
7812 compose_attach_remove_selected(compose);
7818 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7820 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7821 toolbar_comp_set_sensitive(compose, allow);
7822 menu_set_sensitive(ifactory, "/Message", allow);
7823 menu_set_sensitive(ifactory, "/Edit", allow);
7825 menu_set_sensitive(ifactory, "/Spelling", allow);
7827 menu_set_sensitive(ifactory, "/Options", allow);
7828 menu_set_sensitive(ifactory, "/Tools", allow);
7829 menu_set_sensitive(ifactory, "/Help", allow);
7831 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7835 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7837 Compose *compose = (Compose *)data;
7839 if (prefs_common.work_offline &&
7840 !inc_offline_should_override(
7841 _("Claws Mail needs network access in order "
7842 "to send this email.")))
7845 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7846 gtk_timeout_remove(compose->draft_timeout_tag);
7847 compose->draft_timeout_tag = -1;
7850 compose_send(compose);
7853 static void compose_send_later_cb(gpointer data, guint action,
7856 Compose *compose = (Compose *)data;
7860 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
7864 compose_close(compose);
7865 } else if (val == -1) {
7866 alertpanel_error(_("Could not queue message."));
7867 } else if (val == -2) {
7868 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7869 } else if (val == -3) {
7870 if (privacy_peek_error())
7871 alertpanel_error(_("Could not queue message for sending:\n\n"
7872 "Signature failed: %s"), privacy_get_error());
7873 } else if (val == -4) {
7874 alertpanel_error(_("Could not queue message for sending:\n\n"
7875 "Charset conversion failed."));
7876 } else if (val == -5) {
7877 alertpanel_error(_("Could not queue message for sending:\n\n"
7878 "Couldn't get recipient encryption key."));
7880 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
7883 void compose_draft (gpointer data)
7885 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7888 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7890 Compose *compose = (Compose *)data;
7894 MsgFlags flag = {0, 0};
7895 static gboolean lock = FALSE;
7896 MsgInfo *newmsginfo;
7898 gboolean target_locked = FALSE;
7902 draft = account_get_special_folder(compose->account, F_DRAFT);
7903 g_return_if_fail(draft != NULL);
7905 if (!g_mutex_trylock(compose->mutex)) {
7906 /* we don't want to lock the mutex once it's available,
7907 * because as the only other part of compose.c locking
7908 * it is compose_close - which means once unlocked,
7909 * the compose struct will be freed */
7910 debug_print("couldn't lock mutex, probably sending\n");
7916 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7917 G_DIR_SEPARATOR, compose);
7918 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7919 FILE_OP_ERROR(tmp, "fopen");
7923 /* chmod for security */
7924 if (change_file_mode_rw(fp, tmp) < 0) {
7925 FILE_OP_ERROR(tmp, "chmod");
7926 g_warning("can't change file mode\n");
7929 /* Save draft infos */
7930 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7931 fprintf(fp, "S:%s\n", compose->account->address);
7933 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7934 gchar *savefolderid;
7936 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7937 fprintf(fp, "SCF:%s\n", savefolderid);
7938 g_free(savefolderid);
7940 if (compose->return_receipt) {
7941 fprintf(fp, "RRCPT:1\n");
7943 if (compose->privacy_system) {
7944 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7945 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7946 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7949 /* Message-ID of message replying to */
7950 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
7953 folderid = folder_item_get_identifier(compose->replyinfo->folder);
7954 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
7957 /* Message-ID of message forwarding to */
7958 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
7961 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
7962 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
7966 /* end of headers */
7967 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
7969 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
7977 if (compose->targetinfo) {
7978 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7979 flag.perm_flags = target_locked?MSG_LOCKED:0;
7981 flag.tmp_flags = MSG_DRAFT;
7983 folder_item_scan(draft);
7984 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7987 if (action != COMPOSE_AUTO_SAVE)
7988 alertpanel_error(_("Could not save draft."));
7993 if (compose->mode == COMPOSE_REEDIT) {
7994 compose_remove_reedit_target(compose, TRUE);
7997 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7999 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
8001 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
8003 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
8004 if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
8005 procmsg_msginfo_set_flags(newmsginfo, 0,
8006 MSG_HAS_ATTACHMENT);
8008 procmsg_msginfo_free(newmsginfo);
8011 folder_item_scan(draft);
8013 if (action == COMPOSE_QUIT_EDITING) {
8015 g_mutex_unlock(compose->mutex); /* must be done before closing */
8016 compose_close(compose);
8022 path = folder_item_fetch_msg(draft, msgnum);
8024 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
8027 if (g_stat(path, &s) < 0) {
8028 FILE_OP_ERROR(path, "stat");
8034 procmsg_msginfo_free(compose->targetinfo);
8035 compose->targetinfo = procmsg_msginfo_new();
8036 compose->targetinfo->msgnum = msgnum;
8037 compose->targetinfo->size = s.st_size;
8038 compose->targetinfo->mtime = s.st_mtime;
8039 compose->targetinfo->folder = draft;
8041 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
8042 compose->mode = COMPOSE_REEDIT;
8044 if (action == COMPOSE_AUTO_SAVE) {
8045 compose->autosaved_draft = compose->targetinfo;
8047 compose->modified = FALSE;
8048 compose_set_title(compose);
8052 g_mutex_unlock(compose->mutex);
8055 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
8057 Compose *compose = (Compose *)data;
8060 if (compose->redirect_filename != NULL)
8063 file_list = filesel_select_multiple_files_open(_("Select file"));
8068 for ( tmp = file_list; tmp; tmp = tmp->next) {
8069 gchar *file = (gchar *) tmp->data;
8070 gchar *utf8_filename = conv_filename_to_utf8(file);
8071 compose_attach_append(compose, file, utf8_filename, NULL);
8072 compose_changed_cb(NULL, compose);
8074 g_free(utf8_filename);
8076 g_list_free(file_list);
8080 static void compose_insert_file_cb(gpointer data, guint action,
8083 Compose *compose = (Compose *)data;
8086 file_list = filesel_select_multiple_files_open(_("Select file"));
8091 for ( tmp = file_list; tmp; tmp = tmp->next) {
8092 gchar *file = (gchar *) tmp->data;
8093 gchar *filedup = g_strdup(file);
8094 gchar *shortfile = g_path_get_basename(filedup);
8095 ComposeInsertResult res;
8097 res = compose_insert_file(compose, file);
8098 if (res == COMPOSE_INSERT_READ_ERROR) {
8099 alertpanel_error(_("File '%s' could not be read."), shortfile);
8100 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
8101 alertpanel_error(_("File '%s' contained invalid characters\n"
8102 "for the current encoding, insertion may be incorrect."), shortfile);
8108 g_list_free(file_list);
8112 static void compose_insert_sig_cb(gpointer data, guint action,
8115 Compose *compose = (Compose *)data;
8117 compose_insert_sig(compose, FALSE);
8120 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
8124 Compose *compose = (Compose *)data;
8126 gtkut_widget_get_uposition(widget, &x, &y);
8127 prefs_common.compose_x = x;
8128 prefs_common.compose_y = y;
8130 if (compose->sending || compose->updating)
8132 compose_close_cb(compose, 0, NULL);
8136 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
8138 Compose *compose = (Compose *)data;
8142 if (compose->exteditor_tag != -1) {
8143 if (!compose_ext_editor_kill(compose))
8148 if (compose->modified) {
8149 val = alertpanel(_("Discard message"),
8150 _("This message has been modified. Discard it?"),
8151 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
8154 case G_ALERTDEFAULT:
8155 if (prefs_common.autosave)
8156 compose_remove_draft(compose);
8158 case G_ALERTALTERNATE:
8159 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
8166 compose_close(compose);
8169 static void compose_set_encoding_cb(gpointer data, guint action,
8172 Compose *compose = (Compose *)data;
8174 if (GTK_CHECK_MENU_ITEM(widget)->active)
8175 compose->out_encoding = (CharSet)action;
8178 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
8180 Compose *compose = (Compose *)data;
8182 addressbook_open(compose);
8185 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
8187 Compose *compose = (Compose *)data;
8192 tmpl = g_object_get_data(G_OBJECT(widget), "template");
8193 g_return_if_fail(tmpl != NULL);
8195 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
8197 val = alertpanel(_("Apply template"), msg,
8198 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
8201 if (val == G_ALERTDEFAULT)
8202 compose_template_apply(compose, tmpl, TRUE);
8203 else if (val == G_ALERTALTERNATE)
8204 compose_template_apply(compose, tmpl, FALSE);
8207 static void compose_ext_editor_cb(gpointer data, guint action,
8210 Compose *compose = (Compose *)data;
8212 compose_exec_ext_editor(compose);
8215 static void compose_undo_cb(Compose *compose)
8217 gboolean prev_autowrap = compose->autowrap;
8219 compose->autowrap = FALSE;
8220 undo_undo(compose->undostruct);
8221 compose->autowrap = prev_autowrap;
8224 static void compose_redo_cb(Compose *compose)
8226 gboolean prev_autowrap = compose->autowrap;
8228 compose->autowrap = FALSE;
8229 undo_redo(compose->undostruct);
8230 compose->autowrap = prev_autowrap;
8233 static void entry_cut_clipboard(GtkWidget *entry)
8235 if (GTK_IS_EDITABLE(entry))
8236 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
8237 else if (GTK_IS_TEXT_VIEW(entry))
8238 gtk_text_buffer_cut_clipboard(
8239 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
8240 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
8244 static void entry_copy_clipboard(GtkWidget *entry)
8246 if (GTK_IS_EDITABLE(entry))
8247 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
8248 else if (GTK_IS_TEXT_VIEW(entry))
8249 gtk_text_buffer_copy_clipboard(
8250 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
8251 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
8254 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
8255 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
8257 if (GTK_IS_TEXT_VIEW(entry)) {
8258 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
8259 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
8260 GtkTextIter start_iter, end_iter;
8262 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
8264 if (contents == NULL)
8267 undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);
8269 /* we shouldn't delete the selection when middle-click-pasting, or we
8270 * can't mid-click-paste our own selection */
8271 if (clip != GDK_SELECTION_PRIMARY) {
8272 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
8275 if (insert_place == NULL) {
8276 /* if insert_place isn't specified, insert at the cursor.
8277 * used for Ctrl-V pasting */
8278 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
8279 start = gtk_text_iter_get_offset(&start_iter);
8280 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
8282 /* if insert_place is specified, paste here.
8283 * used for mid-click-pasting */
8284 start = gtk_text_iter_get_offset(insert_place);
8285 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
8289 /* paste unwrapped: mark the paste so it's not wrapped later */
8290 end = start + strlen(contents);
8291 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
8292 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
8293 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
8294 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
8295 /* rewrap paragraph now (after a mid-click-paste) */
8296 mark_start = gtk_text_buffer_get_insert(buffer);
8297 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
8298 gtk_text_iter_backward_char(&start_iter);
8299 compose_beautify_paragraph(compose, &start_iter, TRUE);
8301 } else if (GTK_IS_EDITABLE(entry))
8302 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
8306 static void entry_allsel(GtkWidget *entry)
8308 if (GTK_IS_EDITABLE(entry))
8309 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
8310 else if (GTK_IS_TEXT_VIEW(entry)) {
8311 GtkTextIter startiter, enditer;
8312 GtkTextBuffer *textbuf;
8314 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
8315 gtk_text_buffer_get_start_iter(textbuf, &startiter);
8316 gtk_text_buffer_get_end_iter(textbuf, &enditer);
8318 gtk_text_buffer_move_mark_by_name(textbuf,
8319 "selection_bound", &startiter);
8320 gtk_text_buffer_move_mark_by_name(textbuf,
8321 "insert", &enditer);
8325 static void compose_cut_cb(Compose *compose)
8327 if (compose->focused_editable &&
8328 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8329 entry_cut_clipboard(compose->focused_editable);
8332 static void compose_copy_cb(Compose *compose)
8334 if (compose->focused_editable &&
8335 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8336 entry_copy_clipboard(compose->focused_editable);
8339 static void compose_paste_cb(Compose *compose)
8342 GtkTextBuffer *buffer;
8344 if (compose->focused_editable &&
8345 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8346 entry_paste_clipboard(compose, compose->focused_editable,
8347 prefs_common.linewrap_pastes,
8348 GDK_SELECTION_CLIPBOARD, NULL);
8352 static void compose_paste_as_quote_cb(Compose *compose)
8354 gint wrap_quote = prefs_common.linewrap_quote;
8355 if (compose->focused_editable &&
8356 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
8357 /* let text_insert() (called directly or at a later time
8358 * after the gtk_editable_paste_clipboard) know that
8359 * text is to be inserted as a quotation. implemented
8360 * by using a simple refcount... */
8361 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
8362 G_OBJECT(compose->focused_editable),
8363 "paste_as_quotation"));
8364 g_object_set_data(G_OBJECT(compose->focused_editable),
8365 "paste_as_quotation",
8366 GINT_TO_POINTER(paste_as_quotation + 1));
8367 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
8368 entry_paste_clipboard(compose, compose->focused_editable,
8369 prefs_common.linewrap_pastes,
8370 GDK_SELECTION_CLIPBOARD, NULL);
8371 prefs_common.linewrap_quote = wrap_quote;
8375 static void compose_paste_no_wrap_cb(Compose *compose)
8378 GtkTextBuffer *buffer;
8380 if (compose->focused_editable &&
8381 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8382 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
8383 GDK_SELECTION_CLIPBOARD, NULL);
8387 static void compose_paste_wrap_cb(Compose *compose)
8390 GtkTextBuffer *buffer;
8392 if (compose->focused_editable &&
8393 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8394 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
8395 GDK_SELECTION_CLIPBOARD, NULL);
8399 static void compose_allsel_cb(Compose *compose)
8401 if (compose->focused_editable &&
8402 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8403 entry_allsel(compose->focused_editable);
8406 static void textview_move_beginning_of_line (GtkTextView *text)
8408 GtkTextBuffer *buffer;
8412 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8414 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8415 mark = gtk_text_buffer_get_insert(buffer);
8416 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8417 gtk_text_iter_set_line_offset(&ins, 0);
8418 gtk_text_buffer_place_cursor(buffer, &ins);
8421 static void textview_move_forward_character (GtkTextView *text)
8423 GtkTextBuffer *buffer;
8427 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8429 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8430 mark = gtk_text_buffer_get_insert(buffer);
8431 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8432 if (gtk_text_iter_forward_cursor_position(&ins))
8433 gtk_text_buffer_place_cursor(buffer, &ins);
8436 static void textview_move_backward_character (GtkTextView *text)
8438 GtkTextBuffer *buffer;
8442 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8444 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8445 mark = gtk_text_buffer_get_insert(buffer);
8446 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8447 if (gtk_text_iter_backward_cursor_position(&ins))
8448 gtk_text_buffer_place_cursor(buffer, &ins);
8451 static void textview_move_forward_word (GtkTextView *text)
8453 GtkTextBuffer *buffer;
8458 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8460 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8461 mark = gtk_text_buffer_get_insert(buffer);
8462 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8463 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8464 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8465 gtk_text_iter_backward_word_start(&ins);
8466 gtk_text_buffer_place_cursor(buffer, &ins);
8470 static void textview_move_backward_word (GtkTextView *text)
8472 GtkTextBuffer *buffer;
8477 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8479 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8480 mark = gtk_text_buffer_get_insert(buffer);
8481 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8482 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8483 if (gtk_text_iter_backward_word_starts(&ins, 1))
8484 gtk_text_buffer_place_cursor(buffer, &ins);
8487 static void textview_move_end_of_line (GtkTextView *text)
8489 GtkTextBuffer *buffer;
8493 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8495 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8496 mark = gtk_text_buffer_get_insert(buffer);
8497 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8498 if (gtk_text_iter_forward_to_line_end(&ins))
8499 gtk_text_buffer_place_cursor(buffer, &ins);
8502 static void textview_move_next_line (GtkTextView *text)
8504 GtkTextBuffer *buffer;
8509 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8511 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8512 mark = gtk_text_buffer_get_insert(buffer);
8513 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8514 offset = gtk_text_iter_get_line_offset(&ins);
8515 if (gtk_text_iter_forward_line(&ins)) {
8516 gtk_text_iter_set_line_offset(&ins, offset);
8517 gtk_text_buffer_place_cursor(buffer, &ins);
8521 static void textview_move_previous_line (GtkTextView *text)
8523 GtkTextBuffer *buffer;
8528 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8530 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8531 mark = gtk_text_buffer_get_insert(buffer);
8532 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8533 offset = gtk_text_iter_get_line_offset(&ins);
8534 if (gtk_text_iter_backward_line(&ins)) {
8535 gtk_text_iter_set_line_offset(&ins, offset);
8536 gtk_text_buffer_place_cursor(buffer, &ins);
8540 static void textview_delete_forward_character (GtkTextView *text)
8542 GtkTextBuffer *buffer;
8544 GtkTextIter ins, end_iter;
8546 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8548 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8549 mark = gtk_text_buffer_get_insert(buffer);
8550 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8552 if (gtk_text_iter_forward_char(&end_iter)) {
8553 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8557 static void textview_delete_backward_character (GtkTextView *text)
8559 GtkTextBuffer *buffer;
8561 GtkTextIter ins, end_iter;
8563 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8565 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8566 mark = gtk_text_buffer_get_insert(buffer);
8567 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8569 if (gtk_text_iter_backward_char(&end_iter)) {
8570 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8574 static void textview_delete_forward_word (GtkTextView *text)
8576 GtkTextBuffer *buffer;
8578 GtkTextIter ins, end_iter;
8580 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8582 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8583 mark = gtk_text_buffer_get_insert(buffer);
8584 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8586 if (gtk_text_iter_forward_word_end(&end_iter)) {
8587 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8591 static void textview_delete_backward_word (GtkTextView *text)
8593 GtkTextBuffer *buffer;
8595 GtkTextIter ins, end_iter;
8597 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8599 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8600 mark = gtk_text_buffer_get_insert(buffer);
8601 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8603 if (gtk_text_iter_backward_word_start(&end_iter)) {
8604 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8608 static void textview_delete_line (GtkTextView *text)
8610 GtkTextBuffer *buffer;
8612 GtkTextIter ins, start_iter, end_iter;
8615 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8617 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8618 mark = gtk_text_buffer_get_insert(buffer);
8619 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8622 gtk_text_iter_set_line_offset(&start_iter, 0);
8625 if (gtk_text_iter_ends_line(&end_iter))
8626 found = gtk_text_iter_forward_char(&end_iter);
8628 found = gtk_text_iter_forward_to_line_end(&end_iter);
8631 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8634 static void textview_delete_to_line_end (GtkTextView *text)
8636 GtkTextBuffer *buffer;
8638 GtkTextIter ins, end_iter;
8641 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8643 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8644 mark = gtk_text_buffer_get_insert(buffer);
8645 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8647 if (gtk_text_iter_ends_line(&end_iter))
8648 found = gtk_text_iter_forward_char(&end_iter);
8650 found = gtk_text_iter_forward_to_line_end(&end_iter);
8652 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8655 static void compose_advanced_action_cb(Compose *compose,
8656 ComposeCallAdvancedAction action)
8658 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8660 void (*do_action) (GtkTextView *text);
8661 } action_table[] = {
8662 {textview_move_beginning_of_line},
8663 {textview_move_forward_character},
8664 {textview_move_backward_character},
8665 {textview_move_forward_word},
8666 {textview_move_backward_word},
8667 {textview_move_end_of_line},
8668 {textview_move_next_line},
8669 {textview_move_previous_line},
8670 {textview_delete_forward_character},
8671 {textview_delete_backward_character},
8672 {textview_delete_forward_word},
8673 {textview_delete_backward_word},
8674 {textview_delete_line},
8675 {NULL}, /* gtk_stext_delete_line_n */
8676 {textview_delete_to_line_end}
8679 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8681 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8682 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8683 if (action_table[action].do_action)
8684 action_table[action].do_action(text);
8686 g_warning("Not implemented yet.");
8690 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8694 if (GTK_IS_EDITABLE(widget)) {
8695 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8696 gtk_editable_set_position(GTK_EDITABLE(widget),
8699 if (widget->parent && widget->parent->parent
8700 && widget->parent->parent->parent) {
8701 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8702 gint y = widget->allocation.y;
8703 gint height = widget->allocation.height;
8704 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8705 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8707 if (y < (int)shown->value) {
8708 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8710 if (y + height > (int)shown->value + (int)shown->page_size) {
8711 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8712 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8713 y + height - (int)shown->page_size - 1);
8715 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8716 (int)shown->upper - (int)shown->page_size - 1);
8723 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8724 compose->focused_editable = widget;
8727 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8729 compose->modified = TRUE;
8730 compose_set_title(compose);
8733 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8735 Compose *compose = (Compose *)data;
8738 compose_wrap_all_full(compose, TRUE);
8740 compose_beautify_paragraph(compose, NULL, TRUE);
8743 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8745 Compose *compose = (Compose *)data;
8747 message_search_compose(compose);
8750 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8753 Compose *compose = (Compose *)data;
8754 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8755 if (compose->autowrap)
8756 compose_wrap_all_full(compose, TRUE);
8757 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8760 static void compose_toggle_sign_cb(gpointer data, guint action,
8763 Compose *compose = (Compose *)data;
8765 if (GTK_CHECK_MENU_ITEM(widget)->active)
8766 compose->use_signing = TRUE;
8768 compose->use_signing = FALSE;
8771 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8774 Compose *compose = (Compose *)data;
8776 if (GTK_CHECK_MENU_ITEM(widget)->active)
8777 compose->use_encryption = TRUE;
8779 compose->use_encryption = FALSE;
8782 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8784 g_free(compose->privacy_system);
8786 compose->privacy_system = g_strdup(account->default_privacy_system);
8787 compose_update_privacy_system_menu_item(compose, warn);
8790 static void compose_toggle_ruler_cb(gpointer data, guint action,
8793 Compose *compose = (Compose *)data;
8795 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8796 gtk_widget_show(compose->ruler_hbox);
8797 prefs_common.show_ruler = TRUE;
8799 gtk_widget_hide(compose->ruler_hbox);
8800 gtk_widget_queue_resize(compose->edit_vbox);
8801 prefs_common.show_ruler = FALSE;
8805 static void compose_attach_drag_received_cb (GtkWidget *widget,
8806 GdkDragContext *context,
8809 GtkSelectionData *data,
8814 Compose *compose = (Compose *)user_data;
8817 if (gdk_atom_name(data->type) &&
8818 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8819 && gtk_drag_get_source_widget(context) !=
8820 summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
8821 list = uri_list_extract_filenames((const gchar *)data->data);
8822 for (tmp = list; tmp != NULL; tmp = tmp->next)
8823 compose_attach_append
8824 (compose, (const gchar *)tmp->data,
8825 (const gchar *)tmp->data, NULL);
8826 if (list) compose_changed_cb(NULL, compose);
8827 list_free_strings(list);
8829 } else if (gtk_drag_get_source_widget(context)
8830 == summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
8831 /* comes from our summaryview */
8832 SummaryView * summaryview = NULL;
8833 GSList * list = NULL, *cur = NULL;
8835 if (mainwindow_get_mainwindow())
8836 summaryview = mainwindow_get_mainwindow()->summaryview;
8839 list = summary_get_selected_msg_list(summaryview);
8841 for (cur = list; cur; cur = cur->next) {
8842 MsgInfo *msginfo = (MsgInfo *)cur->data;
8845 file = procmsg_get_message_file_full(msginfo,
8848 compose_attach_append(compose, (const gchar *)file,
8849 (const gchar *)file, "message/rfc822");
8857 static gboolean compose_drag_drop(GtkWidget *widget,
8858 GdkDragContext *drag_context,
8860 guint time, gpointer user_data)
8862 /* not handling this signal makes compose_insert_drag_received_cb
8867 static void compose_insert_drag_received_cb (GtkWidget *widget,
8868 GdkDragContext *drag_context,
8871 GtkSelectionData *data,
8876 Compose *compose = (Compose *)user_data;
8879 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8881 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8882 AlertValue val = G_ALERTDEFAULT;
8884 switch (prefs_common.compose_dnd_mode) {
8885 case COMPOSE_DND_ASK:
8886 val = alertpanel_full(_("Insert or attach?"),
8887 _("Do you want to insert the contents of the file(s) "
8888 "into the message body, or attach it to the email?"),
8889 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
8890 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
8892 case COMPOSE_DND_INSERT:
8893 val = G_ALERTALTERNATE;
8895 case COMPOSE_DND_ATTACH:
8899 /* unexpected case */
8900 g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
8903 if (val & G_ALERTDISABLE) {
8904 val &= ~G_ALERTDISABLE;
8905 /* remember what action to perform by default, only if we don't click Cancel */
8906 if (val == G_ALERTALTERNATE)
8907 prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
8908 else if (val == G_ALERTOTHER)
8909 prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
8912 if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
8913 gtk_drag_finish(drag_context, FALSE, FALSE, time);
8915 } else if (val == G_ALERTOTHER) {
8916 compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
8919 list = uri_list_extract_filenames((const gchar *)data->data);
8920 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8921 compose_insert_file(compose, (const gchar *)tmp->data);
8923 list_free_strings(list);
8925 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8928 #if GTK_CHECK_VERSION(2, 8, 0)
8929 /* do nothing, handled by GTK */
8931 gchar *tmpfile = get_tmp_file();
8932 str_write_to_file((const gchar *)data->data, tmpfile);
8933 compose_insert_file(compose, tmpfile);
8936 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8940 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8943 static void compose_header_drag_received_cb (GtkWidget *widget,
8944 GdkDragContext *drag_context,
8947 GtkSelectionData *data,
8952 GtkEditable *entry = (GtkEditable *)user_data;
8953 gchar *email = (gchar *)data->data;
8955 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8958 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8959 gchar *decoded=g_new(gchar, strlen(email));
8962 email += strlen("mailto:");
8963 decode_uri(decoded, email); /* will fit */
8964 gtk_editable_delete_text(entry, 0, -1);
8965 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8966 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8970 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8973 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8976 Compose *compose = (Compose *)data;
8978 if (GTK_CHECK_MENU_ITEM(widget)->active)
8979 compose->return_receipt = TRUE;
8981 compose->return_receipt = FALSE;
8984 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8987 Compose *compose = (Compose *)data;
8989 if (GTK_CHECK_MENU_ITEM(widget)->active)
8990 compose->remove_references = TRUE;
8992 compose->remove_references = FALSE;
8995 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8997 ComposeHeaderEntry *headerentry)
8999 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
9000 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
9001 !(event->state & GDK_MODIFIER_MASK) &&
9002 (event->keyval == GDK_BackSpace) &&
9003 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
9004 gtk_container_remove
9005 (GTK_CONTAINER(headerentry->compose->header_table),
9006 headerentry->combo);
9007 gtk_container_remove
9008 (GTK_CONTAINER(headerentry->compose->header_table),
9009 headerentry->entry);
9010 headerentry->compose->header_list =
9011 g_slist_remove(headerentry->compose->header_list,
9013 g_free(headerentry);
9014 } else if (event->keyval == GDK_Tab) {
9015 if (headerentry->compose->header_last == headerentry) {
9016 /* Override default next focus, and give it to subject_entry
9017 * instead of notebook tabs
9019 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
9020 gtk_widget_grab_focus(headerentry->compose->subject_entry);
9027 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
9028 ComposeHeaderEntry *headerentry)
9030 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
9031 headerentry->compose->header_list =
9032 g_slist_append(headerentry->compose->header_list,
9035 compose_create_header_entry(headerentry->compose);
9036 g_signal_handlers_disconnect_matched
9037 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
9038 0, 0, NULL, NULL, headerentry);
9040 /* Automatically scroll down */
9041 compose_show_first_last_header(headerentry->compose, FALSE);
9047 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
9049 GtkAdjustment *vadj;
9051 g_return_if_fail(compose);
9052 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
9053 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
9055 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
9056 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
9059 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
9060 const gchar *text, gint len, Compose *compose)
9062 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
9063 (G_OBJECT(compose->text), "paste_as_quotation"));
9066 g_return_if_fail(text != NULL);
9068 g_signal_handlers_block_by_func(G_OBJECT(buffer),
9069 G_CALLBACK(text_inserted),
9071 if (paste_as_quotation) {
9078 new_text = g_strndup(text, len);
9079 if (prefs_common.quotemark && *prefs_common.quotemark)
9080 qmark = prefs_common.quotemark;
9084 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
9085 gtk_text_buffer_place_cursor(buffer, iter);
9087 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE,
9088 _("Quote format error."));
9089 quote_fmt_reset_vartable();
9091 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
9092 GINT_TO_POINTER(paste_as_quotation - 1));
9094 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
9095 gtk_text_buffer_place_cursor(buffer, iter);
9097 if (strcmp(text, "\n") || automatic_break
9098 || gtk_text_iter_starts_line(iter))
9099 gtk_text_buffer_insert(buffer, iter, text, len);
9101 debug_print("insert nowrap \\n\n");
9102 gtk_text_buffer_insert_with_tags_by_name(buffer,
9103 iter, text, len, "no_join", NULL);
9107 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
9109 compose_beautify_paragraph(compose, iter, FALSE);
9111 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
9112 gtk_text_buffer_delete_mark(buffer, mark);
9114 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
9115 G_CALLBACK(text_inserted),
9117 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
9119 if (prefs_common.autosave &&
9120 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
9121 compose->draft_timeout_tag = gtk_timeout_add
9122 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
9124 static gint compose_defer_auto_save_draft(Compose *compose)
9126 compose->draft_timeout_tag = -1;
9127 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
9132 static void compose_check_all(Compose *compose)
9134 if (compose->gtkaspell)
9135 gtkaspell_check_all(compose->gtkaspell);
9138 static void compose_highlight_all(Compose *compose)
9140 if (compose->gtkaspell)
9141 gtkaspell_highlight_all(compose->gtkaspell);
9144 static void compose_check_backwards(Compose *compose)
9146 if (compose->gtkaspell)
9147 gtkaspell_check_backwards(compose->gtkaspell);
9149 GtkItemFactory *ifactory;
9150 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
9151 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
9152 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
9156 static void compose_check_forwards_go(Compose *compose)
9158 if (compose->gtkaspell)
9159 gtkaspell_check_forwards_go(compose->gtkaspell);
9161 GtkItemFactory *ifactory;
9162 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
9163 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
9164 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
9170 *\brief Guess originating forward account from MsgInfo and several
9171 * "common preference" settings. Return NULL if no guess.
9173 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
9175 PrefsAccount *account = NULL;
9177 g_return_val_if_fail(msginfo, NULL);
9178 g_return_val_if_fail(msginfo->folder, NULL);
9179 g_return_val_if_fail(msginfo->folder->prefs, NULL);
9181 if (msginfo->folder->prefs->enable_default_account)
9182 account = account_find_from_id(msginfo->folder->prefs->default_account);
9185 account = msginfo->folder->folder->account;
9187 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
9189 Xstrdup_a(to, msginfo->to, return NULL);
9190 extract_address(to);
9191 account = account_find_from_address(to);
9194 if (!account && prefs_common.forward_account_autosel) {
9196 if (!procheader_get_header_from_msginfo
9197 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
9198 extract_address(cc);
9199 account = account_find_from_address(cc);
9206 gboolean compose_close(Compose *compose)
9210 if (!g_mutex_trylock(compose->mutex)) {
9211 /* we have to wait for the (possibly deferred by auto-save)
9212 * drafting to be done, before destroying the compose under
9214 debug_print("waiting for drafting to finish...\n");
9215 g_timeout_add (500, (GSourceFunc) compose_close, compose);
9218 g_return_val_if_fail(compose, FALSE);
9219 gtkut_widget_get_uposition(compose->window, &x, &y);
9220 prefs_common.compose_x = x;
9221 prefs_common.compose_y = y;
9222 g_mutex_unlock(compose->mutex);
9223 compose_destroy(compose);
9228 * Add entry field for each address in list.
9229 * \param compose E-Mail composition object.
9230 * \param listAddress List of (formatted) E-Mail addresses.
9232 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
9237 addr = ( gchar * ) node->data;
9238 compose_entry_append( compose, addr, COMPOSE_TO );
9239 node = g_list_next( node );
9243 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
9244 guint action, gboolean opening_multiple)
9247 GSList *new_msglist = NULL;
9248 MsgInfo *tmp_msginfo = NULL;
9249 gboolean originally_enc = FALSE;
9250 Compose *compose = NULL;
9252 g_return_if_fail(msgview != NULL);
9254 g_return_if_fail(msginfo_list != NULL);
9256 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
9257 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
9258 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
9260 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
9261 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
9262 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
9263 orig_msginfo, mimeinfo);
9264 if (tmp_msginfo != NULL) {
9265 new_msglist = g_slist_append(NULL, tmp_msginfo);
9266 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
9267 originally_enc = TRUE;
9273 if (!opening_multiple)
9274 body = messageview_get_selection(msgview);
9277 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
9278 procmsg_msginfo_free(tmp_msginfo);
9279 g_slist_free(new_msglist);
9281 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
9283 if (originally_enc) {
9284 compose_force_encryption(compose, compose->account, FALSE);
9290 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
9293 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
9294 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
9295 GSList *cur = msginfo_list;
9296 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
9297 "messages. Opening the windows "
9298 "could take some time. Do you "
9299 "want to continue?"),
9300 g_slist_length(msginfo_list));
9301 if (g_slist_length(msginfo_list) > 9
9302 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
9303 != G_ALERTALTERNATE) {
9308 /* We'll open multiple compose windows */
9309 /* let the WM place the next windows */
9310 compose_force_window_origin = FALSE;
9311 for (; cur; cur = cur->next) {
9313 tmplist.data = cur->data;
9314 tmplist.next = NULL;
9315 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
9317 compose_force_window_origin = TRUE;
9319 /* forwarding multiple mails as attachments is done via a
9320 * single compose window */
9321 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
9325 void compose_set_position(Compose *compose, gint pos)
9327 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9329 gtkut_text_view_set_position(text, pos);
9332 gboolean compose_search_string(Compose *compose,
9333 const gchar *str, gboolean case_sens)
9335 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9337 return gtkut_text_view_search_string(text, str, case_sens);
9340 gboolean compose_search_string_backward(Compose *compose,
9341 const gchar *str, gboolean case_sens)
9343 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
9345 return gtkut_text_view_search_string_backward(text, str, case_sens);
9348 /* allocate a msginfo structure and populate its data from a compose data structure */
9349 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
9351 MsgInfo *newmsginfo;
9353 gchar buf[BUFFSIZE];
9355 g_return_val_if_fail( compose != NULL, NULL );
9357 newmsginfo = procmsg_msginfo_new();
9360 get_rfc822_date(buf, sizeof(buf));
9361 newmsginfo->date = g_strdup(buf);
9364 if (compose->from_name) {
9365 newmsginfo->from = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
9366 newmsginfo->fromname = procheader_get_fromname(newmsginfo->from);
9370 if (compose->subject_entry)
9371 newmsginfo->subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
9373 /* to, cc, reply-to, newsgroups */
9374 for (list = compose->header_list; list; list = list->next) {
9375 gchar *header = gtk_editable_get_chars(
9377 GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
9378 gchar *entry = gtk_editable_get_chars(
9379 GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
9381 if ( strcasecmp(header, (prefs_common.trans_hdr ? gettext("To:") : "To:")) == 0 ) {
9382 if ( newmsginfo->to == NULL ) {
9383 newmsginfo->to = g_strdup(entry);
9385 gchar *tmp = g_strconcat(newmsginfo->to, ", ", entry, NULL);
9386 g_free(newmsginfo->to);
9387 newmsginfo->to = tmp;
9390 if ( strcasecmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:")) == 0 ) {
9391 if ( newmsginfo->cc == NULL ) {
9392 newmsginfo->cc = g_strdup(entry);
9394 gchar *tmp = g_strconcat(newmsginfo->cc, ", ", entry, NULL);
9395 g_free(newmsginfo->cc);
9396 newmsginfo->cc = tmp;
9399 if ( strcasecmp(header,
9400 (prefs_common.trans_hdr ? gettext("Newsgroups:") : "Newsgroups:")) == 0 ) {
9401 if ( newmsginfo->newsgroups == NULL ) {
9402 newmsginfo->newsgroups = g_strdup(entry);
9404 gchar *tmp = g_strconcat(newmsginfo->newsgroups, ", ", entry, NULL);
9405 g_free(newmsginfo->newsgroups);
9406 newmsginfo->newsgroups = tmp;
9414 /* other data is unset */