2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
134 #define N_ATTACH_COLS (N_COL_COLUMNS)
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
153 } ComposeCallAdvancedAction;
157 PRIORITY_HIGHEST = 1,
166 COMPOSE_INSERT_SUCCESS,
167 COMPOSE_INSERT_READ_ERROR,
168 COMPOSE_INSERT_INVALID_CHARACTER,
169 COMPOSE_INSERT_NO_FILE
170 } ComposeInsertResult;
174 COMPOSE_QUIT_EDITING,
175 COMPOSE_KEEP_EDITING,
177 } ComposeDraftAction;
181 COMPOSE_WRITE_FOR_SEND,
182 COMPOSE_WRITE_FOR_STORE
185 #define B64_LINE_SIZE 57
186 #define B64_BUFFSIZE 77
188 #define MAX_REFERENCES_LEN 999
190 static GList *compose_list = NULL;
192 Compose *compose_generic_new (PrefsAccount *account,
195 GPtrArray *attach_files,
196 GList *listAddress );
198 static Compose *compose_create (PrefsAccount *account,
202 static GtkWidget *compose_account_option_menu_create
204 static void compose_set_out_encoding (Compose *compose);
205 static void compose_set_template_menu (Compose *compose);
206 static void compose_template_apply (Compose *compose,
209 static void compose_destroy (Compose *compose);
211 static void compose_entries_set (Compose *compose,
212 const gchar *mailto);
213 static gint compose_parse_header (Compose *compose,
215 static gchar *compose_parse_references (const gchar *ref,
218 static gchar *compose_quote_fmt (Compose *compose,
225 static void compose_reply_set_entry (Compose *compose,
231 followup_and_reply_to);
232 static void compose_reedit_set_entry (Compose *compose,
235 static void compose_insert_sig (Compose *compose,
237 static gchar *compose_get_signature_str (Compose *compose);
238 static ComposeInsertResult compose_insert_file (Compose *compose,
241 static void compose_attach_append (Compose *compose,
244 const gchar *content_type);
245 static void compose_attach_parts (Compose *compose,
248 static void compose_beautify_paragraph (Compose *compose,
249 GtkTextIter *par_iter,
251 static void compose_wrap_all (Compose *compose);
252 static void compose_wrap_all_full (Compose *compose,
255 static void compose_set_title (Compose *compose);
256 static void compose_select_account (Compose *compose,
257 PrefsAccount *account,
260 static PrefsAccount *compose_current_mail_account(void);
261 /* static gint compose_send (Compose *compose); */
262 static gboolean compose_check_for_valid_recipient
264 static gboolean compose_check_entries (Compose *compose,
265 gboolean check_subject);
266 static gint compose_write_to_file (Compose *compose,
269 static gint compose_write_body_to_file (Compose *compose,
271 static gint compose_remove_reedit_target (Compose *compose,
273 void compose_remove_draft (Compose *compose);
274 static gint compose_queue_sub (Compose *compose,
278 gboolean check_subject,
279 gboolean remove_reedit_target);
280 static void compose_add_attachments (Compose *compose,
282 static gchar *compose_get_header (Compose *compose);
284 static void compose_convert_header (Compose *compose,
289 gboolean addr_field);
291 static void compose_attach_info_free (AttachInfo *ainfo);
292 static void compose_attach_remove_selected (Compose *compose);
294 static void compose_attach_property (Compose *compose);
295 static void compose_attach_property_create (gboolean *cancelled);
296 static void attach_property_ok (GtkWidget *widget,
297 gboolean *cancelled);
298 static void attach_property_cancel (GtkWidget *widget,
299 gboolean *cancelled);
300 static gint attach_property_delete_event (GtkWidget *widget,
302 gboolean *cancelled);
303 static gboolean attach_property_key_pressed (GtkWidget *widget,
305 gboolean *cancelled);
307 static void compose_exec_ext_editor (Compose *compose);
309 static gint compose_exec_ext_editor_real (const gchar *file);
310 static gboolean compose_ext_editor_kill (Compose *compose);
311 static gboolean compose_input_cb (GIOChannel *source,
312 GIOCondition condition,
314 static void compose_set_ext_editor_sensitive (Compose *compose,
316 #endif /* G_OS_UNIX */
318 static void compose_undo_state_changed (UndoMain *undostruct,
323 static void compose_create_header_entry (Compose *compose);
324 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
325 static void compose_update_priority_menu_item(Compose * compose);
327 static void compose_add_field_list ( Compose *compose,
328 GList *listAddress );
330 /* callback functions */
332 static gboolean compose_edit_size_alloc (GtkEditable *widget,
333 GtkAllocation *allocation,
334 GtkSHRuler *shruler);
335 static void account_activated (GtkMenuItem *menuitem,
337 static void attach_selected (GtkTreeView *tree_view,
338 GtkTreePath *tree_path,
339 GtkTreeViewColumn *column,
341 static gboolean attach_button_pressed (GtkWidget *widget,
342 GdkEventButton *event,
344 static gboolean attach_key_pressed (GtkWidget *widget,
348 static void compose_send_cb (gpointer data,
351 static void compose_send_later_cb (gpointer data,
355 static void compose_draft_cb (gpointer data,
359 static void compose_attach_cb (gpointer data,
362 static void compose_insert_file_cb (gpointer data,
365 static void compose_insert_sig_cb (gpointer data,
369 static void compose_close_cb (gpointer data,
373 static void compose_set_encoding_cb (gpointer data,
377 static void compose_address_cb (gpointer data,
380 static void compose_template_activate_cb(GtkWidget *widget,
383 static void compose_ext_editor_cb (gpointer data,
387 static gint compose_delete_cb (GtkWidget *widget,
391 static void compose_undo_cb (Compose *compose);
392 static void compose_redo_cb (Compose *compose);
393 static void compose_cut_cb (Compose *compose);
394 static void compose_copy_cb (Compose *compose);
395 static void compose_paste_cb (Compose *compose);
396 static void compose_paste_as_quote_cb (Compose *compose);
397 static void compose_paste_no_wrap_cb (Compose *compose);
398 static void compose_paste_wrap_cb (Compose *compose);
399 static void compose_allsel_cb (Compose *compose);
401 static void compose_advanced_action_cb (Compose *compose,
402 ComposeCallAdvancedAction action);
404 static void compose_grab_focus_cb (GtkWidget *widget,
407 static void compose_changed_cb (GtkTextBuffer *textbuf,
410 static void compose_wrap_cb (gpointer data,
413 static void compose_find_cb (gpointer data,
416 static void compose_toggle_autowrap_cb (gpointer data,
420 static void compose_toggle_ruler_cb (gpointer data,
423 static void compose_toggle_sign_cb (gpointer data,
426 static void compose_toggle_encrypt_cb (gpointer data,
429 static void compose_set_privacy_system_cb(GtkWidget *widget,
431 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
432 static void activate_privacy_system (Compose *compose,
433 PrefsAccount *account,
435 static void compose_use_signing(Compose *compose, gboolean use_signing);
436 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
437 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
439 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
441 static void compose_set_priority_cb (gpointer data,
445 static void compose_attach_drag_received_cb (GtkWidget *widget,
446 GdkDragContext *drag_context,
449 GtkSelectionData *data,
453 static void compose_insert_drag_received_cb (GtkWidget *widget,
454 GdkDragContext *drag_context,
457 GtkSelectionData *data,
461 static void compose_header_drag_received_cb (GtkWidget *widget,
462 GdkDragContext *drag_context,
465 GtkSelectionData *data,
470 static gboolean compose_drag_drop (GtkWidget *widget,
471 GdkDragContext *drag_context,
473 guint time, gpointer user_data);
475 static void text_inserted (GtkTextBuffer *buffer,
480 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
481 gboolean to_all, gboolean to_ml,
483 gboolean followup_and_reply_to,
486 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
487 ComposeHeaderEntry *headerentry);
488 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
490 ComposeHeaderEntry *headerentry);
492 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
494 static void compose_allow_user_actions (Compose *compose, gboolean allow);
497 static void compose_check_all (Compose *compose);
498 static void compose_highlight_all (Compose *compose);
499 static void compose_check_backwards (Compose *compose);
500 static void compose_check_forwards_go (Compose *compose);
503 static gint compose_defer_auto_save_draft (Compose *compose);
504 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
506 static GtkItemFactoryEntry compose_popup_entries[] =
508 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
509 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
510 {N_("/---"), NULL, NULL, 0, "<Separator>"},
511 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
514 static GtkItemFactoryEntry compose_entries[] =
516 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
517 {N_("/_Message/_Send"), "<control>Return",
518 compose_send_cb, 0, NULL},
519 {N_("/_Message/Send _later"), "<shift><control>S",
520 compose_send_later_cb, 0, NULL},
521 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
522 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
523 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
524 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
525 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_Message/_Save"),
527 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
528 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
531 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
532 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
533 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
534 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
535 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
536 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
537 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
538 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
539 {N_("/_Edit/Special paste/as _quotation"),
540 NULL, compose_paste_as_quote_cb, 0, NULL},
541 {N_("/_Edit/Special paste/_wrapped"),
542 NULL, compose_paste_wrap_cb, 0, NULL},
543 {N_("/_Edit/Special paste/_unwrapped"),
544 NULL, compose_paste_no_wrap_cb, 0, NULL},
545 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
546 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
547 {N_("/_Edit/A_dvanced/Move a character backward"),
549 compose_advanced_action_cb,
550 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
552 {N_("/_Edit/A_dvanced/Move a character forward"),
554 compose_advanced_action_cb,
555 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
557 {N_("/_Edit/A_dvanced/Move a word backward"),
559 compose_advanced_action_cb,
560 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
562 {N_("/_Edit/A_dvanced/Move a word forward"),
564 compose_advanced_action_cb,
565 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
567 {N_("/_Edit/A_dvanced/Move to beginning of line"),
568 NULL, /* "<control>A" */
569 compose_advanced_action_cb,
570 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
572 {N_("/_Edit/A_dvanced/Move to end of line"),
574 compose_advanced_action_cb,
575 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
577 {N_("/_Edit/A_dvanced/Move to previous line"),
579 compose_advanced_action_cb,
580 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
582 {N_("/_Edit/A_dvanced/Move to next line"),
584 compose_advanced_action_cb,
585 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
587 {N_("/_Edit/A_dvanced/Delete a character backward"),
589 compose_advanced_action_cb,
590 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
592 {N_("/_Edit/A_dvanced/Delete a character forward"),
594 compose_advanced_action_cb,
595 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
597 {N_("/_Edit/A_dvanced/Delete a word backward"),
598 NULL, /* "<control>W" */
599 compose_advanced_action_cb,
600 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
602 {N_("/_Edit/A_dvanced/Delete a word forward"),
603 NULL, /* "<alt>D", */
604 compose_advanced_action_cb,
605 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
607 {N_("/_Edit/A_dvanced/Delete line"),
609 compose_advanced_action_cb,
610 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
612 {N_("/_Edit/A_dvanced/Delete entire line"),
614 compose_advanced_action_cb,
615 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
617 {N_("/_Edit/A_dvanced/Delete to end of line"),
619 compose_advanced_action_cb,
620 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
622 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
624 "<control>F", compose_find_cb, 0, NULL},
625 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
626 {N_("/_Edit/_Wrap current paragraph"),
627 "<control>L", compose_wrap_cb, 0, NULL},
628 {N_("/_Edit/Wrap all long _lines"),
629 "<control><alt>L", compose_wrap_cb, 1, NULL},
630 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
631 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
632 {N_("/_Edit/Edit with e_xternal editor"),
633 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
635 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
636 {N_("/_Spelling/_Check all or check selection"),
637 NULL, compose_check_all, 0, NULL},
638 {N_("/_Spelling/_Highlight all misspelled words"),
639 NULL, compose_highlight_all, 0, NULL},
640 {N_("/_Spelling/Check _backwards misspelled word"),
641 NULL, compose_check_backwards , 0, NULL},
642 {N_("/_Spelling/_Forward to next misspelled word"),
643 NULL, compose_check_forwards_go, 0, NULL},
644 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Spelling/Options"),
646 NULL, NULL, 0, "<Branch>"},
648 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
649 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
650 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
651 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
652 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
653 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
655 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
656 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
657 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
658 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
660 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
661 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
662 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
664 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
666 #define ENC_ACTION(action) \
667 NULL, compose_set_encoding_cb, action, \
668 "/Options/Character encoding/Automatic"
670 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
671 {N_("/_Options/Character _encoding/_Automatic"),
672 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
673 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
675 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
676 ENC_ACTION(C_US_ASCII)},
677 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
678 ENC_ACTION(C_UTF_8)},
679 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
681 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
682 ENC_ACTION(C_ISO_8859_1)},
683 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
684 ENC_ACTION(C_ISO_8859_15)},
685 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
686 ENC_ACTION(C_WINDOWS_1252)},
687 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
689 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
690 ENC_ACTION(C_ISO_8859_2)},
691 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
693 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
694 ENC_ACTION(C_ISO_8859_13)},
695 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
696 ENC_ACTION(C_ISO_8859_4)},
697 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
699 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
700 ENC_ACTION(C_ISO_8859_7)},
701 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
703 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
704 ENC_ACTION(C_ISO_8859_8)},
705 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
706 ENC_ACTION(C_WINDOWS_1255)},
707 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
709 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
710 ENC_ACTION(C_ISO_8859_6)},
711 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
712 ENC_ACTION(C_CP1256)},
713 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
715 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
716 ENC_ACTION(C_ISO_8859_9)},
717 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
719 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
720 ENC_ACTION(C_ISO_8859_5)},
721 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
722 ENC_ACTION(C_KOI8_R)},
723 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
724 ENC_ACTION(C_KOI8_U)},
725 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
726 ENC_ACTION(C_WINDOWS_1251)},
727 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
729 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
730 ENC_ACTION(C_ISO_2022_JP)},
731 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
733 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
734 ENC_ACTION(C_GB2312)},
735 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
737 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
739 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
740 ENC_ACTION(C_EUC_TW)},
741 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
743 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
744 ENC_ACTION(C_EUC_KR)},
745 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
747 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
748 ENC_ACTION(C_TIS_620)},
749 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
750 ENC_ACTION(C_WINDOWS_874)},
752 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
753 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
754 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
755 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
756 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
757 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
761 static GtkTargetEntry compose_mime_types[] =
763 {"text/uri-list", 0, 0},
764 {"text/plain", 0, 0},
768 static gboolean compose_put_existing_to_front(MsgInfo *info)
770 GList *compose_list = compose_get_compose_list();
774 for (elem = compose_list; elem != NULL && elem->data != NULL;
776 Compose *c = (Compose*)elem->data;
778 if (!c->targetinfo || !c->targetinfo->msgid ||
782 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
783 gtkut_window_popup(c->window);
791 static GdkColor quote_color1 =
792 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
793 static GdkColor quote_color2 =
794 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
795 static GdkColor quote_color3 =
796 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
798 static GdkColor quote_bgcolor1 =
799 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
800 static GdkColor quote_bgcolor2 =
801 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
802 static GdkColor quote_bgcolor3 =
803 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
805 static GdkColor signature_color = {
812 static GdkColor uri_color = {
819 static void compose_create_tags(GtkTextView *text, Compose *compose)
821 GtkTextBuffer *buffer;
822 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
828 buffer = gtk_text_view_get_buffer(text);
830 if (prefs_common.enable_color) {
831 /* grab the quote colors, converting from an int to a GdkColor */
832 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
834 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
836 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
838 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
840 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
842 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
844 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
846 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
849 signature_color = quote_color1 = quote_color2 = quote_color3 =
850 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
853 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
854 gtk_text_buffer_create_tag(buffer, "quote0",
855 "foreground-gdk", "e_color1,
856 "paragraph-background-gdk", "e_bgcolor1,
858 gtk_text_buffer_create_tag(buffer, "quote1",
859 "foreground-gdk", "e_color2,
860 "paragraph-background-gdk", "e_bgcolor2,
862 gtk_text_buffer_create_tag(buffer, "quote2",
863 "foreground-gdk", "e_color3,
864 "paragraph-background-gdk", "e_bgcolor3,
867 gtk_text_buffer_create_tag(buffer, "quote0",
868 "foreground-gdk", "e_color1,
870 gtk_text_buffer_create_tag(buffer, "quote1",
871 "foreground-gdk", "e_color2,
873 gtk_text_buffer_create_tag(buffer, "quote2",
874 "foreground-gdk", "e_color3,
878 gtk_text_buffer_create_tag(buffer, "signature",
879 "foreground-gdk", &signature_color,
881 gtk_text_buffer_create_tag(buffer, "link",
882 "foreground-gdk", &uri_color,
884 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
885 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
887 color[0] = quote_color1;
888 color[1] = quote_color2;
889 color[2] = quote_color3;
890 color[3] = quote_bgcolor1;
891 color[4] = quote_bgcolor2;
892 color[5] = quote_bgcolor3;
893 color[6] = signature_color;
894 color[7] = uri_color;
895 cmap = gdk_drawable_get_colormap(compose->window->window);
896 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
898 for (i = 0; i < 8; i++) {
899 if (success[i] == FALSE) {
902 g_warning("Compose: color allocation failed.\n");
903 style = gtk_widget_get_style(GTK_WIDGET(text));
904 quote_color1 = quote_color2 = quote_color3 =
905 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
906 signature_color = uri_color = black;
911 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
912 GPtrArray *attach_files)
914 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
917 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
919 return compose_generic_new(account, NULL, item, NULL, NULL);
922 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
924 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
927 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
928 GPtrArray *attach_files, GList *listAddress )
931 GtkTextView *textview;
932 GtkTextBuffer *textbuf;
934 GtkItemFactory *ifactory;
936 if (item && item->prefs && item->prefs->enable_default_account)
937 account = account_find_from_id(item->prefs->default_account);
939 if (!account) account = cur_account;
940 g_return_val_if_fail(account != NULL, NULL);
942 compose = compose_create(account, COMPOSE_NEW, FALSE);
944 ifactory = gtk_item_factory_from_widget(compose->menubar);
946 compose->replyinfo = NULL;
947 compose->fwdinfo = NULL;
949 textview = GTK_TEXT_VIEW(compose->text);
950 textbuf = gtk_text_view_get_buffer(textview);
951 compose_create_tags(textview, compose);
953 undo_block(compose->undostruct);
955 if (item && item->prefs && item->prefs->enable_default_dictionary &&
957 gtkaspell_change_dict(compose->gtkaspell,
958 item->prefs->default_dictionary);
961 if (account->auto_sig)
962 compose_insert_sig(compose, FALSE);
963 gtk_text_buffer_get_start_iter(textbuf, &iter);
964 gtk_text_buffer_place_cursor(textbuf, &iter);
966 if (account->protocol != A_NNTP) {
967 if (mailto && *mailto != '\0') {
968 compose_entries_set(compose, mailto);
970 } else if (item && item->prefs->enable_default_to) {
971 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
972 compose_entry_mark_default_to(compose, item->prefs->default_to);
974 if (item && item->ret_rcpt) {
975 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
979 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
981 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
984 * CLAWS: just don't allow return receipt request, even if the user
985 * may want to send an email. simple but foolproof.
987 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
989 compose_add_field_list( compose, listAddress );
995 for (i = 0; i < attach_files->len; i++) {
996 file = g_ptr_array_index(attach_files, i);
997 compose_attach_append(compose, file, file, NULL);
1001 compose_show_first_last_header(compose, TRUE);
1003 /* Set save folder */
1004 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1005 gchar *folderidentifier;
1007 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1008 folderidentifier = folder_item_get_identifier(item);
1009 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1010 g_free(folderidentifier);
1013 gtk_widget_grab_focus(compose->header_last->entry);
1015 undo_unblock(compose->undostruct);
1017 if (prefs_common.auto_exteditor)
1018 compose_exec_ext_editor(compose);
1020 compose->modified = FALSE;
1021 compose_set_title(compose);
1025 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1026 gboolean override_pref)
1028 gchar *privacy = NULL;
1030 g_return_if_fail(compose != NULL);
1031 g_return_if_fail(account != NULL);
1033 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1036 if (account->default_privacy_system
1037 && strlen(account->default_privacy_system)) {
1038 privacy = account->default_privacy_system;
1040 GSList *privacy_avail = privacy_get_system_ids();
1041 if (privacy_avail && g_slist_length(privacy_avail)) {
1042 privacy = (gchar *)(privacy_avail->data);
1045 if (privacy != NULL) {
1046 compose->privacy_system = g_strdup(privacy);
1047 compose_update_privacy_system_menu_item(compose, FALSE);
1048 compose_use_encryption(compose, TRUE);
1052 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1054 gchar *privacy = NULL;
1056 if (account->default_privacy_system
1057 && strlen(account->default_privacy_system)) {
1058 privacy = account->default_privacy_system;
1060 GSList *privacy_avail = privacy_get_system_ids();
1061 if (privacy_avail && g_slist_length(privacy_avail)) {
1062 privacy = (gchar *)(privacy_avail->data);
1065 if (privacy != NULL) {
1066 compose->privacy_system = g_strdup(privacy);
1067 compose_update_privacy_system_menu_item(compose, FALSE);
1068 compose_use_signing(compose, TRUE);
1072 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1076 Compose *compose = NULL;
1077 g_return_val_if_fail(msginfo_list != NULL, NULL);
1079 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1080 g_return_val_if_fail(msginfo != NULL, NULL);
1082 list_len = g_slist_length(msginfo_list);
1086 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1087 FALSE, prefs_common.default_reply_list, FALSE, body);
1089 case COMPOSE_REPLY_WITH_QUOTE:
1090 compose = compose_reply(msginfo, TRUE,
1091 FALSE, prefs_common.default_reply_list, FALSE, body);
1093 case COMPOSE_REPLY_WITHOUT_QUOTE:
1094 compose = compose_reply(msginfo, FALSE,
1095 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1097 case COMPOSE_REPLY_TO_SENDER:
1098 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1099 FALSE, FALSE, TRUE, body);
1101 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1102 compose = compose_followup_and_reply_to(msginfo,
1103 prefs_common.reply_with_quote,
1104 FALSE, FALSE, body);
1106 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1107 compose = compose_reply(msginfo, TRUE,
1108 FALSE, FALSE, TRUE, body);
1110 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1111 compose = compose_reply(msginfo, FALSE,
1112 FALSE, FALSE, TRUE, NULL);
1114 case COMPOSE_REPLY_TO_ALL:
1115 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1116 TRUE, FALSE, FALSE, body);
1118 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1119 compose = compose_reply(msginfo, TRUE,
1120 TRUE, FALSE, FALSE, body);
1122 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1123 compose = compose_reply(msginfo, FALSE,
1124 TRUE, FALSE, FALSE, NULL);
1126 case COMPOSE_REPLY_TO_LIST:
1127 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1128 FALSE, TRUE, FALSE, body);
1130 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1131 compose = compose_reply(msginfo, TRUE,
1132 FALSE, TRUE, FALSE, body);
1134 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1135 compose = compose_reply(msginfo, FALSE,
1136 FALSE, TRUE, FALSE, NULL);
1138 case COMPOSE_FORWARD:
1139 if (prefs_common.forward_as_attachment) {
1140 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1143 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1147 case COMPOSE_FORWARD_INLINE:
1148 /* check if we reply to more than one Message */
1149 if (list_len == 1) {
1150 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1153 /* more messages FALL THROUGH */
1154 case COMPOSE_FORWARD_AS_ATTACH:
1155 compose = compose_forward_multiple(NULL, msginfo_list);
1157 case COMPOSE_REDIRECT:
1158 compose = compose_redirect(NULL, msginfo, FALSE);
1161 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1166 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1167 gboolean to_ml, gboolean to_sender,
1170 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1171 to_sender, FALSE, body);
1174 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1179 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1180 to_sender, TRUE, body);
1183 static void compose_extract_original_charset(Compose *compose)
1185 MsgInfo *info = NULL;
1186 if (compose->replyinfo) {
1187 info = compose->replyinfo;
1188 } else if (compose->fwdinfo) {
1189 info = compose->fwdinfo;
1190 } else if (compose->targetinfo) {
1191 info = compose->targetinfo;
1194 MimeInfo *mimeinfo = procmime_scan_message(info);
1195 MimeInfo *partinfo = mimeinfo;
1196 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1197 partinfo = procmime_mimeinfo_next(partinfo);
1199 compose->orig_charset =
1200 g_strdup(procmime_mimeinfo_get_parameter(
1201 partinfo, "charset"));
1203 procmime_mimeinfo_free_all(mimeinfo);
1207 #define SIGNAL_BLOCK(buffer) { \
1208 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1209 G_CALLBACK(compose_changed_cb), \
1211 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1212 G_CALLBACK(text_inserted), \
1216 #define SIGNAL_UNBLOCK(buffer) { \
1217 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1218 G_CALLBACK(compose_changed_cb), \
1220 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1221 G_CALLBACK(text_inserted), \
1225 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1226 gboolean to_all, gboolean to_ml,
1228 gboolean followup_and_reply_to,
1231 GtkItemFactory *ifactory;
1233 PrefsAccount *account = NULL;
1234 PrefsAccount *reply_account;
1235 GtkTextView *textview;
1236 GtkTextBuffer *textbuf;
1238 g_return_val_if_fail(msginfo != NULL, NULL);
1239 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1241 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1243 g_return_val_if_fail(account != NULL, NULL);
1245 if (to_sender && account->protocol == A_NNTP &&
1246 !followup_and_reply_to) {
1248 account_find_from_address(account->address);
1250 reply_account = compose_current_mail_account();
1254 reply_account = account;
1256 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1258 compose->updating = TRUE;
1260 ifactory = gtk_item_factory_from_widget(compose->menubar);
1262 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1263 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1265 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1266 if (!compose->replyinfo)
1267 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1269 compose_extract_original_charset(compose);
1271 if (msginfo->folder && msginfo->folder->ret_rcpt)
1272 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1274 /* Set save folder */
1275 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1276 gchar *folderidentifier;
1278 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1279 folderidentifier = folder_item_get_identifier(msginfo->folder);
1280 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1281 g_free(folderidentifier);
1284 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1285 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1286 to_sender, followup_and_reply_to);
1287 compose_show_first_last_header(compose, TRUE);
1289 textview = (GTK_TEXT_VIEW(compose->text));
1290 textbuf = gtk_text_view_get_buffer(textview);
1291 compose_create_tags(textview, compose);
1293 undo_block(compose->undostruct);
1295 if (msginfo->folder && msginfo->folder->prefs &&
1296 msginfo->folder->prefs &&
1297 msginfo->folder->prefs->enable_default_dictionary &&
1299 gtkaspell_change_dict(compose->gtkaspell,
1300 msginfo->folder->prefs->default_dictionary);
1306 if (prefs_common.quotemark && *prefs_common.quotemark)
1307 qmark = prefs_common.quotemark;
1311 compose_quote_fmt(compose, compose->replyinfo,
1312 prefs_common.quotefmt,
1313 qmark, body, FALSE);
1315 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1316 compose_force_encryption(compose, account, FALSE);
1319 SIGNAL_BLOCK(textbuf);
1321 if (account->auto_sig)
1322 compose_insert_sig(compose, FALSE);
1324 compose_wrap_all(compose);
1326 SIGNAL_UNBLOCK(textbuf);
1328 gtk_widget_grab_focus(compose->text);
1330 undo_unblock(compose->undostruct);
1332 if (prefs_common.auto_exteditor)
1333 compose_exec_ext_editor(compose);
1335 compose->modified = FALSE;
1336 compose_set_title(compose);
1338 compose->updating = FALSE;
1340 if (compose->deferred_destroy) {
1341 compose_destroy(compose);
1348 #define INSERT_FW_HEADER(var, hdr) \
1349 if (msginfo->var && *msginfo->var) { \
1350 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1351 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1352 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1355 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1356 gboolean as_attach, const gchar *body,
1357 gboolean no_extedit,
1361 GtkTextView *textview;
1362 GtkTextBuffer *textbuf;
1365 g_return_val_if_fail(msginfo != NULL, NULL);
1366 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1369 !(account = compose_guess_forward_account_from_msginfo
1371 account = cur_account;
1373 compose = compose_create(account, COMPOSE_FORWARD, batch);
1375 compose->updating = TRUE;
1376 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1377 if (!compose->fwdinfo)
1378 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1380 compose_extract_original_charset(compose);
1382 if (msginfo->subject && *msginfo->subject) {
1383 gchar *buf, *buf2, *p;
1385 buf = p = g_strdup(msginfo->subject);
1386 p += subject_get_prefix_length(p);
1387 memmove(buf, p, strlen(p) + 1);
1389 buf2 = g_strdup_printf("Fw: %s", buf);
1390 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1396 textview = GTK_TEXT_VIEW(compose->text);
1397 textbuf = gtk_text_view_get_buffer(textview);
1398 compose_create_tags(textview, compose);
1400 undo_block(compose->undostruct);
1404 msgfile = procmsg_get_message_file_path(msginfo);
1405 if (!is_file_exist(msgfile))
1406 g_warning("%s: file not exist\n", msgfile);
1408 compose_attach_append(compose, msgfile, msgfile,
1414 MsgInfo *full_msginfo;
1416 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1418 full_msginfo = procmsg_msginfo_copy(msginfo);
1420 if (prefs_common.fw_quotemark &&
1421 *prefs_common.fw_quotemark)
1422 qmark = prefs_common.fw_quotemark;
1426 compose_quote_fmt(compose, full_msginfo,
1427 prefs_common.fw_quotefmt,
1428 qmark, body, FALSE);
1429 compose_attach_parts(compose, msginfo);
1431 procmsg_msginfo_free(full_msginfo);
1434 SIGNAL_BLOCK(textbuf);
1436 if (account->auto_sig)
1437 compose_insert_sig(compose, FALSE);
1439 compose_wrap_all(compose);
1441 SIGNAL_UNBLOCK(textbuf);
1443 gtk_text_buffer_get_start_iter(textbuf, &iter);
1444 gtk_text_buffer_place_cursor(textbuf, &iter);
1446 gtk_widget_grab_focus(compose->header_last->entry);
1448 if (!no_extedit && prefs_common.auto_exteditor)
1449 compose_exec_ext_editor(compose);
1452 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1453 gchar *folderidentifier;
1455 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1456 folderidentifier = folder_item_get_identifier(msginfo->folder);
1457 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1458 g_free(folderidentifier);
1461 undo_unblock(compose->undostruct);
1463 compose->modified = FALSE;
1464 compose_set_title(compose);
1466 compose->updating = FALSE;
1468 if (compose->deferred_destroy) {
1469 compose_destroy(compose);
1476 #undef INSERT_FW_HEADER
1478 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1481 GtkTextView *textview;
1482 GtkTextBuffer *textbuf;
1486 gboolean single_mail = TRUE;
1488 g_return_val_if_fail(msginfo_list != NULL, NULL);
1490 if (g_slist_length(msginfo_list) > 1)
1491 single_mail = FALSE;
1493 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1494 if (((MsgInfo *)msginfo->data)->folder == NULL)
1497 /* guess account from first selected message */
1499 !(account = compose_guess_forward_account_from_msginfo
1500 (msginfo_list->data)))
1501 account = cur_account;
1503 g_return_val_if_fail(account != NULL, NULL);
1505 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1506 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1507 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1510 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1512 compose->updating = TRUE;
1514 textview = GTK_TEXT_VIEW(compose->text);
1515 textbuf = gtk_text_view_get_buffer(textview);
1516 compose_create_tags(textview, compose);
1518 undo_block(compose->undostruct);
1519 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1520 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1522 if (!is_file_exist(msgfile))
1523 g_warning("%s: file not exist\n", msgfile);
1525 compose_attach_append(compose, msgfile, msgfile,
1531 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1532 if (info->subject && *info->subject) {
1533 gchar *buf, *buf2, *p;
1535 buf = p = g_strdup(info->subject);
1536 p += subject_get_prefix_length(p);
1537 memmove(buf, p, strlen(p) + 1);
1539 buf2 = g_strdup_printf("Fw: %s", buf);
1540 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1546 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1547 _("Fw: multiple emails"));
1550 SIGNAL_BLOCK(textbuf);
1552 if (account->auto_sig)
1553 compose_insert_sig(compose, FALSE);
1555 compose_wrap_all(compose);
1557 SIGNAL_UNBLOCK(textbuf);
1559 gtk_text_buffer_get_start_iter(textbuf, &iter);
1560 gtk_text_buffer_place_cursor(textbuf, &iter);
1562 gtk_widget_grab_focus(compose->header_last->entry);
1563 undo_unblock(compose->undostruct);
1564 compose->modified = FALSE;
1565 compose_set_title(compose);
1567 compose->updating = FALSE;
1569 if (compose->deferred_destroy) {
1570 compose_destroy(compose);
1577 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1579 GtkTextIter start = *iter;
1580 GtkTextIter end_iter;
1581 int start_pos = gtk_text_iter_get_offset(&start);
1583 if (!compose->account->sig_sep)
1586 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1587 start_pos+strlen(compose->account->sig_sep));
1589 /* check sig separator */
1590 str = gtk_text_iter_get_text(&start, &end_iter);
1591 if (!strcmp(str, compose->account->sig_sep)) {
1593 /* check end of line (\n) */
1594 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1595 start_pos+strlen(compose->account->sig_sep));
1596 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1597 start_pos+strlen(compose->account->sig_sep)+1);
1598 tmp = gtk_text_iter_get_text(&start, &end_iter);
1599 if (!strcmp(tmp,"\n")) {
1611 static void compose_colorize_signature(Compose *compose)
1613 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1615 GtkTextIter end_iter;
1616 gtk_text_buffer_get_start_iter(buffer, &iter);
1617 while (gtk_text_iter_forward_line(&iter))
1618 if (compose_is_sig_separator(compose, buffer, &iter)) {
1619 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1620 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1624 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1626 Compose *compose = NULL;
1627 PrefsAccount *account = NULL;
1628 GtkTextView *textview;
1629 GtkTextBuffer *textbuf;
1633 gchar buf[BUFFSIZE];
1634 gboolean use_signing = FALSE;
1635 gboolean use_encryption = FALSE;
1636 gchar *privacy_system = NULL;
1638 g_return_val_if_fail(msginfo != NULL, NULL);
1639 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1641 if (compose_put_existing_to_front(msginfo)) {
1645 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1646 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1647 gchar queueheader_buf[BUFFSIZE];
1650 /* Select Account from queue headers */
1651 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1652 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1653 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1654 account = account_find_from_id(id);
1656 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1657 sizeof(queueheader_buf), "NAID:")) {
1658 id = atoi(&queueheader_buf[strlen("NAID:")]);
1659 account = account_find_from_id(id);
1661 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1662 sizeof(queueheader_buf), "MAID:")) {
1663 id = atoi(&queueheader_buf[strlen("MAID:")]);
1664 account = account_find_from_id(id);
1666 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1667 sizeof(queueheader_buf), "S:")) {
1668 account = account_find_from_address(queueheader_buf);
1670 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1671 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1672 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1673 use_signing = param;
1676 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1677 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1678 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1679 use_encryption = param;
1681 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1682 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1683 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1685 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1686 sizeof(queueheader_buf), "X-Priority: ")) {
1687 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1688 compose->priority = param;
1691 account = msginfo->folder->folder->account;
1694 if (!account && prefs_common.reedit_account_autosel) {
1695 gchar from[BUFFSIZE];
1696 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1697 extract_address(from);
1698 account = account_find_from_address(from);
1702 account = cur_account;
1704 g_return_val_if_fail(account != NULL, NULL);
1706 compose = compose_create(account, COMPOSE_REEDIT, batch);
1708 compose->updating = TRUE;
1710 if (privacy_system != NULL) {
1711 compose->privacy_system = privacy_system;
1712 compose_use_signing(compose, use_signing);
1713 compose_use_encryption(compose, use_encryption);
1714 compose_update_privacy_system_menu_item(compose, FALSE);
1716 activate_privacy_system(compose, account, FALSE);
1719 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1721 compose_extract_original_charset(compose);
1723 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1724 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1725 gchar queueheader_buf[BUFFSIZE];
1727 /* Set message save folder */
1728 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1731 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1732 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1733 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1735 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1736 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1738 GtkItemFactory *ifactory;
1739 ifactory = gtk_item_factory_from_widget(compose->menubar);
1740 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1745 if (compose_parse_header(compose, msginfo) < 0) {
1746 compose->updating = FALSE;
1747 compose_destroy(compose);
1750 compose_reedit_set_entry(compose, msginfo);
1752 textview = GTK_TEXT_VIEW(compose->text);
1753 textbuf = gtk_text_view_get_buffer(textview);
1754 compose_create_tags(textview, compose);
1756 mark = gtk_text_buffer_get_insert(textbuf);
1757 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1759 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1760 G_CALLBACK(compose_changed_cb),
1763 if (procmime_msginfo_is_encrypted(msginfo)) {
1764 fp = procmime_get_first_encrypted_text_content(msginfo);
1766 compose_force_encryption(compose, account, TRUE);
1769 fp = procmime_get_first_text_content(msginfo);
1772 g_warning("Can't get text part\n");
1776 gboolean prev_autowrap = compose->autowrap;
1778 compose->autowrap = FALSE;
1779 while (fgets(buf, sizeof(buf), fp) != NULL) {
1781 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1783 compose_wrap_all_full(compose, FALSE);
1784 compose->autowrap = prev_autowrap;
1788 compose_attach_parts(compose, msginfo);
1790 compose_colorize_signature(compose);
1792 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1793 G_CALLBACK(compose_changed_cb),
1796 gtk_widget_grab_focus(compose->text);
1798 if (prefs_common.auto_exteditor) {
1799 compose_exec_ext_editor(compose);
1801 compose->modified = FALSE;
1802 compose_set_title(compose);
1804 compose->updating = FALSE;
1806 if (compose->deferred_destroy) {
1807 compose_destroy(compose);
1813 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1818 GtkItemFactory *ifactory;
1821 g_return_val_if_fail(msginfo != NULL, NULL);
1824 account = account_get_reply_account(msginfo,
1825 prefs_common.reply_account_autosel);
1826 g_return_val_if_fail(account != NULL, NULL);
1828 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1830 compose->updating = TRUE;
1832 ifactory = gtk_item_factory_from_widget(compose->menubar);
1833 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1834 compose->replyinfo = NULL;
1835 compose->fwdinfo = NULL;
1837 compose_show_first_last_header(compose, TRUE);
1839 gtk_widget_grab_focus(compose->header_last->entry);
1841 filename = procmsg_get_message_file_path(msginfo);
1843 if (filename == NULL) {
1844 compose->updating = FALSE;
1845 compose_destroy(compose);
1850 compose->redirect_filename = filename;
1852 /* Set save folder */
1853 item = msginfo->folder;
1854 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1855 gchar *folderidentifier;
1857 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1858 folderidentifier = folder_item_get_identifier(item);
1859 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1860 g_free(folderidentifier);
1863 compose_attach_parts(compose, msginfo);
1865 if (msginfo->subject)
1866 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1868 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1870 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1871 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1873 compose_colorize_signature(compose);
1875 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1876 menu_set_sensitive(ifactory, "/Add...", FALSE);
1877 menu_set_sensitive(ifactory, "/Remove", FALSE);
1878 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1880 ifactory = gtk_item_factory_from_widget(compose->menubar);
1881 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1882 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1883 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1884 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1885 menu_set_sensitive(ifactory, "/Edit", FALSE);
1886 menu_set_sensitive(ifactory, "/Options", FALSE);
1887 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1888 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1890 if (compose->toolbar->draft_btn)
1891 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1892 if (compose->toolbar->insert_btn)
1893 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1894 if (compose->toolbar->attach_btn)
1895 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1896 if (compose->toolbar->sig_btn)
1897 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1898 if (compose->toolbar->exteditor_btn)
1899 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1900 if (compose->toolbar->linewrap_current_btn)
1901 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1902 if (compose->toolbar->linewrap_all_btn)
1903 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1905 compose->modified = FALSE;
1906 compose_set_title(compose);
1907 compose->updating = FALSE;
1909 if (compose->deferred_destroy) {
1910 compose_destroy(compose);
1917 GList *compose_get_compose_list(void)
1919 return compose_list;
1922 void compose_entry_append(Compose *compose, const gchar *address,
1923 ComposeEntryType type)
1927 gboolean in_quote = FALSE;
1928 if (!address || *address == '\0') return;
1935 header = N_("Bcc:");
1937 case COMPOSE_REPLYTO:
1938 header = N_("Reply-To:");
1940 case COMPOSE_NEWSGROUPS:
1941 header = N_("Newsgroups:");
1943 case COMPOSE_FOLLOWUPTO:
1944 header = N_( "Followup-To:");
1951 header = prefs_common.trans_hdr ? gettext(header) : header;
1953 cur = begin = (gchar *)address;
1955 /* we separate the line by commas, but not if we're inside a quoted
1957 while (*cur != '\0') {
1959 in_quote = !in_quote;
1960 if (*cur == ',' && !in_quote) {
1961 gchar *tmp = g_strdup(begin);
1963 tmp[cur-begin]='\0';
1966 while (*tmp == ' ' || *tmp == '\t')
1968 compose_add_header_entry(compose, header, tmp);
1975 gchar *tmp = g_strdup(begin);
1977 tmp[cur-begin]='\0';
1980 while (*tmp == ' ' || *tmp == '\t')
1982 compose_add_header_entry(compose, header, tmp);
1987 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1989 static GdkColor yellow;
1990 static GdkColor black;
1991 static gboolean yellow_initialised = FALSE;
1995 if (!yellow_initialised) {
1996 gdk_color_parse("#f5f6be", &yellow);
1997 gdk_color_parse("#000000", &black);
1998 yellow_initialised = gdk_colormap_alloc_color(
1999 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2000 yellow_initialised &= gdk_colormap_alloc_color(
2001 gdk_colormap_get_system(), &black, FALSE, TRUE);
2004 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2005 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2006 if (gtk_entry_get_text(entry) &&
2007 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2008 if (yellow_initialised) {
2009 gtk_widget_modify_base(
2010 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2011 GTK_STATE_NORMAL, &yellow);
2012 gtk_widget_modify_text(
2013 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2014 GTK_STATE_NORMAL, &black);
2020 void compose_toolbar_cb(gint action, gpointer data)
2022 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2023 Compose *compose = (Compose*)toolbar_item->parent;
2025 g_return_if_fail(compose != NULL);
2029 compose_send_cb(compose, 0, NULL);
2032 compose_send_later_cb(compose, 0, NULL);
2035 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2038 compose_insert_file_cb(compose, 0, NULL);
2041 compose_attach_cb(compose, 0, NULL);
2044 compose_insert_sig(compose, FALSE);
2047 compose_ext_editor_cb(compose, 0, NULL);
2049 case A_LINEWRAP_CURRENT:
2050 compose_beautify_paragraph(compose, NULL, TRUE);
2052 case A_LINEWRAP_ALL:
2053 compose_wrap_all_full(compose, TRUE);
2056 compose_address_cb(compose, 0, NULL);
2059 case A_CHECK_SPELLING:
2060 compose_check_all(compose);
2068 static void compose_entries_set(Compose *compose, const gchar *mailto)
2072 gchar *subject = NULL;
2077 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2080 compose_entry_append(compose, to, COMPOSE_TO);
2082 compose_entry_append(compose, cc, COMPOSE_CC);
2084 if (!g_utf8_validate (subject, -1, NULL)) {
2085 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2086 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2089 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2093 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2094 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2097 gboolean prev_autowrap = compose->autowrap;
2099 compose->autowrap = FALSE;
2101 mark = gtk_text_buffer_get_insert(buffer);
2102 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2104 if (!g_utf8_validate (body, -1, NULL)) {
2105 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2106 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2109 gtk_text_buffer_insert(buffer, &iter, body, -1);
2111 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2113 compose->autowrap = prev_autowrap;
2114 if (compose->autowrap)
2115 compose_wrap_all(compose);
2124 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2126 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2127 {"Cc:", NULL, TRUE},
2128 {"References:", NULL, FALSE},
2129 {"Bcc:", NULL, TRUE},
2130 {"Newsgroups:", NULL, TRUE},
2131 {"Followup-To:", NULL, TRUE},
2132 {"List-Post:", NULL, FALSE},
2133 {"X-Priority:", NULL, FALSE},
2134 {NULL, NULL, FALSE}};
2150 g_return_val_if_fail(msginfo != NULL, -1);
2152 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2153 procheader_get_header_fields(fp, hentry);
2156 if (hentry[H_REPLY_TO].body != NULL) {
2157 if (hentry[H_REPLY_TO].body[0] != '\0') {
2159 conv_unmime_header(hentry[H_REPLY_TO].body,
2162 g_free(hentry[H_REPLY_TO].body);
2163 hentry[H_REPLY_TO].body = NULL;
2165 if (hentry[H_CC].body != NULL) {
2166 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2167 g_free(hentry[H_CC].body);
2168 hentry[H_CC].body = NULL;
2170 if (hentry[H_REFERENCES].body != NULL) {
2171 if (compose->mode == COMPOSE_REEDIT)
2172 compose->references = hentry[H_REFERENCES].body;
2174 compose->references = compose_parse_references
2175 (hentry[H_REFERENCES].body, msginfo->msgid);
2176 g_free(hentry[H_REFERENCES].body);
2178 hentry[H_REFERENCES].body = NULL;
2180 if (hentry[H_BCC].body != NULL) {
2181 if (compose->mode == COMPOSE_REEDIT)
2183 conv_unmime_header(hentry[H_BCC].body, NULL);
2184 g_free(hentry[H_BCC].body);
2185 hentry[H_BCC].body = NULL;
2187 if (hentry[H_NEWSGROUPS].body != NULL) {
2188 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2189 hentry[H_NEWSGROUPS].body = NULL;
2191 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2192 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2193 compose->followup_to =
2194 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2197 g_free(hentry[H_FOLLOWUP_TO].body);
2198 hentry[H_FOLLOWUP_TO].body = NULL;
2200 if (hentry[H_LIST_POST].body != NULL) {
2203 extract_address(hentry[H_LIST_POST].body);
2204 if (hentry[H_LIST_POST].body[0] != '\0') {
2205 scan_mailto_url(hentry[H_LIST_POST].body,
2206 &to, NULL, NULL, NULL, NULL);
2208 g_free(compose->ml_post);
2209 compose->ml_post = to;
2212 g_free(hentry[H_LIST_POST].body);
2213 hentry[H_LIST_POST].body = NULL;
2216 /* CLAWS - X-Priority */
2217 if (compose->mode == COMPOSE_REEDIT)
2218 if (hentry[H_X_PRIORITY].body != NULL) {
2221 priority = atoi(hentry[H_X_PRIORITY].body);
2222 g_free(hentry[H_X_PRIORITY].body);
2224 hentry[H_X_PRIORITY].body = NULL;
2226 if (priority < PRIORITY_HIGHEST ||
2227 priority > PRIORITY_LOWEST)
2228 priority = PRIORITY_NORMAL;
2230 compose->priority = priority;
2233 if (compose->mode == COMPOSE_REEDIT) {
2234 if (msginfo->inreplyto && *msginfo->inreplyto)
2235 compose->inreplyto = g_strdup(msginfo->inreplyto);
2239 if (msginfo->msgid && *msginfo->msgid)
2240 compose->inreplyto = g_strdup(msginfo->msgid);
2242 if (!compose->references) {
2243 if (msginfo->msgid && *msginfo->msgid) {
2244 if (msginfo->inreplyto && *msginfo->inreplyto)
2245 compose->references =
2246 g_strdup_printf("<%s>\n\t<%s>",
2250 compose->references =
2251 g_strconcat("<", msginfo->msgid, ">",
2253 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2254 compose->references =
2255 g_strconcat("<", msginfo->inreplyto, ">",
2263 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2265 GSList *ref_id_list, *cur;
2269 ref_id_list = references_list_append(NULL, ref);
2270 if (!ref_id_list) return NULL;
2271 if (msgid && *msgid)
2272 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2277 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2278 /* "<" + Message-ID + ">" + CR+LF+TAB */
2279 len += strlen((gchar *)cur->data) + 5;
2281 if (len > MAX_REFERENCES_LEN) {
2282 /* remove second message-ID */
2283 if (ref_id_list && ref_id_list->next &&
2284 ref_id_list->next->next) {
2285 g_free(ref_id_list->next->data);
2286 ref_id_list = g_slist_remove
2287 (ref_id_list, ref_id_list->next->data);
2289 slist_free_strings(ref_id_list);
2290 g_slist_free(ref_id_list);
2297 new_ref = g_string_new("");
2298 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2299 if (new_ref->len > 0)
2300 g_string_append(new_ref, "\n\t");
2301 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2304 slist_free_strings(ref_id_list);
2305 g_slist_free(ref_id_list);
2307 new_ref_str = new_ref->str;
2308 g_string_free(new_ref, FALSE);
2313 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2314 const gchar *fmt, const gchar *qmark,
2315 const gchar *body, gboolean rewrap)
2317 static MsgInfo dummyinfo;
2318 gchar *quote_str = NULL;
2320 gboolean prev_autowrap;
2321 const gchar *trimmed_body = body;
2322 gint cursor_pos = -1;
2323 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2324 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2329 SIGNAL_BLOCK(buffer);
2332 msginfo = &dummyinfo;
2334 if (qmark != NULL) {
2335 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2336 quote_fmt_scan_string(qmark);
2339 buf = quote_fmt_get_buffer();
2341 alertpanel_error(_("Quote mark format error."));
2343 Xstrdup_a(quote_str, buf, goto error)
2346 if (fmt && *fmt != '\0') {
2347 while (trimmed_body && strlen(trimmed_body) > 1
2348 && trimmed_body[0]=='\n')
2351 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2352 quote_fmt_scan_string(fmt);
2355 buf = quote_fmt_get_buffer();
2357 alertpanel_error(_("Message reply/forward format error."));
2363 prev_autowrap = compose->autowrap;
2364 compose->autowrap = FALSE;
2366 mark = gtk_text_buffer_get_insert(buffer);
2367 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2368 if (g_utf8_validate(buf, -1, NULL)) {
2369 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2371 gchar *tmpout = NULL;
2372 tmpout = conv_codeset_strdup
2373 (buf, conv_get_locale_charset_str_no_utf8(),
2375 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2377 tmpout = g_malloc(strlen(buf)*2+1);
2378 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2380 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2384 cursor_pos = quote_fmt_get_cursor_pos();
2385 compose->set_cursor_pos = cursor_pos;
2386 if (cursor_pos == -1) {
2389 gtk_text_buffer_get_start_iter(buffer, &iter);
2390 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2391 gtk_text_buffer_place_cursor(buffer, &iter);
2393 compose->autowrap = prev_autowrap;
2394 if (compose->autowrap && rewrap)
2395 compose_wrap_all(compose);
2402 SIGNAL_UNBLOCK(buffer);
2408 /* if ml_post is of type addr@host and from is of type
2409 * addr-anything@host, return TRUE
2411 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2413 gchar *left_ml = NULL;
2414 gchar *right_ml = NULL;
2415 gchar *left_from = NULL;
2416 gchar *right_from = NULL;
2417 gboolean result = FALSE;
2419 if (!ml_post || !from)
2422 left_ml = g_strdup(ml_post);
2423 if (strstr(left_ml, "@")) {
2424 right_ml = strstr(left_ml, "@")+1;
2425 *(strstr(left_ml, "@")) = '\0';
2428 left_from = g_strdup(from);
2429 if (strstr(left_from, "@")) {
2430 right_from = strstr(left_from, "@")+1;
2431 *(strstr(left_from, "@")) = '\0';
2434 if (left_ml && left_from && right_ml && right_from
2435 && !strncmp(left_from, left_ml, strlen(left_ml))
2436 && !strcmp(right_from, right_ml)) {
2445 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2447 gchar *my_addr1, *my_addr2;
2449 if (!addr1 || !addr2)
2452 Xstrdup_a(my_addr1, addr1, return FALSE);
2453 Xstrdup_a(my_addr2, addr2, return FALSE);
2455 extract_address(my_addr1);
2456 extract_address(my_addr2);
2458 return !strcmp(my_addr1, my_addr2);
2461 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2462 gboolean to_all, gboolean to_ml,
2464 gboolean followup_and_reply_to)
2466 GSList *cc_list = NULL;
2469 gchar *replyto = NULL;
2470 GHashTable *to_table;
2472 gboolean reply_to_ml = FALSE;
2473 gboolean default_reply_to = FALSE;
2475 g_return_if_fail(compose->account != NULL);
2476 g_return_if_fail(msginfo != NULL);
2478 reply_to_ml = to_ml && compose->ml_post;
2480 default_reply_to = msginfo->folder &&
2481 msginfo->folder->prefs->enable_default_reply_to;
2483 if (compose->account->protocol != A_NNTP) {
2484 if (reply_to_ml && !default_reply_to) {
2486 gboolean is_subscr = is_subscription(compose->ml_post,
2489 /* normal answer to ml post with a reply-to */
2490 compose_entry_append(compose,
2493 if (compose->replyto
2494 && !same_address(compose->ml_post, compose->replyto))
2495 compose_entry_append(compose,
2499 /* answer to subscription confirmation */
2500 if (compose->replyto)
2501 compose_entry_append(compose,
2504 else if (msginfo->from)
2505 compose_entry_append(compose,
2510 else if (!(to_all || to_sender) && default_reply_to) {
2511 compose_entry_append(compose,
2512 msginfo->folder->prefs->default_reply_to,
2514 compose_entry_mark_default_to(compose,
2515 msginfo->folder->prefs->default_reply_to);
2520 Xstrdup_a(tmp1, msginfo->from, return);
2521 extract_address(tmp1);
2522 if (to_all || to_sender ||
2523 !account_find_from_address(tmp1))
2524 compose_entry_append(compose,
2525 (compose->replyto && !to_sender)
2526 ? compose->replyto :
2527 msginfo->from ? msginfo->from : "",
2529 else if (!to_all && !to_sender) {
2530 /* reply to the last list of recipients */
2531 compose_entry_append(compose,
2532 msginfo->to ? msginfo->to : "",
2534 compose_entry_append(compose,
2535 msginfo->cc ? msginfo->cc : "",
2540 if (to_sender || (compose->followup_to &&
2541 !strncmp(compose->followup_to, "poster", 6)))
2542 compose_entry_append
2544 (compose->replyto ? compose->replyto :
2545 msginfo->from ? msginfo->from : ""),
2548 else if (followup_and_reply_to || to_all) {
2549 compose_entry_append
2551 (compose->replyto ? compose->replyto :
2552 msginfo->from ? msginfo->from : ""),
2555 compose_entry_append
2557 compose->followup_to ? compose->followup_to :
2558 compose->newsgroups ? compose->newsgroups : "",
2559 COMPOSE_NEWSGROUPS);
2562 compose_entry_append
2564 compose->followup_to ? compose->followup_to :
2565 compose->newsgroups ? compose->newsgroups : "",
2566 COMPOSE_NEWSGROUPS);
2569 if (msginfo->subject && *msginfo->subject) {
2573 buf = p = g_strdup(msginfo->subject);
2574 p += subject_get_prefix_length(p);
2575 memmove(buf, p, strlen(p) + 1);
2577 buf2 = g_strdup_printf("Re: %s", buf);
2578 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2583 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2585 if (to_ml && compose->ml_post) return;
2586 if (!to_all || compose->account->protocol == A_NNTP) return;
2588 if (compose->replyto) {
2589 Xstrdup_a(replyto, compose->replyto, return);
2590 extract_address(replyto);
2592 if (msginfo->from) {
2593 Xstrdup_a(from, msginfo->from, return);
2594 extract_address(from);
2597 if (replyto && from)
2598 cc_list = address_list_append_with_comments(cc_list, from);
2599 if (to_all && msginfo->folder &&
2600 msginfo->folder->prefs->enable_default_reply_to)
2601 cc_list = address_list_append_with_comments(cc_list,
2602 msginfo->folder->prefs->default_reply_to);
2603 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2604 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2606 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2608 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2609 if (compose->account)
2610 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2611 GINT_TO_POINTER(1));
2613 /* remove address on To: and that of current account */
2614 for (cur = cc_list; cur != NULL; ) {
2615 GSList *next = cur->next;
2618 addr = g_strdup(cur->data);
2619 extract_address(addr);
2621 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2622 cc_list = g_slist_remove(cc_list, cur->data);
2624 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2628 hash_free_strings(to_table);
2629 g_hash_table_destroy(to_table);
2632 for (cur = cc_list; cur != NULL; cur = cur->next)
2633 compose_entry_append(compose, (gchar *)cur->data,
2635 slist_free_strings(cc_list);
2636 g_slist_free(cc_list);
2641 #define SET_ENTRY(entry, str) \
2644 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2647 #define SET_ADDRESS(type, str) \
2650 compose_entry_append(compose, str, type); \
2653 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2655 g_return_if_fail(msginfo != NULL);
2657 SET_ENTRY(subject_entry, msginfo->subject);
2658 SET_ENTRY(from_name, msginfo->from);
2659 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2660 SET_ADDRESS(COMPOSE_CC, compose->cc);
2661 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2662 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2663 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2664 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2666 compose_update_priority_menu_item(compose);
2667 compose_update_privacy_system_menu_item(compose, FALSE);
2668 compose_show_first_last_header(compose, TRUE);
2674 static void compose_insert_sig(Compose *compose, gboolean replace)
2676 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2677 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2679 GtkTextIter iter, iter_end;
2681 gboolean prev_autowrap;
2684 g_return_if_fail(compose->account != NULL);
2686 prev_autowrap = compose->autowrap;
2687 compose->autowrap = FALSE;
2689 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2690 G_CALLBACK(compose_changed_cb),
2693 mark = gtk_text_buffer_get_insert(buffer);
2694 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2695 cur_pos = gtk_text_iter_get_offset (&iter);
2697 gtk_text_buffer_get_end_iter(buffer, &iter);
2699 if (replace && compose->sig_str) {
2701 GtkTextIter first_iter, start_iter, end_iter;
2703 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2705 if (compose->sig_str[0] == '\0')
2708 found = gtk_text_iter_forward_search(&first_iter,
2710 GTK_TEXT_SEARCH_TEXT_ONLY,
2711 &start_iter, &end_iter,
2715 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2720 g_free(compose->sig_str);
2721 compose->sig_str = compose_get_signature_str(compose);
2722 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2723 compose->sig_str = g_strdup("");
2725 cur_pos = gtk_text_iter_get_offset(&iter);
2726 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2728 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2729 gtk_text_iter_forward_char(&iter);
2730 gtk_text_iter_forward_char(&iter);
2731 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2732 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2734 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2735 cur_pos = gtk_text_buffer_get_char_count (buffer);
2737 /* put the cursor where it should be
2738 * either where the quote_fmt says, either before the signature */
2739 if (compose->set_cursor_pos < 0)
2740 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2742 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2743 compose->set_cursor_pos);
2745 gtk_text_buffer_place_cursor(buffer, &iter);
2746 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2747 G_CALLBACK(compose_changed_cb),
2750 compose->autowrap = prev_autowrap;
2751 if (compose->autowrap)
2752 compose_wrap_all(compose);
2755 static gchar *compose_get_signature_str(Compose *compose)
2757 gchar *sig_body = NULL;
2758 gchar *sig_str = NULL;
2759 gchar *utf8_sig_str = NULL;
2761 g_return_val_if_fail(compose->account != NULL, NULL);
2763 if (!compose->account->sig_path)
2766 if (compose->account->sig_type == SIG_FILE) {
2767 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2768 g_warning("can't open signature file: %s\n",
2769 compose->account->sig_path);
2774 if (compose->account->sig_type == SIG_COMMAND)
2775 sig_body = get_command_output(compose->account->sig_path);
2779 tmp = file_read_to_str(compose->account->sig_path);
2782 sig_body = normalize_newlines(tmp);
2786 if (compose->account->sig_sep) {
2787 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2791 sig_str = g_strconcat("\n\n", sig_body, NULL);
2794 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2795 utf8_sig_str = sig_str;
2797 utf8_sig_str = conv_codeset_strdup
2798 (sig_str, conv_get_locale_charset_str_no_utf8(),
2804 return utf8_sig_str;
2807 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2810 GtkTextBuffer *buffer;
2813 const gchar *cur_encoding;
2814 gchar buf[BUFFSIZE];
2817 gboolean prev_autowrap;
2818 gboolean badtxt = FALSE;
2820 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2822 if ((fp = g_fopen(file, "rb")) == NULL) {
2823 FILE_OP_ERROR(file, "fopen");
2824 return COMPOSE_INSERT_READ_ERROR;
2827 prev_autowrap = compose->autowrap;
2828 compose->autowrap = FALSE;
2830 text = GTK_TEXT_VIEW(compose->text);
2831 buffer = gtk_text_view_get_buffer(text);
2832 mark = gtk_text_buffer_get_insert(buffer);
2833 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2835 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2836 G_CALLBACK(text_inserted),
2839 cur_encoding = conv_get_locale_charset_str_no_utf8();
2841 while (fgets(buf, sizeof(buf), fp) != NULL) {
2844 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2845 str = g_strdup(buf);
2847 str = conv_codeset_strdup
2848 (buf, cur_encoding, CS_INTERNAL);
2851 /* strip <CR> if DOS/Windows file,
2852 replace <CR> with <LF> if Macintosh file. */
2855 if (len > 0 && str[len - 1] != '\n') {
2857 if (str[len] == '\r') str[len] = '\n';
2860 gtk_text_buffer_insert(buffer, &iter, str, -1);
2864 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2865 G_CALLBACK(text_inserted),
2867 compose->autowrap = prev_autowrap;
2868 if (compose->autowrap)
2869 compose_wrap_all(compose);
2874 return COMPOSE_INSERT_INVALID_CHARACTER;
2876 return COMPOSE_INSERT_SUCCESS;
2879 static void compose_attach_append(Compose *compose, const gchar *file,
2880 const gchar *filename,
2881 const gchar *content_type)
2889 GtkListStore *store;
2891 gboolean has_binary = FALSE;
2893 if (!is_file_exist(file)) {
2894 g_warning("File %s doesn't exist\n", filename);
2897 if ((size = get_file_size(file)) < 0) {
2898 g_warning("Can't get file size of %s\n", filename);
2902 alertpanel_notice(_("File %s is empty."), filename);
2905 if ((fp = g_fopen(file, "rb")) == NULL) {
2906 alertpanel_error(_("Can't read %s."), filename);
2911 ainfo = g_new0(AttachInfo, 1);
2912 auto_ainfo = g_auto_pointer_new_with_free
2913 (ainfo, (GFreeFunc) compose_attach_info_free);
2914 ainfo->file = g_strdup(file);
2917 ainfo->content_type = g_strdup(content_type);
2918 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2920 MsgFlags flags = {0, 0};
2922 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2923 ainfo->encoding = ENC_7BIT;
2925 ainfo->encoding = ENC_8BIT;
2927 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2928 if (msginfo && msginfo->subject)
2929 name = g_strdup(msginfo->subject);
2931 name = g_path_get_basename(filename ? filename : file);
2933 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2935 procmsg_msginfo_free(msginfo);
2937 if (!g_ascii_strncasecmp(content_type, "text", 4))
2938 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2940 ainfo->encoding = ENC_BASE64;
2941 name = g_path_get_basename(filename ? filename : file);
2942 ainfo->name = g_strdup(name);
2946 ainfo->content_type = procmime_get_mime_type(file);
2947 if (!ainfo->content_type) {
2948 ainfo->content_type =
2949 g_strdup("application/octet-stream");
2950 ainfo->encoding = ENC_BASE64;
2951 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2953 procmime_get_encoding_for_text_file(file, &has_binary);
2955 ainfo->encoding = ENC_BASE64;
2956 name = g_path_get_basename(filename ? filename : file);
2957 ainfo->name = g_strdup(name);
2961 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2962 g_free(ainfo->content_type);
2963 ainfo->content_type = g_strdup("application/octet-stream");
2967 size_text = to_human_readable(size);
2969 store = GTK_LIST_STORE(gtk_tree_view_get_model
2970 (GTK_TREE_VIEW(compose->attach_clist)));
2972 gtk_list_store_append(store, &iter);
2973 gtk_list_store_set(store, &iter,
2974 COL_MIMETYPE, ainfo->content_type,
2975 COL_SIZE, size_text,
2976 COL_NAME, ainfo->name,
2978 COL_AUTODATA, auto_ainfo,
2981 g_auto_pointer_free(auto_ainfo);
2984 static void compose_use_signing(Compose *compose, gboolean use_signing)
2986 GtkItemFactory *ifactory;
2987 GtkWidget *menuitem = NULL;
2989 compose->use_signing = use_signing;
2990 ifactory = gtk_item_factory_from_widget(compose->menubar);
2991 menuitem = gtk_item_factory_get_item
2992 (ifactory, "/Options/Sign");
2993 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2997 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2999 GtkItemFactory *ifactory;
3000 GtkWidget *menuitem = NULL;
3002 compose->use_encryption = use_encryption;
3003 ifactory = gtk_item_factory_from_widget(compose->menubar);
3004 menuitem = gtk_item_factory_get_item
3005 (ifactory, "/Options/Encrypt");
3007 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3011 #define NEXT_PART_NOT_CHILD(info) \
3013 node = info->node; \
3014 while (node->children) \
3015 node = g_node_last_child(node); \
3016 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3019 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3023 MimeInfo *firsttext = NULL;
3024 MimeInfo *encrypted = NULL;
3027 const gchar *partname = NULL;
3029 mimeinfo = procmime_scan_message(msginfo);
3030 if (!mimeinfo) return;
3032 if (mimeinfo->node->children == NULL) {
3033 procmime_mimeinfo_free_all(mimeinfo);
3037 /* find first content part */
3038 child = (MimeInfo *) mimeinfo->node->children->data;
3039 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3040 child = (MimeInfo *)child->node->children->data;
3042 if (child->type == MIMETYPE_TEXT) {
3044 debug_print("First text part found\n");
3045 } else if (compose->mode == COMPOSE_REEDIT &&
3046 child->type == MIMETYPE_APPLICATION &&
3047 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3048 encrypted = (MimeInfo *)child->node->parent->data;
3051 child = (MimeInfo *) mimeinfo->node->children->data;
3052 while (child != NULL) {
3053 if (child == encrypted) {
3054 /* skip this part of tree */
3055 NEXT_PART_NOT_CHILD(child);
3059 if (child->type == MIMETYPE_MULTIPART) {
3060 /* get the actual content */
3061 child = procmime_mimeinfo_next(child);
3065 if (child == firsttext) {
3066 child = procmime_mimeinfo_next(child);
3070 outfile = procmime_get_tmp_file_name(child);
3071 if (procmime_get_part(outfile, child) < 0)
3072 g_warning("Can't get the part of multipart message.");
3074 gchar *content_type;
3076 content_type = procmime_get_content_type_str(child->type, child->subtype);
3078 /* if we meet a pgp signature, we don't attach it, but
3079 * we force signing. */
3080 if (strcmp(content_type, "application/pgp-signature")) {
3081 partname = procmime_mimeinfo_get_parameter(child, "filename");
3082 if (partname == NULL)
3083 partname = procmime_mimeinfo_get_parameter(child, "name");
3084 if (partname == NULL)
3086 compose_attach_append(compose, outfile,
3087 partname, content_type);
3089 compose_force_signing(compose, compose->account);
3091 g_free(content_type);
3094 NEXT_PART_NOT_CHILD(child);
3096 procmime_mimeinfo_free_all(mimeinfo);
3099 #undef NEXT_PART_NOT_CHILD
3104 WAIT_FOR_INDENT_CHAR,
3105 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3108 /* return indent length, we allow:
3109 indent characters followed by indent characters or spaces/tabs,
3110 alphabets and numbers immediately followed by indent characters,
3111 and the repeating sequences of the above
3112 If quote ends with multiple spaces, only the first one is included. */
3113 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3114 const GtkTextIter *start, gint *len)
3116 GtkTextIter iter = *start;
3120 IndentState state = WAIT_FOR_INDENT_CHAR;
3123 gint alnum_count = 0;
3124 gint space_count = 0;
3127 if (prefs_common.quote_chars == NULL) {
3131 while (!gtk_text_iter_ends_line(&iter)) {
3132 wc = gtk_text_iter_get_char(&iter);
3133 if (g_unichar_iswide(wc))
3135 clen = g_unichar_to_utf8(wc, ch);
3139 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3140 is_space = g_unichar_isspace(wc);
3142 if (state == WAIT_FOR_INDENT_CHAR) {
3143 if (!is_indent && !g_unichar_isalnum(wc))
3146 quote_len += alnum_count + space_count + 1;
3147 alnum_count = space_count = 0;
3148 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3151 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3152 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3156 else if (is_indent) {
3157 quote_len += alnum_count + space_count + 1;
3158 alnum_count = space_count = 0;
3161 state = WAIT_FOR_INDENT_CHAR;
3165 gtk_text_iter_forward_char(&iter);
3168 if (quote_len > 0 && space_count > 0)
3174 if (quote_len > 0) {
3176 gtk_text_iter_forward_chars(&iter, quote_len);
3177 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3183 /* return TRUE if the line is itemized */
3184 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3185 const GtkTextIter *start)
3187 GtkTextIter iter = *start;
3192 if (gtk_text_iter_ends_line(&iter))
3196 wc = gtk_text_iter_get_char(&iter);
3197 if (!g_unichar_isspace(wc))
3199 gtk_text_iter_forward_char(&iter);
3200 if (gtk_text_iter_ends_line(&iter))
3204 clen = g_unichar_to_utf8(wc, ch);
3208 if (!strchr("*-+", ch[0]))
3211 gtk_text_iter_forward_char(&iter);
3212 if (gtk_text_iter_ends_line(&iter))
3214 wc = gtk_text_iter_get_char(&iter);
3215 if (g_unichar_isspace(wc))
3221 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3222 const GtkTextIter *start,
3223 GtkTextIter *break_pos,
3227 GtkTextIter iter = *start, line_end = *start;
3228 PangoLogAttr *attrs;
3235 gboolean can_break = FALSE;
3236 gboolean do_break = FALSE;
3237 gboolean was_white = FALSE;
3238 gboolean prev_dont_break = FALSE;
3240 gtk_text_iter_forward_to_line_end(&line_end);
3241 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3242 len = g_utf8_strlen(str, -1);
3243 /* g_print("breaking line: %d: %s (len = %d)\n",
3244 gtk_text_iter_get_line(&iter), str, len); */
3245 attrs = g_new(PangoLogAttr, len + 1);
3247 pango_default_break(str, -1, NULL, attrs, len + 1);
3251 /* skip quote and leading spaces */
3252 for (i = 0; *p != '\0' && i < len; i++) {
3255 wc = g_utf8_get_char(p);
3256 if (i >= quote_len && !g_unichar_isspace(wc))
3258 if (g_unichar_iswide(wc))
3260 else if (*p == '\t')
3264 p = g_utf8_next_char(p);
3267 for (; *p != '\0' && i < len; i++) {
3268 PangoLogAttr *attr = attrs + i;
3272 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3275 was_white = attr->is_white;
3277 /* don't wrap URI */
3278 if ((uri_len = get_uri_len(p)) > 0) {
3280 if (pos > 0 && col > max_col) {
3290 wc = g_utf8_get_char(p);
3291 if (g_unichar_iswide(wc)) {
3293 if (prev_dont_break && can_break && attr->is_line_break)
3295 } else if (*p == '\t')
3299 if (pos > 0 && col > max_col) {
3304 if (*p == '-' || *p == '/')
3305 prev_dont_break = TRUE;
3307 prev_dont_break = FALSE;
3309 p = g_utf8_next_char(p);
3313 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3318 *break_pos = *start;
3319 gtk_text_iter_set_line_offset(break_pos, pos);
3324 static gboolean compose_join_next_line(Compose *compose,
3325 GtkTextBuffer *buffer,
3327 const gchar *quote_str)
3329 GtkTextIter iter_ = *iter, cur, prev, next, end;
3330 PangoLogAttr attrs[3];
3332 gchar *next_quote_str;
3335 gboolean keep_cursor = FALSE;
3337 if (!gtk_text_iter_forward_line(&iter_) ||
3338 gtk_text_iter_ends_line(&iter_))
3341 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3343 if ((quote_str || next_quote_str) &&
3344 strcmp2(quote_str, next_quote_str) != 0) {
3345 g_free(next_quote_str);
3348 g_free(next_quote_str);
3351 if (quote_len > 0) {
3352 gtk_text_iter_forward_chars(&end, quote_len);
3353 if (gtk_text_iter_ends_line(&end))
3357 /* don't join itemized lines */
3358 if (compose_is_itemized(buffer, &end))
3361 /* don't join signature separator */
3362 if (compose_is_sig_separator(compose, buffer, &iter_))
3365 /* delete quote str */
3367 gtk_text_buffer_delete(buffer, &iter_, &end);
3369 /* don't join line breaks put by the user */
3371 gtk_text_iter_backward_char(&cur);
3372 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3373 gtk_text_iter_forward_char(&cur);
3377 gtk_text_iter_forward_char(&cur);
3378 /* delete linebreak and extra spaces */
3379 while (gtk_text_iter_backward_char(&cur)) {
3380 wc1 = gtk_text_iter_get_char(&cur);
3381 if (!g_unichar_isspace(wc1))
3386 while (!gtk_text_iter_ends_line(&cur)) {
3387 wc1 = gtk_text_iter_get_char(&cur);
3388 if (!g_unichar_isspace(wc1))
3390 gtk_text_iter_forward_char(&cur);
3393 if (!gtk_text_iter_equal(&prev, &next)) {
3396 mark = gtk_text_buffer_get_insert(buffer);
3397 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3398 if (gtk_text_iter_equal(&prev, &cur))
3400 gtk_text_buffer_delete(buffer, &prev, &next);
3404 /* insert space if required */
3405 gtk_text_iter_backward_char(&prev);
3406 wc1 = gtk_text_iter_get_char(&prev);
3407 wc2 = gtk_text_iter_get_char(&next);
3408 gtk_text_iter_forward_char(&next);
3409 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3410 pango_default_break(str, -1, NULL, attrs, 3);
3411 if (!attrs[1].is_line_break ||
3412 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3413 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3415 gtk_text_iter_backward_char(&iter_);
3416 gtk_text_buffer_place_cursor(buffer, &iter_);
3425 #define ADD_TXT_POS(bp_, ep_, pti_) \
3426 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3427 last = last->next; \
3428 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3429 last->next = NULL; \
3431 g_warning("alloc error scanning URIs\n"); \
3434 static gboolean automatic_break = FALSE;
3435 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3437 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3438 GtkTextBuffer *buffer;
3439 GtkTextIter iter, break_pos, end_of_line;
3440 gchar *quote_str = NULL;
3442 gboolean wrap_quote = prefs_common.linewrap_quote;
3443 gboolean prev_autowrap = compose->autowrap;
3444 gint startq_offset = -1, noq_offset = -1;
3445 gint uri_start = -1, uri_stop = -1;
3446 gint nouri_start = -1, nouri_stop = -1;
3447 gint num_blocks = 0;
3448 gint quotelevel = -1;
3450 compose->autowrap = FALSE;
3452 buffer = gtk_text_view_get_buffer(text);
3453 undo_wrapping(compose->undostruct, TRUE);
3458 mark = gtk_text_buffer_get_insert(buffer);
3459 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3462 /* move to paragraph start */
3463 gtk_text_iter_set_line_offset(&iter, 0);
3464 if (gtk_text_iter_ends_line(&iter)) {
3465 while (gtk_text_iter_ends_line(&iter) &&
3466 gtk_text_iter_forward_line(&iter))
3469 while (gtk_text_iter_backward_line(&iter)) {
3470 if (gtk_text_iter_ends_line(&iter)) {
3471 gtk_text_iter_forward_line(&iter);
3477 /* go until paragraph end (empty line) */
3479 while (!gtk_text_iter_ends_line(&iter)) {
3480 gchar *scanpos = NULL;
3481 /* parse table - in order of priority */
3483 const gchar *needle; /* token */
3485 /* token search function */
3486 gchar *(*search) (const gchar *haystack,
3487 const gchar *needle);
3488 /* part parsing function */
3489 gboolean (*parse) (const gchar *start,
3490 const gchar *scanpos,
3494 /* part to URI function */
3495 gchar *(*build_uri) (const gchar *bp,
3499 static struct table parser[] = {
3500 {"http://", strcasestr, get_uri_part, make_uri_string},
3501 {"https://", strcasestr, get_uri_part, make_uri_string},
3502 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3503 {"www.", strcasestr, get_uri_part, make_http_string},
3504 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3505 {"@", strcasestr, get_email_part, make_email_string}
3507 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3508 gint last_index = PARSE_ELEMS;
3510 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3513 if (!prev_autowrap && num_blocks == 0) {
3515 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3516 G_CALLBACK(text_inserted),
3519 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3522 uri_start = uri_stop = -1;
3524 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3528 if (startq_offset == -1) {
3529 startq_offset = gtk_text_iter_get_offset(&iter);
3533 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3534 if (startq_offset == -1)
3535 startq_offset = gtk_text_iter_get_offset(&iter);
3536 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3537 if (quotelevel > 2) {
3538 /* recycle colors */
3539 if (prefs_common.recycle_quote_colors)
3545 if (startq_offset == -1)
3546 noq_offset = gtk_text_iter_get_offset(&iter);
3550 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3553 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3554 prefs_common.linewrap_len,
3556 GtkTextIter prev, next, cur;
3558 if (prev_autowrap != FALSE || force) {
3559 automatic_break = TRUE;
3560 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3561 automatic_break = FALSE;
3562 } else if (quote_str && wrap_quote) {
3563 automatic_break = TRUE;
3564 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3565 automatic_break = FALSE;
3568 /* remove trailing spaces */
3570 gtk_text_iter_backward_char(&cur);
3572 while (!gtk_text_iter_starts_line(&cur)) {
3575 gtk_text_iter_backward_char(&cur);
3576 wc = gtk_text_iter_get_char(&cur);
3577 if (!g_unichar_isspace(wc))
3581 if (!gtk_text_iter_equal(&prev, &next)) {
3582 gtk_text_buffer_delete(buffer, &prev, &next);
3584 gtk_text_iter_forward_char(&break_pos);
3588 gtk_text_buffer_insert(buffer, &break_pos,
3592 compose_join_next_line(compose, buffer, &iter, quote_str);
3594 /* move iter to current line start */
3595 gtk_text_iter_set_line_offset(&iter, 0);
3602 /* move iter to next line start */
3607 if (!prev_autowrap && num_blocks > 0) {
3609 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3610 G_CALLBACK(text_inserted),
3614 while (!gtk_text_iter_ends_line(&end_of_line)) {
3615 gtk_text_iter_forward_char(&end_of_line);
3617 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3619 nouri_start = gtk_text_iter_get_offset(&iter);
3620 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3622 walk_pos = gtk_text_iter_get_offset(&iter);
3623 /* FIXME: this looks phony. scanning for anything in the parse table */
3624 for (n = 0; n < PARSE_ELEMS; n++) {
3627 tmp = parser[n].search(walk, parser[n].needle);
3629 if (scanpos == NULL || tmp < scanpos) {
3638 /* check if URI can be parsed */
3639 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3640 (const gchar **)&ep, FALSE)
3641 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3645 strlen(parser[last_index].needle);
3648 uri_start = walk_pos + (bp - o_walk);
3649 uri_stop = walk_pos + (ep - o_walk);
3653 gtk_text_iter_forward_line(&iter);
3656 if (startq_offset != -1) {
3657 GtkTextIter startquote, endquote;
3658 gtk_text_buffer_get_iter_at_offset(
3659 buffer, &startquote, startq_offset);
3661 switch (quotelevel) {
3662 case 0: gtk_text_buffer_apply_tag_by_name(
3663 buffer, "quote0", &startquote, &endquote);
3665 case 1: gtk_text_buffer_apply_tag_by_name(
3666 buffer, "quote1", &startquote, &endquote);
3668 case 2: gtk_text_buffer_apply_tag_by_name(
3669 buffer, "quote2", &startquote, &endquote);
3673 } else if (noq_offset != -1) {
3674 GtkTextIter startnoquote, endnoquote;
3675 gtk_text_buffer_get_iter_at_offset(
3676 buffer, &startnoquote, noq_offset);
3678 gtk_text_buffer_remove_tag_by_name(
3679 buffer, "quote0", &startnoquote, &endnoquote);
3680 gtk_text_buffer_remove_tag_by_name(
3681 buffer, "quote1", &startnoquote, &endnoquote);
3682 gtk_text_buffer_remove_tag_by_name(
3683 buffer, "quote2", &startnoquote, &endnoquote);
3688 GtkTextIter nouri_start_iter, nouri_end_iter;
3689 gtk_text_buffer_get_iter_at_offset(
3690 buffer, &nouri_start_iter, nouri_start);
3691 gtk_text_buffer_get_iter_at_offset(
3692 buffer, &nouri_end_iter, nouri_stop);
3693 gtk_text_buffer_remove_tag_by_name(
3694 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3696 if (uri_start > 0 && uri_stop > 0) {
3697 GtkTextIter uri_start_iter, uri_end_iter;
3698 gtk_text_buffer_get_iter_at_offset(
3699 buffer, &uri_start_iter, uri_start);
3700 gtk_text_buffer_get_iter_at_offset(
3701 buffer, &uri_end_iter, uri_stop);
3702 gtk_text_buffer_apply_tag_by_name(
3703 buffer, "link", &uri_start_iter, &uri_end_iter);
3709 undo_wrapping(compose->undostruct, FALSE);
3710 compose->autowrap = prev_autowrap;
3713 void compose_action_cb(void *data)
3715 Compose *compose = (Compose *)data;
3716 compose_wrap_all(compose);
3719 static void compose_wrap_all(Compose *compose)
3721 compose_wrap_all_full(compose, FALSE);
3724 static void compose_wrap_all_full(Compose *compose, gboolean force)
3726 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3727 GtkTextBuffer *buffer;
3730 buffer = gtk_text_view_get_buffer(text);
3732 gtk_text_buffer_get_start_iter(buffer, &iter);
3733 while (!gtk_text_iter_is_end(&iter))
3734 compose_beautify_paragraph(compose, &iter, force);
3738 static void compose_set_title(Compose *compose)
3744 edited = compose->modified ? _(" [Edited]") : "";
3746 subject = gtk_editable_get_chars(
3747 GTK_EDITABLE(compose->subject_entry), 0, -1);
3749 if (subject && strlen(subject))
3750 str = g_strdup_printf(_("%s - Compose message%s"),
3753 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3754 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3760 * compose_current_mail_account:
3762 * Find a current mail account (the currently selected account, or the
3763 * default account, if a news account is currently selected). If a
3764 * mail account cannot be found, display an error message.
3766 * Return value: Mail account, or NULL if not found.
3768 static PrefsAccount *
3769 compose_current_mail_account(void)
3773 if (cur_account && cur_account->protocol != A_NNTP)
3776 ac = account_get_default();
3777 if (!ac || ac->protocol == A_NNTP) {
3778 alertpanel_error(_("Account for sending mail is not specified.\n"
3779 "Please select a mail account before sending."));
3786 #define QUOTE_IF_REQUIRED(out, str) \
3788 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3792 len = strlen(str) + 3; \
3793 if ((__tmp = alloca(len)) == NULL) { \
3794 g_warning("can't allocate memory\n"); \
3795 g_string_free(header, TRUE); \
3798 g_snprintf(__tmp, len, "\"%s\"", str); \
3803 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3804 g_warning("can't allocate memory\n"); \
3805 g_string_free(header, TRUE); \
3808 strcpy(__tmp, str); \
3814 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
3816 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3820 len = strlen(str) + 3; \
3821 if ((__tmp = alloca(len)) == NULL) { \
3822 g_warning("can't allocate memory\n"); \
3825 g_snprintf(__tmp, len, "\"%s\"", str); \
3830 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3831 g_warning("can't allocate memory\n"); \
3834 strcpy(__tmp, str); \
3840 static void compose_select_account(Compose *compose, PrefsAccount *account,
3843 GtkItemFactory *ifactory;
3846 g_return_if_fail(account != NULL);
3848 compose->account = account;
3850 if (account->name && *account->name) {
3852 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
3853 from = g_strdup_printf("%s <%s>",
3854 buf, account->address);
3855 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3857 from = g_strdup_printf("<%s>",
3859 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3864 compose_set_title(compose);
3866 ifactory = gtk_item_factory_from_widget(compose->menubar);
3868 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3869 menu_set_active(ifactory, "/Options/Sign", TRUE);
3871 menu_set_active(ifactory, "/Options/Sign", FALSE);
3872 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3873 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3875 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3877 activate_privacy_system(compose, account, FALSE);
3879 if (!init && compose->mode != COMPOSE_REDIRECT)
3880 compose_insert_sig(compose, TRUE);
3883 gboolean compose_check_for_valid_recipient(Compose *compose) {
3884 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3885 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3886 gboolean recipient_found = FALSE;
3890 /* free to and newsgroup list */
3891 slist_free_strings(compose->to_list);
3892 g_slist_free(compose->to_list);
3893 compose->to_list = NULL;
3895 slist_free_strings(compose->newsgroup_list);
3896 g_slist_free(compose->newsgroup_list);
3897 compose->newsgroup_list = NULL;
3899 /* search header entries for to and newsgroup entries */
3900 for (list = compose->header_list; list; list = list->next) {
3903 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3904 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3906 if (entry[0] != '\0') {
3907 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3908 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3909 compose->to_list = address_list_append(compose->to_list, entry);
3910 recipient_found = TRUE;
3913 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3914 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3915 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3916 recipient_found = TRUE;
3923 return recipient_found;
3926 static gboolean compose_check_for_set_recipients(Compose *compose)
3928 if (compose->account->set_autocc && compose->account->auto_cc) {
3929 gboolean found_other = FALSE;
3931 /* search header entries for to and newsgroup entries */
3932 for (list = compose->header_list; list; list = list->next) {
3935 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3936 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3938 if (strcmp(entry, compose->account->auto_cc)
3939 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3949 if (compose->batch) {
3950 gtk_widget_show_all(compose->window);
3952 aval = alertpanel(_("Send"),
3953 _("The only recipient is the default CC address. Send anyway?"),
3954 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3955 if (aval != G_ALERTALTERNATE)
3959 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3960 gboolean found_other = FALSE;
3962 /* search header entries for to and newsgroup entries */
3963 for (list = compose->header_list; list; list = list->next) {
3966 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3967 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3969 if (strcmp(entry, compose->account->auto_cc)
3970 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3980 if (compose->batch) {
3981 gtk_widget_show_all(compose->window);
3983 aval = alertpanel(_("Send"),
3984 _("The only recipient is the default BCC address. Send anyway?"),
3985 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3986 if (aval != G_ALERTALTERNATE)
3993 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3997 if (compose_check_for_valid_recipient(compose) == FALSE) {
3998 if (compose->batch) {
3999 gtk_widget_show_all(compose->window);
4001 alertpanel_error(_("Recipient is not specified."));
4005 if (compose_check_for_set_recipients(compose) == FALSE) {
4009 if (!compose->batch) {
4010 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4011 if (*str == '\0' && check_subject == TRUE) {
4014 aval = alertpanel(_("Send"),
4015 _("Subject is empty. Send it anyway?"),
4016 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4017 if (aval != G_ALERTALTERNATE)
4025 gint compose_send(Compose *compose)
4028 FolderItem *folder = NULL;
4030 gchar *msgpath = NULL;
4031 gboolean discard_window = FALSE;
4032 gchar *errstr = NULL;
4033 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4034 || compose->batch == TRUE)
4035 discard_window = TRUE;
4037 compose_allow_user_actions (compose, FALSE);
4038 compose->sending = TRUE;
4040 if (compose_check_entries(compose, TRUE) == FALSE) {
4041 if (compose->batch) {
4042 gtk_widget_show_all(compose->window);
4047 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
4050 if (compose->batch) {
4051 gtk_widget_show_all(compose->window);
4054 alertpanel_error(_("Could not queue message for sending:\n\n"
4055 "Charset conversion failed."));
4056 } else if (val == -3) {
4057 alertpanel_error(_("Could not queue message for sending:\n\n"
4058 "Signature failed."));
4059 } else if (val == -2 && errno != 0) {
4060 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4062 alertpanel_error(_("Could not queue message for sending."));
4067 if (discard_window) {
4068 compose->sending = FALSE;
4069 compose_close(compose);
4070 /* No more compose access in the normal codepath
4071 * after this point! */
4076 alertpanel_error(_("The message was queued but could not be "
4077 "sent.\nUse \"Send queued messages\" from "
4078 "the main window to retry."));
4079 if (!discard_window) {
4085 if (msgpath == NULL) {
4086 msgpath = folder_item_fetch_msg(folder, msgnum);
4087 val = procmsg_send_message_queue(msgpath, &errstr);
4090 val = procmsg_send_message_queue(msgpath, &errstr);
4094 if (!discard_window) {
4095 compose->sending = FALSE;
4096 compose_allow_user_actions (compose, TRUE);
4098 folder_item_remove_msg(folder, msgnum);
4099 folder_item_scan(folder);
4104 folder_item_remove_msg(folder, msgnum);
4105 folder_item_scan(folder);
4106 if (!discard_window)
4107 compose_close(compose);
4110 gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
4111 "the main window to retry."), errstr);
4113 alertpanel_error_log(tmp);
4116 alertpanel_error_log(_("The message was queued but could not be "
4117 "sent.\nUse \"Send queued messages\" from "
4118 "the main window to retry."));
4120 if (!discard_window) {
4129 compose_allow_user_actions (compose, TRUE);
4130 compose->sending = FALSE;
4131 compose->modified = TRUE;
4136 static gboolean compose_use_attach(Compose *compose)
4138 GtkTreeModel *model = gtk_tree_view_get_model
4139 (GTK_TREE_VIEW(compose->attach_clist));
4140 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4143 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4146 gchar buf[BUFFSIZE];
4148 gboolean first_to_address;
4149 gboolean first_cc_address;
4151 ComposeHeaderEntry *headerentry;
4152 const gchar *headerentryname;
4156 debug_print("Writing redirect header\n");
4158 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4159 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4161 first_to_address = TRUE;
4162 for (list = compose->header_list; list; list = list->next) {
4163 headerentry = ((ComposeHeaderEntry *)list->data);
4164 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4166 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4167 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4168 Xstrdup_a(str, entstr, return -1);
4170 if (str[0] != '\0') {
4171 compose_convert_header
4172 (compose, buf, sizeof(buf), str,
4173 strlen("Resent-To") + 2, TRUE);
4175 if (first_to_address) {
4176 fprintf(fp, "Resent-To: ");
4177 first_to_address = FALSE;
4181 fprintf(fp, "%s", buf);
4185 if (!first_to_address) {
4189 first_cc_address = TRUE;
4190 for (list = compose->header_list; list; list = list->next) {
4191 headerentry = ((ComposeHeaderEntry *)list->data);
4192 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4194 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4195 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4196 Xstrdup_a(str, strg, return -1);
4198 if (str[0] != '\0') {
4199 compose_convert_header
4200 (compose, buf, sizeof(buf), str,
4201 strlen("Resent-Cc") + 2, TRUE);
4203 if (first_cc_address) {
4204 fprintf(fp, "Resent-Cc: ");
4205 first_cc_address = FALSE;
4209 fprintf(fp, "%s", buf);
4213 if (!first_cc_address) {
4220 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4222 gchar buf[BUFFSIZE];
4224 const gchar *entstr;
4225 /* struct utsname utsbuf; */
4227 g_return_val_if_fail(fp != NULL, -1);
4228 g_return_val_if_fail(compose->account != NULL, -1);
4229 g_return_val_if_fail(compose->account->address != NULL, -1);
4232 get_rfc822_date(buf, sizeof(buf));
4233 fprintf(fp, "Resent-Date: %s\n", buf);
4236 if (compose->account->name && *compose->account->name) {
4237 compose_convert_header
4238 (compose, buf, sizeof(buf), compose->account->name,
4239 strlen("From: "), TRUE);
4240 fprintf(fp, "Resent-From: %s <%s>\n",
4241 buf, compose->account->address);
4243 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4246 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4247 if (*entstr != '\0') {
4248 Xstrdup_a(str, entstr, return -1);
4251 compose_convert_header(compose, buf, sizeof(buf), str,
4252 strlen("Subject: "), FALSE);
4253 fprintf(fp, "Subject: %s\n", buf);
4257 /* Resent-Message-ID */
4258 if (compose->account->gen_msgid) {
4259 generate_msgid(buf, sizeof(buf));
4260 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4261 compose->msgid = g_strdup(buf);
4264 compose_redirect_write_headers_from_headerlist(compose, fp);
4266 /* separator between header and body */
4272 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4276 gchar buf[BUFFSIZE];
4278 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4279 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4283 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4284 /* should filter returnpath, delivered-to */
4285 if (g_ascii_strncasecmp(buf, "Return-Path:",
4286 strlen("Return-Path:")) == 0 ||
4287 g_ascii_strncasecmp(buf, "Delivered-To:",
4288 strlen("Delivered-To:")) == 0 ||
4289 g_ascii_strncasecmp(buf, "Received:",
4290 strlen("Received:")) == 0 ||
4291 g_ascii_strncasecmp(buf, "Subject:",
4292 strlen("Subject:")) == 0 ||
4293 g_ascii_strncasecmp(buf, "X-UIDL:",
4294 strlen("X-UIDL:")) == 0)
4297 if (fputs(buf, fdest) == -1)
4300 if (!prefs_common.redirect_keep_from) {
4301 if (g_ascii_strncasecmp(buf, "From:",
4302 strlen("From:")) == 0) {
4303 fputs(" (by way of ", fdest);
4304 if (compose->account->name
4305 && *compose->account->name) {
4306 compose_convert_header
4307 (compose, buf, sizeof(buf),
4308 compose->account->name,
4311 fprintf(fdest, "%s <%s>",
4313 compose->account->address);
4315 fprintf(fdest, "%s",
4316 compose->account->address);
4321 if (fputs("\n", fdest) == -1)
4325 compose_redirect_write_headers(compose, fdest);
4327 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4328 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4341 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4343 GtkTextBuffer *buffer;
4344 GtkTextIter start, end;
4347 const gchar *out_codeset;
4348 EncodingType encoding;
4349 MimeInfo *mimemsg, *mimetext;
4352 /* create message MimeInfo */
4353 mimemsg = procmime_mimeinfo_new();
4354 mimemsg->type = MIMETYPE_MESSAGE;
4355 mimemsg->subtype = g_strdup("rfc822");
4356 mimemsg->content = MIMECONTENT_MEM;
4357 mimemsg->tmp = TRUE; /* must free content later */
4358 mimemsg->data.mem = compose_get_header(compose);
4360 /* Create text part MimeInfo */
4361 /* get all composed text */
4362 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4363 gtk_text_buffer_get_start_iter(buffer, &start);
4364 gtk_text_buffer_get_end_iter(buffer, &end);
4365 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4366 if (is_ascii_str(chars)) {
4369 out_codeset = CS_US_ASCII;
4370 encoding = ENC_7BIT;
4372 const gchar *src_codeset = CS_INTERNAL;
4374 out_codeset = conv_get_charset_str(compose->out_encoding);
4377 gchar *test_conv_global_out = NULL;
4378 gchar *test_conv_reply = NULL;
4380 /* automatic mode. be automatic. */
4381 codeconv_set_strict(TRUE);
4383 out_codeset = conv_get_outgoing_charset_str();
4385 debug_print("trying to convert to %s\n", out_codeset);
4386 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4389 if (!test_conv_global_out && compose->orig_charset
4390 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4391 out_codeset = compose->orig_charset;
4392 debug_print("failure; trying to convert to %s\n", out_codeset);
4393 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4396 if (!test_conv_global_out && !test_conv_reply) {
4398 out_codeset = CS_INTERNAL;
4399 debug_print("failure; finally using %s\n", out_codeset);
4401 g_free(test_conv_global_out);
4402 g_free(test_conv_reply);
4403 codeconv_set_strict(FALSE);
4406 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4407 out_codeset = CS_ISO_8859_1;
4409 if (prefs_common.encoding_method == CTE_BASE64)
4410 encoding = ENC_BASE64;
4411 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4412 encoding = ENC_QUOTED_PRINTABLE;
4413 else if (prefs_common.encoding_method == CTE_8BIT)
4414 encoding = ENC_8BIT;
4416 encoding = procmime_get_encoding_for_charset(out_codeset);
4418 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4419 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4421 if (action == COMPOSE_WRITE_FOR_SEND) {
4422 codeconv_set_strict(TRUE);
4423 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4424 codeconv_set_strict(FALSE);
4430 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4431 "to the specified %s charset.\n"
4432 "Send it as %s?"), out_codeset, src_codeset);
4433 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4434 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4437 if (aval != G_ALERTALTERNATE) {
4442 out_codeset = src_codeset;
4448 out_codeset = src_codeset;
4454 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4455 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4456 strstr(buf, "\nFrom ") != NULL) {
4457 encoding = ENC_QUOTED_PRINTABLE;
4461 mimetext = procmime_mimeinfo_new();
4462 mimetext->content = MIMECONTENT_MEM;
4463 mimetext->tmp = TRUE; /* must free content later */
4464 mimetext->data.mem = buf;
4465 mimetext->type = MIMETYPE_TEXT;
4466 mimetext->subtype = g_strdup("plain");
4467 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4468 g_strdup(out_codeset));
4469 /* protect trailing spaces when signing message */
4470 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4471 privacy_system_can_sign(compose->privacy_system)) {
4472 encoding = ENC_QUOTED_PRINTABLE;
4475 /* check for line length limit */
4476 if (action == COMPOSE_WRITE_FOR_SEND &&
4477 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4478 check_line_length(buf, 1000, &line) < 0) {
4482 msg = g_strdup_printf
4483 (_("Line %d exceeds the line length limit (998 bytes).\n"
4484 "The contents of the message might be broken on the way to the delivery.\n"
4486 "Send it anyway?"), line + 1);
4487 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4489 if (aval != G_ALERTALTERNATE) {
4494 if (encoding != ENC_UNKNOWN)
4495 procmime_encode_content(mimetext, encoding);
4497 /* append attachment parts */
4498 if (compose_use_attach(compose)) {
4499 MimeInfo *mimempart;
4500 gchar *boundary = NULL;
4501 mimempart = procmime_mimeinfo_new();
4502 mimempart->content = MIMECONTENT_EMPTY;
4503 mimempart->type = MIMETYPE_MULTIPART;
4504 mimempart->subtype = g_strdup("mixed");
4508 boundary = generate_mime_boundary(NULL);
4509 } while (strstr(buf, boundary) != NULL);
4511 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4514 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4516 g_node_append(mimempart->node, mimetext->node);
4517 g_node_append(mimemsg->node, mimempart->node);
4519 compose_add_attachments(compose, mimempart);
4521 g_node_append(mimemsg->node, mimetext->node);
4523 /* sign message if sending */
4524 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4525 privacy_system_can_sign(compose->privacy_system))
4526 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4529 procmime_write_mimeinfo(mimemsg, fp);
4531 procmime_mimeinfo_free_all(mimemsg);
4536 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4538 GtkTextBuffer *buffer;
4539 GtkTextIter start, end;
4544 if ((fp = g_fopen(file, "wb")) == NULL) {
4545 FILE_OP_ERROR(file, "fopen");
4549 /* chmod for security */
4550 if (change_file_mode_rw(fp, file) < 0) {
4551 FILE_OP_ERROR(file, "chmod");
4552 g_warning("can't change file mode\n");
4555 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4556 gtk_text_buffer_get_start_iter(buffer, &start);
4557 gtk_text_buffer_get_end_iter(buffer, &end);
4558 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4560 chars = conv_codeset_strdup
4561 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4564 if (!chars) return -1;
4567 len = strlen(chars);
4568 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4569 FILE_OP_ERROR(file, "fwrite");
4578 if (fclose(fp) == EOF) {
4579 FILE_OP_ERROR(file, "fclose");
4586 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4589 MsgInfo *msginfo = compose->targetinfo;
4591 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4592 if (!msginfo) return -1;
4594 if (!force && MSG_IS_LOCKED(msginfo->flags))
4597 item = msginfo->folder;
4598 g_return_val_if_fail(item != NULL, -1);
4600 if (procmsg_msg_exist(msginfo) &&
4601 (folder_has_parent_of_type(item, F_QUEUE) ||
4602 folder_has_parent_of_type(item, F_DRAFT)
4603 || msginfo == compose->autosaved_draft)) {
4604 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4605 g_warning("can't remove the old message\n");
4613 void compose_remove_draft(Compose *compose)
4616 MsgInfo *msginfo = compose->targetinfo;
4617 drafts = account_get_special_folder(compose->account, F_DRAFT);
4619 if (procmsg_msg_exist(msginfo)) {
4620 folder_item_remove_msg(drafts, msginfo->msgnum);
4625 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
4626 gboolean remove_reedit_target)
4628 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
4630 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
4631 gchar **msgpath, gboolean check_subject,
4632 gboolean remove_reedit_target)
4639 static gboolean lock = FALSE;
4640 PrefsAccount *mailac = NULL, *newsac = NULL;
4642 debug_print("queueing message...\n");
4643 g_return_val_if_fail(compose->account != NULL, -1);
4647 if (compose_check_entries(compose, check_subject) == FALSE) {
4649 if (compose->batch) {
4650 gtk_widget_show_all(compose->window);
4655 if (!compose->to_list && !compose->newsgroup_list) {
4656 g_warning("can't get recipient list.");
4661 if (compose->to_list) {
4662 if (compose->account->protocol != A_NNTP)
4663 mailac = compose->account;
4664 else if (cur_account && cur_account->protocol != A_NNTP)
4665 mailac = cur_account;
4666 else if (!(mailac = compose_current_mail_account())) {
4668 alertpanel_error(_("No account for sending mails available!"));
4673 if (compose->newsgroup_list) {
4674 if (compose->account->protocol == A_NNTP)
4675 newsac = compose->account;
4676 else if (!newsac->protocol != A_NNTP) {
4678 alertpanel_error(_("No account for posting news available!"));
4683 /* write queue header */
4684 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4685 G_DIR_SEPARATOR, compose);
4686 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4687 FILE_OP_ERROR(tmp, "fopen");
4693 if (change_file_mode_rw(fp, tmp) < 0) {
4694 FILE_OP_ERROR(tmp, "chmod");
4695 g_warning("can't change file mode\n");
4698 /* queueing variables */
4699 fprintf(fp, "AF:\n");
4700 fprintf(fp, "NF:0\n");
4701 fprintf(fp, "PS:10\n");
4702 fprintf(fp, "SRH:1\n");
4703 fprintf(fp, "SFN:\n");
4704 fprintf(fp, "DSR:\n");
4706 fprintf(fp, "MID:<%s>\n", compose->msgid);
4708 fprintf(fp, "MID:\n");
4709 fprintf(fp, "CFG:\n");
4710 fprintf(fp, "PT:0\n");
4711 fprintf(fp, "S:%s\n", compose->account->address);
4712 fprintf(fp, "RQ:\n");
4714 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4716 fprintf(fp, "SSV:\n");
4718 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4720 fprintf(fp, "NSV:\n");
4721 fprintf(fp, "SSH:\n");
4722 /* write recepient list */
4723 if (compose->to_list) {
4724 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4725 for (cur = compose->to_list->next; cur != NULL;
4727 fprintf(fp, ",<%s>", (gchar *)cur->data);
4730 /* write newsgroup list */
4731 if (compose->newsgroup_list) {
4733 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4734 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4735 fprintf(fp, ",%s", (gchar *)cur->data);
4738 /* Sylpheed account IDs */
4740 fprintf(fp, "MAID:%d\n", mailac->account_id);
4742 fprintf(fp, "NAID:%d\n", newsac->account_id);
4745 if (compose->privacy_system != NULL) {
4746 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4747 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4748 if (compose->use_encryption) {
4750 if (mailac && mailac->encrypt_to_self) {
4751 GSList *tmp_list = g_slist_copy(compose->to_list);
4752 tmp_list = g_slist_append(tmp_list, compose->account->address);
4753 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
4754 g_slist_free(tmp_list);
4756 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4758 if (encdata != NULL) {
4759 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4760 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4761 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4763 } /* else we finally dont want to encrypt */
4765 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4766 /* and if encdata was null, it means there's been a problem in
4773 /* Save copy folder */
4774 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4775 gchar *savefolderid;
4777 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4778 fprintf(fp, "SCF:%s\n", savefolderid);
4779 g_free(savefolderid);
4781 /* Save copy folder */
4782 if (compose->return_receipt) {
4783 fprintf(fp, "RRCPT:1\n");
4785 /* Message-ID of message replying to */
4786 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4789 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4790 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4793 /* Message-ID of message forwarding to */
4794 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4797 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4798 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4802 /* end of headers */
4803 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
4805 if (compose->redirect_filename != NULL) {
4806 if (compose_redirect_write_to_file(compose, fp) < 0) {
4815 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4820 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4824 if (fclose(fp) == EOF) {
4825 FILE_OP_ERROR(tmp, "fclose");
4832 if (item && *item) {
4835 queue = account_get_special_folder(compose->account, F_QUEUE);
4838 g_warning("can't find queue folder\n");
4844 folder_item_scan(queue);
4845 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4846 g_warning("can't queue the message\n");
4853 if (msgpath == NULL) {
4859 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
4860 compose_remove_reedit_target(compose, FALSE);
4863 if ((msgnum != NULL) && (item != NULL)) {
4871 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4874 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4876 struct stat statbuf;
4877 gchar *type, *subtype;
4878 GtkTreeModel *model;
4881 model = gtk_tree_view_get_model(tree_view);
4883 if (!gtk_tree_model_get_iter_first(model, &iter))
4886 gtk_tree_model_get(model, &iter,
4890 mimepart = procmime_mimeinfo_new();
4891 mimepart->content = MIMECONTENT_FILE;
4892 mimepart->data.filename = g_strdup(ainfo->file);
4893 mimepart->tmp = FALSE; /* or we destroy our attachment */
4894 mimepart->offset = 0;
4896 stat(ainfo->file, &statbuf);
4897 mimepart->length = statbuf.st_size;
4899 type = g_strdup(ainfo->content_type);
4901 if (!strchr(type, '/')) {
4903 type = g_strdup("application/octet-stream");
4906 subtype = strchr(type, '/') + 1;
4907 *(subtype - 1) = '\0';
4908 mimepart->type = procmime_get_media_type(type);
4909 mimepart->subtype = g_strdup(subtype);
4912 if (mimepart->type == MIMETYPE_MESSAGE &&
4913 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4914 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4916 g_hash_table_insert(mimepart->typeparameters,
4917 g_strdup("name"), g_strdup(ainfo->name));
4918 g_hash_table_insert(mimepart->dispositionparameters,
4919 g_strdup("filename"), g_strdup(ainfo->name));
4920 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4923 if (compose->use_signing) {
4924 if (ainfo->encoding == ENC_7BIT)
4925 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4926 else if (ainfo->encoding == ENC_8BIT)
4927 ainfo->encoding = ENC_BASE64;
4930 procmime_encode_content(mimepart, ainfo->encoding);
4932 g_node_append(parent->node, mimepart->node);
4933 } while (gtk_tree_model_iter_next(model, &iter));
4936 #define IS_IN_CUSTOM_HEADER(header) \
4937 (compose->account->add_customhdr && \
4938 custom_header_find(compose->account->customhdr_list, header) != NULL)
4940 static void compose_add_headerfield_from_headerlist(Compose *compose,
4942 const gchar *fieldname,
4943 const gchar *seperator)
4945 gchar *str, *fieldname_w_colon, *trans_fieldname;
4946 gboolean add_field = FALSE;
4948 ComposeHeaderEntry *headerentry;
4949 const gchar * headerentryname;
4952 if (IS_IN_CUSTOM_HEADER(fieldname))
4955 debug_print("Adding %s-fields\n", fieldname);
4957 fieldstr = g_string_sized_new(64);
4959 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4960 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4962 for (list = compose->header_list; list; list = list->next) {
4963 headerentry = ((ComposeHeaderEntry *)list->data);
4964 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4966 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4967 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4969 if (str[0] != '\0') {
4971 g_string_append(fieldstr, seperator);
4972 g_string_append(fieldstr, str);
4981 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4982 compose_convert_header
4983 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4984 strlen(fieldname) + 2, TRUE);
4985 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4989 g_free(fieldname_w_colon);
4990 g_string_free(fieldstr, TRUE);
4995 static gchar *compose_get_header(Compose *compose)
4997 gchar buf[BUFFSIZE];
4998 const gchar *entry_str;
5002 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5004 gchar *from_name = NULL, *from_address = NULL;
5007 g_return_val_if_fail(compose->account != NULL, NULL);
5008 g_return_val_if_fail(compose->account->address != NULL, NULL);
5010 header = g_string_sized_new(64);
5013 if (compose->account->add_date) {
5014 get_rfc822_date(buf, sizeof(buf));
5015 g_string_append_printf(header, "Date: %s\n", buf);
5020 if (compose->account->name && *compose->account->name) {
5022 QUOTE_IF_REQUIRED(buf, compose->account->name);
5023 tmp = g_strdup_printf("%s <%s>",
5024 buf, compose->account->address);
5026 tmp = g_strdup_printf("%s",
5027 compose->account->address);
5029 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5030 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5032 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5033 from_address = g_strdup(compose->account->address);
5035 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5036 /* extract name and address */
5037 if (strstr(spec, " <") && strstr(spec, ">")) {
5038 from_address = g_strdup(strrchr(spec, '<')+1);
5039 *(strrchr(from_address, '>')) = '\0';
5040 from_name = g_strdup(spec);
5041 *(strrchr(from_name, '<')) = '\0';
5044 from_address = g_strdup(spec);
5051 if (from_name && *from_name) {
5052 compose_convert_header
5053 (compose, buf, sizeof(buf), from_name,
5054 strlen("From: "), TRUE);
5055 QUOTE_IF_REQUIRED(name, buf);
5057 g_string_append_printf(header, "From: %s <%s>\n",
5058 name, from_address);
5060 g_string_append_printf(header, "From: %s\n", from_address);
5063 g_free(from_address);
5066 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5069 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5072 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5075 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5078 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5080 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5083 compose_convert_header(compose, buf, sizeof(buf), str,
5084 strlen("Subject: "), FALSE);
5085 g_string_append_printf(header, "Subject: %s\n", buf);
5091 if (compose->account->gen_msgid) {
5092 generate_msgid(buf, sizeof(buf));
5093 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5094 compose->msgid = g_strdup(buf);
5097 if (compose->remove_references == FALSE) {
5099 if (compose->inreplyto && compose->to_list)
5100 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5103 if (compose->references)
5104 g_string_append_printf(header, "References: %s\n", compose->references);
5108 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5111 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5114 if (compose->account->organization &&
5115 strlen(compose->account->organization) &&
5116 !IS_IN_CUSTOM_HEADER("Organization")) {
5117 compose_convert_header(compose, buf, sizeof(buf),
5118 compose->account->organization,
5119 strlen("Organization: "), FALSE);
5120 g_string_append_printf(header, "Organization: %s\n", buf);
5123 /* Program version and system info */
5124 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5125 !compose->newsgroup_list) {
5126 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5128 gtk_major_version, gtk_minor_version, gtk_micro_version,
5131 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5132 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5134 gtk_major_version, gtk_minor_version, gtk_micro_version,
5138 /* custom headers */
5139 if (compose->account->add_customhdr) {
5142 for (cur = compose->account->customhdr_list; cur != NULL;
5144 CustomHeader *chdr = (CustomHeader *)cur->data;
5146 if (custom_header_is_allowed(chdr->name)) {
5147 compose_convert_header
5148 (compose, buf, sizeof(buf),
5149 chdr->value ? chdr->value : "",
5150 strlen(chdr->name) + 2, FALSE);
5151 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5157 switch (compose->priority) {
5158 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5159 "X-Priority: 1 (Highest)\n");
5161 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5162 "X-Priority: 2 (High)\n");
5164 case PRIORITY_NORMAL: break;
5165 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5166 "X-Priority: 4 (Low)\n");
5168 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5169 "X-Priority: 5 (Lowest)\n");
5171 default: debug_print("compose: priority unknown : %d\n",
5175 /* Request Return Receipt */
5176 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5177 if (compose->return_receipt) {
5178 if (compose->account->name
5179 && *compose->account->name) {
5180 compose_convert_header(compose, buf, sizeof(buf),
5181 compose->account->name,
5182 strlen("Disposition-Notification-To: "),
5184 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5186 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5190 /* get special headers */
5191 for (list = compose->header_list; list; list = list->next) {
5192 ComposeHeaderEntry *headerentry;
5195 gchar *headername_wcolon;
5196 gchar *headername_trans;
5199 gboolean standard_header = FALSE;
5201 headerentry = ((ComposeHeaderEntry *)list->data);
5203 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5204 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5209 if (!strstr(tmp, ":")) {
5210 headername_wcolon = g_strconcat(tmp, ":", NULL);
5211 headername = g_strdup(tmp);
5213 headername_wcolon = g_strdup(tmp);
5214 headername = g_strdup(strtok(tmp, ":"));
5218 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5219 Xstrdup_a(headervalue, entry_str, return NULL);
5220 subst_char(headervalue, '\r', ' ');
5221 subst_char(headervalue, '\n', ' ');
5222 string = std_headers;
5223 while (*string != NULL) {
5224 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5225 if (!strcmp(headername_trans,headername_wcolon))
5226 standard_header = TRUE;
5229 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5230 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5233 g_free(headername_wcolon);
5237 g_string_free(header, FALSE);
5242 #undef IS_IN_CUSTOM_HEADER
5244 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5245 gint header_len, gboolean addr_field)
5247 gchar *tmpstr = NULL;
5248 const gchar *out_codeset = NULL;
5250 g_return_if_fail(src != NULL);
5251 g_return_if_fail(dest != NULL);
5253 if (len < 1) return;
5255 tmpstr = g_strdup(src);
5257 subst_char(tmpstr, '\n', ' ');
5258 subst_char(tmpstr, '\r', ' ');
5261 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5262 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5263 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5268 codeconv_set_strict(TRUE);
5269 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5270 conv_get_charset_str(compose->out_encoding));
5271 codeconv_set_strict(FALSE);
5273 if (!dest || *dest == '\0') {
5274 gchar *test_conv_global_out = NULL;
5275 gchar *test_conv_reply = NULL;
5277 /* automatic mode. be automatic. */
5278 codeconv_set_strict(TRUE);
5280 out_codeset = conv_get_outgoing_charset_str();
5282 debug_print("trying to convert to %s\n", out_codeset);
5283 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5286 if (!test_conv_global_out && compose->orig_charset
5287 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5288 out_codeset = compose->orig_charset;
5289 debug_print("failure; trying to convert to %s\n", out_codeset);
5290 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5293 if (!test_conv_global_out && !test_conv_reply) {
5295 out_codeset = CS_INTERNAL;
5296 debug_print("finally using %s\n", out_codeset);
5298 g_free(test_conv_global_out);
5299 g_free(test_conv_reply);
5300 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5302 codeconv_set_strict(FALSE);
5307 static void compose_create_header_entry(Compose *compose)
5309 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5313 GList *combo_list = NULL;
5315 const gchar *header = NULL;
5316 ComposeHeaderEntry *headerentry;
5317 gboolean standard_header = FALSE;
5319 headerentry = g_new0(ComposeHeaderEntry, 1);
5322 combo = gtk_combo_new();
5324 while(*string != NULL) {
5325 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5328 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5329 g_list_free(combo_list);
5330 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5331 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5332 G_CALLBACK(compose_grab_focus_cb), compose);
5333 gtk_widget_show(combo);
5334 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5335 if (compose->header_last) {
5336 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5338 while (*string != NULL) {
5339 if (!strcmp(*string, last_header_entry))
5340 standard_header = TRUE;
5343 if (standard_header)
5344 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5346 if (!compose->header_last || !standard_header) {
5347 switch(compose->account->protocol) {
5349 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5352 header = prefs_common.trans_hdr ? _("To:") : "To:";
5357 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5359 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5360 G_CALLBACK(compose_grab_focus_cb), compose);
5363 entry = gtk_entry_new();
5364 gtk_widget_show(entry);
5365 gtk_tooltips_set_tip(compose->tooltips, entry,
5366 _("Use <tab> to autocomplete from addressbook"), NULL);
5367 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);
5369 g_signal_connect(G_OBJECT(entry), "key-press-event",
5370 G_CALLBACK(compose_headerentry_key_press_event_cb),
5372 g_signal_connect(G_OBJECT(entry), "changed",
5373 G_CALLBACK(compose_headerentry_changed_cb),
5375 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5376 G_CALLBACK(compose_grab_focus_cb), compose);
5379 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5380 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5381 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5382 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5383 G_CALLBACK(compose_header_drag_received_cb),
5385 g_signal_connect(G_OBJECT(entry), "drag-drop",
5386 G_CALLBACK(compose_drag_drop),
5389 address_completion_register_entry(GTK_ENTRY(entry));
5391 headerentry->compose = compose;
5392 headerentry->combo = combo;
5393 headerentry->entry = entry;
5394 headerentry->headernum = compose->header_nextrow;
5396 compose->header_nextrow++;
5397 compose->header_last = headerentry;
5400 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5402 ComposeHeaderEntry *last_header;
5404 last_header = compose->header_last;
5406 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5407 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5410 static GtkWidget *compose_create_header(Compose *compose)
5412 GtkWidget *from_optmenu_hbox;
5413 GtkWidget *header_scrolledwin;
5414 GtkWidget *header_table;
5418 /* header labels and entries */
5419 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5420 gtk_widget_show(header_scrolledwin);
5421 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5423 header_table = gtk_table_new(2, 2, FALSE);
5424 gtk_widget_show(header_table);
5425 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5426 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5427 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5430 /* option menu for selecting accounts */
5431 from_optmenu_hbox = compose_account_option_menu_create(compose);
5432 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5433 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5436 compose->header_table = header_table;
5437 compose->header_list = NULL;
5438 compose->header_nextrow = count;
5440 compose_create_header_entry(compose);
5442 compose->table = NULL;
5444 return header_scrolledwin ;
5447 GtkWidget *compose_create_attach(Compose *compose)
5449 GtkWidget *attach_scrwin;
5450 GtkWidget *attach_clist;
5452 GtkListStore *store;
5453 GtkCellRenderer *renderer;
5454 GtkTreeViewColumn *column;
5455 GtkTreeSelection *selection;
5457 /* attachment list */
5458 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5459 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5460 GTK_POLICY_AUTOMATIC,
5461 GTK_POLICY_AUTOMATIC);
5462 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5464 store = gtk_list_store_new(N_ATTACH_COLS,
5469 G_TYPE_AUTO_POINTER,
5471 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5472 (GTK_TREE_MODEL(store)));
5473 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5474 g_object_unref(store);
5476 renderer = gtk_cell_renderer_text_new();
5477 column = gtk_tree_view_column_new_with_attributes
5478 (_("Mime type"), renderer, "text",
5479 COL_MIMETYPE, NULL);
5480 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5482 renderer = gtk_cell_renderer_text_new();
5483 column = gtk_tree_view_column_new_with_attributes
5484 (_("Size"), renderer, "text",
5486 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5488 renderer = gtk_cell_renderer_text_new();
5489 column = gtk_tree_view_column_new_with_attributes
5490 (_("Name"), renderer, "text",
5492 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5494 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5495 prefs_common.enable_rules_hint);
5496 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5497 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5499 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5500 G_CALLBACK(attach_selected), compose);
5501 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5502 G_CALLBACK(attach_button_pressed), compose);
5503 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5504 G_CALLBACK(attach_key_pressed), compose);
5507 gtk_drag_dest_set(attach_clist,
5508 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5509 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5510 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5511 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5512 G_CALLBACK(compose_attach_drag_received_cb),
5514 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5515 G_CALLBACK(compose_drag_drop),
5518 compose->attach_scrwin = attach_scrwin;
5519 compose->attach_clist = attach_clist;
5521 return attach_scrwin;
5524 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5525 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5527 static GtkWidget *compose_create_others(Compose *compose)
5530 GtkWidget *savemsg_checkbtn;
5531 GtkWidget *savemsg_entry;
5532 GtkWidget *savemsg_select;
5535 gchar *folderidentifier;
5537 /* Table for settings */
5538 table = gtk_table_new(3, 1, FALSE);
5539 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5540 gtk_widget_show(table);
5541 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5544 /* Save Message to folder */
5545 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5546 gtk_widget_show(savemsg_checkbtn);
5547 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5548 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5549 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5551 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5552 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5554 savemsg_entry = gtk_entry_new();
5555 gtk_widget_show(savemsg_entry);
5556 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5557 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5558 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5559 G_CALLBACK(compose_grab_focus_cb), compose);
5560 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5561 folderidentifier = folder_item_get_identifier(account_get_special_folder
5562 (compose->account, F_OUTBOX));
5563 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5564 g_free(folderidentifier);
5567 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5568 gtk_widget_show(savemsg_select);
5569 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5570 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5571 G_CALLBACK(compose_savemsg_select_cb),
5576 compose->savemsg_checkbtn = savemsg_checkbtn;
5577 compose->savemsg_entry = savemsg_entry;
5582 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5584 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5585 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5588 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5593 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5596 path = folder_item_get_identifier(dest);
5598 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5602 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5603 GdkAtom clip, GtkTextIter *insert_place);
5605 #define BLOCK_WRAP() { \
5606 prev_autowrap = compose->autowrap; \
5607 buffer = gtk_text_view_get_buffer( \
5608 GTK_TEXT_VIEW(compose->text)); \
5609 compose->autowrap = FALSE; \
5611 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5612 G_CALLBACK(compose_changed_cb), \
5614 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5615 G_CALLBACK(text_inserted), \
5618 #define UNBLOCK_WRAP() { \
5619 compose->autowrap = prev_autowrap; \
5620 if (compose->autowrap) \
5621 compose_wrap_all(compose); \
5623 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5624 G_CALLBACK(compose_changed_cb), \
5626 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5627 G_CALLBACK(text_inserted), \
5632 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5636 GtkTextBuffer *buffer;
5638 if (event->button == 3) {
5640 GtkTextIter sel_start, sel_end;
5641 gboolean stuff_selected;
5643 /* move the cursor to allow GtkAspell to check the word
5644 * under the mouse */
5645 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5646 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5648 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5651 stuff_selected = gtk_text_buffer_get_selection_bounds(
5652 GTK_TEXT_VIEW(text)->buffer,
5653 &sel_start, &sel_end);
5655 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5656 /* reselect stuff */
5658 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5659 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5660 &sel_start, &sel_end);
5662 return FALSE; /* pass the event so that the right-click goes through */
5665 if (event->button == 2) {
5670 /* get the middle-click position to paste at the correct place */
5671 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5672 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5674 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5677 entry_paste_clipboard(compose, text,
5678 prefs_common.linewrap_pastes,
5679 GDK_SELECTION_PRIMARY, &iter);
5687 static void compose_spell_menu_changed(void *data)
5689 Compose *compose = (Compose *)data;
5691 GtkWidget *menuitem;
5692 GtkWidget *parent_item;
5693 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5694 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5697 if (compose->gtkaspell == NULL)
5700 parent_item = gtk_item_factory_get_item(ifactory,
5701 "/Spelling/Options");
5703 /* setting the submenu removes /Spelling/Options from the factory
5704 * so we need to save it */
5706 if (parent_item == NULL) {
5707 parent_item = compose->aspell_options_menu;
5708 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5710 compose->aspell_options_menu = parent_item;
5712 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5714 spell_menu = g_slist_reverse(spell_menu);
5715 for (items = spell_menu;
5716 items; items = items->next) {
5717 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
5718 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5719 gtk_widget_show(GTK_WIDGET(menuitem));
5721 g_slist_free(spell_menu);
5723 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
5728 static gboolean compose_force_window_origin = TRUE;
5729 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5736 GtkWidget *handlebox;
5738 GtkWidget *notebook;
5743 GtkWidget *subject_hbox;
5744 GtkWidget *subject_frame;
5745 GtkWidget *subject_entry;
5749 GtkWidget *edit_vbox;
5750 GtkWidget *ruler_hbox;
5752 GtkWidget *scrolledwin;
5754 GtkTextBuffer *buffer;
5755 GtkClipboard *clipboard;
5757 UndoMain *undostruct;
5759 gchar *titles[N_ATTACH_COLS];
5760 guint n_menu_entries;
5761 GtkWidget *popupmenu;
5762 GtkItemFactory *popupfactory;
5763 GtkItemFactory *ifactory;
5764 GtkWidget *tmpl_menu;
5766 GtkWidget *menuitem;
5769 GtkAspell * gtkaspell = NULL;
5772 static GdkGeometry geometry;
5774 g_return_val_if_fail(account != NULL, NULL);
5776 debug_print("Creating compose window...\n");
5777 compose = g_new0(Compose, 1);
5779 titles[COL_MIMETYPE] = _("MIME type");
5780 titles[COL_SIZE] = _("Size");
5781 titles[COL_NAME] = _("Name");
5783 compose->batch = batch;
5784 compose->account = account;
5786 compose->mutex = g_mutex_new();
5787 compose->set_cursor_pos = -1;
5789 compose->tooltips = gtk_tooltips_new();
5791 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5792 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5793 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5795 if (!geometry.max_width) {
5796 geometry.max_width = gdk_screen_width();
5797 geometry.max_height = gdk_screen_height();
5800 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5801 &geometry, GDK_HINT_MAX_SIZE);
5802 if (!geometry.min_width) {
5803 geometry.min_width = 600;
5804 geometry.min_height = 480;
5806 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5807 &geometry, GDK_HINT_MIN_SIZE);
5809 if (compose_force_window_origin)
5810 gtk_widget_set_uposition(window, prefs_common.compose_x,
5811 prefs_common.compose_y);
5813 g_signal_connect(G_OBJECT(window), "delete_event",
5814 G_CALLBACK(compose_delete_cb), compose);
5815 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5816 gtk_widget_realize(window);
5818 gtkut_widget_set_composer_icon(window);
5820 vbox = gtk_vbox_new(FALSE, 0);
5821 gtk_container_add(GTK_CONTAINER(window), vbox);
5823 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5824 menubar = menubar_create(window, compose_entries,
5825 n_menu_entries, "<Compose>", compose);
5826 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5828 if (prefs_common.toolbar_detachable) {
5829 handlebox = gtk_handle_box_new();
5831 handlebox = gtk_hbox_new(FALSE, 0);
5833 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5835 gtk_widget_realize(handlebox);
5836 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5839 vbox2 = gtk_vbox_new(FALSE, 2);
5840 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5841 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5844 notebook = gtk_notebook_new();
5845 gtk_widget_set_size_request(notebook, -1, 130);
5846 gtk_widget_show(notebook);
5848 /* header labels and entries */
5849 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5850 compose_create_header(compose),
5851 gtk_label_new_with_mnemonic(_("Hea_der")));
5852 /* attachment list */
5853 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5854 compose_create_attach(compose),
5855 gtk_label_new_with_mnemonic(_("_Attachments")));
5857 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5858 compose_create_others(compose),
5859 gtk_label_new_with_mnemonic(_("Othe_rs")));
5862 subject_hbox = gtk_hbox_new(FALSE, 0);
5863 gtk_widget_show(subject_hbox);
5865 subject_frame = gtk_frame_new(NULL);
5866 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5867 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5868 gtk_widget_show(subject_frame);
5870 subject = gtk_hbox_new(FALSE, 0);
5871 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5872 gtk_widget_show(subject);
5874 label = gtk_label_new(_("Subject:"));
5875 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5876 gtk_widget_show(label);
5878 subject_entry = gtk_entry_new();
5879 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5880 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5881 G_CALLBACK(compose_grab_focus_cb), compose);
5882 gtk_widget_show(subject_entry);
5883 compose->subject_entry = subject_entry;
5884 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5886 edit_vbox = gtk_vbox_new(FALSE, 0);
5888 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5891 ruler_hbox = gtk_hbox_new(FALSE, 0);
5892 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5894 ruler = gtk_shruler_new();
5895 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5896 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5900 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5901 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5902 GTK_POLICY_AUTOMATIC,
5903 GTK_POLICY_AUTOMATIC);
5904 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5906 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5907 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5909 text = gtk_text_view_new();
5910 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5911 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5912 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5913 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5914 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5916 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5918 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5919 G_CALLBACK(compose_edit_size_alloc),
5921 g_signal_connect(G_OBJECT(buffer), "changed",
5922 G_CALLBACK(compose_changed_cb), compose);
5923 g_signal_connect(G_OBJECT(text), "grab_focus",
5924 G_CALLBACK(compose_grab_focus_cb), compose);
5925 g_signal_connect(G_OBJECT(buffer), "insert_text",
5926 G_CALLBACK(text_inserted), compose);
5927 g_signal_connect(G_OBJECT(text), "button_press_event",
5928 G_CALLBACK(text_clicked), compose);
5929 g_signal_connect(G_OBJECT(subject_entry), "changed",
5930 G_CALLBACK(compose_changed_cb), compose);
5933 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5934 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5935 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5936 g_signal_connect(G_OBJECT(text), "drag_data_received",
5937 G_CALLBACK(compose_insert_drag_received_cb),
5939 g_signal_connect(G_OBJECT(text), "drag-drop",
5940 G_CALLBACK(compose_drag_drop),
5942 gtk_widget_show_all(vbox);
5944 /* pane between attach clist and text */
5945 paned = gtk_vpaned_new();
5946 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5947 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5948 gtk_paned_add1(GTK_PANED(paned), notebook);
5949 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5950 gtk_widget_show_all(paned);
5953 if (prefs_common.textfont) {
5954 PangoFontDescription *font_desc;
5956 font_desc = pango_font_description_from_string
5957 (prefs_common.textfont);
5959 gtk_widget_modify_font(text, font_desc);
5960 pango_font_description_free(font_desc);
5964 n_entries = sizeof(compose_popup_entries) /
5965 sizeof(compose_popup_entries[0]);
5966 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5967 "<Compose>", &popupfactory,
5970 ifactory = gtk_item_factory_from_widget(menubar);
5971 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5972 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5973 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5975 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5977 undostruct = undo_init(text);
5978 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5981 address_completion_start(window);
5983 compose->window = window;
5984 compose->vbox = vbox;
5985 compose->menubar = menubar;
5986 compose->handlebox = handlebox;
5988 compose->vbox2 = vbox2;
5990 compose->paned = paned;
5992 compose->edit_vbox = edit_vbox;
5993 compose->ruler_hbox = ruler_hbox;
5994 compose->ruler = ruler;
5995 compose->scrolledwin = scrolledwin;
5996 compose->text = text;
5998 compose->focused_editable = NULL;
6000 compose->popupmenu = popupmenu;
6001 compose->popupfactory = popupfactory;
6003 compose->tmpl_menu = tmpl_menu;
6005 compose->mode = mode;
6007 compose->targetinfo = NULL;
6008 compose->replyinfo = NULL;
6009 compose->fwdinfo = NULL;
6011 compose->replyto = NULL;
6013 compose->bcc = NULL;
6014 compose->followup_to = NULL;
6016 compose->ml_post = NULL;
6018 compose->inreplyto = NULL;
6019 compose->references = NULL;
6020 compose->msgid = NULL;
6021 compose->boundary = NULL;
6023 compose->autowrap = prefs_common.autowrap;
6025 compose->use_signing = FALSE;
6026 compose->use_encryption = FALSE;
6027 compose->privacy_system = NULL;
6029 compose->modified = FALSE;
6031 compose->return_receipt = FALSE;
6033 compose->to_list = NULL;
6034 compose->newsgroup_list = NULL;
6036 compose->undostruct = undostruct;
6038 compose->sig_str = NULL;
6040 compose->exteditor_file = NULL;
6041 compose->exteditor_pid = -1;
6042 compose->exteditor_tag = -1;
6043 compose->draft_timeout_tag = -1;
6046 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6047 if (mode != COMPOSE_REDIRECT) {
6048 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6049 strcmp(prefs_common.dictionary, "")) {
6050 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6051 prefs_common.dictionary,
6052 conv_get_locale_charset_str(),
6053 prefs_common.misspelled_col,
6054 prefs_common.check_while_typing,
6055 prefs_common.recheck_when_changing_dict,
6056 prefs_common.use_alternate,
6057 GTK_TEXT_VIEW(text),
6058 GTK_WINDOW(compose->window),
6059 compose_spell_menu_changed,
6062 alertpanel_error(_("Spell checker could not "
6064 gtkaspell_checkers_strerror());
6065 gtkaspell_checkers_reset_error();
6067 if (!gtkaspell_set_sug_mode(gtkaspell,
6068 prefs_common.aspell_sugmode)) {
6069 debug_print("Aspell: could not set "
6070 "suggestion mode %s\n",
6071 gtkaspell_checkers_strerror());
6072 gtkaspell_checkers_reset_error();
6075 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6079 compose->gtkaspell = gtkaspell;
6080 compose_spell_menu_changed(compose);
6083 compose_select_account(compose, account, TRUE);
6085 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6086 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6087 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6089 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6090 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6092 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6093 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6096 if (account->protocol != A_NNTP)
6097 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6099 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6101 addressbook_set_target_compose(compose);
6103 if (mode != COMPOSE_REDIRECT)
6104 compose_set_template_menu(compose);
6106 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6107 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6110 compose_list = g_list_append(compose_list, compose);
6112 if (!prefs_common.show_ruler)
6113 gtk_widget_hide(ruler_hbox);
6115 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6116 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6117 prefs_common.show_ruler);
6120 compose->priority = PRIORITY_NORMAL;
6121 compose_update_priority_menu_item(compose);
6123 compose_set_out_encoding(compose);
6126 compose_update_actions_menu(compose);
6128 /* Privacy Systems menu */
6129 compose_update_privacy_systems_menu(compose);
6131 activate_privacy_system(compose, account, TRUE);
6132 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6134 gtk_widget_realize(window);
6136 gtk_widget_show(window);
6142 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6148 GtkWidget *from_name = NULL;
6150 gint num = 0, def_menu = 0;
6152 accounts = account_get_list();
6153 g_return_val_if_fail(accounts != NULL, NULL);
6155 optmenu = gtk_option_menu_new();
6156 menu = gtk_menu_new();
6158 hbox = gtk_hbox_new(FALSE, 6);
6159 from_name = gtk_entry_new();
6161 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6162 G_CALLBACK(compose_grab_focus_cb), compose);
6164 for (; accounts != NULL; accounts = accounts->next, num++) {
6165 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6166 GtkWidget *menuitem;
6167 gchar *name, *from = NULL;
6169 if (ac == compose->account) def_menu = num;
6171 name = g_markup_printf_escaped("From: <i>%s</i>",
6174 if (ac == compose->account) {
6175 if (ac->name && *ac->name) {
6177 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6178 from = g_strdup_printf("%s <%s>",
6180 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6182 from = g_strdup_printf("%s",
6184 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6187 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
6188 gtk_label_set_use_markup (
6189 GTK_LABEL (gtk_bin_get_child (GTK_BIN (menuitem))),
6193 g_signal_connect(G_OBJECT(menuitem), "activate",
6194 G_CALLBACK(account_activated),
6198 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
6199 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
6201 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
6202 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6204 gtk_tooltips_set_tip(compose->tooltips, optmenu,
6205 _("Account to use for this email"), NULL);
6206 gtk_tooltips_set_tip(compose->tooltips, from_name,
6207 _("Sender address to be used"), NULL);
6209 compose->from_name = from_name;
6214 static void compose_set_priority_cb(gpointer data,
6218 Compose *compose = (Compose *) data;
6219 compose->priority = action;
6222 static void compose_update_priority_menu_item(Compose * compose)
6224 GtkItemFactory *ifactory;
6225 GtkWidget *menuitem = NULL;
6227 ifactory = gtk_item_factory_from_widget(compose->menubar);
6229 switch (compose->priority) {
6230 case PRIORITY_HIGHEST:
6231 menuitem = gtk_item_factory_get_item
6232 (ifactory, "/Options/Priority/Highest");
6235 menuitem = gtk_item_factory_get_item
6236 (ifactory, "/Options/Priority/High");
6238 case PRIORITY_NORMAL:
6239 menuitem = gtk_item_factory_get_item
6240 (ifactory, "/Options/Priority/Normal");
6243 menuitem = gtk_item_factory_get_item
6244 (ifactory, "/Options/Priority/Low");
6246 case PRIORITY_LOWEST:
6247 menuitem = gtk_item_factory_get_item
6248 (ifactory, "/Options/Priority/Lowest");
6251 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6254 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6256 Compose *compose = (Compose *) data;
6258 GtkItemFactory *ifactory;
6259 gboolean can_sign = FALSE, can_encrypt = FALSE;
6261 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6263 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6266 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6267 g_free(compose->privacy_system);
6268 compose->privacy_system = NULL;
6269 if (systemid != NULL) {
6270 compose->privacy_system = g_strdup(systemid);
6272 can_sign = privacy_system_can_sign(systemid);
6273 can_encrypt = privacy_system_can_encrypt(systemid);
6276 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6278 ifactory = gtk_item_factory_from_widget(compose->menubar);
6279 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6280 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6283 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6285 static gchar *branch_path = "/Options/Privacy System";
6286 GtkItemFactory *ifactory;
6287 GtkWidget *menuitem = NULL;
6289 gboolean can_sign = FALSE, can_encrypt = FALSE;
6290 gboolean found = FALSE;
6292 ifactory = gtk_item_factory_from_widget(compose->menubar);
6294 if (compose->privacy_system != NULL) {
6297 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6298 g_return_if_fail(menuitem != NULL);
6300 amenu = GTK_MENU_SHELL(menuitem)->children;
6302 while (amenu != NULL) {
6303 GList *alist = amenu->next;
6305 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6306 if (systemid != NULL) {
6307 if (strcmp(systemid, compose->privacy_system) == 0) {
6308 menuitem = GTK_WIDGET(amenu->data);
6310 can_sign = privacy_system_can_sign(systemid);
6311 can_encrypt = privacy_system_can_encrypt(systemid);
6315 } else if (strlen(compose->privacy_system) == 0) {
6316 menuitem = GTK_WIDGET(amenu->data);
6319 can_encrypt = FALSE;
6326 if (menuitem != NULL)
6327 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6329 if (warn && !found && strlen(compose->privacy_system)) {
6330 gchar *tmp = g_strdup_printf(
6331 _("The privacy system '%s' cannot be loaded. You "
6332 "will not be able to sign or encrypt this message."),
6333 compose->privacy_system);
6334 alertpanel_warning(tmp);
6339 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6340 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6343 static void compose_set_out_encoding(Compose *compose)
6345 GtkItemFactoryEntry *entry;
6346 GtkItemFactory *ifactory;
6347 CharSet out_encoding;
6348 gchar *path, *p, *q;
6351 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6352 ifactory = gtk_item_factory_from_widget(compose->menubar);
6354 for (entry = compose_entries; entry->callback != compose_address_cb;
6356 if (entry->callback == compose_set_encoding_cb &&
6357 (CharSet)entry->callback_action == out_encoding) {
6358 p = q = path = g_strdup(entry->path);
6370 item = gtk_item_factory_get_item(ifactory, path);
6371 gtk_widget_activate(item);
6378 static void compose_set_template_menu(Compose *compose)
6380 GSList *tmpl_list, *cur;
6384 tmpl_list = template_get_config();
6386 menu = gtk_menu_new();
6388 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6389 Template *tmpl = (Template *)cur->data;
6391 item = gtk_menu_item_new_with_label(tmpl->name);
6392 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6393 g_signal_connect(G_OBJECT(item), "activate",
6394 G_CALLBACK(compose_template_activate_cb),
6396 g_object_set_data(G_OBJECT(item), "template", tmpl);
6397 gtk_widget_show(item);
6400 gtk_widget_show(menu);
6401 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6404 void compose_update_actions_menu(Compose *compose)
6406 GtkItemFactory *ifactory;
6408 ifactory = gtk_item_factory_from_widget(compose->menubar);
6409 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6412 void compose_update_privacy_systems_menu(Compose *compose)
6414 static gchar *branch_path = "/Options/Privacy System";
6415 GtkItemFactory *ifactory;
6416 GtkWidget *menuitem;
6417 GSList *systems, *cur;
6420 GtkWidget *system_none;
6423 ifactory = gtk_item_factory_from_widget(compose->menubar);
6425 /* remove old entries */
6426 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6427 g_return_if_fail(menuitem != NULL);
6429 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6430 while (amenu != NULL) {
6431 GList *alist = amenu->next;
6432 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6436 system_none = gtk_item_factory_get_widget(ifactory,
6437 "/Options/Privacy System/None");
6439 g_signal_connect(G_OBJECT(system_none), "activate",
6440 G_CALLBACK(compose_set_privacy_system_cb), compose);
6442 systems = privacy_get_system_ids();
6443 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6444 gchar *systemid = cur->data;
6446 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6447 widget = gtk_radio_menu_item_new_with_label(group,
6448 privacy_system_get_name(systemid));
6449 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6450 g_strdup(systemid), g_free);
6451 g_signal_connect(G_OBJECT(widget), "activate",
6452 G_CALLBACK(compose_set_privacy_system_cb), compose);
6454 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6455 gtk_widget_show(widget);
6458 g_slist_free(systems);
6461 void compose_reflect_prefs_all(void)
6466 for (cur = compose_list; cur != NULL; cur = cur->next) {
6467 compose = (Compose *)cur->data;
6468 compose_set_template_menu(compose);
6472 void compose_reflect_prefs_pixmap_theme(void)
6477 for (cur = compose_list; cur != NULL; cur = cur->next) {
6478 compose = (Compose *)cur->data;
6479 toolbar_update(TOOLBAR_COMPOSE, compose);
6483 static void compose_template_apply(Compose *compose, Template *tmpl,
6487 GtkTextBuffer *buffer;
6491 gchar *parsed_str = NULL;
6492 gint cursor_pos = 0;
6495 /* process the body */
6497 text = GTK_TEXT_VIEW(compose->text);
6498 buffer = gtk_text_view_get_buffer(text);
6501 gtk_text_buffer_set_text(buffer, "", -1);
6503 mark = gtk_text_buffer_get_insert(buffer);
6504 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6507 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6508 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6511 if (prefs_common.quotemark && *prefs_common.quotemark)
6512 qmark = prefs_common.quotemark;
6516 if (compose->replyinfo != NULL)
6517 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6518 tmpl->value, qmark, NULL, FALSE);
6519 else if (compose->fwdinfo != NULL)
6520 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6521 tmpl->value, qmark, NULL, FALSE);
6526 if (replace && parsed_str && compose->account->auto_sig)
6527 compose_insert_sig(compose, FALSE);
6529 if (replace && parsed_str) {
6530 gtk_text_buffer_get_start_iter(buffer, &iter);
6531 gtk_text_buffer_place_cursor(buffer, &iter);
6535 cursor_pos = quote_fmt_get_cursor_pos();
6536 compose->set_cursor_pos = cursor_pos;
6537 if (cursor_pos == -1)
6539 gtk_text_buffer_get_start_iter(buffer, &iter);
6540 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6541 gtk_text_buffer_place_cursor(buffer, &iter);
6544 /* process the other fields */
6545 compose_template_apply_fields(compose, tmpl);
6547 compose_changed_cb(NULL, compose);
6550 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6552 static MsgInfo dummyinfo;
6553 MsgInfo *msginfo = NULL;
6556 if (compose->replyinfo != NULL)
6557 msginfo = compose->replyinfo;
6558 else if (compose->fwdinfo != NULL)
6559 msginfo = compose->fwdinfo;
6561 msginfo = &dummyinfo;
6563 if (tmpl->to && *tmpl->to != '\0') {
6564 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6565 quote_fmt_scan_string(tmpl->to);
6568 buf = quote_fmt_get_buffer();
6570 alertpanel_error(_("Message To format error."));
6572 compose_entry_append(compose, buf, COMPOSE_TO);
6576 if (tmpl->cc && *tmpl->cc != '\0') {
6577 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6578 quote_fmt_scan_string(tmpl->cc);
6581 buf = quote_fmt_get_buffer();
6583 alertpanel_error(_("Message Cc format error."));
6585 compose_entry_append(compose, buf, COMPOSE_CC);
6589 if (tmpl->bcc && *tmpl->bcc != '\0') {
6590 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6591 quote_fmt_scan_string(tmpl->bcc);
6594 buf = quote_fmt_get_buffer();
6596 alertpanel_error(_("Message Bcc format error."));
6598 compose_entry_append(compose, buf, COMPOSE_BCC);
6602 /* process the subject */
6603 if (tmpl->subject && *tmpl->subject != '\0') {
6604 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6605 quote_fmt_scan_string(tmpl->subject);
6608 buf = quote_fmt_get_buffer();
6610 alertpanel_error(_("Message subject format error."));
6612 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6617 static void compose_destroy(Compose *compose)
6619 compose_list = g_list_remove(compose_list, compose);
6621 if (compose->updating) {
6622 debug_print("danger, not destroying anything now\n");
6623 compose->deferred_destroy = TRUE;
6626 /* NOTE: address_completion_end() does nothing with the window
6627 * however this may change. */
6628 address_completion_end(compose->window);
6630 slist_free_strings(compose->to_list);
6631 g_slist_free(compose->to_list);
6632 slist_free_strings(compose->newsgroup_list);
6633 g_slist_free(compose->newsgroup_list);
6634 slist_free_strings(compose->header_list);
6635 g_slist_free(compose->header_list);
6637 procmsg_msginfo_free(compose->targetinfo);
6638 procmsg_msginfo_free(compose->replyinfo);
6639 procmsg_msginfo_free(compose->fwdinfo);
6641 g_free(compose->replyto);
6642 g_free(compose->cc);
6643 g_free(compose->bcc);
6644 g_free(compose->newsgroups);
6645 g_free(compose->followup_to);
6647 g_free(compose->ml_post);
6649 g_free(compose->inreplyto);
6650 g_free(compose->references);
6651 g_free(compose->msgid);
6652 g_free(compose->boundary);
6654 g_free(compose->redirect_filename);
6655 if (compose->undostruct)
6656 undo_destroy(compose->undostruct);
6658 g_free(compose->sig_str);
6660 g_free(compose->exteditor_file);
6662 g_free(compose->orig_charset);
6664 g_free(compose->privacy_system);
6666 if (addressbook_get_target_compose() == compose)
6667 addressbook_set_target_compose(NULL);
6670 if (compose->gtkaspell) {
6671 gtkaspell_delete(compose->gtkaspell);
6672 compose->gtkaspell = NULL;
6676 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6677 prefs_common.compose_height = compose->window->allocation.height;
6679 if (!gtk_widget_get_parent(compose->paned))
6680 gtk_widget_destroy(compose->paned);
6681 gtk_widget_destroy(compose->popupmenu);
6683 gtk_widget_destroy(compose->window);
6684 toolbar_destroy(compose->toolbar);
6685 g_free(compose->toolbar);
6686 g_mutex_free(compose->mutex);
6690 static void compose_attach_info_free(AttachInfo *ainfo)
6692 g_free(ainfo->file);
6693 g_free(ainfo->content_type);
6694 g_free(ainfo->name);
6698 static void compose_attach_remove_selected(Compose *compose)
6700 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6701 GtkTreeSelection *selection;
6703 GtkTreeModel *model;
6705 selection = gtk_tree_view_get_selection(tree_view);
6706 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6711 for (cur = sel; cur != NULL; cur = cur->next) {
6712 GtkTreePath *path = cur->data;
6713 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6716 gtk_tree_path_free(path);
6719 for (cur = sel; cur != NULL; cur = cur->next) {
6720 GtkTreeRowReference *ref = cur->data;
6721 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6724 if (gtk_tree_model_get_iter(model, &iter, path))
6725 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6727 gtk_tree_path_free(path);
6728 gtk_tree_row_reference_free(ref);
6734 static struct _AttachProperty
6737 GtkWidget *mimetype_entry;
6738 GtkWidget *encoding_optmenu;
6739 GtkWidget *path_entry;
6740 GtkWidget *filename_entry;
6742 GtkWidget *cancel_btn;
6745 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6747 gtk_tree_path_free((GtkTreePath *)ptr);
6750 static void compose_attach_property(Compose *compose)
6752 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6754 GtkOptionMenu *optmenu;
6755 GtkTreeSelection *selection;
6757 GtkTreeModel *model;
6760 static gboolean cancelled;
6762 /* only if one selected */
6763 selection = gtk_tree_view_get_selection(tree_view);
6764 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6767 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6771 path = (GtkTreePath *) sel->data;
6772 gtk_tree_model_get_iter(model, &iter, path);
6773 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6776 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6782 if (!attach_prop.window)
6783 compose_attach_property_create(&cancelled);
6784 gtk_widget_grab_focus(attach_prop.ok_btn);
6785 gtk_widget_show(attach_prop.window);
6786 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6788 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6789 if (ainfo->encoding == ENC_UNKNOWN)
6790 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6791 GINT_TO_POINTER(ENC_BASE64));
6793 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6794 GINT_TO_POINTER(ainfo->encoding));
6796 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6797 ainfo->content_type ? ainfo->content_type : "");
6798 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6799 ainfo->file ? ainfo->file : "");
6800 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6801 ainfo->name ? ainfo->name : "");
6804 const gchar *entry_text;
6806 gchar *cnttype = NULL;
6810 GtkWidget *menuitem;
6815 gtk_widget_hide(attach_prop.window);
6820 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6821 if (*entry_text != '\0') {
6824 text = g_strstrip(g_strdup(entry_text));
6825 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6826 cnttype = g_strdup(text);
6829 alertpanel_error(_("Invalid MIME type."));
6835 menu = gtk_option_menu_get_menu(optmenu);
6836 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6837 ainfo->encoding = GPOINTER_TO_INT
6838 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6840 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6841 if (*entry_text != '\0') {
6842 if (is_file_exist(entry_text) &&
6843 (size = get_file_size(entry_text)) > 0)
6844 file = g_strdup(entry_text);
6847 (_("File doesn't exist or is empty."));
6853 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6854 if (*entry_text != '\0') {
6855 g_free(ainfo->name);
6856 ainfo->name = g_strdup(entry_text);
6860 g_free(ainfo->content_type);
6861 ainfo->content_type = cnttype;
6864 g_free(ainfo->file);
6870 /* update tree store */
6871 text = to_human_readable(ainfo->size);
6872 gtk_tree_model_get_iter(model, &iter, path);
6873 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6874 COL_MIMETYPE, ainfo->content_type,
6876 COL_NAME, ainfo->name,
6882 gtk_tree_path_free(path);
6885 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6887 label = gtk_label_new(str); \
6888 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6889 GTK_FILL, 0, 0, 0); \
6890 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6892 entry = gtk_entry_new(); \
6893 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6894 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6897 static void compose_attach_property_create(gboolean *cancelled)
6903 GtkWidget *mimetype_entry;
6906 GtkWidget *optmenu_menu;
6907 GtkWidget *menuitem;
6908 GtkWidget *path_entry;
6909 GtkWidget *filename_entry;
6912 GtkWidget *cancel_btn;
6913 GList *mime_type_list, *strlist;
6915 debug_print("Creating attach_property window...\n");
6917 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6918 gtk_widget_set_size_request(window, 480, -1);
6919 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6920 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6921 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6922 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6923 g_signal_connect(G_OBJECT(window), "delete_event",
6924 G_CALLBACK(attach_property_delete_event),
6926 g_signal_connect(G_OBJECT(window), "key_press_event",
6927 G_CALLBACK(attach_property_key_pressed),
6930 vbox = gtk_vbox_new(FALSE, 8);
6931 gtk_container_add(GTK_CONTAINER(window), vbox);
6933 table = gtk_table_new(4, 2, FALSE);
6934 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6935 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6936 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6938 label = gtk_label_new(_("MIME type"));
6939 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6941 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6942 mimetype_entry = gtk_combo_new();
6943 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6944 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6946 /* stuff with list */
6947 mime_type_list = procmime_get_mime_type_list();
6949 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6950 MimeType *type = (MimeType *) mime_type_list->data;
6953 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6955 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6958 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6959 (GCompareFunc)strcmp2);
6962 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6964 for (mime_type_list = strlist; mime_type_list != NULL;
6965 mime_type_list = mime_type_list->next)
6966 g_free(mime_type_list->data);
6967 g_list_free(strlist);
6969 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6971 label = gtk_label_new(_("Encoding"));
6972 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6974 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6976 hbox = gtk_hbox_new(FALSE, 0);
6977 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6978 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6980 optmenu = gtk_option_menu_new();
6981 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6983 optmenu_menu = gtk_menu_new();
6984 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6985 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6986 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6987 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6988 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6989 ENC_QUOTED_PRINTABLE);
6990 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6992 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6994 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6996 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6997 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6999 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
7000 &ok_btn, GTK_STOCK_OK,
7002 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
7003 gtk_widget_grab_default(ok_btn);
7005 g_signal_connect(G_OBJECT(ok_btn), "clicked",
7006 G_CALLBACK(attach_property_ok),
7008 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
7009 G_CALLBACK(attach_property_cancel),
7012 gtk_widget_show_all(vbox);
7014 attach_prop.window = window;
7015 attach_prop.mimetype_entry = mimetype_entry;
7016 attach_prop.encoding_optmenu = optmenu;
7017 attach_prop.path_entry = path_entry;
7018 attach_prop.filename_entry = filename_entry;
7019 attach_prop.ok_btn = ok_btn;
7020 attach_prop.cancel_btn = cancel_btn;
7023 #undef SET_LABEL_AND_ENTRY
7025 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7031 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7037 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7038 gboolean *cancelled)
7046 static gboolean attach_property_key_pressed(GtkWidget *widget,
7048 gboolean *cancelled)
7050 if (event && event->keyval == GDK_Escape) {
7057 static void compose_exec_ext_editor(Compose *compose)
7064 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7065 G_DIR_SEPARATOR, compose);
7067 if (pipe(pipe_fds) < 0) {
7073 if ((pid = fork()) < 0) {
7080 /* close the write side of the pipe */
7083 compose->exteditor_file = g_strdup(tmp);
7084 compose->exteditor_pid = pid;
7086 compose_set_ext_editor_sensitive(compose, FALSE);
7088 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7089 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7093 } else { /* process-monitoring process */
7099 /* close the read side of the pipe */
7102 if (compose_write_body_to_file(compose, tmp) < 0) {
7103 fd_write_all(pipe_fds[1], "2\n", 2);
7107 pid_ed = compose_exec_ext_editor_real(tmp);
7109 fd_write_all(pipe_fds[1], "1\n", 2);
7113 /* wait until editor is terminated */
7114 waitpid(pid_ed, NULL, 0);
7116 fd_write_all(pipe_fds[1], "0\n", 2);
7123 #endif /* G_OS_UNIX */
7127 static gint compose_exec_ext_editor_real(const gchar *file)
7134 g_return_val_if_fail(file != NULL, -1);
7136 if ((pid = fork()) < 0) {
7141 if (pid != 0) return pid;
7143 /* grandchild process */
7145 if (setpgid(0, getppid()))
7148 if (prefs_common.ext_editor_cmd &&
7149 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7150 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7151 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7153 if (prefs_common.ext_editor_cmd)
7154 g_warning("External editor command line is invalid: '%s'\n",
7155 prefs_common.ext_editor_cmd);
7156 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7159 cmdline = strsplit_with_quote(buf, " ", 1024);
7160 execvp(cmdline[0], cmdline);
7163 g_strfreev(cmdline);
7168 static gboolean compose_ext_editor_kill(Compose *compose)
7170 pid_t pgid = compose->exteditor_pid * -1;
7173 ret = kill(pgid, 0);
7175 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7179 msg = g_strdup_printf
7180 (_("The external editor is still working.\n"
7181 "Force terminating the process?\n"
7182 "process group id: %d"), -pgid);
7183 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7184 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7188 if (val == G_ALERTALTERNATE) {
7189 g_source_remove(compose->exteditor_tag);
7190 g_io_channel_shutdown(compose->exteditor_ch,
7192 g_io_channel_unref(compose->exteditor_ch);
7194 if (kill(pgid, SIGTERM) < 0) perror("kill");
7195 waitpid(compose->exteditor_pid, NULL, 0);
7197 g_warning("Terminated process group id: %d", -pgid);
7198 g_warning("Temporary file: %s",
7199 compose->exteditor_file);
7201 compose_set_ext_editor_sensitive(compose, TRUE);
7203 g_free(compose->exteditor_file);
7204 compose->exteditor_file = NULL;
7205 compose->exteditor_pid = -1;
7206 compose->exteditor_ch = NULL;
7207 compose->exteditor_tag = -1;
7215 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7219 Compose *compose = (Compose *)data;
7222 debug_print(_("Compose: input from monitoring process\n"));
7224 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7226 g_io_channel_shutdown(source, FALSE, NULL);
7227 g_io_channel_unref(source);
7229 waitpid(compose->exteditor_pid, NULL, 0);
7231 if (buf[0] == '0') { /* success */
7232 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7233 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7235 gtk_text_buffer_set_text(buffer, "", -1);
7236 compose_insert_file(compose, compose->exteditor_file);
7237 compose_changed_cb(NULL, compose);
7239 if (g_unlink(compose->exteditor_file) < 0)
7240 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7241 } else if (buf[0] == '1') { /* failed */
7242 g_warning("Couldn't exec external editor\n");
7243 if (g_unlink(compose->exteditor_file) < 0)
7244 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7245 } else if (buf[0] == '2') {
7246 g_warning("Couldn't write to file\n");
7247 } else if (buf[0] == '3') {
7248 g_warning("Pipe read failed\n");
7251 compose_set_ext_editor_sensitive(compose, TRUE);
7253 g_free(compose->exteditor_file);
7254 compose->exteditor_file = NULL;
7255 compose->exteditor_pid = -1;
7256 compose->exteditor_ch = NULL;
7257 compose->exteditor_tag = -1;
7262 static void compose_set_ext_editor_sensitive(Compose *compose,
7265 GtkItemFactory *ifactory;
7267 ifactory = gtk_item_factory_from_widget(compose->menubar);
7269 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7270 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7271 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7272 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7273 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7274 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7275 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7278 gtk_widget_set_sensitive(compose->text, sensitive);
7279 if (compose->toolbar->send_btn)
7280 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7281 if (compose->toolbar->sendl_btn)
7282 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7283 if (compose->toolbar->draft_btn)
7284 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7285 if (compose->toolbar->insert_btn)
7286 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7287 if (compose->toolbar->sig_btn)
7288 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7289 if (compose->toolbar->exteditor_btn)
7290 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7291 if (compose->toolbar->linewrap_current_btn)
7292 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7293 if (compose->toolbar->linewrap_all_btn)
7294 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7296 #endif /* G_OS_UNIX */
7299 * compose_undo_state_changed:
7301 * Change the sensivity of the menuentries undo and redo
7303 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7304 gint redo_state, gpointer data)
7306 GtkWidget *widget = GTK_WIDGET(data);
7307 GtkItemFactory *ifactory;
7309 g_return_if_fail(widget != NULL);
7311 ifactory = gtk_item_factory_from_widget(widget);
7313 switch (undo_state) {
7314 case UNDO_STATE_TRUE:
7315 if (!undostruct->undo_state) {
7316 undostruct->undo_state = TRUE;
7317 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7320 case UNDO_STATE_FALSE:
7321 if (undostruct->undo_state) {
7322 undostruct->undo_state = FALSE;
7323 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7326 case UNDO_STATE_UNCHANGED:
7328 case UNDO_STATE_REFRESH:
7329 menu_set_sensitive(ifactory, "/Edit/Undo",
7330 undostruct->undo_state);
7333 g_warning("Undo state not recognized");
7337 switch (redo_state) {
7338 case UNDO_STATE_TRUE:
7339 if (!undostruct->redo_state) {
7340 undostruct->redo_state = TRUE;
7341 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7344 case UNDO_STATE_FALSE:
7345 if (undostruct->redo_state) {
7346 undostruct->redo_state = FALSE;
7347 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7350 case UNDO_STATE_UNCHANGED:
7352 case UNDO_STATE_REFRESH:
7353 menu_set_sensitive(ifactory, "/Edit/Redo",
7354 undostruct->redo_state);
7357 g_warning("Redo state not recognized");
7362 /* callback functions */
7364 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7365 * includes "non-client" (windows-izm) in calculation, so this calculation
7366 * may not be accurate.
7368 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7369 GtkAllocation *allocation,
7370 GtkSHRuler *shruler)
7372 if (prefs_common.show_ruler) {
7373 gint char_width = 0, char_height = 0;
7374 gint line_width_in_chars;
7376 gtkut_get_font_size(GTK_WIDGET(widget),
7377 &char_width, &char_height);
7378 line_width_in_chars =
7379 (allocation->width - allocation->x) / char_width;
7381 /* got the maximum */
7382 gtk_ruler_set_range(GTK_RULER(shruler),
7383 0.0, line_width_in_chars, 0,
7384 /*line_width_in_chars*/ char_width);
7390 static void account_activated(GtkMenuItem *menuitem, gpointer data)
7392 Compose *compose = (Compose *)data;
7395 gchar *folderidentifier;
7397 ac = account_find_from_id(
7398 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
7399 g_return_if_fail(ac != NULL);
7401 if (ac != compose->account)
7402 compose_select_account(compose, ac, FALSE);
7404 /* Set message save folder */
7405 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7406 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7408 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7409 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7411 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7412 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7413 folderidentifier = folder_item_get_identifier(account_get_special_folder
7414 (compose->account, F_OUTBOX));
7415 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7416 g_free(folderidentifier);
7420 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7421 GtkTreeViewColumn *column, Compose *compose)
7423 compose_attach_property(compose);
7426 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7429 Compose *compose = (Compose *)data;
7430 GtkTreeSelection *attach_selection;
7431 gint attach_nr_selected;
7432 GtkItemFactory *ifactory;
7434 if (!event) return FALSE;
7436 if (event->button == 3) {
7437 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7438 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7439 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7441 if (attach_nr_selected > 0)
7443 menu_set_sensitive(ifactory, "/Remove", TRUE);
7444 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7446 menu_set_sensitive(ifactory, "/Remove", FALSE);
7447 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7450 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7451 NULL, NULL, event->button, event->time);
7458 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7461 Compose *compose = (Compose *)data;
7463 if (!event) return FALSE;
7465 switch (event->keyval) {
7467 compose_attach_remove_selected(compose);
7473 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7475 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7476 toolbar_comp_set_sensitive(compose, allow);
7477 menu_set_sensitive(ifactory, "/Message", allow);
7478 menu_set_sensitive(ifactory, "/Edit", allow);
7480 menu_set_sensitive(ifactory, "/Spelling", allow);
7482 menu_set_sensitive(ifactory, "/Options", allow);
7483 menu_set_sensitive(ifactory, "/Tools", allow);
7484 menu_set_sensitive(ifactory, "/Help", allow);
7486 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7490 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7492 Compose *compose = (Compose *)data;
7494 if (prefs_common.work_offline &&
7495 !inc_offline_should_override(
7496 _("Sylpheed-Claws needs network access in order "
7497 "to send this email.")))
7500 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7501 gtk_timeout_remove(compose->draft_timeout_tag);
7502 compose->draft_timeout_tag = -1;
7505 compose_send(compose);
7508 static void compose_send_later_cb(gpointer data, guint action,
7511 Compose *compose = (Compose *)data;
7514 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
7516 compose_close(compose);
7517 else if (val == -1) {
7518 alertpanel_error(_("Could not queue message."));
7519 } else if (val == -2) {
7520 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7521 } else if (val == -3) {
7522 alertpanel_error(_("Could not queue message for sending:\n\n"
7523 "Signature failed."));
7524 } else if (val == -4) {
7525 alertpanel_error(_("Could not queue message for sending:\n\n"
7526 "Charset conversion failed."));
7530 void compose_draft (gpointer data)
7532 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7535 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7537 Compose *compose = (Compose *)data;
7541 MsgFlags flag = {0, 0};
7542 static gboolean lock = FALSE;
7543 MsgInfo *newmsginfo;
7545 gboolean target_locked = FALSE;
7549 draft = account_get_special_folder(compose->account, F_DRAFT);
7550 g_return_if_fail(draft != NULL);
7552 if (!g_mutex_trylock(compose->mutex)) {
7553 /* we don't want to lock the mutex once it's available,
7554 * because as the only other part of compose.c locking
7555 * it is compose_close - which means once unlocked,
7556 * the compose struct will be freed */
7557 debug_print("couldn't lock mutex, probably sending\n");
7563 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7564 G_DIR_SEPARATOR, compose);
7565 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7566 FILE_OP_ERROR(tmp, "fopen");
7570 /* chmod for security */
7571 if (change_file_mode_rw(fp, tmp) < 0) {
7572 FILE_OP_ERROR(tmp, "chmod");
7573 g_warning("can't change file mode\n");
7576 /* Save draft infos */
7577 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7578 fprintf(fp, "S:%s\n", compose->account->address);
7580 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7581 gchar *savefolderid;
7583 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7584 fprintf(fp, "SCF:%s\n", savefolderid);
7585 g_free(savefolderid);
7587 if (compose->return_receipt) {
7588 fprintf(fp, "RRCPT:1\n");
7590 if (compose->privacy_system) {
7591 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7592 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7593 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7596 /* end of headers */
7597 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
7599 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7607 if (compose->targetinfo) {
7608 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7609 flag.perm_flags = target_locked?MSG_LOCKED:0;
7611 flag.tmp_flags = MSG_DRAFT;
7613 folder_item_scan(draft);
7614 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7617 if (action != COMPOSE_AUTO_SAVE)
7618 alertpanel_error(_("Could not save draft."));
7622 draft->mtime = 0; /* force updating */
7624 if (compose->mode == COMPOSE_REEDIT) {
7625 compose_remove_reedit_target(compose, TRUE);
7628 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7630 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7632 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7634 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7635 if (compose_use_attach(compose))
7636 procmsg_msginfo_set_flags(newmsginfo, 0,
7637 MSG_HAS_ATTACHMENT);
7639 procmsg_msginfo_free(newmsginfo);
7642 folder_item_scan(draft);
7644 if (action == COMPOSE_QUIT_EDITING) {
7646 g_mutex_unlock(compose->mutex); /* must be done before closing */
7647 compose_close(compose);
7653 path = folder_item_fetch_msg(draft, msgnum);
7655 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7658 if (g_stat(path, &s) < 0) {
7659 FILE_OP_ERROR(path, "stat");
7665 procmsg_msginfo_free(compose->targetinfo);
7666 compose->targetinfo = procmsg_msginfo_new();
7667 compose->targetinfo->msgnum = msgnum;
7668 compose->targetinfo->size = s.st_size;
7669 compose->targetinfo->mtime = s.st_mtime;
7670 compose->targetinfo->folder = draft;
7672 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7673 compose->mode = COMPOSE_REEDIT;
7675 if (action == COMPOSE_AUTO_SAVE) {
7676 compose->autosaved_draft = compose->targetinfo;
7678 compose->modified = FALSE;
7679 compose_set_title(compose);
7683 g_mutex_unlock(compose->mutex);
7686 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7688 Compose *compose = (Compose *)data;
7691 if (compose->redirect_filename != NULL)
7694 file_list = filesel_select_multiple_files_open(_("Select file"));
7699 for ( tmp = file_list; tmp; tmp = tmp->next) {
7700 gchar *file = (gchar *) tmp->data;
7701 gchar *utf8_filename = conv_filename_to_utf8(file);
7702 compose_attach_append(compose, file, utf8_filename, NULL);
7703 compose_changed_cb(NULL, compose);
7705 g_free(utf8_filename);
7707 g_list_free(file_list);
7711 static void compose_insert_file_cb(gpointer data, guint action,
7714 Compose *compose = (Compose *)data;
7717 file_list = filesel_select_multiple_files_open(_("Select file"));
7722 for ( tmp = file_list; tmp; tmp = tmp->next) {
7723 gchar *file = (gchar *) tmp->data;
7724 gchar *filedup = g_strdup(file);
7725 gchar *shortfile = g_path_get_basename(filedup);
7726 ComposeInsertResult res;
7728 res = compose_insert_file(compose, file);
7729 if (res == COMPOSE_INSERT_READ_ERROR) {
7730 alertpanel_error(_("File '%s' could not be read."), shortfile);
7731 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7732 alertpanel_error(_("File '%s' contained invalid characters\n"
7733 "for the current encoding, insertion may be incorrect."), shortfile);
7739 g_list_free(file_list);
7743 static void compose_insert_sig_cb(gpointer data, guint action,
7746 Compose *compose = (Compose *)data;
7748 compose_insert_sig(compose, FALSE);
7751 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7755 Compose *compose = (Compose *)data;
7757 gtkut_widget_get_uposition(widget, &x, &y);
7758 prefs_common.compose_x = x;
7759 prefs_common.compose_y = y;
7761 if (compose->sending || compose->updating)
7763 compose_close_cb(compose, 0, NULL);
7767 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7769 Compose *compose = (Compose *)data;
7773 if (compose->exteditor_tag != -1) {
7774 if (!compose_ext_editor_kill(compose))
7779 if (compose->modified) {
7780 val = alertpanel(_("Discard message"),
7781 _("This message has been modified. Discard it?"),
7782 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7785 case G_ALERTDEFAULT:
7786 if (prefs_common.autosave)
7787 compose_remove_draft(compose);
7789 case G_ALERTALTERNATE:
7790 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7797 compose_close(compose);
7800 static void compose_set_encoding_cb(gpointer data, guint action,
7803 Compose *compose = (Compose *)data;
7805 if (GTK_CHECK_MENU_ITEM(widget)->active)
7806 compose->out_encoding = (CharSet)action;
7809 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7811 Compose *compose = (Compose *)data;
7813 addressbook_open(compose);
7816 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7818 Compose *compose = (Compose *)data;
7823 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7824 g_return_if_fail(tmpl != NULL);
7826 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7828 val = alertpanel(_("Apply template"), msg,
7829 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7832 if (val == G_ALERTDEFAULT)
7833 compose_template_apply(compose, tmpl, TRUE);
7834 else if (val == G_ALERTALTERNATE)
7835 compose_template_apply(compose, tmpl, FALSE);
7838 static void compose_ext_editor_cb(gpointer data, guint action,
7841 Compose *compose = (Compose *)data;
7843 compose_exec_ext_editor(compose);
7846 static void compose_undo_cb(Compose *compose)
7848 gboolean prev_autowrap = compose->autowrap;
7850 compose->autowrap = FALSE;
7851 undo_undo(compose->undostruct);
7852 compose->autowrap = prev_autowrap;
7855 static void compose_redo_cb(Compose *compose)
7857 gboolean prev_autowrap = compose->autowrap;
7859 compose->autowrap = FALSE;
7860 undo_redo(compose->undostruct);
7861 compose->autowrap = prev_autowrap;
7864 static void entry_cut_clipboard(GtkWidget *entry)
7866 if (GTK_IS_EDITABLE(entry))
7867 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7868 else if (GTK_IS_TEXT_VIEW(entry))
7869 gtk_text_buffer_cut_clipboard(
7870 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7871 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7875 static void entry_copy_clipboard(GtkWidget *entry)
7877 if (GTK_IS_EDITABLE(entry))
7878 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7879 else if (GTK_IS_TEXT_VIEW(entry))
7880 gtk_text_buffer_copy_clipboard(
7881 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7882 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7885 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7886 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
7888 if (GTK_IS_TEXT_VIEW(entry)) {
7889 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7890 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7891 GtkTextIter start_iter, end_iter;
7894 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7896 if (contents == NULL)
7899 /* we shouldn't delete the selection when middle-click-pasting, or we
7900 * can't mid-click-paste our own selection */
7901 if (clip != GDK_SELECTION_PRIMARY)
7902 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7904 if (insert_place == NULL) {
7905 /* if insert_place isn't specified, insert at the cursor.
7906 * used for Ctrl-V pasting */
7907 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7908 start = gtk_text_iter_get_offset(&start_iter);
7909 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7911 /* if insert_place is specified, paste here.
7912 * used for mid-click-pasting */
7913 start = gtk_text_iter_get_offset(insert_place);
7914 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
7918 /* paste unwrapped: mark the paste so it's not wrapped later */
7919 end = start + strlen(contents);
7920 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7921 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7922 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7923 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7924 /* rewrap paragraph now (after a mid-click-paste) */
7925 mark_start = gtk_text_buffer_get_insert(buffer);
7926 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7927 gtk_text_iter_backward_char(&start_iter);
7928 compose_beautify_paragraph(compose, &start_iter, TRUE);
7931 } else if (GTK_IS_EDITABLE(entry))
7932 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7936 static void entry_allsel(GtkWidget *entry)
7938 if (GTK_IS_EDITABLE(entry))
7939 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7940 else if (GTK_IS_TEXT_VIEW(entry)) {
7941 GtkTextIter startiter, enditer;
7942 GtkTextBuffer *textbuf;
7944 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7945 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7946 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7948 gtk_text_buffer_move_mark_by_name(textbuf,
7949 "selection_bound", &startiter);
7950 gtk_text_buffer_move_mark_by_name(textbuf,
7951 "insert", &enditer);
7955 static void compose_cut_cb(Compose *compose)
7957 if (compose->focused_editable &&
7958 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7959 entry_cut_clipboard(compose->focused_editable);
7962 static void compose_copy_cb(Compose *compose)
7964 if (compose->focused_editable &&
7965 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7966 entry_copy_clipboard(compose->focused_editable);
7969 static void compose_paste_cb(Compose *compose)
7972 GtkTextBuffer *buffer;
7974 if (compose->focused_editable &&
7975 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7976 entry_paste_clipboard(compose, compose->focused_editable,
7977 prefs_common.linewrap_pastes,
7978 GDK_SELECTION_CLIPBOARD, NULL);
7982 static void compose_paste_as_quote_cb(Compose *compose)
7984 gint wrap_quote = prefs_common.linewrap_quote;
7985 if (compose->focused_editable &&
7986 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7987 /* let text_insert() (called directly or at a later time
7988 * after the gtk_editable_paste_clipboard) know that
7989 * text is to be inserted as a quotation. implemented
7990 * by using a simple refcount... */
7991 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7992 G_OBJECT(compose->focused_editable),
7993 "paste_as_quotation"));
7994 g_object_set_data(G_OBJECT(compose->focused_editable),
7995 "paste_as_quotation",
7996 GINT_TO_POINTER(paste_as_quotation + 1));
7997 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7998 entry_paste_clipboard(compose, compose->focused_editable,
7999 prefs_common.linewrap_pastes,
8000 GDK_SELECTION_CLIPBOARD, NULL);
8001 prefs_common.linewrap_quote = wrap_quote;
8005 static void compose_paste_no_wrap_cb(Compose *compose)
8008 GtkTextBuffer *buffer;
8010 if (compose->focused_editable &&
8011 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8012 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
8013 GDK_SELECTION_CLIPBOARD, NULL);
8017 static void compose_paste_wrap_cb(Compose *compose)
8020 GtkTextBuffer *buffer;
8022 if (compose->focused_editable &&
8023 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8024 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
8025 GDK_SELECTION_CLIPBOARD, NULL);
8029 static void compose_allsel_cb(Compose *compose)
8031 if (compose->focused_editable &&
8032 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8033 entry_allsel(compose->focused_editable);
8036 static void textview_move_beginning_of_line (GtkTextView *text)
8038 GtkTextBuffer *buffer;
8042 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8044 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8045 mark = gtk_text_buffer_get_insert(buffer);
8046 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8047 gtk_text_iter_set_line_offset(&ins, 0);
8048 gtk_text_buffer_place_cursor(buffer, &ins);
8051 static void textview_move_forward_character (GtkTextView *text)
8053 GtkTextBuffer *buffer;
8057 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8059 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8060 mark = gtk_text_buffer_get_insert(buffer);
8061 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8062 if (gtk_text_iter_forward_cursor_position(&ins))
8063 gtk_text_buffer_place_cursor(buffer, &ins);
8066 static void textview_move_backward_character (GtkTextView *text)
8068 GtkTextBuffer *buffer;
8072 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8074 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8075 mark = gtk_text_buffer_get_insert(buffer);
8076 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8077 if (gtk_text_iter_backward_cursor_position(&ins))
8078 gtk_text_buffer_place_cursor(buffer, &ins);
8081 static void textview_move_forward_word (GtkTextView *text)
8083 GtkTextBuffer *buffer;
8088 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8090 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8091 mark = gtk_text_buffer_get_insert(buffer);
8092 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8093 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8094 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8095 gtk_text_iter_backward_word_start(&ins);
8096 gtk_text_buffer_place_cursor(buffer, &ins);
8100 static void textview_move_backward_word (GtkTextView *text)
8102 GtkTextBuffer *buffer;
8107 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8109 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8110 mark = gtk_text_buffer_get_insert(buffer);
8111 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8112 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8113 if (gtk_text_iter_backward_word_starts(&ins, 1))
8114 gtk_text_buffer_place_cursor(buffer, &ins);
8117 static void textview_move_end_of_line (GtkTextView *text)
8119 GtkTextBuffer *buffer;
8123 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8125 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8126 mark = gtk_text_buffer_get_insert(buffer);
8127 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8128 if (gtk_text_iter_forward_to_line_end(&ins))
8129 gtk_text_buffer_place_cursor(buffer, &ins);
8132 static void textview_move_next_line (GtkTextView *text)
8134 GtkTextBuffer *buffer;
8139 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8141 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8142 mark = gtk_text_buffer_get_insert(buffer);
8143 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8144 offset = gtk_text_iter_get_line_offset(&ins);
8145 if (gtk_text_iter_forward_line(&ins)) {
8146 gtk_text_iter_set_line_offset(&ins, offset);
8147 gtk_text_buffer_place_cursor(buffer, &ins);
8151 static void textview_move_previous_line (GtkTextView *text)
8153 GtkTextBuffer *buffer;
8158 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8160 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8161 mark = gtk_text_buffer_get_insert(buffer);
8162 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8163 offset = gtk_text_iter_get_line_offset(&ins);
8164 if (gtk_text_iter_backward_line(&ins)) {
8165 gtk_text_iter_set_line_offset(&ins, offset);
8166 gtk_text_buffer_place_cursor(buffer, &ins);
8170 static void textview_delete_forward_character (GtkTextView *text)
8172 GtkTextBuffer *buffer;
8174 GtkTextIter ins, end_iter;
8176 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8178 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8179 mark = gtk_text_buffer_get_insert(buffer);
8180 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8182 if (gtk_text_iter_forward_char(&end_iter)) {
8183 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8187 static void textview_delete_backward_character (GtkTextView *text)
8189 GtkTextBuffer *buffer;
8191 GtkTextIter ins, end_iter;
8193 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8195 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8196 mark = gtk_text_buffer_get_insert(buffer);
8197 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8199 if (gtk_text_iter_backward_char(&end_iter)) {
8200 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8204 static void textview_delete_forward_word (GtkTextView *text)
8206 GtkTextBuffer *buffer;
8208 GtkTextIter ins, end_iter;
8210 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8212 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8213 mark = gtk_text_buffer_get_insert(buffer);
8214 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8216 if (gtk_text_iter_forward_word_end(&end_iter)) {
8217 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8221 static void textview_delete_backward_word (GtkTextView *text)
8223 GtkTextBuffer *buffer;
8225 GtkTextIter ins, end_iter;
8227 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8229 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8230 mark = gtk_text_buffer_get_insert(buffer);
8231 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8233 if (gtk_text_iter_backward_word_start(&end_iter)) {
8234 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8238 static void textview_delete_line (GtkTextView *text)
8240 GtkTextBuffer *buffer;
8242 GtkTextIter ins, start_iter, end_iter;
8245 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8247 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8248 mark = gtk_text_buffer_get_insert(buffer);
8249 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8252 gtk_text_iter_set_line_offset(&start_iter, 0);
8255 if (gtk_text_iter_ends_line(&end_iter))
8256 found = gtk_text_iter_forward_char(&end_iter);
8258 found = gtk_text_iter_forward_to_line_end(&end_iter);
8261 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8264 static void textview_delete_to_line_end (GtkTextView *text)
8266 GtkTextBuffer *buffer;
8268 GtkTextIter ins, end_iter;
8271 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8273 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8274 mark = gtk_text_buffer_get_insert(buffer);
8275 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8277 if (gtk_text_iter_ends_line(&end_iter))
8278 found = gtk_text_iter_forward_char(&end_iter);
8280 found = gtk_text_iter_forward_to_line_end(&end_iter);
8282 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8285 static void compose_advanced_action_cb(Compose *compose,
8286 ComposeCallAdvancedAction action)
8288 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8290 void (*do_action) (GtkTextView *text);
8291 } action_table[] = {
8292 {textview_move_beginning_of_line},
8293 {textview_move_forward_character},
8294 {textview_move_backward_character},
8295 {textview_move_forward_word},
8296 {textview_move_backward_word},
8297 {textview_move_end_of_line},
8298 {textview_move_next_line},
8299 {textview_move_previous_line},
8300 {textview_delete_forward_character},
8301 {textview_delete_backward_character},
8302 {textview_delete_forward_word},
8303 {textview_delete_backward_word},
8304 {textview_delete_line},
8305 {NULL}, /* gtk_stext_delete_line_n */
8306 {textview_delete_to_line_end}
8309 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8311 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8312 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8313 if (action_table[action].do_action)
8314 action_table[action].do_action(text);
8316 g_warning("Not implemented yet.");
8320 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8324 if (GTK_IS_EDITABLE(widget)) {
8325 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8326 gtk_editable_set_position(GTK_EDITABLE(widget),
8329 if (widget->parent && widget->parent->parent
8330 && widget->parent->parent->parent) {
8331 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8332 gint y = widget->allocation.y;
8333 gint height = widget->allocation.height;
8334 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8335 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8337 if (y < (int)shown->value) {
8338 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8340 if (y + height > (int)shown->value + (int)shown->page_size) {
8341 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8342 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8343 y + height - (int)shown->page_size - 1);
8345 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8346 (int)shown->upper - (int)shown->page_size - 1);
8353 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8354 compose->focused_editable = widget;
8357 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8359 compose->modified = TRUE;
8360 compose_set_title(compose);
8363 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8365 Compose *compose = (Compose *)data;
8368 compose_wrap_all_full(compose, TRUE);
8370 compose_beautify_paragraph(compose, NULL, TRUE);
8373 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8375 Compose *compose = (Compose *)data;
8377 message_search_compose(compose);
8380 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8383 Compose *compose = (Compose *)data;
8384 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8385 if (compose->autowrap)
8386 compose_wrap_all_full(compose, TRUE);
8387 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8390 static void compose_toggle_sign_cb(gpointer data, guint action,
8393 Compose *compose = (Compose *)data;
8395 if (GTK_CHECK_MENU_ITEM(widget)->active)
8396 compose->use_signing = TRUE;
8398 compose->use_signing = FALSE;
8401 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8404 Compose *compose = (Compose *)data;
8406 if (GTK_CHECK_MENU_ITEM(widget)->active)
8407 compose->use_encryption = TRUE;
8409 compose->use_encryption = FALSE;
8412 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8414 g_free(compose->privacy_system);
8416 compose->privacy_system = g_strdup(account->default_privacy_system);
8417 compose_update_privacy_system_menu_item(compose, warn);
8420 static void compose_toggle_ruler_cb(gpointer data, guint action,
8423 Compose *compose = (Compose *)data;
8425 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8426 gtk_widget_show(compose->ruler_hbox);
8427 prefs_common.show_ruler = TRUE;
8429 gtk_widget_hide(compose->ruler_hbox);
8430 gtk_widget_queue_resize(compose->edit_vbox);
8431 prefs_common.show_ruler = FALSE;
8435 static void compose_attach_drag_received_cb (GtkWidget *widget,
8436 GdkDragContext *context,
8439 GtkSelectionData *data,
8444 Compose *compose = (Compose *)user_data;
8447 if (gdk_atom_name(data->type) &&
8448 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8449 && gtk_drag_get_source_widget(context) !=
8450 mainwindow_get_mainwindow()->summaryview->ctree) {
8451 list = uri_list_extract_filenames((const gchar *)data->data);
8452 for (tmp = list; tmp != NULL; tmp = tmp->next)
8453 compose_attach_append
8454 (compose, (const gchar *)tmp->data,
8455 (const gchar *)tmp->data, NULL);
8456 if (list) compose_changed_cb(NULL, compose);
8457 list_free_strings(list);
8459 } else if (gtk_drag_get_source_widget(context)
8460 == mainwindow_get_mainwindow()->summaryview->ctree) {
8461 /* comes from our summaryview */
8462 SummaryView * summaryview = NULL;
8463 GSList * list = NULL, *cur = NULL;
8465 if (mainwindow_get_mainwindow())
8466 summaryview = mainwindow_get_mainwindow()->summaryview;
8469 list = summary_get_selected_msg_list(summaryview);
8471 for (cur = list; cur; cur = cur->next) {
8472 MsgInfo *msginfo = (MsgInfo *)cur->data;
8475 file = procmsg_get_message_file_full(msginfo,
8478 compose_attach_append(compose, (const gchar *)file,
8479 (const gchar *)file, "message/rfc822");
8487 static gboolean compose_drag_drop(GtkWidget *widget,
8488 GdkDragContext *drag_context,
8490 guint time, gpointer user_data)
8492 /* not handling this signal makes compose_insert_drag_received_cb
8497 static void compose_insert_drag_received_cb (GtkWidget *widget,
8498 GdkDragContext *drag_context,
8501 GtkSelectionData *data,
8506 Compose *compose = (Compose *)user_data;
8509 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8511 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8512 list = uri_list_extract_filenames((const gchar *)data->data);
8513 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8514 compose_insert_file(compose, (const gchar *)tmp->data);
8516 list_free_strings(list);
8518 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8521 #if GTK_CHECK_VERSION(2, 8, 0)
8522 /* do nothing, handled by GTK */
8524 gchar *tmpfile = get_tmp_file();
8525 str_write_to_file((const gchar *)data->data, tmpfile);
8526 compose_insert_file(compose, tmpfile);
8529 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8533 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8536 static void compose_header_drag_received_cb (GtkWidget *widget,
8537 GdkDragContext *drag_context,
8540 GtkSelectionData *data,
8545 GtkEditable *entry = (GtkEditable *)user_data;
8546 gchar *email = (gchar *)data->data;
8548 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8551 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8552 gchar *decoded=g_new(gchar, strlen(email));
8555 email += strlen("mailto:");
8556 decode_uri(decoded, email); /* will fit */
8557 gtk_editable_delete_text(entry, 0, -1);
8558 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8559 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8563 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8566 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8569 Compose *compose = (Compose *)data;
8571 if (GTK_CHECK_MENU_ITEM(widget)->active)
8572 compose->return_receipt = TRUE;
8574 compose->return_receipt = FALSE;
8577 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8580 Compose *compose = (Compose *)data;
8582 if (GTK_CHECK_MENU_ITEM(widget)->active)
8583 compose->remove_references = TRUE;
8585 compose->remove_references = FALSE;
8588 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8590 ComposeHeaderEntry *headerentry)
8592 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8593 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8594 !(event->state & GDK_MODIFIER_MASK) &&
8595 (event->keyval == GDK_BackSpace) &&
8596 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8597 gtk_container_remove
8598 (GTK_CONTAINER(headerentry->compose->header_table),
8599 headerentry->combo);
8600 gtk_container_remove
8601 (GTK_CONTAINER(headerentry->compose->header_table),
8602 headerentry->entry);
8603 headerentry->compose->header_list =
8604 g_slist_remove(headerentry->compose->header_list,
8606 g_free(headerentry);
8607 } else if (event->keyval == GDK_Tab) {
8608 if (headerentry->compose->header_last == headerentry) {
8609 /* Override default next focus, and give it to subject_entry
8610 * instead of notebook tabs
8612 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8613 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8620 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8621 ComposeHeaderEntry *headerentry)
8623 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8624 headerentry->compose->header_list =
8625 g_slist_append(headerentry->compose->header_list,
8628 compose_create_header_entry(headerentry->compose);
8629 g_signal_handlers_disconnect_matched
8630 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8631 0, 0, NULL, NULL, headerentry);
8633 /* Automatically scroll down */
8634 compose_show_first_last_header(headerentry->compose, FALSE);
8640 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8642 GtkAdjustment *vadj;
8644 g_return_if_fail(compose);
8645 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8646 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8648 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8649 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8652 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8653 const gchar *text, gint len, Compose *compose)
8655 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8656 (G_OBJECT(compose->text), "paste_as_quotation"));
8659 g_return_if_fail(text != NULL);
8661 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8662 G_CALLBACK(text_inserted),
8664 if (paste_as_quotation) {
8671 new_text = g_strndup(text, len);
8672 if (prefs_common.quotemark && *prefs_common.quotemark)
8673 qmark = prefs_common.quotemark;
8677 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8678 gtk_text_buffer_place_cursor(buffer, iter);
8680 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8682 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8683 GINT_TO_POINTER(paste_as_quotation - 1));
8685 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8686 gtk_text_buffer_place_cursor(buffer, iter);
8688 if (strcmp(text, "\n") || automatic_break
8689 || gtk_text_iter_starts_line(iter))
8690 gtk_text_buffer_insert(buffer, iter, text, len);
8692 debug_print("insert nowrap \\n\n");
8693 gtk_text_buffer_insert_with_tags_by_name(buffer,
8694 iter, text, len, "no_join", NULL);
8698 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8700 compose_beautify_paragraph(compose, iter, FALSE);
8702 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8703 gtk_text_buffer_delete_mark(buffer, mark);
8705 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8706 G_CALLBACK(text_inserted),
8708 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8710 if (prefs_common.autosave &&
8711 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8712 compose->draft_timeout_tag = gtk_timeout_add
8713 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8715 static gint compose_defer_auto_save_draft(Compose *compose)
8717 compose->draft_timeout_tag = -1;
8718 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8723 static void compose_check_all(Compose *compose)
8725 if (compose->gtkaspell)
8726 gtkaspell_check_all(compose->gtkaspell);
8729 static void compose_highlight_all(Compose *compose)
8731 if (compose->gtkaspell)
8732 gtkaspell_highlight_all(compose->gtkaspell);
8735 static void compose_check_backwards(Compose *compose)
8737 if (compose->gtkaspell)
8738 gtkaspell_check_backwards(compose->gtkaspell);
8740 GtkItemFactory *ifactory;
8741 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8742 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8743 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8747 static void compose_check_forwards_go(Compose *compose)
8749 if (compose->gtkaspell)
8750 gtkaspell_check_forwards_go(compose->gtkaspell);
8752 GtkItemFactory *ifactory;
8753 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8754 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8755 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8761 *\brief Guess originating forward account from MsgInfo and several
8762 * "common preference" settings. Return NULL if no guess.
8764 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8766 PrefsAccount *account = NULL;
8768 g_return_val_if_fail(msginfo, NULL);
8769 g_return_val_if_fail(msginfo->folder, NULL);
8770 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8772 if (msginfo->folder->prefs->enable_default_account)
8773 account = account_find_from_id(msginfo->folder->prefs->default_account);
8776 account = msginfo->folder->folder->account;
8778 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8780 Xstrdup_a(to, msginfo->to, return NULL);
8781 extract_address(to);
8782 account = account_find_from_address(to);
8785 if (!account && prefs_common.forward_account_autosel) {
8787 if (!procheader_get_header_from_msginfo
8788 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8789 extract_address(cc);
8790 account = account_find_from_address(cc);
8797 gboolean compose_close(Compose *compose)
8801 if (!g_mutex_trylock(compose->mutex)) {
8802 /* we have to wait for the (possibly deferred by auto-save)
8803 * drafting to be done, before destroying the compose under
8805 debug_print("waiting for drafting to finish...\n");
8806 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8809 g_return_val_if_fail(compose, FALSE);
8810 gtkut_widget_get_uposition(compose->window, &x, &y);
8811 prefs_common.compose_x = x;
8812 prefs_common.compose_y = y;
8813 g_mutex_unlock(compose->mutex);
8814 compose_destroy(compose);
8819 * Add entry field for each address in list.
8820 * \param compose E-Mail composition object.
8821 * \param listAddress List of (formatted) E-Mail addresses.
8823 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8828 addr = ( gchar * ) node->data;
8829 compose_entry_append( compose, addr, COMPOSE_TO );
8830 node = g_list_next( node );
8834 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
8835 guint action, gboolean opening_multiple)
8838 GSList *new_msglist = NULL;
8839 MsgInfo *tmp_msginfo = NULL;
8840 gboolean originally_enc = FALSE;
8841 Compose *compose = NULL;
8843 g_return_if_fail(msgview != NULL);
8845 g_return_if_fail(msginfo_list != NULL);
8847 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
8848 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8849 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8851 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8852 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8853 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8854 orig_msginfo, mimeinfo);
8855 if (tmp_msginfo != NULL) {
8856 new_msglist = g_slist_append(NULL, tmp_msginfo);
8857 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8858 originally_enc = TRUE;
8864 if (!opening_multiple)
8865 body = messageview_get_selection(msgview);
8868 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8869 procmsg_msginfo_free(tmp_msginfo);
8870 g_slist_free(new_msglist);
8872 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8874 if (originally_enc) {
8875 compose_force_encryption(compose, compose->account, FALSE);
8881 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8884 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
8885 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
8886 GSList *cur = msginfo_list;
8887 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
8888 "messages. Opening the windows "
8889 "could take some time. Do you "
8890 "want to continue?"),
8891 g_slist_length(msginfo_list));
8892 if (g_slist_length(msginfo_list) > 9
8893 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
8894 != G_ALERTALTERNATE) {
8899 /* We'll open multiple compose windows */
8900 /* let the WM place the next windows */
8901 compose_force_window_origin = FALSE;
8902 for (; cur; cur = cur->next) {
8904 tmplist.data = cur->data;
8905 tmplist.next = NULL;
8906 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
8908 compose_force_window_origin = TRUE;
8910 /* forwarding multiple mails as attachments is done via a
8911 * single compose window */
8912 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
8916 void compose_set_position(Compose *compose, gint pos)
8918 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8920 gtkut_text_view_set_position(text, pos);
8923 gboolean compose_search_string(Compose *compose,
8924 const gchar *str, gboolean case_sens)
8926 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8928 return gtkut_text_view_search_string(text, str, case_sens);
8931 gboolean compose_search_string_backward(Compose *compose,
8932 const gchar *str, gboolean case_sens)
8934 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8936 return gtkut_text_view_search_string_backward(text, str, case_sens);