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},
636 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
639 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
640 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
641 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
642 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
643 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
644 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
645 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
646 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
647 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
648 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
650 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
651 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
652 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 #define ENC_ACTION(action) \
655 NULL, compose_set_encoding_cb, action, \
656 "/Options/Character encoding/Automatic"
658 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Options/Character _encoding/_Automatic"),
660 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
661 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
664 ENC_ACTION(C_US_ASCII)},
665 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
666 ENC_ACTION(C_UTF_8)},
667 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
669 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
670 ENC_ACTION(C_ISO_8859_1)},
671 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
672 ENC_ACTION(C_ISO_8859_15)},
673 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
674 ENC_ACTION(C_WINDOWS_1252)},
675 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
677 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
678 ENC_ACTION(C_ISO_8859_2)},
679 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
681 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
682 ENC_ACTION(C_ISO_8859_13)},
683 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
684 ENC_ACTION(C_ISO_8859_4)},
685 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
687 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
688 ENC_ACTION(C_ISO_8859_7)},
689 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
691 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
692 ENC_ACTION(C_ISO_8859_8)},
693 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
694 ENC_ACTION(C_WINDOWS_1255)},
695 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
697 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
698 ENC_ACTION(C_ISO_8859_9)},
699 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
701 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
702 ENC_ACTION(C_ISO_8859_5)},
703 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
704 ENC_ACTION(C_KOI8_R)},
705 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
706 ENC_ACTION(C_KOI8_U)},
707 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
708 ENC_ACTION(C_WINDOWS_1251)},
709 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
711 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
712 ENC_ACTION(C_ISO_2022_JP)},
713 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
715 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
716 ENC_ACTION(C_GB2312)},
717 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
719 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
721 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
722 ENC_ACTION(C_EUC_TW)},
723 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
725 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
726 ENC_ACTION(C_EUC_KR)},
727 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
729 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
730 ENC_ACTION(C_TIS_620)},
731 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
732 ENC_ACTION(C_WINDOWS_874)},
734 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
735 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
736 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
737 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
738 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
739 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
740 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
743 static GtkTargetEntry compose_mime_types[] =
745 {"text/uri-list", 0, 0},
746 {"text/plain", 0, 0},
750 static gboolean compose_put_existing_to_front(MsgInfo *info)
752 GList *compose_list = compose_get_compose_list();
756 for (elem = compose_list; elem != NULL && elem->data != NULL;
758 Compose *c = (Compose*)elem->data;
760 if (!c->targetinfo || !c->targetinfo->msgid ||
764 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
765 gtkut_window_popup(c->window);
773 static GdkColor quote_color =
774 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
776 static GdkColor signature_color = {
783 static GdkColor uri_color = {
790 static void compose_create_tags(GtkTextView *text, Compose *compose)
792 GtkTextBuffer *buffer;
793 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
795 buffer = gtk_text_view_get_buffer(text);
797 if (prefs_common.enable_color) {
798 /* grab the quote colors, converting from an int to a GdkColor */
799 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
801 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
803 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
806 signature_color = quote_color = uri_color = black;
809 gtk_text_buffer_create_tag(buffer, "quote",
810 "foreground-gdk", "e_color,
812 gtk_text_buffer_create_tag(buffer, "signature",
813 "foreground-gdk", &signature_color,
815 gtk_text_buffer_create_tag(buffer, "link",
816 "foreground-gdk", &uri_color,
818 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
821 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
822 GPtrArray *attach_files)
824 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
827 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
829 return compose_generic_new(account, NULL, item, NULL, NULL);
832 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
834 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
837 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
838 GPtrArray *attach_files, GList *listAddress )
841 GtkTextView *textview;
842 GtkTextBuffer *textbuf;
844 GtkItemFactory *ifactory;
846 if (item && item->prefs && item->prefs->enable_default_account)
847 account = account_find_from_id(item->prefs->default_account);
849 if (!account) account = cur_account;
850 g_return_val_if_fail(account != NULL, NULL);
852 compose = compose_create(account, COMPOSE_NEW);
853 ifactory = gtk_item_factory_from_widget(compose->menubar);
855 compose->replyinfo = NULL;
856 compose->fwdinfo = NULL;
858 textview = GTK_TEXT_VIEW(compose->text);
859 textbuf = gtk_text_view_get_buffer(textview);
860 compose_create_tags(textview, compose);
862 undo_block(compose->undostruct);
864 if (item && item->prefs && item->prefs->enable_default_dictionary &&
866 gtkaspell_change_dict(compose->gtkaspell,
867 item->prefs->default_dictionary);
870 if (account->auto_sig)
871 compose_insert_sig(compose, FALSE);
872 gtk_text_buffer_get_start_iter(textbuf, &iter);
873 gtk_text_buffer_place_cursor(textbuf, &iter);
875 if (account->protocol != A_NNTP) {
876 if (mailto && *mailto != '\0') {
877 compose_entries_set(compose, mailto);
879 } else if (item && item->prefs->enable_default_to) {
880 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
881 compose_entry_mark_default_to(compose, item->prefs->default_to);
883 if (item && item->ret_rcpt) {
884 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
888 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
890 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
893 * CLAWS: just don't allow return receipt request, even if the user
894 * may want to send an email. simple but foolproof.
896 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
898 compose_add_field_list( compose, listAddress );
904 for (i = 0; i < attach_files->len; i++) {
905 file = g_ptr_array_index(attach_files, i);
906 compose_attach_append(compose, file, file, NULL);
910 compose_show_first_last_header(compose, TRUE);
912 /* Set save folder */
913 if (item && item->prefs && item->prefs->save_copy_to_folder) {
914 gchar *folderidentifier;
916 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
917 folderidentifier = folder_item_get_identifier(item);
918 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
919 g_free(folderidentifier);
922 gtk_widget_grab_focus(compose->header_last->entry);
924 undo_unblock(compose->undostruct);
926 if (prefs_common.auto_exteditor)
927 compose_exec_ext_editor(compose);
929 compose_set_title(compose);
933 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
934 gboolean override_pref)
936 gchar *privacy = NULL;
938 g_return_if_fail(compose != NULL);
939 g_return_if_fail(account != NULL);
941 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
944 if (account->default_privacy_system
945 && strlen(account->default_privacy_system)) {
946 privacy = account->default_privacy_system;
948 GSList *privacy_avail = privacy_get_system_ids();
949 if (privacy_avail && g_slist_length(privacy_avail)) {
950 privacy = (gchar *)(privacy_avail->data);
953 if (privacy != NULL) {
954 compose->privacy_system = g_strdup(privacy);
955 compose_update_privacy_system_menu_item(compose, FALSE);
956 compose_use_encryption(compose, TRUE);
960 static void compose_force_signing(Compose *compose, PrefsAccount *account)
962 gchar *privacy = NULL;
964 if (account->default_privacy_system
965 && strlen(account->default_privacy_system)) {
966 privacy = account->default_privacy_system;
968 GSList *privacy_avail = privacy_get_system_ids();
969 if (privacy_avail && g_slist_length(privacy_avail)) {
970 privacy = (gchar *)(privacy_avail->data);
973 if (privacy != NULL) {
974 compose->privacy_system = g_strdup(privacy);
975 compose_update_privacy_system_menu_item(compose, FALSE);
976 compose_use_signing(compose, TRUE);
980 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
984 Compose *compose = NULL;
985 g_return_val_if_fail(msginfo_list != NULL, NULL);
987 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
988 g_return_val_if_fail(msginfo != NULL, NULL);
990 list_len = g_slist_length(msginfo_list);
994 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
995 FALSE, prefs_common.default_reply_list, FALSE, body);
997 case COMPOSE_REPLY_WITH_QUOTE:
998 compose = compose_reply(msginfo, TRUE,
999 FALSE, prefs_common.default_reply_list, FALSE, body);
1001 case COMPOSE_REPLY_WITHOUT_QUOTE:
1002 compose = compose_reply(msginfo, FALSE,
1003 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1005 case COMPOSE_REPLY_TO_SENDER:
1006 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1007 FALSE, FALSE, TRUE, body);
1009 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1010 compose = compose_followup_and_reply_to(msginfo,
1011 prefs_common.reply_with_quote,
1012 FALSE, FALSE, body);
1014 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1015 compose = compose_reply(msginfo, TRUE,
1016 FALSE, FALSE, TRUE, body);
1018 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1019 compose = compose_reply(msginfo, FALSE,
1020 FALSE, FALSE, TRUE, NULL);
1022 case COMPOSE_REPLY_TO_ALL:
1023 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1024 TRUE, FALSE, FALSE, body);
1026 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1027 compose = compose_reply(msginfo, TRUE,
1028 TRUE, FALSE, FALSE, body);
1030 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1031 compose = compose_reply(msginfo, FALSE,
1032 TRUE, FALSE, FALSE, NULL);
1034 case COMPOSE_REPLY_TO_LIST:
1035 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1036 FALSE, TRUE, FALSE, body);
1038 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1039 compose = compose_reply(msginfo, TRUE,
1040 FALSE, TRUE, FALSE, body);
1042 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1043 compose = compose_reply(msginfo, FALSE,
1044 FALSE, TRUE, FALSE, NULL);
1046 case COMPOSE_FORWARD:
1047 if (prefs_common.forward_as_attachment) {
1048 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1051 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1055 case COMPOSE_FORWARD_INLINE:
1056 /* check if we reply to more than one Message */
1057 if (list_len == 1) {
1058 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1061 /* more messages FALL THROUGH */
1062 case COMPOSE_FORWARD_AS_ATTACH:
1063 compose = compose_forward_multiple(NULL, msginfo_list);
1065 case COMPOSE_REDIRECT:
1066 compose = compose_redirect(NULL, msginfo);
1069 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1074 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1075 gboolean to_ml, gboolean to_sender,
1078 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1079 to_sender, FALSE, body);
1082 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1087 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1088 to_sender, TRUE, body);
1091 static void compose_extract_original_charset(Compose *compose)
1093 MsgInfo *info = NULL;
1094 if (compose->replyinfo) {
1095 info = compose->replyinfo;
1096 } else if (compose->fwdinfo) {
1097 info = compose->fwdinfo;
1098 } else if (compose->targetinfo) {
1099 info = compose->targetinfo;
1102 MimeInfo *mimeinfo = procmime_scan_message(info);
1103 MimeInfo *partinfo = mimeinfo;
1104 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1105 partinfo = procmime_mimeinfo_next(partinfo);
1107 compose->orig_charset =
1108 g_strdup(procmime_mimeinfo_get_parameter(
1109 partinfo, "charset"));
1111 procmime_mimeinfo_free_all(mimeinfo);
1115 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1116 gboolean to_all, gboolean to_ml,
1118 gboolean followup_and_reply_to,
1121 GtkItemFactory *ifactory;
1123 PrefsAccount *account = NULL;
1124 PrefsAccount *reply_account;
1125 GtkTextView *textview;
1126 GtkTextBuffer *textbuf;
1128 g_return_val_if_fail(msginfo != NULL, NULL);
1129 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1131 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1133 g_return_val_if_fail(account != NULL, NULL);
1135 if (to_sender && account->protocol == A_NNTP &&
1136 !followup_and_reply_to) {
1138 account_find_from_address(account->address);
1140 reply_account = compose_current_mail_account();
1144 reply_account = account;
1146 compose = compose_create(account, COMPOSE_REPLY);
1147 ifactory = gtk_item_factory_from_widget(compose->menubar);
1149 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1150 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1152 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1154 if (!compose->replyinfo)
1155 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1157 compose_extract_original_charset(compose);
1159 if (msginfo->folder && msginfo->folder->ret_rcpt)
1160 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1162 /* Set save folder */
1163 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1164 gchar *folderidentifier;
1166 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1167 folderidentifier = folder_item_get_identifier(msginfo->folder);
1168 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1169 g_free(folderidentifier);
1172 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1173 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1174 to_sender, followup_and_reply_to);
1175 compose_show_first_last_header(compose, TRUE);
1177 textview = (GTK_TEXT_VIEW(compose->text));
1178 textbuf = gtk_text_view_get_buffer(textview);
1179 compose_create_tags(textview, compose);
1181 undo_block(compose->undostruct);
1183 if (msginfo->folder && msginfo->folder->prefs &&
1184 msginfo->folder->prefs &&
1185 msginfo->folder->prefs->enable_default_dictionary &&
1187 gtkaspell_change_dict(compose->gtkaspell,
1188 msginfo->folder->prefs->default_dictionary);
1194 if (prefs_common.quotemark && *prefs_common.quotemark)
1195 qmark = prefs_common.quotemark;
1199 compose_quote_fmt(compose, compose->replyinfo,
1200 prefs_common.quotefmt,
1203 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1204 compose_force_encryption(compose, account, FALSE);
1207 if (account->auto_sig)
1208 compose_insert_sig(compose, FALSE);
1210 compose_wrap_all(compose);
1212 gtk_widget_grab_focus(compose->text);
1214 undo_unblock(compose->undostruct);
1216 if (prefs_common.auto_exteditor)
1217 compose_exec_ext_editor(compose);
1219 compose_set_title(compose);
1223 #define INSERT_FW_HEADER(var, hdr) \
1224 if (msginfo->var && *msginfo->var) { \
1225 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1226 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1227 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1230 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1231 gboolean as_attach, const gchar *body,
1232 gboolean no_extedit)
1235 GtkTextView *textview;
1236 GtkTextBuffer *textbuf;
1239 g_return_val_if_fail(msginfo != NULL, NULL);
1240 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1243 !(account = compose_guess_forward_account_from_msginfo
1245 account = cur_account;
1247 compose = compose_create(account, COMPOSE_FORWARD);
1249 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1250 if (!compose->fwdinfo)
1251 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1253 compose_extract_original_charset(compose);
1255 if (msginfo->subject && *msginfo->subject) {
1256 gchar *buf, *buf2, *p;
1258 buf = p = g_strdup(msginfo->subject);
1259 p += subject_get_prefix_length(p);
1260 memmove(buf, p, strlen(p) + 1);
1262 buf2 = g_strdup_printf("Fw: %s", buf);
1263 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1269 textview = GTK_TEXT_VIEW(compose->text);
1270 textbuf = gtk_text_view_get_buffer(textview);
1271 compose_create_tags(textview, compose);
1276 msgfile = procmsg_get_message_file_path(msginfo);
1277 if (!is_file_exist(msgfile))
1278 g_warning("%s: file not exist\n", msgfile);
1280 compose_attach_append(compose, msgfile, msgfile,
1286 MsgInfo *full_msginfo;
1288 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1290 full_msginfo = procmsg_msginfo_copy(msginfo);
1292 if (prefs_common.fw_quotemark &&
1293 *prefs_common.fw_quotemark)
1294 qmark = prefs_common.fw_quotemark;
1298 compose_quote_fmt(compose, full_msginfo,
1299 prefs_common.fw_quotefmt,
1301 compose_attach_parts(compose, msginfo);
1303 procmsg_msginfo_free(full_msginfo);
1306 if (account->auto_sig)
1307 compose_insert_sig(compose, FALSE);
1309 compose_wrap_all(compose);
1311 gtk_text_buffer_get_start_iter(textbuf, &iter);
1312 gtk_text_buffer_place_cursor(textbuf, &iter);
1314 gtk_widget_grab_focus(compose->header_last->entry);
1316 if (!no_extedit && prefs_common.auto_exteditor)
1317 compose_exec_ext_editor(compose);
1320 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1321 gchar *folderidentifier;
1323 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1324 folderidentifier = folder_item_get_identifier(msginfo->folder);
1325 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1326 g_free(folderidentifier);
1329 compose_set_title(compose);
1333 #undef INSERT_FW_HEADER
1335 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1338 GtkTextView *textview;
1339 GtkTextBuffer *textbuf;
1343 gboolean single_mail = TRUE;
1345 g_return_val_if_fail(msginfo_list != NULL, NULL);
1347 if (g_slist_length(msginfo_list) > 1)
1348 single_mail = FALSE;
1350 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1351 if (((MsgInfo *)msginfo->data)->folder == NULL)
1354 /* guess account from first selected message */
1356 !(account = compose_guess_forward_account_from_msginfo
1357 (msginfo_list->data)))
1358 account = cur_account;
1360 g_return_val_if_fail(account != NULL, NULL);
1362 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1363 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1364 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1367 compose = compose_create(account, COMPOSE_FORWARD);
1369 textview = GTK_TEXT_VIEW(compose->text);
1370 textbuf = gtk_text_view_get_buffer(textview);
1371 compose_create_tags(textview, compose);
1373 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1374 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1375 if (!is_file_exist(msgfile))
1376 g_warning("%s: file not exist\n", msgfile);
1378 compose_attach_append(compose, msgfile, msgfile,
1384 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1385 if (info->subject && *info->subject) {
1386 gchar *buf, *buf2, *p;
1388 buf = p = g_strdup(info->subject);
1389 p += subject_get_prefix_length(p);
1390 memmove(buf, p, strlen(p) + 1);
1392 buf2 = g_strdup_printf("Fw: %s", buf);
1393 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1399 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1400 _("Fw: multiple emails"));
1403 if (account->auto_sig)
1404 compose_insert_sig(compose, FALSE);
1406 compose_wrap_all(compose);
1408 gtk_text_buffer_get_start_iter(textbuf, &iter);
1409 gtk_text_buffer_place_cursor(textbuf, &iter);
1411 gtk_widget_grab_focus(compose->header_last->entry);
1413 compose_set_title(compose);
1417 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1419 GtkTextIter start = *iter;
1420 GtkTextIter end_iter;
1421 int start_pos = gtk_text_iter_get_offset(&start);
1423 if (!compose->account->sig_sep)
1426 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1427 start_pos+strlen(compose->account->sig_sep));
1429 /* check sig separator */
1430 str = gtk_text_iter_get_text(&start, &end_iter);
1431 if (!strcmp(str, compose->account->sig_sep)) {
1433 /* check end of line (\n) */
1434 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1435 start_pos+strlen(compose->account->sig_sep));
1436 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1437 start_pos+strlen(compose->account->sig_sep)+1);
1438 tmp = gtk_text_iter_get_text(&start, &end_iter);
1439 if (!strcmp(tmp,"\n")) {
1451 static void compose_colorize_signature(Compose *compose)
1453 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1455 GtkTextIter end_iter;
1456 gtk_text_buffer_get_start_iter(buffer, &iter);
1457 while (gtk_text_iter_forward_line(&iter))
1458 if (compose_is_sig_separator(compose, buffer, &iter)) {
1459 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1460 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1464 void compose_reedit(MsgInfo *msginfo)
1466 Compose *compose = NULL;
1467 PrefsAccount *account = NULL;
1468 GtkTextView *textview;
1469 GtkTextBuffer *textbuf;
1473 gchar buf[BUFFSIZE];
1474 gboolean use_signing = FALSE;
1475 gboolean use_encryption = FALSE;
1476 gchar *privacy_system = NULL;
1478 g_return_if_fail(msginfo != NULL);
1479 g_return_if_fail(msginfo->folder != NULL);
1481 if (compose_put_existing_to_front(msginfo))
1484 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1485 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1486 gchar queueheader_buf[BUFFSIZE];
1489 /* Select Account from queue headers */
1490 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1491 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1492 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1493 account = account_find_from_id(id);
1495 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1496 sizeof(queueheader_buf), "NAID:")) {
1497 id = atoi(&queueheader_buf[strlen("NAID:")]);
1498 account = account_find_from_id(id);
1500 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1501 sizeof(queueheader_buf), "MAID:")) {
1502 id = atoi(&queueheader_buf[strlen("MAID:")]);
1503 account = account_find_from_id(id);
1505 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1506 sizeof(queueheader_buf), "S:")) {
1507 account = account_find_from_address(queueheader_buf);
1509 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1510 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1511 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1512 use_signing = param;
1515 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1516 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1517 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1518 use_encryption = param;
1520 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1521 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1522 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1524 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1525 sizeof(queueheader_buf), "X-Priority: ")) {
1526 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1527 compose->priority = param;
1530 account = msginfo->folder->folder->account;
1532 if (!account && prefs_common.reedit_account_autosel) {
1533 gchar from[BUFFSIZE];
1534 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1535 extract_address(from);
1536 account = account_find_from_address(from);
1539 if (!account) account = cur_account;
1540 g_return_if_fail(account != NULL);
1542 compose = compose_create(account, COMPOSE_REEDIT);
1543 if (privacy_system != NULL) {
1544 compose->privacy_system = privacy_system;
1545 compose_use_signing(compose, use_signing);
1546 compose_use_encryption(compose, use_encryption);
1547 compose_update_privacy_system_menu_item(compose, FALSE);
1549 activate_privacy_system(compose, account, FALSE);
1551 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1553 compose_extract_original_charset(compose);
1555 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1556 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1557 gchar queueheader_buf[BUFFSIZE];
1559 /* Set message save folder */
1560 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1563 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1564 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1565 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1567 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1568 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1570 GtkItemFactory *ifactory;
1571 ifactory = gtk_item_factory_from_widget(compose->menubar);
1572 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1577 if (compose_parse_header(compose, msginfo) < 0) return;
1578 compose_reedit_set_entry(compose, msginfo);
1580 textview = GTK_TEXT_VIEW(compose->text);
1581 textbuf = gtk_text_view_get_buffer(textview);
1582 compose_create_tags(textview, compose);
1584 mark = gtk_text_buffer_get_insert(textbuf);
1585 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1587 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1588 G_CALLBACK(compose_changed_cb),
1591 if (procmime_msginfo_is_encrypted(msginfo)) {
1592 fp = procmime_get_first_encrypted_text_content(msginfo);
1594 compose_force_encryption(compose, account, TRUE);
1596 fp = procmime_get_first_text_content(msginfo);
1598 g_warning("Can't get text part\n");
1601 gboolean prev_autowrap = compose->autowrap;
1603 compose->autowrap = FALSE;
1604 while (fgets(buf, sizeof(buf), fp) != NULL) {
1606 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1608 compose_wrap_all_full(compose, FALSE);
1609 compose->autowrap = prev_autowrap;
1613 compose_attach_parts(compose, msginfo);
1615 compose_colorize_signature(compose);
1617 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1618 G_CALLBACK(compose_changed_cb),
1621 gtk_widget_grab_focus(compose->text);
1623 if (prefs_common.auto_exteditor)
1624 compose_exec_ext_editor(compose);
1625 compose_set_title(compose);
1628 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1632 GtkItemFactory *ifactory;
1635 g_return_val_if_fail(msginfo != NULL, NULL);
1638 account = account_get_reply_account(msginfo,
1639 prefs_common.reply_account_autosel);
1640 g_return_val_if_fail(account != NULL, NULL);
1642 compose = compose_create(account, COMPOSE_REDIRECT);
1643 ifactory = gtk_item_factory_from_widget(compose->menubar);
1644 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1645 compose->replyinfo = NULL;
1646 compose->fwdinfo = NULL;
1648 compose_show_first_last_header(compose, TRUE);
1650 gtk_widget_grab_focus(compose->header_last->entry);
1652 filename = procmsg_get_message_file_path(msginfo);
1653 if (filename == NULL)
1656 compose->redirect_filename = filename;
1658 /* Set save folder */
1659 item = msginfo->folder;
1660 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1661 gchar *folderidentifier;
1663 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1664 folderidentifier = folder_item_get_identifier(item);
1665 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1666 g_free(folderidentifier);
1669 compose_attach_parts(compose, msginfo);
1671 if (msginfo->subject)
1672 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1674 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1676 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1677 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1679 compose_colorize_signature(compose);
1681 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1682 menu_set_sensitive(ifactory, "/Add...", FALSE);
1683 menu_set_sensitive(ifactory, "/Remove", FALSE);
1684 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1686 ifactory = gtk_item_factory_from_widget(compose->menubar);
1687 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1688 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1689 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1690 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1691 menu_set_sensitive(ifactory, "/Edit", FALSE);
1692 menu_set_sensitive(ifactory, "/Options", FALSE);
1693 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1694 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1696 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1697 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1698 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1699 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1700 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1701 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1702 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1704 compose_set_title(compose);
1708 GList *compose_get_compose_list(void)
1710 return compose_list;
1713 void compose_entry_append(Compose *compose, const gchar *address,
1714 ComposeEntryType type)
1718 gboolean in_quote = FALSE;
1719 if (!address || *address == '\0') return;
1726 header = N_("Bcc:");
1728 case COMPOSE_REPLYTO:
1729 header = N_("Reply-To:");
1731 case COMPOSE_NEWSGROUPS:
1732 header = N_("Newsgroups:");
1734 case COMPOSE_FOLLOWUPTO:
1735 header = N_( "Followup-To:");
1742 header = prefs_common.trans_hdr ? gettext(header) : header;
1744 cur = begin = (gchar *)address;
1746 /* we separate the line by commas, but not if we're inside a quoted
1748 while (*cur != '\0') {
1750 in_quote = !in_quote;
1751 if (*cur == ',' && !in_quote) {
1752 gchar *tmp = g_strdup(begin);
1754 tmp[cur-begin]='\0';
1759 compose_add_header_entry(compose, header, tmp);
1766 gchar *tmp = g_strdup(begin);
1768 tmp[cur-begin]='\0';
1773 compose_add_header_entry(compose, header, tmp);
1778 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1780 static GtkStyle *bold_style = NULL;
1781 static GdkColor bold_color;
1785 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1786 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1787 if (gtk_entry_get_text(entry) &&
1788 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1789 gtk_widget_ensure_style(GTK_WIDGET(entry));
1791 gtkut_convert_int_to_gdk_color
1792 (prefs_common.color_new, &bold_color);
1793 bold_style = gtk_style_copy(gtk_widget_get_style
1794 (GTK_WIDGET(entry)));
1795 pango_font_description_set_weight
1796 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
1797 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1799 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1804 void compose_toolbar_cb(gint action, gpointer data)
1806 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1807 Compose *compose = (Compose*)toolbar_item->parent;
1809 g_return_if_fail(compose != NULL);
1813 compose_send_cb(compose, 0, NULL);
1816 compose_send_later_cb(compose, 0, NULL);
1819 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1822 compose_insert_file_cb(compose, 0, NULL);
1825 compose_attach_cb(compose, 0, NULL);
1828 compose_insert_sig(compose, FALSE);
1831 compose_ext_editor_cb(compose, 0, NULL);
1833 case A_LINEWRAP_CURRENT:
1834 compose_beautify_paragraph(compose, NULL, TRUE);
1836 case A_LINEWRAP_ALL:
1837 compose_wrap_all_full(compose, TRUE);
1840 compose_address_cb(compose, 0, NULL);
1843 case A_CHECK_SPELLING:
1844 compose_check_all(compose);
1852 static void compose_entries_set(Compose *compose, const gchar *mailto)
1856 gchar *subject = NULL;
1861 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1864 compose_entry_append(compose, to, COMPOSE_TO);
1866 compose_entry_append(compose, cc, COMPOSE_CC);
1868 if (!g_utf8_validate (subject, -1, NULL)) {
1869 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1870 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1873 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1877 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1878 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1881 gboolean prev_autowrap = compose->autowrap;
1883 compose->autowrap = FALSE;
1885 mark = gtk_text_buffer_get_insert(buffer);
1886 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1888 if (!g_utf8_validate (body, -1, NULL)) {
1889 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1890 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1893 gtk_text_buffer_insert(buffer, &iter, body, -1);
1895 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1897 compose->autowrap = prev_autowrap;
1898 if (compose->autowrap)
1899 compose_wrap_all(compose);
1908 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1910 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1911 {"Cc:", NULL, TRUE},
1912 {"References:", NULL, FALSE},
1913 {"Bcc:", NULL, TRUE},
1914 {"Newsgroups:", NULL, TRUE},
1915 {"Followup-To:", NULL, TRUE},
1916 {"List-Post:", NULL, FALSE},
1917 {"X-Priority:", NULL, FALSE},
1918 {NULL, NULL, FALSE}};
1934 g_return_val_if_fail(msginfo != NULL, -1);
1936 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1937 procheader_get_header_fields(fp, hentry);
1940 if (hentry[H_REPLY_TO].body != NULL) {
1941 if (hentry[H_REPLY_TO].body[0] != '\0') {
1943 conv_unmime_header(hentry[H_REPLY_TO].body,
1946 g_free(hentry[H_REPLY_TO].body);
1947 hentry[H_REPLY_TO].body = NULL;
1949 if (hentry[H_CC].body != NULL) {
1950 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1951 g_free(hentry[H_CC].body);
1952 hentry[H_CC].body = NULL;
1954 if (hentry[H_REFERENCES].body != NULL) {
1955 if (compose->mode == COMPOSE_REEDIT)
1956 compose->references = hentry[H_REFERENCES].body;
1958 compose->references = compose_parse_references
1959 (hentry[H_REFERENCES].body, msginfo->msgid);
1960 g_free(hentry[H_REFERENCES].body);
1962 hentry[H_REFERENCES].body = NULL;
1964 if (hentry[H_BCC].body != NULL) {
1965 if (compose->mode == COMPOSE_REEDIT)
1967 conv_unmime_header(hentry[H_BCC].body, NULL);
1968 g_free(hentry[H_BCC].body);
1969 hentry[H_BCC].body = NULL;
1971 if (hentry[H_NEWSGROUPS].body != NULL) {
1972 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1973 hentry[H_NEWSGROUPS].body = NULL;
1975 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1976 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1977 compose->followup_to =
1978 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1981 g_free(hentry[H_FOLLOWUP_TO].body);
1982 hentry[H_FOLLOWUP_TO].body = NULL;
1984 if (hentry[H_LIST_POST].body != NULL) {
1987 extract_address(hentry[H_LIST_POST].body);
1988 if (hentry[H_LIST_POST].body[0] != '\0') {
1989 scan_mailto_url(hentry[H_LIST_POST].body,
1990 &to, NULL, NULL, NULL, NULL);
1992 g_free(compose->ml_post);
1993 compose->ml_post = to;
1996 g_free(hentry[H_LIST_POST].body);
1997 hentry[H_LIST_POST].body = NULL;
2000 /* CLAWS - X-Priority */
2001 if (compose->mode == COMPOSE_REEDIT)
2002 if (hentry[H_X_PRIORITY].body != NULL) {
2005 priority = atoi(hentry[H_X_PRIORITY].body);
2006 g_free(hentry[H_X_PRIORITY].body);
2008 hentry[H_X_PRIORITY].body = NULL;
2010 if (priority < PRIORITY_HIGHEST ||
2011 priority > PRIORITY_LOWEST)
2012 priority = PRIORITY_NORMAL;
2014 compose->priority = priority;
2017 if (compose->mode == COMPOSE_REEDIT) {
2018 if (msginfo->inreplyto && *msginfo->inreplyto)
2019 compose->inreplyto = g_strdup(msginfo->inreplyto);
2023 if (msginfo->msgid && *msginfo->msgid)
2024 compose->inreplyto = g_strdup(msginfo->msgid);
2026 if (!compose->references) {
2027 if (msginfo->msgid && *msginfo->msgid) {
2028 if (msginfo->inreplyto && *msginfo->inreplyto)
2029 compose->references =
2030 g_strdup_printf("<%s>\n\t<%s>",
2034 compose->references =
2035 g_strconcat("<", msginfo->msgid, ">",
2037 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2038 compose->references =
2039 g_strconcat("<", msginfo->inreplyto, ">",
2047 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2049 GSList *ref_id_list, *cur;
2053 ref_id_list = references_list_append(NULL, ref);
2054 if (!ref_id_list) return NULL;
2055 if (msgid && *msgid)
2056 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2061 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2062 /* "<" + Message-ID + ">" + CR+LF+TAB */
2063 len += strlen((gchar *)cur->data) + 5;
2065 if (len > MAX_REFERENCES_LEN) {
2066 /* remove second message-ID */
2067 if (ref_id_list && ref_id_list->next &&
2068 ref_id_list->next->next) {
2069 g_free(ref_id_list->next->data);
2070 ref_id_list = g_slist_remove
2071 (ref_id_list, ref_id_list->next->data);
2073 slist_free_strings(ref_id_list);
2074 g_slist_free(ref_id_list);
2081 new_ref = g_string_new("");
2082 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2083 if (new_ref->len > 0)
2084 g_string_append(new_ref, "\n\t");
2085 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2088 slist_free_strings(ref_id_list);
2089 g_slist_free(ref_id_list);
2091 new_ref_str = new_ref->str;
2092 g_string_free(new_ref, FALSE);
2097 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2098 const gchar *fmt, const gchar *qmark,
2101 static MsgInfo dummyinfo;
2102 gchar *quote_str = NULL;
2106 gboolean prev_autowrap;
2107 const gchar *trimmed_body = body;
2108 gint cursor_pos = 0;
2109 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2110 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2114 msginfo = &dummyinfo;
2116 if (qmark != NULL) {
2117 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2118 quote_fmt_scan_string(qmark);
2121 buf = quote_fmt_get_buffer();
2123 alertpanel_error(_("Quote mark format error."));
2125 Xstrdup_a(quote_str, buf, return NULL)
2128 if (fmt && *fmt != '\0') {
2129 while (trimmed_body && strlen(trimmed_body) > 1
2130 && trimmed_body[0]=='\n')
2133 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2134 quote_fmt_scan_string(fmt);
2137 buf = quote_fmt_get_buffer();
2139 alertpanel_error(_("Message reply/forward format error."));
2145 prev_autowrap = compose->autowrap;
2146 compose->autowrap = FALSE;
2148 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2149 G_CALLBACK(compose_changed_cb),
2151 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2152 G_CALLBACK(text_inserted),
2154 for (p = buf; *p != '\0'; ) {
2157 mark = gtk_text_buffer_get_insert(buffer);
2158 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2160 lastp = strchr(p, '\n');
2161 len = lastp ? lastp - p + 1 : -1;
2163 if (g_utf8_validate(p, -1, NULL)) {
2164 gtk_text_buffer_insert(buffer, &iter, p, len);
2166 gchar *tmpin = g_strdup(p);
2167 gchar *tmpout = NULL;
2169 tmpout = conv_codeset_strdup
2170 (tmpin, conv_get_locale_charset_str(),
2172 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2183 cursor_pos = quote_fmt_get_cursor_pos();
2184 gtk_text_buffer_get_start_iter(buffer, &iter);
2185 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2186 gtk_text_buffer_place_cursor(buffer, &iter);
2187 compose->set_cursor_pos = cursor_pos;
2189 compose->autowrap = prev_autowrap;
2190 if (compose->autowrap)
2191 compose_wrap_all(compose);
2193 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2194 G_CALLBACK(compose_changed_cb),
2196 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2197 G_CALLBACK(text_inserted),
2204 /* if ml_post is of type addr@host and from is of type
2205 * addr-anything@host, return TRUE
2207 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2209 gchar *left_ml = NULL;
2210 gchar *right_ml = NULL;
2211 gchar *left_from = NULL;
2212 gchar *right_from = NULL;
2213 gboolean result = FALSE;
2215 if (!ml_post || !from)
2218 left_ml = g_strdup(ml_post);
2219 if (strstr(left_ml, "@")) {
2220 right_ml = strstr(left_ml, "@")+1;
2221 *(strstr(left_ml, "@")) = '\0';
2224 left_from = g_strdup(from);
2225 if (strstr(left_from, "@")) {
2226 right_from = strstr(left_from, "@")+1;
2227 *(strstr(left_from, "@")) = '\0';
2230 if (left_ml && left_from && right_ml && right_from
2231 && !strncmp(left_from, left_ml, strlen(left_ml))
2232 && !strcmp(right_from, right_ml)) {
2241 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2243 gchar *my_addr1, *my_addr2;
2245 if (!addr1 || !addr2)
2248 Xstrdup_a(my_addr1, addr1, return FALSE);
2249 Xstrdup_a(my_addr2, addr2, return FALSE);
2251 extract_address(my_addr1);
2252 extract_address(my_addr2);
2254 return !strcmp(my_addr1, my_addr2);
2257 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2258 gboolean to_all, gboolean to_ml,
2260 gboolean followup_and_reply_to)
2262 GSList *cc_list = NULL;
2265 gchar *replyto = NULL;
2266 GHashTable *to_table;
2268 gboolean reply_to_ml = FALSE;
2269 gboolean default_reply_to = FALSE;
2271 g_return_if_fail(compose->account != NULL);
2272 g_return_if_fail(msginfo != NULL);
2274 reply_to_ml = to_ml && compose->ml_post;
2276 default_reply_to = msginfo->folder &&
2277 msginfo->folder->prefs->enable_default_reply_to;
2279 if (compose->account->protocol != A_NNTP) {
2280 if (reply_to_ml && !default_reply_to) {
2282 gboolean is_subscr = is_subscription(compose->ml_post,
2285 /* normal answer to ml post with a reply-to */
2286 compose_entry_append(compose,
2289 if (compose->replyto
2290 && !same_address(compose->ml_post, compose->replyto))
2291 compose_entry_append(compose,
2295 /* answer to subscription confirmation */
2296 if (compose->replyto)
2297 compose_entry_append(compose,
2300 else if (msginfo->from)
2301 compose_entry_append(compose,
2306 else if (!(to_all || to_sender) && default_reply_to) {
2307 compose_entry_append(compose,
2308 msginfo->folder->prefs->default_reply_to,
2310 compose_entry_mark_default_to(compose,
2311 msginfo->folder->prefs->default_reply_to);
2314 Xstrdup_a(tmp1, msginfo->from, return);
2315 extract_address(tmp1);
2316 if (to_all || to_sender ||
2317 !account_find_from_address(tmp1))
2318 compose_entry_append(compose,
2319 (compose->replyto && !to_sender)
2320 ? compose->replyto :
2321 msginfo->from ? msginfo->from : "",
2323 else if (!to_all && !to_sender) {
2324 /* reply to the last list of recipients */
2325 compose_entry_append(compose,
2326 msginfo->to ? msginfo->to : "",
2328 compose_entry_append(compose,
2329 msginfo->cc ? msginfo->cc : "",
2334 if (to_sender || (compose->followup_to &&
2335 !strncmp(compose->followup_to, "poster", 6)))
2336 compose_entry_append
2338 (compose->replyto ? compose->replyto :
2339 msginfo->from ? msginfo->from : ""),
2342 else if (followup_and_reply_to || to_all) {
2343 compose_entry_append
2345 (compose->replyto ? compose->replyto :
2346 msginfo->from ? msginfo->from : ""),
2349 compose_entry_append
2351 compose->followup_to ? compose->followup_to :
2352 compose->newsgroups ? compose->newsgroups : "",
2353 COMPOSE_NEWSGROUPS);
2356 compose_entry_append
2358 compose->followup_to ? compose->followup_to :
2359 compose->newsgroups ? compose->newsgroups : "",
2360 COMPOSE_NEWSGROUPS);
2363 if (msginfo->subject && *msginfo->subject) {
2367 buf = p = g_strdup(msginfo->subject);
2368 p += subject_get_prefix_length(p);
2369 memmove(buf, p, strlen(p) + 1);
2371 buf2 = g_strdup_printf("Re: %s", buf);
2372 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2377 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2379 if (to_ml && compose->ml_post) return;
2380 if (!to_all || compose->account->protocol == A_NNTP) return;
2382 if (compose->replyto) {
2383 Xstrdup_a(replyto, compose->replyto, return);
2384 extract_address(replyto);
2386 if (msginfo->from) {
2387 Xstrdup_a(from, msginfo->from, return);
2388 extract_address(from);
2391 if (replyto && from)
2392 cc_list = address_list_append_with_comments(cc_list, from);
2393 if (to_all && msginfo->folder &&
2394 msginfo->folder->prefs->enable_default_reply_to)
2395 cc_list = address_list_append_with_comments(cc_list,
2396 msginfo->folder->prefs->default_reply_to);
2397 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2398 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2400 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2402 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2403 if (compose->account)
2404 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2405 GINT_TO_POINTER(1));
2407 /* remove address on To: and that of current account */
2408 for (cur = cc_list; cur != NULL; ) {
2409 GSList *next = cur->next;
2412 addr = g_strdup(cur->data);
2413 extract_address(addr);
2415 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2416 cc_list = g_slist_remove(cc_list, cur->data);
2418 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2422 hash_free_strings(to_table);
2423 g_hash_table_destroy(to_table);
2426 for (cur = cc_list; cur != NULL; cur = cur->next)
2427 compose_entry_append(compose, (gchar *)cur->data,
2429 slist_free_strings(cc_list);
2430 g_slist_free(cc_list);
2435 #define SET_ENTRY(entry, str) \
2438 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2441 #define SET_ADDRESS(type, str) \
2444 compose_entry_append(compose, str, type); \
2447 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2449 g_return_if_fail(msginfo != NULL);
2451 SET_ENTRY(subject_entry, msginfo->subject);
2452 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2453 SET_ADDRESS(COMPOSE_CC, compose->cc);
2454 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2455 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2456 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2457 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2459 compose_update_priority_menu_item(compose);
2460 compose_update_privacy_system_menu_item(compose, FALSE);
2461 compose_show_first_last_header(compose, TRUE);
2467 static void compose_insert_sig(Compose *compose, gboolean replace)
2469 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2470 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2472 GtkTextIter iter, iter_end;
2474 gboolean prev_autowrap;
2477 g_return_if_fail(compose->account != NULL);
2479 prev_autowrap = compose->autowrap;
2480 compose->autowrap = FALSE;
2482 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2483 G_CALLBACK(compose_changed_cb),
2486 mark = gtk_text_buffer_get_insert(buffer);
2487 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2488 cur_pos = gtk_text_iter_get_offset (&iter);
2490 gtk_text_buffer_get_end_iter(buffer, &iter);
2492 if (replace && compose->sig_str) {
2494 GtkTextIter first_iter, start_iter, end_iter;
2496 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2498 if (compose->sig_str[0] == '\0')
2501 found = gtk_text_iter_forward_search(&first_iter,
2503 GTK_TEXT_SEARCH_TEXT_ONLY,
2504 &start_iter, &end_iter,
2508 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2513 g_free(compose->sig_str);
2514 compose->sig_str = compose_get_signature_str(compose);
2515 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2516 compose->sig_str = g_strdup("");
2518 cur_pos = gtk_text_iter_get_offset(&iter);
2519 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2521 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2522 gtk_text_iter_forward_char(&iter);
2523 gtk_text_iter_forward_char(&iter);
2524 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2525 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2527 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2528 cur_pos = gtk_text_buffer_get_char_count (buffer);
2530 /* put the cursor where it should be
2531 * either where the quote_fmt says, either before the signature */
2532 if (compose->set_cursor_pos <= 0)
2533 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2535 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2536 compose->set_cursor_pos);
2538 gtk_text_buffer_place_cursor(buffer, &iter);
2539 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2540 G_CALLBACK(compose_changed_cb),
2543 compose->autowrap = prev_autowrap;
2544 if (compose->autowrap)
2545 compose_wrap_all(compose);
2548 static gchar *compose_get_signature_str(Compose *compose)
2550 gchar *sig_body = NULL;
2551 gchar *sig_str = NULL;
2552 gchar *utf8_sig_str = NULL;
2554 g_return_val_if_fail(compose->account != NULL, NULL);
2556 if (!compose->account->sig_path)
2559 if (compose->account->sig_type == SIG_FILE) {
2560 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2561 g_warning("can't open signature file: %s\n",
2562 compose->account->sig_path);
2567 if (compose->account->sig_type == SIG_COMMAND)
2568 sig_body = get_command_output(compose->account->sig_path);
2572 tmp = file_read_to_str(compose->account->sig_path);
2575 sig_body = normalize_newlines(tmp);
2579 if (compose->account->sig_sep) {
2580 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2584 sig_str = g_strconcat("\n\n", sig_body, NULL);
2587 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2588 utf8_sig_str = sig_str;
2590 utf8_sig_str = conv_codeset_strdup
2591 (sig_str, conv_get_locale_charset_str(),
2597 return utf8_sig_str;
2600 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2603 GtkTextBuffer *buffer;
2606 const gchar *cur_encoding;
2607 gchar buf[BUFFSIZE];
2610 gboolean prev_autowrap;
2611 gboolean badtxt = FALSE;
2613 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2615 if ((fp = g_fopen(file, "rb")) == NULL) {
2616 FILE_OP_ERROR(file, "fopen");
2617 return COMPOSE_INSERT_READ_ERROR;
2620 prev_autowrap = compose->autowrap;
2621 compose->autowrap = FALSE;
2623 text = GTK_TEXT_VIEW(compose->text);
2624 buffer = gtk_text_view_get_buffer(text);
2625 mark = gtk_text_buffer_get_insert(buffer);
2626 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2628 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2629 G_CALLBACK(text_inserted),
2632 cur_encoding = conv_get_locale_charset_str();
2634 while (fgets(buf, sizeof(buf), fp) != NULL) {
2637 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2638 str = g_strdup(buf);
2640 str = conv_codeset_strdup
2641 (buf, cur_encoding, CS_INTERNAL);
2644 /* strip <CR> if DOS/Windows file,
2645 replace <CR> with <LF> if Macintosh file. */
2648 if (len > 0 && str[len - 1] != '\n') {
2650 if (str[len] == '\r') str[len] = '\n';
2653 gtk_text_buffer_insert(buffer, &iter, str, -1);
2657 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2658 G_CALLBACK(text_inserted),
2660 compose->autowrap = prev_autowrap;
2661 if (compose->autowrap)
2662 compose_wrap_all(compose);
2667 return COMPOSE_INSERT_INVALID_CHARACTER;
2669 return COMPOSE_INSERT_SUCCESS;
2672 static void compose_attach_append(Compose *compose, const gchar *file,
2673 const gchar *filename,
2674 const gchar *content_type)
2682 GtkListStore *store;
2685 if (!is_file_exist(file)) {
2686 g_warning("File %s doesn't exist\n", filename);
2689 if ((size = get_file_size(file)) < 0) {
2690 g_warning("Can't get file size of %s\n", filename);
2694 alertpanel_notice(_("File %s is empty."), filename);
2697 if ((fp = g_fopen(file, "rb")) == NULL) {
2698 alertpanel_error(_("Can't read %s."), filename);
2703 ainfo = g_new0(AttachInfo, 1);
2704 auto_ainfo = g_auto_pointer_new_with_free
2705 (ainfo, (GFreeFunc) compose_attach_info_free);
2706 ainfo->file = g_strdup(file);
2709 ainfo->content_type = g_strdup(content_type);
2710 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2712 MsgFlags flags = {0, 0};
2714 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2715 ainfo->encoding = ENC_7BIT;
2717 ainfo->encoding = ENC_8BIT;
2719 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2720 if (msginfo && msginfo->subject)
2721 name = g_strdup(msginfo->subject);
2723 name = g_path_get_basename(filename ? filename : file);
2725 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2727 procmsg_msginfo_free(msginfo);
2729 if (!g_ascii_strncasecmp(content_type, "text", 4))
2730 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2732 ainfo->encoding = ENC_BASE64;
2733 name = g_path_get_basename(filename ? filename : file);
2734 ainfo->name = g_strdup(name);
2738 ainfo->content_type = procmime_get_mime_type(file);
2739 if (!ainfo->content_type) {
2740 ainfo->content_type =
2741 g_strdup("application/octet-stream");
2742 ainfo->encoding = ENC_BASE64;
2743 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2745 procmime_get_encoding_for_text_file(file);
2747 ainfo->encoding = ENC_BASE64;
2748 name = g_path_get_basename(filename ? filename : file);
2749 ainfo->name = g_strdup(name);
2753 if (!strcmp(ainfo->content_type, "unknown")) {
2754 g_free(ainfo->content_type);
2755 ainfo->content_type = g_strdup("application/octet-stream");
2759 size_text = to_human_readable(size);
2761 store = GTK_LIST_STORE(gtk_tree_view_get_model
2762 (GTK_TREE_VIEW(compose->attach_clist)));
2764 gtk_list_store_append(store, &iter);
2765 gtk_list_store_set(store, &iter,
2766 COL_MIMETYPE, ainfo->content_type,
2767 COL_SIZE, size_text,
2768 COL_NAME, ainfo->name,
2770 COL_AUTODATA, auto_ainfo,
2773 g_auto_pointer_free(auto_ainfo);
2776 static void compose_use_signing(Compose *compose, gboolean use_signing)
2778 GtkItemFactory *ifactory;
2779 GtkWidget *menuitem = NULL;
2781 compose->use_signing = use_signing;
2782 ifactory = gtk_item_factory_from_widget(compose->menubar);
2783 menuitem = gtk_item_factory_get_item
2784 (ifactory, "/Options/Sign");
2785 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2789 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2791 GtkItemFactory *ifactory;
2792 GtkWidget *menuitem = NULL;
2794 compose->use_encryption = use_encryption;
2795 ifactory = gtk_item_factory_from_widget(compose->menubar);
2796 menuitem = gtk_item_factory_get_item
2797 (ifactory, "/Options/Encrypt");
2799 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2803 #define NEXT_PART_NOT_CHILD(info) \
2805 node = info->node; \
2806 while (node->children) \
2807 node = g_node_last_child(node); \
2808 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2811 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2815 MimeInfo *firsttext = NULL;
2816 MimeInfo *encrypted = NULL;
2819 const gchar *partname = NULL;
2821 mimeinfo = procmime_scan_message(msginfo);
2822 if (!mimeinfo) return;
2824 if (mimeinfo->node->children == NULL) {
2825 procmime_mimeinfo_free_all(mimeinfo);
2829 /* find first content part */
2830 child = (MimeInfo *) mimeinfo->node->children->data;
2831 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2832 child = (MimeInfo *)child->node->children->data;
2834 if (child->type == MIMETYPE_TEXT) {
2836 debug_print("First text part found\n");
2837 } else if (compose->mode == COMPOSE_REEDIT &&
2838 child->type == MIMETYPE_APPLICATION &&
2839 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2840 encrypted = (MimeInfo *)child->node->parent->data;
2843 child = (MimeInfo *) mimeinfo->node->children->data;
2844 while (child != NULL) {
2845 if (child == encrypted) {
2846 /* skip this part of tree */
2847 NEXT_PART_NOT_CHILD(child);
2851 if (child->type == MIMETYPE_MULTIPART) {
2852 /* get the actual content */
2853 child = procmime_mimeinfo_next(child);
2857 if (child == firsttext) {
2858 child = procmime_mimeinfo_next(child);
2862 outfile = procmime_get_tmp_file_name(child);
2863 if (procmime_get_part(outfile, child) < 0)
2864 g_warning("Can't get the part of multipart message.");
2866 gchar *content_type;
2868 content_type = procmime_get_content_type_str(child->type, child->subtype);
2870 /* if we meet a pgp signature, we don't attach it, but
2871 * we force signing. */
2872 if (strcmp(content_type, "application/pgp-signature")) {
2873 partname = procmime_mimeinfo_get_parameter(child, "filename");
2874 if (partname == NULL)
2875 partname = procmime_mimeinfo_get_parameter(child, "name");
2876 if (partname == NULL)
2878 compose_attach_append(compose, outfile,
2879 partname, content_type);
2881 compose_force_signing(compose, compose->account);
2883 g_free(content_type);
2886 NEXT_PART_NOT_CHILD(child);
2888 procmime_mimeinfo_free_all(mimeinfo);
2891 #undef NEXT_PART_NOT_CHILD
2896 WAIT_FOR_INDENT_CHAR,
2897 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2900 /* return indent length, we allow:
2901 indent characters followed by indent characters or spaces/tabs,
2902 alphabets and numbers immediately followed by indent characters,
2903 and the repeating sequences of the above
2904 If quote ends with multiple spaces, only the first one is included. */
2905 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2906 const GtkTextIter *start, gint *len)
2908 GtkTextIter iter = *start;
2912 IndentState state = WAIT_FOR_INDENT_CHAR;
2915 gint alnum_count = 0;
2916 gint space_count = 0;
2919 if (prefs_common.quote_chars == NULL) {
2923 while (!gtk_text_iter_ends_line(&iter)) {
2924 wc = gtk_text_iter_get_char(&iter);
2925 if (g_unichar_iswide(wc))
2927 clen = g_unichar_to_utf8(wc, ch);
2931 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2932 is_space = g_unichar_isspace(wc);
2934 if (state == WAIT_FOR_INDENT_CHAR) {
2935 if (!is_indent && !g_unichar_isalnum(wc))
2938 quote_len += alnum_count + space_count + 1;
2939 alnum_count = space_count = 0;
2940 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2943 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2944 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2948 else if (is_indent) {
2949 quote_len += alnum_count + space_count + 1;
2950 alnum_count = space_count = 0;
2953 state = WAIT_FOR_INDENT_CHAR;
2957 gtk_text_iter_forward_char(&iter);
2960 if (quote_len > 0 && space_count > 0)
2966 if (quote_len > 0) {
2968 gtk_text_iter_forward_chars(&iter, quote_len);
2969 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2975 /* return TRUE if the line is itemized */
2976 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2977 const GtkTextIter *start)
2979 GtkTextIter iter = *start;
2984 if (gtk_text_iter_ends_line(&iter))
2988 wc = gtk_text_iter_get_char(&iter);
2989 if (!g_unichar_isspace(wc))
2991 gtk_text_iter_forward_char(&iter);
2992 if (gtk_text_iter_ends_line(&iter))
2996 clen = g_unichar_to_utf8(wc, ch);
3000 if (!strchr("*-+", ch[0]))
3003 gtk_text_iter_forward_char(&iter);
3004 if (gtk_text_iter_ends_line(&iter))
3006 wc = gtk_text_iter_get_char(&iter);
3007 if (g_unichar_isspace(wc))
3013 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3014 const GtkTextIter *start,
3015 GtkTextIter *break_pos,
3019 GtkTextIter iter = *start, line_end = *start;
3020 PangoLogAttr *attrs;
3027 gboolean can_break = FALSE;
3028 gboolean do_break = FALSE;
3029 gboolean was_white = FALSE;
3030 gboolean prev_dont_break = FALSE;
3032 gtk_text_iter_forward_to_line_end(&line_end);
3033 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3034 len = g_utf8_strlen(str, -1);
3035 /* g_print("breaking line: %d: %s (len = %d)\n",
3036 gtk_text_iter_get_line(&iter), str, len); */
3037 attrs = g_new(PangoLogAttr, len + 1);
3039 pango_default_break(str, -1, NULL, attrs, len + 1);
3043 /* skip quote and leading spaces */
3044 for (i = 0; *p != '\0' && i < len; i++) {
3047 wc = g_utf8_get_char(p);
3048 if (i >= quote_len && !g_unichar_isspace(wc))
3050 if (g_unichar_iswide(wc))
3052 else if (*p == '\t')
3056 p = g_utf8_next_char(p);
3059 for (; *p != '\0' && i < len; i++) {
3060 PangoLogAttr *attr = attrs + i;
3064 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3067 was_white = attr->is_white;
3069 /* don't wrap URI */
3070 if ((uri_len = get_uri_len(p)) > 0) {
3072 if (pos > 0 && col > max_col) {
3082 wc = g_utf8_get_char(p);
3083 if (g_unichar_iswide(wc)) {
3085 if (prev_dont_break && can_break && attr->is_line_break)
3087 } else if (*p == '\t')
3091 if (pos > 0 && col > max_col) {
3096 if (*p == '-' || *p == '/')
3097 prev_dont_break = TRUE;
3099 prev_dont_break = FALSE;
3101 p = g_utf8_next_char(p);
3105 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3110 *break_pos = *start;
3111 gtk_text_iter_set_line_offset(break_pos, pos);
3116 static gboolean compose_join_next_line(Compose *compose,
3117 GtkTextBuffer *buffer,
3119 const gchar *quote_str)
3121 GtkTextIter iter_ = *iter, cur, prev, next, end;
3122 PangoLogAttr attrs[3];
3124 gchar *next_quote_str;
3127 gboolean keep_cursor = FALSE;
3129 if (!gtk_text_iter_forward_line(&iter_) ||
3130 gtk_text_iter_ends_line(&iter_))
3133 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3135 if ((quote_str || next_quote_str) &&
3136 strcmp2(quote_str, next_quote_str) != 0) {
3137 g_free(next_quote_str);
3140 g_free(next_quote_str);
3143 if (quote_len > 0) {
3144 gtk_text_iter_forward_chars(&end, quote_len);
3145 if (gtk_text_iter_ends_line(&end))
3149 /* don't join itemized lines */
3150 if (compose_is_itemized(buffer, &end))
3153 /* don't join signature separator */
3154 if (compose_is_sig_separator(compose, buffer, &iter_))
3157 /* delete quote str */
3159 gtk_text_buffer_delete(buffer, &iter_, &end);
3161 /* delete linebreak and extra spaces */
3163 while (gtk_text_iter_backward_char(&cur)) {
3164 wc1 = gtk_text_iter_get_char(&cur);
3165 if (!g_unichar_isspace(wc1))
3170 while (!gtk_text_iter_ends_line(&cur)) {
3171 wc1 = gtk_text_iter_get_char(&cur);
3172 if (!g_unichar_isspace(wc1))
3174 gtk_text_iter_forward_char(&cur);
3177 if (!gtk_text_iter_equal(&prev, &next)) {
3180 mark = gtk_text_buffer_get_insert(buffer);
3181 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3182 if (gtk_text_iter_equal(&prev, &cur))
3184 gtk_text_buffer_delete(buffer, &prev, &next);
3188 /* insert space if required */
3189 gtk_text_iter_backward_char(&prev);
3190 wc1 = gtk_text_iter_get_char(&prev);
3191 wc2 = gtk_text_iter_get_char(&next);
3192 gtk_text_iter_forward_char(&next);
3193 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3194 pango_default_break(str, -1, NULL, attrs, 3);
3195 if (!attrs[1].is_line_break ||
3196 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3197 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3199 gtk_text_iter_backward_char(&iter_);
3200 gtk_text_buffer_place_cursor(buffer, &iter_);
3209 #define ADD_TXT_POS(bp_, ep_, pti_) \
3210 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3211 last = last->next; \
3212 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3213 last->next = NULL; \
3215 g_warning("alloc error scanning URIs\n"); \
3218 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3220 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3221 GtkTextBuffer *buffer;
3222 GtkTextIter iter, break_pos, end_of_line;
3223 gchar *quote_str = NULL;
3225 gboolean wrap_quote = prefs_common.linewrap_quote;
3226 gboolean prev_autowrap = compose->autowrap;
3227 gint startq_offset = -1, noq_offset = -1;
3228 gint uri_start = -1, uri_stop = -1;
3229 gint nouri_start = -1, nouri_stop = -1;
3231 compose->autowrap = FALSE;
3233 buffer = gtk_text_view_get_buffer(text);
3235 undo_block(compose->undostruct);
3241 mark = gtk_text_buffer_get_insert(buffer);
3242 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3245 /* move to paragraph start */
3246 gtk_text_iter_set_line_offset(&iter, 0);
3247 if (gtk_text_iter_ends_line(&iter)) {
3248 while (gtk_text_iter_ends_line(&iter) &&
3249 gtk_text_iter_forward_line(&iter))
3252 while (gtk_text_iter_backward_line(&iter)) {
3253 if (gtk_text_iter_ends_line(&iter)) {
3254 gtk_text_iter_forward_line(&iter);
3260 /* go until paragraph end (empty line) */
3261 while (!gtk_text_iter_ends_line(&iter)) {
3262 gchar *scanpos = NULL;
3263 /* parse table - in order of priority */
3265 const gchar *needle; /* token */
3267 /* token search function */
3268 gchar *(*search) (const gchar *haystack,
3269 const gchar *needle);
3270 /* part parsing function */
3271 gboolean (*parse) (const gchar *start,
3272 const gchar *scanpos,
3276 /* part to URI function */
3277 gchar *(*build_uri) (const gchar *bp,
3281 static struct table parser[] = {
3282 {"http://", strcasestr, get_uri_part, make_uri_string},
3283 {"https://", strcasestr, get_uri_part, make_uri_string},
3284 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3285 {"www.", strcasestr, get_uri_part, make_http_string},
3286 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3287 {"@", strcasestr, get_email_part, make_email_string}
3289 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3290 gint last_index = PARSE_ELEMS;
3292 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3295 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3298 uri_start = uri_stop = -1;
3299 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3303 if (startq_offset == -1) {
3304 startq_offset = gtk_text_iter_get_offset(&iter);
3308 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3309 if (startq_offset == -1)
3310 startq_offset = gtk_text_iter_get_offset(&iter);
3312 if (startq_offset == -1)
3313 noq_offset = gtk_text_iter_get_offset(&iter);
3316 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3319 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3320 prefs_common.linewrap_len,
3322 GtkTextIter prev, next, cur;
3324 if (prev_autowrap != FALSE || force)
3325 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3326 else if (quote_str && wrap_quote)
3327 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3330 /* remove trailing spaces */
3332 gtk_text_iter_backward_char(&cur);
3334 while (!gtk_text_iter_starts_line(&cur)) {
3337 gtk_text_iter_backward_char(&cur);
3338 wc = gtk_text_iter_get_char(&cur);
3339 if (!g_unichar_isspace(wc))
3343 if (!gtk_text_iter_equal(&prev, &next)) {
3344 gtk_text_buffer_delete(buffer, &prev, &next);
3346 gtk_text_iter_forward_char(&break_pos);
3350 gtk_text_buffer_insert(buffer, &break_pos,
3354 compose_join_next_line(compose, buffer, &iter, quote_str);
3356 /* move iter to current line start */
3357 gtk_text_iter_set_line_offset(&iter, 0);
3360 /* move iter to next line start */
3366 while (!gtk_text_iter_ends_line(&end_of_line)) {
3367 gtk_text_iter_forward_char(&end_of_line);
3369 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3371 nouri_start = gtk_text_iter_get_offset(&iter);
3372 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3374 walk_pos = gtk_text_iter_get_offset(&iter);
3375 /* FIXME: this looks phony. scanning for anything in the parse table */
3376 for (n = 0; n < PARSE_ELEMS; n++) {
3379 tmp = parser[n].search(walk, parser[n].needle);
3381 if (scanpos == NULL || tmp < scanpos) {
3390 /* check if URI can be parsed */
3391 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3392 (const gchar **)&ep, FALSE)
3393 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3397 strlen(parser[last_index].needle);
3400 uri_start = walk_pos + (bp - o_walk);
3401 uri_stop = walk_pos + (ep - o_walk);
3405 gtk_text_iter_forward_line(&iter);
3408 if (startq_offset != -1) {
3409 GtkTextIter startquote, endquote;
3410 gtk_text_buffer_get_iter_at_offset(
3411 buffer, &startquote, startq_offset);
3413 gtk_text_buffer_apply_tag_by_name(
3414 buffer, "quote", &startquote, &endquote);
3416 } else if (noq_offset != -1) {
3417 GtkTextIter startnoquote, endnoquote;
3418 gtk_text_buffer_get_iter_at_offset(
3419 buffer, &startnoquote, noq_offset);
3421 gtk_text_buffer_remove_tag_by_name(
3422 buffer, "quote", &startnoquote, &endnoquote);
3427 GtkTextIter nouri_start_iter, nouri_end_iter;
3428 gtk_text_buffer_get_iter_at_offset(
3429 buffer, &nouri_start_iter, nouri_start);
3430 gtk_text_buffer_get_iter_at_offset(
3431 buffer, &nouri_end_iter, nouri_stop);
3432 gtk_text_buffer_remove_tag_by_name(
3433 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3435 if (uri_start > 0 && uri_stop > 0) {
3436 GtkTextIter uri_start_iter, uri_end_iter;
3437 gtk_text_buffer_get_iter_at_offset(
3438 buffer, &uri_start_iter, uri_start);
3439 gtk_text_buffer_get_iter_at_offset(
3440 buffer, &uri_end_iter, uri_stop);
3441 gtk_text_buffer_apply_tag_by_name(
3442 buffer, "link", &uri_start_iter, &uri_end_iter);
3449 undo_unblock(compose->undostruct);
3450 compose->autowrap = prev_autowrap;
3453 static void compose_wrap_all(Compose *compose)
3455 compose_wrap_all_full(compose, FALSE);
3458 static void compose_wrap_all_full(Compose *compose, gboolean force)
3460 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3461 GtkTextBuffer *buffer;
3464 buffer = gtk_text_view_get_buffer(text);
3466 undo_block(compose->undostruct);
3468 gtk_text_buffer_get_start_iter(buffer, &iter);
3469 while (!gtk_text_iter_is_end(&iter))
3470 compose_beautify_paragraph(compose, &iter, force);
3472 undo_unblock(compose->undostruct);
3475 static void compose_set_title(Compose *compose)
3481 edited = compose->modified ? _(" [Edited]") : "";
3483 subject = gtk_editable_get_chars(
3484 GTK_EDITABLE(compose->subject_entry), 0, -1);
3486 if (subject && strlen(subject))
3487 str = g_strdup_printf(_("%s - Compose message%s"),
3490 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3491 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3497 * compose_current_mail_account:
3499 * Find a current mail account (the currently selected account, or the
3500 * default account, if a news account is currently selected). If a
3501 * mail account cannot be found, display an error message.
3503 * Return value: Mail account, or NULL if not found.
3505 static PrefsAccount *
3506 compose_current_mail_account(void)
3510 if (cur_account && cur_account->protocol != A_NNTP)
3513 ac = account_get_default();
3514 if (!ac || ac->protocol == A_NNTP) {
3515 alertpanel_error(_("Account for sending mail is not specified.\n"
3516 "Please select a mail account before sending."));
3523 static void compose_select_account(Compose *compose, PrefsAccount *account,
3526 GtkItemFactory *ifactory;
3528 g_return_if_fail(account != NULL);
3530 compose->account = account;
3532 compose_set_title(compose);
3534 ifactory = gtk_item_factory_from_widget(compose->menubar);
3536 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3537 menu_set_active(ifactory, "/Options/Sign", TRUE);
3539 menu_set_active(ifactory, "/Options/Sign", FALSE);
3540 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3541 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3543 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3545 activate_privacy_system(compose, account, FALSE);
3547 if (!init && compose->mode != COMPOSE_REDIRECT)
3548 compose_insert_sig(compose, TRUE);
3551 gboolean compose_check_for_valid_recipient(Compose *compose) {
3552 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3553 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3554 gboolean recipient_found = FALSE;
3558 /* free to and newsgroup list */
3559 slist_free_strings(compose->to_list);
3560 g_slist_free(compose->to_list);
3561 compose->to_list = NULL;
3563 slist_free_strings(compose->newsgroup_list);
3564 g_slist_free(compose->newsgroup_list);
3565 compose->newsgroup_list = NULL;
3567 /* search header entries for to and newsgroup entries */
3568 for (list = compose->header_list; list; list = list->next) {
3571 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3572 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3574 if (entry[0] != '\0') {
3575 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3576 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3577 compose->to_list = address_list_append(compose->to_list, entry);
3578 recipient_found = TRUE;
3581 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3582 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3583 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3584 recipient_found = TRUE;
3591 return recipient_found;
3594 static gboolean compose_check_for_set_recipients(Compose *compose)
3596 if (compose->account->set_autocc && compose->account->auto_cc) {
3597 gboolean found_other = FALSE;
3599 /* search header entries for to and newsgroup entries */
3600 for (list = compose->header_list; list; list = list->next) {
3603 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3604 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3606 if (strcmp(entry, compose->account->auto_cc)
3607 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3617 aval = alertpanel(_("Send"),
3618 _("The only recipient is the default CC address. Send anyway?"),
3619 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3620 if (aval != G_ALERTDEFAULT)
3624 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3625 gboolean found_other = FALSE;
3627 /* search header entries for to and newsgroup entries */
3628 for (list = compose->header_list; list; list = list->next) {
3631 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3632 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3634 if (strcmp(entry, compose->account->auto_cc)
3635 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3645 aval = alertpanel(_("Send"),
3646 _("The only recipient is the default BCC address. Send anyway?"),
3647 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3648 if (aval != G_ALERTDEFAULT)
3655 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3659 if (compose_check_for_valid_recipient(compose) == FALSE) {
3660 alertpanel_error(_("Recipient is not specified."));
3664 if (compose_check_for_set_recipients(compose) == FALSE) {
3668 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3669 if (*str == '\0' && check_subject == TRUE) {
3672 aval = alertpanel(_("Send"),
3673 _("Subject is empty. Send it anyway?"),
3674 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3675 if (aval != G_ALERTDEFAULT)
3682 gint compose_send(Compose *compose)
3689 compose_allow_user_actions (compose, FALSE);
3690 compose->sending = TRUE;
3692 if (compose_check_entries(compose, TRUE) == FALSE)
3695 val = compose_queue(compose, &msgnum, &folder);
3699 alertpanel_error(_("Could not queue message for sending:\n\n"
3700 "Charset conversion failed."));
3701 } else if (val == -3) {
3702 alertpanel_error(_("Could not queue message for sending:\n\n"
3703 "Signature failed."));
3704 } else if (val == -2) {
3705 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3707 alertpanel_error(_("Could not queue message for sending."));
3713 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3714 compose->sending = FALSE;
3715 compose_close(compose);
3716 /* No more compose access in the normal codepath
3717 * after this point! */
3722 alertpanel_error(_("The message was queued but could not be "
3723 "sent.\nUse \"Send queued messages\" from "
3724 "the main window to retry."));
3725 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3726 compose->sending = FALSE;
3727 compose_allow_user_actions (compose, TRUE);
3732 msgpath = folder_item_fetch_msg(folder, msgnum);
3733 val = procmsg_send_message_queue(msgpath);
3736 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3737 compose->sending = FALSE;
3738 compose_allow_user_actions (compose, TRUE);
3740 folder_item_remove_msg(folder, msgnum);
3741 folder_item_scan(folder);
3746 folder_item_remove_msg(folder, msgnum);
3747 folder_item_scan(folder);
3748 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3749 compose_close(compose);
3751 alertpanel_error(_("The message was queued but could not be "
3752 "sent.\nUse \"Send queued messages\" from "
3753 "the main window to retry."));
3754 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3755 compose_allow_user_actions (compose, TRUE);
3756 compose->sending = FALSE;
3764 compose_allow_user_actions (compose, TRUE);
3765 compose->sending = FALSE;
3770 static gboolean compose_use_attach(Compose *compose)
3772 GtkTreeModel *model = gtk_tree_view_get_model
3773 (GTK_TREE_VIEW(compose->attach_clist));
3774 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3777 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3780 gchar buf[BUFFSIZE];
3782 gboolean first_to_address;
3783 gboolean first_cc_address;
3785 ComposeHeaderEntry *headerentry;
3786 const gchar *headerentryname;
3790 debug_print("Writing redirect header\n");
3792 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3793 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3795 first_to_address = TRUE;
3796 for (list = compose->header_list; list; list = list->next) {
3797 headerentry = ((ComposeHeaderEntry *)list->data);
3798 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3800 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3801 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3802 Xstrdup_a(str, entstr, return -1);
3804 if (str[0] != '\0') {
3805 compose_convert_header
3806 (compose, buf, sizeof(buf), str,
3807 strlen("Resent-To") + 2, TRUE);
3809 if (first_to_address) {
3810 fprintf(fp, "Resent-To: ");
3811 first_to_address = FALSE;
3815 fprintf(fp, "%s", buf);
3819 if (!first_to_address) {
3823 first_cc_address = TRUE;
3824 for (list = compose->header_list; list; list = list->next) {
3825 headerentry = ((ComposeHeaderEntry *)list->data);
3826 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3828 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3829 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3830 Xstrdup_a(str, strg, return -1);
3832 if (str[0] != '\0') {
3833 compose_convert_header
3834 (compose, buf, sizeof(buf), str,
3835 strlen("Resent-Cc") + 2, TRUE);
3837 if (first_cc_address) {
3838 fprintf(fp, "Resent-Cc: ");
3839 first_cc_address = FALSE;
3843 fprintf(fp, "%s", buf);
3847 if (!first_cc_address) {
3854 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3856 gchar buf[BUFFSIZE];
3858 const gchar *entstr;
3859 /* struct utsname utsbuf; */
3861 g_return_val_if_fail(fp != NULL, -1);
3862 g_return_val_if_fail(compose->account != NULL, -1);
3863 g_return_val_if_fail(compose->account->address != NULL, -1);
3866 get_rfc822_date(buf, sizeof(buf));
3867 fprintf(fp, "Resent-Date: %s\n", buf);
3870 if (compose->account->name && *compose->account->name) {
3871 compose_convert_header
3872 (compose, buf, sizeof(buf), compose->account->name,
3873 strlen("From: "), TRUE);
3874 fprintf(fp, "Resent-From: %s <%s>\n",
3875 buf, compose->account->address);
3877 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3880 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3881 if (*entstr != '\0') {
3882 Xstrdup_a(str, entstr, return -1);
3885 compose_convert_header(compose, buf, sizeof(buf), str,
3886 strlen("Subject: "), FALSE);
3887 fprintf(fp, "Subject: %s\n", buf);
3891 /* Resent-Message-ID */
3892 if (compose->account->gen_msgid) {
3893 generate_msgid(buf, sizeof(buf));
3894 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3895 compose->msgid = g_strdup(buf);
3898 compose_redirect_write_headers_from_headerlist(compose, fp);
3900 /* separator between header and body */
3906 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3910 gchar buf[BUFFSIZE];
3912 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3913 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3917 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3918 /* should filter returnpath, delivered-to */
3919 if (g_ascii_strncasecmp(buf, "Return-Path:",
3920 strlen("Return-Path:")) == 0 ||
3921 g_ascii_strncasecmp(buf, "Delivered-To:",
3922 strlen("Delivered-To:")) == 0 ||
3923 g_ascii_strncasecmp(buf, "Received:",
3924 strlen("Received:")) == 0 ||
3925 g_ascii_strncasecmp(buf, "Subject:",
3926 strlen("Subject:")) == 0 ||
3927 g_ascii_strncasecmp(buf, "X-UIDL:",
3928 strlen("X-UIDL:")) == 0)
3931 if (fputs(buf, fdest) == -1)
3934 if (!prefs_common.redirect_keep_from) {
3935 if (g_ascii_strncasecmp(buf, "From:",
3936 strlen("From:")) == 0) {
3937 fputs(" (by way of ", fdest);
3938 if (compose->account->name
3939 && *compose->account->name) {
3940 compose_convert_header
3941 (compose, buf, sizeof(buf),
3942 compose->account->name,
3945 fprintf(fdest, "%s <%s>",
3947 compose->account->address);
3949 fprintf(fdest, "%s",
3950 compose->account->address);
3955 if (fputs("\n", fdest) == -1)
3959 compose_redirect_write_headers(compose, fdest);
3961 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3962 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3975 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3977 GtkTextBuffer *buffer;
3978 GtkTextIter start, end;
3981 const gchar *out_codeset;
3982 EncodingType encoding;
3983 MimeInfo *mimemsg, *mimetext;
3986 /* create message MimeInfo */
3987 mimemsg = procmime_mimeinfo_new();
3988 mimemsg->type = MIMETYPE_MESSAGE;
3989 mimemsg->subtype = g_strdup("rfc822");
3990 mimemsg->content = MIMECONTENT_MEM;
3991 mimemsg->data.mem = compose_get_header(compose);
3993 /* Create text part MimeInfo */
3994 /* get all composed text */
3995 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3996 gtk_text_buffer_get_start_iter(buffer, &start);
3997 gtk_text_buffer_get_end_iter(buffer, &end);
3998 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3999 if (is_ascii_str(chars)) {
4002 out_codeset = CS_US_ASCII;
4003 encoding = ENC_7BIT;
4005 const gchar *src_codeset = CS_INTERNAL;
4007 out_codeset = conv_get_charset_str(compose->out_encoding);
4010 gchar *test_conv_global_out = NULL;
4011 gchar *test_conv_reply = NULL;
4013 /* automatic mode. be automatic. */
4014 codeconv_set_strict(TRUE);
4016 out_codeset = conv_get_outgoing_charset_str();
4018 debug_print("trying to convert to %s\n", out_codeset);
4019 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4022 if (!test_conv_global_out && compose->orig_charset) {
4023 out_codeset = compose->orig_charset;
4024 debug_print("failure; trying to convert to %s\n", out_codeset);
4025 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4028 if (!test_conv_global_out && !test_conv_reply) {
4030 out_codeset = CS_INTERNAL;
4031 debug_print("finally using %s\n", out_codeset);
4033 g_free(test_conv_global_out);
4034 g_free(test_conv_reply);
4035 codeconv_set_strict(FALSE);
4038 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4039 out_codeset = CS_ISO_8859_1;
4041 if (prefs_common.encoding_method == CTE_BASE64)
4042 encoding = ENC_BASE64;
4043 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4044 encoding = ENC_QUOTED_PRINTABLE;
4045 else if (prefs_common.encoding_method == CTE_8BIT)
4046 encoding = ENC_8BIT;
4048 encoding = procmime_get_encoding_for_charset(out_codeset);
4050 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4051 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4053 if (action == COMPOSE_WRITE_FOR_SEND) {
4054 codeconv_set_strict(TRUE);
4055 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4056 codeconv_set_strict(FALSE);
4062 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4063 "to the specified %s charset.\n"
4064 "Send it as %s?"), out_codeset, src_codeset);
4065 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
4066 NULL, ALERT_ERROR, G_ALERTALTERNATE);
4069 if (aval != G_ALERTDEFAULT) {
4074 out_codeset = src_codeset;
4080 out_codeset = src_codeset;
4086 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4087 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4088 strstr(buf, "\nFrom ") != NULL) {
4089 encoding = ENC_QUOTED_PRINTABLE;
4093 mimetext = procmime_mimeinfo_new();
4094 mimetext->content = MIMECONTENT_MEM;
4095 mimetext->data.mem = buf;
4096 mimetext->type = MIMETYPE_TEXT;
4097 mimetext->subtype = g_strdup("plain");
4098 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4099 g_strdup(out_codeset));
4100 /* protect trailing spaces when signing message */
4101 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4102 privacy_system_can_sign(compose->privacy_system)) {
4103 encoding = ENC_QUOTED_PRINTABLE;
4106 /* check for line length limit */
4107 if (action == COMPOSE_WRITE_FOR_SEND &&
4108 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4109 check_line_length(buf, 1000, &line) < 0) {
4113 msg = g_strdup_printf
4114 (_("Line %d exceeds the line length limit (998 bytes).\n"
4115 "The contents of the message might be broken on the way to the delivery.\n"
4117 "Send it anyway?"), line + 1);
4118 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
4120 if (aval != G_ALERTDEFAULT) {
4125 if (encoding != ENC_UNKNOWN)
4126 procmime_encode_content(mimetext, encoding);
4128 /* append attachment parts */
4129 if (compose_use_attach(compose)) {
4130 MimeInfo *mimempart;
4131 gchar *boundary = NULL;
4132 mimempart = procmime_mimeinfo_new();
4133 mimempart->content = MIMECONTENT_EMPTY;
4134 mimempart->type = MIMETYPE_MULTIPART;
4135 mimempart->subtype = g_strdup("mixed");
4140 boundary = generate_mime_boundary(NULL);
4141 } while (strstr(buf, boundary) != NULL);
4143 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4146 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4148 g_node_append(mimempart->node, mimetext->node);
4149 g_node_append(mimemsg->node, mimempart->node);
4151 compose_add_attachments(compose, mimempart);
4153 g_node_append(mimemsg->node, mimetext->node);
4155 /* sign message if sending */
4156 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4157 privacy_system_can_sign(compose->privacy_system))
4158 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4161 procmime_write_mimeinfo(mimemsg, fp);
4163 procmime_mimeinfo_free_all(mimemsg);
4168 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4170 GtkTextBuffer *buffer;
4171 GtkTextIter start, end;
4176 if ((fp = g_fopen(file, "wb")) == NULL) {
4177 FILE_OP_ERROR(file, "fopen");
4181 /* chmod for security */
4182 if (change_file_mode_rw(fp, file) < 0) {
4183 FILE_OP_ERROR(file, "chmod");
4184 g_warning("can't change file mode\n");
4187 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4188 gtk_text_buffer_get_start_iter(buffer, &start);
4189 gtk_text_buffer_get_end_iter(buffer, &end);
4190 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4192 chars = conv_codeset_strdup
4193 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4196 if (!chars) return -1;
4199 len = strlen(chars);
4200 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4201 FILE_OP_ERROR(file, "fwrite");
4210 if (fclose(fp) == EOF) {
4211 FILE_OP_ERROR(file, "fclose");
4218 static gint compose_remove_reedit_target(Compose *compose)
4221 MsgInfo *msginfo = compose->targetinfo;
4223 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4224 if (!msginfo) return -1;
4226 item = msginfo->folder;
4227 g_return_val_if_fail(item != NULL, -1);
4229 if (procmsg_msg_exist(msginfo) &&
4230 (folder_has_parent_of_type(item, F_QUEUE) ||
4231 folder_has_parent_of_type(item, F_DRAFT)
4232 || msginfo == compose->autosaved_draft)) {
4233 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4234 g_warning("can't remove the old message\n");
4242 void compose_remove_draft(Compose *compose)
4245 MsgInfo *msginfo = compose->targetinfo;
4246 drafts = account_get_special_folder(compose->account, F_DRAFT);
4248 if (procmsg_msg_exist(msginfo)) {
4249 folder_item_remove_msg(drafts, msginfo->msgnum);
4254 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4256 return compose_queue_sub (compose, msgnum, item, FALSE);
4258 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4265 static gboolean lock = FALSE;
4266 PrefsAccount *mailac = NULL, *newsac = NULL;
4268 debug_print("queueing message...\n");
4269 g_return_val_if_fail(compose->account != NULL, -1);
4273 if (compose_check_entries(compose, check_subject) == FALSE) {
4278 if (!compose->to_list && !compose->newsgroup_list) {
4279 g_warning("can't get recipient list.");
4284 if (compose->to_list) {
4285 if (compose->account->protocol != A_NNTP)
4286 mailac = compose->account;
4287 else if (cur_account && cur_account->protocol != A_NNTP)
4288 mailac = cur_account;
4289 else if (!(mailac = compose_current_mail_account())) {
4291 alertpanel_error(_("No account for sending mails available!"));
4296 if (compose->newsgroup_list) {
4297 if (compose->account->protocol == A_NNTP)
4298 newsac = compose->account;
4299 else if (!newsac->protocol != A_NNTP) {
4301 alertpanel_error(_("No account for posting news available!"));
4306 if (prefs_common.linewrap_at_send)
4307 compose_wrap_all(compose);
4309 /* write queue header */
4310 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4311 G_DIR_SEPARATOR, compose);
4312 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4313 FILE_OP_ERROR(tmp, "fopen");
4318 if (change_file_mode_rw(fp, tmp) < 0) {
4319 FILE_OP_ERROR(tmp, "chmod");
4320 g_warning("can't change file mode\n");
4323 /* queueing variables */
4324 fprintf(fp, "AF:\n");
4325 fprintf(fp, "NF:0\n");
4326 fprintf(fp, "PS:10\n");
4327 fprintf(fp, "SRH:1\n");
4328 fprintf(fp, "SFN:\n");
4329 fprintf(fp, "DSR:\n");
4331 fprintf(fp, "MID:<%s>\n", compose->msgid);
4333 fprintf(fp, "MID:\n");
4334 fprintf(fp, "CFG:\n");
4335 fprintf(fp, "PT:0\n");
4336 fprintf(fp, "S:%s\n", compose->account->address);
4337 fprintf(fp, "RQ:\n");
4339 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4341 fprintf(fp, "SSV:\n");
4343 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4345 fprintf(fp, "NSV:\n");
4346 fprintf(fp, "SSH:\n");
4347 /* write recepient list */
4348 if (compose->to_list) {
4349 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4350 for (cur = compose->to_list->next; cur != NULL;
4352 fprintf(fp, ",<%s>", (gchar *)cur->data);
4355 /* write newsgroup list */
4356 if (compose->newsgroup_list) {
4358 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4359 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4360 fprintf(fp, ",%s", (gchar *)cur->data);
4363 /* Sylpheed account IDs */
4365 fprintf(fp, "MAID:%d\n", mailac->account_id);
4367 fprintf(fp, "NAID:%d\n", newsac->account_id);
4369 if (compose->privacy_system != NULL) {
4370 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4371 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4372 if (compose->use_encryption) {
4375 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4376 if (encdata != NULL) {
4377 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4378 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4379 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4381 } /* else we finally dont want to encrypt */
4383 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4384 /* and if encdata was null, it means there's been a problem in
4391 /* Save copy folder */
4392 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4393 gchar *savefolderid;
4395 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4396 fprintf(fp, "SCF:%s\n", savefolderid);
4397 g_free(savefolderid);
4399 /* Save copy folder */
4400 if (compose->return_receipt) {
4401 fprintf(fp, "RRCPT:1\n");
4403 /* Message-ID of message replying to */
4404 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4407 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4408 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4411 /* Message-ID of message forwarding to */
4412 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4415 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4416 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4421 if (compose->redirect_filename != NULL) {
4422 if (compose_redirect_write_to_file(compose, fp) < 0) {
4431 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4436 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4440 if (fclose(fp) == EOF) {
4441 FILE_OP_ERROR(tmp, "fclose");
4447 queue = account_get_special_folder(compose->account, F_QUEUE);
4449 g_warning("can't find queue folder\n");
4454 folder_item_scan(queue);
4455 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4456 g_warning("can't queue the message\n");
4464 if (compose->mode == COMPOSE_REEDIT) {
4465 compose_remove_reedit_target(compose);
4468 if ((msgnum != NULL) && (item != NULL)) {
4476 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4479 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4481 struct stat statbuf;
4482 gchar *type, *subtype;
4483 GtkTreeModel *model;
4486 model = gtk_tree_view_get_model(tree_view);
4488 if (!gtk_tree_model_get_iter_first(model, &iter))
4491 gtk_tree_model_get(model, &iter,
4495 mimepart = procmime_mimeinfo_new();
4496 mimepart->content = MIMECONTENT_FILE;
4497 mimepart->data.filename = g_strdup(ainfo->file);
4498 mimepart->offset = 0;
4500 stat(ainfo->file, &statbuf);
4501 mimepart->length = statbuf.st_size;
4503 type = g_strdup(ainfo->content_type);
4505 if (!strchr(type, '/')) {
4507 type = g_strdup("application/octet-stream");
4510 subtype = strchr(type, '/') + 1;
4511 *(subtype - 1) = '\0';
4512 mimepart->type = procmime_get_media_type(type);
4513 mimepart->subtype = g_strdup(subtype);
4516 if (mimepart->type == MIMETYPE_MESSAGE &&
4517 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4518 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4520 g_hash_table_insert(mimepart->typeparameters,
4521 g_strdup("name"), g_strdup(ainfo->name));
4522 g_hash_table_insert(mimepart->dispositionparameters,
4523 g_strdup("filename"), g_strdup(ainfo->name));
4524 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4527 if (compose->use_signing) {
4528 if (ainfo->encoding == ENC_7BIT)
4529 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4530 else if (ainfo->encoding == ENC_8BIT)
4531 ainfo->encoding = ENC_BASE64;
4534 procmime_encode_content(mimepart, ainfo->encoding);
4536 g_node_append(parent->node, mimepart->node);
4537 } while (gtk_tree_model_iter_next(model, &iter));
4540 #define QUOTE_IF_REQUIRED(out, str) \
4542 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4546 len = strlen(str) + 3; \
4547 if ((__tmp = alloca(len)) == NULL) { \
4548 g_warning("can't allocate memory\n"); \
4549 g_string_free(header, TRUE); \
4552 g_snprintf(__tmp, len, "\"%s\"", str); \
4557 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4558 g_warning("can't allocate memory\n"); \
4559 g_string_free(header, TRUE); \
4562 strcpy(__tmp, str); \
4568 #define IS_IN_CUSTOM_HEADER(header) \
4569 (compose->account->add_customhdr && \
4570 custom_header_find(compose->account->customhdr_list, header) != NULL)
4572 static void compose_add_headerfield_from_headerlist(Compose *compose,
4574 const gchar *fieldname,
4575 const gchar *seperator)
4577 gchar *str, *fieldname_w_colon, *trans_fieldname;
4578 gboolean add_field = FALSE;
4580 ComposeHeaderEntry *headerentry;
4581 const gchar * headerentryname;
4584 if (IS_IN_CUSTOM_HEADER(fieldname))
4587 debug_print("Adding %s-fields\n", fieldname);
4589 fieldstr = g_string_sized_new(64);
4591 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4592 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4594 for (list = compose->header_list; list; list = list->next) {
4595 headerentry = ((ComposeHeaderEntry *)list->data);
4596 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4598 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4599 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4601 if (str[0] != '\0') {
4603 g_string_append(fieldstr, seperator);
4604 g_string_append(fieldstr, str);
4613 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4614 compose_convert_header
4615 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4616 strlen(fieldname) + 2, TRUE);
4617 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4621 g_free(fieldname_w_colon);
4622 g_string_free(fieldstr, TRUE);
4627 static gchar *compose_get_header(Compose *compose)
4629 gchar buf[BUFFSIZE];
4630 const gchar *entry_str;
4634 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4637 g_return_val_if_fail(compose->account != NULL, NULL);
4638 g_return_val_if_fail(compose->account->address != NULL, NULL);
4640 header = g_string_sized_new(64);
4643 if (compose->account->add_date) {
4644 get_rfc822_date(buf, sizeof(buf));
4645 g_string_append_printf(header, "Date: %s\n", buf);
4649 if (compose->account->name && *compose->account->name) {
4650 compose_convert_header
4651 (compose, buf, sizeof(buf), compose->account->name,
4652 strlen("From: "), TRUE);
4653 QUOTE_IF_REQUIRED(name, buf);
4654 g_string_append_printf(header, "From: %s <%s>\n",
4655 name, compose->account->address);
4657 g_string_append_printf(header, "From: %s\n", compose->account->address);
4660 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4663 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4666 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4669 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4672 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4674 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4677 compose_convert_header(compose, buf, sizeof(buf), str,
4678 strlen("Subject: "), FALSE);
4679 g_string_append_printf(header, "Subject: %s\n", buf);
4685 if (compose->account->gen_msgid) {
4686 generate_msgid(buf, sizeof(buf));
4687 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4688 compose->msgid = g_strdup(buf);
4691 if (compose->remove_references == FALSE) {
4693 if (compose->inreplyto && compose->to_list)
4694 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4697 if (compose->references)
4698 g_string_append_printf(header, "References: %s\n", compose->references);
4702 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4705 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4708 if (compose->account->organization &&
4709 strlen(compose->account->organization) &&
4710 !IS_IN_CUSTOM_HEADER("Organization")) {
4711 compose_convert_header(compose, buf, sizeof(buf),
4712 compose->account->organization,
4713 strlen("Organization: "), FALSE);
4714 g_string_append_printf(header, "Organization: %s\n", buf);
4717 /* Program version and system info */
4718 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4719 !compose->newsgroup_list) {
4720 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4722 gtk_major_version, gtk_minor_version, gtk_micro_version,
4725 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4726 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4728 gtk_major_version, gtk_minor_version, gtk_micro_version,
4732 /* custom headers */
4733 if (compose->account->add_customhdr) {
4736 for (cur = compose->account->customhdr_list; cur != NULL;
4738 CustomHeader *chdr = (CustomHeader *)cur->data;
4740 if (custom_header_is_allowed(chdr->name)) {
4741 compose_convert_header
4742 (compose, buf, sizeof(buf),
4743 chdr->value ? chdr->value : "",
4744 strlen(chdr->name) + 2, FALSE);
4745 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4751 switch (compose->priority) {
4752 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4753 "X-Priority: 1 (Highest)\n");
4755 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4756 "X-Priority: 2 (High)\n");
4758 case PRIORITY_NORMAL: break;
4759 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4760 "X-Priority: 4 (Low)\n");
4762 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4763 "X-Priority: 5 (Lowest)\n");
4765 default: debug_print("compose: priority unknown : %d\n",
4769 /* Request Return Receipt */
4770 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4771 if (compose->return_receipt) {
4772 if (compose->account->name
4773 && *compose->account->name) {
4774 compose_convert_header(compose, buf, sizeof(buf),
4775 compose->account->name,
4776 strlen("Disposition-Notification-To: "),
4778 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4780 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4784 /* get special headers */
4785 for (list = compose->header_list; list; list = list->next) {
4786 ComposeHeaderEntry *headerentry;
4789 gchar *headername_wcolon;
4790 gchar *headername_trans;
4793 gboolean standard_header = FALSE;
4795 headerentry = ((ComposeHeaderEntry *)list->data);
4797 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4798 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4803 if (!strstr(tmp, ":")) {
4804 headername_wcolon = g_strconcat(tmp, ":", NULL);
4805 headername = g_strdup(tmp);
4807 headername_wcolon = g_strdup(tmp);
4808 headername = g_strdup(strtok(tmp, ":"));
4812 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4813 Xstrdup_a(headervalue, entry_str, return NULL);
4814 subst_char(headervalue, '\r', ' ');
4815 subst_char(headervalue, '\n', ' ');
4816 string = std_headers;
4817 while (*string != NULL) {
4818 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4819 if (!strcmp(headername_trans,headername_wcolon))
4820 standard_header = TRUE;
4823 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4824 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4827 g_free(headername_wcolon);
4831 g_string_free(header, FALSE);
4836 #undef IS_IN_CUSTOM_HEADER
4838 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4839 gint header_len, gboolean addr_field)
4841 gchar *tmpstr = NULL;
4842 const gchar *out_codeset = NULL;
4844 g_return_if_fail(src != NULL);
4845 g_return_if_fail(dest != NULL);
4847 if (len < 1) return;
4849 tmpstr = g_strdup(src);
4851 subst_char(tmpstr, '\n', ' ');
4852 subst_char(tmpstr, '\r', ' ');
4855 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4856 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4857 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4862 codeconv_set_strict(TRUE);
4863 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4864 conv_get_charset_str(compose->out_encoding));
4865 codeconv_set_strict(FALSE);
4867 if (!dest || *dest == '\0') {
4868 gchar *test_conv_global_out = NULL;
4869 gchar *test_conv_reply = NULL;
4871 /* automatic mode. be automatic. */
4872 codeconv_set_strict(TRUE);
4874 out_codeset = conv_get_outgoing_charset_str();
4876 debug_print("trying to convert to %s\n", out_codeset);
4877 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4880 if (!test_conv_global_out && compose->orig_charset) {
4881 out_codeset = compose->orig_charset;
4882 debug_print("failure; trying to convert to %s\n", out_codeset);
4883 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4886 if (!test_conv_global_out && !test_conv_reply) {
4888 out_codeset = CS_INTERNAL;
4889 debug_print("finally using %s\n", out_codeset);
4891 g_free(test_conv_global_out);
4892 g_free(test_conv_reply);
4893 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4895 codeconv_set_strict(FALSE);
4900 static void compose_create_header_entry(Compose *compose)
4902 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4906 GList *combo_list = NULL;
4908 const gchar *header = NULL;
4909 ComposeHeaderEntry *headerentry;
4910 gboolean standard_header = FALSE;
4912 headerentry = g_new0(ComposeHeaderEntry, 1);
4915 combo = gtk_combo_new();
4917 while(*string != NULL) {
4918 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4921 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4922 g_list_free(combo_list);
4923 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4924 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4925 G_CALLBACK(compose_grab_focus_cb), compose);
4926 gtk_widget_show(combo);
4927 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4928 if (compose->header_last) {
4929 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4931 while (*string != NULL) {
4932 if (!strcmp(*string, last_header_entry))
4933 standard_header = TRUE;
4936 if (standard_header)
4937 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4939 if (!compose->header_last || !standard_header) {
4940 switch(compose->account->protocol) {
4942 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4945 header = prefs_common.trans_hdr ? _("To:") : "To:";
4950 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4952 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4953 G_CALLBACK(compose_grab_focus_cb), compose);
4956 entry = gtk_entry_new();
4957 gtk_widget_show(entry);
4958 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);
4960 g_signal_connect(G_OBJECT(entry), "key-press-event",
4961 G_CALLBACK(compose_headerentry_key_press_event_cb),
4963 g_signal_connect(G_OBJECT(entry), "changed",
4964 G_CALLBACK(compose_headerentry_changed_cb),
4966 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4967 G_CALLBACK(compose_grab_focus_cb), compose);
4970 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4971 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4972 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4973 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4974 G_CALLBACK(compose_header_drag_received_cb),
4976 g_signal_connect(G_OBJECT(entry), "drag-drop",
4977 G_CALLBACK(compose_drag_drop),
4980 address_completion_register_entry(GTK_ENTRY(entry));
4982 headerentry->compose = compose;
4983 headerentry->combo = combo;
4984 headerentry->entry = entry;
4985 headerentry->headernum = compose->header_nextrow;
4987 compose->header_nextrow++;
4988 compose->header_last = headerentry;
4991 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4993 ComposeHeaderEntry *last_header;
4995 last_header = compose->header_last;
4997 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4998 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5001 static GtkWidget *compose_create_header(Compose *compose)
5005 GtkWidget *from_optmenu_hbox;
5006 GtkWidget *header_scrolledwin;
5007 GtkWidget *header_table;
5011 /* header labels and entries */
5012 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5013 gtk_widget_show(header_scrolledwin);
5014 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5016 header_table = gtk_table_new(2, 2, FALSE);
5017 gtk_widget_show(header_table);
5018 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5019 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5020 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5023 /* option menu for selecting accounts */
5024 hbox = gtk_hbox_new(FALSE, 0);
5025 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5026 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5027 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5029 from_optmenu_hbox = compose_account_option_menu_create(compose);
5030 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5031 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5034 compose->header_table = header_table;
5035 compose->header_list = NULL;
5036 compose->header_nextrow = count;
5038 compose_create_header_entry(compose);
5040 compose->table = NULL;
5042 return header_scrolledwin ;
5045 GtkWidget *compose_create_attach(Compose *compose)
5047 GtkWidget *attach_scrwin;
5048 GtkWidget *attach_clist;
5050 GtkListStore *store;
5051 GtkCellRenderer *renderer;
5052 GtkTreeViewColumn *column;
5053 GtkTreeSelection *selection;
5055 /* attachment list */
5056 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5057 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5058 GTK_POLICY_AUTOMATIC,
5059 GTK_POLICY_AUTOMATIC);
5060 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5062 store = gtk_list_store_new(N_ATTACH_COLS,
5067 G_TYPE_AUTO_POINTER,
5069 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5070 (GTK_TREE_MODEL(store)));
5071 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5072 g_object_unref(store);
5074 renderer = gtk_cell_renderer_text_new();
5075 column = gtk_tree_view_column_new_with_attributes
5076 (_("Mime type"), renderer, "text",
5077 COL_MIMETYPE, NULL);
5078 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5080 renderer = gtk_cell_renderer_text_new();
5081 column = gtk_tree_view_column_new_with_attributes
5082 (_("Size"), renderer, "text",
5084 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5086 renderer = gtk_cell_renderer_text_new();
5087 column = gtk_tree_view_column_new_with_attributes
5088 (_("Name"), renderer, "text",
5090 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5092 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5093 prefs_common.enable_rules_hint);
5094 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5095 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5097 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5098 G_CALLBACK(attach_selected), compose);
5099 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5100 G_CALLBACK(attach_button_pressed), compose);
5101 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5102 G_CALLBACK(attach_key_pressed), compose);
5105 gtk_drag_dest_set(attach_clist,
5106 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5107 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5108 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5109 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5110 G_CALLBACK(compose_attach_drag_received_cb),
5112 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5113 G_CALLBACK(compose_drag_drop),
5116 compose->attach_scrwin = attach_scrwin;
5117 compose->attach_clist = attach_clist;
5119 return attach_scrwin;
5122 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5123 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5125 static GtkWidget *compose_create_others(Compose *compose)
5128 GtkWidget *savemsg_checkbtn;
5129 GtkWidget *savemsg_entry;
5130 GtkWidget *savemsg_select;
5133 gchar *folderidentifier;
5135 /* Table for settings */
5136 table = gtk_table_new(3, 1, FALSE);
5137 gtk_widget_show(table);
5138 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5141 /* Save Message to folder */
5142 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5143 gtk_widget_show(savemsg_checkbtn);
5144 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5145 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5146 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5148 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5149 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5151 savemsg_entry = gtk_entry_new();
5152 gtk_widget_show(savemsg_entry);
5153 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5154 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5155 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5156 G_CALLBACK(compose_grab_focus_cb), compose);
5157 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5158 folderidentifier = folder_item_get_identifier(account_get_special_folder
5159 (compose->account, F_OUTBOX));
5160 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5161 g_free(folderidentifier);
5164 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5165 gtk_widget_show(savemsg_select);
5166 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5167 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5168 G_CALLBACK(compose_savemsg_select_cb),
5173 compose->savemsg_checkbtn = savemsg_checkbtn;
5174 compose->savemsg_entry = savemsg_entry;
5179 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5181 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5182 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5185 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5190 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5193 path = folder_item_get_identifier(dest);
5195 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5199 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5202 #define BLOCK_WRAP() { \
5203 prev_autowrap = compose->autowrap; \
5204 buffer = gtk_text_view_get_buffer( \
5205 GTK_TEXT_VIEW(compose->text)); \
5206 compose->autowrap = FALSE; \
5208 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5209 G_CALLBACK(compose_changed_cb), \
5211 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5212 G_CALLBACK(text_inserted), \
5215 #define UNBLOCK_WRAP() { \
5216 compose->autowrap = prev_autowrap; \
5217 if (compose->autowrap) \
5218 compose_wrap_all(compose); \
5220 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5221 G_CALLBACK(compose_changed_cb), \
5223 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5224 G_CALLBACK(text_inserted), \
5229 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5233 GtkTextBuffer *buffer;
5235 if (event->button == 3) {
5238 /* move the cursor to allow GtkAspell to check the word
5239 * under the mouse */
5240 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5241 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5243 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5245 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5246 return FALSE; /* pass the event so that the right-click goes through */
5249 if (event->button == 2) {
5251 entry_paste_clipboard(compose, compose->focused_editable,
5252 prefs_common.linewrap_pastes,
5253 GDK_SELECTION_PRIMARY);
5260 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5266 GtkWidget *handlebox;
5268 GtkWidget *notebook;
5273 GtkWidget *subject_hbox;
5274 GtkWidget *subject_frame;
5275 GtkWidget *subject_entry;
5279 GtkWidget *edit_vbox;
5280 GtkWidget *ruler_hbox;
5282 GtkWidget *scrolledwin;
5284 GtkTextBuffer *buffer;
5285 GtkClipboard *clipboard;
5287 UndoMain *undostruct;
5289 gchar *titles[N_ATTACH_COLS];
5290 guint n_menu_entries;
5293 gboolean success[1];
5294 GtkWidget *popupmenu;
5295 GtkItemFactory *popupfactory;
5296 GtkItemFactory *ifactory;
5297 GtkWidget *tmpl_menu;
5299 GtkWidget *menuitem;
5302 GtkAspell * gtkaspell = NULL;
5305 static GdkGeometry geometry;
5307 g_return_val_if_fail(account != NULL, NULL);
5309 debug_print("Creating compose window...\n");
5310 compose = g_new0(Compose, 1);
5312 titles[COL_MIMETYPE] = _("MIME type");
5313 titles[COL_SIZE] = _("Size");
5314 titles[COL_NAME] = _("Name");
5316 compose->account = account;
5318 compose->mutex = g_mutex_new();
5319 compose->set_cursor_pos = -1;
5321 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5322 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5323 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5325 if (!geometry.max_width) {
5326 geometry.max_width = gdk_screen_width();
5327 geometry.max_height = gdk_screen_height();
5330 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5331 &geometry, GDK_HINT_MAX_SIZE);
5332 if (!geometry.min_width) {
5333 geometry.min_width = 600;
5334 geometry.min_height = 480;
5336 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5337 &geometry, GDK_HINT_MIN_SIZE);
5338 gtk_widget_set_uposition(window, prefs_common.compose_x,
5339 prefs_common.compose_y);
5341 g_signal_connect(G_OBJECT(window), "delete_event",
5342 G_CALLBACK(compose_delete_cb), compose);
5343 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5344 gtk_widget_realize(window);
5346 gtkut_widget_set_composer_icon(window);
5348 vbox = gtk_vbox_new(FALSE, 0);
5349 gtk_container_add(GTK_CONTAINER(window), vbox);
5351 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5352 menubar = menubar_create(window, compose_entries,
5353 n_menu_entries, "<Compose>", compose);
5354 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5356 if (prefs_common.toolbar_detachable) {
5357 handlebox = gtk_handle_box_new();
5359 handlebox = gtk_hbox_new(FALSE, 0);
5361 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5363 gtk_widget_realize(handlebox);
5364 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5367 vbox2 = gtk_vbox_new(FALSE, 2);
5368 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5369 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5372 notebook = gtk_notebook_new();
5373 gtk_widget_set_size_request(notebook, -1, 130);
5374 gtk_widget_show(notebook);
5376 /* header labels and entries */
5377 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5378 /* attachment list */
5379 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5381 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5384 subject_hbox = gtk_hbox_new(FALSE, 0);
5385 gtk_widget_show(subject_hbox);
5387 subject_frame = gtk_frame_new(NULL);
5388 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5389 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5390 gtk_widget_show(subject_frame);
5392 subject = gtk_hbox_new(FALSE, 0);
5393 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5394 gtk_widget_show(subject);
5396 label = gtk_label_new(_("Subject:"));
5397 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5398 gtk_widget_show(label);
5400 subject_entry = gtk_entry_new();
5401 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5402 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5403 G_CALLBACK(compose_grab_focus_cb), compose);
5404 gtk_widget_show(subject_entry);
5405 compose->subject_entry = subject_entry;
5406 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5408 edit_vbox = gtk_vbox_new(FALSE, 0);
5410 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5413 ruler_hbox = gtk_hbox_new(FALSE, 0);
5414 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5416 ruler = gtk_shruler_new();
5417 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5418 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5422 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5423 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5424 GTK_POLICY_AUTOMATIC,
5425 GTK_POLICY_AUTOMATIC);
5426 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5428 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5429 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5431 text = gtk_text_view_new();
5432 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5433 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5434 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5435 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5436 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5438 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5440 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5441 G_CALLBACK(compose_edit_size_alloc),
5443 g_signal_connect(G_OBJECT(buffer), "changed",
5444 G_CALLBACK(compose_changed_cb), compose);
5445 g_signal_connect(G_OBJECT(text), "grab_focus",
5446 G_CALLBACK(compose_grab_focus_cb), compose);
5447 g_signal_connect(G_OBJECT(buffer), "insert_text",
5448 G_CALLBACK(text_inserted), compose);
5449 g_signal_connect(G_OBJECT(text), "button_press_event",
5450 G_CALLBACK(text_clicked), compose);
5453 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5454 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5455 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5456 g_signal_connect(G_OBJECT(text), "drag_data_received",
5457 G_CALLBACK(compose_insert_drag_received_cb),
5459 g_signal_connect(G_OBJECT(text), "drag-drop",
5460 G_CALLBACK(compose_drag_drop),
5462 gtk_widget_show_all(vbox);
5464 /* pane between attach clist and text */
5465 paned = gtk_vpaned_new();
5466 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5467 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5468 gtk_paned_add1(GTK_PANED(paned), notebook);
5469 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5470 gtk_widget_show_all(paned);
5473 if (prefs_common.textfont) {
5474 PangoFontDescription *font_desc;
5476 font_desc = pango_font_description_from_string
5477 (prefs_common.textfont);
5479 gtk_widget_modify_font(text, font_desc);
5480 pango_font_description_free(font_desc);
5484 color[0] = quote_color;
5485 cmap = gdk_drawable_get_colormap(window->window);
5486 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5487 if (success[0] == FALSE) {
5490 g_warning("Compose: color allocation failed.\n");
5491 style = gtk_widget_get_style(text);
5492 quote_color = style->black;
5495 n_entries = sizeof(compose_popup_entries) /
5496 sizeof(compose_popup_entries[0]);
5497 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5498 "<Compose>", &popupfactory,
5501 ifactory = gtk_item_factory_from_widget(menubar);
5502 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5503 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5504 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5506 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5508 undostruct = undo_init(text);
5509 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5512 address_completion_start(window);
5514 compose->window = window;
5515 compose->vbox = vbox;
5516 compose->menubar = menubar;
5517 compose->handlebox = handlebox;
5519 compose->vbox2 = vbox2;
5521 compose->paned = paned;
5523 compose->edit_vbox = edit_vbox;
5524 compose->ruler_hbox = ruler_hbox;
5525 compose->ruler = ruler;
5526 compose->scrolledwin = scrolledwin;
5527 compose->text = text;
5529 compose->focused_editable = NULL;
5531 compose->popupmenu = popupmenu;
5532 compose->popupfactory = popupfactory;
5534 compose->tmpl_menu = tmpl_menu;
5536 compose->mode = mode;
5538 compose->targetinfo = NULL;
5539 compose->replyinfo = NULL;
5540 compose->fwdinfo = NULL;
5542 compose->replyto = NULL;
5544 compose->bcc = NULL;
5545 compose->followup_to = NULL;
5547 compose->ml_post = NULL;
5549 compose->inreplyto = NULL;
5550 compose->references = NULL;
5551 compose->msgid = NULL;
5552 compose->boundary = NULL;
5554 compose->autowrap = prefs_common.autowrap;
5556 compose->use_signing = FALSE;
5557 compose->use_encryption = FALSE;
5558 compose->privacy_system = NULL;
5560 compose->modified = FALSE;
5562 compose->return_receipt = FALSE;
5564 compose->to_list = NULL;
5565 compose->newsgroup_list = NULL;
5567 compose->undostruct = undostruct;
5569 compose->sig_str = NULL;
5571 compose->exteditor_file = NULL;
5572 compose->exteditor_pid = -1;
5573 compose->exteditor_tag = -1;
5574 compose->draft_timeout_tag = -1;
5577 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5578 if (mode != COMPOSE_REDIRECT) {
5579 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5580 strcmp(prefs_common.dictionary, _("None"))) {
5581 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5582 prefs_common.dictionary,
5583 conv_get_locale_charset_str(),
5584 prefs_common.misspelled_col,
5585 prefs_common.check_while_typing,
5586 prefs_common.use_alternate,
5587 GTK_TEXT_VIEW(text),
5588 GTK_WINDOW(compose->window));
5590 alertpanel_error(_("Spell checker could not "
5592 gtkaspell_checkers_strerror());
5593 gtkaspell_checkers_reset_error();
5595 if (!gtkaspell_set_sug_mode(gtkaspell,
5596 prefs_common.aspell_sugmode)) {
5597 debug_print("Aspell: could not set "
5598 "suggestion mode %s\n",
5599 gtkaspell_checkers_strerror());
5600 gtkaspell_checkers_reset_error();
5603 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5607 compose->gtkaspell = gtkaspell;
5610 compose_select_account(compose, account, TRUE);
5612 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5613 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5614 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5616 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5617 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5619 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5620 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5623 if (account->protocol != A_NNTP)
5624 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5626 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5628 addressbook_set_target_compose(compose);
5630 if (mode != COMPOSE_REDIRECT)
5631 compose_set_template_menu(compose);
5633 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5634 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5637 compose_list = g_list_append(compose_list, compose);
5639 if (!prefs_common.show_ruler)
5640 gtk_widget_hide(ruler_hbox);
5642 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5643 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5644 prefs_common.show_ruler);
5647 compose->priority = PRIORITY_NORMAL;
5648 compose_update_priority_menu_item(compose);
5650 compose_set_out_encoding(compose);
5653 compose_update_actions_menu(compose);
5655 /* Privacy Systems menu */
5656 compose_update_privacy_systems_menu(compose);
5658 activate_privacy_system(compose, account, TRUE);
5659 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5660 gtk_widget_show(window);
5665 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5671 gint num = 0, def_menu = 0;
5673 accounts = account_get_list();
5674 g_return_val_if_fail(accounts != NULL, NULL);
5676 hbox = gtk_hbox_new(FALSE, 0);
5677 optmenu = gtk_option_menu_new();
5678 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5679 menu = gtk_menu_new();
5681 for (; accounts != NULL; accounts = accounts->next, num++) {
5682 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5683 GtkWidget *menuitem;
5686 if (ac == compose->account) def_menu = num;
5689 name = g_strdup_printf("%s: %s <%s>",
5691 ac->name, ac->address);
5693 name = g_strdup_printf("%s: %s",
5694 ac->account_name, ac->address);
5695 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5697 g_signal_connect(G_OBJECT(menuitem), "activate",
5698 G_CALLBACK(account_activated),
5702 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5703 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5708 static void compose_set_priority_cb(gpointer data,
5712 Compose *compose = (Compose *) data;
5713 compose->priority = action;
5716 static void compose_update_priority_menu_item(Compose * compose)
5718 GtkItemFactory *ifactory;
5719 GtkWidget *menuitem = NULL;
5721 ifactory = gtk_item_factory_from_widget(compose->menubar);
5723 switch (compose->priority) {
5724 case PRIORITY_HIGHEST:
5725 menuitem = gtk_item_factory_get_item
5726 (ifactory, "/Options/Priority/Highest");
5729 menuitem = gtk_item_factory_get_item
5730 (ifactory, "/Options/Priority/High");
5732 case PRIORITY_NORMAL:
5733 menuitem = gtk_item_factory_get_item
5734 (ifactory, "/Options/Priority/Normal");
5737 menuitem = gtk_item_factory_get_item
5738 (ifactory, "/Options/Priority/Low");
5740 case PRIORITY_LOWEST:
5741 menuitem = gtk_item_factory_get_item
5742 (ifactory, "/Options/Priority/Lowest");
5745 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5748 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5750 Compose *compose = (Compose *) data;
5752 GtkItemFactory *ifactory;
5753 gboolean can_sign = FALSE, can_encrypt = FALSE;
5755 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5757 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5760 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5761 g_free(compose->privacy_system);
5762 compose->privacy_system = NULL;
5763 if (systemid != NULL) {
5764 compose->privacy_system = g_strdup(systemid);
5766 can_sign = privacy_system_can_sign(systemid);
5767 can_encrypt = privacy_system_can_encrypt(systemid);
5770 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5772 ifactory = gtk_item_factory_from_widget(compose->menubar);
5773 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5774 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5777 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5779 static gchar *branch_path = "/Options/Privacy System";
5780 GtkItemFactory *ifactory;
5781 GtkWidget *menuitem = NULL;
5783 gboolean can_sign = FALSE, can_encrypt = FALSE;
5784 gboolean found = FALSE;
5786 ifactory = gtk_item_factory_from_widget(compose->menubar);
5788 if (compose->privacy_system != NULL) {
5791 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5792 g_return_if_fail(menuitem != NULL);
5794 amenu = GTK_MENU_SHELL(menuitem)->children;
5796 while (amenu != NULL) {
5797 GList *alist = amenu->next;
5799 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5800 if (systemid != NULL) {
5801 if (strcmp(systemid, compose->privacy_system) == 0) {
5802 menuitem = GTK_WIDGET(amenu->data);
5804 can_sign = privacy_system_can_sign(systemid);
5805 can_encrypt = privacy_system_can_encrypt(systemid);
5809 } else if (strlen(compose->privacy_system) == 0) {
5810 menuitem = GTK_WIDGET(amenu->data);
5813 can_encrypt = FALSE;
5820 if (menuitem != NULL)
5821 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5823 if (warn && !found && strlen(compose->privacy_system)) {
5824 gchar *tmp = g_strdup_printf(
5825 _("The privacy system '%s' cannot be loaded. You "
5826 "will not be able to sign or encrypt this message."),
5827 compose->privacy_system);
5828 alertpanel_warning(tmp);
5833 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5834 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5837 static void compose_set_out_encoding(Compose *compose)
5839 GtkItemFactoryEntry *entry;
5840 GtkItemFactory *ifactory;
5841 CharSet out_encoding;
5842 gchar *path, *p, *q;
5845 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5846 ifactory = gtk_item_factory_from_widget(compose->menubar);
5848 for (entry = compose_entries; entry->callback != compose_address_cb;
5850 if (entry->callback == compose_set_encoding_cb &&
5851 (CharSet)entry->callback_action == out_encoding) {
5852 p = q = path = g_strdup(entry->path);
5864 item = gtk_item_factory_get_item(ifactory, path);
5865 gtk_widget_activate(item);
5872 static void compose_set_template_menu(Compose *compose)
5874 GSList *tmpl_list, *cur;
5878 tmpl_list = template_get_config();
5880 menu = gtk_menu_new();
5882 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5883 Template *tmpl = (Template *)cur->data;
5885 item = gtk_menu_item_new_with_label(tmpl->name);
5886 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5887 g_signal_connect(G_OBJECT(item), "activate",
5888 G_CALLBACK(compose_template_activate_cb),
5890 g_object_set_data(G_OBJECT(item), "template", tmpl);
5891 gtk_widget_show(item);
5894 gtk_widget_show(menu);
5895 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5898 void compose_update_actions_menu(Compose *compose)
5900 GtkItemFactory *ifactory;
5902 ifactory = gtk_item_factory_from_widget(compose->menubar);
5903 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5906 void compose_update_privacy_systems_menu(Compose *compose)
5908 static gchar *branch_path = "/Options/Privacy System";
5909 GtkItemFactory *ifactory;
5910 GtkWidget *menuitem;
5911 GSList *systems, *cur;
5914 GtkWidget *system_none;
5917 ifactory = gtk_item_factory_from_widget(compose->menubar);
5919 /* remove old entries */
5920 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5921 g_return_if_fail(menuitem != NULL);
5923 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5924 while (amenu != NULL) {
5925 GList *alist = amenu->next;
5926 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5930 system_none = gtk_item_factory_get_widget(ifactory,
5931 "/Options/Privacy System/None");
5933 g_signal_connect(G_OBJECT(system_none), "activate",
5934 G_CALLBACK(compose_set_privacy_system_cb), compose);
5936 systems = privacy_get_system_ids();
5937 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5938 gchar *systemid = cur->data;
5940 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5941 widget = gtk_radio_menu_item_new_with_label(group,
5942 privacy_system_get_name(systemid));
5943 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5944 g_strdup(systemid), g_free);
5945 g_signal_connect(G_OBJECT(widget), "activate",
5946 G_CALLBACK(compose_set_privacy_system_cb), compose);
5948 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5949 gtk_widget_show(widget);
5952 g_slist_free(systems);
5955 void compose_reflect_prefs_all(void)
5960 for (cur = compose_list; cur != NULL; cur = cur->next) {
5961 compose = (Compose *)cur->data;
5962 compose_set_template_menu(compose);
5966 void compose_reflect_prefs_pixmap_theme(void)
5971 for (cur = compose_list; cur != NULL; cur = cur->next) {
5972 compose = (Compose *)cur->data;
5973 toolbar_update(TOOLBAR_COMPOSE, compose);
5977 static void compose_template_apply(Compose *compose, Template *tmpl,
5981 GtkTextBuffer *buffer;
5986 gint cursor_pos = 0;
5987 if (!tmpl || !tmpl->value) return;
5989 text = GTK_TEXT_VIEW(compose->text);
5990 buffer = gtk_text_view_get_buffer(text);
5992 if (tmpl->subject && *tmpl->subject != '\0')
5993 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5995 if (tmpl->to && *tmpl->to != '\0')
5996 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5997 if (tmpl->cc && *tmpl->cc != '\0')
5998 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
6000 if (tmpl->bcc && *tmpl->bcc != '\0')
6001 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
6004 gtk_text_buffer_set_text(buffer, "", -1);
6006 mark = gtk_text_buffer_get_insert(buffer);
6007 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6009 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6010 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6013 if (prefs_common.quotemark && *prefs_common.quotemark)
6014 qmark = prefs_common.quotemark;
6018 if (compose->replyinfo != NULL)
6019 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6020 tmpl->value, qmark, NULL);
6021 else if (compose->fwdinfo != NULL)
6022 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6023 tmpl->value, qmark, NULL);
6028 if (replace && parsed_str && compose->account->auto_sig)
6029 compose_insert_sig(compose, FALSE);
6031 if (replace && parsed_str) {
6032 gtk_text_buffer_get_start_iter(buffer, &iter);
6033 gtk_text_buffer_place_cursor(buffer, &iter);
6037 cursor_pos = quote_fmt_get_cursor_pos();
6038 gtk_text_buffer_get_start_iter(buffer, &iter);
6039 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6040 gtk_text_buffer_place_cursor(buffer, &iter);
6041 compose->set_cursor_pos = cursor_pos;
6045 compose_changed_cb(NULL, compose);
6048 static void compose_destroy(Compose *compose)
6050 compose_list = g_list_remove(compose_list, compose);
6052 /* NOTE: address_completion_end() does nothing with the window
6053 * however this may change. */
6054 address_completion_end(compose->window);
6056 slist_free_strings(compose->to_list);
6057 g_slist_free(compose->to_list);
6058 slist_free_strings(compose->newsgroup_list);
6059 g_slist_free(compose->newsgroup_list);
6060 slist_free_strings(compose->header_list);
6061 g_slist_free(compose->header_list);
6063 procmsg_msginfo_free(compose->targetinfo);
6064 procmsg_msginfo_free(compose->replyinfo);
6065 procmsg_msginfo_free(compose->fwdinfo);
6067 g_free(compose->replyto);
6068 g_free(compose->cc);
6069 g_free(compose->bcc);
6070 g_free(compose->newsgroups);
6071 g_free(compose->followup_to);
6073 g_free(compose->ml_post);
6075 g_free(compose->inreplyto);
6076 g_free(compose->references);
6077 g_free(compose->msgid);
6078 g_free(compose->boundary);
6080 if (compose->redirect_filename)
6081 g_free(compose->redirect_filename);
6082 if (compose->undostruct)
6083 undo_destroy(compose->undostruct);
6085 g_free(compose->sig_str);
6087 g_free(compose->exteditor_file);
6089 g_free(compose->orig_charset);
6091 g_free(compose->privacy_system);
6093 if (addressbook_get_target_compose() == compose)
6094 addressbook_set_target_compose(NULL);
6097 if (compose->gtkaspell) {
6098 gtkaspell_delete(compose->gtkaspell);
6099 compose->gtkaspell = NULL;
6103 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6104 prefs_common.compose_height = compose->window->allocation.height;
6106 if (!gtk_widget_get_parent(compose->paned))
6107 gtk_widget_destroy(compose->paned);
6108 gtk_widget_destroy(compose->popupmenu);
6110 gtk_widget_destroy(compose->window);
6111 toolbar_destroy(compose->toolbar);
6112 g_free(compose->toolbar);
6113 g_mutex_free(compose->mutex);
6117 static void compose_attach_info_free(AttachInfo *ainfo)
6119 g_free(ainfo->file);
6120 g_free(ainfo->content_type);
6121 g_free(ainfo->name);
6125 static void compose_attach_remove_selected(Compose *compose)
6127 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6128 GtkTreeSelection *selection;
6130 GtkTreeModel *model;
6132 selection = gtk_tree_view_get_selection(tree_view);
6133 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6138 for (cur = sel; cur != NULL; cur = cur->next) {
6139 GtkTreePath *path = cur->data;
6140 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6143 gtk_tree_path_free(path);
6146 for (cur = sel; cur != NULL; cur = cur->next) {
6147 GtkTreeRowReference *ref = cur->data;
6148 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6151 if (gtk_tree_model_get_iter(model, &iter, path))
6152 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6154 gtk_tree_path_free(path);
6155 gtk_tree_row_reference_free(ref);
6161 static struct _AttachProperty
6164 GtkWidget *mimetype_entry;
6165 GtkWidget *encoding_optmenu;
6166 GtkWidget *path_entry;
6167 GtkWidget *filename_entry;
6169 GtkWidget *cancel_btn;
6172 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6174 gtk_tree_path_free((GtkTreePath *)ptr);
6177 static void compose_attach_property(Compose *compose)
6179 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6181 GtkOptionMenu *optmenu;
6182 GtkTreeSelection *selection;
6184 GtkTreeModel *model;
6187 static gboolean cancelled;
6189 /* only if one selected */
6190 selection = gtk_tree_view_get_selection(tree_view);
6191 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6194 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6198 path = (GtkTreePath *) sel->data;
6199 gtk_tree_model_get_iter(model, &iter, path);
6200 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6203 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6209 if (!attach_prop.window)
6210 compose_attach_property_create(&cancelled);
6211 gtk_widget_grab_focus(attach_prop.ok_btn);
6212 gtk_widget_show(attach_prop.window);
6213 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6215 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6216 if (ainfo->encoding == ENC_UNKNOWN)
6217 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6218 GINT_TO_POINTER(ENC_BASE64));
6220 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6221 GINT_TO_POINTER(ainfo->encoding));
6223 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6224 ainfo->content_type ? ainfo->content_type : "");
6225 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6226 ainfo->file ? ainfo->file : "");
6227 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6228 ainfo->name ? ainfo->name : "");
6231 const gchar *entry_text;
6233 gchar *cnttype = NULL;
6237 GtkWidget *menuitem;
6242 gtk_widget_hide(attach_prop.window);
6247 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6248 if (*entry_text != '\0') {
6251 text = g_strstrip(g_strdup(entry_text));
6252 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6253 cnttype = g_strdup(text);
6256 alertpanel_error(_("Invalid MIME type."));
6262 menu = gtk_option_menu_get_menu(optmenu);
6263 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6264 ainfo->encoding = GPOINTER_TO_INT
6265 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6267 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6268 if (*entry_text != '\0') {
6269 if (is_file_exist(entry_text) &&
6270 (size = get_file_size(entry_text)) > 0)
6271 file = g_strdup(entry_text);
6274 (_("File doesn't exist or is empty."));
6280 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6281 if (*entry_text != '\0') {
6282 g_free(ainfo->name);
6283 ainfo->name = g_strdup(entry_text);
6287 g_free(ainfo->content_type);
6288 ainfo->content_type = cnttype;
6291 g_free(ainfo->file);
6297 /* update tree store */
6298 text = to_human_readable(ainfo->size);
6299 gtk_tree_model_get_iter(model, &iter, path);
6300 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6301 COL_MIMETYPE, ainfo->content_type,
6303 COL_NAME, ainfo->name,
6309 gtk_tree_path_free(path);
6312 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6314 label = gtk_label_new(str); \
6315 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6316 GTK_FILL, 0, 0, 0); \
6317 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6319 entry = gtk_entry_new(); \
6320 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6321 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6324 static void compose_attach_property_create(gboolean *cancelled)
6330 GtkWidget *mimetype_entry;
6333 GtkWidget *optmenu_menu;
6334 GtkWidget *menuitem;
6335 GtkWidget *path_entry;
6336 GtkWidget *filename_entry;
6339 GtkWidget *cancel_btn;
6340 GList *mime_type_list, *strlist;
6342 debug_print("Creating attach_property window...\n");
6344 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6345 gtk_widget_set_size_request(window, 480, -1);
6346 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6347 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6348 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6349 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6350 g_signal_connect(G_OBJECT(window), "delete_event",
6351 G_CALLBACK(attach_property_delete_event),
6353 g_signal_connect(G_OBJECT(window), "key_press_event",
6354 G_CALLBACK(attach_property_key_pressed),
6357 vbox = gtk_vbox_new(FALSE, 8);
6358 gtk_container_add(GTK_CONTAINER(window), vbox);
6360 table = gtk_table_new(4, 2, FALSE);
6361 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6362 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6363 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6365 label = gtk_label_new(_("MIME type"));
6366 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6368 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6369 mimetype_entry = gtk_combo_new();
6370 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6371 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6373 /* stuff with list */
6374 mime_type_list = procmime_get_mime_type_list();
6376 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6377 MimeType *type = (MimeType *) mime_type_list->data;
6378 strlist = g_list_append(strlist,
6379 g_strdup_printf("%s/%s",
6380 type->type, type->sub_type));
6383 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6385 for (mime_type_list = strlist; mime_type_list != NULL;
6386 mime_type_list = mime_type_list->next)
6387 g_free(mime_type_list->data);
6388 g_list_free(strlist);
6390 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6392 label = gtk_label_new(_("Encoding"));
6393 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6395 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6397 hbox = gtk_hbox_new(FALSE, 0);
6398 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6399 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6401 optmenu = gtk_option_menu_new();
6402 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6404 optmenu_menu = gtk_menu_new();
6405 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6406 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6407 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6408 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6409 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6410 ENC_QUOTED_PRINTABLE);
6411 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6413 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6415 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6417 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6418 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6420 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
6421 &cancel_btn, GTK_STOCK_CANCEL,
6423 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6424 gtk_widget_grab_default(ok_btn);
6426 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6427 G_CALLBACK(attach_property_ok),
6429 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6430 G_CALLBACK(attach_property_cancel),
6433 gtk_widget_show_all(vbox);
6435 attach_prop.window = window;
6436 attach_prop.mimetype_entry = mimetype_entry;
6437 attach_prop.encoding_optmenu = optmenu;
6438 attach_prop.path_entry = path_entry;
6439 attach_prop.filename_entry = filename_entry;
6440 attach_prop.ok_btn = ok_btn;
6441 attach_prop.cancel_btn = cancel_btn;
6444 #undef SET_LABEL_AND_ENTRY
6446 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6452 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6458 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6459 gboolean *cancelled)
6467 static gboolean attach_property_key_pressed(GtkWidget *widget,
6469 gboolean *cancelled)
6471 if (event && event->keyval == GDK_Escape) {
6478 static void compose_exec_ext_editor(Compose *compose)
6485 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6486 G_DIR_SEPARATOR, compose);
6488 if (pipe(pipe_fds) < 0) {
6494 if ((pid = fork()) < 0) {
6501 /* close the write side of the pipe */
6504 compose->exteditor_file = g_strdup(tmp);
6505 compose->exteditor_pid = pid;
6507 compose_set_ext_editor_sensitive(compose, FALSE);
6509 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6510 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6514 } else { /* process-monitoring process */
6520 /* close the read side of the pipe */
6523 if (compose_write_body_to_file(compose, tmp) < 0) {
6524 fd_write_all(pipe_fds[1], "2\n", 2);
6528 pid_ed = compose_exec_ext_editor_real(tmp);
6530 fd_write_all(pipe_fds[1], "1\n", 2);
6534 /* wait until editor is terminated */
6535 waitpid(pid_ed, NULL, 0);
6537 fd_write_all(pipe_fds[1], "0\n", 2);
6544 #endif /* G_OS_UNIX */
6548 static gint compose_exec_ext_editor_real(const gchar *file)
6550 static gchar *def_cmd = "emacs %s";
6556 g_return_val_if_fail(file != NULL, -1);
6558 if ((pid = fork()) < 0) {
6563 if (pid != 0) return pid;
6565 /* grandchild process */
6567 if (setpgid(0, getppid()))
6570 if (prefs_common.ext_editor_cmd &&
6571 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6572 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6573 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6575 if (prefs_common.ext_editor_cmd)
6576 g_warning("External editor command line is invalid: '%s'\n",
6577 prefs_common.ext_editor_cmd);
6578 g_snprintf(buf, sizeof(buf), def_cmd, file);
6581 cmdline = strsplit_with_quote(buf, " ", 1024);
6582 execvp(cmdline[0], cmdline);
6585 g_strfreev(cmdline);
6590 static gboolean compose_ext_editor_kill(Compose *compose)
6592 pid_t pgid = compose->exteditor_pid * -1;
6595 ret = kill(pgid, 0);
6597 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6601 msg = g_strdup_printf
6602 (_("The external editor is still working.\n"
6603 "Force terminating the process?\n"
6604 "process group id: %d"), -pgid);
6605 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6606 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6610 if (val == G_ALERTDEFAULT) {
6611 g_source_remove(compose->exteditor_tag);
6612 g_io_channel_shutdown(compose->exteditor_ch,
6614 g_io_channel_unref(compose->exteditor_ch);
6616 if (kill(pgid, SIGTERM) < 0) perror("kill");
6617 waitpid(compose->exteditor_pid, NULL, 0);
6619 g_warning("Terminated process group id: %d", -pgid);
6620 g_warning("Temporary file: %s",
6621 compose->exteditor_file);
6623 compose_set_ext_editor_sensitive(compose, TRUE);
6625 g_free(compose->exteditor_file);
6626 compose->exteditor_file = NULL;
6627 compose->exteditor_pid = -1;
6628 compose->exteditor_ch = NULL;
6629 compose->exteditor_tag = -1;
6637 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6641 Compose *compose = (Compose *)data;
6644 debug_print(_("Compose: input from monitoring process\n"));
6646 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6648 g_io_channel_shutdown(source, FALSE, NULL);
6649 g_io_channel_unref(source);
6651 waitpid(compose->exteditor_pid, NULL, 0);
6653 if (buf[0] == '0') { /* success */
6654 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6655 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6657 gtk_text_buffer_set_text(buffer, "", -1);
6658 compose_insert_file(compose, compose->exteditor_file);
6659 compose_changed_cb(NULL, compose);
6661 if (g_unlink(compose->exteditor_file) < 0)
6662 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6663 } else if (buf[0] == '1') { /* failed */
6664 g_warning("Couldn't exec external editor\n");
6665 if (g_unlink(compose->exteditor_file) < 0)
6666 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6667 } else if (buf[0] == '2') {
6668 g_warning("Couldn't write to file\n");
6669 } else if (buf[0] == '3') {
6670 g_warning("Pipe read failed\n");
6673 compose_set_ext_editor_sensitive(compose, TRUE);
6675 g_free(compose->exteditor_file);
6676 compose->exteditor_file = NULL;
6677 compose->exteditor_pid = -1;
6678 compose->exteditor_ch = NULL;
6679 compose->exteditor_tag = -1;
6684 static void compose_set_ext_editor_sensitive(Compose *compose,
6687 GtkItemFactory *ifactory;
6689 ifactory = gtk_item_factory_from_widget(compose->menubar);
6691 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6692 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6693 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6694 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6695 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6696 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6697 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6700 gtk_widget_set_sensitive(compose->text, sensitive);
6701 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6702 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6703 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6704 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6705 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6706 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6707 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6708 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6710 #endif /* G_OS_UNIX */
6713 * compose_undo_state_changed:
6715 * Change the sensivity of the menuentries undo and redo
6717 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6718 gint redo_state, gpointer data)
6720 GtkWidget *widget = GTK_WIDGET(data);
6721 GtkItemFactory *ifactory;
6723 g_return_if_fail(widget != NULL);
6725 ifactory = gtk_item_factory_from_widget(widget);
6727 switch (undo_state) {
6728 case UNDO_STATE_TRUE:
6729 if (!undostruct->undo_state) {
6730 undostruct->undo_state = TRUE;
6731 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6734 case UNDO_STATE_FALSE:
6735 if (undostruct->undo_state) {
6736 undostruct->undo_state = FALSE;
6737 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6740 case UNDO_STATE_UNCHANGED:
6742 case UNDO_STATE_REFRESH:
6743 menu_set_sensitive(ifactory, "/Edit/Undo",
6744 undostruct->undo_state);
6747 g_warning("Undo state not recognized");
6751 switch (redo_state) {
6752 case UNDO_STATE_TRUE:
6753 if (!undostruct->redo_state) {
6754 undostruct->redo_state = TRUE;
6755 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6758 case UNDO_STATE_FALSE:
6759 if (undostruct->redo_state) {
6760 undostruct->redo_state = FALSE;
6761 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6764 case UNDO_STATE_UNCHANGED:
6766 case UNDO_STATE_REFRESH:
6767 menu_set_sensitive(ifactory, "/Edit/Redo",
6768 undostruct->redo_state);
6771 g_warning("Redo state not recognized");
6776 /* callback functions */
6778 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6779 * includes "non-client" (windows-izm) in calculation, so this calculation
6780 * may not be accurate.
6782 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6783 GtkAllocation *allocation,
6784 GtkSHRuler *shruler)
6786 if (prefs_common.show_ruler) {
6787 gint char_width = 0, char_height = 0;
6788 gint line_width_in_chars;
6790 gtkut_get_font_size(GTK_WIDGET(widget),
6791 &char_width, &char_height);
6792 line_width_in_chars =
6793 (allocation->width - allocation->x) / char_width;
6795 /* got the maximum */
6796 gtk_ruler_set_range(GTK_RULER(shruler),
6797 0.0, line_width_in_chars, 0,
6798 /*line_width_in_chars*/ char_width);
6804 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6806 Compose *compose = (Compose *)data;
6809 gchar *folderidentifier;
6811 ac = account_find_from_id(
6812 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6813 g_return_if_fail(ac != NULL);
6815 if (ac != compose->account)
6816 compose_select_account(compose, ac, FALSE);
6818 /* Set message save folder */
6819 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6820 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6822 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6823 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6825 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6826 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6827 folderidentifier = folder_item_get_identifier(account_get_special_folder
6828 (compose->account, F_OUTBOX));
6829 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6830 g_free(folderidentifier);
6834 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6835 GtkTreeViewColumn *column, Compose *compose)
6837 compose_attach_property(compose);
6840 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6843 Compose *compose = (Compose *)data;
6844 GtkTreeSelection *attach_selection;
6845 gint attach_nr_selected;
6846 GtkItemFactory *ifactory;
6848 if (!event) return FALSE;
6850 if (event->button == 3) {
6851 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6852 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6853 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6855 if (attach_nr_selected > 0)
6857 menu_set_sensitive(ifactory, "/Remove", TRUE);
6858 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6860 menu_set_sensitive(ifactory, "/Remove", FALSE);
6861 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6864 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6865 NULL, NULL, event->button, event->time);
6872 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6875 Compose *compose = (Compose *)data;
6877 if (!event) return FALSE;
6879 switch (event->keyval) {
6881 compose_attach_remove_selected(compose);
6887 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6889 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6890 toolbar_comp_set_sensitive(compose, allow);
6891 menu_set_sensitive(ifactory, "/Message", allow);
6892 menu_set_sensitive(ifactory, "/Edit", allow);
6894 menu_set_sensitive(ifactory, "/Spelling", allow);
6896 menu_set_sensitive(ifactory, "/Options", allow);
6897 menu_set_sensitive(ifactory, "/Tools", allow);
6898 menu_set_sensitive(ifactory, "/Help", allow);
6900 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6904 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6906 Compose *compose = (Compose *)data;
6908 if (prefs_common.work_offline && !inc_offline_should_override())
6911 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6912 gtk_timeout_remove(compose->draft_timeout_tag);
6913 compose->draft_timeout_tag = -1;
6916 compose_send(compose);
6919 static void compose_send_later_cb(gpointer data, guint action,
6922 Compose *compose = (Compose *)data;
6925 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6927 compose_close(compose);
6928 else if (val == -2) {
6929 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6933 void compose_draft (gpointer data)
6935 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6938 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6940 Compose *compose = (Compose *)data;
6944 MsgFlags flag = {0, 0};
6945 static gboolean lock = FALSE;
6946 MsgInfo *newmsginfo;
6951 draft = account_get_special_folder(compose->account, F_DRAFT);
6952 g_return_if_fail(draft != NULL);
6954 if (!g_mutex_trylock(compose->mutex)) {
6955 /* we don't want to lock the mutex once it's available,
6956 * because as the only other part of compose.c locking
6957 * it is compose_close - which means once unlocked,
6958 * the compose struct will be freed */
6959 debug_print("couldn't lock mutex, probably sending\n");
6965 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6966 G_DIR_SEPARATOR, compose);
6967 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6968 FILE_OP_ERROR(tmp, "fopen");
6972 /* chmod for security */
6973 if (change_file_mode_rw(fp, tmp) < 0) {
6974 FILE_OP_ERROR(tmp, "chmod");
6975 g_warning("can't change file mode\n");
6978 /* Save draft infos */
6979 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6980 fprintf(fp, "S:%s\n", compose->account->address);
6981 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6982 gchar *savefolderid;
6984 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6985 fprintf(fp, "SCF:%s\n", savefolderid);
6986 g_free(savefolderid);
6988 if (compose->return_receipt) {
6989 fprintf(fp, "RRCPT:1\n");
6991 if (compose->privacy_system) {
6992 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6993 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6994 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
6998 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7006 folder_item_scan(draft);
7007 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7010 if (action != COMPOSE_AUTO_SAVE)
7011 alertpanel_error(_("Could not save draft."));
7015 draft->mtime = 0; /* force updating */
7017 if (compose->mode == COMPOSE_REEDIT) {
7018 compose_remove_reedit_target(compose);
7021 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7023 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7024 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7025 if (compose_use_attach(compose))
7026 procmsg_msginfo_set_flags(newmsginfo, 0,
7027 MSG_HAS_ATTACHMENT);
7029 procmsg_msginfo_free(newmsginfo);
7032 folder_item_scan(draft);
7034 if (action == COMPOSE_QUIT_EDITING) {
7036 g_mutex_unlock(compose->mutex); /* must be done before closing */
7037 compose_close(compose);
7043 path = folder_item_fetch_msg(draft, msgnum);
7044 g_return_if_fail(path != NULL);
7045 if (g_stat(path, &s) < 0) {
7046 FILE_OP_ERROR(path, "stat");
7052 procmsg_msginfo_free(compose->targetinfo);
7053 compose->targetinfo = procmsg_msginfo_new();
7054 compose->targetinfo->msgnum = msgnum;
7055 compose->targetinfo->size = s.st_size;
7056 compose->targetinfo->mtime = s.st_mtime;
7057 compose->targetinfo->folder = draft;
7058 compose->mode = COMPOSE_REEDIT;
7060 if (action == COMPOSE_AUTO_SAVE) {
7061 compose->autosaved_draft = compose->targetinfo;
7063 compose->modified = FALSE;
7064 compose_set_title(compose);
7068 g_mutex_unlock(compose->mutex);
7071 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7073 Compose *compose = (Compose *)data;
7076 if (compose->redirect_filename != NULL)
7079 file_list = filesel_select_multiple_files_open(_("Select file"));
7084 for ( tmp = file_list; tmp; tmp = tmp->next) {
7085 gchar *file = (gchar *) tmp->data;
7086 gchar *utf8_filename = conv_filename_to_utf8(file);
7087 compose_attach_append(compose, file, utf8_filename, NULL);
7088 compose_changed_cb(NULL, compose);
7090 g_free(utf8_filename);
7092 g_list_free(file_list);
7096 static void compose_insert_file_cb(gpointer data, guint action,
7099 Compose *compose = (Compose *)data;
7102 file_list = filesel_select_multiple_files_open(_("Select file"));
7107 for ( tmp = file_list; tmp; tmp = tmp->next) {
7108 gchar *file = (gchar *) tmp->data;
7109 gchar *filedup = g_strdup(file);
7110 gchar *shortfile = g_path_get_basename(filedup);
7111 ComposeInsertResult res;
7113 res = compose_insert_file(compose, file);
7114 if (res == COMPOSE_INSERT_READ_ERROR) {
7115 alertpanel_error(_("File '%s' could not be read."), shortfile);
7116 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7117 alertpanel_error(_("File '%s' contained invalid characters\n"
7118 "for the current encoding, insertion may be incorrect."), shortfile);
7124 g_list_free(file_list);
7128 static void compose_insert_sig_cb(gpointer data, guint action,
7131 Compose *compose = (Compose *)data;
7133 compose_insert_sig(compose, FALSE);
7136 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7140 Compose *compose = (Compose *)data;
7142 gtkut_widget_get_uposition(widget, &x, &y);
7143 prefs_common.compose_x = x;
7144 prefs_common.compose_y = y;
7146 if (compose->sending)
7148 compose_close_cb(compose, 0, NULL);
7152 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7154 Compose *compose = (Compose *)data;
7158 if (compose->exteditor_tag != -1) {
7159 if (!compose_ext_editor_kill(compose))
7164 if (compose->modified) {
7165 val = alertpanel(_("Discard message"),
7166 _("This message has been modified. Discard it?"),
7167 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7170 case G_ALERTDEFAULT:
7171 if (prefs_common.autosave)
7172 compose_remove_draft(compose);
7174 case G_ALERTALTERNATE:
7175 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7182 compose_close(compose);
7185 static void compose_set_encoding_cb(gpointer data, guint action,
7188 Compose *compose = (Compose *)data;
7190 if (GTK_CHECK_MENU_ITEM(widget)->active)
7191 compose->out_encoding = (CharSet)action;
7194 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7196 Compose *compose = (Compose *)data;
7198 addressbook_open(compose);
7201 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7203 Compose *compose = (Compose *)data;
7208 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7209 g_return_if_fail(tmpl != NULL);
7211 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7213 val = alertpanel(_("Apply template"), msg,
7214 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7217 if (val == G_ALERTDEFAULT)
7218 compose_template_apply(compose, tmpl, TRUE);
7219 else if (val == G_ALERTALTERNATE)
7220 compose_template_apply(compose, tmpl, FALSE);
7223 static void compose_ext_editor_cb(gpointer data, guint action,
7226 Compose *compose = (Compose *)data;
7228 compose_exec_ext_editor(compose);
7231 static void compose_undo_cb(Compose *compose)
7233 gboolean prev_autowrap = compose->autowrap;
7235 compose->autowrap = FALSE;
7236 undo_undo(compose->undostruct);
7237 compose->autowrap = prev_autowrap;
7240 static void compose_redo_cb(Compose *compose)
7242 gboolean prev_autowrap = compose->autowrap;
7244 compose->autowrap = FALSE;
7245 undo_redo(compose->undostruct);
7246 compose->autowrap = prev_autowrap;
7249 static void entry_cut_clipboard(GtkWidget *entry)
7251 if (GTK_IS_EDITABLE(entry))
7252 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7253 else if (GTK_IS_TEXT_VIEW(entry))
7254 gtk_text_buffer_cut_clipboard(
7255 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7256 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7260 static void entry_copy_clipboard(GtkWidget *entry)
7262 if (GTK_IS_EDITABLE(entry))
7263 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7264 else if (GTK_IS_TEXT_VIEW(entry))
7265 gtk_text_buffer_copy_clipboard(
7266 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7267 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7270 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7271 gboolean wrap, GdkAtom clip)
7273 if (GTK_IS_TEXT_VIEW(entry)) {
7274 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7275 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7276 GtkTextIter start_iter, end_iter;
7279 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7281 if (contents == NULL)
7284 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7285 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7287 start = gtk_text_iter_get_offset(&start_iter);
7289 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7292 end = start + strlen(contents);
7293 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7294 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7295 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7296 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7297 mark_start = gtk_text_buffer_get_insert(buffer);
7298 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7299 gtk_text_iter_backward_char(&start_iter);
7300 compose_beautify_paragraph(compose, &start_iter, TRUE);
7303 } else if (GTK_IS_EDITABLE(entry))
7304 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7308 static void entry_allsel(GtkWidget *entry)
7310 if (GTK_IS_EDITABLE(entry))
7311 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7312 else if (GTK_IS_TEXT_VIEW(entry)) {
7313 GtkTextIter startiter, enditer;
7314 GtkTextBuffer *textbuf;
7316 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7317 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7318 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7320 gtk_text_buffer_move_mark_by_name(textbuf,
7321 "selection_bound", &startiter);
7322 gtk_text_buffer_move_mark_by_name(textbuf,
7323 "insert", &enditer);
7327 static void compose_cut_cb(Compose *compose)
7329 if (compose->focused_editable &&
7330 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7331 entry_cut_clipboard(compose->focused_editable);
7334 static void compose_copy_cb(Compose *compose)
7336 if (compose->focused_editable &&
7337 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7338 entry_copy_clipboard(compose->focused_editable);
7341 static void compose_paste_cb(Compose *compose)
7344 GtkTextBuffer *buffer;
7346 if (compose->focused_editable &&
7347 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7348 entry_paste_clipboard(compose, compose->focused_editable,
7349 prefs_common.linewrap_pastes,
7350 GDK_SELECTION_CLIPBOARD);
7354 static void compose_paste_as_quote_cb(Compose *compose)
7356 gint wrap_quote = prefs_common.linewrap_quote;
7357 if (compose->focused_editable &&
7358 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7359 /* let text_insert() (called directly or at a later time
7360 * after the gtk_editable_paste_clipboard) know that
7361 * text is to be inserted as a quotation. implemented
7362 * by using a simple refcount... */
7363 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7364 G_OBJECT(compose->focused_editable),
7365 "paste_as_quotation"));
7366 g_object_set_data(G_OBJECT(compose->focused_editable),
7367 "paste_as_quotation",
7368 GINT_TO_POINTER(paste_as_quotation + 1));
7369 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7370 entry_paste_clipboard(compose, compose->focused_editable,
7371 prefs_common.linewrap_pastes,
7372 GDK_SELECTION_CLIPBOARD);
7373 prefs_common.linewrap_quote = wrap_quote;
7377 static void compose_paste_no_wrap_cb(Compose *compose)
7380 GtkTextBuffer *buffer;
7382 if (compose->focused_editable &&
7383 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7384 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7385 GDK_SELECTION_CLIPBOARD);
7389 static void compose_paste_wrap_cb(Compose *compose)
7392 GtkTextBuffer *buffer;
7394 if (compose->focused_editable &&
7395 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7396 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7397 GDK_SELECTION_CLIPBOARD);
7401 static void compose_allsel_cb(Compose *compose)
7403 if (compose->focused_editable &&
7404 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7405 entry_allsel(compose->focused_editable);
7408 static void textview_move_beginning_of_line (GtkTextView *text)
7410 GtkTextBuffer *buffer;
7414 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7416 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7417 mark = gtk_text_buffer_get_insert(buffer);
7418 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7419 gtk_text_iter_set_line_offset(&ins, 0);
7420 gtk_text_buffer_place_cursor(buffer, &ins);
7423 static void textview_move_forward_character (GtkTextView *text)
7425 GtkTextBuffer *buffer;
7429 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7431 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7432 mark = gtk_text_buffer_get_insert(buffer);
7433 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7434 if (gtk_text_iter_forward_cursor_position(&ins))
7435 gtk_text_buffer_place_cursor(buffer, &ins);
7438 static void textview_move_backward_character (GtkTextView *text)
7440 GtkTextBuffer *buffer;
7444 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7446 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7447 mark = gtk_text_buffer_get_insert(buffer);
7448 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7449 if (gtk_text_iter_backward_cursor_position(&ins))
7450 gtk_text_buffer_place_cursor(buffer, &ins);
7453 static void textview_move_forward_word (GtkTextView *text)
7455 GtkTextBuffer *buffer;
7460 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7462 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7463 mark = gtk_text_buffer_get_insert(buffer);
7464 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7465 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7466 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7467 gtk_text_iter_backward_word_start(&ins);
7468 gtk_text_buffer_place_cursor(buffer, &ins);
7472 static void textview_move_backward_word (GtkTextView *text)
7474 GtkTextBuffer *buffer;
7479 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7481 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7482 mark = gtk_text_buffer_get_insert(buffer);
7483 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7484 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7485 if (gtk_text_iter_backward_word_starts(&ins, 1))
7486 gtk_text_buffer_place_cursor(buffer, &ins);
7489 static void textview_move_end_of_line (GtkTextView *text)
7491 GtkTextBuffer *buffer;
7495 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7497 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7498 mark = gtk_text_buffer_get_insert(buffer);
7499 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7500 if (gtk_text_iter_forward_to_line_end(&ins))
7501 gtk_text_buffer_place_cursor(buffer, &ins);
7504 static void textview_move_next_line (GtkTextView *text)
7506 GtkTextBuffer *buffer;
7511 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7513 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7514 mark = gtk_text_buffer_get_insert(buffer);
7515 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7516 offset = gtk_text_iter_get_line_offset(&ins);
7517 if (gtk_text_iter_forward_line(&ins)) {
7518 gtk_text_iter_set_line_offset(&ins, offset);
7519 gtk_text_buffer_place_cursor(buffer, &ins);
7523 static void textview_move_previous_line (GtkTextView *text)
7525 GtkTextBuffer *buffer;
7530 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7532 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7533 mark = gtk_text_buffer_get_insert(buffer);
7534 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7535 offset = gtk_text_iter_get_line_offset(&ins);
7536 if (gtk_text_iter_backward_line(&ins)) {
7537 gtk_text_iter_set_line_offset(&ins, offset);
7538 gtk_text_buffer_place_cursor(buffer, &ins);
7542 static void textview_delete_forward_character (GtkTextView *text)
7544 GtkTextBuffer *buffer;
7546 GtkTextIter ins, end_iter;
7548 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7550 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7551 mark = gtk_text_buffer_get_insert(buffer);
7552 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7554 if (gtk_text_iter_forward_char(&end_iter)) {
7555 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7559 static void textview_delete_backward_character (GtkTextView *text)
7561 GtkTextBuffer *buffer;
7563 GtkTextIter ins, end_iter;
7565 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7567 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7568 mark = gtk_text_buffer_get_insert(buffer);
7569 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7571 if (gtk_text_iter_backward_char(&end_iter)) {
7572 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7576 static void textview_delete_forward_word (GtkTextView *text)
7578 GtkTextBuffer *buffer;
7580 GtkTextIter ins, end_iter;
7582 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7584 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7585 mark = gtk_text_buffer_get_insert(buffer);
7586 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7588 if (gtk_text_iter_forward_word_end(&end_iter)) {
7589 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7593 static void textview_delete_backward_word (GtkTextView *text)
7595 GtkTextBuffer *buffer;
7597 GtkTextIter ins, end_iter;
7599 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7601 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7602 mark = gtk_text_buffer_get_insert(buffer);
7603 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7605 if (gtk_text_iter_backward_word_start(&end_iter)) {
7606 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7610 static void textview_delete_line (GtkTextView *text)
7612 GtkTextBuffer *buffer;
7614 GtkTextIter ins, start_iter, end_iter;
7617 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7619 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7620 mark = gtk_text_buffer_get_insert(buffer);
7621 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7624 gtk_text_iter_set_line_offset(&start_iter, 0);
7627 if (gtk_text_iter_ends_line(&end_iter))
7628 found = gtk_text_iter_forward_char(&end_iter);
7630 found = gtk_text_iter_forward_to_line_end(&end_iter);
7633 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7636 static void textview_delete_to_line_end (GtkTextView *text)
7638 GtkTextBuffer *buffer;
7640 GtkTextIter ins, end_iter;
7643 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7645 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7646 mark = gtk_text_buffer_get_insert(buffer);
7647 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7649 if (gtk_text_iter_ends_line(&end_iter))
7650 found = gtk_text_iter_forward_char(&end_iter);
7652 found = gtk_text_iter_forward_to_line_end(&end_iter);
7654 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7657 static void compose_advanced_action_cb(Compose *compose,
7658 ComposeCallAdvancedAction action)
7660 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7662 void (*do_action) (GtkTextView *text);
7663 } action_table[] = {
7664 {textview_move_beginning_of_line},
7665 {textview_move_forward_character},
7666 {textview_move_backward_character},
7667 {textview_move_forward_word},
7668 {textview_move_backward_word},
7669 {textview_move_end_of_line},
7670 {textview_move_next_line},
7671 {textview_move_previous_line},
7672 {textview_delete_forward_character},
7673 {textview_delete_backward_character},
7674 {textview_delete_forward_word},
7675 {textview_delete_backward_word},
7676 {textview_delete_line},
7677 {NULL}, /* gtk_stext_delete_line_n */
7678 {textview_delete_to_line_end}
7681 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7683 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7684 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7685 if (action_table[action].do_action)
7686 action_table[action].do_action(text);
7688 g_warning("Not implemented yet.");
7692 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7696 if (GTK_IS_EDITABLE(widget)) {
7697 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7698 gtk_editable_set_position(GTK_EDITABLE(widget),
7701 if (widget->parent && widget->parent->parent
7702 && widget->parent->parent->parent) {
7703 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7704 gint y = widget->allocation.y;
7705 gint height = widget->allocation.height;
7706 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7707 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7709 if (y < (int)shown->value) {
7710 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7712 if (y + height > (int)shown->value + (int)shown->page_size) {
7713 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7714 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7715 y + height - (int)shown->page_size - 1);
7717 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7718 (int)shown->upper - (int)shown->page_size - 1);
7725 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7726 compose->focused_editable = widget;
7729 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7731 compose->modified = TRUE;
7732 compose_set_title(compose);
7735 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7737 Compose *compose = (Compose *)data;
7740 compose_wrap_all_full(compose, TRUE);
7742 compose_beautify_paragraph(compose, NULL, TRUE);
7745 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7748 Compose *compose = (Compose *)data;
7749 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7750 if (compose->autowrap)
7751 compose_wrap_all_full(compose, TRUE);
7754 static void compose_toggle_sign_cb(gpointer data, guint action,
7757 Compose *compose = (Compose *)data;
7759 if (GTK_CHECK_MENU_ITEM(widget)->active)
7760 compose->use_signing = TRUE;
7762 compose->use_signing = FALSE;
7765 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7768 Compose *compose = (Compose *)data;
7770 if (GTK_CHECK_MENU_ITEM(widget)->active)
7771 compose->use_encryption = TRUE;
7773 compose->use_encryption = FALSE;
7776 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7778 g_free(compose->privacy_system);
7780 compose->privacy_system = g_strdup(account->default_privacy_system);
7781 compose_update_privacy_system_menu_item(compose, warn);
7784 static void compose_toggle_ruler_cb(gpointer data, guint action,
7787 Compose *compose = (Compose *)data;
7789 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7790 gtk_widget_show(compose->ruler_hbox);
7791 prefs_common.show_ruler = TRUE;
7793 gtk_widget_hide(compose->ruler_hbox);
7794 gtk_widget_queue_resize(compose->edit_vbox);
7795 prefs_common.show_ruler = FALSE;
7799 static void compose_attach_drag_received_cb (GtkWidget *widget,
7800 GdkDragContext *drag_context,
7803 GtkSelectionData *data,
7808 Compose *compose = (Compose *)user_data;
7811 if (gdk_atom_name(data->type) &&
7812 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7813 list = uri_list_extract_filenames((const gchar *)data->data);
7814 for (tmp = list; tmp != NULL; tmp = tmp->next)
7815 compose_attach_append
7816 (compose, (const gchar *)tmp->data,
7817 (const gchar *)tmp->data, NULL);
7818 if (list) compose_changed_cb(NULL, compose);
7819 list_free_strings(list);
7821 } else if (gdk_atom_name(data->type) &&
7822 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7823 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7824 /* comes from our summaryview */
7825 SummaryView * summaryview = NULL;
7826 GSList * list = NULL, *cur = NULL;
7828 if (mainwindow_get_mainwindow())
7829 summaryview = mainwindow_get_mainwindow()->summaryview;
7832 list = summary_get_selected_msg_list(summaryview);
7834 for (cur = list; cur; cur = cur->next) {
7835 MsgInfo *msginfo = (MsgInfo *)cur->data;
7838 file = procmsg_get_message_file_full(msginfo,
7841 compose_attach_append(compose, (const gchar *)file,
7842 (const gchar *)file, "message/rfc822");
7850 static gboolean compose_drag_drop(GtkWidget *widget,
7851 GdkDragContext *drag_context,
7853 guint time, gpointer user_data)
7855 /* not handling this signal makes compose_insert_drag_received_cb
7860 static void compose_insert_drag_received_cb (GtkWidget *widget,
7861 GdkDragContext *drag_context,
7864 GtkSelectionData *data,
7869 Compose *compose = (Compose *)user_data;
7872 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7874 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7875 list = uri_list_extract_filenames((const gchar *)data->data);
7876 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7877 compose_insert_file(compose, (const gchar *)tmp->data);
7879 list_free_strings(list);
7881 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7884 #if GTK_CHECK_VERSION(2, 8, 0)
7885 /* do nothing, handled by GTK */
7887 gchar *tmpfile = get_tmp_file();
7888 str_write_to_file((const gchar *)data->data, tmpfile);
7889 compose_insert_file(compose, tmpfile);
7892 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7896 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7899 static void compose_header_drag_received_cb (GtkWidget *widget,
7900 GdkDragContext *drag_context,
7903 GtkSelectionData *data,
7908 GtkEditable *entry = (GtkEditable *)user_data;
7909 gchar *email = (gchar *)data->data;
7911 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7914 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7915 gchar *decoded=g_new(gchar, strlen(email));
7918 email += strlen("mailto:");
7919 decode_uri(decoded, email); /* will fit */
7920 gtk_editable_delete_text(entry, 0, -1);
7921 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7922 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7926 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7929 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7932 Compose *compose = (Compose *)data;
7934 if (GTK_CHECK_MENU_ITEM(widget)->active)
7935 compose->return_receipt = TRUE;
7937 compose->return_receipt = FALSE;
7940 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7943 Compose *compose = (Compose *)data;
7945 if (GTK_CHECK_MENU_ITEM(widget)->active)
7946 compose->remove_references = TRUE;
7948 compose->remove_references = FALSE;
7951 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7953 ComposeHeaderEntry *headerentry)
7955 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7956 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7957 !(event->state & GDK_MODIFIER_MASK) &&
7958 (event->keyval == GDK_BackSpace) &&
7959 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7960 gtk_container_remove
7961 (GTK_CONTAINER(headerentry->compose->header_table),
7962 headerentry->combo);
7963 gtk_container_remove
7964 (GTK_CONTAINER(headerentry->compose->header_table),
7965 headerentry->entry);
7966 headerentry->compose->header_list =
7967 g_slist_remove(headerentry->compose->header_list,
7969 g_free(headerentry);
7970 } else if (event->keyval == GDK_Tab) {
7971 if (headerentry->compose->header_last == headerentry) {
7972 /* Override default next focus, and give it to subject_entry
7973 * instead of notebook tabs
7975 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
7976 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7983 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
7984 ComposeHeaderEntry *headerentry)
7986 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7987 headerentry->compose->header_list =
7988 g_slist_append(headerentry->compose->header_list,
7991 compose_create_header_entry(headerentry->compose);
7992 g_signal_handlers_disconnect_matched
7993 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
7994 0, 0, NULL, NULL, headerentry);
7996 /* Automatically scroll down */
7997 compose_show_first_last_header(headerentry->compose, FALSE);
8003 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8005 GtkAdjustment *vadj;
8007 g_return_if_fail(compose);
8008 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8009 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8011 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8012 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8015 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8016 const gchar *text, gint len, Compose *compose)
8018 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8019 (G_OBJECT(compose->text), "paste_as_quotation"));
8022 g_return_if_fail(text != NULL);
8024 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8025 G_CALLBACK(text_inserted),
8027 if (paste_as_quotation) {
8034 new_text = g_strndup(text, len);
8035 if (prefs_common.quotemark && *prefs_common.quotemark)
8036 qmark = prefs_common.quotemark;
8040 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8041 gtk_text_buffer_place_cursor(buffer, iter);
8043 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
8045 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8046 GINT_TO_POINTER(paste_as_quotation - 1));
8048 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8050 gtk_text_buffer_insert(buffer, iter, text, len);
8052 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8054 compose_beautify_paragraph(compose, iter, FALSE);
8056 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8057 gtk_text_buffer_delete_mark(buffer, mark);
8059 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8060 G_CALLBACK(text_inserted),
8062 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8064 if (prefs_common.autosave &&
8065 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8066 compose->draft_timeout_tag = gtk_timeout_add
8067 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8069 static gint compose_defer_auto_save_draft(Compose *compose)
8071 compose->draft_timeout_tag = -1;
8072 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8077 static void compose_check_all(Compose *compose)
8079 if (compose->gtkaspell)
8080 gtkaspell_check_all(compose->gtkaspell);
8083 static void compose_highlight_all(Compose *compose)
8085 if (compose->gtkaspell)
8086 gtkaspell_highlight_all(compose->gtkaspell);
8089 static void compose_check_backwards(Compose *compose)
8091 if (compose->gtkaspell)
8092 gtkaspell_check_backwards(compose->gtkaspell);
8094 GtkItemFactory *ifactory;
8095 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8096 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8097 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8101 static void compose_check_forwards_go(Compose *compose)
8103 if (compose->gtkaspell)
8104 gtkaspell_check_forwards_go(compose->gtkaspell);
8106 GtkItemFactory *ifactory;
8107 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8108 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8109 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8115 *\brief Guess originating forward account from MsgInfo and several
8116 * "common preference" settings. Return NULL if no guess.
8118 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8120 PrefsAccount *account = NULL;
8122 g_return_val_if_fail(msginfo, NULL);
8123 g_return_val_if_fail(msginfo->folder, NULL);
8124 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8126 if (msginfo->folder->prefs->enable_default_account)
8127 account = account_find_from_id(msginfo->folder->prefs->default_account);
8130 account = msginfo->folder->folder->account;
8132 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8134 Xstrdup_a(to, msginfo->to, return NULL);
8135 extract_address(to);
8136 account = account_find_from_address(to);
8139 if (!account && prefs_common.forward_account_autosel) {
8141 if (!procheader_get_header_from_msginfo
8142 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8143 extract_address(cc);
8144 account = account_find_from_address(cc);
8151 static gboolean compose_close(Compose *compose)
8155 if (!g_mutex_trylock(compose->mutex)) {
8156 /* we have to wait for the (possibly deferred by auto-save)
8157 * drafting to be done, before destroying the compose under
8159 debug_print("waiting for drafting to finish...\n");
8160 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8163 g_return_val_if_fail(compose, FALSE);
8164 gtkut_widget_get_uposition(compose->window, &x, &y);
8165 prefs_common.compose_x = x;
8166 prefs_common.compose_y = y;
8167 g_mutex_unlock(compose->mutex);
8168 compose_destroy(compose);
8173 * Add entry field for each address in list.
8174 * \param compose E-Mail composition object.
8175 * \param listAddress List of (formatted) E-Mail addresses.
8177 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8182 addr = ( gchar * ) node->data;
8183 compose_entry_append( compose, addr, COMPOSE_TO );
8184 node = g_list_next( node );
8188 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8192 GSList *new_msglist = NULL;
8193 MsgInfo *tmp_msginfo = NULL;
8194 gboolean originally_enc = FALSE;
8195 Compose *compose = NULL;
8197 g_return_if_fail(msgview != NULL);
8199 g_return_if_fail(msginfo_list != NULL);
8201 if (g_slist_length(msginfo_list) == 1) {
8202 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8203 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8205 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8206 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8207 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8208 orig_msginfo, mimeinfo);
8209 if (tmp_msginfo != NULL) {
8210 new_msglist = g_slist_append(NULL, tmp_msginfo);
8211 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8212 originally_enc = TRUE;
8218 body = messageview_get_selection(msgview);
8221 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8222 procmsg_msginfo_free(tmp_msginfo);
8223 g_slist_free(new_msglist);
8225 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8227 if (originally_enc) {
8228 compose_force_encryption(compose, compose->account, FALSE);