2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
77 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
84 #include "mainwindow.h"
86 #include "addressbook.h"
87 #include "folderview.h"
90 #include "stock_pixmap.h"
91 #include "send_message.h"
94 #include "customheader.h"
95 #include "prefs_common.h"
96 #include "prefs_account.h"
100 #include "procheader.h"
101 #include "procmime.h"
102 #include "statusbar.h"
105 #include "quoted-printable.h"
106 #include "codeconv.h"
108 #include "gtkutils.h"
110 #include "alertpanel.h"
111 #include "manage_window.h"
112 #include "gtkshruler.h"
114 #include "addr_compl.h"
115 #include "quote_fmt.h"
116 #include "template.h"
118 #include "foldersel.h"
131 #define N_ATTACH_COLS (N_COL_COLUMNS)
135 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
136 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
143 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
144 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
150 } ComposeCallAdvancedAction;
154 PRIORITY_HIGHEST = 1,
163 COMPOSE_INSERT_SUCCESS,
164 COMPOSE_INSERT_READ_ERROR,
165 COMPOSE_INSERT_INVALID_CHARACTER,
166 COMPOSE_INSERT_NO_FILE
167 } ComposeInsertResult;
171 COMPOSE_QUIT_EDITING,
172 COMPOSE_KEEP_EDITING,
174 } ComposeDraftAction;
178 COMPOSE_WRITE_FOR_SEND,
179 COMPOSE_WRITE_FOR_STORE
182 #define B64_LINE_SIZE 57
183 #define B64_BUFFSIZE 77
185 #define MAX_REFERENCES_LEN 999
187 static GList *compose_list = NULL;
189 Compose *compose_generic_new (PrefsAccount *account,
192 GPtrArray *attach_files,
193 GList *listAddress );
195 static Compose *compose_create (PrefsAccount *account,
198 static GtkWidget *compose_account_option_menu_create
200 static void compose_set_out_encoding (Compose *compose);
201 static void compose_set_template_menu (Compose *compose);
202 static void compose_template_apply (Compose *compose,
205 static void compose_destroy (Compose *compose);
207 static void compose_entries_set (Compose *compose,
208 const gchar *mailto);
209 static gint compose_parse_header (Compose *compose,
211 static gchar *compose_parse_references (const gchar *ref,
214 static gchar *compose_quote_fmt (Compose *compose,
220 static void compose_reply_set_entry (Compose *compose,
226 followup_and_reply_to);
227 static void compose_reedit_set_entry (Compose *compose,
230 static void compose_insert_sig (Compose *compose,
232 static gchar *compose_get_signature_str (Compose *compose);
233 static ComposeInsertResult compose_insert_file (Compose *compose,
236 static void compose_attach_append (Compose *compose,
239 const gchar *content_type);
240 static void compose_attach_parts (Compose *compose,
243 static void compose_beautify_paragraph (Compose *compose,
244 GtkTextIter *par_iter,
246 static void compose_wrap_all (Compose *compose);
247 static void compose_wrap_all_full (Compose *compose,
250 static void compose_set_title (Compose *compose);
251 static void compose_select_account (Compose *compose,
252 PrefsAccount *account,
255 static PrefsAccount *compose_current_mail_account(void);
256 /* static gint compose_send (Compose *compose); */
257 static gboolean compose_check_for_valid_recipient
259 static gboolean compose_check_entries (Compose *compose,
260 gboolean check_subject);
261 static gint compose_write_to_file (Compose *compose,
264 static gint compose_write_body_to_file (Compose *compose,
266 static gint compose_remove_reedit_target (Compose *compose);
267 void compose_remove_draft (Compose *compose);
268 static gint compose_queue (Compose *compose,
271 static gint compose_queue_sub (Compose *compose,
274 gboolean check_subject);
275 static void compose_add_attachments (Compose *compose,
277 static gchar *compose_get_header (Compose *compose);
279 static void compose_convert_header (Compose *compose,
284 gboolean addr_field);
286 static void compose_attach_info_free (AttachInfo *ainfo);
287 static void compose_attach_remove_selected (Compose *compose);
289 static void compose_attach_property (Compose *compose);
290 static void compose_attach_property_create (gboolean *cancelled);
291 static void attach_property_ok (GtkWidget *widget,
292 gboolean *cancelled);
293 static void attach_property_cancel (GtkWidget *widget,
294 gboolean *cancelled);
295 static gint attach_property_delete_event (GtkWidget *widget,
297 gboolean *cancelled);
298 static gboolean attach_property_key_pressed (GtkWidget *widget,
300 gboolean *cancelled);
302 static void compose_exec_ext_editor (Compose *compose);
304 static gint compose_exec_ext_editor_real (const gchar *file);
305 static gboolean compose_ext_editor_kill (Compose *compose);
306 static gboolean compose_input_cb (GIOChannel *source,
307 GIOCondition condition,
309 static void compose_set_ext_editor_sensitive (Compose *compose,
311 #endif /* G_OS_UNIX */
313 static void compose_undo_state_changed (UndoMain *undostruct,
318 static void compose_create_header_entry (Compose *compose);
319 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
320 static void compose_update_priority_menu_item(Compose * compose);
322 static void compose_add_field_list ( Compose *compose,
323 GList *listAddress );
325 /* callback functions */
327 static gboolean compose_edit_size_alloc (GtkEditable *widget,
328 GtkAllocation *allocation,
329 GtkSHRuler *shruler);
330 static void account_activated (GtkMenuItem *menuitem,
332 static void attach_selected (GtkTreeView *tree_view,
333 GtkTreePath *tree_path,
334 GtkTreeViewColumn *column,
336 static gboolean attach_button_pressed (GtkWidget *widget,
337 GdkEventButton *event,
339 static gboolean attach_key_pressed (GtkWidget *widget,
343 static void compose_send_cb (gpointer data,
346 static void compose_send_later_cb (gpointer data,
350 static void compose_draft_cb (gpointer data,
354 static void compose_attach_cb (gpointer data,
357 static void compose_insert_file_cb (gpointer data,
360 static void compose_insert_sig_cb (gpointer data,
364 static void compose_close_cb (gpointer data,
368 static void compose_set_encoding_cb (gpointer data,
372 static void compose_address_cb (gpointer data,
375 static void compose_template_activate_cb(GtkWidget *widget,
378 static void compose_ext_editor_cb (gpointer data,
382 static gint compose_delete_cb (GtkWidget *widget,
386 static void compose_undo_cb (Compose *compose);
387 static void compose_redo_cb (Compose *compose);
388 static void compose_cut_cb (Compose *compose);
389 static void compose_copy_cb (Compose *compose);
390 static void compose_paste_cb (Compose *compose);
391 static void compose_paste_as_quote_cb (Compose *compose);
392 static void compose_paste_no_wrap_cb (Compose *compose);
393 static void compose_paste_wrap_cb (Compose *compose);
394 static void compose_allsel_cb (Compose *compose);
396 static void compose_advanced_action_cb (Compose *compose,
397 ComposeCallAdvancedAction action);
399 static void compose_grab_focus_cb (GtkWidget *widget,
402 static void compose_changed_cb (GtkTextBuffer *textbuf,
405 static void compose_wrap_cb (gpointer data,
408 static void compose_toggle_autowrap_cb (gpointer data,
412 static void compose_toggle_ruler_cb (gpointer data,
415 static void compose_toggle_sign_cb (gpointer data,
418 static void compose_toggle_encrypt_cb (gpointer data,
421 static void compose_set_privacy_system_cb(GtkWidget *widget,
423 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
424 static void activate_privacy_system (Compose *compose,
425 PrefsAccount *account,
427 static void compose_use_signing(Compose *compose, gboolean use_signing);
428 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
429 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
431 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
433 static void compose_set_priority_cb (gpointer data,
437 static void compose_attach_drag_received_cb (GtkWidget *widget,
438 GdkDragContext *drag_context,
441 GtkSelectionData *data,
445 static void compose_insert_drag_received_cb (GtkWidget *widget,
446 GdkDragContext *drag_context,
449 GtkSelectionData *data,
453 static void compose_header_drag_received_cb (GtkWidget *widget,
454 GdkDragContext *drag_context,
457 GtkSelectionData *data,
462 static gboolean compose_drag_drop (GtkWidget *widget,
463 GdkDragContext *drag_context,
465 guint time, gpointer user_data);
467 static void text_inserted (GtkTextBuffer *buffer,
472 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
473 gboolean to_all, gboolean to_ml,
475 gboolean followup_and_reply_to,
478 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
479 ComposeHeaderEntry *headerentry);
480 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
482 ComposeHeaderEntry *headerentry);
484 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
486 static void compose_allow_user_actions (Compose *compose, gboolean allow);
489 static void compose_check_all (Compose *compose);
490 static void compose_highlight_all (Compose *compose);
491 static void compose_check_backwards (Compose *compose);
492 static void compose_check_forwards_go (Compose *compose);
495 static gint compose_defer_auto_save_draft (Compose *compose);
496 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
498 static gboolean compose_close (Compose *compose);
500 static GtkItemFactoryEntry compose_popup_entries[] =
502 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
503 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
504 {N_("/---"), NULL, NULL, 0, "<Separator>"},
505 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
508 static GtkItemFactoryEntry compose_entries[] =
510 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
511 {N_("/_Message/_Send"), "<control>Return",
512 compose_send_cb, 0, NULL},
513 {N_("/_Message/Send _later"), "<shift><control>S",
514 compose_send_later_cb, 0, NULL},
515 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
516 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
517 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
518 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
519 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Message/_Save"),
521 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
522 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
525 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
526 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
527 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
528 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
530 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
531 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
532 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
533 {N_("/_Edit/Special paste/as _quotation"),
534 NULL, compose_paste_as_quote_cb, 0, NULL},
535 {N_("/_Edit/Special paste/_wrapped"),
536 NULL, compose_paste_wrap_cb, 0, NULL},
537 {N_("/_Edit/Special paste/_unwrapped"),
538 NULL, compose_paste_no_wrap_cb, 0, NULL},
539 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
540 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/A_dvanced/Move a character backward"),
543 compose_advanced_action_cb,
544 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
546 {N_("/_Edit/A_dvanced/Move a character forward"),
548 compose_advanced_action_cb,
549 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
551 {N_("/_Edit/A_dvanced/Move a word backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
556 {N_("/_Edit/A_dvanced/Move a word forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
561 {N_("/_Edit/A_dvanced/Move to beginning of line"),
562 NULL, /* "<control>A" */
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
566 {N_("/_Edit/A_dvanced/Move to end of line"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
571 {N_("/_Edit/A_dvanced/Move to previous line"),
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
576 {N_("/_Edit/A_dvanced/Move to next line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
581 {N_("/_Edit/A_dvanced/Delete a character backward"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
586 {N_("/_Edit/A_dvanced/Delete a character forward"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
591 {N_("/_Edit/A_dvanced/Delete a word backward"),
592 NULL, /* "<control>W" */
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
596 {N_("/_Edit/A_dvanced/Delete a word forward"),
597 NULL, /* "<alt>D", */
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
601 {N_("/_Edit/A_dvanced/Delete line"),
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
606 {N_("/_Edit/A_dvanced/Delete entire line"),
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
611 {N_("/_Edit/A_dvanced/Delete to end of line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
616 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_Edit/_Wrap current paragraph"),
618 "<control>L", compose_wrap_cb, 0, NULL},
619 {N_("/_Edit/Wrap all long _lines"),
620 "<control><alt>L", compose_wrap_cb, 1, NULL},
621 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
622 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_Edit/Edit with e_xternal editor"),
624 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
626 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
627 {N_("/_Spelling/_Check all or check selection"),
628 NULL, compose_check_all, 0, NULL},
629 {N_("/_Spelling/_Highlight all misspelled words"),
630 NULL, compose_highlight_all, 0, NULL},
631 {N_("/_Spelling/Check _backwards misspelled word"),
632 NULL, compose_check_backwards , 0, NULL},
633 {N_("/_Spelling/_Forward to next misspelled word"),
634 NULL, compose_check_forwards_go, 0, NULL},
635 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Spelling/_Spelling Configuration"),
637 NULL, NULL, 0, "<Branch>"},
639 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
642 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
643 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
644 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
648 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
649 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
650 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
651 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
655 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
657 #define ENC_ACTION(action) \
658 NULL, compose_set_encoding_cb, action, \
659 "/Options/Character encoding/Automatic"
661 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
662 {N_("/_Options/Character _encoding/_Automatic"),
663 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
664 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
667 ENC_ACTION(C_US_ASCII)},
668 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
669 ENC_ACTION(C_UTF_8)},
670 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
672 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
673 ENC_ACTION(C_ISO_8859_1)},
674 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
675 ENC_ACTION(C_ISO_8859_15)},
676 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
678 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
679 ENC_ACTION(C_ISO_8859_2)},
680 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
682 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
683 ENC_ACTION(C_ISO_8859_13)},
684 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
685 ENC_ACTION(C_ISO_8859_4)},
686 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
688 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
689 ENC_ACTION(C_ISO_8859_7)},
690 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
692 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
693 ENC_ACTION(C_ISO_8859_8)},
694 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
695 ENC_ACTION(C_WINDOWS_1255)},
696 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
698 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
699 ENC_ACTION(C_ISO_8859_9)},
700 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
702 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
703 ENC_ACTION(C_ISO_8859_5)},
704 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
705 ENC_ACTION(C_KOI8_R)},
706 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
707 ENC_ACTION(C_KOI8_U)},
708 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
709 ENC_ACTION(C_WINDOWS_1251)},
710 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
712 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
713 ENC_ACTION(C_ISO_2022_JP)},
714 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
716 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
717 ENC_ACTION(C_GB2312)},
718 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
720 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
722 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
723 ENC_ACTION(C_EUC_TW)},
724 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
726 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
727 ENC_ACTION(C_EUC_KR)},
728 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
730 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
731 ENC_ACTION(C_TIS_620)},
732 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
733 ENC_ACTION(C_WINDOWS_874)},
735 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
736 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
737 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
738 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
739 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
740 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
741 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
744 static GtkTargetEntry compose_mime_types[] =
746 {"text/uri-list", 0, 0},
747 {"text/plain", 0, 0},
751 static gboolean compose_put_existing_to_front(MsgInfo *info)
753 GList *compose_list = compose_get_compose_list();
757 for (elem = compose_list; elem != NULL && elem->data != NULL;
759 Compose *c = (Compose*)elem->data;
761 if (!c->targetinfo || !c->targetinfo->msgid ||
765 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
766 gtkut_window_popup(c->window);
774 static GdkColor quote_color =
775 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
777 static GdkColor signature_color = {
784 static GdkColor uri_color = {
791 static void compose_create_tags(GtkTextView *text, Compose *compose)
793 GtkTextBuffer *buffer;
794 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
796 buffer = gtk_text_view_get_buffer(text);
798 if (prefs_common.enable_color) {
799 /* grab the quote colors, converting from an int to a GdkColor */
800 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
802 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
804 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
807 signature_color = quote_color = uri_color = black;
810 gtk_text_buffer_create_tag(buffer, "quote",
811 "foreground-gdk", "e_color,
813 gtk_text_buffer_create_tag(buffer, "signature",
814 "foreground-gdk", &signature_color,
816 gtk_text_buffer_create_tag(buffer, "link",
817 "foreground-gdk", &uri_color,
819 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
822 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
823 GPtrArray *attach_files)
825 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
828 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
830 return compose_generic_new(account, NULL, item, NULL, NULL);
833 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
835 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
838 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
839 GPtrArray *attach_files, GList *listAddress )
842 GtkTextView *textview;
843 GtkTextBuffer *textbuf;
845 GtkItemFactory *ifactory;
847 if (item && item->prefs && item->prefs->enable_default_account)
848 account = account_find_from_id(item->prefs->default_account);
850 if (!account) account = cur_account;
851 g_return_val_if_fail(account != NULL, NULL);
853 compose = compose_create(account, COMPOSE_NEW);
854 ifactory = gtk_item_factory_from_widget(compose->menubar);
856 compose->replyinfo = NULL;
857 compose->fwdinfo = NULL;
859 textview = GTK_TEXT_VIEW(compose->text);
860 textbuf = gtk_text_view_get_buffer(textview);
861 compose_create_tags(textview, compose);
863 undo_block(compose->undostruct);
865 if (item && item->prefs && item->prefs->enable_default_dictionary &&
867 gtkaspell_change_dict(compose->gtkaspell,
868 item->prefs->default_dictionary);
871 if (account->auto_sig)
872 compose_insert_sig(compose, FALSE);
873 gtk_text_buffer_get_start_iter(textbuf, &iter);
874 gtk_text_buffer_place_cursor(textbuf, &iter);
876 if (account->protocol != A_NNTP) {
877 if (mailto && *mailto != '\0') {
878 compose_entries_set(compose, mailto);
880 } else if (item && item->prefs->enable_default_to) {
881 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
882 compose_entry_mark_default_to(compose, item->prefs->default_to);
884 if (item && item->ret_rcpt) {
885 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
889 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
891 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
894 * CLAWS: just don't allow return receipt request, even if the user
895 * may want to send an email. simple but foolproof.
897 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
899 compose_add_field_list( compose, listAddress );
905 for (i = 0; i < attach_files->len; i++) {
906 file = g_ptr_array_index(attach_files, i);
907 compose_attach_append(compose, file, file, NULL);
911 compose_show_first_last_header(compose, TRUE);
913 /* Set save folder */
914 if (item && item->prefs && item->prefs->save_copy_to_folder) {
915 gchar *folderidentifier;
917 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
918 folderidentifier = folder_item_get_identifier(item);
919 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
920 g_free(folderidentifier);
923 gtk_widget_grab_focus(compose->header_last->entry);
925 undo_unblock(compose->undostruct);
927 if (prefs_common.auto_exteditor)
928 compose_exec_ext_editor(compose);
930 compose_set_title(compose);
934 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
935 gboolean override_pref)
937 gchar *privacy = NULL;
939 g_return_if_fail(compose != NULL);
940 g_return_if_fail(account != NULL);
942 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
945 if (account->default_privacy_system
946 && strlen(account->default_privacy_system)) {
947 privacy = account->default_privacy_system;
949 GSList *privacy_avail = privacy_get_system_ids();
950 if (privacy_avail && g_slist_length(privacy_avail)) {
951 privacy = (gchar *)(privacy_avail->data);
954 if (privacy != NULL) {
955 compose->privacy_system = g_strdup(privacy);
956 compose_update_privacy_system_menu_item(compose, FALSE);
957 compose_use_encryption(compose, TRUE);
961 static void compose_force_signing(Compose *compose, PrefsAccount *account)
963 gchar *privacy = NULL;
965 if (account->default_privacy_system
966 && strlen(account->default_privacy_system)) {
967 privacy = account->default_privacy_system;
969 GSList *privacy_avail = privacy_get_system_ids();
970 if (privacy_avail && g_slist_length(privacy_avail)) {
971 privacy = (gchar *)(privacy_avail->data);
974 if (privacy != NULL) {
975 compose->privacy_system = g_strdup(privacy);
976 compose_update_privacy_system_menu_item(compose, FALSE);
977 compose_use_signing(compose, TRUE);
981 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
985 Compose *compose = NULL;
986 g_return_val_if_fail(msginfo_list != NULL, NULL);
988 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
989 g_return_val_if_fail(msginfo != NULL, NULL);
991 list_len = g_slist_length(msginfo_list);
995 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
996 FALSE, prefs_common.default_reply_list, FALSE, body);
998 case COMPOSE_REPLY_WITH_QUOTE:
999 compose = compose_reply(msginfo, TRUE,
1000 FALSE, prefs_common.default_reply_list, FALSE, body);
1002 case COMPOSE_REPLY_WITHOUT_QUOTE:
1003 compose = compose_reply(msginfo, FALSE,
1004 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1006 case COMPOSE_REPLY_TO_SENDER:
1007 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1008 FALSE, FALSE, TRUE, body);
1010 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1011 compose = compose_followup_and_reply_to(msginfo,
1012 prefs_common.reply_with_quote,
1013 FALSE, FALSE, body);
1015 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1016 compose = compose_reply(msginfo, TRUE,
1017 FALSE, FALSE, TRUE, body);
1019 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1020 compose = compose_reply(msginfo, FALSE,
1021 FALSE, FALSE, TRUE, NULL);
1023 case COMPOSE_REPLY_TO_ALL:
1024 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1025 TRUE, FALSE, FALSE, body);
1027 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1028 compose = compose_reply(msginfo, TRUE,
1029 TRUE, FALSE, FALSE, body);
1031 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1032 compose = compose_reply(msginfo, FALSE,
1033 TRUE, FALSE, FALSE, NULL);
1035 case COMPOSE_REPLY_TO_LIST:
1036 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1037 FALSE, TRUE, FALSE, body);
1039 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1040 compose = compose_reply(msginfo, TRUE,
1041 FALSE, TRUE, FALSE, body);
1043 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1044 compose = compose_reply(msginfo, FALSE,
1045 FALSE, TRUE, FALSE, NULL);
1047 case COMPOSE_FORWARD:
1048 if (prefs_common.forward_as_attachment) {
1049 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1052 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1056 case COMPOSE_FORWARD_INLINE:
1057 /* check if we reply to more than one Message */
1058 if (list_len == 1) {
1059 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1062 /* more messages FALL THROUGH */
1063 case COMPOSE_FORWARD_AS_ATTACH:
1064 compose = compose_forward_multiple(NULL, msginfo_list);
1066 case COMPOSE_REDIRECT:
1067 compose = compose_redirect(NULL, msginfo);
1070 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1075 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1076 gboolean to_ml, gboolean to_sender,
1079 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1080 to_sender, FALSE, body);
1083 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1088 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1089 to_sender, TRUE, body);
1092 static void compose_extract_original_charset(Compose *compose)
1094 MsgInfo *info = NULL;
1095 if (compose->replyinfo) {
1096 info = compose->replyinfo;
1097 } else if (compose->fwdinfo) {
1098 info = compose->fwdinfo;
1099 } else if (compose->targetinfo) {
1100 info = compose->targetinfo;
1103 MimeInfo *mimeinfo = procmime_scan_message(info);
1104 MimeInfo *partinfo = mimeinfo;
1105 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1106 partinfo = procmime_mimeinfo_next(partinfo);
1108 compose->orig_charset =
1109 g_strdup(procmime_mimeinfo_get_parameter(
1110 partinfo, "charset"));
1112 procmime_mimeinfo_free_all(mimeinfo);
1116 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1117 gboolean to_all, gboolean to_ml,
1119 gboolean followup_and_reply_to,
1122 GtkItemFactory *ifactory;
1124 PrefsAccount *account = NULL;
1125 PrefsAccount *reply_account;
1126 GtkTextView *textview;
1127 GtkTextBuffer *textbuf;
1131 g_return_val_if_fail(msginfo != NULL, NULL);
1132 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1134 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1136 g_return_val_if_fail(account != NULL, NULL);
1138 if (to_sender && account->protocol == A_NNTP &&
1139 !followup_and_reply_to) {
1141 account_find_from_address(account->address);
1143 reply_account = compose_current_mail_account();
1147 reply_account = account;
1149 compose = compose_create(account, COMPOSE_REPLY);
1150 ifactory = gtk_item_factory_from_widget(compose->menubar);
1152 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1153 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1155 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1157 if (!compose->replyinfo)
1158 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1160 compose_extract_original_charset(compose);
1162 if (msginfo->folder && msginfo->folder->ret_rcpt)
1163 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1165 /* Set save folder */
1166 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1167 gchar *folderidentifier;
1169 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1170 folderidentifier = folder_item_get_identifier(msginfo->folder);
1171 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1172 g_free(folderidentifier);
1175 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1176 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1177 to_sender, followup_and_reply_to);
1178 compose_show_first_last_header(compose, TRUE);
1180 textview = (GTK_TEXT_VIEW(compose->text));
1181 textbuf = gtk_text_view_get_buffer(textview);
1182 compose_create_tags(textview, compose);
1184 undo_block(compose->undostruct);
1186 if (msginfo->folder && msginfo->folder->prefs &&
1187 msginfo->folder->prefs &&
1188 msginfo->folder->prefs->enable_default_dictionary &&
1190 gtkaspell_change_dict(compose->gtkaspell,
1191 msginfo->folder->prefs->default_dictionary);
1197 if (prefs_common.quotemark && *prefs_common.quotemark)
1198 qmark = prefs_common.quotemark;
1202 compose_quote_fmt(compose, compose->replyinfo,
1203 prefs_common.quotefmt,
1206 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1207 compose_force_encryption(compose, account, FALSE);
1210 if (account->auto_sig)
1211 compose_insert_sig(compose, FALSE);
1213 cursor_pos = quote_fmt_get_cursor_pos();
1214 gtk_text_buffer_get_start_iter(textbuf, &iter);
1215 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1216 gtk_text_buffer_place_cursor(textbuf, &iter);
1218 compose_wrap_all(compose);
1220 gtk_widget_grab_focus(compose->text);
1222 undo_unblock(compose->undostruct);
1224 if (prefs_common.auto_exteditor)
1225 compose_exec_ext_editor(compose);
1227 compose_set_title(compose);
1231 #define INSERT_FW_HEADER(var, hdr) \
1232 if (msginfo->var && *msginfo->var) { \
1233 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1234 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1235 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1238 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1239 gboolean as_attach, const gchar *body,
1240 gboolean no_extedit)
1243 GtkTextView *textview;
1244 GtkTextBuffer *textbuf;
1247 g_return_val_if_fail(msginfo != NULL, NULL);
1248 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1251 !(account = compose_guess_forward_account_from_msginfo
1253 account = cur_account;
1255 compose = compose_create(account, COMPOSE_FORWARD);
1257 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1258 if (!compose->fwdinfo)
1259 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1261 compose_extract_original_charset(compose);
1263 if (msginfo->subject && *msginfo->subject) {
1264 gchar *buf, *buf2, *p;
1266 buf = p = g_strdup(msginfo->subject);
1267 p += subject_get_prefix_length(p);
1268 memmove(buf, p, strlen(p) + 1);
1270 buf2 = g_strdup_printf("Fw: %s", buf);
1271 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1277 textview = GTK_TEXT_VIEW(compose->text);
1278 textbuf = gtk_text_view_get_buffer(textview);
1279 compose_create_tags(textview, compose);
1284 msgfile = procmsg_get_message_file_path(msginfo);
1285 if (!is_file_exist(msgfile))
1286 g_warning("%s: file not exist\n", msgfile);
1288 compose_attach_append(compose, msgfile, msgfile,
1294 MsgInfo *full_msginfo;
1296 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1298 full_msginfo = procmsg_msginfo_copy(msginfo);
1300 if (prefs_common.fw_quotemark &&
1301 *prefs_common.fw_quotemark)
1302 qmark = prefs_common.fw_quotemark;
1306 compose_quote_fmt(compose, full_msginfo,
1307 prefs_common.fw_quotefmt,
1309 compose_attach_parts(compose, msginfo);
1311 procmsg_msginfo_free(full_msginfo);
1314 if (account->auto_sig)
1315 compose_insert_sig(compose, FALSE);
1317 compose_wrap_all(compose);
1319 gtk_text_buffer_get_start_iter(textbuf, &iter);
1320 gtk_text_buffer_place_cursor(textbuf, &iter);
1322 gtk_widget_grab_focus(compose->header_last->entry);
1324 if (!no_extedit && prefs_common.auto_exteditor)
1325 compose_exec_ext_editor(compose);
1328 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1329 gchar *folderidentifier;
1331 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1332 folderidentifier = folder_item_get_identifier(msginfo->folder);
1333 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1334 g_free(folderidentifier);
1337 compose_set_title(compose);
1341 #undef INSERT_FW_HEADER
1343 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1346 GtkTextView *textview;
1347 GtkTextBuffer *textbuf;
1351 gboolean single_mail = TRUE;
1353 g_return_val_if_fail(msginfo_list != NULL, NULL);
1355 if (g_slist_length(msginfo_list) > 1)
1356 single_mail = FALSE;
1358 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1359 if (((MsgInfo *)msginfo->data)->folder == NULL)
1362 /* guess account from first selected message */
1364 !(account = compose_guess_forward_account_from_msginfo
1365 (msginfo_list->data)))
1366 account = cur_account;
1368 g_return_val_if_fail(account != NULL, NULL);
1370 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1371 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1372 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1375 compose = compose_create(account, COMPOSE_FORWARD);
1377 textview = GTK_TEXT_VIEW(compose->text);
1378 textbuf = gtk_text_view_get_buffer(textview);
1379 compose_create_tags(textview, compose);
1381 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1382 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1383 if (!is_file_exist(msgfile))
1384 g_warning("%s: file not exist\n", msgfile);
1386 compose_attach_append(compose, msgfile, msgfile,
1392 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1393 if (info->subject && *info->subject) {
1394 gchar *buf, *buf2, *p;
1396 buf = p = g_strdup(info->subject);
1397 p += subject_get_prefix_length(p);
1398 memmove(buf, p, strlen(p) + 1);
1400 buf2 = g_strdup_printf("Fw: %s", buf);
1401 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1407 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1408 _("Fw: multiple emails"));
1411 if (account->auto_sig)
1412 compose_insert_sig(compose, FALSE);
1414 compose_wrap_all(compose);
1416 gtk_text_buffer_get_start_iter(textbuf, &iter);
1417 gtk_text_buffer_place_cursor(textbuf, &iter);
1419 gtk_widget_grab_focus(compose->header_last->entry);
1421 compose_set_title(compose);
1425 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1427 GtkTextIter start = *iter;
1428 GtkTextIter end_iter;
1429 int start_pos = gtk_text_iter_get_offset(&start);
1431 if (!compose->account->sig_sep)
1434 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1435 start_pos+strlen(compose->account->sig_sep));
1437 /* check sig separator */
1438 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),
1439 compose->account->sig_sep)) {
1440 /* check end of line (\n) */
1441 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1442 start_pos+strlen(compose->account->sig_sep));
1443 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1444 start_pos+strlen(compose->account->sig_sep)+1);
1446 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),"\n"));
1455 static void compose_colorize_signature(Compose *compose)
1457 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1459 GtkTextIter end_iter;
1460 gtk_text_buffer_get_start_iter(buffer, &iter);
1461 while (gtk_text_iter_forward_line(&iter))
1462 if (compose_is_sig_separator(compose, buffer, &iter)) {
1463 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1464 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1468 void compose_reedit(MsgInfo *msginfo)
1470 Compose *compose = NULL;
1471 PrefsAccount *account = NULL;
1472 GtkTextView *textview;
1473 GtkTextBuffer *textbuf;
1477 gchar buf[BUFFSIZE];
1478 gboolean use_signing = FALSE;
1479 gboolean use_encryption = FALSE;
1480 gchar *privacy_system = NULL;
1482 g_return_if_fail(msginfo != NULL);
1483 g_return_if_fail(msginfo->folder != NULL);
1485 if (compose_put_existing_to_front(msginfo))
1488 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1489 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1490 gchar queueheader_buf[BUFFSIZE];
1493 /* Select Account from queue headers */
1494 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1495 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1496 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1497 account = account_find_from_id(id);
1499 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1500 sizeof(queueheader_buf), "NAID:")) {
1501 id = atoi(&queueheader_buf[strlen("NAID:")]);
1502 account = account_find_from_id(id);
1504 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1505 sizeof(queueheader_buf), "MAID:")) {
1506 id = atoi(&queueheader_buf[strlen("MAID:")]);
1507 account = account_find_from_id(id);
1509 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1510 sizeof(queueheader_buf), "S:")) {
1511 account = account_find_from_address(queueheader_buf);
1513 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1514 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1515 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1516 use_signing = param;
1519 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1520 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1521 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1522 use_encryption = param;
1524 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1525 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1526 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1528 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1529 sizeof(queueheader_buf), "X-Priority: ")) {
1530 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1531 compose->priority = param;
1534 account = msginfo->folder->folder->account;
1536 if (!account && prefs_common.reedit_account_autosel) {
1537 gchar from[BUFFSIZE];
1538 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1539 extract_address(from);
1540 account = account_find_from_address(from);
1543 if (!account) account = cur_account;
1544 g_return_if_fail(account != NULL);
1546 compose = compose_create(account, COMPOSE_REEDIT);
1547 if (privacy_system != NULL) {
1548 compose->privacy_system = privacy_system;
1549 compose_use_signing(compose, use_signing);
1550 compose_use_encryption(compose, use_encryption);
1551 compose_update_privacy_system_menu_item(compose, FALSE);
1553 activate_privacy_system(compose, account, FALSE);
1555 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1557 compose_extract_original_charset(compose);
1559 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1560 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1561 gchar queueheader_buf[BUFFSIZE];
1563 /* Set message save folder */
1564 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1567 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1568 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1569 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1573 if (compose_parse_header(compose, msginfo) < 0) return;
1574 compose_reedit_set_entry(compose, msginfo);
1576 textview = GTK_TEXT_VIEW(compose->text);
1577 textbuf = gtk_text_view_get_buffer(textview);
1578 compose_create_tags(textview, compose);
1580 mark = gtk_text_buffer_get_insert(textbuf);
1581 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1583 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1584 G_CALLBACK(compose_changed_cb),
1587 if (procmime_msginfo_is_encrypted(msginfo)) {
1588 fp = procmime_get_first_encrypted_text_content(msginfo);
1590 compose_force_encryption(compose, account, TRUE);
1592 fp = procmime_get_first_text_content(msginfo);
1594 g_warning("Can't get text part\n");
1597 gboolean prev_autowrap = compose->autowrap;
1599 compose->autowrap = FALSE;
1600 while (fgets(buf, sizeof(buf), fp) != NULL) {
1602 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1604 compose_wrap_all_full(compose, FALSE);
1605 compose->autowrap = prev_autowrap;
1609 compose_attach_parts(compose, msginfo);
1611 compose_colorize_signature(compose);
1613 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1614 G_CALLBACK(compose_changed_cb),
1617 gtk_widget_grab_focus(compose->text);
1619 if (prefs_common.auto_exteditor)
1620 compose_exec_ext_editor(compose);
1621 compose_set_title(compose);
1624 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1628 GtkItemFactory *ifactory;
1631 g_return_val_if_fail(msginfo != NULL, NULL);
1634 account = account_get_reply_account(msginfo,
1635 prefs_common.reply_account_autosel);
1636 g_return_val_if_fail(account != NULL, NULL);
1638 compose = compose_create(account, COMPOSE_REDIRECT);
1639 ifactory = gtk_item_factory_from_widget(compose->menubar);
1640 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1641 compose->replyinfo = NULL;
1642 compose->fwdinfo = NULL;
1644 compose_show_first_last_header(compose, TRUE);
1646 gtk_widget_grab_focus(compose->header_last->entry);
1648 filename = procmsg_get_message_file_path(msginfo);
1649 if (filename == NULL)
1652 compose->redirect_filename = filename;
1654 /* Set save folder */
1655 item = msginfo->folder;
1656 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1657 gchar *folderidentifier;
1659 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1660 folderidentifier = folder_item_get_identifier(item);
1661 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1662 g_free(folderidentifier);
1665 compose_attach_parts(compose, msginfo);
1667 if (msginfo->subject)
1668 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1670 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1672 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1673 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1675 compose_colorize_signature(compose);
1677 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1678 menu_set_sensitive(ifactory, "/Add...", FALSE);
1679 menu_set_sensitive(ifactory, "/Remove", FALSE);
1680 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1682 ifactory = gtk_item_factory_from_widget(compose->menubar);
1683 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1684 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1685 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1686 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1687 menu_set_sensitive(ifactory, "/Edit", FALSE);
1688 menu_set_sensitive(ifactory, "/Options", FALSE);
1689 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1690 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1692 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1693 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1694 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1695 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1696 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1697 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1698 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1700 compose_set_title(compose);
1704 GList *compose_get_compose_list(void)
1706 return compose_list;
1709 void compose_entry_append(Compose *compose, const gchar *address,
1710 ComposeEntryType type)
1714 gboolean in_quote = FALSE;
1715 if (!address || *address == '\0') return;
1722 header = N_("Bcc:");
1724 case COMPOSE_REPLYTO:
1725 header = N_("Reply-To:");
1727 case COMPOSE_NEWSGROUPS:
1728 header = N_("Newsgroups:");
1730 case COMPOSE_FOLLOWUPTO:
1731 header = N_( "Followup-To:");
1738 header = prefs_common.trans_hdr ? gettext(header) : header;
1740 cur = begin = (gchar *)address;
1742 /* we separate the line by commas, but not if we're inside a quoted
1744 while (*cur != '\0') {
1746 in_quote = !in_quote;
1747 if (*cur == ',' && !in_quote) {
1748 gchar *tmp = g_strdup(begin);
1750 tmp[cur-begin]='\0';
1755 compose_add_header_entry(compose, header, tmp);
1762 gchar *tmp = g_strdup(begin);
1764 tmp[cur-begin]='\0';
1769 compose_add_header_entry(compose, header, tmp);
1774 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1776 static GtkStyle *bold_style = NULL;
1777 static GdkColor bold_color;
1781 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1782 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1783 if (gtk_entry_get_text(entry) &&
1784 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1785 gtk_widget_ensure_style(GTK_WIDGET(entry));
1787 gtkut_convert_int_to_gdk_color
1788 (prefs_common.color_new, &bold_color);
1789 bold_style = gtk_style_copy(gtk_widget_get_style
1790 (GTK_WIDGET(entry)));
1791 pango_font_description_set_weight
1792 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
1793 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1795 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1800 void compose_toolbar_cb(gint action, gpointer data)
1802 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1803 Compose *compose = (Compose*)toolbar_item->parent;
1805 g_return_if_fail(compose != NULL);
1809 compose_send_cb(compose, 0, NULL);
1812 compose_send_later_cb(compose, 0, NULL);
1815 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1818 compose_insert_file_cb(compose, 0, NULL);
1821 compose_attach_cb(compose, 0, NULL);
1824 compose_insert_sig(compose, FALSE);
1827 compose_ext_editor_cb(compose, 0, NULL);
1829 case A_LINEWRAP_CURRENT:
1830 compose_beautify_paragraph(compose, NULL, TRUE);
1832 case A_LINEWRAP_ALL:
1833 compose_wrap_all_full(compose, TRUE);
1836 compose_address_cb(compose, 0, NULL);
1839 case A_CHECK_SPELLING:
1840 compose_check_all(compose);
1848 static void compose_entries_set(Compose *compose, const gchar *mailto)
1852 gchar *subject = NULL;
1857 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1860 compose_entry_append(compose, to, COMPOSE_TO);
1862 compose_entry_append(compose, cc, COMPOSE_CC);
1864 if (!g_utf8_validate (subject, -1, NULL)) {
1865 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1866 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1869 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1873 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1874 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1877 gboolean prev_autowrap = compose->autowrap;
1879 compose->autowrap = FALSE;
1881 mark = gtk_text_buffer_get_insert(buffer);
1882 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1884 if (!g_utf8_validate (body, -1, NULL)) {
1885 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1886 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1889 gtk_text_buffer_insert(buffer, &iter, body, -1);
1891 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1893 compose->autowrap = prev_autowrap;
1894 if (compose->autowrap)
1895 compose_wrap_all(compose);
1904 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1906 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1907 {"Cc:", NULL, TRUE},
1908 {"References:", NULL, FALSE},
1909 {"Bcc:", NULL, TRUE},
1910 {"Newsgroups:", NULL, TRUE},
1911 {"Followup-To:", NULL, TRUE},
1912 {"List-Post:", NULL, FALSE},
1913 {"X-Priority:", NULL, FALSE},
1914 {NULL, NULL, FALSE}};
1930 g_return_val_if_fail(msginfo != NULL, -1);
1932 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1933 procheader_get_header_fields(fp, hentry);
1936 if (hentry[H_REPLY_TO].body != NULL) {
1937 if (hentry[H_REPLY_TO].body[0] != '\0') {
1939 conv_unmime_header(hentry[H_REPLY_TO].body,
1942 g_free(hentry[H_REPLY_TO].body);
1943 hentry[H_REPLY_TO].body = NULL;
1945 if (hentry[H_CC].body != NULL) {
1946 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1947 g_free(hentry[H_CC].body);
1948 hentry[H_CC].body = NULL;
1950 if (hentry[H_REFERENCES].body != NULL) {
1951 if (compose->mode == COMPOSE_REEDIT)
1952 compose->references = hentry[H_REFERENCES].body;
1954 compose->references = compose_parse_references
1955 (hentry[H_REFERENCES].body, msginfo->msgid);
1956 g_free(hentry[H_REFERENCES].body);
1958 hentry[H_REFERENCES].body = NULL;
1960 if (hentry[H_BCC].body != NULL) {
1961 if (compose->mode == COMPOSE_REEDIT)
1963 conv_unmime_header(hentry[H_BCC].body, NULL);
1964 g_free(hentry[H_BCC].body);
1965 hentry[H_BCC].body = NULL;
1967 if (hentry[H_NEWSGROUPS].body != NULL) {
1968 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1969 hentry[H_NEWSGROUPS].body = NULL;
1971 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1972 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1973 compose->followup_to =
1974 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1977 g_free(hentry[H_FOLLOWUP_TO].body);
1978 hentry[H_FOLLOWUP_TO].body = NULL;
1980 if (hentry[H_LIST_POST].body != NULL) {
1983 extract_address(hentry[H_LIST_POST].body);
1984 if (hentry[H_LIST_POST].body[0] != '\0') {
1985 scan_mailto_url(hentry[H_LIST_POST].body,
1986 &to, NULL, NULL, NULL, NULL);
1988 g_free(compose->ml_post);
1989 compose->ml_post = to;
1992 g_free(hentry[H_LIST_POST].body);
1993 hentry[H_LIST_POST].body = NULL;
1996 /* CLAWS - X-Priority */
1997 if (compose->mode == COMPOSE_REEDIT)
1998 if (hentry[H_X_PRIORITY].body != NULL) {
2001 priority = atoi(hentry[H_X_PRIORITY].body);
2002 g_free(hentry[H_X_PRIORITY].body);
2004 hentry[H_X_PRIORITY].body = NULL;
2006 if (priority < PRIORITY_HIGHEST ||
2007 priority > PRIORITY_LOWEST)
2008 priority = PRIORITY_NORMAL;
2010 compose->priority = priority;
2013 if (compose->mode == COMPOSE_REEDIT) {
2014 if (msginfo->inreplyto && *msginfo->inreplyto)
2015 compose->inreplyto = g_strdup(msginfo->inreplyto);
2019 if (msginfo->msgid && *msginfo->msgid)
2020 compose->inreplyto = g_strdup(msginfo->msgid);
2022 if (!compose->references) {
2023 if (msginfo->msgid && *msginfo->msgid) {
2024 if (msginfo->inreplyto && *msginfo->inreplyto)
2025 compose->references =
2026 g_strdup_printf("<%s>\n\t<%s>",
2030 compose->references =
2031 g_strconcat("<", msginfo->msgid, ">",
2033 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2034 compose->references =
2035 g_strconcat("<", msginfo->inreplyto, ">",
2043 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2045 GSList *ref_id_list, *cur;
2049 ref_id_list = references_list_append(NULL, ref);
2050 if (!ref_id_list) return NULL;
2051 if (msgid && *msgid)
2052 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2057 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2058 /* "<" + Message-ID + ">" + CR+LF+TAB */
2059 len += strlen((gchar *)cur->data) + 5;
2061 if (len > MAX_REFERENCES_LEN) {
2062 /* remove second message-ID */
2063 if (ref_id_list && ref_id_list->next &&
2064 ref_id_list->next->next) {
2065 g_free(ref_id_list->next->data);
2066 ref_id_list = g_slist_remove
2067 (ref_id_list, ref_id_list->next->data);
2069 slist_free_strings(ref_id_list);
2070 g_slist_free(ref_id_list);
2077 new_ref = g_string_new("");
2078 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2079 if (new_ref->len > 0)
2080 g_string_append(new_ref, "\n\t");
2081 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2084 slist_free_strings(ref_id_list);
2085 g_slist_free(ref_id_list);
2087 new_ref_str = new_ref->str;
2088 g_string_free(new_ref, FALSE);
2093 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2094 const gchar *fmt, const gchar *qmark,
2097 static MsgInfo dummyinfo;
2098 gchar *quote_str = NULL;
2102 gboolean prev_autowrap;
2103 const gchar *trimmed_body = body;
2104 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2105 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2108 msginfo = &dummyinfo;
2110 if (qmark != NULL) {
2111 quote_fmt_init(msginfo, NULL, NULL);
2112 quote_fmt_scan_string(qmark);
2115 buf = quote_fmt_get_buffer();
2117 alertpanel_error(_("Quote mark format error."));
2119 Xstrdup_a(quote_str, buf, return NULL)
2122 if (fmt && *fmt != '\0') {
2123 while (trimmed_body && strlen(trimmed_body) > 1
2124 && trimmed_body[0]=='\n')
2127 quote_fmt_init(msginfo, quote_str, trimmed_body);
2128 quote_fmt_scan_string(fmt);
2131 buf = quote_fmt_get_buffer();
2133 alertpanel_error(_("Message reply/forward format error."));
2139 prev_autowrap = compose->autowrap;
2140 compose->autowrap = FALSE;
2142 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2143 G_CALLBACK(compose_changed_cb),
2145 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2146 G_CALLBACK(text_inserted),
2148 for (p = buf; *p != '\0'; ) {
2153 mark = gtk_text_buffer_get_insert(buffer);
2154 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2156 lastp = strchr(p, '\n');
2157 len = lastp ? lastp - p + 1 : -1;
2159 if (g_utf8_validate(p, -1, NULL)) {
2160 gtk_text_buffer_insert(buffer, &iter, p, len);
2162 gchar *tmpin = g_strdup(p);
2163 gchar *tmpout = NULL;
2165 tmpout = conv_codeset_strdup
2166 (tmpin, conv_get_locale_charset_str(),
2168 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2179 compose->autowrap = prev_autowrap;
2180 if (compose->autowrap)
2181 compose_wrap_all(compose);
2183 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2184 G_CALLBACK(compose_changed_cb),
2186 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2187 G_CALLBACK(text_inserted),
2194 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2195 gboolean to_all, gboolean to_ml,
2197 gboolean followup_and_reply_to)
2199 GSList *cc_list = NULL;
2202 gchar *replyto = NULL;
2203 GHashTable *to_table;
2205 g_return_if_fail(compose->account != NULL);
2206 g_return_if_fail(msginfo != NULL);
2208 if (compose->account->protocol != A_NNTP) {
2209 if (to_ml && compose->ml_post
2210 && !(msginfo->folder &&
2211 msginfo->folder->prefs->enable_default_reply_to)) {
2212 compose_entry_append(compose,
2215 if (compose->replyto) {
2216 gchar *tmp1 = NULL, *tmp2 = NULL;
2217 Xstrdup_a(tmp1, compose->replyto, return);
2218 if (compose->ml_post)
2219 Xstrdup_a(tmp2, compose->ml_post, return);
2220 extract_address(tmp1);
2221 extract_address(tmp2);
2222 if (tmp1 && tmp2 && strcmp(tmp1, tmp2))
2223 compose_entry_append(compose,
2228 else if (!(to_all || to_sender)
2230 && msginfo->folder->prefs->enable_default_reply_to) {
2231 compose_entry_append(compose,
2232 msginfo->folder->prefs->default_reply_to,
2234 compose_entry_mark_default_to(compose,
2235 msginfo->folder->prefs->default_reply_to);
2238 Xstrdup_a(tmp1, msginfo->from, return);
2239 extract_address(tmp1);
2240 if (to_all || to_sender ||
2241 !account_find_from_address(tmp1))
2242 compose_entry_append(compose,
2243 (compose->replyto && !to_sender)
2244 ? compose->replyto :
2245 msginfo->from ? msginfo->from : "",
2247 else if (!to_all && !to_sender) {
2248 /* reply to the last list of recipients */
2249 compose_entry_append(compose,
2250 msginfo->to ? msginfo->to : "",
2252 compose_entry_append(compose,
2253 msginfo->cc ? msginfo->cc : "",
2258 if (to_sender || (compose->followup_to &&
2259 !strncmp(compose->followup_to, "poster", 6)))
2260 compose_entry_append
2262 (compose->replyto ? compose->replyto :
2263 msginfo->from ? msginfo->from : ""),
2266 else if (followup_and_reply_to || to_all) {
2267 compose_entry_append
2269 (compose->replyto ? compose->replyto :
2270 msginfo->from ? msginfo->from : ""),
2273 compose_entry_append
2275 compose->followup_to ? compose->followup_to :
2276 compose->newsgroups ? compose->newsgroups : "",
2277 COMPOSE_NEWSGROUPS);
2280 compose_entry_append
2282 compose->followup_to ? compose->followup_to :
2283 compose->newsgroups ? compose->newsgroups : "",
2284 COMPOSE_NEWSGROUPS);
2287 if (msginfo->subject && *msginfo->subject) {
2291 buf = p = g_strdup(msginfo->subject);
2292 p += subject_get_prefix_length(p);
2293 memmove(buf, p, strlen(p) + 1);
2295 buf2 = g_strdup_printf("Re: %s", buf);
2296 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2301 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2303 if (to_ml && compose->ml_post) return;
2304 if (!to_all || compose->account->protocol == A_NNTP) return;
2306 if (compose->replyto) {
2307 Xstrdup_a(replyto, compose->replyto, return);
2308 extract_address(replyto);
2310 if (msginfo->from) {
2311 Xstrdup_a(from, msginfo->from, return);
2312 extract_address(from);
2315 if (replyto && from)
2316 cc_list = address_list_append_with_comments(cc_list, from);
2317 if (to_all && msginfo->folder &&
2318 msginfo->folder->prefs->enable_default_reply_to)
2319 cc_list = address_list_append_with_comments(cc_list,
2320 msginfo->folder->prefs->default_reply_to);
2321 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2322 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2324 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2326 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2327 if (compose->account)
2328 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2329 GINT_TO_POINTER(1));
2331 /* remove address on To: and that of current account */
2332 for (cur = cc_list; cur != NULL; ) {
2333 GSList *next = cur->next;
2336 addr = g_strdup(cur->data);
2337 extract_address(addr);
2339 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2340 cc_list = g_slist_remove(cc_list, cur->data);
2342 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2346 hash_free_strings(to_table);
2347 g_hash_table_destroy(to_table);
2350 for (cur = cc_list; cur != NULL; cur = cur->next)
2351 compose_entry_append(compose, (gchar *)cur->data,
2353 slist_free_strings(cc_list);
2354 g_slist_free(cc_list);
2359 #define SET_ENTRY(entry, str) \
2362 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2365 #define SET_ADDRESS(type, str) \
2368 compose_entry_append(compose, str, type); \
2371 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2373 g_return_if_fail(msginfo != NULL);
2375 SET_ENTRY(subject_entry, msginfo->subject);
2376 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2377 SET_ADDRESS(COMPOSE_CC, compose->cc);
2378 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2379 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2380 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2381 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2383 compose_update_priority_menu_item(compose);
2384 compose_update_privacy_system_menu_item(compose, FALSE);
2385 compose_show_first_last_header(compose, TRUE);
2391 static void compose_insert_sig(Compose *compose, gboolean replace)
2393 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2394 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2396 GtkTextIter iter, iter_end;
2398 gboolean prev_autowrap;
2401 g_return_if_fail(compose->account != NULL);
2403 prev_autowrap = compose->autowrap;
2404 compose->autowrap = FALSE;
2406 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2407 G_CALLBACK(compose_changed_cb),
2410 mark = gtk_text_buffer_get_insert(buffer);
2411 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2412 cur_pos = gtk_text_iter_get_offset (&iter);
2414 gtk_text_buffer_get_end_iter(buffer, &iter);
2416 if (replace && compose->sig_str) {
2418 GtkTextIter first_iter, start_iter, end_iter;
2420 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2422 if (compose->sig_str[0] == '\0')
2425 found = gtk_text_iter_forward_search(&first_iter,
2427 GTK_TEXT_SEARCH_TEXT_ONLY,
2428 &start_iter, &end_iter,
2432 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2437 g_free(compose->sig_str);
2438 compose->sig_str = compose_get_signature_str(compose);
2439 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2440 compose->sig_str = g_strdup("");
2442 cur_pos = gtk_text_iter_get_offset(&iter);
2443 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2445 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2446 gtk_text_iter_forward_char(&iter);
2447 gtk_text_iter_forward_char(&iter);
2448 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2449 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2451 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2452 cur_pos = gtk_text_buffer_get_char_count (buffer);
2454 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2455 gtk_text_buffer_place_cursor(buffer, &iter);
2457 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2458 G_CALLBACK(compose_changed_cb),
2461 compose->autowrap = prev_autowrap;
2462 if (compose->autowrap)
2463 compose_wrap_all(compose);
2466 static gchar *compose_get_signature_str(Compose *compose)
2468 gchar *sig_body = NULL;
2469 gchar *sig_str = NULL;
2470 gchar *utf8_sig_str = NULL;
2472 g_return_val_if_fail(compose->account != NULL, NULL);
2474 if (!compose->account->sig_path)
2477 if (compose->account->sig_type == SIG_FILE) {
2478 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2479 g_warning("can't open signature file: %s\n",
2480 compose->account->sig_path);
2485 if (compose->account->sig_type == SIG_COMMAND)
2486 sig_body = get_command_output(compose->account->sig_path);
2490 tmp = file_read_to_str(compose->account->sig_path);
2493 sig_body = normalize_newlines(tmp);
2497 if (compose->account->sig_sep) {
2498 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2502 sig_str = g_strconcat("\n\n", sig_body, NULL);
2505 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2506 utf8_sig_str = sig_str;
2508 utf8_sig_str = conv_codeset_strdup
2509 (sig_str, conv_get_locale_charset_str(),
2515 return utf8_sig_str;
2518 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2521 GtkTextBuffer *buffer;
2524 const gchar *cur_encoding;
2525 gchar buf[BUFFSIZE];
2528 gboolean prev_autowrap;
2529 gboolean badtxt = FALSE;
2531 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2533 if ((fp = g_fopen(file, "rb")) == NULL) {
2534 FILE_OP_ERROR(file, "fopen");
2535 return COMPOSE_INSERT_READ_ERROR;
2538 prev_autowrap = compose->autowrap;
2539 compose->autowrap = FALSE;
2541 text = GTK_TEXT_VIEW(compose->text);
2542 buffer = gtk_text_view_get_buffer(text);
2543 mark = gtk_text_buffer_get_insert(buffer);
2544 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2546 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2547 G_CALLBACK(text_inserted),
2550 cur_encoding = conv_get_locale_charset_str();
2552 while (fgets(buf, sizeof(buf), fp) != NULL) {
2555 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2556 str = g_strdup(buf);
2558 str = conv_codeset_strdup
2559 (buf, cur_encoding, CS_INTERNAL);
2562 /* strip <CR> if DOS/Windows file,
2563 replace <CR> with <LF> if Macintosh file. */
2566 if (len > 0 && str[len - 1] != '\n') {
2568 if (str[len] == '\r') str[len] = '\n';
2571 gtk_text_buffer_insert(buffer, &iter, str, -1);
2575 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2576 G_CALLBACK(text_inserted),
2578 compose->autowrap = prev_autowrap;
2579 if (compose->autowrap)
2580 compose_wrap_all(compose);
2585 return COMPOSE_INSERT_INVALID_CHARACTER;
2587 return COMPOSE_INSERT_SUCCESS;
2590 static void compose_attach_append(Compose *compose, const gchar *file,
2591 const gchar *filename,
2592 const gchar *content_type)
2600 GtkListStore *store;
2603 if (!is_file_exist(file)) {
2604 g_warning("File %s doesn't exist\n", filename);
2607 if ((size = get_file_size(file)) < 0) {
2608 g_warning("Can't get file size of %s\n", filename);
2612 alertpanel_notice(_("File %s is empty."), filename);
2615 if ((fp = g_fopen(file, "rb")) == NULL) {
2616 alertpanel_error(_("Can't read %s."), filename);
2621 ainfo = g_new0(AttachInfo, 1);
2622 auto_ainfo = g_auto_pointer_new_with_free
2623 (ainfo, (GFreeFunc) compose_attach_info_free);
2624 ainfo->file = g_strdup(file);
2627 ainfo->content_type = g_strdup(content_type);
2628 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2630 MsgFlags flags = {0, 0};
2632 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2633 ainfo->encoding = ENC_7BIT;
2635 ainfo->encoding = ENC_8BIT;
2637 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2638 if (msginfo && msginfo->subject)
2639 name = g_strdup(msginfo->subject);
2641 name = g_path_get_basename(filename ? filename : file);
2643 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2645 procmsg_msginfo_free(msginfo);
2647 if (!g_ascii_strncasecmp(content_type, "text", 4))
2648 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2650 ainfo->encoding = ENC_BASE64;
2651 name = g_path_get_basename(filename ? filename : file);
2652 ainfo->name = g_strdup(name);
2656 ainfo->content_type = procmime_get_mime_type(file);
2657 if (!ainfo->content_type) {
2658 ainfo->content_type =
2659 g_strdup("application/octet-stream");
2660 ainfo->encoding = ENC_BASE64;
2661 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2663 procmime_get_encoding_for_text_file(file);
2665 ainfo->encoding = ENC_BASE64;
2666 name = g_path_get_basename(filename ? filename : file);
2667 ainfo->name = g_strdup(name);
2671 if (!strcmp(ainfo->content_type, "unknown")) {
2672 g_free(ainfo->content_type);
2673 ainfo->content_type = g_strdup("application/octet-stream");
2677 size_text = to_human_readable(size);
2679 store = GTK_LIST_STORE(gtk_tree_view_get_model
2680 (GTK_TREE_VIEW(compose->attach_clist)));
2682 gtk_list_store_append(store, &iter);
2683 gtk_list_store_set(store, &iter,
2684 COL_MIMETYPE, ainfo->content_type,
2685 COL_SIZE, size_text,
2686 COL_NAME, ainfo->name,
2688 COL_AUTODATA, auto_ainfo,
2691 g_auto_pointer_free(auto_ainfo);
2694 static void compose_use_signing(Compose *compose, gboolean use_signing)
2696 GtkItemFactory *ifactory;
2697 GtkWidget *menuitem = NULL;
2699 compose->use_signing = use_signing;
2700 ifactory = gtk_item_factory_from_widget(compose->menubar);
2701 menuitem = gtk_item_factory_get_item
2702 (ifactory, "/Options/Sign");
2703 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2707 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2709 GtkItemFactory *ifactory;
2710 GtkWidget *menuitem = NULL;
2712 compose->use_encryption = use_encryption;
2713 ifactory = gtk_item_factory_from_widget(compose->menubar);
2714 menuitem = gtk_item_factory_get_item
2715 (ifactory, "/Options/Encrypt");
2717 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2721 #define NEXT_PART_NOT_CHILD(info) \
2723 node = info->node; \
2724 while (node->children) \
2725 node = g_node_last_child(node); \
2726 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2729 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2733 MimeInfo *firsttext = NULL;
2734 MimeInfo *encrypted = NULL;
2737 const gchar *partname = NULL;
2739 mimeinfo = procmime_scan_message(msginfo);
2740 if (!mimeinfo) return;
2742 if (mimeinfo->node->children == NULL) {
2743 procmime_mimeinfo_free_all(mimeinfo);
2747 /* find first content part */
2748 child = (MimeInfo *) mimeinfo->node->children->data;
2749 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2750 child = (MimeInfo *)child->node->children->data;
2752 if (child->type == MIMETYPE_TEXT) {
2754 debug_print("First text part found\n");
2755 } else if (compose->mode == COMPOSE_REEDIT &&
2756 child->type == MIMETYPE_APPLICATION &&
2757 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2758 encrypted = (MimeInfo *)child->node->parent->data;
2761 child = (MimeInfo *) mimeinfo->node->children->data;
2762 while (child != NULL) {
2763 if (child == encrypted) {
2764 /* skip this part of tree */
2765 NEXT_PART_NOT_CHILD(child);
2769 if (child->type == MIMETYPE_MULTIPART) {
2770 /* get the actual content */
2771 child = procmime_mimeinfo_next(child);
2775 if (child == firsttext) {
2776 child = procmime_mimeinfo_next(child);
2780 outfile = procmime_get_tmp_file_name(child);
2781 if (procmime_get_part(outfile, child) < 0)
2782 g_warning("Can't get the part of multipart message.");
2784 gchar *content_type;
2786 content_type = procmime_get_content_type_str(child->type, child->subtype);
2788 /* if we meet a pgp signature, we don't attach it, but
2789 * we force signing. */
2790 if (strcmp(content_type, "application/pgp-signature")) {
2791 partname = procmime_mimeinfo_get_parameter(child, "filename");
2792 if (partname == NULL)
2793 partname = procmime_mimeinfo_get_parameter(child, "name");
2794 if (partname == NULL)
2796 compose_attach_append(compose, outfile,
2797 partname, content_type);
2799 compose_force_signing(compose, compose->account);
2801 g_free(content_type);
2804 NEXT_PART_NOT_CHILD(child);
2806 procmime_mimeinfo_free_all(mimeinfo);
2809 #undef NEXT_PART_NOT_CHILD
2814 WAIT_FOR_INDENT_CHAR,
2815 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2818 /* return indent length, we allow:
2819 indent characters followed by indent characters or spaces/tabs,
2820 alphabets and numbers immediately followed by indent characters,
2821 and the repeating sequences of the above
2822 If quote ends with multiple spaces, only the first one is included. */
2823 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2824 const GtkTextIter *start, gint *len)
2826 GtkTextIter iter = *start;
2830 IndentState state = WAIT_FOR_INDENT_CHAR;
2833 gint alnum_count = 0;
2834 gint space_count = 0;
2837 if (prefs_common.quote_chars == NULL) {
2841 while (!gtk_text_iter_ends_line(&iter)) {
2842 wc = gtk_text_iter_get_char(&iter);
2843 if (g_unichar_iswide(wc))
2845 clen = g_unichar_to_utf8(wc, ch);
2849 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2850 is_space = g_unichar_isspace(wc);
2852 if (state == WAIT_FOR_INDENT_CHAR) {
2853 if (!is_indent && !g_unichar_isalnum(wc))
2856 quote_len += alnum_count + space_count + 1;
2857 alnum_count = space_count = 0;
2858 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2861 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2862 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2866 else if (is_indent) {
2867 quote_len += alnum_count + space_count + 1;
2868 alnum_count = space_count = 0;
2871 state = WAIT_FOR_INDENT_CHAR;
2875 gtk_text_iter_forward_char(&iter);
2878 if (quote_len > 0 && space_count > 0)
2884 if (quote_len > 0) {
2886 gtk_text_iter_forward_chars(&iter, quote_len);
2887 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2893 /* return TRUE if the line is itemized */
2894 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2895 const GtkTextIter *start)
2897 GtkTextIter iter = *start;
2902 if (gtk_text_iter_ends_line(&iter))
2906 wc = gtk_text_iter_get_char(&iter);
2907 if (!g_unichar_isspace(wc))
2909 gtk_text_iter_forward_char(&iter);
2910 if (gtk_text_iter_ends_line(&iter))
2914 clen = g_unichar_to_utf8(wc, ch);
2918 if (!strchr("*-+", ch[0]))
2921 gtk_text_iter_forward_char(&iter);
2922 if (gtk_text_iter_ends_line(&iter))
2924 wc = gtk_text_iter_get_char(&iter);
2925 if (g_unichar_isspace(wc))
2931 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
2932 const GtkTextIter *start,
2933 GtkTextIter *break_pos,
2937 GtkTextIter iter = *start, line_end = *start;
2938 PangoLogAttr *attrs;
2945 gboolean can_break = FALSE;
2946 gboolean do_break = FALSE;
2947 gboolean was_white = FALSE;
2948 gboolean prev_dont_break = FALSE;
2950 gtk_text_iter_forward_to_line_end(&line_end);
2951 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
2952 len = g_utf8_strlen(str, -1);
2953 /* g_print("breaking line: %d: %s (len = %d)\n",
2954 gtk_text_iter_get_line(&iter), str, len); */
2955 attrs = g_new(PangoLogAttr, len + 1);
2957 pango_default_break(str, -1, NULL, attrs, len + 1);
2961 /* skip quote and leading spaces */
2962 for (i = 0; *p != '\0' && i < len; i++) {
2965 wc = g_utf8_get_char(p);
2966 if (i >= quote_len && !g_unichar_isspace(wc))
2968 if (g_unichar_iswide(wc))
2970 else if (*p == '\t')
2974 p = g_utf8_next_char(p);
2977 for (; *p != '\0' && i < len; i++) {
2978 PangoLogAttr *attr = attrs + i;
2982 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
2985 was_white = attr->is_white;
2987 /* don't wrap URI */
2988 if ((uri_len = get_uri_len(p)) > 0) {
2990 if (pos > 0 && col > max_col) {
3000 wc = g_utf8_get_char(p);
3001 if (g_unichar_iswide(wc)) {
3003 if (prev_dont_break && can_break && attr->is_line_break)
3005 } else if (*p == '\t')
3009 if (pos > 0 && col > max_col) {
3014 if (*p == '-' || *p == '/')
3015 prev_dont_break = TRUE;
3017 prev_dont_break = FALSE;
3019 p = g_utf8_next_char(p);
3023 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3028 *break_pos = *start;
3029 gtk_text_iter_set_line_offset(break_pos, pos);
3034 static gboolean compose_join_next_line(Compose *compose,
3035 GtkTextBuffer *buffer,
3037 const gchar *quote_str)
3039 GtkTextIter iter_ = *iter, cur, prev, next, end;
3040 PangoLogAttr attrs[3];
3042 gchar *next_quote_str;
3045 gboolean keep_cursor = FALSE;
3047 if (!gtk_text_iter_forward_line(&iter_) ||
3048 gtk_text_iter_ends_line(&iter_))
3051 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3053 if ((quote_str || next_quote_str) &&
3054 strcmp2(quote_str, next_quote_str) != 0) {
3055 g_free(next_quote_str);
3058 g_free(next_quote_str);
3061 if (quote_len > 0) {
3062 gtk_text_iter_forward_chars(&end, quote_len);
3063 if (gtk_text_iter_ends_line(&end))
3067 /* don't join itemized lines */
3068 if (compose_is_itemized(buffer, &end))
3071 /* don't join signature separator */
3072 if (compose_is_sig_separator(compose, buffer, &iter_))
3075 /* delete quote str */
3077 gtk_text_buffer_delete(buffer, &iter_, &end);
3079 /* delete linebreak and extra spaces */
3081 while (gtk_text_iter_backward_char(&cur)) {
3082 wc1 = gtk_text_iter_get_char(&cur);
3083 if (!g_unichar_isspace(wc1))
3088 while (!gtk_text_iter_ends_line(&cur)) {
3089 wc1 = gtk_text_iter_get_char(&cur);
3090 if (!g_unichar_isspace(wc1))
3092 gtk_text_iter_forward_char(&cur);
3095 if (!gtk_text_iter_equal(&prev, &next)) {
3098 mark = gtk_text_buffer_get_insert(buffer);
3099 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3100 if (gtk_text_iter_equal(&prev, &cur))
3102 gtk_text_buffer_delete(buffer, &prev, &next);
3106 /* insert space if required */
3107 gtk_text_iter_backward_char(&prev);
3108 wc1 = gtk_text_iter_get_char(&prev);
3109 wc2 = gtk_text_iter_get_char(&next);
3110 gtk_text_iter_forward_char(&next);
3111 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3112 pango_default_break(str, -1, NULL, attrs, 3);
3113 if (!attrs[1].is_line_break ||
3114 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3115 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3117 gtk_text_iter_backward_char(&iter_);
3118 gtk_text_buffer_place_cursor(buffer, &iter_);
3127 #define ADD_TXT_POS(bp_, ep_, pti_) \
3128 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3129 last = last->next; \
3130 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3131 last->next = NULL; \
3133 g_warning("alloc error scanning URIs\n"); \
3136 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3138 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3139 GtkTextBuffer *buffer;
3140 GtkTextIter iter, break_pos, end_of_line;
3141 gchar *quote_str = NULL;
3143 gboolean wrap_quote = prefs_common.linewrap_quote;
3144 gboolean prev_autowrap = compose->autowrap;
3145 gint startq_offset = -1, noq_offset = -1;
3146 gint uri_start = -1, uri_stop = -1;
3147 gint nouri_start = -1, nouri_stop = -1;
3149 compose->autowrap = FALSE;
3151 buffer = gtk_text_view_get_buffer(text);
3153 undo_block(compose->undostruct);
3159 mark = gtk_text_buffer_get_insert(buffer);
3160 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3163 /* move to paragraph start */
3164 gtk_text_iter_set_line_offset(&iter, 0);
3165 if (gtk_text_iter_ends_line(&iter)) {
3166 while (gtk_text_iter_ends_line(&iter) &&
3167 gtk_text_iter_forward_line(&iter))
3170 while (gtk_text_iter_backward_line(&iter)) {
3171 if (gtk_text_iter_ends_line(&iter)) {
3172 gtk_text_iter_forward_line(&iter);
3178 /* go until paragraph end (empty line) */
3179 while (!gtk_text_iter_ends_line(&iter)) {
3180 gchar *scanpos = NULL;
3181 /* parse table - in order of priority */
3183 const gchar *needle; /* token */
3185 /* token search function */
3186 gchar *(*search) (const gchar *haystack,
3187 const gchar *needle);
3188 /* part parsing function */
3189 gboolean (*parse) (const gchar *start,
3190 const gchar *scanpos,
3193 /* part to URI function */
3194 gchar *(*build_uri) (const gchar *bp,
3198 static struct table parser[] = {
3199 {"http://", strcasestr, get_uri_part, make_uri_string},
3200 {"https://", strcasestr, get_uri_part, make_uri_string},
3201 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3202 {"www.", strcasestr, get_uri_part, make_http_string},
3203 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3204 {"@", strcasestr, get_email_part, make_email_string}
3206 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3207 gint last_index = PARSE_ELEMS;
3209 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3212 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3215 uri_start = uri_stop = -1;
3216 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3220 if (startq_offset == -1) {
3221 startq_offset = gtk_text_iter_get_offset(&iter);
3225 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3226 if (startq_offset == -1)
3227 startq_offset = gtk_text_iter_get_offset(&iter);
3229 if (startq_offset == -1)
3230 noq_offset = gtk_text_iter_get_offset(&iter);
3233 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3236 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3237 prefs_common.linewrap_len,
3239 GtkTextIter prev, next, cur;
3241 if (prev_autowrap != FALSE || force)
3242 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3243 else if (quote_str && wrap_quote)
3244 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3247 /* remove trailing spaces */
3249 gtk_text_iter_backward_char(&cur);
3251 while (!gtk_text_iter_starts_line(&cur)) {
3254 gtk_text_iter_backward_char(&cur);
3255 wc = gtk_text_iter_get_char(&cur);
3256 if (!g_unichar_isspace(wc))
3260 if (!gtk_text_iter_equal(&prev, &next)) {
3261 gtk_text_buffer_delete(buffer, &prev, &next);
3263 gtk_text_iter_forward_char(&break_pos);
3267 gtk_text_buffer_insert(buffer, &break_pos,
3271 compose_join_next_line(compose, buffer, &iter, quote_str);
3273 /* move iter to current line start */
3274 gtk_text_iter_set_line_offset(&iter, 0);
3277 /* move iter to next line start */
3283 while (!gtk_text_iter_ends_line(&end_of_line)) {
3284 gtk_text_iter_forward_char(&end_of_line);
3286 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3288 nouri_start = gtk_text_iter_get_offset(&iter);
3289 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3291 walk_pos = gtk_text_iter_get_offset(&iter);
3292 /* FIXME: this looks phony. scanning for anything in the parse table */
3293 for (n = 0; n < PARSE_ELEMS; n++) {
3296 tmp = parser[n].search(walk, parser[n].needle);
3298 if (scanpos == NULL || tmp < scanpos) {
3307 /* check if URI can be parsed */
3308 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,(const gchar **)&ep)
3309 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3313 strlen(parser[last_index].needle);
3316 uri_start = walk_pos + (bp - o_walk);
3317 uri_stop = walk_pos + (ep - o_walk);
3321 gtk_text_iter_forward_line(&iter);
3324 if (startq_offset != -1) {
3325 GtkTextIter startquote, endquote;
3326 gtk_text_buffer_get_iter_at_offset(
3327 buffer, &startquote, startq_offset);
3329 gtk_text_buffer_apply_tag_by_name(
3330 buffer, "quote", &startquote, &endquote);
3332 } else if (noq_offset != -1) {
3333 GtkTextIter startnoquote, endnoquote;
3334 gtk_text_buffer_get_iter_at_offset(
3335 buffer, &startnoquote, noq_offset);
3337 gtk_text_buffer_remove_tag_by_name(
3338 buffer, "quote", &startnoquote, &endnoquote);
3343 GtkTextIter nouri_start_iter, nouri_end_iter;
3344 gtk_text_buffer_get_iter_at_offset(
3345 buffer, &nouri_start_iter, nouri_start);
3346 gtk_text_buffer_get_iter_at_offset(
3347 buffer, &nouri_end_iter, nouri_stop);
3348 gtk_text_buffer_remove_tag_by_name(
3349 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3351 if (uri_start > 0 && uri_stop > 0) {
3352 GtkTextIter uri_start_iter, uri_end_iter;
3353 gtk_text_buffer_get_iter_at_offset(
3354 buffer, &uri_start_iter, uri_start);
3355 gtk_text_buffer_get_iter_at_offset(
3356 buffer, &uri_end_iter, uri_stop);
3357 gtk_text_buffer_apply_tag_by_name(
3358 buffer, "link", &uri_start_iter, &uri_end_iter);
3365 undo_unblock(compose->undostruct);
3366 compose->autowrap = prev_autowrap;
3369 static void compose_wrap_all(Compose *compose)
3371 compose_wrap_all_full(compose, FALSE);
3374 static void compose_wrap_all_full(Compose *compose, gboolean force)
3376 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3377 GtkTextBuffer *buffer;
3380 buffer = gtk_text_view_get_buffer(text);
3382 undo_block(compose->undostruct);
3384 gtk_text_buffer_get_start_iter(buffer, &iter);
3385 while (!gtk_text_iter_is_end(&iter))
3386 compose_beautify_paragraph(compose, &iter, force);
3388 undo_unblock(compose->undostruct);
3391 static void compose_set_title(Compose *compose)
3397 edited = compose->modified ? _(" [Edited]") : "";
3399 subject = gtk_editable_get_chars(
3400 GTK_EDITABLE(compose->subject_entry), 0, -1);
3402 if (subject && strlen(subject))
3403 str = g_strdup_printf(_("%s - Compose message%s"),
3405 else if (compose->account && compose->account->address)
3406 str = g_strdup_printf(_("%s - Compose message%s"),
3407 compose->account->address, edited);
3409 str = g_strdup_printf(_("Compose message%s"), edited);
3410 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3416 * compose_current_mail_account:
3418 * Find a current mail account (the currently selected account, or the
3419 * default account, if a news account is currently selected). If a
3420 * mail account cannot be found, display an error message.
3422 * Return value: Mail account, or NULL if not found.
3424 static PrefsAccount *
3425 compose_current_mail_account(void)
3429 if (cur_account && cur_account->protocol != A_NNTP)
3432 ac = account_get_default();
3433 if (!ac || ac->protocol == A_NNTP) {
3434 alertpanel_error(_("Account for sending mail is not specified.\n"
3435 "Please select a mail account before sending."));
3442 static void compose_select_account(Compose *compose, PrefsAccount *account,
3445 GtkItemFactory *ifactory;
3447 g_return_if_fail(account != NULL);
3449 compose->account = account;
3451 compose_set_title(compose);
3453 ifactory = gtk_item_factory_from_widget(compose->menubar);
3455 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3456 menu_set_active(ifactory, "/Options/Sign", TRUE);
3458 menu_set_active(ifactory, "/Options/Sign", FALSE);
3459 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3460 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3462 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3464 activate_privacy_system(compose, account, FALSE);
3466 if (!init && compose->mode != COMPOSE_REDIRECT)
3467 compose_insert_sig(compose, TRUE);
3470 gboolean compose_check_for_valid_recipient(Compose *compose) {
3471 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3472 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3473 gboolean recipient_found = FALSE;
3477 /* free to and newsgroup list */
3478 slist_free_strings(compose->to_list);
3479 g_slist_free(compose->to_list);
3480 compose->to_list = NULL;
3482 slist_free_strings(compose->newsgroup_list);
3483 g_slist_free(compose->newsgroup_list);
3484 compose->newsgroup_list = NULL;
3486 /* search header entries for to and newsgroup entries */
3487 for (list = compose->header_list; list; list = list->next) {
3490 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3491 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3493 if (entry[0] != '\0') {
3494 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3495 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3496 compose->to_list = address_list_append(compose->to_list, entry);
3497 recipient_found = TRUE;
3500 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3501 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3502 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3503 recipient_found = TRUE;
3510 return recipient_found;
3513 static gboolean compose_check_for_set_recipients(Compose *compose)
3515 if (compose->account->set_autocc && compose->account->auto_cc) {
3516 gboolean found_other = FALSE;
3518 /* search header entries for to and newsgroup entries */
3519 for (list = compose->header_list; list; list = list->next) {
3522 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3523 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3525 if (strcmp(entry, compose->account->auto_cc)
3526 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3536 aval = alertpanel(_("Send"),
3537 _("The only recipient is the default CC address. Send anyway?"),
3538 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3539 if (aval != G_ALERTDEFAULT)
3543 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3544 gboolean found_other = FALSE;
3546 /* search header entries for to and newsgroup entries */
3547 for (list = compose->header_list; list; list = list->next) {
3550 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3551 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3553 if (strcmp(entry, compose->account->auto_cc)
3554 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3564 aval = alertpanel(_("Send"),
3565 _("The only recipient is the default BCC address. Send anyway?"),
3566 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3567 if (aval != G_ALERTDEFAULT)
3574 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3578 if (compose_check_for_valid_recipient(compose) == FALSE) {
3579 alertpanel_error(_("Recipient is not specified."));
3583 if (compose_check_for_set_recipients(compose) == FALSE) {
3587 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3588 if (*str == '\0' && check_subject == TRUE) {
3591 aval = alertpanel(_("Send"),
3592 _("Subject is empty. Send it anyway?"),
3593 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3594 if (aval != G_ALERTDEFAULT)
3601 gint compose_send(Compose *compose)
3608 compose_allow_user_actions (compose, FALSE);
3609 compose->sending = TRUE;
3611 if (compose_check_entries(compose, TRUE) == FALSE)
3614 val = compose_queue(compose, &msgnum, &folder);
3618 alertpanel_error(_("Could not queue message for sending:\n\n"
3619 "Charset conversion failed."));
3620 } else if (val == -3) {
3621 alertpanel_error(_("Could not queue message for sending:\n\n"
3622 "Signature failed."));
3623 } else if (val == -2) {
3624 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3626 alertpanel_error(_("Could not queue message for sending."));
3632 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3633 compose->sending = FALSE;
3634 compose_close(compose);
3635 /* No more compose access in the normal codepath
3636 * after this point! */
3641 alertpanel_error(_("The message was queued but could not be "
3642 "sent.\nUse \"Send queued messages\" from "
3643 "the main window to retry."));
3644 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3645 compose->sending = FALSE;
3646 compose_allow_user_actions (compose, TRUE);
3651 msgpath = folder_item_fetch_msg(folder, msgnum);
3652 val = procmsg_send_message_queue(msgpath);
3655 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3656 compose->sending = FALSE;
3657 compose_allow_user_actions (compose, TRUE);
3659 folder_item_remove_msg(folder, msgnum);
3660 folder_item_scan(folder);
3665 folder_item_remove_msg(folder, msgnum);
3666 folder_item_scan(folder);
3667 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3668 compose_close(compose);
3670 alertpanel_error(_("The message was queued but could not be "
3671 "sent.\nUse \"Send queued messages\" from "
3672 "the main window to retry."));
3673 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3674 compose_allow_user_actions (compose, TRUE);
3675 compose->sending = FALSE;
3683 compose_allow_user_actions (compose, TRUE);
3684 compose->sending = FALSE;
3689 static gboolean compose_use_attach(Compose *compose)
3691 GtkTreeModel *model = gtk_tree_view_get_model
3692 (GTK_TREE_VIEW(compose->attach_clist));
3693 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3696 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3699 gchar buf[BUFFSIZE];
3701 gboolean first_to_address;
3702 gboolean first_cc_address;
3704 ComposeHeaderEntry *headerentry;
3705 const gchar *headerentryname;
3709 debug_print("Writing redirect header\n");
3711 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3712 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3714 first_to_address = TRUE;
3715 for (list = compose->header_list; list; list = list->next) {
3716 headerentry = ((ComposeHeaderEntry *)list->data);
3717 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3719 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3720 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3721 Xstrdup_a(str, entstr, return -1);
3723 if (str[0] != '\0') {
3724 compose_convert_header
3725 (compose, buf, sizeof(buf), str,
3726 strlen("Resent-To") + 2, TRUE);
3728 if (first_to_address) {
3729 fprintf(fp, "Resent-To: ");
3730 first_to_address = FALSE;
3734 fprintf(fp, "%s", buf);
3738 if (!first_to_address) {
3742 first_cc_address = TRUE;
3743 for (list = compose->header_list; list; list = list->next) {
3744 headerentry = ((ComposeHeaderEntry *)list->data);
3745 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3747 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3748 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3749 Xstrdup_a(str, strg, return -1);
3751 if (str[0] != '\0') {
3752 compose_convert_header
3753 (compose, buf, sizeof(buf), str,
3754 strlen("Resent-Cc") + 2, TRUE);
3756 if (first_cc_address) {
3757 fprintf(fp, "Resent-Cc: ");
3758 first_cc_address = FALSE;
3762 fprintf(fp, "%s", buf);
3766 if (!first_cc_address) {
3773 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3775 gchar buf[BUFFSIZE];
3777 const gchar *entstr;
3778 /* struct utsname utsbuf; */
3780 g_return_val_if_fail(fp != NULL, -1);
3781 g_return_val_if_fail(compose->account != NULL, -1);
3782 g_return_val_if_fail(compose->account->address != NULL, -1);
3785 get_rfc822_date(buf, sizeof(buf));
3786 fprintf(fp, "Resent-Date: %s\n", buf);
3789 if (compose->account->name && *compose->account->name) {
3790 compose_convert_header
3791 (compose, buf, sizeof(buf), compose->account->name,
3792 strlen("From: "), TRUE);
3793 fprintf(fp, "Resent-From: %s <%s>\n",
3794 buf, compose->account->address);
3796 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3799 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3800 if (*entstr != '\0') {
3801 Xstrdup_a(str, entstr, return -1);
3804 compose_convert_header(compose, buf, sizeof(buf), str,
3805 strlen("Subject: "), FALSE);
3806 fprintf(fp, "Subject: %s\n", buf);
3810 /* Resent-Message-ID */
3811 if (compose->account->gen_msgid) {
3812 generate_msgid(buf, sizeof(buf));
3813 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3814 compose->msgid = g_strdup(buf);
3817 compose_redirect_write_headers_from_headerlist(compose, fp);
3819 /* separator between header and body */
3825 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3829 gchar buf[BUFFSIZE];
3831 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3832 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3836 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3837 /* should filter returnpath, delivered-to */
3838 if (g_ascii_strncasecmp(buf, "Return-Path:",
3839 strlen("Return-Path:")) == 0 ||
3840 g_ascii_strncasecmp(buf, "Delivered-To:",
3841 strlen("Delivered-To:")) == 0 ||
3842 g_ascii_strncasecmp(buf, "Received:",
3843 strlen("Received:")) == 0 ||
3844 g_ascii_strncasecmp(buf, "Subject:",
3845 strlen("Subject:")) == 0 ||
3846 g_ascii_strncasecmp(buf, "X-UIDL:",
3847 strlen("X-UIDL:")) == 0)
3850 if (fputs(buf, fdest) == -1)
3853 if (!prefs_common.redirect_keep_from) {
3854 if (g_ascii_strncasecmp(buf, "From:",
3855 strlen("From:")) == 0) {
3856 fputs(" (by way of ", fdest);
3857 if (compose->account->name
3858 && *compose->account->name) {
3859 compose_convert_header
3860 (compose, buf, sizeof(buf),
3861 compose->account->name,
3864 fprintf(fdest, "%s <%s>",
3866 compose->account->address);
3868 fprintf(fdest, "%s",
3869 compose->account->address);
3874 if (fputs("\n", fdest) == -1)
3878 compose_redirect_write_headers(compose, fdest);
3880 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3881 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3894 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3896 GtkTextBuffer *buffer;
3897 GtkTextIter start, end;
3900 const gchar *out_codeset;
3901 EncodingType encoding;
3902 MimeInfo *mimemsg, *mimetext;
3905 /* create message MimeInfo */
3906 mimemsg = procmime_mimeinfo_new();
3907 mimemsg->type = MIMETYPE_MESSAGE;
3908 mimemsg->subtype = g_strdup("rfc822");
3909 mimemsg->content = MIMECONTENT_MEM;
3910 mimemsg->data.mem = compose_get_header(compose);
3912 /* Create text part MimeInfo */
3913 /* get all composed text */
3914 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3915 gtk_text_buffer_get_start_iter(buffer, &start);
3916 gtk_text_buffer_get_end_iter(buffer, &end);
3917 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3918 if (is_ascii_str(chars)) {
3921 out_codeset = CS_US_ASCII;
3922 encoding = ENC_7BIT;
3924 const gchar *src_codeset = CS_INTERNAL;
3926 out_codeset = conv_get_charset_str(compose->out_encoding);
3929 gchar *test_conv_global_out = NULL;
3930 gchar *test_conv_reply = NULL;
3932 /* automatic mode. be automatic. */
3933 codeconv_set_strict(TRUE);
3935 out_codeset = conv_get_outgoing_charset_str();
3937 debug_print("trying to convert to %s\n", out_codeset);
3938 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
3941 if (!test_conv_global_out && compose->orig_charset) {
3942 out_codeset = compose->orig_charset;
3943 debug_print("failure; trying to convert to %s\n", out_codeset);
3944 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
3947 if (!test_conv_global_out && !test_conv_reply) {
3949 out_codeset = CS_INTERNAL;
3950 debug_print("finally using %s\n", out_codeset);
3952 g_free(test_conv_global_out);
3953 g_free(test_conv_reply);
3954 codeconv_set_strict(FALSE);
3957 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
3958 out_codeset = CS_ISO_8859_1;
3960 if (prefs_common.encoding_method == CTE_BASE64)
3961 encoding = ENC_BASE64;
3962 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3963 encoding = ENC_QUOTED_PRINTABLE;
3964 else if (prefs_common.encoding_method == CTE_8BIT)
3965 encoding = ENC_8BIT;
3967 encoding = procmime_get_encoding_for_charset(out_codeset);
3969 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3970 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3972 if (action == COMPOSE_WRITE_FOR_SEND) {
3973 codeconv_set_strict(TRUE);
3974 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3975 codeconv_set_strict(FALSE);
3981 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
3982 "to the specified %s charset.\n"
3983 "Send it as %s?"), out_codeset, src_codeset);
3984 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
3985 NULL, ALERT_ERROR, G_ALERTALTERNATE);
3988 if (aval != G_ALERTDEFAULT) {
3993 out_codeset = src_codeset;
3999 out_codeset = src_codeset;
4005 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4006 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4007 strstr(buf, "\nFrom ") != NULL) {
4008 encoding = ENC_QUOTED_PRINTABLE;
4012 mimetext = procmime_mimeinfo_new();
4013 mimetext->content = MIMECONTENT_MEM;
4014 mimetext->data.mem = buf;
4015 mimetext->type = MIMETYPE_TEXT;
4016 mimetext->subtype = g_strdup("plain");
4017 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4018 g_strdup(out_codeset));
4019 /* protect trailing spaces when signing message */
4020 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4021 privacy_system_can_sign(compose->privacy_system)) {
4022 encoding = ENC_QUOTED_PRINTABLE;
4025 /* check for line length limit */
4026 if (action == COMPOSE_WRITE_FOR_SEND &&
4027 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4028 check_line_length(buf, 1000, &line) < 0) {
4032 msg = g_strdup_printf
4033 (_("Line %d exceeds the line length limit (998 bytes).\n"
4034 "The contents of the message might be broken on the way to the delivery.\n"
4036 "Send it anyway?"), line + 1);
4037 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
4039 if (aval != G_ALERTDEFAULT) {
4044 if (encoding != ENC_UNKNOWN)
4045 procmime_encode_content(mimetext, encoding);
4047 /* append attachment parts */
4048 if (compose_use_attach(compose)) {
4049 MimeInfo *mimempart;
4050 gchar *boundary = NULL;
4051 mimempart = procmime_mimeinfo_new();
4052 mimempart->content = MIMECONTENT_EMPTY;
4053 mimempart->type = MIMETYPE_MULTIPART;
4054 mimempart->subtype = g_strdup("mixed");
4059 boundary = generate_mime_boundary(NULL);
4060 } while (strstr(buf, boundary) != NULL);
4062 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4065 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4067 g_node_append(mimempart->node, mimetext->node);
4068 g_node_append(mimemsg->node, mimempart->node);
4070 compose_add_attachments(compose, mimempart);
4072 g_node_append(mimemsg->node, mimetext->node);
4074 /* sign message if sending */
4075 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4076 privacy_system_can_sign(compose->privacy_system))
4077 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4080 procmime_write_mimeinfo(mimemsg, fp);
4082 procmime_mimeinfo_free_all(mimemsg);
4087 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4089 GtkTextBuffer *buffer;
4090 GtkTextIter start, end;
4095 if ((fp = g_fopen(file, "wb")) == NULL) {
4096 FILE_OP_ERROR(file, "fopen");
4100 /* chmod for security */
4101 if (change_file_mode_rw(fp, file) < 0) {
4102 FILE_OP_ERROR(file, "chmod");
4103 g_warning("can't change file mode\n");
4106 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4107 gtk_text_buffer_get_start_iter(buffer, &start);
4108 gtk_text_buffer_get_end_iter(buffer, &end);
4109 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4111 chars = conv_codeset_strdup
4112 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4115 if (!chars) return -1;
4118 len = strlen(chars);
4119 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4120 FILE_OP_ERROR(file, "fwrite");
4129 if (fclose(fp) == EOF) {
4130 FILE_OP_ERROR(file, "fclose");
4137 static gint compose_remove_reedit_target(Compose *compose)
4140 MsgInfo *msginfo = compose->targetinfo;
4142 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4143 if (!msginfo) return -1;
4145 item = msginfo->folder;
4146 g_return_val_if_fail(item != NULL, -1);
4148 if (procmsg_msg_exist(msginfo) &&
4149 (folder_has_parent_of_type(item, F_QUEUE) ||
4150 folder_has_parent_of_type(item, F_DRAFT)
4151 || msginfo == compose->autosaved_draft)) {
4152 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4153 g_warning("can't remove the old message\n");
4161 void compose_remove_draft(Compose *compose)
4164 MsgInfo *msginfo = compose->targetinfo;
4165 drafts = account_get_special_folder(compose->account, F_DRAFT);
4167 if (procmsg_msg_exist(msginfo)) {
4168 folder_item_remove_msg(drafts, msginfo->msgnum);
4173 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4175 return compose_queue_sub (compose, msgnum, item, FALSE);
4177 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4184 static gboolean lock = FALSE;
4185 PrefsAccount *mailac = NULL, *newsac = NULL;
4187 debug_print("queueing message...\n");
4188 g_return_val_if_fail(compose->account != NULL, -1);
4192 if (compose_check_entries(compose, check_subject) == FALSE) {
4197 if (!compose->to_list && !compose->newsgroup_list) {
4198 g_warning("can't get recipient list.");
4203 if (compose->to_list) {
4204 if (compose->account->protocol != A_NNTP)
4205 mailac = compose->account;
4206 else if (cur_account && cur_account->protocol != A_NNTP)
4207 mailac = cur_account;
4208 else if (!(mailac = compose_current_mail_account())) {
4210 alertpanel_error(_("No account for sending mails available!"));
4215 if (compose->newsgroup_list) {
4216 if (compose->account->protocol == A_NNTP)
4217 newsac = compose->account;
4218 else if (!newsac->protocol != A_NNTP) {
4220 alertpanel_error(_("No account for posting news available!"));
4225 if (prefs_common.linewrap_at_send)
4226 compose_wrap_all(compose);
4228 /* write queue header */
4229 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4230 G_DIR_SEPARATOR, compose);
4231 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4232 FILE_OP_ERROR(tmp, "fopen");
4237 if (change_file_mode_rw(fp, tmp) < 0) {
4238 FILE_OP_ERROR(tmp, "chmod");
4239 g_warning("can't change file mode\n");
4242 /* queueing variables */
4243 fprintf(fp, "AF:\n");
4244 fprintf(fp, "NF:0\n");
4245 fprintf(fp, "PS:10\n");
4246 fprintf(fp, "SRH:1\n");
4247 fprintf(fp, "SFN:\n");
4248 fprintf(fp, "DSR:\n");
4250 fprintf(fp, "MID:<%s>\n", compose->msgid);
4252 fprintf(fp, "MID:\n");
4253 fprintf(fp, "CFG:\n");
4254 fprintf(fp, "PT:0\n");
4255 fprintf(fp, "S:%s\n", compose->account->address);
4256 fprintf(fp, "RQ:\n");
4258 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4260 fprintf(fp, "SSV:\n");
4262 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4264 fprintf(fp, "NSV:\n");
4265 fprintf(fp, "SSH:\n");
4266 /* write recepient list */
4267 if (compose->to_list) {
4268 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4269 for (cur = compose->to_list->next; cur != NULL;
4271 fprintf(fp, ",<%s>", (gchar *)cur->data);
4274 /* write newsgroup list */
4275 if (compose->newsgroup_list) {
4277 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4278 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4279 fprintf(fp, ",%s", (gchar *)cur->data);
4282 /* Sylpheed account IDs */
4284 fprintf(fp, "MAID:%d\n", mailac->account_id);
4286 fprintf(fp, "NAID:%d\n", newsac->account_id);
4288 if (compose->privacy_system != NULL) {
4289 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4290 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4291 if (compose->use_encryption) {
4294 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4295 if (encdata != NULL) {
4296 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4297 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4298 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4300 } /* else we finally dont want to encrypt */
4302 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4303 /* and if encdata was null, it means there's been a problem in
4310 /* Save copy folder */
4311 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4312 gchar *savefolderid;
4314 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4315 fprintf(fp, "SCF:%s\n", savefolderid);
4316 g_free(savefolderid);
4318 /* Message-ID of message replying to */
4319 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4322 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4323 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4326 /* Message-ID of message forwarding to */
4327 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4330 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4331 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4336 if (compose->redirect_filename != NULL) {
4337 if (compose_redirect_write_to_file(compose, fp) < 0) {
4346 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4351 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4355 if (fclose(fp) == EOF) {
4356 FILE_OP_ERROR(tmp, "fclose");
4362 queue = account_get_special_folder(compose->account, F_QUEUE);
4364 g_warning("can't find queue folder\n");
4369 folder_item_scan(queue);
4370 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4371 g_warning("can't queue the message\n");
4379 if (compose->mode == COMPOSE_REEDIT) {
4380 compose_remove_reedit_target(compose);
4383 if ((msgnum != NULL) && (item != NULL)) {
4391 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4394 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4396 struct stat statbuf;
4397 gchar *type, *subtype;
4398 GtkTreeModel *model;
4401 model = gtk_tree_view_get_model(tree_view);
4403 if (!gtk_tree_model_get_iter_first(model, &iter))
4406 gtk_tree_model_get(model, &iter,
4410 mimepart = procmime_mimeinfo_new();
4411 mimepart->content = MIMECONTENT_FILE;
4412 mimepart->data.filename = g_strdup(ainfo->file);
4413 mimepart->offset = 0;
4415 stat(ainfo->file, &statbuf);
4416 mimepart->length = statbuf.st_size;
4418 type = g_strdup(ainfo->content_type);
4420 if (!strchr(type, '/')) {
4422 type = g_strdup("application/octet-stream");
4425 subtype = strchr(type, '/') + 1;
4426 *(subtype - 1) = '\0';
4427 mimepart->type = procmime_get_media_type(type);
4428 mimepart->subtype = g_strdup(subtype);
4431 if (mimepart->type == MIMETYPE_MESSAGE &&
4432 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4433 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4435 g_hash_table_insert(mimepart->typeparameters,
4436 g_strdup("name"), g_strdup(ainfo->name));
4437 g_hash_table_insert(mimepart->dispositionparameters,
4438 g_strdup("filename"), g_strdup(ainfo->name));
4439 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4442 if (compose->use_signing) {
4443 if (ainfo->encoding == ENC_7BIT)
4444 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4445 else if (ainfo->encoding == ENC_8BIT)
4446 ainfo->encoding = ENC_BASE64;
4449 procmime_encode_content(mimepart, ainfo->encoding);
4451 g_node_append(parent->node, mimepart->node);
4452 } while (gtk_tree_model_iter_next(model, &iter));
4455 #define QUOTE_IF_REQUIRED(out, str) \
4457 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4461 len = strlen(str) + 3; \
4462 if ((__tmp = alloca(len)) == NULL) { \
4463 g_warning("can't allocate memory\n"); \
4464 g_string_free(header, TRUE); \
4467 g_snprintf(__tmp, len, "\"%s\"", str); \
4472 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4473 g_warning("can't allocate memory\n"); \
4474 g_string_free(header, TRUE); \
4477 strcpy(__tmp, str); \
4483 #define IS_IN_CUSTOM_HEADER(header) \
4484 (compose->account->add_customhdr && \
4485 custom_header_find(compose->account->customhdr_list, header) != NULL)
4487 static void compose_add_headerfield_from_headerlist(Compose *compose,
4489 const gchar *fieldname,
4490 const gchar *seperator)
4492 gchar *str, *fieldname_w_colon, *trans_fieldname;
4493 gboolean add_field = FALSE;
4495 ComposeHeaderEntry *headerentry;
4496 const gchar * headerentryname;
4499 if (IS_IN_CUSTOM_HEADER(fieldname))
4502 debug_print("Adding %s-fields\n", fieldname);
4504 fieldstr = g_string_sized_new(64);
4506 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4507 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4509 for (list = compose->header_list; list; list = list->next) {
4510 headerentry = ((ComposeHeaderEntry *)list->data);
4511 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4513 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4514 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4516 if (str[0] != '\0') {
4518 g_string_append(fieldstr, seperator);
4519 g_string_append(fieldstr, str);
4528 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4529 compose_convert_header
4530 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4531 strlen(fieldname) + 2, TRUE);
4532 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4536 g_free(fieldname_w_colon);
4537 g_string_free(fieldstr, TRUE);
4542 static gchar *compose_get_header(Compose *compose)
4544 gchar buf[BUFFSIZE];
4545 const gchar *entry_str;
4549 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4552 g_return_val_if_fail(compose->account != NULL, NULL);
4553 g_return_val_if_fail(compose->account->address != NULL, NULL);
4555 header = g_string_sized_new(64);
4558 if (compose->account->add_date) {
4559 get_rfc822_date(buf, sizeof(buf));
4560 g_string_append_printf(header, "Date: %s\n", buf);
4564 if (compose->account->name && *compose->account->name) {
4565 compose_convert_header
4566 (compose, buf, sizeof(buf), compose->account->name,
4567 strlen("From: "), TRUE);
4568 QUOTE_IF_REQUIRED(name, buf);
4569 g_string_append_printf(header, "From: %s <%s>\n",
4570 name, compose->account->address);
4572 g_string_append_printf(header, "From: %s\n", compose->account->address);
4575 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4578 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4581 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4584 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4587 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4589 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4592 compose_convert_header(compose, buf, sizeof(buf), str,
4593 strlen("Subject: "), FALSE);
4594 g_string_append_printf(header, "Subject: %s\n", buf);
4600 if (compose->account->gen_msgid) {
4601 generate_msgid(buf, sizeof(buf));
4602 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4603 compose->msgid = g_strdup(buf);
4606 if (compose->remove_references == FALSE) {
4608 if (compose->inreplyto && compose->to_list)
4609 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4612 if (compose->references)
4613 g_string_append_printf(header, "References: %s\n", compose->references);
4617 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4620 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4623 if (compose->account->organization &&
4624 strlen(compose->account->organization) &&
4625 !IS_IN_CUSTOM_HEADER("Organization")) {
4626 compose_convert_header(compose, buf, sizeof(buf),
4627 compose->account->organization,
4628 strlen("Organization: "), FALSE);
4629 g_string_append_printf(header, "Organization: %s\n", buf);
4632 /* Program version and system info */
4633 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4634 !compose->newsgroup_list) {
4635 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4637 gtk_major_version, gtk_minor_version, gtk_micro_version,
4640 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4641 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4643 gtk_major_version, gtk_minor_version, gtk_micro_version,
4647 /* custom headers */
4648 if (compose->account->add_customhdr) {
4651 for (cur = compose->account->customhdr_list; cur != NULL;
4653 CustomHeader *chdr = (CustomHeader *)cur->data;
4655 if (custom_header_is_allowed(chdr->name)) {
4656 compose_convert_header
4657 (compose, buf, sizeof(buf),
4658 chdr->value ? chdr->value : "",
4659 strlen(chdr->name) + 2, FALSE);
4660 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4666 switch (compose->priority) {
4667 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4668 "X-Priority: 1 (Highest)\n");
4670 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4671 "X-Priority: 2 (High)\n");
4673 case PRIORITY_NORMAL: break;
4674 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4675 "X-Priority: 4 (Low)\n");
4677 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4678 "X-Priority: 5 (Lowest)\n");
4680 default: debug_print("compose: priority unknown : %d\n",
4684 /* Request Return Receipt */
4685 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4686 if (compose->return_receipt) {
4687 if (compose->account->name
4688 && *compose->account->name) {
4689 compose_convert_header(compose, buf, sizeof(buf),
4690 compose->account->name,
4691 strlen("Disposition-Notification-To: "),
4693 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4695 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4699 /* get special headers */
4700 for (list = compose->header_list; list; list = list->next) {
4701 ComposeHeaderEntry *headerentry;
4704 gchar *headername_wcolon;
4705 gchar *headername_trans;
4708 gboolean standard_header = FALSE;
4710 headerentry = ((ComposeHeaderEntry *)list->data);
4712 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4713 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4718 if (!strstr(tmp, ":")) {
4719 headername_wcolon = g_strconcat(tmp, ":", NULL);
4720 headername = g_strdup(tmp);
4722 headername_wcolon = g_strdup(tmp);
4723 headername = g_strdup(strtok(tmp, ":"));
4727 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4728 Xstrdup_a(headervalue, entry_str, return NULL);
4729 subst_char(headervalue, '\r', ' ');
4730 subst_char(headervalue, '\n', ' ');
4731 string = std_headers;
4732 while (*string != NULL) {
4733 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4734 if (!strcmp(headername_trans,headername_wcolon))
4735 standard_header = TRUE;
4738 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4739 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4742 g_free(headername_wcolon);
4746 g_string_free(header, FALSE);
4751 #undef IS_IN_CUSTOM_HEADER
4753 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4754 gint header_len, gboolean addr_field)
4756 gchar *tmpstr = NULL;
4757 const gchar *out_codeset = NULL;
4759 g_return_if_fail(src != NULL);
4760 g_return_if_fail(dest != NULL);
4762 if (len < 1) return;
4764 tmpstr = g_strdup(src);
4766 subst_char(tmpstr, '\n', ' ');
4767 subst_char(tmpstr, '\r', ' ');
4770 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4771 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4772 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4777 codeconv_set_strict(TRUE);
4778 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4779 conv_get_charset_str(compose->out_encoding));
4780 codeconv_set_strict(FALSE);
4782 if (!dest || *dest == '\0') {
4783 gchar *test_conv_global_out = NULL;
4784 gchar *test_conv_reply = NULL;
4786 /* automatic mode. be automatic. */
4787 codeconv_set_strict(TRUE);
4789 out_codeset = conv_get_outgoing_charset_str();
4791 debug_print("trying to convert to %s\n", out_codeset);
4792 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4795 if (!test_conv_global_out && compose->orig_charset) {
4796 out_codeset = compose->orig_charset;
4797 debug_print("failure; trying to convert to %s\n", out_codeset);
4798 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4801 if (!test_conv_global_out && !test_conv_reply) {
4803 out_codeset = CS_INTERNAL;
4804 debug_print("finally using %s\n", out_codeset);
4806 g_free(test_conv_global_out);
4807 g_free(test_conv_reply);
4808 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4810 codeconv_set_strict(FALSE);
4815 static void compose_create_header_entry(Compose *compose)
4817 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4821 GList *combo_list = NULL;
4823 const gchar *header = NULL;
4824 ComposeHeaderEntry *headerentry;
4825 gboolean standard_header = FALSE;
4827 headerentry = g_new0(ComposeHeaderEntry, 1);
4830 combo = gtk_combo_new();
4832 while(*string != NULL) {
4833 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4836 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4837 g_list_free(combo_list);
4838 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4839 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4840 G_CALLBACK(compose_grab_focus_cb), compose);
4841 gtk_widget_show(combo);
4842 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4843 if (compose->header_last) {
4844 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4846 while (*string != NULL) {
4847 if (!strcmp(*string, last_header_entry))
4848 standard_header = TRUE;
4851 if (standard_header)
4852 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4854 if (!compose->header_last || !standard_header) {
4855 switch(compose->account->protocol) {
4857 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4860 header = prefs_common.trans_hdr ? _("To:") : "To:";
4865 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4867 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4868 G_CALLBACK(compose_grab_focus_cb), compose);
4871 entry = gtk_entry_new();
4872 gtk_widget_show(entry);
4873 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);
4875 g_signal_connect(G_OBJECT(entry), "key-press-event",
4876 G_CALLBACK(compose_headerentry_key_press_event_cb),
4878 g_signal_connect(G_OBJECT(entry), "changed",
4879 G_CALLBACK(compose_headerentry_changed_cb),
4881 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4882 G_CALLBACK(compose_grab_focus_cb), compose);
4885 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4886 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4887 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4888 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4889 G_CALLBACK(compose_header_drag_received_cb),
4891 g_signal_connect(G_OBJECT(entry), "drag-drop",
4892 G_CALLBACK(compose_drag_drop),
4895 address_completion_register_entry(GTK_ENTRY(entry));
4897 headerentry->compose = compose;
4898 headerentry->combo = combo;
4899 headerentry->entry = entry;
4900 headerentry->headernum = compose->header_nextrow;
4902 compose->header_nextrow++;
4903 compose->header_last = headerentry;
4906 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4908 ComposeHeaderEntry *last_header;
4910 last_header = compose->header_last;
4912 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4913 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4916 static GtkWidget *compose_create_header(Compose *compose)
4920 GtkWidget *from_optmenu_hbox;
4921 GtkWidget *header_scrolledwin;
4922 GtkWidget *header_table;
4926 /* header labels and entries */
4927 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4928 gtk_widget_show(header_scrolledwin);
4929 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4931 header_table = gtk_table_new(2, 2, FALSE);
4932 gtk_widget_show(header_table);
4933 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4934 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4935 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4938 /* option menu for selecting accounts */
4939 hbox = gtk_hbox_new(FALSE, 0);
4940 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4941 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4942 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4944 from_optmenu_hbox = compose_account_option_menu_create(compose);
4945 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4946 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4949 compose->header_table = header_table;
4950 compose->header_list = NULL;
4951 compose->header_nextrow = count;
4953 compose_create_header_entry(compose);
4955 compose->table = NULL;
4957 return header_scrolledwin ;
4960 GtkWidget *compose_create_attach(Compose *compose)
4962 GtkWidget *attach_scrwin;
4963 GtkWidget *attach_clist;
4965 GtkListStore *store;
4966 GtkCellRenderer *renderer;
4967 GtkTreeViewColumn *column;
4968 GtkTreeSelection *selection;
4970 /* attachment list */
4971 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4972 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4973 GTK_POLICY_AUTOMATIC,
4974 GTK_POLICY_AUTOMATIC);
4975 gtk_widget_set_size_request(attach_scrwin, -1, 80);
4977 store = gtk_list_store_new(N_ATTACH_COLS,
4982 G_TYPE_AUTO_POINTER,
4984 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
4985 (GTK_TREE_MODEL(store)));
4986 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4987 g_object_unref(store);
4989 renderer = gtk_cell_renderer_text_new();
4990 column = gtk_tree_view_column_new_with_attributes
4991 (_("Mime type"), renderer, "text",
4992 COL_MIMETYPE, NULL);
4993 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4995 renderer = gtk_cell_renderer_text_new();
4996 column = gtk_tree_view_column_new_with_attributes
4997 (_("Size"), renderer, "text",
4999 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5001 renderer = gtk_cell_renderer_text_new();
5002 column = gtk_tree_view_column_new_with_attributes
5003 (_("Name"), renderer, "text",
5005 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5007 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5008 prefs_common.enable_rules_hint);
5009 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5010 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5012 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5013 G_CALLBACK(attach_selected), compose);
5014 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5015 G_CALLBACK(attach_button_pressed), compose);
5016 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5017 G_CALLBACK(attach_key_pressed), compose);
5020 gtk_drag_dest_set(attach_clist,
5021 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5022 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5023 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5024 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5025 G_CALLBACK(compose_attach_drag_received_cb),
5027 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5028 G_CALLBACK(compose_drag_drop),
5031 compose->attach_scrwin = attach_scrwin;
5032 compose->attach_clist = attach_clist;
5034 return attach_scrwin;
5037 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5038 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5040 static GtkWidget *compose_create_others(Compose *compose)
5043 GtkWidget *savemsg_checkbtn;
5044 GtkWidget *savemsg_entry;
5045 GtkWidget *savemsg_select;
5048 gchar *folderidentifier;
5050 /* Table for settings */
5051 table = gtk_table_new(3, 1, FALSE);
5052 gtk_widget_show(table);
5053 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5056 /* Save Message to folder */
5057 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5058 gtk_widget_show(savemsg_checkbtn);
5059 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5060 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5061 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5063 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5064 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5066 savemsg_entry = gtk_entry_new();
5067 gtk_widget_show(savemsg_entry);
5068 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5069 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5070 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5071 G_CALLBACK(compose_grab_focus_cb), compose);
5072 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5073 folderidentifier = folder_item_get_identifier(account_get_special_folder
5074 (compose->account, F_OUTBOX));
5075 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5076 g_free(folderidentifier);
5079 savemsg_select = gtk_button_new_with_label (_("Select ..."));
5080 gtk_widget_show(savemsg_select);
5081 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5082 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5083 G_CALLBACK(compose_savemsg_select_cb),
5088 compose->savemsg_checkbtn = savemsg_checkbtn;
5089 compose->savemsg_entry = savemsg_entry;
5094 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5096 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5097 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5100 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5105 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5108 path = folder_item_get_identifier(dest);
5110 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5114 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5117 #define BLOCK_WRAP() { \
5118 prev_autowrap = compose->autowrap; \
5119 buffer = gtk_text_view_get_buffer( \
5120 GTK_TEXT_VIEW(compose->text)); \
5121 compose->autowrap = FALSE; \
5123 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5124 G_CALLBACK(compose_changed_cb), \
5126 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5127 G_CALLBACK(text_inserted), \
5130 #define UNBLOCK_WRAP() { \
5131 compose->autowrap = prev_autowrap; \
5132 if (compose->autowrap) \
5133 compose_wrap_all(compose); \
5135 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5136 G_CALLBACK(compose_changed_cb), \
5138 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5139 G_CALLBACK(text_inserted), \
5144 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5148 GtkTextBuffer *buffer;
5149 if (event->button == 2) {
5151 entry_paste_clipboard(compose, compose->focused_editable,
5152 prefs_common.linewrap_pastes,
5153 GDK_SELECTION_PRIMARY);
5160 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5166 GtkWidget *handlebox;
5168 GtkWidget *notebook;
5173 GtkWidget *subject_hbox;
5174 GtkWidget *subject_frame;
5175 GtkWidget *subject_entry;
5179 GtkWidget *edit_vbox;
5180 GtkWidget *ruler_hbox;
5182 GtkWidget *scrolledwin;
5184 GtkTextBuffer *buffer;
5185 GtkClipboard *clipboard;
5187 UndoMain *undostruct;
5189 gchar *titles[N_ATTACH_COLS];
5190 guint n_menu_entries;
5193 gboolean success[1];
5194 GtkWidget *popupmenu;
5195 GtkItemFactory *popupfactory;
5196 GtkItemFactory *ifactory;
5197 GtkWidget *tmpl_menu;
5199 GtkWidget *menuitem;
5202 GtkAspell * gtkaspell = NULL;
5205 static GdkGeometry geometry;
5207 g_return_val_if_fail(account != NULL, NULL);
5209 debug_print("Creating compose window...\n");
5210 compose = g_new0(Compose, 1);
5212 titles[COL_MIMETYPE] = _("MIME type");
5213 titles[COL_SIZE] = _("Size");
5214 titles[COL_NAME] = _("Name");
5216 compose->account = account;
5218 compose->mutex = g_mutex_new();
5220 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5221 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5222 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5224 if (!geometry.max_width) {
5225 geometry.max_width = gdk_screen_width();
5226 geometry.max_height = gdk_screen_height();
5229 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5230 &geometry, GDK_HINT_MAX_SIZE);
5231 if (!geometry.min_width) {
5232 geometry.min_width = 600;
5233 geometry.min_height = 480;
5235 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5236 &geometry, GDK_HINT_MIN_SIZE);
5237 gtk_widget_set_uposition(window, prefs_common.compose_x,
5238 prefs_common.compose_y);
5240 g_signal_connect(G_OBJECT(window), "delete_event",
5241 G_CALLBACK(compose_delete_cb), compose);
5242 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5243 gtk_widget_realize(window);
5245 gtkut_widget_set_composer_icon(window);
5247 vbox = gtk_vbox_new(FALSE, 0);
5248 gtk_container_add(GTK_CONTAINER(window), vbox);
5250 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5251 menubar = menubar_create(window, compose_entries,
5252 n_menu_entries, "<Compose>", compose);
5253 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5255 if (prefs_common.toolbar_detachable) {
5256 handlebox = gtk_handle_box_new();
5258 handlebox = gtk_hbox_new(FALSE, 0);
5260 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5262 gtk_widget_realize(handlebox);
5263 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5266 vbox2 = gtk_vbox_new(FALSE, 2);
5267 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5268 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
5271 notebook = gtk_notebook_new();
5272 gtk_widget_set_size_request(notebook, -1, 130);
5273 gtk_widget_show(notebook);
5275 /* header labels and entries */
5276 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5277 /* attachment list */
5278 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5280 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5283 subject_hbox = gtk_hbox_new(FALSE, 0);
5284 gtk_widget_show(subject_hbox);
5286 subject_frame = gtk_frame_new(NULL);
5287 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
5288 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
5289 gtk_widget_show(subject_frame);
5291 subject = gtk_hbox_new(FALSE, 0);
5292 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
5293 gtk_widget_show(subject);
5295 label = gtk_label_new(_("Subject:"));
5296 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
5297 gtk_widget_show(label);
5299 subject_entry = gtk_entry_new();
5300 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
5301 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5302 G_CALLBACK(compose_grab_focus_cb), compose);
5303 gtk_widget_show(subject_entry);
5304 compose->subject_entry = subject_entry;
5305 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5307 edit_vbox = gtk_vbox_new(FALSE, 0);
5309 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5312 ruler_hbox = gtk_hbox_new(FALSE, 0);
5313 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5315 ruler = gtk_shruler_new();
5316 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5317 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5321 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5322 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5323 GTK_POLICY_AUTOMATIC,
5324 GTK_POLICY_AUTOMATIC);
5325 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5327 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5328 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5330 text = gtk_text_view_new();
5331 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5332 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5333 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5334 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5335 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5337 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5339 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5340 G_CALLBACK(compose_edit_size_alloc),
5342 g_signal_connect(G_OBJECT(buffer), "changed",
5343 G_CALLBACK(compose_changed_cb), compose);
5344 g_signal_connect(G_OBJECT(text), "grab_focus",
5345 G_CALLBACK(compose_grab_focus_cb), compose);
5346 g_signal_connect(G_OBJECT(buffer), "insert_text",
5347 G_CALLBACK(text_inserted), compose);
5348 g_signal_connect(G_OBJECT(text), "button_press_event",
5349 G_CALLBACK(text_clicked), compose);
5352 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5353 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5354 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5355 g_signal_connect(G_OBJECT(text), "drag_data_received",
5356 G_CALLBACK(compose_insert_drag_received_cb),
5358 g_signal_connect(G_OBJECT(text), "drag-drop",
5359 G_CALLBACK(compose_drag_drop),
5361 gtk_widget_show_all(vbox);
5363 /* pane between attach clist and text */
5364 paned = gtk_vpaned_new();
5365 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5366 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5367 gtk_paned_add1(GTK_PANED(paned), notebook);
5368 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5369 gtk_widget_show_all(paned);
5372 if (prefs_common.textfont) {
5373 PangoFontDescription *font_desc;
5375 font_desc = pango_font_description_from_string
5376 (prefs_common.textfont);
5378 gtk_widget_modify_font(text, font_desc);
5379 pango_font_description_free(font_desc);
5383 color[0] = quote_color;
5384 cmap = gdk_drawable_get_colormap(window->window);
5385 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5386 if (success[0] == FALSE) {
5389 g_warning("Compose: color allocation failed.\n");
5390 style = gtk_widget_get_style(text);
5391 quote_color = style->black;
5394 n_entries = sizeof(compose_popup_entries) /
5395 sizeof(compose_popup_entries[0]);
5396 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5397 "<Compose>", &popupfactory,
5400 ifactory = gtk_item_factory_from_widget(menubar);
5401 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5402 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5403 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5405 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5407 undostruct = undo_init(text);
5408 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5411 address_completion_start(window);
5413 compose->window = window;
5414 compose->vbox = vbox;
5415 compose->menubar = menubar;
5416 compose->handlebox = handlebox;
5418 compose->vbox2 = vbox2;
5420 compose->paned = paned;
5422 compose->edit_vbox = edit_vbox;
5423 compose->ruler_hbox = ruler_hbox;
5424 compose->ruler = ruler;
5425 compose->scrolledwin = scrolledwin;
5426 compose->text = text;
5428 compose->focused_editable = NULL;
5430 compose->popupmenu = popupmenu;
5431 compose->popupfactory = popupfactory;
5433 compose->tmpl_menu = tmpl_menu;
5435 compose->mode = mode;
5437 compose->targetinfo = NULL;
5438 compose->replyinfo = NULL;
5439 compose->fwdinfo = NULL;
5441 compose->replyto = NULL;
5443 compose->bcc = NULL;
5444 compose->followup_to = NULL;
5446 compose->ml_post = NULL;
5448 compose->inreplyto = NULL;
5449 compose->references = NULL;
5450 compose->msgid = NULL;
5451 compose->boundary = NULL;
5453 compose->autowrap = prefs_common.autowrap;
5455 compose->use_signing = FALSE;
5456 compose->use_encryption = FALSE;
5457 compose->privacy_system = NULL;
5459 compose->modified = FALSE;
5461 compose->return_receipt = FALSE;
5463 compose->to_list = NULL;
5464 compose->newsgroup_list = NULL;
5466 compose->undostruct = undostruct;
5468 compose->sig_str = NULL;
5470 compose->exteditor_file = NULL;
5471 compose->exteditor_pid = -1;
5472 compose->exteditor_tag = -1;
5473 compose->draft_timeout_tag = -1;
5476 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5477 if (mode != COMPOSE_REDIRECT) {
5478 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5479 strcmp(prefs_common.dictionary, _("None"))) {
5480 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5481 prefs_common.dictionary,
5482 conv_get_locale_charset_str(),
5483 prefs_common.misspelled_col,
5484 prefs_common.check_while_typing,
5485 prefs_common.use_alternate,
5486 GTK_TEXT_VIEW(text),
5487 GTK_WINDOW(compose->window));
5489 alertpanel_error(_("Spell checker could not "
5491 gtkaspell_checkers_strerror());
5492 gtkaspell_checkers_reset_error();
5495 GtkWidget *menuitem;
5497 if (!gtkaspell_set_sug_mode(gtkaspell,
5498 prefs_common.aspell_sugmode)) {
5499 debug_print("Aspell: could not set "
5500 "suggestion mode %s\n",
5501 gtkaspell_checkers_strerror());
5502 gtkaspell_checkers_reset_error();
5505 menuitem = gtk_item_factory_get_item(ifactory,
5506 "/Spelling/Spelling Configuration");
5507 gtkaspell_populate_submenu(gtkaspell, menuitem);
5508 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5512 compose->gtkaspell = gtkaspell;
5515 compose_select_account(compose, account, TRUE);
5517 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5518 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5519 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5521 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5522 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5524 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5525 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5528 if (account->protocol != A_NNTP)
5529 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5531 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5533 addressbook_set_target_compose(compose);
5535 if (mode != COMPOSE_REDIRECT)
5536 compose_set_template_menu(compose);
5538 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5539 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5542 compose_list = g_list_append(compose_list, compose);
5544 if (!prefs_common.show_ruler)
5545 gtk_widget_hide(ruler_hbox);
5547 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5548 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5549 prefs_common.show_ruler);
5552 compose->priority = PRIORITY_NORMAL;
5553 compose_update_priority_menu_item(compose);
5555 compose_set_out_encoding(compose);
5558 compose_update_actions_menu(compose);
5560 /* Privacy Systems menu */
5561 compose_update_privacy_systems_menu(compose);
5563 activate_privacy_system(compose, account, TRUE);
5564 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5565 gtk_widget_show(window);
5570 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5576 gint num = 0, def_menu = 0;
5578 accounts = account_get_list();
5579 g_return_val_if_fail(accounts != NULL, NULL);
5581 hbox = gtk_hbox_new(FALSE, 0);
5582 optmenu = gtk_option_menu_new();
5583 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5584 menu = gtk_menu_new();
5586 for (; accounts != NULL; accounts = accounts->next, num++) {
5587 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5588 GtkWidget *menuitem;
5591 if (ac == compose->account) def_menu = num;
5594 name = g_strdup_printf("%s: %s <%s>",
5596 ac->name, ac->address);
5598 name = g_strdup_printf("%s: %s",
5599 ac->account_name, ac->address);
5600 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5602 g_signal_connect(G_OBJECT(menuitem), "activate",
5603 G_CALLBACK(account_activated),
5607 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5608 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5613 static void compose_set_priority_cb(gpointer data,
5617 Compose *compose = (Compose *) data;
5618 compose->priority = action;
5621 static void compose_update_priority_menu_item(Compose * compose)
5623 GtkItemFactory *ifactory;
5624 GtkWidget *menuitem = NULL;
5626 ifactory = gtk_item_factory_from_widget(compose->menubar);
5628 switch (compose->priority) {
5629 case PRIORITY_HIGHEST:
5630 menuitem = gtk_item_factory_get_item
5631 (ifactory, "/Options/Priority/Highest");
5634 menuitem = gtk_item_factory_get_item
5635 (ifactory, "/Options/Priority/High");
5637 case PRIORITY_NORMAL:
5638 menuitem = gtk_item_factory_get_item
5639 (ifactory, "/Options/Priority/Normal");
5642 menuitem = gtk_item_factory_get_item
5643 (ifactory, "/Options/Priority/Low");
5645 case PRIORITY_LOWEST:
5646 menuitem = gtk_item_factory_get_item
5647 (ifactory, "/Options/Priority/Lowest");
5650 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5653 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5655 Compose *compose = (Compose *) data;
5657 GtkItemFactory *ifactory;
5658 gboolean can_sign = FALSE, can_encrypt = FALSE;
5660 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5662 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5665 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5666 g_free(compose->privacy_system);
5667 compose->privacy_system = NULL;
5668 if (systemid != NULL) {
5669 compose->privacy_system = g_strdup(systemid);
5671 can_sign = privacy_system_can_sign(systemid);
5672 can_encrypt = privacy_system_can_encrypt(systemid);
5675 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5677 ifactory = gtk_item_factory_from_widget(compose->menubar);
5678 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5679 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5682 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5684 static gchar *branch_path = "/Options/Privacy System";
5685 GtkItemFactory *ifactory;
5686 GtkWidget *menuitem = NULL;
5688 gboolean can_sign = FALSE, can_encrypt = FALSE;
5689 gboolean found = FALSE;
5691 ifactory = gtk_item_factory_from_widget(compose->menubar);
5693 if (compose->privacy_system != NULL) {
5696 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5697 g_return_if_fail(menuitem != NULL);
5699 amenu = GTK_MENU_SHELL(menuitem)->children;
5701 while (amenu != NULL) {
5702 GList *alist = amenu->next;
5704 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5705 if (systemid != NULL) {
5706 if (strcmp(systemid, compose->privacy_system) == 0) {
5707 menuitem = GTK_WIDGET(amenu->data);
5709 can_sign = privacy_system_can_sign(systemid);
5710 can_encrypt = privacy_system_can_encrypt(systemid);
5714 } else if (strlen(compose->privacy_system) == 0) {
5715 menuitem = GTK_WIDGET(amenu->data);
5718 can_encrypt = FALSE;
5725 if (menuitem != NULL)
5726 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5728 if (warn && !found && strlen(compose->privacy_system)) {
5729 gchar *tmp = g_strdup_printf(
5730 _("The privacy system '%s' cannot be loaded. You "
5731 "will not be able to sign or encrypt this message."),
5732 compose->privacy_system);
5733 alertpanel_warning(tmp);
5738 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5739 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5742 static void compose_set_out_encoding(Compose *compose)
5744 GtkItemFactoryEntry *entry;
5745 GtkItemFactory *ifactory;
5746 CharSet out_encoding;
5747 gchar *path, *p, *q;
5750 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5751 ifactory = gtk_item_factory_from_widget(compose->menubar);
5753 for (entry = compose_entries; entry->callback != compose_address_cb;
5755 if (entry->callback == compose_set_encoding_cb &&
5756 (CharSet)entry->callback_action == out_encoding) {
5757 p = q = path = g_strdup(entry->path);
5769 item = gtk_item_factory_get_item(ifactory, path);
5770 gtk_widget_activate(item);
5777 static void compose_set_template_menu(Compose *compose)
5779 GSList *tmpl_list, *cur;
5783 tmpl_list = template_get_config();
5785 menu = gtk_menu_new();
5787 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5788 Template *tmpl = (Template *)cur->data;
5790 item = gtk_menu_item_new_with_label(tmpl->name);
5791 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5792 g_signal_connect(G_OBJECT(item), "activate",
5793 G_CALLBACK(compose_template_activate_cb),
5795 g_object_set_data(G_OBJECT(item), "template", tmpl);
5796 gtk_widget_show(item);
5799 gtk_widget_show(menu);
5800 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5803 void compose_update_actions_menu(Compose *compose)
5805 GtkItemFactory *ifactory;
5807 ifactory = gtk_item_factory_from_widget(compose->menubar);
5808 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5811 void compose_update_privacy_systems_menu(Compose *compose)
5813 static gchar *branch_path = "/Options/Privacy System";
5814 GtkItemFactory *ifactory;
5815 GtkWidget *menuitem;
5816 GSList *systems, *cur;
5819 GtkWidget *system_none;
5822 ifactory = gtk_item_factory_from_widget(compose->menubar);
5824 /* remove old entries */
5825 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5826 g_return_if_fail(menuitem != NULL);
5828 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5829 while (amenu != NULL) {
5830 GList *alist = amenu->next;
5831 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5835 system_none = gtk_item_factory_get_widget(ifactory,
5836 "/Options/Privacy System/None");
5838 g_signal_connect(G_OBJECT(system_none), "activate",
5839 G_CALLBACK(compose_set_privacy_system_cb), compose);
5841 systems = privacy_get_system_ids();
5842 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5843 gchar *systemid = cur->data;
5845 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5846 widget = gtk_radio_menu_item_new_with_label(group,
5847 privacy_system_get_name(systemid));
5848 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5849 g_strdup(systemid), g_free);
5850 g_signal_connect(G_OBJECT(widget), "activate",
5851 G_CALLBACK(compose_set_privacy_system_cb), compose);
5853 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5854 gtk_widget_show(widget);
5857 g_slist_free(systems);
5860 void compose_reflect_prefs_all(void)
5865 for (cur = compose_list; cur != NULL; cur = cur->next) {
5866 compose = (Compose *)cur->data;
5867 compose_set_template_menu(compose);
5871 void compose_reflect_prefs_pixmap_theme(void)
5876 for (cur = compose_list; cur != NULL; cur = cur->next) {
5877 compose = (Compose *)cur->data;
5878 toolbar_update(TOOLBAR_COMPOSE, compose);
5882 static void compose_template_apply(Compose *compose, Template *tmpl,
5886 GtkTextBuffer *buffer;
5891 gint cursor_pos = 0;
5892 if (!tmpl || !tmpl->value) return;
5894 text = GTK_TEXT_VIEW(compose->text);
5895 buffer = gtk_text_view_get_buffer(text);
5897 if (tmpl->subject && *tmpl->subject != '\0')
5898 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5900 if (tmpl->to && *tmpl->to != '\0')
5901 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5902 if (tmpl->cc && *tmpl->cc != '\0')
5903 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5905 if (tmpl->bcc && *tmpl->bcc != '\0')
5906 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5909 gtk_text_buffer_set_text(buffer, "", -1);
5911 mark = gtk_text_buffer_get_insert(buffer);
5912 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
5914 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5915 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5918 if (prefs_common.quotemark && *prefs_common.quotemark)
5919 qmark = prefs_common.quotemark;
5923 if (compose->replyinfo != NULL)
5924 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5925 tmpl->value, qmark, NULL);
5926 else if (compose->fwdinfo != NULL)
5927 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5928 tmpl->value, qmark, NULL);
5933 if (replace && parsed_str && compose->account->auto_sig)
5934 compose_insert_sig(compose, FALSE);
5936 if (replace && parsed_str) {
5937 gtk_text_buffer_get_start_iter(buffer, &iter);
5938 gtk_text_buffer_place_cursor(buffer, &iter);
5942 cursor_pos = quote_fmt_get_cursor_pos();
5943 gtk_text_buffer_get_start_iter(buffer, &iter);
5944 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
5945 gtk_text_buffer_place_cursor(buffer, &iter);
5949 compose_changed_cb(NULL, compose);
5952 static void compose_destroy(Compose *compose)
5954 compose_list = g_list_remove(compose_list, compose);
5956 /* NOTE: address_completion_end() does nothing with the window
5957 * however this may change. */
5958 address_completion_end(compose->window);
5960 slist_free_strings(compose->to_list);
5961 g_slist_free(compose->to_list);
5962 slist_free_strings(compose->newsgroup_list);
5963 g_slist_free(compose->newsgroup_list);
5964 slist_free_strings(compose->header_list);
5965 g_slist_free(compose->header_list);
5967 procmsg_msginfo_free(compose->targetinfo);
5968 procmsg_msginfo_free(compose->replyinfo);
5969 procmsg_msginfo_free(compose->fwdinfo);
5971 g_free(compose->replyto);
5972 g_free(compose->cc);
5973 g_free(compose->bcc);
5974 g_free(compose->newsgroups);
5975 g_free(compose->followup_to);
5977 g_free(compose->ml_post);
5979 g_free(compose->inreplyto);
5980 g_free(compose->references);
5981 g_free(compose->msgid);
5982 g_free(compose->boundary);
5984 if (compose->redirect_filename)
5985 g_free(compose->redirect_filename);
5986 if (compose->undostruct)
5987 undo_destroy(compose->undostruct);
5989 g_free(compose->sig_str);
5991 g_free(compose->exteditor_file);
5993 g_free(compose->orig_charset);
5994 if (addressbook_get_target_compose() == compose)
5995 addressbook_set_target_compose(NULL);
5998 if (compose->gtkaspell) {
5999 gtkaspell_delete(compose->gtkaspell);
6000 compose->gtkaspell = NULL;
6004 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6005 prefs_common.compose_height = compose->window->allocation.height;
6007 if (!gtk_widget_get_parent(compose->paned))
6008 gtk_widget_destroy(compose->paned);
6009 gtk_widget_destroy(compose->popupmenu);
6011 gtk_widget_destroy(compose->window);
6012 toolbar_destroy(compose->toolbar);
6013 g_free(compose->toolbar);
6014 g_mutex_free(compose->mutex);
6018 static void compose_attach_info_free(AttachInfo *ainfo)
6020 g_free(ainfo->file);
6021 g_free(ainfo->content_type);
6022 g_free(ainfo->name);
6026 static void compose_attach_remove_selected(Compose *compose)
6028 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6029 GtkTreeSelection *selection;
6031 GtkTreeModel *model;
6033 selection = gtk_tree_view_get_selection(tree_view);
6034 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6039 for (cur = sel; cur != NULL; cur = cur->next) {
6040 GtkTreePath *path = cur->data;
6041 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6044 gtk_tree_path_free(path);
6047 for (cur = sel; cur != NULL; cur = cur->next) {
6048 GtkTreeRowReference *ref = cur->data;
6049 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6052 if (gtk_tree_model_get_iter(model, &iter, path))
6053 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6055 gtk_tree_path_free(path);
6056 gtk_tree_row_reference_free(ref);
6062 static struct _AttachProperty
6065 GtkWidget *mimetype_entry;
6066 GtkWidget *encoding_optmenu;
6067 GtkWidget *path_entry;
6068 GtkWidget *filename_entry;
6070 GtkWidget *cancel_btn;
6073 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6075 gtk_tree_path_free((GtkTreePath *)ptr);
6078 static void compose_attach_property(Compose *compose)
6080 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6082 GtkOptionMenu *optmenu;
6083 GtkTreeSelection *selection;
6085 GtkTreeModel *model;
6088 static gboolean cancelled;
6090 /* only if one selected */
6091 selection = gtk_tree_view_get_selection(tree_view);
6092 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6095 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6099 path = (GtkTreePath *) sel->data;
6100 gtk_tree_model_get_iter(model, &iter, path);
6101 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6104 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6110 if (!attach_prop.window)
6111 compose_attach_property_create(&cancelled);
6112 gtk_widget_grab_focus(attach_prop.ok_btn);
6113 gtk_widget_show(attach_prop.window);
6114 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6116 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6117 if (ainfo->encoding == ENC_UNKNOWN)
6118 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6119 GINT_TO_POINTER(ENC_BASE64));
6121 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6122 GINT_TO_POINTER(ainfo->encoding));
6124 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6125 ainfo->content_type ? ainfo->content_type : "");
6126 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6127 ainfo->file ? ainfo->file : "");
6128 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6129 ainfo->name ? ainfo->name : "");
6132 const gchar *entry_text;
6134 gchar *cnttype = NULL;
6138 GtkWidget *menuitem;
6143 gtk_widget_hide(attach_prop.window);
6148 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6149 if (*entry_text != '\0') {
6152 text = g_strstrip(g_strdup(entry_text));
6153 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6154 cnttype = g_strdup(text);
6157 alertpanel_error(_("Invalid MIME type."));
6163 menu = gtk_option_menu_get_menu(optmenu);
6164 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6165 ainfo->encoding = GPOINTER_TO_INT
6166 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6168 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6169 if (*entry_text != '\0') {
6170 if (is_file_exist(entry_text) &&
6171 (size = get_file_size(entry_text)) > 0)
6172 file = g_strdup(entry_text);
6175 (_("File doesn't exist or is empty."));
6181 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6182 if (*entry_text != '\0') {
6183 g_free(ainfo->name);
6184 ainfo->name = g_strdup(entry_text);
6188 g_free(ainfo->content_type);
6189 ainfo->content_type = cnttype;
6192 g_free(ainfo->file);
6198 /* update tree store */
6199 text = to_human_readable(ainfo->size);
6200 gtk_tree_model_get_iter(model, &iter, path);
6201 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6202 COL_MIMETYPE, ainfo->content_type,
6204 COL_NAME, ainfo->name,
6210 gtk_tree_path_free(path);
6213 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6215 label = gtk_label_new(str); \
6216 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6217 GTK_FILL, 0, 0, 0); \
6218 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6220 entry = gtk_entry_new(); \
6221 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6222 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6225 static void compose_attach_property_create(gboolean *cancelled)
6231 GtkWidget *mimetype_entry;
6234 GtkWidget *optmenu_menu;
6235 GtkWidget *menuitem;
6236 GtkWidget *path_entry;
6237 GtkWidget *filename_entry;
6240 GtkWidget *cancel_btn;
6241 GList *mime_type_list, *strlist;
6243 debug_print("Creating attach_property window...\n");
6245 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6246 gtk_widget_set_size_request(window, 480, -1);
6247 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6248 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6249 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6250 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6251 g_signal_connect(G_OBJECT(window), "delete_event",
6252 G_CALLBACK(attach_property_delete_event),
6254 g_signal_connect(G_OBJECT(window), "key_press_event",
6255 G_CALLBACK(attach_property_key_pressed),
6258 vbox = gtk_vbox_new(FALSE, 8);
6259 gtk_container_add(GTK_CONTAINER(window), vbox);
6261 table = gtk_table_new(4, 2, FALSE);
6262 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6263 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6264 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6266 label = gtk_label_new(_("MIME type"));
6267 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6269 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6270 mimetype_entry = gtk_combo_new();
6271 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6272 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6274 /* stuff with list */
6275 mime_type_list = procmime_get_mime_type_list();
6277 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6278 MimeType *type = (MimeType *) mime_type_list->data;
6279 strlist = g_list_append(strlist,
6280 g_strdup_printf("%s/%s",
6281 type->type, type->sub_type));
6284 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6286 for (mime_type_list = strlist; mime_type_list != NULL;
6287 mime_type_list = mime_type_list->next)
6288 g_free(mime_type_list->data);
6289 g_list_free(strlist);
6291 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6293 label = gtk_label_new(_("Encoding"));
6294 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6296 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6298 hbox = gtk_hbox_new(FALSE, 0);
6299 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6300 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6302 optmenu = gtk_option_menu_new();
6303 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6305 optmenu_menu = gtk_menu_new();
6306 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6307 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6308 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6309 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6310 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6311 ENC_QUOTED_PRINTABLE);
6312 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6314 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6316 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6318 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6319 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6321 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
6322 &cancel_btn, GTK_STOCK_CANCEL,
6324 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6325 gtk_widget_grab_default(ok_btn);
6327 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6328 G_CALLBACK(attach_property_ok),
6330 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6331 G_CALLBACK(attach_property_cancel),
6334 gtk_widget_show_all(vbox);
6336 attach_prop.window = window;
6337 attach_prop.mimetype_entry = mimetype_entry;
6338 attach_prop.encoding_optmenu = optmenu;
6339 attach_prop.path_entry = path_entry;
6340 attach_prop.filename_entry = filename_entry;
6341 attach_prop.ok_btn = ok_btn;
6342 attach_prop.cancel_btn = cancel_btn;
6345 #undef SET_LABEL_AND_ENTRY
6347 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6353 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6359 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6360 gboolean *cancelled)
6368 static gboolean attach_property_key_pressed(GtkWidget *widget,
6370 gboolean *cancelled)
6372 if (event && event->keyval == GDK_Escape) {
6379 static void compose_exec_ext_editor(Compose *compose)
6386 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6387 G_DIR_SEPARATOR, compose);
6389 if (pipe(pipe_fds) < 0) {
6395 if ((pid = fork()) < 0) {
6402 /* close the write side of the pipe */
6405 compose->exteditor_file = g_strdup(tmp);
6406 compose->exteditor_pid = pid;
6408 compose_set_ext_editor_sensitive(compose, FALSE);
6410 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6411 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6415 } else { /* process-monitoring process */
6421 /* close the read side of the pipe */
6424 if (compose_write_body_to_file(compose, tmp) < 0) {
6425 fd_write_all(pipe_fds[1], "2\n", 2);
6429 pid_ed = compose_exec_ext_editor_real(tmp);
6431 fd_write_all(pipe_fds[1], "1\n", 2);
6435 /* wait until editor is terminated */
6436 waitpid(pid_ed, NULL, 0);
6438 fd_write_all(pipe_fds[1], "0\n", 2);
6445 #endif /* G_OS_UNIX */
6449 static gint compose_exec_ext_editor_real(const gchar *file)
6451 static gchar *def_cmd = "emacs %s";
6457 g_return_val_if_fail(file != NULL, -1);
6459 if ((pid = fork()) < 0) {
6464 if (pid != 0) return pid;
6466 /* grandchild process */
6468 if (setpgid(0, getppid()))
6471 if (prefs_common.ext_editor_cmd &&
6472 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6473 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6474 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6476 if (prefs_common.ext_editor_cmd)
6477 g_warning("External editor command line is invalid: '%s'\n",
6478 prefs_common.ext_editor_cmd);
6479 g_snprintf(buf, sizeof(buf), def_cmd, file);
6482 cmdline = strsplit_with_quote(buf, " ", 1024);
6483 execvp(cmdline[0], cmdline);
6486 g_strfreev(cmdline);
6491 static gboolean compose_ext_editor_kill(Compose *compose)
6493 pid_t pgid = compose->exteditor_pid * -1;
6496 ret = kill(pgid, 0);
6498 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6502 msg = g_strdup_printf
6503 (_("The external editor is still working.\n"
6504 "Force terminating the process?\n"
6505 "process group id: %d"), -pgid);
6506 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6507 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6511 if (val == G_ALERTDEFAULT) {
6512 g_source_remove(compose->exteditor_tag);
6513 g_io_channel_shutdown(compose->exteditor_ch,
6515 g_io_channel_unref(compose->exteditor_ch);
6517 if (kill(pgid, SIGTERM) < 0) perror("kill");
6518 waitpid(compose->exteditor_pid, NULL, 0);
6520 g_warning("Terminated process group id: %d", -pgid);
6521 g_warning("Temporary file: %s",
6522 compose->exteditor_file);
6524 compose_set_ext_editor_sensitive(compose, TRUE);
6526 g_free(compose->exteditor_file);
6527 compose->exteditor_file = NULL;
6528 compose->exteditor_pid = -1;
6529 compose->exteditor_ch = NULL;
6530 compose->exteditor_tag = -1;
6538 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6542 Compose *compose = (Compose *)data;
6545 debug_print(_("Compose: input from monitoring process\n"));
6547 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6549 g_io_channel_shutdown(source, FALSE, NULL);
6550 g_io_channel_unref(source);
6552 waitpid(compose->exteditor_pid, NULL, 0);
6554 if (buf[0] == '0') { /* success */
6555 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6556 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6558 gtk_text_buffer_set_text(buffer, "", -1);
6559 compose_insert_file(compose, compose->exteditor_file);
6560 compose_changed_cb(NULL, compose);
6562 if (g_unlink(compose->exteditor_file) < 0)
6563 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6564 } else if (buf[0] == '1') { /* failed */
6565 g_warning("Couldn't exec external editor\n");
6566 if (g_unlink(compose->exteditor_file) < 0)
6567 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6568 } else if (buf[0] == '2') {
6569 g_warning("Couldn't write to file\n");
6570 } else if (buf[0] == '3') {
6571 g_warning("Pipe read failed\n");
6574 compose_set_ext_editor_sensitive(compose, TRUE);
6576 g_free(compose->exteditor_file);
6577 compose->exteditor_file = NULL;
6578 compose->exteditor_pid = -1;
6579 compose->exteditor_ch = NULL;
6580 compose->exteditor_tag = -1;
6585 static void compose_set_ext_editor_sensitive(Compose *compose,
6588 GtkItemFactory *ifactory;
6590 ifactory = gtk_item_factory_from_widget(compose->menubar);
6592 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6593 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6594 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6595 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6596 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6597 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6598 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6601 gtk_widget_set_sensitive(compose->text, sensitive);
6602 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6603 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6604 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6605 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6606 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6607 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6608 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6609 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6611 #endif /* G_OS_UNIX */
6614 * compose_undo_state_changed:
6616 * Change the sensivity of the menuentries undo and redo
6618 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6619 gint redo_state, gpointer data)
6621 GtkWidget *widget = GTK_WIDGET(data);
6622 GtkItemFactory *ifactory;
6624 g_return_if_fail(widget != NULL);
6626 ifactory = gtk_item_factory_from_widget(widget);
6628 switch (undo_state) {
6629 case UNDO_STATE_TRUE:
6630 if (!undostruct->undo_state) {
6631 undostruct->undo_state = TRUE;
6632 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6635 case UNDO_STATE_FALSE:
6636 if (undostruct->undo_state) {
6637 undostruct->undo_state = FALSE;
6638 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6641 case UNDO_STATE_UNCHANGED:
6643 case UNDO_STATE_REFRESH:
6644 menu_set_sensitive(ifactory, "/Edit/Undo",
6645 undostruct->undo_state);
6648 g_warning("Undo state not recognized");
6652 switch (redo_state) {
6653 case UNDO_STATE_TRUE:
6654 if (!undostruct->redo_state) {
6655 undostruct->redo_state = TRUE;
6656 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6659 case UNDO_STATE_FALSE:
6660 if (undostruct->redo_state) {
6661 undostruct->redo_state = FALSE;
6662 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6665 case UNDO_STATE_UNCHANGED:
6667 case UNDO_STATE_REFRESH:
6668 menu_set_sensitive(ifactory, "/Edit/Redo",
6669 undostruct->redo_state);
6672 g_warning("Redo state not recognized");
6677 /* callback functions */
6679 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6680 * includes "non-client" (windows-izm) in calculation, so this calculation
6681 * may not be accurate.
6683 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6684 GtkAllocation *allocation,
6685 GtkSHRuler *shruler)
6687 if (prefs_common.show_ruler) {
6688 gint char_width = 0, char_height = 0;
6689 gint line_width_in_chars;
6691 gtkut_get_font_size(GTK_WIDGET(widget),
6692 &char_width, &char_height);
6693 line_width_in_chars =
6694 (allocation->width - allocation->x) / char_width;
6696 /* got the maximum */
6697 gtk_ruler_set_range(GTK_RULER(shruler),
6698 0.0, line_width_in_chars, 0,
6699 /*line_width_in_chars*/ char_width);
6705 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6707 Compose *compose = (Compose *)data;
6710 gchar *folderidentifier;
6712 ac = account_find_from_id(
6713 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6714 g_return_if_fail(ac != NULL);
6716 if (ac != compose->account)
6717 compose_select_account(compose, ac, FALSE);
6719 /* Set message save folder */
6720 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6721 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6723 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6724 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6726 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6727 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6728 folderidentifier = folder_item_get_identifier(account_get_special_folder
6729 (compose->account, F_OUTBOX));
6730 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6731 g_free(folderidentifier);
6735 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6736 GtkTreeViewColumn *column, Compose *compose)
6738 compose_attach_property(compose);
6741 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6744 Compose *compose = (Compose *)data;
6745 GtkTreeSelection *attach_selection;
6746 gint attach_nr_selected;
6747 GtkItemFactory *ifactory;
6749 if (!event) return FALSE;
6751 if (event->button == 3) {
6752 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6753 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6754 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6756 if (attach_nr_selected > 0)
6758 menu_set_sensitive(ifactory, "/Remove", TRUE);
6759 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6761 menu_set_sensitive(ifactory, "/Remove", FALSE);
6762 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6765 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6766 NULL, NULL, event->button, event->time);
6773 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6776 Compose *compose = (Compose *)data;
6778 if (!event) return FALSE;
6780 switch (event->keyval) {
6782 compose_attach_remove_selected(compose);
6788 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6790 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6791 toolbar_comp_set_sensitive(compose, allow);
6792 menu_set_sensitive(ifactory, "/Message", allow);
6793 menu_set_sensitive(ifactory, "/Edit", allow);
6795 menu_set_sensitive(ifactory, "/Spelling", allow);
6797 menu_set_sensitive(ifactory, "/Options", allow);
6798 menu_set_sensitive(ifactory, "/Tools", allow);
6799 menu_set_sensitive(ifactory, "/Help", allow);
6801 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6805 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6807 Compose *compose = (Compose *)data;
6809 if (prefs_common.work_offline && !inc_offline_should_override())
6812 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6813 gtk_timeout_remove(compose->draft_timeout_tag);
6814 compose->draft_timeout_tag = -1;
6817 compose_send(compose);
6820 static void compose_send_later_cb(gpointer data, guint action,
6823 Compose *compose = (Compose *)data;
6826 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6828 compose_close(compose);
6829 else if (val == -2) {
6830 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6834 void compose_draft (gpointer data)
6836 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6839 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6841 Compose *compose = (Compose *)data;
6845 MsgFlags flag = {0, 0};
6846 static gboolean lock = FALSE;
6847 MsgInfo *newmsginfo;
6852 draft = account_get_special_folder(compose->account, F_DRAFT);
6853 g_return_if_fail(draft != NULL);
6855 if (!g_mutex_trylock(compose->mutex)) {
6856 /* we don't want to lock the mutex once it's available,
6857 * because as the only other part of compose.c locking
6858 * it is compose_close - which means once unlocked,
6859 * the compose struct will be freed */
6860 debug_print("couldn't lock mutex, probably sending\n");
6866 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6867 G_DIR_SEPARATOR, compose);
6868 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6869 FILE_OP_ERROR(tmp, "fopen");
6873 /* chmod for security */
6874 if (change_file_mode_rw(fp, tmp) < 0) {
6875 FILE_OP_ERROR(tmp, "chmod");
6876 g_warning("can't change file mode\n");
6879 /* Save draft infos */
6880 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6881 fprintf(fp, "S:%s\n", compose->account->address);
6882 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6883 gchar *savefolderid;
6885 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6886 fprintf(fp, "SCF:%s\n", savefolderid);
6887 g_free(savefolderid);
6889 if (compose->privacy_system) {
6890 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6891 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6892 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
6896 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6904 folder_item_scan(draft);
6905 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6908 if (action != COMPOSE_AUTO_SAVE)
6909 alertpanel_error(_("Could not save draft."));
6913 draft->mtime = 0; /* force updating */
6915 if (compose->mode == COMPOSE_REEDIT) {
6916 compose_remove_reedit_target(compose);
6919 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6921 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6922 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6923 if (compose_use_attach(compose))
6924 procmsg_msginfo_set_flags(newmsginfo, 0,
6925 MSG_HAS_ATTACHMENT);
6927 procmsg_msginfo_free(newmsginfo);
6930 folder_item_scan(draft);
6932 if (action == COMPOSE_QUIT_EDITING) {
6934 g_mutex_unlock(compose->mutex); /* must be done before closing */
6935 compose_close(compose);
6941 path = folder_item_fetch_msg(draft, msgnum);
6942 g_return_if_fail(path != NULL);
6943 if (g_stat(path, &s) < 0) {
6944 FILE_OP_ERROR(path, "stat");
6950 procmsg_msginfo_free(compose->targetinfo);
6951 compose->targetinfo = procmsg_msginfo_new();
6952 compose->targetinfo->msgnum = msgnum;
6953 compose->targetinfo->size = s.st_size;
6954 compose->targetinfo->mtime = s.st_mtime;
6955 compose->targetinfo->folder = draft;
6956 compose->mode = COMPOSE_REEDIT;
6958 if (action == COMPOSE_AUTO_SAVE) {
6959 compose->autosaved_draft = compose->targetinfo;
6961 compose->modified = FALSE;
6962 compose_set_title(compose);
6966 g_mutex_unlock(compose->mutex);
6969 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6971 Compose *compose = (Compose *)data;
6974 if (compose->redirect_filename != NULL)
6977 file_list = filesel_select_multiple_files_open(_("Select file"));
6982 for ( tmp = file_list; tmp; tmp = tmp->next) {
6983 gchar *file = (gchar *) tmp->data;
6984 gchar *utf8_filename = conv_filename_to_utf8(file);
6985 compose_attach_append(compose, file, utf8_filename, NULL);
6986 compose_changed_cb(NULL, compose);
6988 g_free(utf8_filename);
6990 g_list_free(file_list);
6994 static void compose_insert_file_cb(gpointer data, guint action,
6997 Compose *compose = (Compose *)data;
7000 file_list = filesel_select_multiple_files_open(_("Select file"));
7005 for ( tmp = file_list; tmp; tmp = tmp->next) {
7006 gchar *file = (gchar *) tmp->data;
7007 gchar *filedup = g_strdup(file);
7008 gchar *shortfile = g_path_get_basename(filedup);
7009 ComposeInsertResult res;
7011 res = compose_insert_file(compose, file);
7012 if (res == COMPOSE_INSERT_READ_ERROR) {
7013 alertpanel_error(_("File '%s' could not be read."), shortfile);
7014 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7015 alertpanel_error(_("File '%s' contained invalid characters\n"
7016 "for the current encoding, insertion may be incorrect."), shortfile);
7022 g_list_free(file_list);
7026 static void compose_insert_sig_cb(gpointer data, guint action,
7029 Compose *compose = (Compose *)data;
7031 compose_insert_sig(compose, FALSE);
7034 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7038 Compose *compose = (Compose *)data;
7040 gtkut_widget_get_uposition(widget, &x, &y);
7041 prefs_common.compose_x = x;
7042 prefs_common.compose_y = y;
7044 if (compose->sending)
7046 compose_close_cb(compose, 0, NULL);
7050 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7052 Compose *compose = (Compose *)data;
7056 if (compose->exteditor_tag != -1) {
7057 if (!compose_ext_editor_kill(compose))
7062 if (compose->modified) {
7063 val = alertpanel(_("Discard message"),
7064 _("This message has been modified. Discard it?"),
7065 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7068 case G_ALERTDEFAULT:
7069 if (prefs_common.autosave)
7070 compose_remove_draft(compose);
7072 case G_ALERTALTERNATE:
7073 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7080 compose_close(compose);
7083 static void compose_set_encoding_cb(gpointer data, guint action,
7086 Compose *compose = (Compose *)data;
7088 if (GTK_CHECK_MENU_ITEM(widget)->active)
7089 compose->out_encoding = (CharSet)action;
7092 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7094 Compose *compose = (Compose *)data;
7096 addressbook_open(compose);
7099 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7101 Compose *compose = (Compose *)data;
7106 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7107 g_return_if_fail(tmpl != NULL);
7109 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7111 val = alertpanel(_("Apply template"), msg,
7112 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7115 if (val == G_ALERTDEFAULT)
7116 compose_template_apply(compose, tmpl, TRUE);
7117 else if (val == G_ALERTALTERNATE)
7118 compose_template_apply(compose, tmpl, FALSE);
7121 static void compose_ext_editor_cb(gpointer data, guint action,
7124 Compose *compose = (Compose *)data;
7126 compose_exec_ext_editor(compose);
7129 static void compose_undo_cb(Compose *compose)
7131 gboolean prev_autowrap = compose->autowrap;
7133 compose->autowrap = FALSE;
7134 undo_undo(compose->undostruct);
7135 compose->autowrap = prev_autowrap;
7138 static void compose_redo_cb(Compose *compose)
7140 gboolean prev_autowrap = compose->autowrap;
7142 compose->autowrap = FALSE;
7143 undo_redo(compose->undostruct);
7144 compose->autowrap = prev_autowrap;
7147 static void entry_cut_clipboard(GtkWidget *entry)
7149 if (GTK_IS_EDITABLE(entry))
7150 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7151 else if (GTK_IS_TEXT_VIEW(entry))
7152 gtk_text_buffer_cut_clipboard(
7153 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7154 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7158 static void entry_copy_clipboard(GtkWidget *entry)
7160 if (GTK_IS_EDITABLE(entry))
7161 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7162 else if (GTK_IS_TEXT_VIEW(entry))
7163 gtk_text_buffer_copy_clipboard(
7164 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7165 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7168 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7169 gboolean wrap, GdkAtom clip)
7171 if (GTK_IS_TEXT_VIEW(entry)) {
7172 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7173 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7174 GtkTextIter start_iter, end_iter;
7177 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7179 if (contents == NULL)
7182 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7183 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7185 start = gtk_text_iter_get_offset(&start_iter);
7187 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7190 end = start + strlen(contents);
7191 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7192 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7193 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7194 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7195 mark_start = gtk_text_buffer_get_insert(buffer);
7196 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7197 gtk_text_iter_backward_char(&start_iter);
7198 compose_beautify_paragraph(compose, &start_iter, TRUE);
7201 } else if (GTK_IS_EDITABLE(entry))
7202 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7206 static void entry_allsel(GtkWidget *entry)
7208 if (GTK_IS_EDITABLE(entry))
7209 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7210 else if (GTK_IS_TEXT_VIEW(entry)) {
7211 GtkTextIter startiter, enditer;
7212 GtkTextBuffer *textbuf;
7214 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7215 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7216 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7218 gtk_text_buffer_move_mark_by_name(textbuf,
7219 "selection_bound", &startiter);
7220 gtk_text_buffer_move_mark_by_name(textbuf,
7221 "insert", &enditer);
7225 static void compose_cut_cb(Compose *compose)
7227 if (compose->focused_editable &&
7228 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7229 entry_cut_clipboard(compose->focused_editable);
7232 static void compose_copy_cb(Compose *compose)
7234 if (compose->focused_editable &&
7235 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7236 entry_copy_clipboard(compose->focused_editable);
7239 static void compose_paste_cb(Compose *compose)
7242 GtkTextBuffer *buffer;
7244 if (compose->focused_editable &&
7245 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7246 entry_paste_clipboard(compose, compose->focused_editable,
7247 prefs_common.linewrap_pastes,
7248 GDK_SELECTION_CLIPBOARD);
7252 static void compose_paste_as_quote_cb(Compose *compose)
7254 gint wrap_quote = prefs_common.linewrap_quote;
7255 if (compose->focused_editable &&
7256 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7257 /* let text_insert() (called directly or at a later time
7258 * after the gtk_editable_paste_clipboard) know that
7259 * text is to be inserted as a quotation. implemented
7260 * by using a simple refcount... */
7261 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7262 G_OBJECT(compose->focused_editable),
7263 "paste_as_quotation"));
7264 g_object_set_data(G_OBJECT(compose->focused_editable),
7265 "paste_as_quotation",
7266 GINT_TO_POINTER(paste_as_quotation + 1));
7267 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7268 entry_paste_clipboard(compose, compose->focused_editable,
7269 prefs_common.linewrap_pastes,
7270 GDK_SELECTION_CLIPBOARD);
7271 prefs_common.linewrap_quote = wrap_quote;
7275 static void compose_paste_no_wrap_cb(Compose *compose)
7278 GtkTextBuffer *buffer;
7280 if (compose->focused_editable &&
7281 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7282 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7283 GDK_SELECTION_CLIPBOARD);
7287 static void compose_paste_wrap_cb(Compose *compose)
7290 GtkTextBuffer *buffer;
7292 if (compose->focused_editable &&
7293 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7294 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7295 GDK_SELECTION_CLIPBOARD);
7299 static void compose_allsel_cb(Compose *compose)
7301 if (compose->focused_editable &&
7302 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7303 entry_allsel(compose->focused_editable);
7306 static void textview_move_beginning_of_line (GtkTextView *text)
7308 GtkTextBuffer *buffer;
7312 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7314 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7315 mark = gtk_text_buffer_get_insert(buffer);
7316 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7317 gtk_text_iter_set_line_offset(&ins, 0);
7318 gtk_text_buffer_place_cursor(buffer, &ins);
7321 static void textview_move_forward_character (GtkTextView *text)
7323 GtkTextBuffer *buffer;
7327 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7329 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7330 mark = gtk_text_buffer_get_insert(buffer);
7331 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7332 if (gtk_text_iter_forward_cursor_position(&ins))
7333 gtk_text_buffer_place_cursor(buffer, &ins);
7336 static void textview_move_backward_character (GtkTextView *text)
7338 GtkTextBuffer *buffer;
7342 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7344 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7345 mark = gtk_text_buffer_get_insert(buffer);
7346 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7347 if (gtk_text_iter_backward_cursor_position(&ins))
7348 gtk_text_buffer_place_cursor(buffer, &ins);
7351 static void textview_move_forward_word (GtkTextView *text)
7353 GtkTextBuffer *buffer;
7358 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7360 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7361 mark = gtk_text_buffer_get_insert(buffer);
7362 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7363 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7364 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7365 gtk_text_iter_backward_word_start(&ins);
7366 gtk_text_buffer_place_cursor(buffer, &ins);
7370 static void textview_move_backward_word (GtkTextView *text)
7372 GtkTextBuffer *buffer;
7377 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7379 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7380 mark = gtk_text_buffer_get_insert(buffer);
7381 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7382 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7383 if (gtk_text_iter_backward_word_starts(&ins, 1))
7384 gtk_text_buffer_place_cursor(buffer, &ins);
7387 static void textview_move_end_of_line (GtkTextView *text)
7389 GtkTextBuffer *buffer;
7393 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7395 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7396 mark = gtk_text_buffer_get_insert(buffer);
7397 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7398 if (gtk_text_iter_forward_to_line_end(&ins))
7399 gtk_text_buffer_place_cursor(buffer, &ins);
7402 static void textview_move_next_line (GtkTextView *text)
7404 GtkTextBuffer *buffer;
7409 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7411 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7412 mark = gtk_text_buffer_get_insert(buffer);
7413 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7414 offset = gtk_text_iter_get_line_offset(&ins);
7415 if (gtk_text_iter_forward_line(&ins)) {
7416 gtk_text_iter_set_line_offset(&ins, offset);
7417 gtk_text_buffer_place_cursor(buffer, &ins);
7421 static void textview_move_previous_line (GtkTextView *text)
7423 GtkTextBuffer *buffer;
7428 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7430 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7431 mark = gtk_text_buffer_get_insert(buffer);
7432 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7433 offset = gtk_text_iter_get_line_offset(&ins);
7434 if (gtk_text_iter_backward_line(&ins)) {
7435 gtk_text_iter_set_line_offset(&ins, offset);
7436 gtk_text_buffer_place_cursor(buffer, &ins);
7440 static void textview_delete_forward_character (GtkTextView *text)
7442 GtkTextBuffer *buffer;
7444 GtkTextIter ins, end_iter;
7446 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7448 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7449 mark = gtk_text_buffer_get_insert(buffer);
7450 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7452 if (gtk_text_iter_forward_char(&end_iter)) {
7453 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7457 static void textview_delete_backward_character (GtkTextView *text)
7459 GtkTextBuffer *buffer;
7461 GtkTextIter ins, end_iter;
7463 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7465 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7466 mark = gtk_text_buffer_get_insert(buffer);
7467 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7469 if (gtk_text_iter_backward_char(&end_iter)) {
7470 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7474 static void textview_delete_forward_word (GtkTextView *text)
7476 GtkTextBuffer *buffer;
7478 GtkTextIter ins, end_iter;
7480 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7482 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7483 mark = gtk_text_buffer_get_insert(buffer);
7484 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7486 if (gtk_text_iter_forward_word_end(&end_iter)) {
7487 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7491 static void textview_delete_backward_word (GtkTextView *text)
7493 GtkTextBuffer *buffer;
7495 GtkTextIter ins, end_iter;
7497 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7499 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7500 mark = gtk_text_buffer_get_insert(buffer);
7501 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7503 if (gtk_text_iter_backward_word_start(&end_iter)) {
7504 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7508 static void textview_delete_line (GtkTextView *text)
7510 GtkTextBuffer *buffer;
7512 GtkTextIter ins, start_iter, end_iter;
7515 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7517 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7518 mark = gtk_text_buffer_get_insert(buffer);
7519 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7522 gtk_text_iter_set_line_offset(&start_iter, 0);
7525 if (gtk_text_iter_ends_line(&end_iter))
7526 found = gtk_text_iter_forward_char(&end_iter);
7528 found = gtk_text_iter_forward_to_line_end(&end_iter);
7531 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7534 static void textview_delete_to_line_end (GtkTextView *text)
7536 GtkTextBuffer *buffer;
7538 GtkTextIter ins, end_iter;
7541 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7543 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7544 mark = gtk_text_buffer_get_insert(buffer);
7545 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7547 if (gtk_text_iter_ends_line(&end_iter))
7548 found = gtk_text_iter_forward_char(&end_iter);
7550 found = gtk_text_iter_forward_to_line_end(&end_iter);
7552 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7555 static void compose_advanced_action_cb(Compose *compose,
7556 ComposeCallAdvancedAction action)
7558 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7560 void (*do_action) (GtkTextView *text);
7561 } action_table[] = {
7562 {textview_move_beginning_of_line},
7563 {textview_move_forward_character},
7564 {textview_move_backward_character},
7565 {textview_move_forward_word},
7566 {textview_move_backward_word},
7567 {textview_move_end_of_line},
7568 {textview_move_next_line},
7569 {textview_move_previous_line},
7570 {textview_delete_forward_character},
7571 {textview_delete_backward_character},
7572 {textview_delete_forward_word},
7573 {textview_delete_backward_word},
7574 {textview_delete_line},
7575 {NULL}, /* gtk_stext_delete_line_n */
7576 {textview_delete_to_line_end}
7579 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7581 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7582 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7583 if (action_table[action].do_action)
7584 action_table[action].do_action(text);
7586 g_warning("Not implemented yet.");
7590 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7594 if (GTK_IS_EDITABLE(widget)) {
7595 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7596 gtk_editable_set_position(GTK_EDITABLE(widget),
7599 if (widget->parent && widget->parent->parent
7600 && widget->parent->parent->parent) {
7601 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7602 gint y = widget->allocation.y;
7603 gint height = widget->allocation.height;
7604 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7605 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7607 if (y < (int)shown->value) {
7608 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7610 if (y + height > (int)shown->value + (int)shown->page_size) {
7611 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7612 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7613 y + height - (int)shown->page_size - 1);
7615 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7616 (int)shown->upper - (int)shown->page_size - 1);
7623 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7624 compose->focused_editable = widget;
7627 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7629 compose->modified = TRUE;
7630 compose_set_title(compose);
7633 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7635 Compose *compose = (Compose *)data;
7638 compose_wrap_all_full(compose, TRUE);
7640 compose_beautify_paragraph(compose, NULL, TRUE);
7643 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7646 Compose *compose = (Compose *)data;
7647 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7648 if (compose->autowrap)
7649 compose_wrap_all_full(compose, TRUE);
7652 static void compose_toggle_sign_cb(gpointer data, guint action,
7655 Compose *compose = (Compose *)data;
7657 if (GTK_CHECK_MENU_ITEM(widget)->active)
7658 compose->use_signing = TRUE;
7660 compose->use_signing = FALSE;
7663 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7666 Compose *compose = (Compose *)data;
7668 if (GTK_CHECK_MENU_ITEM(widget)->active)
7669 compose->use_encryption = TRUE;
7671 compose->use_encryption = FALSE;
7674 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7676 g_free(compose->privacy_system);
7678 compose->privacy_system = g_strdup(account->default_privacy_system);
7679 compose_update_privacy_system_menu_item(compose, warn);
7682 static void compose_toggle_ruler_cb(gpointer data, guint action,
7685 Compose *compose = (Compose *)data;
7687 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7688 gtk_widget_show(compose->ruler_hbox);
7689 prefs_common.show_ruler = TRUE;
7691 gtk_widget_hide(compose->ruler_hbox);
7692 gtk_widget_queue_resize(compose->edit_vbox);
7693 prefs_common.show_ruler = FALSE;
7697 static void compose_attach_drag_received_cb (GtkWidget *widget,
7698 GdkDragContext *drag_context,
7701 GtkSelectionData *data,
7706 Compose *compose = (Compose *)user_data;
7709 if (gdk_atom_name(data->type) &&
7710 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7711 list = uri_list_extract_filenames((const gchar *)data->data);
7712 for (tmp = list; tmp != NULL; tmp = tmp->next)
7713 compose_attach_append
7714 (compose, (const gchar *)tmp->data,
7715 (const gchar *)tmp->data, NULL);
7716 if (list) compose_changed_cb(NULL, compose);
7717 list_free_strings(list);
7719 } else if (gdk_atom_name(data->type) &&
7720 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7721 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7722 /* comes from our summaryview */
7723 SummaryView * summaryview = NULL;
7724 GSList * list = NULL, *cur = NULL;
7726 if (mainwindow_get_mainwindow())
7727 summaryview = mainwindow_get_mainwindow()->summaryview;
7730 list = summary_get_selected_msg_list(summaryview);
7732 for (cur = list; cur; cur = cur->next) {
7733 MsgInfo *msginfo = (MsgInfo *)cur->data;
7736 file = procmsg_get_message_file_full(msginfo,
7739 compose_attach_append(compose, (const gchar *)file,
7740 (const gchar *)file, "message/rfc822");
7748 static gboolean compose_drag_drop(GtkWidget *widget,
7749 GdkDragContext *drag_context,
7751 guint time, gpointer user_data)
7753 /* not handling this signal makes compose_insert_drag_received_cb
7758 static void compose_insert_drag_received_cb (GtkWidget *widget,
7759 GdkDragContext *drag_context,
7762 GtkSelectionData *data,
7767 Compose *compose = (Compose *)user_data;
7770 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7772 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7773 list = uri_list_extract_filenames((const gchar *)data->data);
7774 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7775 compose_insert_file(compose, (const gchar *)tmp->data);
7777 list_free_strings(list);
7779 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7782 gchar *tmpfile = get_tmp_file();
7783 str_write_to_file((const gchar *)data->data, tmpfile);
7784 compose_insert_file(compose, tmpfile);
7787 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7790 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7793 static void compose_header_drag_received_cb (GtkWidget *widget,
7794 GdkDragContext *drag_context,
7797 GtkSelectionData *data,
7802 GtkEditable *entry = (GtkEditable *)user_data;
7803 gchar *email = (gchar *)data->data;
7805 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7808 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7809 gchar *decoded=g_new(gchar, strlen(email));
7812 email += strlen("mailto:");
7813 decode_uri(decoded, email); /* will fit */
7814 gtk_editable_delete_text(entry, 0, -1);
7815 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7816 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7820 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7823 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7826 Compose *compose = (Compose *)data;
7828 if (GTK_CHECK_MENU_ITEM(widget)->active)
7829 compose->return_receipt = TRUE;
7831 compose->return_receipt = FALSE;
7834 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7837 Compose *compose = (Compose *)data;
7839 if (GTK_CHECK_MENU_ITEM(widget)->active)
7840 compose->remove_references = TRUE;
7842 compose->remove_references = FALSE;
7845 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7847 ComposeHeaderEntry *headerentry)
7849 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7850 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7851 !(event->state & GDK_MODIFIER_MASK) &&
7852 (event->keyval == GDK_BackSpace) &&
7853 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7854 gtk_container_remove
7855 (GTK_CONTAINER(headerentry->compose->header_table),
7856 headerentry->combo);
7857 gtk_container_remove
7858 (GTK_CONTAINER(headerentry->compose->header_table),
7859 headerentry->entry);
7860 headerentry->compose->header_list =
7861 g_slist_remove(headerentry->compose->header_list,
7863 g_free(headerentry);
7864 } else if (event->keyval == GDK_Tab) {
7865 if (headerentry->compose->header_last == headerentry) {
7866 /* Override default next focus, and give it to subject_entry
7867 * instead of notebook tabs
7869 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
7870 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7877 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
7878 ComposeHeaderEntry *headerentry)
7880 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7881 headerentry->compose->header_list =
7882 g_slist_append(headerentry->compose->header_list,
7885 compose_create_header_entry(headerentry->compose);
7886 g_signal_handlers_disconnect_matched
7887 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
7888 0, 0, NULL, NULL, headerentry);
7890 /* Automatically scroll down */
7891 compose_show_first_last_header(headerentry->compose, FALSE);
7897 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7899 GtkAdjustment *vadj;
7901 g_return_if_fail(compose);
7902 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7903 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7905 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7906 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7909 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
7910 const gchar *text, gint len, Compose *compose)
7912 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
7913 (G_OBJECT(compose->text), "paste_as_quotation"));
7916 g_return_if_fail(text != NULL);
7918 g_signal_handlers_block_by_func(G_OBJECT(buffer),
7919 G_CALLBACK(text_inserted),
7921 if (paste_as_quotation) {
7928 new_text = g_strndup(text, len);
7929 if (prefs_common.quotemark && *prefs_common.quotemark)
7930 qmark = prefs_common.quotemark;
7934 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
7935 gtk_text_buffer_place_cursor(buffer, iter);
7937 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
7939 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
7940 GINT_TO_POINTER(paste_as_quotation - 1));
7942 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
7944 gtk_text_buffer_insert(buffer, iter, text, len);
7946 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
7948 compose_beautify_paragraph(compose, iter, FALSE);
7950 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
7951 gtk_text_buffer_delete_mark(buffer, mark);
7953 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
7954 G_CALLBACK(text_inserted),
7956 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
7958 if (prefs_common.autosave &&
7959 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
7960 compose->draft_timeout_tag = gtk_timeout_add
7961 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
7963 static gint compose_defer_auto_save_draft(Compose *compose)
7965 compose->draft_timeout_tag = -1;
7966 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
7971 static void compose_check_all(Compose *compose)
7973 if (compose->gtkaspell)
7974 gtkaspell_check_all(compose->gtkaspell);
7977 static void compose_highlight_all(Compose *compose)
7979 if (compose->gtkaspell)
7980 gtkaspell_highlight_all(compose->gtkaspell);
7983 static void compose_check_backwards(Compose *compose)
7985 if (compose->gtkaspell)
7986 gtkaspell_check_backwards(compose->gtkaspell);
7988 GtkItemFactory *ifactory;
7989 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7990 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7991 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7995 static void compose_check_forwards_go(Compose *compose)
7997 if (compose->gtkaspell)
7998 gtkaspell_check_forwards_go(compose->gtkaspell);
8000 GtkItemFactory *ifactory;
8001 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8002 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8003 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8009 *\brief Guess originating forward account from MsgInfo and several
8010 * "common preference" settings. Return NULL if no guess.
8012 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8014 PrefsAccount *account = NULL;
8016 g_return_val_if_fail(msginfo, NULL);
8017 g_return_val_if_fail(msginfo->folder, NULL);
8018 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8020 if (msginfo->folder->prefs->enable_default_account)
8021 account = account_find_from_id(msginfo->folder->prefs->default_account);
8024 account = msginfo->folder->folder->account;
8026 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8028 Xstrdup_a(to, msginfo->to, return NULL);
8029 extract_address(to);
8030 account = account_find_from_address(to);
8033 if (!account && prefs_common.forward_account_autosel) {
8035 if (!procheader_get_header_from_msginfo
8036 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8037 extract_address(cc);
8038 account = account_find_from_address(cc);
8045 static gboolean compose_close(Compose *compose)
8049 if (!g_mutex_trylock(compose->mutex)) {
8050 /* we have to wait for the (possibly deferred by auto-save)
8051 * drafting to be done, before destroying the compose under
8053 debug_print("waiting for drafting to finish...\n");
8054 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8057 g_return_val_if_fail(compose, FALSE);
8058 gtkut_widget_get_uposition(compose->window, &x, &y);
8059 prefs_common.compose_x = x;
8060 prefs_common.compose_y = y;
8061 g_mutex_unlock(compose->mutex);
8062 compose_destroy(compose);
8067 * Add entry field for each address in list.
8068 * \param compose E-Mail composition object.
8069 * \param listAddress List of (formatted) E-Mail addresses.
8071 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8076 addr = ( gchar * ) node->data;
8077 compose_entry_append( compose, addr, COMPOSE_TO );
8078 node = g_list_next( node );
8082 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8086 GSList *new_msglist = NULL;
8087 MsgInfo *tmp_msginfo = NULL;
8088 gboolean originally_enc = FALSE;
8089 Compose *compose = NULL;
8091 g_return_if_fail(msgview != NULL);
8093 g_return_if_fail(msginfo_list != NULL);
8095 if (g_slist_length(msginfo_list) == 1) {
8096 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8097 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8099 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8100 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8101 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8102 orig_msginfo, mimeinfo);
8103 if (tmp_msginfo != NULL) {
8104 new_msglist = g_slist_append(NULL, tmp_msginfo);
8105 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8106 originally_enc = TRUE;
8112 body = messageview_get_selection(msgview);
8115 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8116 procmsg_msginfo_free(tmp_msginfo);
8117 g_slist_free(new_msglist);
8119 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8121 if (originally_enc) {
8122 compose_force_encryption(compose, compose->account, FALSE);