2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
77 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
84 #include "mainwindow.h"
86 #include "addressbook.h"
87 #include "folderview.h"
90 #include "stock_pixmap.h"
91 #include "send_message.h"
94 #include "customheader.h"
95 #include "prefs_common.h"
96 #include "prefs_account.h"
100 #include "procheader.h"
101 #include "procmime.h"
102 #include "statusbar.h"
105 #include "quoted-printable.h"
106 #include "codeconv.h"
108 #include "gtkutils.h"
110 #include "alertpanel.h"
111 #include "manage_window.h"
112 #include "gtkshruler.h"
114 #include "addr_compl.h"
115 #include "quote_fmt.h"
116 #include "template.h"
118 #include "foldersel.h"
131 #define N_ATTACH_COLS (N_COL_COLUMNS)
135 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
136 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
143 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
144 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
150 } ComposeCallAdvancedAction;
154 PRIORITY_HIGHEST = 1,
163 COMPOSE_INSERT_SUCCESS,
164 COMPOSE_INSERT_READ_ERROR,
165 COMPOSE_INSERT_INVALID_CHARACTER,
166 COMPOSE_INSERT_NO_FILE
167 } ComposeInsertResult;
171 COMPOSE_QUIT_EDITING,
172 COMPOSE_KEEP_EDITING,
174 } ComposeDraftAction;
178 COMPOSE_WRITE_FOR_SEND,
179 COMPOSE_WRITE_FOR_STORE
182 #define B64_LINE_SIZE 57
183 #define B64_BUFFSIZE 77
185 #define MAX_REFERENCES_LEN 999
187 static GList *compose_list = NULL;
189 Compose *compose_generic_new (PrefsAccount *account,
192 GPtrArray *attach_files,
193 GList *listAddress );
195 static Compose *compose_create (PrefsAccount *account,
198 static GtkWidget *compose_account_option_menu_create
200 static void compose_set_out_encoding (Compose *compose);
201 static void compose_set_template_menu (Compose *compose);
202 static void compose_template_apply (Compose *compose,
205 static void compose_destroy (Compose *compose);
207 static void compose_entries_set (Compose *compose,
208 const gchar *mailto);
209 static gint compose_parse_header (Compose *compose,
211 static gchar *compose_parse_references (const gchar *ref,
214 static gchar *compose_quote_fmt (Compose *compose,
220 static void compose_reply_set_entry (Compose *compose,
226 followup_and_reply_to);
227 static void compose_reedit_set_entry (Compose *compose,
230 static void compose_insert_sig (Compose *compose,
232 static gchar *compose_get_signature_str (Compose *compose);
233 static ComposeInsertResult compose_insert_file (Compose *compose,
236 static void compose_attach_append (Compose *compose,
239 const gchar *content_type);
240 static void compose_attach_parts (Compose *compose,
243 static void compose_beautify_paragraph (Compose *compose,
244 GtkTextIter *par_iter,
246 static void compose_wrap_all (Compose *compose);
247 static void compose_wrap_all_full (Compose *compose,
250 static void compose_set_title (Compose *compose);
251 static void compose_select_account (Compose *compose,
252 PrefsAccount *account,
255 static PrefsAccount *compose_current_mail_account(void);
256 /* static gint compose_send (Compose *compose); */
257 static gboolean compose_check_for_valid_recipient
259 static gboolean compose_check_entries (Compose *compose,
260 gboolean check_subject);
261 static gint compose_write_to_file (Compose *compose,
264 static gint compose_write_body_to_file (Compose *compose,
266 static gint compose_remove_reedit_target (Compose *compose);
267 void compose_remove_draft (Compose *compose);
268 static gint compose_queue (Compose *compose,
271 static gint compose_queue_sub (Compose *compose,
274 gboolean check_subject);
275 static void compose_add_attachments (Compose *compose,
277 static gchar *compose_get_header (Compose *compose);
279 static void compose_convert_header (Compose *compose,
284 gboolean addr_field);
286 static void compose_attach_info_free (AttachInfo *ainfo);
287 static void compose_attach_remove_selected (Compose *compose);
289 static void compose_attach_property (Compose *compose);
290 static void compose_attach_property_create (gboolean *cancelled);
291 static void attach_property_ok (GtkWidget *widget,
292 gboolean *cancelled);
293 static void attach_property_cancel (GtkWidget *widget,
294 gboolean *cancelled);
295 static gint attach_property_delete_event (GtkWidget *widget,
297 gboolean *cancelled);
298 static gboolean attach_property_key_pressed (GtkWidget *widget,
300 gboolean *cancelled);
302 static void compose_exec_ext_editor (Compose *compose);
304 static gint compose_exec_ext_editor_real (const gchar *file);
305 static gboolean compose_ext_editor_kill (Compose *compose);
306 static gboolean compose_input_cb (GIOChannel *source,
307 GIOCondition condition,
309 static void compose_set_ext_editor_sensitive (Compose *compose,
311 #endif /* G_OS_UNIX */
313 static void compose_undo_state_changed (UndoMain *undostruct,
318 static void compose_create_header_entry (Compose *compose);
319 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
320 static void compose_update_priority_menu_item(Compose * compose);
322 static void compose_add_field_list ( Compose *compose,
323 GList *listAddress );
325 /* callback functions */
327 static gboolean compose_edit_size_alloc (GtkEditable *widget,
328 GtkAllocation *allocation,
329 GtkSHRuler *shruler);
330 static void account_activated (GtkMenuItem *menuitem,
332 static void attach_selected (GtkTreeView *tree_view,
333 GtkTreePath *tree_path,
334 GtkTreeViewColumn *column,
336 static gboolean attach_button_pressed (GtkWidget *widget,
337 GdkEventButton *event,
339 static gboolean attach_key_pressed (GtkWidget *widget,
343 static void compose_send_cb (gpointer data,
346 static void compose_send_later_cb (gpointer data,
350 static void compose_draft_cb (gpointer data,
354 static void compose_attach_cb (gpointer data,
357 static void compose_insert_file_cb (gpointer data,
360 static void compose_insert_sig_cb (gpointer data,
364 static void compose_close_cb (gpointer data,
368 static void compose_set_encoding_cb (gpointer data,
372 static void compose_address_cb (gpointer data,
375 static void compose_template_activate_cb(GtkWidget *widget,
378 static void compose_ext_editor_cb (gpointer data,
382 static gint compose_delete_cb (GtkWidget *widget,
386 static void compose_undo_cb (Compose *compose);
387 static void compose_redo_cb (Compose *compose);
388 static void compose_cut_cb (Compose *compose);
389 static void compose_copy_cb (Compose *compose);
390 static void compose_paste_cb (Compose *compose);
391 static void compose_paste_as_quote_cb (Compose *compose);
392 static void compose_paste_no_wrap_cb (Compose *compose);
393 static void compose_paste_wrap_cb (Compose *compose);
394 static void compose_allsel_cb (Compose *compose);
396 static void compose_advanced_action_cb (Compose *compose,
397 ComposeCallAdvancedAction action);
399 static void compose_grab_focus_cb (GtkWidget *widget,
402 static void compose_changed_cb (GtkTextBuffer *textbuf,
405 static void compose_wrap_cb (gpointer data,
408 static void compose_toggle_autowrap_cb (gpointer data,
412 static void compose_toggle_ruler_cb (gpointer data,
415 static void compose_toggle_sign_cb (gpointer data,
418 static void compose_toggle_encrypt_cb (gpointer data,
421 static void compose_set_privacy_system_cb(GtkWidget *widget,
423 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
424 static void activate_privacy_system (Compose *compose,
425 PrefsAccount *account,
427 static void compose_use_signing(Compose *compose, gboolean use_signing);
428 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
429 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
431 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
433 static void compose_set_priority_cb (gpointer data,
437 static void compose_attach_drag_received_cb (GtkWidget *widget,
438 GdkDragContext *drag_context,
441 GtkSelectionData *data,
445 static void compose_insert_drag_received_cb (GtkWidget *widget,
446 GdkDragContext *drag_context,
449 GtkSelectionData *data,
453 static void compose_header_drag_received_cb (GtkWidget *widget,
454 GdkDragContext *drag_context,
457 GtkSelectionData *data,
462 static gboolean compose_drag_drop (GtkWidget *widget,
463 GdkDragContext *drag_context,
465 guint time, gpointer user_data);
467 static void text_inserted (GtkTextBuffer *buffer,
472 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
473 gboolean to_all, gboolean to_ml,
475 gboolean followup_and_reply_to,
478 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
479 ComposeHeaderEntry *headerentry);
480 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
482 ComposeHeaderEntry *headerentry);
484 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
486 static void compose_allow_user_actions (Compose *compose, gboolean allow);
489 static void compose_check_all (Compose *compose);
490 static void compose_highlight_all (Compose *compose);
491 static void compose_check_backwards (Compose *compose);
492 static void compose_check_forwards_go (Compose *compose);
495 static gint compose_defer_auto_save_draft (Compose *compose);
496 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
498 static gboolean compose_close (Compose *compose);
500 static GtkItemFactoryEntry compose_popup_entries[] =
502 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
503 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
504 {N_("/---"), NULL, NULL, 0, "<Separator>"},
505 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
508 static GtkItemFactoryEntry compose_entries[] =
510 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
511 {N_("/_Message/_Send"), "<control>Return",
512 compose_send_cb, 0, NULL},
513 {N_("/_Message/Send _later"), "<shift><control>S",
514 compose_send_later_cb, 0, NULL},
515 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
516 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
517 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
518 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
519 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Message/_Save"),
521 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
522 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
525 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
526 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
527 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
528 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
530 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
531 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
532 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
533 {N_("/_Edit/Special paste/as _quotation"),
534 NULL, compose_paste_as_quote_cb, 0, NULL},
535 {N_("/_Edit/Special paste/_wrapped"),
536 NULL, compose_paste_wrap_cb, 0, NULL},
537 {N_("/_Edit/Special paste/_unwrapped"),
538 NULL, compose_paste_no_wrap_cb, 0, NULL},
539 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
540 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/A_dvanced/Move a character backward"),
543 compose_advanced_action_cb,
544 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
546 {N_("/_Edit/A_dvanced/Move a character forward"),
548 compose_advanced_action_cb,
549 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
551 {N_("/_Edit/A_dvanced/Move a word backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
556 {N_("/_Edit/A_dvanced/Move a word forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
561 {N_("/_Edit/A_dvanced/Move to beginning of line"),
562 NULL, /* "<control>A" */
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
566 {N_("/_Edit/A_dvanced/Move to end of line"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
571 {N_("/_Edit/A_dvanced/Move to previous line"),
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
576 {N_("/_Edit/A_dvanced/Move to next line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
581 {N_("/_Edit/A_dvanced/Delete a character backward"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
586 {N_("/_Edit/A_dvanced/Delete a character forward"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
591 {N_("/_Edit/A_dvanced/Delete a word backward"),
592 NULL, /* "<control>W" */
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
596 {N_("/_Edit/A_dvanced/Delete a word forward"),
597 NULL, /* "<alt>D", */
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
601 {N_("/_Edit/A_dvanced/Delete line"),
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
606 {N_("/_Edit/A_dvanced/Delete entire line"),
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
611 {N_("/_Edit/A_dvanced/Delete to end of line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
616 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_Edit/_Wrap current paragraph"),
618 "<control>L", compose_wrap_cb, 0, NULL},
619 {N_("/_Edit/Wrap all long _lines"),
620 "<control><alt>L", compose_wrap_cb, 1, NULL},
621 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
622 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_Edit/Edit with e_xternal editor"),
624 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
626 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
627 {N_("/_Spelling/_Check all or check selection"),
628 NULL, compose_check_all, 0, NULL},
629 {N_("/_Spelling/_Highlight all misspelled words"),
630 NULL, compose_highlight_all, 0, NULL},
631 {N_("/_Spelling/Check _backwards misspelled word"),
632 NULL, compose_check_backwards , 0, NULL},
633 {N_("/_Spelling/_Forward to next misspelled word"),
634 NULL, compose_check_forwards_go, 0, NULL},
635 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Spelling/_Spelling Configuration"),
637 NULL, NULL, 0, "<Branch>"},
639 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
642 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
643 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
644 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
648 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
649 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
650 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
651 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
655 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
657 #define ENC_ACTION(action) \
658 NULL, compose_set_encoding_cb, action, \
659 "/Options/Character encoding/Automatic"
661 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
662 {N_("/_Options/Character _encoding/_Automatic"),
663 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
664 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
667 ENC_ACTION(C_US_ASCII)},
668 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
669 ENC_ACTION(C_UTF_8)},
670 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
672 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
673 ENC_ACTION(C_ISO_8859_1)},
674 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
675 ENC_ACTION(C_ISO_8859_15)},
676 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
678 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
679 ENC_ACTION(C_ISO_8859_2)},
680 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
682 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
683 ENC_ACTION(C_ISO_8859_13)},
684 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
685 ENC_ACTION(C_ISO_8859_4)},
686 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
688 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
689 ENC_ACTION(C_ISO_8859_7)},
690 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
692 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
693 ENC_ACTION(C_ISO_8859_8)},
694 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
695 ENC_ACTION(C_WINDOWS_1255)},
696 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
698 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
699 ENC_ACTION(C_ISO_8859_9)},
700 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
702 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
703 ENC_ACTION(C_ISO_8859_5)},
704 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
705 ENC_ACTION(C_KOI8_R)},
706 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
707 ENC_ACTION(C_KOI8_U)},
708 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
709 ENC_ACTION(C_WINDOWS_1251)},
710 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
712 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
713 ENC_ACTION(C_ISO_2022_JP)},
714 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
716 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
717 ENC_ACTION(C_GB2312)},
718 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
720 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
722 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
723 ENC_ACTION(C_EUC_TW)},
724 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
726 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
727 ENC_ACTION(C_EUC_KR)},
728 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
730 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
731 ENC_ACTION(C_TIS_620)},
732 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
733 ENC_ACTION(C_WINDOWS_874)},
735 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
736 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
737 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
738 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
739 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
740 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
741 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
744 static GtkTargetEntry compose_mime_types[] =
746 {"text/uri-list", 0, 0},
747 {"text/plain", 0, 0},
751 static gboolean compose_put_existing_to_front(MsgInfo *info)
753 GList *compose_list = compose_get_compose_list();
757 for (elem = compose_list; elem != NULL && elem->data != NULL;
759 Compose *c = (Compose*)elem->data;
761 if (!c->targetinfo || !c->targetinfo->msgid ||
765 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
766 gtkut_window_popup(c->window);
774 static GdkColor quote_color =
775 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
777 static GdkColor signature_color = {
784 static GdkColor uri_color = {
791 static void compose_create_tags(GtkTextView *text, Compose *compose)
793 GtkTextBuffer *buffer;
794 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
796 buffer = gtk_text_view_get_buffer(text);
798 if (prefs_common.enable_color) {
799 /* grab the quote colors, converting from an int to a GdkColor */
800 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
802 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
804 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
807 signature_color = quote_color = uri_color = black;
810 gtk_text_buffer_create_tag(buffer, "quote",
811 "foreground-gdk", "e_color,
813 gtk_text_buffer_create_tag(buffer, "signature",
814 "foreground-gdk", &signature_color,
816 gtk_text_buffer_create_tag(buffer, "link",
817 "foreground-gdk", &uri_color,
819 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
822 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
823 GPtrArray *attach_files)
825 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
828 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
830 return compose_generic_new(account, NULL, item, NULL, NULL);
833 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
835 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
838 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
839 GPtrArray *attach_files, GList *listAddress )
842 GtkTextView *textview;
843 GtkTextBuffer *textbuf;
845 GtkItemFactory *ifactory;
847 if (item && item->prefs && item->prefs->enable_default_account)
848 account = account_find_from_id(item->prefs->default_account);
850 if (!account) account = cur_account;
851 g_return_val_if_fail(account != NULL, NULL);
853 compose = compose_create(account, COMPOSE_NEW);
854 ifactory = gtk_item_factory_from_widget(compose->menubar);
856 compose->replyinfo = NULL;
857 compose->fwdinfo = NULL;
859 textview = GTK_TEXT_VIEW(compose->text);
860 textbuf = gtk_text_view_get_buffer(textview);
861 compose_create_tags(textview, compose);
863 undo_block(compose->undostruct);
865 if (item && item->prefs && item->prefs->enable_default_dictionary &&
867 gtkaspell_change_dict(compose->gtkaspell,
868 item->prefs->default_dictionary);
871 if (account->auto_sig)
872 compose_insert_sig(compose, FALSE);
873 gtk_text_buffer_get_start_iter(textbuf, &iter);
874 gtk_text_buffer_place_cursor(textbuf, &iter);
876 if (account->protocol != A_NNTP) {
877 if (mailto && *mailto != '\0') {
878 compose_entries_set(compose, mailto);
880 } else if (item && item->prefs->enable_default_to) {
881 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
882 compose_entry_mark_default_to(compose, item->prefs->default_to);
884 if (item && item->ret_rcpt) {
885 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
889 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
891 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
894 * CLAWS: just don't allow return receipt request, even if the user
895 * may want to send an email. simple but foolproof.
897 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
899 compose_add_field_list( compose, listAddress );
905 for (i = 0; i < attach_files->len; i++) {
906 file = g_ptr_array_index(attach_files, i);
907 compose_attach_append(compose, file, file, NULL);
911 compose_show_first_last_header(compose, TRUE);
913 /* Set save folder */
914 if (item && item->prefs && item->prefs->save_copy_to_folder) {
915 gchar *folderidentifier;
917 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
918 folderidentifier = folder_item_get_identifier(item);
919 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
920 g_free(folderidentifier);
923 gtk_widget_grab_focus(compose->header_last->entry);
925 undo_unblock(compose->undostruct);
927 if (prefs_common.auto_exteditor)
928 compose_exec_ext_editor(compose);
930 compose_set_title(compose);
934 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
935 gboolean override_pref)
937 gchar *privacy = NULL;
939 g_return_if_fail(compose != NULL);
940 g_return_if_fail(account != NULL);
942 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
945 if (account->default_privacy_system
946 && strlen(account->default_privacy_system)) {
947 privacy = account->default_privacy_system;
949 GSList *privacy_avail = privacy_get_system_ids();
950 if (privacy_avail && g_slist_length(privacy_avail)) {
951 privacy = (gchar *)(privacy_avail->data);
954 if (privacy != NULL) {
955 compose->privacy_system = g_strdup(privacy);
956 compose_update_privacy_system_menu_item(compose, FALSE);
957 compose_use_encryption(compose, TRUE);
961 static void compose_force_signing(Compose *compose, PrefsAccount *account)
963 gchar *privacy = NULL;
965 if (account->default_privacy_system
966 && strlen(account->default_privacy_system)) {
967 privacy = account->default_privacy_system;
969 GSList *privacy_avail = privacy_get_system_ids();
970 if (privacy_avail && g_slist_length(privacy_avail)) {
971 privacy = (gchar *)(privacy_avail->data);
974 if (privacy != NULL) {
975 compose->privacy_system = g_strdup(privacy);
976 compose_update_privacy_system_menu_item(compose, FALSE);
977 compose_use_signing(compose, TRUE);
981 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
985 Compose *compose = NULL;
986 g_return_val_if_fail(msginfo_list != NULL, NULL);
988 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
989 g_return_val_if_fail(msginfo != NULL, NULL);
991 list_len = g_slist_length(msginfo_list);
995 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
996 FALSE, prefs_common.default_reply_list, FALSE, body);
998 case COMPOSE_REPLY_WITH_QUOTE:
999 compose = compose_reply(msginfo, TRUE,
1000 FALSE, prefs_common.default_reply_list, FALSE, body);
1002 case COMPOSE_REPLY_WITHOUT_QUOTE:
1003 compose = compose_reply(msginfo, FALSE,
1004 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1006 case COMPOSE_REPLY_TO_SENDER:
1007 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1008 FALSE, FALSE, TRUE, body);
1010 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1011 compose = compose_followup_and_reply_to(msginfo,
1012 prefs_common.reply_with_quote,
1013 FALSE, FALSE, body);
1015 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1016 compose = compose_reply(msginfo, TRUE,
1017 FALSE, FALSE, TRUE, body);
1019 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1020 compose = compose_reply(msginfo, FALSE,
1021 FALSE, FALSE, TRUE, NULL);
1023 case COMPOSE_REPLY_TO_ALL:
1024 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1025 TRUE, FALSE, FALSE, body);
1027 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1028 compose = compose_reply(msginfo, TRUE,
1029 TRUE, FALSE, FALSE, body);
1031 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1032 compose = compose_reply(msginfo, FALSE,
1033 TRUE, FALSE, FALSE, NULL);
1035 case COMPOSE_REPLY_TO_LIST:
1036 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1037 FALSE, TRUE, FALSE, body);
1039 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1040 compose = compose_reply(msginfo, TRUE,
1041 FALSE, TRUE, FALSE, body);
1043 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1044 compose = compose_reply(msginfo, FALSE,
1045 FALSE, TRUE, FALSE, NULL);
1047 case COMPOSE_FORWARD:
1048 if (prefs_common.forward_as_attachment) {
1049 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1052 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1056 case COMPOSE_FORWARD_INLINE:
1057 /* check if we reply to more than one Message */
1058 if (list_len == 1) {
1059 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1062 /* more messages FALL THROUGH */
1063 case COMPOSE_FORWARD_AS_ATTACH:
1064 compose = compose_forward_multiple(NULL, msginfo_list);
1066 case COMPOSE_REDIRECT:
1067 compose = compose_redirect(NULL, msginfo);
1070 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1075 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1076 gboolean to_ml, gboolean to_sender,
1079 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1080 to_sender, FALSE, body);
1083 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1088 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1089 to_sender, TRUE, body);
1092 static void compose_extract_original_charset(Compose *compose)
1094 MsgInfo *info = NULL;
1095 if (compose->replyinfo) {
1096 info = compose->replyinfo;
1097 } else if (compose->fwdinfo) {
1098 info = compose->fwdinfo;
1099 } else if (compose->targetinfo) {
1100 info = compose->targetinfo;
1103 MimeInfo *mimeinfo = procmime_scan_message(info);
1104 MimeInfo *partinfo = mimeinfo;
1105 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1106 partinfo = procmime_mimeinfo_next(partinfo);
1108 compose->orig_charset =
1109 g_strdup(procmime_mimeinfo_get_parameter(
1110 partinfo, "charset"));
1112 procmime_mimeinfo_free_all(mimeinfo);
1116 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1117 gboolean to_all, gboolean to_ml,
1119 gboolean followup_and_reply_to,
1122 GtkItemFactory *ifactory;
1124 PrefsAccount *account = NULL;
1125 PrefsAccount *reply_account;
1126 GtkTextView *textview;
1127 GtkTextBuffer *textbuf;
1129 g_return_val_if_fail(msginfo != NULL, NULL);
1130 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1132 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1134 g_return_val_if_fail(account != NULL, NULL);
1136 if (to_sender && account->protocol == A_NNTP &&
1137 !followup_and_reply_to) {
1139 account_find_from_address(account->address);
1141 reply_account = compose_current_mail_account();
1145 reply_account = account;
1147 compose = compose_create(account, COMPOSE_REPLY);
1148 ifactory = gtk_item_factory_from_widget(compose->menubar);
1150 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1151 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1153 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1155 if (!compose->replyinfo)
1156 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1158 compose_extract_original_charset(compose);
1160 if (msginfo->folder && msginfo->folder->ret_rcpt)
1161 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1163 /* Set save folder */
1164 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1165 gchar *folderidentifier;
1167 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1168 folderidentifier = folder_item_get_identifier(msginfo->folder);
1169 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1170 g_free(folderidentifier);
1173 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1174 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1175 to_sender, followup_and_reply_to);
1176 compose_show_first_last_header(compose, TRUE);
1178 textview = (GTK_TEXT_VIEW(compose->text));
1179 textbuf = gtk_text_view_get_buffer(textview);
1180 compose_create_tags(textview, compose);
1182 undo_block(compose->undostruct);
1184 if (msginfo->folder && msginfo->folder->prefs &&
1185 msginfo->folder->prefs &&
1186 msginfo->folder->prefs->enable_default_dictionary &&
1188 gtkaspell_change_dict(compose->gtkaspell,
1189 msginfo->folder->prefs->default_dictionary);
1195 if (prefs_common.quotemark && *prefs_common.quotemark)
1196 qmark = prefs_common.quotemark;
1200 compose_quote_fmt(compose, compose->replyinfo,
1201 prefs_common.quotefmt,
1204 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1205 compose_force_encryption(compose, account, FALSE);
1208 if (account->auto_sig)
1209 compose_insert_sig(compose, FALSE);
1211 compose_wrap_all(compose);
1213 gtk_widget_grab_focus(compose->text);
1215 undo_unblock(compose->undostruct);
1217 if (prefs_common.auto_exteditor)
1218 compose_exec_ext_editor(compose);
1220 compose_set_title(compose);
1224 #define INSERT_FW_HEADER(var, hdr) \
1225 if (msginfo->var && *msginfo->var) { \
1226 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1227 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1228 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1231 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1232 gboolean as_attach, const gchar *body,
1233 gboolean no_extedit)
1236 GtkTextView *textview;
1237 GtkTextBuffer *textbuf;
1240 g_return_val_if_fail(msginfo != NULL, NULL);
1241 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1244 !(account = compose_guess_forward_account_from_msginfo
1246 account = cur_account;
1248 compose = compose_create(account, COMPOSE_FORWARD);
1250 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1251 if (!compose->fwdinfo)
1252 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1254 compose_extract_original_charset(compose);
1256 if (msginfo->subject && *msginfo->subject) {
1257 gchar *buf, *buf2, *p;
1259 buf = p = g_strdup(msginfo->subject);
1260 p += subject_get_prefix_length(p);
1261 memmove(buf, p, strlen(p) + 1);
1263 buf2 = g_strdup_printf("Fw: %s", buf);
1264 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1270 textview = GTK_TEXT_VIEW(compose->text);
1271 textbuf = gtk_text_view_get_buffer(textview);
1272 compose_create_tags(textview, compose);
1277 msgfile = procmsg_get_message_file_path(msginfo);
1278 if (!is_file_exist(msgfile))
1279 g_warning("%s: file not exist\n", msgfile);
1281 compose_attach_append(compose, msgfile, msgfile,
1287 MsgInfo *full_msginfo;
1289 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1291 full_msginfo = procmsg_msginfo_copy(msginfo);
1293 if (prefs_common.fw_quotemark &&
1294 *prefs_common.fw_quotemark)
1295 qmark = prefs_common.fw_quotemark;
1299 compose_quote_fmt(compose, full_msginfo,
1300 prefs_common.fw_quotefmt,
1302 compose_attach_parts(compose, msginfo);
1304 procmsg_msginfo_free(full_msginfo);
1307 if (account->auto_sig)
1308 compose_insert_sig(compose, FALSE);
1310 compose_wrap_all(compose);
1312 gtk_text_buffer_get_start_iter(textbuf, &iter);
1313 gtk_text_buffer_place_cursor(textbuf, &iter);
1315 gtk_widget_grab_focus(compose->header_last->entry);
1317 if (!no_extedit && prefs_common.auto_exteditor)
1318 compose_exec_ext_editor(compose);
1321 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1322 gchar *folderidentifier;
1324 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1325 folderidentifier = folder_item_get_identifier(msginfo->folder);
1326 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1327 g_free(folderidentifier);
1330 compose_set_title(compose);
1334 #undef INSERT_FW_HEADER
1336 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1339 GtkTextView *textview;
1340 GtkTextBuffer *textbuf;
1344 gboolean single_mail = TRUE;
1346 g_return_val_if_fail(msginfo_list != NULL, NULL);
1348 if (g_slist_length(msginfo_list) > 1)
1349 single_mail = FALSE;
1351 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1352 if (((MsgInfo *)msginfo->data)->folder == NULL)
1355 /* guess account from first selected message */
1357 !(account = compose_guess_forward_account_from_msginfo
1358 (msginfo_list->data)))
1359 account = cur_account;
1361 g_return_val_if_fail(account != NULL, NULL);
1363 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1364 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1365 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1368 compose = compose_create(account, COMPOSE_FORWARD);
1370 textview = GTK_TEXT_VIEW(compose->text);
1371 textbuf = gtk_text_view_get_buffer(textview);
1372 compose_create_tags(textview, compose);
1374 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1375 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1376 if (!is_file_exist(msgfile))
1377 g_warning("%s: file not exist\n", msgfile);
1379 compose_attach_append(compose, msgfile, msgfile,
1385 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1386 if (info->subject && *info->subject) {
1387 gchar *buf, *buf2, *p;
1389 buf = p = g_strdup(info->subject);
1390 p += subject_get_prefix_length(p);
1391 memmove(buf, p, strlen(p) + 1);
1393 buf2 = g_strdup_printf("Fw: %s", buf);
1394 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1400 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1401 _("Fw: multiple emails"));
1404 if (account->auto_sig)
1405 compose_insert_sig(compose, FALSE);
1407 compose_wrap_all(compose);
1409 gtk_text_buffer_get_start_iter(textbuf, &iter);
1410 gtk_text_buffer_place_cursor(textbuf, &iter);
1412 gtk_widget_grab_focus(compose->header_last->entry);
1414 compose_set_title(compose);
1418 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1420 GtkTextIter start = *iter;
1421 GtkTextIter end_iter;
1422 int start_pos = gtk_text_iter_get_offset(&start);
1424 if (!compose->account->sig_sep)
1427 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1428 start_pos+strlen(compose->account->sig_sep));
1430 /* check sig separator */
1431 str = gtk_text_iter_get_text(&start, &end_iter);
1432 if (!strcmp(str, compose->account->sig_sep)) {
1434 /* check end of line (\n) */
1435 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1436 start_pos+strlen(compose->account->sig_sep));
1437 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1438 start_pos+strlen(compose->account->sig_sep)+1);
1439 tmp = gtk_text_iter_get_text(&start, &end_iter);
1440 if (!strcmp(tmp,"\n")) {
1452 static void compose_colorize_signature(Compose *compose)
1454 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1456 GtkTextIter end_iter;
1457 gtk_text_buffer_get_start_iter(buffer, &iter);
1458 while (gtk_text_iter_forward_line(&iter))
1459 if (compose_is_sig_separator(compose, buffer, &iter)) {
1460 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1461 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1465 void compose_reedit(MsgInfo *msginfo)
1467 Compose *compose = NULL;
1468 PrefsAccount *account = NULL;
1469 GtkTextView *textview;
1470 GtkTextBuffer *textbuf;
1474 gchar buf[BUFFSIZE];
1475 gboolean use_signing = FALSE;
1476 gboolean use_encryption = FALSE;
1477 gchar *privacy_system = NULL;
1479 g_return_if_fail(msginfo != NULL);
1480 g_return_if_fail(msginfo->folder != NULL);
1482 if (compose_put_existing_to_front(msginfo))
1485 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1486 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1487 gchar queueheader_buf[BUFFSIZE];
1490 /* Select Account from queue headers */
1491 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1492 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1493 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1494 account = account_find_from_id(id);
1496 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1497 sizeof(queueheader_buf), "NAID:")) {
1498 id = atoi(&queueheader_buf[strlen("NAID:")]);
1499 account = account_find_from_id(id);
1501 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1502 sizeof(queueheader_buf), "MAID:")) {
1503 id = atoi(&queueheader_buf[strlen("MAID:")]);
1504 account = account_find_from_id(id);
1506 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1507 sizeof(queueheader_buf), "S:")) {
1508 account = account_find_from_address(queueheader_buf);
1510 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1511 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1512 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1513 use_signing = param;
1516 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1517 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1518 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1519 use_encryption = param;
1521 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1522 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1523 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1525 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1526 sizeof(queueheader_buf), "X-Priority: ")) {
1527 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1528 compose->priority = param;
1531 account = msginfo->folder->folder->account;
1533 if (!account && prefs_common.reedit_account_autosel) {
1534 gchar from[BUFFSIZE];
1535 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1536 extract_address(from);
1537 account = account_find_from_address(from);
1540 if (!account) account = cur_account;
1541 g_return_if_fail(account != NULL);
1543 compose = compose_create(account, COMPOSE_REEDIT);
1544 if (privacy_system != NULL) {
1545 compose->privacy_system = privacy_system;
1546 compose_use_signing(compose, use_signing);
1547 compose_use_encryption(compose, use_encryption);
1548 compose_update_privacy_system_menu_item(compose, FALSE);
1550 activate_privacy_system(compose, account, FALSE);
1552 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1554 compose_extract_original_charset(compose);
1556 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1557 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1558 gchar queueheader_buf[BUFFSIZE];
1560 /* Set message save folder */
1561 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1564 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1565 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1566 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1570 if (compose_parse_header(compose, msginfo) < 0) return;
1571 compose_reedit_set_entry(compose, msginfo);
1573 textview = GTK_TEXT_VIEW(compose->text);
1574 textbuf = gtk_text_view_get_buffer(textview);
1575 compose_create_tags(textview, compose);
1577 mark = gtk_text_buffer_get_insert(textbuf);
1578 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1580 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1581 G_CALLBACK(compose_changed_cb),
1584 if (procmime_msginfo_is_encrypted(msginfo)) {
1585 fp = procmime_get_first_encrypted_text_content(msginfo);
1587 compose_force_encryption(compose, account, TRUE);
1589 fp = procmime_get_first_text_content(msginfo);
1591 g_warning("Can't get text part\n");
1594 gboolean prev_autowrap = compose->autowrap;
1596 compose->autowrap = FALSE;
1597 while (fgets(buf, sizeof(buf), fp) != NULL) {
1599 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1601 compose_wrap_all_full(compose, FALSE);
1602 compose->autowrap = prev_autowrap;
1606 compose_attach_parts(compose, msginfo);
1608 compose_colorize_signature(compose);
1610 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1611 G_CALLBACK(compose_changed_cb),
1614 gtk_widget_grab_focus(compose->text);
1616 if (prefs_common.auto_exteditor)
1617 compose_exec_ext_editor(compose);
1618 compose_set_title(compose);
1621 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1625 GtkItemFactory *ifactory;
1628 g_return_val_if_fail(msginfo != NULL, NULL);
1631 account = account_get_reply_account(msginfo,
1632 prefs_common.reply_account_autosel);
1633 g_return_val_if_fail(account != NULL, NULL);
1635 compose = compose_create(account, COMPOSE_REDIRECT);
1636 ifactory = gtk_item_factory_from_widget(compose->menubar);
1637 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1638 compose->replyinfo = NULL;
1639 compose->fwdinfo = NULL;
1641 compose_show_first_last_header(compose, TRUE);
1643 gtk_widget_grab_focus(compose->header_last->entry);
1645 filename = procmsg_get_message_file_path(msginfo);
1646 if (filename == NULL)
1649 compose->redirect_filename = filename;
1651 /* Set save folder */
1652 item = msginfo->folder;
1653 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1654 gchar *folderidentifier;
1656 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1657 folderidentifier = folder_item_get_identifier(item);
1658 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1659 g_free(folderidentifier);
1662 compose_attach_parts(compose, msginfo);
1664 if (msginfo->subject)
1665 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1667 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1669 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1670 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1672 compose_colorize_signature(compose);
1674 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1675 menu_set_sensitive(ifactory, "/Add...", FALSE);
1676 menu_set_sensitive(ifactory, "/Remove", FALSE);
1677 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1679 ifactory = gtk_item_factory_from_widget(compose->menubar);
1680 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1681 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1682 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1683 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1684 menu_set_sensitive(ifactory, "/Edit", FALSE);
1685 menu_set_sensitive(ifactory, "/Options", FALSE);
1686 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1687 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1689 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1690 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1691 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1692 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1693 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1694 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1695 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1697 compose_set_title(compose);
1701 GList *compose_get_compose_list(void)
1703 return compose_list;
1706 void compose_entry_append(Compose *compose, const gchar *address,
1707 ComposeEntryType type)
1711 gboolean in_quote = FALSE;
1712 if (!address || *address == '\0') return;
1719 header = N_("Bcc:");
1721 case COMPOSE_REPLYTO:
1722 header = N_("Reply-To:");
1724 case COMPOSE_NEWSGROUPS:
1725 header = N_("Newsgroups:");
1727 case COMPOSE_FOLLOWUPTO:
1728 header = N_( "Followup-To:");
1735 header = prefs_common.trans_hdr ? gettext(header) : header;
1737 cur = begin = (gchar *)address;
1739 /* we separate the line by commas, but not if we're inside a quoted
1741 while (*cur != '\0') {
1743 in_quote = !in_quote;
1744 if (*cur == ',' && !in_quote) {
1745 gchar *tmp = g_strdup(begin);
1747 tmp[cur-begin]='\0';
1752 compose_add_header_entry(compose, header, tmp);
1759 gchar *tmp = g_strdup(begin);
1761 tmp[cur-begin]='\0';
1766 compose_add_header_entry(compose, header, tmp);
1771 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1773 static GtkStyle *bold_style = NULL;
1774 static GdkColor bold_color;
1778 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1779 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1780 if (gtk_entry_get_text(entry) &&
1781 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1782 gtk_widget_ensure_style(GTK_WIDGET(entry));
1784 gtkut_convert_int_to_gdk_color
1785 (prefs_common.color_new, &bold_color);
1786 bold_style = gtk_style_copy(gtk_widget_get_style
1787 (GTK_WIDGET(entry)));
1788 pango_font_description_set_weight
1789 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
1790 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1792 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1797 void compose_toolbar_cb(gint action, gpointer data)
1799 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1800 Compose *compose = (Compose*)toolbar_item->parent;
1802 g_return_if_fail(compose != NULL);
1806 compose_send_cb(compose, 0, NULL);
1809 compose_send_later_cb(compose, 0, NULL);
1812 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1815 compose_insert_file_cb(compose, 0, NULL);
1818 compose_attach_cb(compose, 0, NULL);
1821 compose_insert_sig(compose, FALSE);
1824 compose_ext_editor_cb(compose, 0, NULL);
1826 case A_LINEWRAP_CURRENT:
1827 compose_beautify_paragraph(compose, NULL, TRUE);
1829 case A_LINEWRAP_ALL:
1830 compose_wrap_all_full(compose, TRUE);
1833 compose_address_cb(compose, 0, NULL);
1836 case A_CHECK_SPELLING:
1837 compose_check_all(compose);
1845 static void compose_entries_set(Compose *compose, const gchar *mailto)
1849 gchar *subject = NULL;
1854 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1857 compose_entry_append(compose, to, COMPOSE_TO);
1859 compose_entry_append(compose, cc, COMPOSE_CC);
1861 if (!g_utf8_validate (subject, -1, NULL)) {
1862 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1863 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1866 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1870 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1871 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1874 gboolean prev_autowrap = compose->autowrap;
1876 compose->autowrap = FALSE;
1878 mark = gtk_text_buffer_get_insert(buffer);
1879 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1881 if (!g_utf8_validate (body, -1, NULL)) {
1882 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1883 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1886 gtk_text_buffer_insert(buffer, &iter, body, -1);
1888 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1890 compose->autowrap = prev_autowrap;
1891 if (compose->autowrap)
1892 compose_wrap_all(compose);
1901 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1903 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1904 {"Cc:", NULL, TRUE},
1905 {"References:", NULL, FALSE},
1906 {"Bcc:", NULL, TRUE},
1907 {"Newsgroups:", NULL, TRUE},
1908 {"Followup-To:", NULL, TRUE},
1909 {"List-Post:", NULL, FALSE},
1910 {"X-Priority:", NULL, FALSE},
1911 {NULL, NULL, FALSE}};
1927 g_return_val_if_fail(msginfo != NULL, -1);
1929 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1930 procheader_get_header_fields(fp, hentry);
1933 if (hentry[H_REPLY_TO].body != NULL) {
1934 if (hentry[H_REPLY_TO].body[0] != '\0') {
1936 conv_unmime_header(hentry[H_REPLY_TO].body,
1939 g_free(hentry[H_REPLY_TO].body);
1940 hentry[H_REPLY_TO].body = NULL;
1942 if (hentry[H_CC].body != NULL) {
1943 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1944 g_free(hentry[H_CC].body);
1945 hentry[H_CC].body = NULL;
1947 if (hentry[H_REFERENCES].body != NULL) {
1948 if (compose->mode == COMPOSE_REEDIT)
1949 compose->references = hentry[H_REFERENCES].body;
1951 compose->references = compose_parse_references
1952 (hentry[H_REFERENCES].body, msginfo->msgid);
1953 g_free(hentry[H_REFERENCES].body);
1955 hentry[H_REFERENCES].body = NULL;
1957 if (hentry[H_BCC].body != NULL) {
1958 if (compose->mode == COMPOSE_REEDIT)
1960 conv_unmime_header(hentry[H_BCC].body, NULL);
1961 g_free(hentry[H_BCC].body);
1962 hentry[H_BCC].body = NULL;
1964 if (hentry[H_NEWSGROUPS].body != NULL) {
1965 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1966 hentry[H_NEWSGROUPS].body = NULL;
1968 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1969 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1970 compose->followup_to =
1971 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1974 g_free(hentry[H_FOLLOWUP_TO].body);
1975 hentry[H_FOLLOWUP_TO].body = NULL;
1977 if (hentry[H_LIST_POST].body != NULL) {
1980 extract_address(hentry[H_LIST_POST].body);
1981 if (hentry[H_LIST_POST].body[0] != '\0') {
1982 scan_mailto_url(hentry[H_LIST_POST].body,
1983 &to, NULL, NULL, NULL, NULL);
1985 g_free(compose->ml_post);
1986 compose->ml_post = to;
1989 g_free(hentry[H_LIST_POST].body);
1990 hentry[H_LIST_POST].body = NULL;
1993 /* CLAWS - X-Priority */
1994 if (compose->mode == COMPOSE_REEDIT)
1995 if (hentry[H_X_PRIORITY].body != NULL) {
1998 priority = atoi(hentry[H_X_PRIORITY].body);
1999 g_free(hentry[H_X_PRIORITY].body);
2001 hentry[H_X_PRIORITY].body = NULL;
2003 if (priority < PRIORITY_HIGHEST ||
2004 priority > PRIORITY_LOWEST)
2005 priority = PRIORITY_NORMAL;
2007 compose->priority = priority;
2010 if (compose->mode == COMPOSE_REEDIT) {
2011 if (msginfo->inreplyto && *msginfo->inreplyto)
2012 compose->inreplyto = g_strdup(msginfo->inreplyto);
2016 if (msginfo->msgid && *msginfo->msgid)
2017 compose->inreplyto = g_strdup(msginfo->msgid);
2019 if (!compose->references) {
2020 if (msginfo->msgid && *msginfo->msgid) {
2021 if (msginfo->inreplyto && *msginfo->inreplyto)
2022 compose->references =
2023 g_strdup_printf("<%s>\n\t<%s>",
2027 compose->references =
2028 g_strconcat("<", msginfo->msgid, ">",
2030 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2031 compose->references =
2032 g_strconcat("<", msginfo->inreplyto, ">",
2040 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2042 GSList *ref_id_list, *cur;
2046 ref_id_list = references_list_append(NULL, ref);
2047 if (!ref_id_list) return NULL;
2048 if (msgid && *msgid)
2049 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2054 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2055 /* "<" + Message-ID + ">" + CR+LF+TAB */
2056 len += strlen((gchar *)cur->data) + 5;
2058 if (len > MAX_REFERENCES_LEN) {
2059 /* remove second message-ID */
2060 if (ref_id_list && ref_id_list->next &&
2061 ref_id_list->next->next) {
2062 g_free(ref_id_list->next->data);
2063 ref_id_list = g_slist_remove
2064 (ref_id_list, ref_id_list->next->data);
2066 slist_free_strings(ref_id_list);
2067 g_slist_free(ref_id_list);
2074 new_ref = g_string_new("");
2075 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2076 if (new_ref->len > 0)
2077 g_string_append(new_ref, "\n\t");
2078 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2081 slist_free_strings(ref_id_list);
2082 g_slist_free(ref_id_list);
2084 new_ref_str = new_ref->str;
2085 g_string_free(new_ref, FALSE);
2090 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2091 const gchar *fmt, const gchar *qmark,
2094 static MsgInfo dummyinfo;
2095 gchar *quote_str = NULL;
2099 gboolean prev_autowrap;
2100 const gchar *trimmed_body = body;
2101 gint cursor_pos = 0;
2102 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2103 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2107 msginfo = &dummyinfo;
2109 if (qmark != NULL) {
2110 quote_fmt_init(msginfo, NULL, NULL);
2111 quote_fmt_scan_string(qmark);
2114 buf = quote_fmt_get_buffer();
2116 alertpanel_error(_("Quote mark format error."));
2118 Xstrdup_a(quote_str, buf, return NULL)
2121 if (fmt && *fmt != '\0') {
2122 while (trimmed_body && strlen(trimmed_body) > 1
2123 && trimmed_body[0]=='\n')
2126 quote_fmt_init(msginfo, quote_str, trimmed_body);
2127 quote_fmt_scan_string(fmt);
2130 buf = quote_fmt_get_buffer();
2132 alertpanel_error(_("Message reply/forward format error."));
2138 prev_autowrap = compose->autowrap;
2139 compose->autowrap = FALSE;
2141 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2142 G_CALLBACK(compose_changed_cb),
2144 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2145 G_CALLBACK(text_inserted),
2147 for (p = buf; *p != '\0'; ) {
2150 mark = gtk_text_buffer_get_insert(buffer);
2151 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2153 lastp = strchr(p, '\n');
2154 len = lastp ? lastp - p + 1 : -1;
2156 if (g_utf8_validate(p, -1, NULL)) {
2157 gtk_text_buffer_insert(buffer, &iter, p, len);
2159 gchar *tmpin = g_strdup(p);
2160 gchar *tmpout = NULL;
2162 tmpout = conv_codeset_strdup
2163 (tmpin, conv_get_locale_charset_str(),
2165 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2176 cursor_pos = quote_fmt_get_cursor_pos();
2177 gtk_text_buffer_get_start_iter(buffer, &iter);
2178 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2179 gtk_text_buffer_place_cursor(buffer, &iter);
2182 compose->autowrap = prev_autowrap;
2183 if (compose->autowrap)
2184 compose_wrap_all(compose);
2186 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2187 G_CALLBACK(compose_changed_cb),
2189 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2190 G_CALLBACK(text_inserted),
2197 /* if ml_post is of type addr@host and from is of type
2198 * addr-anything@host, return TRUE
2200 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2202 gchar *left_ml = NULL;
2203 gchar *right_ml = NULL;
2204 gchar *left_from = NULL;
2205 gchar *right_from = NULL;
2206 gboolean result = FALSE;
2208 if (!ml_post || !from)
2211 left_ml = g_strdup(ml_post);
2212 if (strstr(left_ml, "@")) {
2213 right_ml = strstr(left_ml, "@")+1;
2214 *(strstr(left_ml, "@")) = '\0';
2217 left_from = g_strdup(from);
2218 if (strstr(left_from, "@")) {
2219 right_from = strstr(left_from, "@")+1;
2220 *(strstr(left_from, "@")) = '\0';
2223 if (left_ml && left_from && right_ml && right_from
2224 && !strncmp(left_from, left_ml, strlen(left_ml))
2225 && !strcmp(right_from, right_ml)) {
2234 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2236 gchar *my_addr1, *my_addr2;
2238 if (!addr1 || !addr2)
2241 Xstrdup_a(my_addr1, addr1, return FALSE);
2242 Xstrdup_a(my_addr2, addr2, return FALSE);
2244 extract_address(my_addr1);
2245 extract_address(my_addr2);
2247 return !strcmp(my_addr1, my_addr2);
2250 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2251 gboolean to_all, gboolean to_ml,
2253 gboolean followup_and_reply_to)
2255 GSList *cc_list = NULL;
2258 gchar *replyto = NULL;
2259 GHashTable *to_table;
2261 gboolean reply_to_ml = FALSE;
2262 gboolean default_reply_to = FALSE;
2264 g_return_if_fail(compose->account != NULL);
2265 g_return_if_fail(msginfo != NULL);
2267 reply_to_ml = to_ml && compose->ml_post;
2269 default_reply_to = msginfo->folder &&
2270 msginfo->folder->prefs->enable_default_reply_to;
2272 if (compose->account->protocol != A_NNTP) {
2273 if (reply_to_ml && !default_reply_to) {
2275 gboolean is_subscr = is_subscription(compose->ml_post,
2278 /* normal answer to ml post with a reply-to */
2279 compose_entry_append(compose,
2282 if (compose->replyto
2283 && !same_address(compose->ml_post, compose->replyto))
2284 compose_entry_append(compose,
2288 /* answer to subscription confirmation */
2289 if (compose->replyto)
2290 compose_entry_append(compose,
2293 else if (msginfo->from)
2294 compose_entry_append(compose,
2299 else if (!(to_all || to_sender) && default_reply_to) {
2300 compose_entry_append(compose,
2301 msginfo->folder->prefs->default_reply_to,
2303 compose_entry_mark_default_to(compose,
2304 msginfo->folder->prefs->default_reply_to);
2307 Xstrdup_a(tmp1, msginfo->from, return);
2308 extract_address(tmp1);
2309 if (to_all || to_sender ||
2310 !account_find_from_address(tmp1))
2311 compose_entry_append(compose,
2312 (compose->replyto && !to_sender)
2313 ? compose->replyto :
2314 msginfo->from ? msginfo->from : "",
2316 else if (!to_all && !to_sender) {
2317 /* reply to the last list of recipients */
2318 compose_entry_append(compose,
2319 msginfo->to ? msginfo->to : "",
2321 compose_entry_append(compose,
2322 msginfo->cc ? msginfo->cc : "",
2327 if (to_sender || (compose->followup_to &&
2328 !strncmp(compose->followup_to, "poster", 6)))
2329 compose_entry_append
2331 (compose->replyto ? compose->replyto :
2332 msginfo->from ? msginfo->from : ""),
2335 else if (followup_and_reply_to || to_all) {
2336 compose_entry_append
2338 (compose->replyto ? compose->replyto :
2339 msginfo->from ? msginfo->from : ""),
2342 compose_entry_append
2344 compose->followup_to ? compose->followup_to :
2345 compose->newsgroups ? compose->newsgroups : "",
2346 COMPOSE_NEWSGROUPS);
2349 compose_entry_append
2351 compose->followup_to ? compose->followup_to :
2352 compose->newsgroups ? compose->newsgroups : "",
2353 COMPOSE_NEWSGROUPS);
2356 if (msginfo->subject && *msginfo->subject) {
2360 buf = p = g_strdup(msginfo->subject);
2361 p += subject_get_prefix_length(p);
2362 memmove(buf, p, strlen(p) + 1);
2364 buf2 = g_strdup_printf("Re: %s", buf);
2365 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2370 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2372 if (to_ml && compose->ml_post) return;
2373 if (!to_all || compose->account->protocol == A_NNTP) return;
2375 if (compose->replyto) {
2376 Xstrdup_a(replyto, compose->replyto, return);
2377 extract_address(replyto);
2379 if (msginfo->from) {
2380 Xstrdup_a(from, msginfo->from, return);
2381 extract_address(from);
2384 if (replyto && from)
2385 cc_list = address_list_append_with_comments(cc_list, from);
2386 if (to_all && msginfo->folder &&
2387 msginfo->folder->prefs->enable_default_reply_to)
2388 cc_list = address_list_append_with_comments(cc_list,
2389 msginfo->folder->prefs->default_reply_to);
2390 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2391 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2393 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2395 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2396 if (compose->account)
2397 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2398 GINT_TO_POINTER(1));
2400 /* remove address on To: and that of current account */
2401 for (cur = cc_list; cur != NULL; ) {
2402 GSList *next = cur->next;
2405 addr = g_strdup(cur->data);
2406 extract_address(addr);
2408 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2409 cc_list = g_slist_remove(cc_list, cur->data);
2411 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2415 hash_free_strings(to_table);
2416 g_hash_table_destroy(to_table);
2419 for (cur = cc_list; cur != NULL; cur = cur->next)
2420 compose_entry_append(compose, (gchar *)cur->data,
2422 slist_free_strings(cc_list);
2423 g_slist_free(cc_list);
2428 #define SET_ENTRY(entry, str) \
2431 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2434 #define SET_ADDRESS(type, str) \
2437 compose_entry_append(compose, str, type); \
2440 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2442 g_return_if_fail(msginfo != NULL);
2444 SET_ENTRY(subject_entry, msginfo->subject);
2445 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2446 SET_ADDRESS(COMPOSE_CC, compose->cc);
2447 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2448 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2449 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2450 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2452 compose_update_priority_menu_item(compose);
2453 compose_update_privacy_system_menu_item(compose, FALSE);
2454 compose_show_first_last_header(compose, TRUE);
2460 static void compose_insert_sig(Compose *compose, gboolean replace)
2462 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2463 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2465 GtkTextIter iter, iter_end;
2467 gboolean prev_autowrap;
2470 g_return_if_fail(compose->account != NULL);
2472 prev_autowrap = compose->autowrap;
2473 compose->autowrap = FALSE;
2475 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2476 G_CALLBACK(compose_changed_cb),
2479 mark = gtk_text_buffer_get_insert(buffer);
2480 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2481 cur_pos = gtk_text_iter_get_offset (&iter);
2483 gtk_text_buffer_get_end_iter(buffer, &iter);
2485 if (replace && compose->sig_str) {
2487 GtkTextIter first_iter, start_iter, end_iter;
2489 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2491 if (compose->sig_str[0] == '\0')
2494 found = gtk_text_iter_forward_search(&first_iter,
2496 GTK_TEXT_SEARCH_TEXT_ONLY,
2497 &start_iter, &end_iter,
2501 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2506 g_free(compose->sig_str);
2507 compose->sig_str = compose_get_signature_str(compose);
2508 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2509 compose->sig_str = g_strdup("");
2511 cur_pos = gtk_text_iter_get_offset(&iter);
2512 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2514 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2515 gtk_text_iter_forward_char(&iter);
2516 gtk_text_iter_forward_char(&iter);
2517 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2518 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2520 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2521 cur_pos = gtk_text_buffer_get_char_count (buffer);
2523 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2524 gtk_text_buffer_place_cursor(buffer, &iter);
2526 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2527 G_CALLBACK(compose_changed_cb),
2530 compose->autowrap = prev_autowrap;
2531 if (compose->autowrap)
2532 compose_wrap_all(compose);
2535 static gchar *compose_get_signature_str(Compose *compose)
2537 gchar *sig_body = NULL;
2538 gchar *sig_str = NULL;
2539 gchar *utf8_sig_str = NULL;
2541 g_return_val_if_fail(compose->account != NULL, NULL);
2543 if (!compose->account->sig_path)
2546 if (compose->account->sig_type == SIG_FILE) {
2547 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2548 g_warning("can't open signature file: %s\n",
2549 compose->account->sig_path);
2554 if (compose->account->sig_type == SIG_COMMAND)
2555 sig_body = get_command_output(compose->account->sig_path);
2559 tmp = file_read_to_str(compose->account->sig_path);
2562 sig_body = normalize_newlines(tmp);
2566 if (compose->account->sig_sep) {
2567 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2571 sig_str = g_strconcat("\n\n", sig_body, NULL);
2574 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2575 utf8_sig_str = sig_str;
2577 utf8_sig_str = conv_codeset_strdup
2578 (sig_str, conv_get_locale_charset_str(),
2584 return utf8_sig_str;
2587 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2590 GtkTextBuffer *buffer;
2593 const gchar *cur_encoding;
2594 gchar buf[BUFFSIZE];
2597 gboolean prev_autowrap;
2598 gboolean badtxt = FALSE;
2600 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2602 if ((fp = g_fopen(file, "rb")) == NULL) {
2603 FILE_OP_ERROR(file, "fopen");
2604 return COMPOSE_INSERT_READ_ERROR;
2607 prev_autowrap = compose->autowrap;
2608 compose->autowrap = FALSE;
2610 text = GTK_TEXT_VIEW(compose->text);
2611 buffer = gtk_text_view_get_buffer(text);
2612 mark = gtk_text_buffer_get_insert(buffer);
2613 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2615 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2616 G_CALLBACK(text_inserted),
2619 cur_encoding = conv_get_locale_charset_str();
2621 while (fgets(buf, sizeof(buf), fp) != NULL) {
2624 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2625 str = g_strdup(buf);
2627 str = conv_codeset_strdup
2628 (buf, cur_encoding, CS_INTERNAL);
2631 /* strip <CR> if DOS/Windows file,
2632 replace <CR> with <LF> if Macintosh file. */
2635 if (len > 0 && str[len - 1] != '\n') {
2637 if (str[len] == '\r') str[len] = '\n';
2640 gtk_text_buffer_insert(buffer, &iter, str, -1);
2644 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2645 G_CALLBACK(text_inserted),
2647 compose->autowrap = prev_autowrap;
2648 if (compose->autowrap)
2649 compose_wrap_all(compose);
2654 return COMPOSE_INSERT_INVALID_CHARACTER;
2656 return COMPOSE_INSERT_SUCCESS;
2659 static void compose_attach_append(Compose *compose, const gchar *file,
2660 const gchar *filename,
2661 const gchar *content_type)
2669 GtkListStore *store;
2672 if (!is_file_exist(file)) {
2673 g_warning("File %s doesn't exist\n", filename);
2676 if ((size = get_file_size(file)) < 0) {
2677 g_warning("Can't get file size of %s\n", filename);
2681 alertpanel_notice(_("File %s is empty."), filename);
2684 if ((fp = g_fopen(file, "rb")) == NULL) {
2685 alertpanel_error(_("Can't read %s."), filename);
2690 ainfo = g_new0(AttachInfo, 1);
2691 auto_ainfo = g_auto_pointer_new_with_free
2692 (ainfo, (GFreeFunc) compose_attach_info_free);
2693 ainfo->file = g_strdup(file);
2696 ainfo->content_type = g_strdup(content_type);
2697 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2699 MsgFlags flags = {0, 0};
2701 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2702 ainfo->encoding = ENC_7BIT;
2704 ainfo->encoding = ENC_8BIT;
2706 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2707 if (msginfo && msginfo->subject)
2708 name = g_strdup(msginfo->subject);
2710 name = g_path_get_basename(filename ? filename : file);
2712 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2714 procmsg_msginfo_free(msginfo);
2716 if (!g_ascii_strncasecmp(content_type, "text", 4))
2717 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2719 ainfo->encoding = ENC_BASE64;
2720 name = g_path_get_basename(filename ? filename : file);
2721 ainfo->name = g_strdup(name);
2725 ainfo->content_type = procmime_get_mime_type(file);
2726 if (!ainfo->content_type) {
2727 ainfo->content_type =
2728 g_strdup("application/octet-stream");
2729 ainfo->encoding = ENC_BASE64;
2730 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2732 procmime_get_encoding_for_text_file(file);
2734 ainfo->encoding = ENC_BASE64;
2735 name = g_path_get_basename(filename ? filename : file);
2736 ainfo->name = g_strdup(name);
2740 if (!strcmp(ainfo->content_type, "unknown")) {
2741 g_free(ainfo->content_type);
2742 ainfo->content_type = g_strdup("application/octet-stream");
2746 size_text = to_human_readable(size);
2748 store = GTK_LIST_STORE(gtk_tree_view_get_model
2749 (GTK_TREE_VIEW(compose->attach_clist)));
2751 gtk_list_store_append(store, &iter);
2752 gtk_list_store_set(store, &iter,
2753 COL_MIMETYPE, ainfo->content_type,
2754 COL_SIZE, size_text,
2755 COL_NAME, ainfo->name,
2757 COL_AUTODATA, auto_ainfo,
2760 g_auto_pointer_free(auto_ainfo);
2763 static void compose_use_signing(Compose *compose, gboolean use_signing)
2765 GtkItemFactory *ifactory;
2766 GtkWidget *menuitem = NULL;
2768 compose->use_signing = use_signing;
2769 ifactory = gtk_item_factory_from_widget(compose->menubar);
2770 menuitem = gtk_item_factory_get_item
2771 (ifactory, "/Options/Sign");
2772 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2776 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2778 GtkItemFactory *ifactory;
2779 GtkWidget *menuitem = NULL;
2781 compose->use_encryption = use_encryption;
2782 ifactory = gtk_item_factory_from_widget(compose->menubar);
2783 menuitem = gtk_item_factory_get_item
2784 (ifactory, "/Options/Encrypt");
2786 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2790 #define NEXT_PART_NOT_CHILD(info) \
2792 node = info->node; \
2793 while (node->children) \
2794 node = g_node_last_child(node); \
2795 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2798 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2802 MimeInfo *firsttext = NULL;
2803 MimeInfo *encrypted = NULL;
2806 const gchar *partname = NULL;
2808 mimeinfo = procmime_scan_message(msginfo);
2809 if (!mimeinfo) return;
2811 if (mimeinfo->node->children == NULL) {
2812 procmime_mimeinfo_free_all(mimeinfo);
2816 /* find first content part */
2817 child = (MimeInfo *) mimeinfo->node->children->data;
2818 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2819 child = (MimeInfo *)child->node->children->data;
2821 if (child->type == MIMETYPE_TEXT) {
2823 debug_print("First text part found\n");
2824 } else if (compose->mode == COMPOSE_REEDIT &&
2825 child->type == MIMETYPE_APPLICATION &&
2826 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2827 encrypted = (MimeInfo *)child->node->parent->data;
2830 child = (MimeInfo *) mimeinfo->node->children->data;
2831 while (child != NULL) {
2832 if (child == encrypted) {
2833 /* skip this part of tree */
2834 NEXT_PART_NOT_CHILD(child);
2838 if (child->type == MIMETYPE_MULTIPART) {
2839 /* get the actual content */
2840 child = procmime_mimeinfo_next(child);
2844 if (child == firsttext) {
2845 child = procmime_mimeinfo_next(child);
2849 outfile = procmime_get_tmp_file_name(child);
2850 if (procmime_get_part(outfile, child) < 0)
2851 g_warning("Can't get the part of multipart message.");
2853 gchar *content_type;
2855 content_type = procmime_get_content_type_str(child->type, child->subtype);
2857 /* if we meet a pgp signature, we don't attach it, but
2858 * we force signing. */
2859 if (strcmp(content_type, "application/pgp-signature")) {
2860 partname = procmime_mimeinfo_get_parameter(child, "filename");
2861 if (partname == NULL)
2862 partname = procmime_mimeinfo_get_parameter(child, "name");
2863 if (partname == NULL)
2865 compose_attach_append(compose, outfile,
2866 partname, content_type);
2868 compose_force_signing(compose, compose->account);
2870 g_free(content_type);
2873 NEXT_PART_NOT_CHILD(child);
2875 procmime_mimeinfo_free_all(mimeinfo);
2878 #undef NEXT_PART_NOT_CHILD
2883 WAIT_FOR_INDENT_CHAR,
2884 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2887 /* return indent length, we allow:
2888 indent characters followed by indent characters or spaces/tabs,
2889 alphabets and numbers immediately followed by indent characters,
2890 and the repeating sequences of the above
2891 If quote ends with multiple spaces, only the first one is included. */
2892 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2893 const GtkTextIter *start, gint *len)
2895 GtkTextIter iter = *start;
2899 IndentState state = WAIT_FOR_INDENT_CHAR;
2902 gint alnum_count = 0;
2903 gint space_count = 0;
2906 if (prefs_common.quote_chars == NULL) {
2910 while (!gtk_text_iter_ends_line(&iter)) {
2911 wc = gtk_text_iter_get_char(&iter);
2912 if (g_unichar_iswide(wc))
2914 clen = g_unichar_to_utf8(wc, ch);
2918 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2919 is_space = g_unichar_isspace(wc);
2921 if (state == WAIT_FOR_INDENT_CHAR) {
2922 if (!is_indent && !g_unichar_isalnum(wc))
2925 quote_len += alnum_count + space_count + 1;
2926 alnum_count = space_count = 0;
2927 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2930 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2931 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2935 else if (is_indent) {
2936 quote_len += alnum_count + space_count + 1;
2937 alnum_count = space_count = 0;
2940 state = WAIT_FOR_INDENT_CHAR;
2944 gtk_text_iter_forward_char(&iter);
2947 if (quote_len > 0 && space_count > 0)
2953 if (quote_len > 0) {
2955 gtk_text_iter_forward_chars(&iter, quote_len);
2956 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2962 /* return TRUE if the line is itemized */
2963 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2964 const GtkTextIter *start)
2966 GtkTextIter iter = *start;
2971 if (gtk_text_iter_ends_line(&iter))
2975 wc = gtk_text_iter_get_char(&iter);
2976 if (!g_unichar_isspace(wc))
2978 gtk_text_iter_forward_char(&iter);
2979 if (gtk_text_iter_ends_line(&iter))
2983 clen = g_unichar_to_utf8(wc, ch);
2987 if (!strchr("*-+", ch[0]))
2990 gtk_text_iter_forward_char(&iter);
2991 if (gtk_text_iter_ends_line(&iter))
2993 wc = gtk_text_iter_get_char(&iter);
2994 if (g_unichar_isspace(wc))
3000 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3001 const GtkTextIter *start,
3002 GtkTextIter *break_pos,
3006 GtkTextIter iter = *start, line_end = *start;
3007 PangoLogAttr *attrs;
3014 gboolean can_break = FALSE;
3015 gboolean do_break = FALSE;
3016 gboolean was_white = FALSE;
3017 gboolean prev_dont_break = FALSE;
3019 gtk_text_iter_forward_to_line_end(&line_end);
3020 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3021 len = g_utf8_strlen(str, -1);
3022 /* g_print("breaking line: %d: %s (len = %d)\n",
3023 gtk_text_iter_get_line(&iter), str, len); */
3024 attrs = g_new(PangoLogAttr, len + 1);
3026 pango_default_break(str, -1, NULL, attrs, len + 1);
3030 /* skip quote and leading spaces */
3031 for (i = 0; *p != '\0' && i < len; i++) {
3034 wc = g_utf8_get_char(p);
3035 if (i >= quote_len && !g_unichar_isspace(wc))
3037 if (g_unichar_iswide(wc))
3039 else if (*p == '\t')
3043 p = g_utf8_next_char(p);
3046 for (; *p != '\0' && i < len; i++) {
3047 PangoLogAttr *attr = attrs + i;
3051 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3054 was_white = attr->is_white;
3056 /* don't wrap URI */
3057 if ((uri_len = get_uri_len(p)) > 0) {
3059 if (pos > 0 && col > max_col) {
3069 wc = g_utf8_get_char(p);
3070 if (g_unichar_iswide(wc)) {
3072 if (prev_dont_break && can_break && attr->is_line_break)
3074 } else if (*p == '\t')
3078 if (pos > 0 && col > max_col) {
3083 if (*p == '-' || *p == '/')
3084 prev_dont_break = TRUE;
3086 prev_dont_break = FALSE;
3088 p = g_utf8_next_char(p);
3092 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3097 *break_pos = *start;
3098 gtk_text_iter_set_line_offset(break_pos, pos);
3103 static gboolean compose_join_next_line(Compose *compose,
3104 GtkTextBuffer *buffer,
3106 const gchar *quote_str)
3108 GtkTextIter iter_ = *iter, cur, prev, next, end;
3109 PangoLogAttr attrs[3];
3111 gchar *next_quote_str;
3114 gboolean keep_cursor = FALSE;
3116 if (!gtk_text_iter_forward_line(&iter_) ||
3117 gtk_text_iter_ends_line(&iter_))
3120 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3122 if ((quote_str || next_quote_str) &&
3123 strcmp2(quote_str, next_quote_str) != 0) {
3124 g_free(next_quote_str);
3127 g_free(next_quote_str);
3130 if (quote_len > 0) {
3131 gtk_text_iter_forward_chars(&end, quote_len);
3132 if (gtk_text_iter_ends_line(&end))
3136 /* don't join itemized lines */
3137 if (compose_is_itemized(buffer, &end))
3140 /* don't join signature separator */
3141 if (compose_is_sig_separator(compose, buffer, &iter_))
3144 /* delete quote str */
3146 gtk_text_buffer_delete(buffer, &iter_, &end);
3148 /* delete linebreak and extra spaces */
3150 while (gtk_text_iter_backward_char(&cur)) {
3151 wc1 = gtk_text_iter_get_char(&cur);
3152 if (!g_unichar_isspace(wc1))
3157 while (!gtk_text_iter_ends_line(&cur)) {
3158 wc1 = gtk_text_iter_get_char(&cur);
3159 if (!g_unichar_isspace(wc1))
3161 gtk_text_iter_forward_char(&cur);
3164 if (!gtk_text_iter_equal(&prev, &next)) {
3167 mark = gtk_text_buffer_get_insert(buffer);
3168 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3169 if (gtk_text_iter_equal(&prev, &cur))
3171 gtk_text_buffer_delete(buffer, &prev, &next);
3175 /* insert space if required */
3176 gtk_text_iter_backward_char(&prev);
3177 wc1 = gtk_text_iter_get_char(&prev);
3178 wc2 = gtk_text_iter_get_char(&next);
3179 gtk_text_iter_forward_char(&next);
3180 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3181 pango_default_break(str, -1, NULL, attrs, 3);
3182 if (!attrs[1].is_line_break ||
3183 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3184 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3186 gtk_text_iter_backward_char(&iter_);
3187 gtk_text_buffer_place_cursor(buffer, &iter_);
3196 #define ADD_TXT_POS(bp_, ep_, pti_) \
3197 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3198 last = last->next; \
3199 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3200 last->next = NULL; \
3202 g_warning("alloc error scanning URIs\n"); \
3205 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3207 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3208 GtkTextBuffer *buffer;
3209 GtkTextIter iter, break_pos, end_of_line;
3210 gchar *quote_str = NULL;
3212 gboolean wrap_quote = prefs_common.linewrap_quote;
3213 gboolean prev_autowrap = compose->autowrap;
3214 gint startq_offset = -1, noq_offset = -1;
3215 gint uri_start = -1, uri_stop = -1;
3216 gint nouri_start = -1, nouri_stop = -1;
3218 compose->autowrap = FALSE;
3220 buffer = gtk_text_view_get_buffer(text);
3222 undo_block(compose->undostruct);
3228 mark = gtk_text_buffer_get_insert(buffer);
3229 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3232 /* move to paragraph start */
3233 gtk_text_iter_set_line_offset(&iter, 0);
3234 if (gtk_text_iter_ends_line(&iter)) {
3235 while (gtk_text_iter_ends_line(&iter) &&
3236 gtk_text_iter_forward_line(&iter))
3239 while (gtk_text_iter_backward_line(&iter)) {
3240 if (gtk_text_iter_ends_line(&iter)) {
3241 gtk_text_iter_forward_line(&iter);
3247 /* go until paragraph end (empty line) */
3248 while (!gtk_text_iter_ends_line(&iter)) {
3249 gchar *scanpos = NULL;
3250 /* parse table - in order of priority */
3252 const gchar *needle; /* token */
3254 /* token search function */
3255 gchar *(*search) (const gchar *haystack,
3256 const gchar *needle);
3257 /* part parsing function */
3258 gboolean (*parse) (const gchar *start,
3259 const gchar *scanpos,
3263 /* part to URI function */
3264 gchar *(*build_uri) (const gchar *bp,
3268 static struct table parser[] = {
3269 {"http://", strcasestr, get_uri_part, make_uri_string},
3270 {"https://", strcasestr, get_uri_part, make_uri_string},
3271 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3272 {"www.", strcasestr, get_uri_part, make_http_string},
3273 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3274 {"@", strcasestr, get_email_part, make_email_string}
3276 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3277 gint last_index = PARSE_ELEMS;
3279 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3282 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3285 uri_start = uri_stop = -1;
3286 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3290 if (startq_offset == -1) {
3291 startq_offset = gtk_text_iter_get_offset(&iter);
3295 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3296 if (startq_offset == -1)
3297 startq_offset = gtk_text_iter_get_offset(&iter);
3299 if (startq_offset == -1)
3300 noq_offset = gtk_text_iter_get_offset(&iter);
3303 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3306 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3307 prefs_common.linewrap_len,
3309 GtkTextIter prev, next, cur;
3311 if (prev_autowrap != FALSE || force)
3312 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3313 else if (quote_str && wrap_quote)
3314 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3317 /* remove trailing spaces */
3319 gtk_text_iter_backward_char(&cur);
3321 while (!gtk_text_iter_starts_line(&cur)) {
3324 gtk_text_iter_backward_char(&cur);
3325 wc = gtk_text_iter_get_char(&cur);
3326 if (!g_unichar_isspace(wc))
3330 if (!gtk_text_iter_equal(&prev, &next)) {
3331 gtk_text_buffer_delete(buffer, &prev, &next);
3333 gtk_text_iter_forward_char(&break_pos);
3337 gtk_text_buffer_insert(buffer, &break_pos,
3341 compose_join_next_line(compose, buffer, &iter, quote_str);
3343 /* move iter to current line start */
3344 gtk_text_iter_set_line_offset(&iter, 0);
3347 /* move iter to next line start */
3353 while (!gtk_text_iter_ends_line(&end_of_line)) {
3354 gtk_text_iter_forward_char(&end_of_line);
3356 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3358 nouri_start = gtk_text_iter_get_offset(&iter);
3359 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3361 walk_pos = gtk_text_iter_get_offset(&iter);
3362 /* FIXME: this looks phony. scanning for anything in the parse table */
3363 for (n = 0; n < PARSE_ELEMS; n++) {
3366 tmp = parser[n].search(walk, parser[n].needle);
3368 if (scanpos == NULL || tmp < scanpos) {
3377 /* check if URI can be parsed */
3378 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3379 (const gchar **)&ep, FALSE)
3380 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3384 strlen(parser[last_index].needle);
3387 uri_start = walk_pos + (bp - o_walk);
3388 uri_stop = walk_pos + (ep - o_walk);
3392 gtk_text_iter_forward_line(&iter);
3395 if (startq_offset != -1) {
3396 GtkTextIter startquote, endquote;
3397 gtk_text_buffer_get_iter_at_offset(
3398 buffer, &startquote, startq_offset);
3400 gtk_text_buffer_apply_tag_by_name(
3401 buffer, "quote", &startquote, &endquote);
3403 } else if (noq_offset != -1) {
3404 GtkTextIter startnoquote, endnoquote;
3405 gtk_text_buffer_get_iter_at_offset(
3406 buffer, &startnoquote, noq_offset);
3408 gtk_text_buffer_remove_tag_by_name(
3409 buffer, "quote", &startnoquote, &endnoquote);
3414 GtkTextIter nouri_start_iter, nouri_end_iter;
3415 gtk_text_buffer_get_iter_at_offset(
3416 buffer, &nouri_start_iter, nouri_start);
3417 gtk_text_buffer_get_iter_at_offset(
3418 buffer, &nouri_end_iter, nouri_stop);
3419 gtk_text_buffer_remove_tag_by_name(
3420 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3422 if (uri_start > 0 && uri_stop > 0) {
3423 GtkTextIter uri_start_iter, uri_end_iter;
3424 gtk_text_buffer_get_iter_at_offset(
3425 buffer, &uri_start_iter, uri_start);
3426 gtk_text_buffer_get_iter_at_offset(
3427 buffer, &uri_end_iter, uri_stop);
3428 gtk_text_buffer_apply_tag_by_name(
3429 buffer, "link", &uri_start_iter, &uri_end_iter);
3436 undo_unblock(compose->undostruct);
3437 compose->autowrap = prev_autowrap;
3440 static void compose_wrap_all(Compose *compose)
3442 compose_wrap_all_full(compose, FALSE);
3445 static void compose_wrap_all_full(Compose *compose, gboolean force)
3447 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3448 GtkTextBuffer *buffer;
3451 buffer = gtk_text_view_get_buffer(text);
3453 undo_block(compose->undostruct);
3455 gtk_text_buffer_get_start_iter(buffer, &iter);
3456 while (!gtk_text_iter_is_end(&iter))
3457 compose_beautify_paragraph(compose, &iter, force);
3459 undo_unblock(compose->undostruct);
3462 static void compose_set_title(Compose *compose)
3468 edited = compose->modified ? _(" [Edited]") : "";
3470 subject = gtk_editable_get_chars(
3471 GTK_EDITABLE(compose->subject_entry), 0, -1);
3473 if (subject && strlen(subject))
3474 str = g_strdup_printf(_("%s - Compose message%s"),
3477 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3478 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3484 * compose_current_mail_account:
3486 * Find a current mail account (the currently selected account, or the
3487 * default account, if a news account is currently selected). If a
3488 * mail account cannot be found, display an error message.
3490 * Return value: Mail account, or NULL if not found.
3492 static PrefsAccount *
3493 compose_current_mail_account(void)
3497 if (cur_account && cur_account->protocol != A_NNTP)
3500 ac = account_get_default();
3501 if (!ac || ac->protocol == A_NNTP) {
3502 alertpanel_error(_("Account for sending mail is not specified.\n"
3503 "Please select a mail account before sending."));
3510 static void compose_select_account(Compose *compose, PrefsAccount *account,
3513 GtkItemFactory *ifactory;
3515 g_return_if_fail(account != NULL);
3517 compose->account = account;
3519 compose_set_title(compose);
3521 ifactory = gtk_item_factory_from_widget(compose->menubar);
3523 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3524 menu_set_active(ifactory, "/Options/Sign", TRUE);
3526 menu_set_active(ifactory, "/Options/Sign", FALSE);
3527 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3528 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3530 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3532 activate_privacy_system(compose, account, FALSE);
3534 if (!init && compose->mode != COMPOSE_REDIRECT)
3535 compose_insert_sig(compose, TRUE);
3538 gboolean compose_check_for_valid_recipient(Compose *compose) {
3539 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3540 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3541 gboolean recipient_found = FALSE;
3545 /* free to and newsgroup list */
3546 slist_free_strings(compose->to_list);
3547 g_slist_free(compose->to_list);
3548 compose->to_list = NULL;
3550 slist_free_strings(compose->newsgroup_list);
3551 g_slist_free(compose->newsgroup_list);
3552 compose->newsgroup_list = NULL;
3554 /* search header entries for to and newsgroup entries */
3555 for (list = compose->header_list; list; list = list->next) {
3558 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3559 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3561 if (entry[0] != '\0') {
3562 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3563 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3564 compose->to_list = address_list_append(compose->to_list, entry);
3565 recipient_found = TRUE;
3568 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3569 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3570 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3571 recipient_found = TRUE;
3578 return recipient_found;
3581 static gboolean compose_check_for_set_recipients(Compose *compose)
3583 if (compose->account->set_autocc && compose->account->auto_cc) {
3584 gboolean found_other = FALSE;
3586 /* search header entries for to and newsgroup entries */
3587 for (list = compose->header_list; list; list = list->next) {
3590 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3591 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3593 if (strcmp(entry, compose->account->auto_cc)
3594 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3604 aval = alertpanel(_("Send"),
3605 _("The only recipient is the default CC address. Send anyway?"),
3606 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3607 if (aval != G_ALERTDEFAULT)
3611 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3612 gboolean found_other = FALSE;
3614 /* search header entries for to and newsgroup entries */
3615 for (list = compose->header_list; list; list = list->next) {
3618 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3619 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3621 if (strcmp(entry, compose->account->auto_cc)
3622 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3632 aval = alertpanel(_("Send"),
3633 _("The only recipient is the default BCC address. Send anyway?"),
3634 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3635 if (aval != G_ALERTDEFAULT)
3642 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3646 if (compose_check_for_valid_recipient(compose) == FALSE) {
3647 alertpanel_error(_("Recipient is not specified."));
3651 if (compose_check_for_set_recipients(compose) == FALSE) {
3655 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3656 if (*str == '\0' && check_subject == TRUE) {
3659 aval = alertpanel(_("Send"),
3660 _("Subject is empty. Send it anyway?"),
3661 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3662 if (aval != G_ALERTDEFAULT)
3669 gint compose_send(Compose *compose)
3676 compose_allow_user_actions (compose, FALSE);
3677 compose->sending = TRUE;
3679 if (compose_check_entries(compose, TRUE) == FALSE)
3682 val = compose_queue(compose, &msgnum, &folder);
3686 alertpanel_error(_("Could not queue message for sending:\n\n"
3687 "Charset conversion failed."));
3688 } else if (val == -3) {
3689 alertpanel_error(_("Could not queue message for sending:\n\n"
3690 "Signature failed."));
3691 } else if (val == -2) {
3692 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3694 alertpanel_error(_("Could not queue message for sending."));
3700 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3701 compose->sending = FALSE;
3702 compose_close(compose);
3703 /* No more compose access in the normal codepath
3704 * after this point! */
3709 alertpanel_error(_("The message was queued but could not be "
3710 "sent.\nUse \"Send queued messages\" from "
3711 "the main window to retry."));
3712 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3713 compose->sending = FALSE;
3714 compose_allow_user_actions (compose, TRUE);
3719 msgpath = folder_item_fetch_msg(folder, msgnum);
3720 val = procmsg_send_message_queue(msgpath);
3723 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3724 compose->sending = FALSE;
3725 compose_allow_user_actions (compose, TRUE);
3727 folder_item_remove_msg(folder, msgnum);
3728 folder_item_scan(folder);
3733 folder_item_remove_msg(folder, msgnum);
3734 folder_item_scan(folder);
3735 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3736 compose_close(compose);
3738 alertpanel_error(_("The message was queued but could not be "
3739 "sent.\nUse \"Send queued messages\" from "
3740 "the main window to retry."));
3741 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3742 compose_allow_user_actions (compose, TRUE);
3743 compose->sending = FALSE;
3751 compose_allow_user_actions (compose, TRUE);
3752 compose->sending = FALSE;
3757 static gboolean compose_use_attach(Compose *compose)
3759 GtkTreeModel *model = gtk_tree_view_get_model
3760 (GTK_TREE_VIEW(compose->attach_clist));
3761 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3764 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3767 gchar buf[BUFFSIZE];
3769 gboolean first_to_address;
3770 gboolean first_cc_address;
3772 ComposeHeaderEntry *headerentry;
3773 const gchar *headerentryname;
3777 debug_print("Writing redirect header\n");
3779 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3780 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3782 first_to_address = TRUE;
3783 for (list = compose->header_list; list; list = list->next) {
3784 headerentry = ((ComposeHeaderEntry *)list->data);
3785 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3787 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3788 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3789 Xstrdup_a(str, entstr, return -1);
3791 if (str[0] != '\0') {
3792 compose_convert_header
3793 (compose, buf, sizeof(buf), str,
3794 strlen("Resent-To") + 2, TRUE);
3796 if (first_to_address) {
3797 fprintf(fp, "Resent-To: ");
3798 first_to_address = FALSE;
3802 fprintf(fp, "%s", buf);
3806 if (!first_to_address) {
3810 first_cc_address = TRUE;
3811 for (list = compose->header_list; list; list = list->next) {
3812 headerentry = ((ComposeHeaderEntry *)list->data);
3813 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3815 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3816 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3817 Xstrdup_a(str, strg, return -1);
3819 if (str[0] != '\0') {
3820 compose_convert_header
3821 (compose, buf, sizeof(buf), str,
3822 strlen("Resent-Cc") + 2, TRUE);
3824 if (first_cc_address) {
3825 fprintf(fp, "Resent-Cc: ");
3826 first_cc_address = FALSE;
3830 fprintf(fp, "%s", buf);
3834 if (!first_cc_address) {
3841 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3843 gchar buf[BUFFSIZE];
3845 const gchar *entstr;
3846 /* struct utsname utsbuf; */
3848 g_return_val_if_fail(fp != NULL, -1);
3849 g_return_val_if_fail(compose->account != NULL, -1);
3850 g_return_val_if_fail(compose->account->address != NULL, -1);
3853 get_rfc822_date(buf, sizeof(buf));
3854 fprintf(fp, "Resent-Date: %s\n", buf);
3857 if (compose->account->name && *compose->account->name) {
3858 compose_convert_header
3859 (compose, buf, sizeof(buf), compose->account->name,
3860 strlen("From: "), TRUE);
3861 fprintf(fp, "Resent-From: %s <%s>\n",
3862 buf, compose->account->address);
3864 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3867 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3868 if (*entstr != '\0') {
3869 Xstrdup_a(str, entstr, return -1);
3872 compose_convert_header(compose, buf, sizeof(buf), str,
3873 strlen("Subject: "), FALSE);
3874 fprintf(fp, "Subject: %s\n", buf);
3878 /* Resent-Message-ID */
3879 if (compose->account->gen_msgid) {
3880 generate_msgid(buf, sizeof(buf));
3881 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3882 compose->msgid = g_strdup(buf);
3885 compose_redirect_write_headers_from_headerlist(compose, fp);
3887 /* separator between header and body */
3893 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3897 gchar buf[BUFFSIZE];
3899 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3900 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3904 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3905 /* should filter returnpath, delivered-to */
3906 if (g_ascii_strncasecmp(buf, "Return-Path:",
3907 strlen("Return-Path:")) == 0 ||
3908 g_ascii_strncasecmp(buf, "Delivered-To:",
3909 strlen("Delivered-To:")) == 0 ||
3910 g_ascii_strncasecmp(buf, "Received:",
3911 strlen("Received:")) == 0 ||
3912 g_ascii_strncasecmp(buf, "Subject:",
3913 strlen("Subject:")) == 0 ||
3914 g_ascii_strncasecmp(buf, "X-UIDL:",
3915 strlen("X-UIDL:")) == 0)
3918 if (fputs(buf, fdest) == -1)
3921 if (!prefs_common.redirect_keep_from) {
3922 if (g_ascii_strncasecmp(buf, "From:",
3923 strlen("From:")) == 0) {
3924 fputs(" (by way of ", fdest);
3925 if (compose->account->name
3926 && *compose->account->name) {
3927 compose_convert_header
3928 (compose, buf, sizeof(buf),
3929 compose->account->name,
3932 fprintf(fdest, "%s <%s>",
3934 compose->account->address);
3936 fprintf(fdest, "%s",
3937 compose->account->address);
3942 if (fputs("\n", fdest) == -1)
3946 compose_redirect_write_headers(compose, fdest);
3948 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3949 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3962 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3964 GtkTextBuffer *buffer;
3965 GtkTextIter start, end;
3968 const gchar *out_codeset;
3969 EncodingType encoding;
3970 MimeInfo *mimemsg, *mimetext;
3973 /* create message MimeInfo */
3974 mimemsg = procmime_mimeinfo_new();
3975 mimemsg->type = MIMETYPE_MESSAGE;
3976 mimemsg->subtype = g_strdup("rfc822");
3977 mimemsg->content = MIMECONTENT_MEM;
3978 mimemsg->data.mem = compose_get_header(compose);
3980 /* Create text part MimeInfo */
3981 /* get all composed text */
3982 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3983 gtk_text_buffer_get_start_iter(buffer, &start);
3984 gtk_text_buffer_get_end_iter(buffer, &end);
3985 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3986 if (is_ascii_str(chars)) {
3989 out_codeset = CS_US_ASCII;
3990 encoding = ENC_7BIT;
3992 const gchar *src_codeset = CS_INTERNAL;
3994 out_codeset = conv_get_charset_str(compose->out_encoding);
3997 gchar *test_conv_global_out = NULL;
3998 gchar *test_conv_reply = NULL;
4000 /* automatic mode. be automatic. */
4001 codeconv_set_strict(TRUE);
4003 out_codeset = conv_get_outgoing_charset_str();
4005 debug_print("trying to convert to %s\n", out_codeset);
4006 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4009 if (!test_conv_global_out && compose->orig_charset) {
4010 out_codeset = compose->orig_charset;
4011 debug_print("failure; trying to convert to %s\n", out_codeset);
4012 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4015 if (!test_conv_global_out && !test_conv_reply) {
4017 out_codeset = CS_INTERNAL;
4018 debug_print("finally using %s\n", out_codeset);
4020 g_free(test_conv_global_out);
4021 g_free(test_conv_reply);
4022 codeconv_set_strict(FALSE);
4025 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4026 out_codeset = CS_ISO_8859_1;
4028 if (prefs_common.encoding_method == CTE_BASE64)
4029 encoding = ENC_BASE64;
4030 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4031 encoding = ENC_QUOTED_PRINTABLE;
4032 else if (prefs_common.encoding_method == CTE_8BIT)
4033 encoding = ENC_8BIT;
4035 encoding = procmime_get_encoding_for_charset(out_codeset);
4037 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4038 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4040 if (action == COMPOSE_WRITE_FOR_SEND) {
4041 codeconv_set_strict(TRUE);
4042 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4043 codeconv_set_strict(FALSE);
4049 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4050 "to the specified %s charset.\n"
4051 "Send it as %s?"), out_codeset, src_codeset);
4052 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
4053 NULL, ALERT_ERROR, G_ALERTALTERNATE);
4056 if (aval != G_ALERTDEFAULT) {
4061 out_codeset = src_codeset;
4067 out_codeset = src_codeset;
4073 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4074 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4075 strstr(buf, "\nFrom ") != NULL) {
4076 encoding = ENC_QUOTED_PRINTABLE;
4080 mimetext = procmime_mimeinfo_new();
4081 mimetext->content = MIMECONTENT_MEM;
4082 mimetext->data.mem = buf;
4083 mimetext->type = MIMETYPE_TEXT;
4084 mimetext->subtype = g_strdup("plain");
4085 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4086 g_strdup(out_codeset));
4087 /* protect trailing spaces when signing message */
4088 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4089 privacy_system_can_sign(compose->privacy_system)) {
4090 encoding = ENC_QUOTED_PRINTABLE;
4093 /* check for line length limit */
4094 if (action == COMPOSE_WRITE_FOR_SEND &&
4095 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4096 check_line_length(buf, 1000, &line) < 0) {
4100 msg = g_strdup_printf
4101 (_("Line %d exceeds the line length limit (998 bytes).\n"
4102 "The contents of the message might be broken on the way to the delivery.\n"
4104 "Send it anyway?"), line + 1);
4105 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
4107 if (aval != G_ALERTDEFAULT) {
4112 if (encoding != ENC_UNKNOWN)
4113 procmime_encode_content(mimetext, encoding);
4115 /* append attachment parts */
4116 if (compose_use_attach(compose)) {
4117 MimeInfo *mimempart;
4118 gchar *boundary = NULL;
4119 mimempart = procmime_mimeinfo_new();
4120 mimempart->content = MIMECONTENT_EMPTY;
4121 mimempart->type = MIMETYPE_MULTIPART;
4122 mimempart->subtype = g_strdup("mixed");
4127 boundary = generate_mime_boundary(NULL);
4128 } while (strstr(buf, boundary) != NULL);
4130 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4133 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4135 g_node_append(mimempart->node, mimetext->node);
4136 g_node_append(mimemsg->node, mimempart->node);
4138 compose_add_attachments(compose, mimempart);
4140 g_node_append(mimemsg->node, mimetext->node);
4142 /* sign message if sending */
4143 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4144 privacy_system_can_sign(compose->privacy_system))
4145 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4148 procmime_write_mimeinfo(mimemsg, fp);
4150 procmime_mimeinfo_free_all(mimemsg);
4155 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4157 GtkTextBuffer *buffer;
4158 GtkTextIter start, end;
4163 if ((fp = g_fopen(file, "wb")) == NULL) {
4164 FILE_OP_ERROR(file, "fopen");
4168 /* chmod for security */
4169 if (change_file_mode_rw(fp, file) < 0) {
4170 FILE_OP_ERROR(file, "chmod");
4171 g_warning("can't change file mode\n");
4174 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4175 gtk_text_buffer_get_start_iter(buffer, &start);
4176 gtk_text_buffer_get_end_iter(buffer, &end);
4177 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4179 chars = conv_codeset_strdup
4180 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4183 if (!chars) return -1;
4186 len = strlen(chars);
4187 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4188 FILE_OP_ERROR(file, "fwrite");
4197 if (fclose(fp) == EOF) {
4198 FILE_OP_ERROR(file, "fclose");
4205 static gint compose_remove_reedit_target(Compose *compose)
4208 MsgInfo *msginfo = compose->targetinfo;
4210 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4211 if (!msginfo) return -1;
4213 item = msginfo->folder;
4214 g_return_val_if_fail(item != NULL, -1);
4216 if (procmsg_msg_exist(msginfo) &&
4217 (folder_has_parent_of_type(item, F_QUEUE) ||
4218 folder_has_parent_of_type(item, F_DRAFT)
4219 || msginfo == compose->autosaved_draft)) {
4220 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4221 g_warning("can't remove the old message\n");
4229 void compose_remove_draft(Compose *compose)
4232 MsgInfo *msginfo = compose->targetinfo;
4233 drafts = account_get_special_folder(compose->account, F_DRAFT);
4235 if (procmsg_msg_exist(msginfo)) {
4236 folder_item_remove_msg(drafts, msginfo->msgnum);
4241 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4243 return compose_queue_sub (compose, msgnum, item, FALSE);
4245 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4252 static gboolean lock = FALSE;
4253 PrefsAccount *mailac = NULL, *newsac = NULL;
4255 debug_print("queueing message...\n");
4256 g_return_val_if_fail(compose->account != NULL, -1);
4260 if (compose_check_entries(compose, check_subject) == FALSE) {
4265 if (!compose->to_list && !compose->newsgroup_list) {
4266 g_warning("can't get recipient list.");
4271 if (compose->to_list) {
4272 if (compose->account->protocol != A_NNTP)
4273 mailac = compose->account;
4274 else if (cur_account && cur_account->protocol != A_NNTP)
4275 mailac = cur_account;
4276 else if (!(mailac = compose_current_mail_account())) {
4278 alertpanel_error(_("No account for sending mails available!"));
4283 if (compose->newsgroup_list) {
4284 if (compose->account->protocol == A_NNTP)
4285 newsac = compose->account;
4286 else if (!newsac->protocol != A_NNTP) {
4288 alertpanel_error(_("No account for posting news available!"));
4293 if (prefs_common.linewrap_at_send)
4294 compose_wrap_all(compose);
4296 /* write queue header */
4297 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4298 G_DIR_SEPARATOR, compose);
4299 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4300 FILE_OP_ERROR(tmp, "fopen");
4305 if (change_file_mode_rw(fp, tmp) < 0) {
4306 FILE_OP_ERROR(tmp, "chmod");
4307 g_warning("can't change file mode\n");
4310 /* queueing variables */
4311 fprintf(fp, "AF:\n");
4312 fprintf(fp, "NF:0\n");
4313 fprintf(fp, "PS:10\n");
4314 fprintf(fp, "SRH:1\n");
4315 fprintf(fp, "SFN:\n");
4316 fprintf(fp, "DSR:\n");
4318 fprintf(fp, "MID:<%s>\n", compose->msgid);
4320 fprintf(fp, "MID:\n");
4321 fprintf(fp, "CFG:\n");
4322 fprintf(fp, "PT:0\n");
4323 fprintf(fp, "S:%s\n", compose->account->address);
4324 fprintf(fp, "RQ:\n");
4326 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4328 fprintf(fp, "SSV:\n");
4330 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4332 fprintf(fp, "NSV:\n");
4333 fprintf(fp, "SSH:\n");
4334 /* write recepient list */
4335 if (compose->to_list) {
4336 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4337 for (cur = compose->to_list->next; cur != NULL;
4339 fprintf(fp, ",<%s>", (gchar *)cur->data);
4342 /* write newsgroup list */
4343 if (compose->newsgroup_list) {
4345 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4346 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4347 fprintf(fp, ",%s", (gchar *)cur->data);
4350 /* Sylpheed account IDs */
4352 fprintf(fp, "MAID:%d\n", mailac->account_id);
4354 fprintf(fp, "NAID:%d\n", newsac->account_id);
4356 if (compose->privacy_system != NULL) {
4357 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4358 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4359 if (compose->use_encryption) {
4362 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4363 if (encdata != NULL) {
4364 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4365 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4366 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4368 } /* else we finally dont want to encrypt */
4370 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4371 /* and if encdata was null, it means there's been a problem in
4378 /* Save copy folder */
4379 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4380 gchar *savefolderid;
4382 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4383 fprintf(fp, "SCF:%s\n", savefolderid);
4384 g_free(savefolderid);
4386 /* Message-ID of message replying to */
4387 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4390 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4391 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4394 /* Message-ID of message forwarding to */
4395 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4398 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4399 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4404 if (compose->redirect_filename != NULL) {
4405 if (compose_redirect_write_to_file(compose, fp) < 0) {
4414 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4419 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4423 if (fclose(fp) == EOF) {
4424 FILE_OP_ERROR(tmp, "fclose");
4430 queue = account_get_special_folder(compose->account, F_QUEUE);
4432 g_warning("can't find queue folder\n");
4437 folder_item_scan(queue);
4438 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4439 g_warning("can't queue the message\n");
4447 if (compose->mode == COMPOSE_REEDIT) {
4448 compose_remove_reedit_target(compose);
4451 if ((msgnum != NULL) && (item != NULL)) {
4459 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4462 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4464 struct stat statbuf;
4465 gchar *type, *subtype;
4466 GtkTreeModel *model;
4469 model = gtk_tree_view_get_model(tree_view);
4471 if (!gtk_tree_model_get_iter_first(model, &iter))
4474 gtk_tree_model_get(model, &iter,
4478 mimepart = procmime_mimeinfo_new();
4479 mimepart->content = MIMECONTENT_FILE;
4480 mimepart->data.filename = g_strdup(ainfo->file);
4481 mimepart->offset = 0;
4483 stat(ainfo->file, &statbuf);
4484 mimepart->length = statbuf.st_size;
4486 type = g_strdup(ainfo->content_type);
4488 if (!strchr(type, '/')) {
4490 type = g_strdup("application/octet-stream");
4493 subtype = strchr(type, '/') + 1;
4494 *(subtype - 1) = '\0';
4495 mimepart->type = procmime_get_media_type(type);
4496 mimepart->subtype = g_strdup(subtype);
4499 if (mimepart->type == MIMETYPE_MESSAGE &&
4500 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4501 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4503 g_hash_table_insert(mimepart->typeparameters,
4504 g_strdup("name"), g_strdup(ainfo->name));
4505 g_hash_table_insert(mimepart->dispositionparameters,
4506 g_strdup("filename"), g_strdup(ainfo->name));
4507 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4510 if (compose->use_signing) {
4511 if (ainfo->encoding == ENC_7BIT)
4512 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4513 else if (ainfo->encoding == ENC_8BIT)
4514 ainfo->encoding = ENC_BASE64;
4517 procmime_encode_content(mimepart, ainfo->encoding);
4519 g_node_append(parent->node, mimepart->node);
4520 } while (gtk_tree_model_iter_next(model, &iter));
4523 #define QUOTE_IF_REQUIRED(out, str) \
4525 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4529 len = strlen(str) + 3; \
4530 if ((__tmp = alloca(len)) == NULL) { \
4531 g_warning("can't allocate memory\n"); \
4532 g_string_free(header, TRUE); \
4535 g_snprintf(__tmp, len, "\"%s\"", str); \
4540 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4541 g_warning("can't allocate memory\n"); \
4542 g_string_free(header, TRUE); \
4545 strcpy(__tmp, str); \
4551 #define IS_IN_CUSTOM_HEADER(header) \
4552 (compose->account->add_customhdr && \
4553 custom_header_find(compose->account->customhdr_list, header) != NULL)
4555 static void compose_add_headerfield_from_headerlist(Compose *compose,
4557 const gchar *fieldname,
4558 const gchar *seperator)
4560 gchar *str, *fieldname_w_colon, *trans_fieldname;
4561 gboolean add_field = FALSE;
4563 ComposeHeaderEntry *headerentry;
4564 const gchar * headerentryname;
4567 if (IS_IN_CUSTOM_HEADER(fieldname))
4570 debug_print("Adding %s-fields\n", fieldname);
4572 fieldstr = g_string_sized_new(64);
4574 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4575 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4577 for (list = compose->header_list; list; list = list->next) {
4578 headerentry = ((ComposeHeaderEntry *)list->data);
4579 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4581 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4582 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4584 if (str[0] != '\0') {
4586 g_string_append(fieldstr, seperator);
4587 g_string_append(fieldstr, str);
4596 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4597 compose_convert_header
4598 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4599 strlen(fieldname) + 2, TRUE);
4600 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4604 g_free(fieldname_w_colon);
4605 g_string_free(fieldstr, TRUE);
4610 static gchar *compose_get_header(Compose *compose)
4612 gchar buf[BUFFSIZE];
4613 const gchar *entry_str;
4617 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4620 g_return_val_if_fail(compose->account != NULL, NULL);
4621 g_return_val_if_fail(compose->account->address != NULL, NULL);
4623 header = g_string_sized_new(64);
4626 if (compose->account->add_date) {
4627 get_rfc822_date(buf, sizeof(buf));
4628 g_string_append_printf(header, "Date: %s\n", buf);
4632 if (compose->account->name && *compose->account->name) {
4633 compose_convert_header
4634 (compose, buf, sizeof(buf), compose->account->name,
4635 strlen("From: "), TRUE);
4636 QUOTE_IF_REQUIRED(name, buf);
4637 g_string_append_printf(header, "From: %s <%s>\n",
4638 name, compose->account->address);
4640 g_string_append_printf(header, "From: %s\n", compose->account->address);
4643 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4646 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4649 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4652 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4655 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4657 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4660 compose_convert_header(compose, buf, sizeof(buf), str,
4661 strlen("Subject: "), FALSE);
4662 g_string_append_printf(header, "Subject: %s\n", buf);
4668 if (compose->account->gen_msgid) {
4669 generate_msgid(buf, sizeof(buf));
4670 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4671 compose->msgid = g_strdup(buf);
4674 if (compose->remove_references == FALSE) {
4676 if (compose->inreplyto && compose->to_list)
4677 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4680 if (compose->references)
4681 g_string_append_printf(header, "References: %s\n", compose->references);
4685 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4688 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4691 if (compose->account->organization &&
4692 strlen(compose->account->organization) &&
4693 !IS_IN_CUSTOM_HEADER("Organization")) {
4694 compose_convert_header(compose, buf, sizeof(buf),
4695 compose->account->organization,
4696 strlen("Organization: "), FALSE);
4697 g_string_append_printf(header, "Organization: %s\n", buf);
4700 /* Program version and system info */
4701 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4702 !compose->newsgroup_list) {
4703 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4705 gtk_major_version, gtk_minor_version, gtk_micro_version,
4708 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4709 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4711 gtk_major_version, gtk_minor_version, gtk_micro_version,
4715 /* custom headers */
4716 if (compose->account->add_customhdr) {
4719 for (cur = compose->account->customhdr_list; cur != NULL;
4721 CustomHeader *chdr = (CustomHeader *)cur->data;
4723 if (custom_header_is_allowed(chdr->name)) {
4724 compose_convert_header
4725 (compose, buf, sizeof(buf),
4726 chdr->value ? chdr->value : "",
4727 strlen(chdr->name) + 2, FALSE);
4728 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4734 switch (compose->priority) {
4735 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4736 "X-Priority: 1 (Highest)\n");
4738 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4739 "X-Priority: 2 (High)\n");
4741 case PRIORITY_NORMAL: break;
4742 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4743 "X-Priority: 4 (Low)\n");
4745 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4746 "X-Priority: 5 (Lowest)\n");
4748 default: debug_print("compose: priority unknown : %d\n",
4752 /* Request Return Receipt */
4753 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4754 if (compose->return_receipt) {
4755 if (compose->account->name
4756 && *compose->account->name) {
4757 compose_convert_header(compose, buf, sizeof(buf),
4758 compose->account->name,
4759 strlen("Disposition-Notification-To: "),
4761 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4763 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4767 /* get special headers */
4768 for (list = compose->header_list; list; list = list->next) {
4769 ComposeHeaderEntry *headerentry;
4772 gchar *headername_wcolon;
4773 gchar *headername_trans;
4776 gboolean standard_header = FALSE;
4778 headerentry = ((ComposeHeaderEntry *)list->data);
4780 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4781 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4786 if (!strstr(tmp, ":")) {
4787 headername_wcolon = g_strconcat(tmp, ":", NULL);
4788 headername = g_strdup(tmp);
4790 headername_wcolon = g_strdup(tmp);
4791 headername = g_strdup(strtok(tmp, ":"));
4795 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4796 Xstrdup_a(headervalue, entry_str, return NULL);
4797 subst_char(headervalue, '\r', ' ');
4798 subst_char(headervalue, '\n', ' ');
4799 string = std_headers;
4800 while (*string != NULL) {
4801 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4802 if (!strcmp(headername_trans,headername_wcolon))
4803 standard_header = TRUE;
4806 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4807 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4810 g_free(headername_wcolon);
4814 g_string_free(header, FALSE);
4819 #undef IS_IN_CUSTOM_HEADER
4821 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4822 gint header_len, gboolean addr_field)
4824 gchar *tmpstr = NULL;
4825 const gchar *out_codeset = NULL;
4827 g_return_if_fail(src != NULL);
4828 g_return_if_fail(dest != NULL);
4830 if (len < 1) return;
4832 tmpstr = g_strdup(src);
4834 subst_char(tmpstr, '\n', ' ');
4835 subst_char(tmpstr, '\r', ' ');
4838 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4839 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4840 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4845 codeconv_set_strict(TRUE);
4846 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4847 conv_get_charset_str(compose->out_encoding));
4848 codeconv_set_strict(FALSE);
4850 if (!dest || *dest == '\0') {
4851 gchar *test_conv_global_out = NULL;
4852 gchar *test_conv_reply = NULL;
4854 /* automatic mode. be automatic. */
4855 codeconv_set_strict(TRUE);
4857 out_codeset = conv_get_outgoing_charset_str();
4859 debug_print("trying to convert to %s\n", out_codeset);
4860 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4863 if (!test_conv_global_out && compose->orig_charset) {
4864 out_codeset = compose->orig_charset;
4865 debug_print("failure; trying to convert to %s\n", out_codeset);
4866 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4869 if (!test_conv_global_out && !test_conv_reply) {
4871 out_codeset = CS_INTERNAL;
4872 debug_print("finally using %s\n", out_codeset);
4874 g_free(test_conv_global_out);
4875 g_free(test_conv_reply);
4876 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4878 codeconv_set_strict(FALSE);
4883 static void compose_create_header_entry(Compose *compose)
4885 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4889 GList *combo_list = NULL;
4891 const gchar *header = NULL;
4892 ComposeHeaderEntry *headerentry;
4893 gboolean standard_header = FALSE;
4895 headerentry = g_new0(ComposeHeaderEntry, 1);
4898 combo = gtk_combo_new();
4900 while(*string != NULL) {
4901 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4904 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4905 g_list_free(combo_list);
4906 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4907 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4908 G_CALLBACK(compose_grab_focus_cb), compose);
4909 gtk_widget_show(combo);
4910 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4911 if (compose->header_last) {
4912 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4914 while (*string != NULL) {
4915 if (!strcmp(*string, last_header_entry))
4916 standard_header = TRUE;
4919 if (standard_header)
4920 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4922 if (!compose->header_last || !standard_header) {
4923 switch(compose->account->protocol) {
4925 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4928 header = prefs_common.trans_hdr ? _("To:") : "To:";
4933 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4935 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4936 G_CALLBACK(compose_grab_focus_cb), compose);
4939 entry = gtk_entry_new();
4940 gtk_widget_show(entry);
4941 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);
4943 g_signal_connect(G_OBJECT(entry), "key-press-event",
4944 G_CALLBACK(compose_headerentry_key_press_event_cb),
4946 g_signal_connect(G_OBJECT(entry), "changed",
4947 G_CALLBACK(compose_headerentry_changed_cb),
4949 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4950 G_CALLBACK(compose_grab_focus_cb), compose);
4953 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4954 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4955 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4956 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4957 G_CALLBACK(compose_header_drag_received_cb),
4959 g_signal_connect(G_OBJECT(entry), "drag-drop",
4960 G_CALLBACK(compose_drag_drop),
4963 address_completion_register_entry(GTK_ENTRY(entry));
4965 headerentry->compose = compose;
4966 headerentry->combo = combo;
4967 headerentry->entry = entry;
4968 headerentry->headernum = compose->header_nextrow;
4970 compose->header_nextrow++;
4971 compose->header_last = headerentry;
4974 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4976 ComposeHeaderEntry *last_header;
4978 last_header = compose->header_last;
4980 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4981 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4984 static GtkWidget *compose_create_header(Compose *compose)
4988 GtkWidget *from_optmenu_hbox;
4989 GtkWidget *header_scrolledwin;
4990 GtkWidget *header_table;
4994 /* header labels and entries */
4995 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4996 gtk_widget_show(header_scrolledwin);
4997 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4999 header_table = gtk_table_new(2, 2, FALSE);
5000 gtk_widget_show(header_table);
5001 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5002 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5003 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5006 /* option menu for selecting accounts */
5007 hbox = gtk_hbox_new(FALSE, 0);
5008 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5009 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5010 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5012 from_optmenu_hbox = compose_account_option_menu_create(compose);
5013 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5014 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5017 compose->header_table = header_table;
5018 compose->header_list = NULL;
5019 compose->header_nextrow = count;
5021 compose_create_header_entry(compose);
5023 compose->table = NULL;
5025 return header_scrolledwin ;
5028 GtkWidget *compose_create_attach(Compose *compose)
5030 GtkWidget *attach_scrwin;
5031 GtkWidget *attach_clist;
5033 GtkListStore *store;
5034 GtkCellRenderer *renderer;
5035 GtkTreeViewColumn *column;
5036 GtkTreeSelection *selection;
5038 /* attachment list */
5039 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5040 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5041 GTK_POLICY_AUTOMATIC,
5042 GTK_POLICY_AUTOMATIC);
5043 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5045 store = gtk_list_store_new(N_ATTACH_COLS,
5050 G_TYPE_AUTO_POINTER,
5052 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5053 (GTK_TREE_MODEL(store)));
5054 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5055 g_object_unref(store);
5057 renderer = gtk_cell_renderer_text_new();
5058 column = gtk_tree_view_column_new_with_attributes
5059 (_("Mime type"), renderer, "text",
5060 COL_MIMETYPE, NULL);
5061 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5063 renderer = gtk_cell_renderer_text_new();
5064 column = gtk_tree_view_column_new_with_attributes
5065 (_("Size"), renderer, "text",
5067 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5069 renderer = gtk_cell_renderer_text_new();
5070 column = gtk_tree_view_column_new_with_attributes
5071 (_("Name"), renderer, "text",
5073 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5075 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5076 prefs_common.enable_rules_hint);
5077 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5078 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5080 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5081 G_CALLBACK(attach_selected), compose);
5082 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5083 G_CALLBACK(attach_button_pressed), compose);
5084 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5085 G_CALLBACK(attach_key_pressed), compose);
5088 gtk_drag_dest_set(attach_clist,
5089 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5090 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5091 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5092 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5093 G_CALLBACK(compose_attach_drag_received_cb),
5095 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5096 G_CALLBACK(compose_drag_drop),
5099 compose->attach_scrwin = attach_scrwin;
5100 compose->attach_clist = attach_clist;
5102 return attach_scrwin;
5105 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5106 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5108 static GtkWidget *compose_create_others(Compose *compose)
5111 GtkWidget *savemsg_checkbtn;
5112 GtkWidget *savemsg_entry;
5113 GtkWidget *savemsg_select;
5116 gchar *folderidentifier;
5118 /* Table for settings */
5119 table = gtk_table_new(3, 1, FALSE);
5120 gtk_widget_show(table);
5121 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5124 /* Save Message to folder */
5125 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5126 gtk_widget_show(savemsg_checkbtn);
5127 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5128 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5129 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5131 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5132 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5134 savemsg_entry = gtk_entry_new();
5135 gtk_widget_show(savemsg_entry);
5136 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5137 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5138 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5139 G_CALLBACK(compose_grab_focus_cb), compose);
5140 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5141 folderidentifier = folder_item_get_identifier(account_get_special_folder
5142 (compose->account, F_OUTBOX));
5143 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5144 g_free(folderidentifier);
5147 savemsg_select = gtk_button_new_with_label (_("Select ..."));
5148 gtk_widget_show(savemsg_select);
5149 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5150 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5151 G_CALLBACK(compose_savemsg_select_cb),
5156 compose->savemsg_checkbtn = savemsg_checkbtn;
5157 compose->savemsg_entry = savemsg_entry;
5162 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5164 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5165 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5168 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5173 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5176 path = folder_item_get_identifier(dest);
5178 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5182 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5185 #define BLOCK_WRAP() { \
5186 prev_autowrap = compose->autowrap; \
5187 buffer = gtk_text_view_get_buffer( \
5188 GTK_TEXT_VIEW(compose->text)); \
5189 compose->autowrap = FALSE; \
5191 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5192 G_CALLBACK(compose_changed_cb), \
5194 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5195 G_CALLBACK(text_inserted), \
5198 #define UNBLOCK_WRAP() { \
5199 compose->autowrap = prev_autowrap; \
5200 if (compose->autowrap) \
5201 compose_wrap_all(compose); \
5203 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5204 G_CALLBACK(compose_changed_cb), \
5206 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5207 G_CALLBACK(text_inserted), \
5212 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5216 GtkTextBuffer *buffer;
5217 if (event->button == 2) {
5219 entry_paste_clipboard(compose, compose->focused_editable,
5220 prefs_common.linewrap_pastes,
5221 GDK_SELECTION_PRIMARY);
5228 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5234 GtkWidget *handlebox;
5236 GtkWidget *notebook;
5241 GtkWidget *subject_hbox;
5242 GtkWidget *subject_frame;
5243 GtkWidget *subject_entry;
5247 GtkWidget *edit_vbox;
5248 GtkWidget *ruler_hbox;
5250 GtkWidget *scrolledwin;
5252 GtkTextBuffer *buffer;
5253 GtkClipboard *clipboard;
5255 UndoMain *undostruct;
5257 gchar *titles[N_ATTACH_COLS];
5258 guint n_menu_entries;
5261 gboolean success[1];
5262 GtkWidget *popupmenu;
5263 GtkItemFactory *popupfactory;
5264 GtkItemFactory *ifactory;
5265 GtkWidget *tmpl_menu;
5267 GtkWidget *menuitem;
5270 GtkAspell * gtkaspell = NULL;
5273 static GdkGeometry geometry;
5275 g_return_val_if_fail(account != NULL, NULL);
5277 debug_print("Creating compose window...\n");
5278 compose = g_new0(Compose, 1);
5280 titles[COL_MIMETYPE] = _("MIME type");
5281 titles[COL_SIZE] = _("Size");
5282 titles[COL_NAME] = _("Name");
5284 compose->account = account;
5286 compose->mutex = g_mutex_new();
5288 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5289 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5290 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5292 if (!geometry.max_width) {
5293 geometry.max_width = gdk_screen_width();
5294 geometry.max_height = gdk_screen_height();
5297 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5298 &geometry, GDK_HINT_MAX_SIZE);
5299 if (!geometry.min_width) {
5300 geometry.min_width = 600;
5301 geometry.min_height = 480;
5303 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5304 &geometry, GDK_HINT_MIN_SIZE);
5305 gtk_widget_set_uposition(window, prefs_common.compose_x,
5306 prefs_common.compose_y);
5308 g_signal_connect(G_OBJECT(window), "delete_event",
5309 G_CALLBACK(compose_delete_cb), compose);
5310 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5311 gtk_widget_realize(window);
5313 gtkut_widget_set_composer_icon(window);
5315 vbox = gtk_vbox_new(FALSE, 0);
5316 gtk_container_add(GTK_CONTAINER(window), vbox);
5318 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5319 menubar = menubar_create(window, compose_entries,
5320 n_menu_entries, "<Compose>", compose);
5321 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5323 if (prefs_common.toolbar_detachable) {
5324 handlebox = gtk_handle_box_new();
5326 handlebox = gtk_hbox_new(FALSE, 0);
5328 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5330 gtk_widget_realize(handlebox);
5331 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5334 vbox2 = gtk_vbox_new(FALSE, 2);
5335 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5336 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5339 notebook = gtk_notebook_new();
5340 gtk_widget_set_size_request(notebook, -1, 130);
5341 gtk_widget_show(notebook);
5343 /* header labels and entries */
5344 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5345 /* attachment list */
5346 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5348 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5351 subject_hbox = gtk_hbox_new(FALSE, 0);
5352 gtk_widget_show(subject_hbox);
5354 subject_frame = gtk_frame_new(NULL);
5355 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5356 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5357 gtk_widget_show(subject_frame);
5359 subject = gtk_hbox_new(FALSE, 0);
5360 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5361 gtk_widget_show(subject);
5363 label = gtk_label_new(_("Subject:"));
5364 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5365 gtk_widget_show(label);
5367 subject_entry = gtk_entry_new();
5368 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5369 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5370 G_CALLBACK(compose_grab_focus_cb), compose);
5371 gtk_widget_show(subject_entry);
5372 compose->subject_entry = subject_entry;
5373 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5375 edit_vbox = gtk_vbox_new(FALSE, 0);
5377 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5380 ruler_hbox = gtk_hbox_new(FALSE, 0);
5381 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5383 ruler = gtk_shruler_new();
5384 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5385 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5389 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5390 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5391 GTK_POLICY_AUTOMATIC,
5392 GTK_POLICY_AUTOMATIC);
5393 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5395 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5396 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5398 text = gtk_text_view_new();
5399 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5400 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5401 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5402 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5403 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5405 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5407 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5408 G_CALLBACK(compose_edit_size_alloc),
5410 g_signal_connect(G_OBJECT(buffer), "changed",
5411 G_CALLBACK(compose_changed_cb), compose);
5412 g_signal_connect(G_OBJECT(text), "grab_focus",
5413 G_CALLBACK(compose_grab_focus_cb), compose);
5414 g_signal_connect(G_OBJECT(buffer), "insert_text",
5415 G_CALLBACK(text_inserted), compose);
5416 g_signal_connect(G_OBJECT(text), "button_press_event",
5417 G_CALLBACK(text_clicked), compose);
5420 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5421 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5422 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5423 g_signal_connect(G_OBJECT(text), "drag_data_received",
5424 G_CALLBACK(compose_insert_drag_received_cb),
5426 g_signal_connect(G_OBJECT(text), "drag-drop",
5427 G_CALLBACK(compose_drag_drop),
5429 gtk_widget_show_all(vbox);
5431 /* pane between attach clist and text */
5432 paned = gtk_vpaned_new();
5433 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5434 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5435 gtk_paned_add1(GTK_PANED(paned), notebook);
5436 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5437 gtk_widget_show_all(paned);
5440 if (prefs_common.textfont) {
5441 PangoFontDescription *font_desc;
5443 font_desc = pango_font_description_from_string
5444 (prefs_common.textfont);
5446 gtk_widget_modify_font(text, font_desc);
5447 pango_font_description_free(font_desc);
5451 color[0] = quote_color;
5452 cmap = gdk_drawable_get_colormap(window->window);
5453 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5454 if (success[0] == FALSE) {
5457 g_warning("Compose: color allocation failed.\n");
5458 style = gtk_widget_get_style(text);
5459 quote_color = style->black;
5462 n_entries = sizeof(compose_popup_entries) /
5463 sizeof(compose_popup_entries[0]);
5464 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5465 "<Compose>", &popupfactory,
5468 ifactory = gtk_item_factory_from_widget(menubar);
5469 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5470 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5471 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5473 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5475 undostruct = undo_init(text);
5476 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5479 address_completion_start(window);
5481 compose->window = window;
5482 compose->vbox = vbox;
5483 compose->menubar = menubar;
5484 compose->handlebox = handlebox;
5486 compose->vbox2 = vbox2;
5488 compose->paned = paned;
5490 compose->edit_vbox = edit_vbox;
5491 compose->ruler_hbox = ruler_hbox;
5492 compose->ruler = ruler;
5493 compose->scrolledwin = scrolledwin;
5494 compose->text = text;
5496 compose->focused_editable = NULL;
5498 compose->popupmenu = popupmenu;
5499 compose->popupfactory = popupfactory;
5501 compose->tmpl_menu = tmpl_menu;
5503 compose->mode = mode;
5505 compose->targetinfo = NULL;
5506 compose->replyinfo = NULL;
5507 compose->fwdinfo = NULL;
5509 compose->replyto = NULL;
5511 compose->bcc = NULL;
5512 compose->followup_to = NULL;
5514 compose->ml_post = NULL;
5516 compose->inreplyto = NULL;
5517 compose->references = NULL;
5518 compose->msgid = NULL;
5519 compose->boundary = NULL;
5521 compose->autowrap = prefs_common.autowrap;
5523 compose->use_signing = FALSE;
5524 compose->use_encryption = FALSE;
5525 compose->privacy_system = NULL;
5527 compose->modified = FALSE;
5529 compose->return_receipt = FALSE;
5531 compose->to_list = NULL;
5532 compose->newsgroup_list = NULL;
5534 compose->undostruct = undostruct;
5536 compose->sig_str = NULL;
5538 compose->exteditor_file = NULL;
5539 compose->exteditor_pid = -1;
5540 compose->exteditor_tag = -1;
5541 compose->draft_timeout_tag = -1;
5544 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5545 if (mode != COMPOSE_REDIRECT) {
5546 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5547 strcmp(prefs_common.dictionary, _("None"))) {
5548 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5549 prefs_common.dictionary,
5550 conv_get_locale_charset_str(),
5551 prefs_common.misspelled_col,
5552 prefs_common.check_while_typing,
5553 prefs_common.use_alternate,
5554 GTK_TEXT_VIEW(text),
5555 GTK_WINDOW(compose->window));
5557 alertpanel_error(_("Spell checker could not "
5559 gtkaspell_checkers_strerror());
5560 gtkaspell_checkers_reset_error();
5563 GtkWidget *menuitem;
5565 if (!gtkaspell_set_sug_mode(gtkaspell,
5566 prefs_common.aspell_sugmode)) {
5567 debug_print("Aspell: could not set "
5568 "suggestion mode %s\n",
5569 gtkaspell_checkers_strerror());
5570 gtkaspell_checkers_reset_error();
5573 menuitem = gtk_item_factory_get_item(ifactory,
5574 "/Spelling/Spelling Configuration");
5575 gtkaspell_populate_submenu(gtkaspell, menuitem);
5576 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5580 compose->gtkaspell = gtkaspell;
5583 compose_select_account(compose, account, TRUE);
5585 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5586 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5587 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5589 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5590 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5592 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5593 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5596 if (account->protocol != A_NNTP)
5597 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5599 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5601 addressbook_set_target_compose(compose);
5603 if (mode != COMPOSE_REDIRECT)
5604 compose_set_template_menu(compose);
5606 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5607 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5610 compose_list = g_list_append(compose_list, compose);
5612 if (!prefs_common.show_ruler)
5613 gtk_widget_hide(ruler_hbox);
5615 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5616 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5617 prefs_common.show_ruler);
5620 compose->priority = PRIORITY_NORMAL;
5621 compose_update_priority_menu_item(compose);
5623 compose_set_out_encoding(compose);
5626 compose_update_actions_menu(compose);
5628 /* Privacy Systems menu */
5629 compose_update_privacy_systems_menu(compose);
5631 activate_privacy_system(compose, account, TRUE);
5632 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5633 gtk_widget_show(window);
5638 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5644 gint num = 0, def_menu = 0;
5646 accounts = account_get_list();
5647 g_return_val_if_fail(accounts != NULL, NULL);
5649 hbox = gtk_hbox_new(FALSE, 0);
5650 optmenu = gtk_option_menu_new();
5651 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5652 menu = gtk_menu_new();
5654 for (; accounts != NULL; accounts = accounts->next, num++) {
5655 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5656 GtkWidget *menuitem;
5659 if (ac == compose->account) def_menu = num;
5662 name = g_strdup_printf("%s: %s <%s>",
5664 ac->name, ac->address);
5666 name = g_strdup_printf("%s: %s",
5667 ac->account_name, ac->address);
5668 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5670 g_signal_connect(G_OBJECT(menuitem), "activate",
5671 G_CALLBACK(account_activated),
5675 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5676 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5681 static void compose_set_priority_cb(gpointer data,
5685 Compose *compose = (Compose *) data;
5686 compose->priority = action;
5689 static void compose_update_priority_menu_item(Compose * compose)
5691 GtkItemFactory *ifactory;
5692 GtkWidget *menuitem = NULL;
5694 ifactory = gtk_item_factory_from_widget(compose->menubar);
5696 switch (compose->priority) {
5697 case PRIORITY_HIGHEST:
5698 menuitem = gtk_item_factory_get_item
5699 (ifactory, "/Options/Priority/Highest");
5702 menuitem = gtk_item_factory_get_item
5703 (ifactory, "/Options/Priority/High");
5705 case PRIORITY_NORMAL:
5706 menuitem = gtk_item_factory_get_item
5707 (ifactory, "/Options/Priority/Normal");
5710 menuitem = gtk_item_factory_get_item
5711 (ifactory, "/Options/Priority/Low");
5713 case PRIORITY_LOWEST:
5714 menuitem = gtk_item_factory_get_item
5715 (ifactory, "/Options/Priority/Lowest");
5718 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5721 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5723 Compose *compose = (Compose *) data;
5725 GtkItemFactory *ifactory;
5726 gboolean can_sign = FALSE, can_encrypt = FALSE;
5728 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5730 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5733 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5734 g_free(compose->privacy_system);
5735 compose->privacy_system = NULL;
5736 if (systemid != NULL) {
5737 compose->privacy_system = g_strdup(systemid);
5739 can_sign = privacy_system_can_sign(systemid);
5740 can_encrypt = privacy_system_can_encrypt(systemid);
5743 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5745 ifactory = gtk_item_factory_from_widget(compose->menubar);
5746 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5747 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5750 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5752 static gchar *branch_path = "/Options/Privacy System";
5753 GtkItemFactory *ifactory;
5754 GtkWidget *menuitem = NULL;
5756 gboolean can_sign = FALSE, can_encrypt = FALSE;
5757 gboolean found = FALSE;
5759 ifactory = gtk_item_factory_from_widget(compose->menubar);
5761 if (compose->privacy_system != NULL) {
5764 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5765 g_return_if_fail(menuitem != NULL);
5767 amenu = GTK_MENU_SHELL(menuitem)->children;
5769 while (amenu != NULL) {
5770 GList *alist = amenu->next;
5772 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5773 if (systemid != NULL) {
5774 if (strcmp(systemid, compose->privacy_system) == 0) {
5775 menuitem = GTK_WIDGET(amenu->data);
5777 can_sign = privacy_system_can_sign(systemid);
5778 can_encrypt = privacy_system_can_encrypt(systemid);
5782 } else if (strlen(compose->privacy_system) == 0) {
5783 menuitem = GTK_WIDGET(amenu->data);
5786 can_encrypt = FALSE;
5793 if (menuitem != NULL)
5794 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5796 if (warn && !found && strlen(compose->privacy_system)) {
5797 gchar *tmp = g_strdup_printf(
5798 _("The privacy system '%s' cannot be loaded. You "
5799 "will not be able to sign or encrypt this message."),
5800 compose->privacy_system);
5801 alertpanel_warning(tmp);
5806 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5807 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5810 static void compose_set_out_encoding(Compose *compose)
5812 GtkItemFactoryEntry *entry;
5813 GtkItemFactory *ifactory;
5814 CharSet out_encoding;
5815 gchar *path, *p, *q;
5818 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5819 ifactory = gtk_item_factory_from_widget(compose->menubar);
5821 for (entry = compose_entries; entry->callback != compose_address_cb;
5823 if (entry->callback == compose_set_encoding_cb &&
5824 (CharSet)entry->callback_action == out_encoding) {
5825 p = q = path = g_strdup(entry->path);
5837 item = gtk_item_factory_get_item(ifactory, path);
5838 gtk_widget_activate(item);
5845 static void compose_set_template_menu(Compose *compose)
5847 GSList *tmpl_list, *cur;
5851 tmpl_list = template_get_config();
5853 menu = gtk_menu_new();
5855 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5856 Template *tmpl = (Template *)cur->data;
5858 item = gtk_menu_item_new_with_label(tmpl->name);
5859 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5860 g_signal_connect(G_OBJECT(item), "activate",
5861 G_CALLBACK(compose_template_activate_cb),
5863 g_object_set_data(G_OBJECT(item), "template", tmpl);
5864 gtk_widget_show(item);
5867 gtk_widget_show(menu);
5868 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5871 void compose_update_actions_menu(Compose *compose)
5873 GtkItemFactory *ifactory;
5875 ifactory = gtk_item_factory_from_widget(compose->menubar);
5876 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5879 void compose_update_privacy_systems_menu(Compose *compose)
5881 static gchar *branch_path = "/Options/Privacy System";
5882 GtkItemFactory *ifactory;
5883 GtkWidget *menuitem;
5884 GSList *systems, *cur;
5887 GtkWidget *system_none;
5890 ifactory = gtk_item_factory_from_widget(compose->menubar);
5892 /* remove old entries */
5893 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5894 g_return_if_fail(menuitem != NULL);
5896 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5897 while (amenu != NULL) {
5898 GList *alist = amenu->next;
5899 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5903 system_none = gtk_item_factory_get_widget(ifactory,
5904 "/Options/Privacy System/None");
5906 g_signal_connect(G_OBJECT(system_none), "activate",
5907 G_CALLBACK(compose_set_privacy_system_cb), compose);
5909 systems = privacy_get_system_ids();
5910 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5911 gchar *systemid = cur->data;
5913 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5914 widget = gtk_radio_menu_item_new_with_label(group,
5915 privacy_system_get_name(systemid));
5916 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5917 g_strdup(systemid), g_free);
5918 g_signal_connect(G_OBJECT(widget), "activate",
5919 G_CALLBACK(compose_set_privacy_system_cb), compose);
5921 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5922 gtk_widget_show(widget);
5925 g_slist_free(systems);
5928 void compose_reflect_prefs_all(void)
5933 for (cur = compose_list; cur != NULL; cur = cur->next) {
5934 compose = (Compose *)cur->data;
5935 compose_set_template_menu(compose);
5939 void compose_reflect_prefs_pixmap_theme(void)
5944 for (cur = compose_list; cur != NULL; cur = cur->next) {
5945 compose = (Compose *)cur->data;
5946 toolbar_update(TOOLBAR_COMPOSE, compose);
5950 static void compose_template_apply(Compose *compose, Template *tmpl,
5954 GtkTextBuffer *buffer;
5959 gint cursor_pos = 0;
5960 if (!tmpl || !tmpl->value) return;
5962 text = GTK_TEXT_VIEW(compose->text);
5963 buffer = gtk_text_view_get_buffer(text);
5965 if (tmpl->subject && *tmpl->subject != '\0')
5966 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5968 if (tmpl->to && *tmpl->to != '\0')
5969 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5970 if (tmpl->cc && *tmpl->cc != '\0')
5971 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5973 if (tmpl->bcc && *tmpl->bcc != '\0')
5974 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5977 gtk_text_buffer_set_text(buffer, "", -1);
5979 mark = gtk_text_buffer_get_insert(buffer);
5980 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
5982 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5983 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5986 if (prefs_common.quotemark && *prefs_common.quotemark)
5987 qmark = prefs_common.quotemark;
5991 if (compose->replyinfo != NULL)
5992 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5993 tmpl->value, qmark, NULL);
5994 else if (compose->fwdinfo != NULL)
5995 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5996 tmpl->value, qmark, NULL);
6001 if (replace && parsed_str && compose->account->auto_sig)
6002 compose_insert_sig(compose, FALSE);
6004 if (replace && parsed_str) {
6005 gtk_text_buffer_get_start_iter(buffer, &iter);
6006 gtk_text_buffer_place_cursor(buffer, &iter);
6010 cursor_pos = quote_fmt_get_cursor_pos();
6011 gtk_text_buffer_get_start_iter(buffer, &iter);
6012 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6013 gtk_text_buffer_place_cursor(buffer, &iter);
6017 compose_changed_cb(NULL, compose);
6020 static void compose_destroy(Compose *compose)
6022 compose_list = g_list_remove(compose_list, compose);
6024 /* NOTE: address_completion_end() does nothing with the window
6025 * however this may change. */
6026 address_completion_end(compose->window);
6028 slist_free_strings(compose->to_list);
6029 g_slist_free(compose->to_list);
6030 slist_free_strings(compose->newsgroup_list);
6031 g_slist_free(compose->newsgroup_list);
6032 slist_free_strings(compose->header_list);
6033 g_slist_free(compose->header_list);
6035 procmsg_msginfo_free(compose->targetinfo);
6036 procmsg_msginfo_free(compose->replyinfo);
6037 procmsg_msginfo_free(compose->fwdinfo);
6039 g_free(compose->replyto);
6040 g_free(compose->cc);
6041 g_free(compose->bcc);
6042 g_free(compose->newsgroups);
6043 g_free(compose->followup_to);
6045 g_free(compose->ml_post);
6047 g_free(compose->inreplyto);
6048 g_free(compose->references);
6049 g_free(compose->msgid);
6050 g_free(compose->boundary);
6052 if (compose->redirect_filename)
6053 g_free(compose->redirect_filename);
6054 if (compose->undostruct)
6055 undo_destroy(compose->undostruct);
6057 g_free(compose->sig_str);
6059 g_free(compose->exteditor_file);
6061 g_free(compose->orig_charset);
6063 g_free(compose->privacy_system);
6065 if (addressbook_get_target_compose() == compose)
6066 addressbook_set_target_compose(NULL);
6069 if (compose->gtkaspell) {
6070 gtkaspell_delete(compose->gtkaspell);
6071 compose->gtkaspell = NULL;
6075 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6076 prefs_common.compose_height = compose->window->allocation.height;
6078 if (!gtk_widget_get_parent(compose->paned))
6079 gtk_widget_destroy(compose->paned);
6080 gtk_widget_destroy(compose->popupmenu);
6082 gtk_widget_destroy(compose->window);
6083 toolbar_destroy(compose->toolbar);
6084 g_free(compose->toolbar);
6085 g_mutex_free(compose->mutex);
6089 static void compose_attach_info_free(AttachInfo *ainfo)
6091 g_free(ainfo->file);
6092 g_free(ainfo->content_type);
6093 g_free(ainfo->name);
6097 static void compose_attach_remove_selected(Compose *compose)
6099 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6100 GtkTreeSelection *selection;
6102 GtkTreeModel *model;
6104 selection = gtk_tree_view_get_selection(tree_view);
6105 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6110 for (cur = sel; cur != NULL; cur = cur->next) {
6111 GtkTreePath *path = cur->data;
6112 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6115 gtk_tree_path_free(path);
6118 for (cur = sel; cur != NULL; cur = cur->next) {
6119 GtkTreeRowReference *ref = cur->data;
6120 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6123 if (gtk_tree_model_get_iter(model, &iter, path))
6124 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6126 gtk_tree_path_free(path);
6127 gtk_tree_row_reference_free(ref);
6133 static struct _AttachProperty
6136 GtkWidget *mimetype_entry;
6137 GtkWidget *encoding_optmenu;
6138 GtkWidget *path_entry;
6139 GtkWidget *filename_entry;
6141 GtkWidget *cancel_btn;
6144 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6146 gtk_tree_path_free((GtkTreePath *)ptr);
6149 static void compose_attach_property(Compose *compose)
6151 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6153 GtkOptionMenu *optmenu;
6154 GtkTreeSelection *selection;
6156 GtkTreeModel *model;
6159 static gboolean cancelled;
6161 /* only if one selected */
6162 selection = gtk_tree_view_get_selection(tree_view);
6163 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6166 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6170 path = (GtkTreePath *) sel->data;
6171 gtk_tree_model_get_iter(model, &iter, path);
6172 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6175 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6181 if (!attach_prop.window)
6182 compose_attach_property_create(&cancelled);
6183 gtk_widget_grab_focus(attach_prop.ok_btn);
6184 gtk_widget_show(attach_prop.window);
6185 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6187 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6188 if (ainfo->encoding == ENC_UNKNOWN)
6189 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6190 GINT_TO_POINTER(ENC_BASE64));
6192 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6193 GINT_TO_POINTER(ainfo->encoding));
6195 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6196 ainfo->content_type ? ainfo->content_type : "");
6197 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6198 ainfo->file ? ainfo->file : "");
6199 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6200 ainfo->name ? ainfo->name : "");
6203 const gchar *entry_text;
6205 gchar *cnttype = NULL;
6209 GtkWidget *menuitem;
6214 gtk_widget_hide(attach_prop.window);
6219 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6220 if (*entry_text != '\0') {
6223 text = g_strstrip(g_strdup(entry_text));
6224 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6225 cnttype = g_strdup(text);
6228 alertpanel_error(_("Invalid MIME type."));
6234 menu = gtk_option_menu_get_menu(optmenu);
6235 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6236 ainfo->encoding = GPOINTER_TO_INT
6237 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6239 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6240 if (*entry_text != '\0') {
6241 if (is_file_exist(entry_text) &&
6242 (size = get_file_size(entry_text)) > 0)
6243 file = g_strdup(entry_text);
6246 (_("File doesn't exist or is empty."));
6252 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6253 if (*entry_text != '\0') {
6254 g_free(ainfo->name);
6255 ainfo->name = g_strdup(entry_text);
6259 g_free(ainfo->content_type);
6260 ainfo->content_type = cnttype;
6263 g_free(ainfo->file);
6269 /* update tree store */
6270 text = to_human_readable(ainfo->size);
6271 gtk_tree_model_get_iter(model, &iter, path);
6272 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6273 COL_MIMETYPE, ainfo->content_type,
6275 COL_NAME, ainfo->name,
6281 gtk_tree_path_free(path);
6284 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6286 label = gtk_label_new(str); \
6287 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6288 GTK_FILL, 0, 0, 0); \
6289 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6291 entry = gtk_entry_new(); \
6292 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6293 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6296 static void compose_attach_property_create(gboolean *cancelled)
6302 GtkWidget *mimetype_entry;
6305 GtkWidget *optmenu_menu;
6306 GtkWidget *menuitem;
6307 GtkWidget *path_entry;
6308 GtkWidget *filename_entry;
6311 GtkWidget *cancel_btn;
6312 GList *mime_type_list, *strlist;
6314 debug_print("Creating attach_property window...\n");
6316 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6317 gtk_widget_set_size_request(window, 480, -1);
6318 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6319 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6320 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6321 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6322 g_signal_connect(G_OBJECT(window), "delete_event",
6323 G_CALLBACK(attach_property_delete_event),
6325 g_signal_connect(G_OBJECT(window), "key_press_event",
6326 G_CALLBACK(attach_property_key_pressed),
6329 vbox = gtk_vbox_new(FALSE, 8);
6330 gtk_container_add(GTK_CONTAINER(window), vbox);
6332 table = gtk_table_new(4, 2, FALSE);
6333 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6334 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6335 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6337 label = gtk_label_new(_("MIME type"));
6338 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6340 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6341 mimetype_entry = gtk_combo_new();
6342 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6343 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6345 /* stuff with list */
6346 mime_type_list = procmime_get_mime_type_list();
6348 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6349 MimeType *type = (MimeType *) mime_type_list->data;
6350 strlist = g_list_append(strlist,
6351 g_strdup_printf("%s/%s",
6352 type->type, type->sub_type));
6355 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6357 for (mime_type_list = strlist; mime_type_list != NULL;
6358 mime_type_list = mime_type_list->next)
6359 g_free(mime_type_list->data);
6360 g_list_free(strlist);
6362 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6364 label = gtk_label_new(_("Encoding"));
6365 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6367 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6369 hbox = gtk_hbox_new(FALSE, 0);
6370 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6371 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6373 optmenu = gtk_option_menu_new();
6374 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6376 optmenu_menu = gtk_menu_new();
6377 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6378 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6379 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6380 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6381 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6382 ENC_QUOTED_PRINTABLE);
6383 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6385 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6387 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6389 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6390 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6392 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
6393 &cancel_btn, GTK_STOCK_CANCEL,
6395 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6396 gtk_widget_grab_default(ok_btn);
6398 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6399 G_CALLBACK(attach_property_ok),
6401 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6402 G_CALLBACK(attach_property_cancel),
6405 gtk_widget_show_all(vbox);
6407 attach_prop.window = window;
6408 attach_prop.mimetype_entry = mimetype_entry;
6409 attach_prop.encoding_optmenu = optmenu;
6410 attach_prop.path_entry = path_entry;
6411 attach_prop.filename_entry = filename_entry;
6412 attach_prop.ok_btn = ok_btn;
6413 attach_prop.cancel_btn = cancel_btn;
6416 #undef SET_LABEL_AND_ENTRY
6418 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6424 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6430 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6431 gboolean *cancelled)
6439 static gboolean attach_property_key_pressed(GtkWidget *widget,
6441 gboolean *cancelled)
6443 if (event && event->keyval == GDK_Escape) {
6450 static void compose_exec_ext_editor(Compose *compose)
6457 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6458 G_DIR_SEPARATOR, compose);
6460 if (pipe(pipe_fds) < 0) {
6466 if ((pid = fork()) < 0) {
6473 /* close the write side of the pipe */
6476 compose->exteditor_file = g_strdup(tmp);
6477 compose->exteditor_pid = pid;
6479 compose_set_ext_editor_sensitive(compose, FALSE);
6481 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6482 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6486 } else { /* process-monitoring process */
6492 /* close the read side of the pipe */
6495 if (compose_write_body_to_file(compose, tmp) < 0) {
6496 fd_write_all(pipe_fds[1], "2\n", 2);
6500 pid_ed = compose_exec_ext_editor_real(tmp);
6502 fd_write_all(pipe_fds[1], "1\n", 2);
6506 /* wait until editor is terminated */
6507 waitpid(pid_ed, NULL, 0);
6509 fd_write_all(pipe_fds[1], "0\n", 2);
6516 #endif /* G_OS_UNIX */
6520 static gint compose_exec_ext_editor_real(const gchar *file)
6522 static gchar *def_cmd = "emacs %s";
6528 g_return_val_if_fail(file != NULL, -1);
6530 if ((pid = fork()) < 0) {
6535 if (pid != 0) return pid;
6537 /* grandchild process */
6539 if (setpgid(0, getppid()))
6542 if (prefs_common.ext_editor_cmd &&
6543 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6544 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6545 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6547 if (prefs_common.ext_editor_cmd)
6548 g_warning("External editor command line is invalid: '%s'\n",
6549 prefs_common.ext_editor_cmd);
6550 g_snprintf(buf, sizeof(buf), def_cmd, file);
6553 cmdline = strsplit_with_quote(buf, " ", 1024);
6554 execvp(cmdline[0], cmdline);
6557 g_strfreev(cmdline);
6562 static gboolean compose_ext_editor_kill(Compose *compose)
6564 pid_t pgid = compose->exteditor_pid * -1;
6567 ret = kill(pgid, 0);
6569 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6573 msg = g_strdup_printf
6574 (_("The external editor is still working.\n"
6575 "Force terminating the process?\n"
6576 "process group id: %d"), -pgid);
6577 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6578 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6582 if (val == G_ALERTDEFAULT) {
6583 g_source_remove(compose->exteditor_tag);
6584 g_io_channel_shutdown(compose->exteditor_ch,
6586 g_io_channel_unref(compose->exteditor_ch);
6588 if (kill(pgid, SIGTERM) < 0) perror("kill");
6589 waitpid(compose->exteditor_pid, NULL, 0);
6591 g_warning("Terminated process group id: %d", -pgid);
6592 g_warning("Temporary file: %s",
6593 compose->exteditor_file);
6595 compose_set_ext_editor_sensitive(compose, TRUE);
6597 g_free(compose->exteditor_file);
6598 compose->exteditor_file = NULL;
6599 compose->exteditor_pid = -1;
6600 compose->exteditor_ch = NULL;
6601 compose->exteditor_tag = -1;
6609 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6613 Compose *compose = (Compose *)data;
6616 debug_print(_("Compose: input from monitoring process\n"));
6618 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6620 g_io_channel_shutdown(source, FALSE, NULL);
6621 g_io_channel_unref(source);
6623 waitpid(compose->exteditor_pid, NULL, 0);
6625 if (buf[0] == '0') { /* success */
6626 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6627 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6629 gtk_text_buffer_set_text(buffer, "", -1);
6630 compose_insert_file(compose, compose->exteditor_file);
6631 compose_changed_cb(NULL, compose);
6633 if (g_unlink(compose->exteditor_file) < 0)
6634 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6635 } else if (buf[0] == '1') { /* failed */
6636 g_warning("Couldn't exec external editor\n");
6637 if (g_unlink(compose->exteditor_file) < 0)
6638 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6639 } else if (buf[0] == '2') {
6640 g_warning("Couldn't write to file\n");
6641 } else if (buf[0] == '3') {
6642 g_warning("Pipe read failed\n");
6645 compose_set_ext_editor_sensitive(compose, TRUE);
6647 g_free(compose->exteditor_file);
6648 compose->exteditor_file = NULL;
6649 compose->exteditor_pid = -1;
6650 compose->exteditor_ch = NULL;
6651 compose->exteditor_tag = -1;
6656 static void compose_set_ext_editor_sensitive(Compose *compose,
6659 GtkItemFactory *ifactory;
6661 ifactory = gtk_item_factory_from_widget(compose->menubar);
6663 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6664 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6665 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6666 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6667 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6668 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6669 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6672 gtk_widget_set_sensitive(compose->text, sensitive);
6673 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6674 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6675 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6676 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6677 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6678 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6679 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6680 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6682 #endif /* G_OS_UNIX */
6685 * compose_undo_state_changed:
6687 * Change the sensivity of the menuentries undo and redo
6689 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6690 gint redo_state, gpointer data)
6692 GtkWidget *widget = GTK_WIDGET(data);
6693 GtkItemFactory *ifactory;
6695 g_return_if_fail(widget != NULL);
6697 ifactory = gtk_item_factory_from_widget(widget);
6699 switch (undo_state) {
6700 case UNDO_STATE_TRUE:
6701 if (!undostruct->undo_state) {
6702 undostruct->undo_state = TRUE;
6703 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6706 case UNDO_STATE_FALSE:
6707 if (undostruct->undo_state) {
6708 undostruct->undo_state = FALSE;
6709 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6712 case UNDO_STATE_UNCHANGED:
6714 case UNDO_STATE_REFRESH:
6715 menu_set_sensitive(ifactory, "/Edit/Undo",
6716 undostruct->undo_state);
6719 g_warning("Undo state not recognized");
6723 switch (redo_state) {
6724 case UNDO_STATE_TRUE:
6725 if (!undostruct->redo_state) {
6726 undostruct->redo_state = TRUE;
6727 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6730 case UNDO_STATE_FALSE:
6731 if (undostruct->redo_state) {
6732 undostruct->redo_state = FALSE;
6733 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6736 case UNDO_STATE_UNCHANGED:
6738 case UNDO_STATE_REFRESH:
6739 menu_set_sensitive(ifactory, "/Edit/Redo",
6740 undostruct->redo_state);
6743 g_warning("Redo state not recognized");
6748 /* callback functions */
6750 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6751 * includes "non-client" (windows-izm) in calculation, so this calculation
6752 * may not be accurate.
6754 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6755 GtkAllocation *allocation,
6756 GtkSHRuler *shruler)
6758 if (prefs_common.show_ruler) {
6759 gint char_width = 0, char_height = 0;
6760 gint line_width_in_chars;
6762 gtkut_get_font_size(GTK_WIDGET(widget),
6763 &char_width, &char_height);
6764 line_width_in_chars =
6765 (allocation->width - allocation->x) / char_width;
6767 /* got the maximum */
6768 gtk_ruler_set_range(GTK_RULER(shruler),
6769 0.0, line_width_in_chars, 0,
6770 /*line_width_in_chars*/ char_width);
6776 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6778 Compose *compose = (Compose *)data;
6781 gchar *folderidentifier;
6783 ac = account_find_from_id(
6784 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6785 g_return_if_fail(ac != NULL);
6787 if (ac != compose->account)
6788 compose_select_account(compose, ac, FALSE);
6790 /* Set message save folder */
6791 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6792 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6794 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6795 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6797 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6798 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6799 folderidentifier = folder_item_get_identifier(account_get_special_folder
6800 (compose->account, F_OUTBOX));
6801 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6802 g_free(folderidentifier);
6806 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6807 GtkTreeViewColumn *column, Compose *compose)
6809 compose_attach_property(compose);
6812 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6815 Compose *compose = (Compose *)data;
6816 GtkTreeSelection *attach_selection;
6817 gint attach_nr_selected;
6818 GtkItemFactory *ifactory;
6820 if (!event) return FALSE;
6822 if (event->button == 3) {
6823 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6824 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6825 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6827 if (attach_nr_selected > 0)
6829 menu_set_sensitive(ifactory, "/Remove", TRUE);
6830 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6832 menu_set_sensitive(ifactory, "/Remove", FALSE);
6833 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6836 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6837 NULL, NULL, event->button, event->time);
6844 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6847 Compose *compose = (Compose *)data;
6849 if (!event) return FALSE;
6851 switch (event->keyval) {
6853 compose_attach_remove_selected(compose);
6859 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6861 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6862 toolbar_comp_set_sensitive(compose, allow);
6863 menu_set_sensitive(ifactory, "/Message", allow);
6864 menu_set_sensitive(ifactory, "/Edit", allow);
6866 menu_set_sensitive(ifactory, "/Spelling", allow);
6868 menu_set_sensitive(ifactory, "/Options", allow);
6869 menu_set_sensitive(ifactory, "/Tools", allow);
6870 menu_set_sensitive(ifactory, "/Help", allow);
6872 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6876 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6878 Compose *compose = (Compose *)data;
6880 if (prefs_common.work_offline && !inc_offline_should_override())
6883 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6884 gtk_timeout_remove(compose->draft_timeout_tag);
6885 compose->draft_timeout_tag = -1;
6888 compose_send(compose);
6891 static void compose_send_later_cb(gpointer data, guint action,
6894 Compose *compose = (Compose *)data;
6897 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6899 compose_close(compose);
6900 else if (val == -2) {
6901 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6905 void compose_draft (gpointer data)
6907 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6910 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6912 Compose *compose = (Compose *)data;
6916 MsgFlags flag = {0, 0};
6917 static gboolean lock = FALSE;
6918 MsgInfo *newmsginfo;
6923 draft = account_get_special_folder(compose->account, F_DRAFT);
6924 g_return_if_fail(draft != NULL);
6926 if (!g_mutex_trylock(compose->mutex)) {
6927 /* we don't want to lock the mutex once it's available,
6928 * because as the only other part of compose.c locking
6929 * it is compose_close - which means once unlocked,
6930 * the compose struct will be freed */
6931 debug_print("couldn't lock mutex, probably sending\n");
6937 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6938 G_DIR_SEPARATOR, compose);
6939 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6940 FILE_OP_ERROR(tmp, "fopen");
6944 /* chmod for security */
6945 if (change_file_mode_rw(fp, tmp) < 0) {
6946 FILE_OP_ERROR(tmp, "chmod");
6947 g_warning("can't change file mode\n");
6950 /* Save draft infos */
6951 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6952 fprintf(fp, "S:%s\n", compose->account->address);
6953 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6954 gchar *savefolderid;
6956 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6957 fprintf(fp, "SCF:%s\n", savefolderid);
6958 g_free(savefolderid);
6960 if (compose->privacy_system) {
6961 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6962 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6963 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
6967 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6975 folder_item_scan(draft);
6976 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6979 if (action != COMPOSE_AUTO_SAVE)
6980 alertpanel_error(_("Could not save draft."));
6984 draft->mtime = 0; /* force updating */
6986 if (compose->mode == COMPOSE_REEDIT) {
6987 compose_remove_reedit_target(compose);
6990 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6992 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6993 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6994 if (compose_use_attach(compose))
6995 procmsg_msginfo_set_flags(newmsginfo, 0,
6996 MSG_HAS_ATTACHMENT);
6998 procmsg_msginfo_free(newmsginfo);
7001 folder_item_scan(draft);
7003 if (action == COMPOSE_QUIT_EDITING) {
7005 g_mutex_unlock(compose->mutex); /* must be done before closing */
7006 compose_close(compose);
7012 path = folder_item_fetch_msg(draft, msgnum);
7013 g_return_if_fail(path != NULL);
7014 if (g_stat(path, &s) < 0) {
7015 FILE_OP_ERROR(path, "stat");
7021 procmsg_msginfo_free(compose->targetinfo);
7022 compose->targetinfo = procmsg_msginfo_new();
7023 compose->targetinfo->msgnum = msgnum;
7024 compose->targetinfo->size = s.st_size;
7025 compose->targetinfo->mtime = s.st_mtime;
7026 compose->targetinfo->folder = draft;
7027 compose->mode = COMPOSE_REEDIT;
7029 if (action == COMPOSE_AUTO_SAVE) {
7030 compose->autosaved_draft = compose->targetinfo;
7032 compose->modified = FALSE;
7033 compose_set_title(compose);
7037 g_mutex_unlock(compose->mutex);
7040 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7042 Compose *compose = (Compose *)data;
7045 if (compose->redirect_filename != NULL)
7048 file_list = filesel_select_multiple_files_open(_("Select file"));
7053 for ( tmp = file_list; tmp; tmp = tmp->next) {
7054 gchar *file = (gchar *) tmp->data;
7055 gchar *utf8_filename = conv_filename_to_utf8(file);
7056 compose_attach_append(compose, file, utf8_filename, NULL);
7057 compose_changed_cb(NULL, compose);
7059 g_free(utf8_filename);
7061 g_list_free(file_list);
7065 static void compose_insert_file_cb(gpointer data, guint action,
7068 Compose *compose = (Compose *)data;
7071 file_list = filesel_select_multiple_files_open(_("Select file"));
7076 for ( tmp = file_list; tmp; tmp = tmp->next) {
7077 gchar *file = (gchar *) tmp->data;
7078 gchar *filedup = g_strdup(file);
7079 gchar *shortfile = g_path_get_basename(filedup);
7080 ComposeInsertResult res;
7082 res = compose_insert_file(compose, file);
7083 if (res == COMPOSE_INSERT_READ_ERROR) {
7084 alertpanel_error(_("File '%s' could not be read."), shortfile);
7085 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7086 alertpanel_error(_("File '%s' contained invalid characters\n"
7087 "for the current encoding, insertion may be incorrect."), shortfile);
7093 g_list_free(file_list);
7097 static void compose_insert_sig_cb(gpointer data, guint action,
7100 Compose *compose = (Compose *)data;
7102 compose_insert_sig(compose, FALSE);
7105 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7109 Compose *compose = (Compose *)data;
7111 gtkut_widget_get_uposition(widget, &x, &y);
7112 prefs_common.compose_x = x;
7113 prefs_common.compose_y = y;
7115 if (compose->sending)
7117 compose_close_cb(compose, 0, NULL);
7121 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7123 Compose *compose = (Compose *)data;
7127 if (compose->exteditor_tag != -1) {
7128 if (!compose_ext_editor_kill(compose))
7133 if (compose->modified) {
7134 val = alertpanel(_("Discard message"),
7135 _("This message has been modified. Discard it?"),
7136 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7139 case G_ALERTDEFAULT:
7140 if (prefs_common.autosave)
7141 compose_remove_draft(compose);
7143 case G_ALERTALTERNATE:
7144 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7151 compose_close(compose);
7154 static void compose_set_encoding_cb(gpointer data, guint action,
7157 Compose *compose = (Compose *)data;
7159 if (GTK_CHECK_MENU_ITEM(widget)->active)
7160 compose->out_encoding = (CharSet)action;
7163 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7165 Compose *compose = (Compose *)data;
7167 addressbook_open(compose);
7170 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7172 Compose *compose = (Compose *)data;
7177 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7178 g_return_if_fail(tmpl != NULL);
7180 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7182 val = alertpanel(_("Apply template"), msg,
7183 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7186 if (val == G_ALERTDEFAULT)
7187 compose_template_apply(compose, tmpl, TRUE);
7188 else if (val == G_ALERTALTERNATE)
7189 compose_template_apply(compose, tmpl, FALSE);
7192 static void compose_ext_editor_cb(gpointer data, guint action,
7195 Compose *compose = (Compose *)data;
7197 compose_exec_ext_editor(compose);
7200 static void compose_undo_cb(Compose *compose)
7202 gboolean prev_autowrap = compose->autowrap;
7204 compose->autowrap = FALSE;
7205 undo_undo(compose->undostruct);
7206 compose->autowrap = prev_autowrap;
7209 static void compose_redo_cb(Compose *compose)
7211 gboolean prev_autowrap = compose->autowrap;
7213 compose->autowrap = FALSE;
7214 undo_redo(compose->undostruct);
7215 compose->autowrap = prev_autowrap;
7218 static void entry_cut_clipboard(GtkWidget *entry)
7220 if (GTK_IS_EDITABLE(entry))
7221 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7222 else if (GTK_IS_TEXT_VIEW(entry))
7223 gtk_text_buffer_cut_clipboard(
7224 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7225 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7229 static void entry_copy_clipboard(GtkWidget *entry)
7231 if (GTK_IS_EDITABLE(entry))
7232 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7233 else if (GTK_IS_TEXT_VIEW(entry))
7234 gtk_text_buffer_copy_clipboard(
7235 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7236 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7239 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7240 gboolean wrap, GdkAtom clip)
7242 if (GTK_IS_TEXT_VIEW(entry)) {
7243 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7244 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7245 GtkTextIter start_iter, end_iter;
7248 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7250 if (contents == NULL)
7253 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7254 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7256 start = gtk_text_iter_get_offset(&start_iter);
7258 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7261 end = start + strlen(contents);
7262 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7263 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7264 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7265 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7266 mark_start = gtk_text_buffer_get_insert(buffer);
7267 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7268 gtk_text_iter_backward_char(&start_iter);
7269 compose_beautify_paragraph(compose, &start_iter, TRUE);
7272 } else if (GTK_IS_EDITABLE(entry))
7273 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7277 static void entry_allsel(GtkWidget *entry)
7279 if (GTK_IS_EDITABLE(entry))
7280 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7281 else if (GTK_IS_TEXT_VIEW(entry)) {
7282 GtkTextIter startiter, enditer;
7283 GtkTextBuffer *textbuf;
7285 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7286 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7287 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7289 gtk_text_buffer_move_mark_by_name(textbuf,
7290 "selection_bound", &startiter);
7291 gtk_text_buffer_move_mark_by_name(textbuf,
7292 "insert", &enditer);
7296 static void compose_cut_cb(Compose *compose)
7298 if (compose->focused_editable &&
7299 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7300 entry_cut_clipboard(compose->focused_editable);
7303 static void compose_copy_cb(Compose *compose)
7305 if (compose->focused_editable &&
7306 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7307 entry_copy_clipboard(compose->focused_editable);
7310 static void compose_paste_cb(Compose *compose)
7313 GtkTextBuffer *buffer;
7315 if (compose->focused_editable &&
7316 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7317 entry_paste_clipboard(compose, compose->focused_editable,
7318 prefs_common.linewrap_pastes,
7319 GDK_SELECTION_CLIPBOARD);
7323 static void compose_paste_as_quote_cb(Compose *compose)
7325 gint wrap_quote = prefs_common.linewrap_quote;
7326 if (compose->focused_editable &&
7327 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7328 /* let text_insert() (called directly or at a later time
7329 * after the gtk_editable_paste_clipboard) know that
7330 * text is to be inserted as a quotation. implemented
7331 * by using a simple refcount... */
7332 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7333 G_OBJECT(compose->focused_editable),
7334 "paste_as_quotation"));
7335 g_object_set_data(G_OBJECT(compose->focused_editable),
7336 "paste_as_quotation",
7337 GINT_TO_POINTER(paste_as_quotation + 1));
7338 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7339 entry_paste_clipboard(compose, compose->focused_editable,
7340 prefs_common.linewrap_pastes,
7341 GDK_SELECTION_CLIPBOARD);
7342 prefs_common.linewrap_quote = wrap_quote;
7346 static void compose_paste_no_wrap_cb(Compose *compose)
7349 GtkTextBuffer *buffer;
7351 if (compose->focused_editable &&
7352 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7353 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7354 GDK_SELECTION_CLIPBOARD);
7358 static void compose_paste_wrap_cb(Compose *compose)
7361 GtkTextBuffer *buffer;
7363 if (compose->focused_editable &&
7364 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7365 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7366 GDK_SELECTION_CLIPBOARD);
7370 static void compose_allsel_cb(Compose *compose)
7372 if (compose->focused_editable &&
7373 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7374 entry_allsel(compose->focused_editable);
7377 static void textview_move_beginning_of_line (GtkTextView *text)
7379 GtkTextBuffer *buffer;
7383 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7385 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7386 mark = gtk_text_buffer_get_insert(buffer);
7387 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7388 gtk_text_iter_set_line_offset(&ins, 0);
7389 gtk_text_buffer_place_cursor(buffer, &ins);
7392 static void textview_move_forward_character (GtkTextView *text)
7394 GtkTextBuffer *buffer;
7398 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7400 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7401 mark = gtk_text_buffer_get_insert(buffer);
7402 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7403 if (gtk_text_iter_forward_cursor_position(&ins))
7404 gtk_text_buffer_place_cursor(buffer, &ins);
7407 static void textview_move_backward_character (GtkTextView *text)
7409 GtkTextBuffer *buffer;
7413 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7415 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7416 mark = gtk_text_buffer_get_insert(buffer);
7417 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7418 if (gtk_text_iter_backward_cursor_position(&ins))
7419 gtk_text_buffer_place_cursor(buffer, &ins);
7422 static void textview_move_forward_word (GtkTextView *text)
7424 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 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7435 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7436 gtk_text_iter_backward_word_start(&ins);
7437 gtk_text_buffer_place_cursor(buffer, &ins);
7441 static void textview_move_backward_word (GtkTextView *text)
7443 GtkTextBuffer *buffer;
7448 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7450 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7451 mark = gtk_text_buffer_get_insert(buffer);
7452 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7453 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7454 if (gtk_text_iter_backward_word_starts(&ins, 1))
7455 gtk_text_buffer_place_cursor(buffer, &ins);
7458 static void textview_move_end_of_line (GtkTextView *text)
7460 GtkTextBuffer *buffer;
7464 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7466 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7467 mark = gtk_text_buffer_get_insert(buffer);
7468 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7469 if (gtk_text_iter_forward_to_line_end(&ins))
7470 gtk_text_buffer_place_cursor(buffer, &ins);
7473 static void textview_move_next_line (GtkTextView *text)
7475 GtkTextBuffer *buffer;
7480 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7482 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7483 mark = gtk_text_buffer_get_insert(buffer);
7484 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7485 offset = gtk_text_iter_get_line_offset(&ins);
7486 if (gtk_text_iter_forward_line(&ins)) {
7487 gtk_text_iter_set_line_offset(&ins, offset);
7488 gtk_text_buffer_place_cursor(buffer, &ins);
7492 static void textview_move_previous_line (GtkTextView *text)
7494 GtkTextBuffer *buffer;
7499 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7501 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7502 mark = gtk_text_buffer_get_insert(buffer);
7503 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7504 offset = gtk_text_iter_get_line_offset(&ins);
7505 if (gtk_text_iter_backward_line(&ins)) {
7506 gtk_text_iter_set_line_offset(&ins, offset);
7507 gtk_text_buffer_place_cursor(buffer, &ins);
7511 static void textview_delete_forward_character (GtkTextView *text)
7513 GtkTextBuffer *buffer;
7515 GtkTextIter ins, end_iter;
7517 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7519 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7520 mark = gtk_text_buffer_get_insert(buffer);
7521 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7523 if (gtk_text_iter_forward_char(&end_iter)) {
7524 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7528 static void textview_delete_backward_character (GtkTextView *text)
7530 GtkTextBuffer *buffer;
7532 GtkTextIter ins, end_iter;
7534 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7536 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7537 mark = gtk_text_buffer_get_insert(buffer);
7538 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7540 if (gtk_text_iter_backward_char(&end_iter)) {
7541 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7545 static void textview_delete_forward_word (GtkTextView *text)
7547 GtkTextBuffer *buffer;
7549 GtkTextIter ins, end_iter;
7551 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7553 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7554 mark = gtk_text_buffer_get_insert(buffer);
7555 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7557 if (gtk_text_iter_forward_word_end(&end_iter)) {
7558 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7562 static void textview_delete_backward_word (GtkTextView *text)
7564 GtkTextBuffer *buffer;
7566 GtkTextIter ins, end_iter;
7568 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7570 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7571 mark = gtk_text_buffer_get_insert(buffer);
7572 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7574 if (gtk_text_iter_backward_word_start(&end_iter)) {
7575 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7579 static void textview_delete_line (GtkTextView *text)
7581 GtkTextBuffer *buffer;
7583 GtkTextIter ins, start_iter, end_iter;
7586 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7588 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7589 mark = gtk_text_buffer_get_insert(buffer);
7590 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7593 gtk_text_iter_set_line_offset(&start_iter, 0);
7596 if (gtk_text_iter_ends_line(&end_iter))
7597 found = gtk_text_iter_forward_char(&end_iter);
7599 found = gtk_text_iter_forward_to_line_end(&end_iter);
7602 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7605 static void textview_delete_to_line_end (GtkTextView *text)
7607 GtkTextBuffer *buffer;
7609 GtkTextIter ins, end_iter;
7612 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7614 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7615 mark = gtk_text_buffer_get_insert(buffer);
7616 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7618 if (gtk_text_iter_ends_line(&end_iter))
7619 found = gtk_text_iter_forward_char(&end_iter);
7621 found = gtk_text_iter_forward_to_line_end(&end_iter);
7623 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7626 static void compose_advanced_action_cb(Compose *compose,
7627 ComposeCallAdvancedAction action)
7629 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7631 void (*do_action) (GtkTextView *text);
7632 } action_table[] = {
7633 {textview_move_beginning_of_line},
7634 {textview_move_forward_character},
7635 {textview_move_backward_character},
7636 {textview_move_forward_word},
7637 {textview_move_backward_word},
7638 {textview_move_end_of_line},
7639 {textview_move_next_line},
7640 {textview_move_previous_line},
7641 {textview_delete_forward_character},
7642 {textview_delete_backward_character},
7643 {textview_delete_forward_word},
7644 {textview_delete_backward_word},
7645 {textview_delete_line},
7646 {NULL}, /* gtk_stext_delete_line_n */
7647 {textview_delete_to_line_end}
7650 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7652 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7653 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7654 if (action_table[action].do_action)
7655 action_table[action].do_action(text);
7657 g_warning("Not implemented yet.");
7661 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7665 if (GTK_IS_EDITABLE(widget)) {
7666 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7667 gtk_editable_set_position(GTK_EDITABLE(widget),
7670 if (widget->parent && widget->parent->parent
7671 && widget->parent->parent->parent) {
7672 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7673 gint y = widget->allocation.y;
7674 gint height = widget->allocation.height;
7675 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7676 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7678 if (y < (int)shown->value) {
7679 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7681 if (y + height > (int)shown->value + (int)shown->page_size) {
7682 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7683 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7684 y + height - (int)shown->page_size - 1);
7686 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7687 (int)shown->upper - (int)shown->page_size - 1);
7694 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7695 compose->focused_editable = widget;
7698 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7700 compose->modified = TRUE;
7701 compose_set_title(compose);
7704 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7706 Compose *compose = (Compose *)data;
7709 compose_wrap_all_full(compose, TRUE);
7711 compose_beautify_paragraph(compose, NULL, TRUE);
7714 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7717 Compose *compose = (Compose *)data;
7718 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7719 if (compose->autowrap)
7720 compose_wrap_all_full(compose, TRUE);
7723 static void compose_toggle_sign_cb(gpointer data, guint action,
7726 Compose *compose = (Compose *)data;
7728 if (GTK_CHECK_MENU_ITEM(widget)->active)
7729 compose->use_signing = TRUE;
7731 compose->use_signing = FALSE;
7734 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7737 Compose *compose = (Compose *)data;
7739 if (GTK_CHECK_MENU_ITEM(widget)->active)
7740 compose->use_encryption = TRUE;
7742 compose->use_encryption = FALSE;
7745 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7747 g_free(compose->privacy_system);
7749 compose->privacy_system = g_strdup(account->default_privacy_system);
7750 compose_update_privacy_system_menu_item(compose, warn);
7753 static void compose_toggle_ruler_cb(gpointer data, guint action,
7756 Compose *compose = (Compose *)data;
7758 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7759 gtk_widget_show(compose->ruler_hbox);
7760 prefs_common.show_ruler = TRUE;
7762 gtk_widget_hide(compose->ruler_hbox);
7763 gtk_widget_queue_resize(compose->edit_vbox);
7764 prefs_common.show_ruler = FALSE;
7768 static void compose_attach_drag_received_cb (GtkWidget *widget,
7769 GdkDragContext *drag_context,
7772 GtkSelectionData *data,
7777 Compose *compose = (Compose *)user_data;
7780 if (gdk_atom_name(data->type) &&
7781 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7782 list = uri_list_extract_filenames((const gchar *)data->data);
7783 for (tmp = list; tmp != NULL; tmp = tmp->next)
7784 compose_attach_append
7785 (compose, (const gchar *)tmp->data,
7786 (const gchar *)tmp->data, NULL);
7787 if (list) compose_changed_cb(NULL, compose);
7788 list_free_strings(list);
7790 } else if (gdk_atom_name(data->type) &&
7791 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7792 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7793 /* comes from our summaryview */
7794 SummaryView * summaryview = NULL;
7795 GSList * list = NULL, *cur = NULL;
7797 if (mainwindow_get_mainwindow())
7798 summaryview = mainwindow_get_mainwindow()->summaryview;
7801 list = summary_get_selected_msg_list(summaryview);
7803 for (cur = list; cur; cur = cur->next) {
7804 MsgInfo *msginfo = (MsgInfo *)cur->data;
7807 file = procmsg_get_message_file_full(msginfo,
7810 compose_attach_append(compose, (const gchar *)file,
7811 (const gchar *)file, "message/rfc822");
7819 static gboolean compose_drag_drop(GtkWidget *widget,
7820 GdkDragContext *drag_context,
7822 guint time, gpointer user_data)
7824 /* not handling this signal makes compose_insert_drag_received_cb
7829 static void compose_insert_drag_received_cb (GtkWidget *widget,
7830 GdkDragContext *drag_context,
7833 GtkSelectionData *data,
7838 Compose *compose = (Compose *)user_data;
7841 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7843 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7844 list = uri_list_extract_filenames((const gchar *)data->data);
7845 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7846 compose_insert_file(compose, (const gchar *)tmp->data);
7848 list_free_strings(list);
7850 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7853 gchar *tmpfile = get_tmp_file();
7854 str_write_to_file((const gchar *)data->data, tmpfile);
7855 compose_insert_file(compose, tmpfile);
7858 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7861 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7864 static void compose_header_drag_received_cb (GtkWidget *widget,
7865 GdkDragContext *drag_context,
7868 GtkSelectionData *data,
7873 GtkEditable *entry = (GtkEditable *)user_data;
7874 gchar *email = (gchar *)data->data;
7876 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7879 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7880 gchar *decoded=g_new(gchar, strlen(email));
7883 email += strlen("mailto:");
7884 decode_uri(decoded, email); /* will fit */
7885 gtk_editable_delete_text(entry, 0, -1);
7886 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7887 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7891 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7894 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7897 Compose *compose = (Compose *)data;
7899 if (GTK_CHECK_MENU_ITEM(widget)->active)
7900 compose->return_receipt = TRUE;
7902 compose->return_receipt = FALSE;
7905 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7908 Compose *compose = (Compose *)data;
7910 if (GTK_CHECK_MENU_ITEM(widget)->active)
7911 compose->remove_references = TRUE;
7913 compose->remove_references = FALSE;
7916 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7918 ComposeHeaderEntry *headerentry)
7920 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7921 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7922 !(event->state & GDK_MODIFIER_MASK) &&
7923 (event->keyval == GDK_BackSpace) &&
7924 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7925 gtk_container_remove
7926 (GTK_CONTAINER(headerentry->compose->header_table),
7927 headerentry->combo);
7928 gtk_container_remove
7929 (GTK_CONTAINER(headerentry->compose->header_table),
7930 headerentry->entry);
7931 headerentry->compose->header_list =
7932 g_slist_remove(headerentry->compose->header_list,
7934 g_free(headerentry);
7935 } else if (event->keyval == GDK_Tab) {
7936 if (headerentry->compose->header_last == headerentry) {
7937 /* Override default next focus, and give it to subject_entry
7938 * instead of notebook tabs
7940 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
7941 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7948 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
7949 ComposeHeaderEntry *headerentry)
7951 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7952 headerentry->compose->header_list =
7953 g_slist_append(headerentry->compose->header_list,
7956 compose_create_header_entry(headerentry->compose);
7957 g_signal_handlers_disconnect_matched
7958 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
7959 0, 0, NULL, NULL, headerentry);
7961 /* Automatically scroll down */
7962 compose_show_first_last_header(headerentry->compose, FALSE);
7968 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7970 GtkAdjustment *vadj;
7972 g_return_if_fail(compose);
7973 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7974 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7976 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7977 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7980 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
7981 const gchar *text, gint len, Compose *compose)
7983 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
7984 (G_OBJECT(compose->text), "paste_as_quotation"));
7987 g_return_if_fail(text != NULL);
7989 g_signal_handlers_block_by_func(G_OBJECT(buffer),
7990 G_CALLBACK(text_inserted),
7992 if (paste_as_quotation) {
7999 new_text = g_strndup(text, len);
8000 if (prefs_common.quotemark && *prefs_common.quotemark)
8001 qmark = prefs_common.quotemark;
8005 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8006 gtk_text_buffer_place_cursor(buffer, iter);
8008 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
8010 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8011 GINT_TO_POINTER(paste_as_quotation - 1));
8013 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8015 gtk_text_buffer_insert(buffer, iter, text, len);
8017 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8019 compose_beautify_paragraph(compose, iter, FALSE);
8021 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8022 gtk_text_buffer_delete_mark(buffer, mark);
8024 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8025 G_CALLBACK(text_inserted),
8027 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8029 if (prefs_common.autosave &&
8030 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8031 compose->draft_timeout_tag = gtk_timeout_add
8032 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8034 static gint compose_defer_auto_save_draft(Compose *compose)
8036 compose->draft_timeout_tag = -1;
8037 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8042 static void compose_check_all(Compose *compose)
8044 if (compose->gtkaspell)
8045 gtkaspell_check_all(compose->gtkaspell);
8048 static void compose_highlight_all(Compose *compose)
8050 if (compose->gtkaspell)
8051 gtkaspell_highlight_all(compose->gtkaspell);
8054 static void compose_check_backwards(Compose *compose)
8056 if (compose->gtkaspell)
8057 gtkaspell_check_backwards(compose->gtkaspell);
8059 GtkItemFactory *ifactory;
8060 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8061 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8062 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8066 static void compose_check_forwards_go(Compose *compose)
8068 if (compose->gtkaspell)
8069 gtkaspell_check_forwards_go(compose->gtkaspell);
8071 GtkItemFactory *ifactory;
8072 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8073 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8074 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8080 *\brief Guess originating forward account from MsgInfo and several
8081 * "common preference" settings. Return NULL if no guess.
8083 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8085 PrefsAccount *account = NULL;
8087 g_return_val_if_fail(msginfo, NULL);
8088 g_return_val_if_fail(msginfo->folder, NULL);
8089 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8091 if (msginfo->folder->prefs->enable_default_account)
8092 account = account_find_from_id(msginfo->folder->prefs->default_account);
8095 account = msginfo->folder->folder->account;
8097 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8099 Xstrdup_a(to, msginfo->to, return NULL);
8100 extract_address(to);
8101 account = account_find_from_address(to);
8104 if (!account && prefs_common.forward_account_autosel) {
8106 if (!procheader_get_header_from_msginfo
8107 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8108 extract_address(cc);
8109 account = account_find_from_address(cc);
8116 static gboolean compose_close(Compose *compose)
8120 if (!g_mutex_trylock(compose->mutex)) {
8121 /* we have to wait for the (possibly deferred by auto-save)
8122 * drafting to be done, before destroying the compose under
8124 debug_print("waiting for drafting to finish...\n");
8125 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8128 g_return_val_if_fail(compose, FALSE);
8129 gtkut_widget_get_uposition(compose->window, &x, &y);
8130 prefs_common.compose_x = x;
8131 prefs_common.compose_y = y;
8132 g_mutex_unlock(compose->mutex);
8133 compose_destroy(compose);
8138 * Add entry field for each address in list.
8139 * \param compose E-Mail composition object.
8140 * \param listAddress List of (formatted) E-Mail addresses.
8142 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8147 addr = ( gchar * ) node->data;
8148 compose_entry_append( compose, addr, COMPOSE_TO );
8149 node = g_list_next( node );
8153 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8157 GSList *new_msglist = NULL;
8158 MsgInfo *tmp_msginfo = NULL;
8159 gboolean originally_enc = FALSE;
8160 Compose *compose = NULL;
8162 g_return_if_fail(msgview != NULL);
8164 g_return_if_fail(msginfo_list != NULL);
8166 if (g_slist_length(msginfo_list) == 1) {
8167 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8168 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8170 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8171 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8172 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8173 orig_msginfo, mimeinfo);
8174 if (tmp_msginfo != NULL) {
8175 new_msglist = g_slist_append(NULL, tmp_msginfo);
8176 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8177 originally_enc = TRUE;
8183 body = messageview_get_selection(msgview);
8186 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8187 procmsg_msginfo_free(tmp_msginfo);
8188 g_slist_free(new_msglist);
8190 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8192 if (originally_enc) {
8193 compose_force_encryption(compose, compose->account, FALSE);