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 (Compose *compose,
278 static gint compose_queue_sub (Compose *compose,
282 gboolean check_subject);
283 static void compose_add_attachments (Compose *compose,
285 static gchar *compose_get_header (Compose *compose);
287 static void compose_convert_header (Compose *compose,
292 gboolean addr_field);
294 static void compose_attach_info_free (AttachInfo *ainfo);
295 static void compose_attach_remove_selected (Compose *compose);
297 static void compose_attach_property (Compose *compose);
298 static void compose_attach_property_create (gboolean *cancelled);
299 static void attach_property_ok (GtkWidget *widget,
300 gboolean *cancelled);
301 static void attach_property_cancel (GtkWidget *widget,
302 gboolean *cancelled);
303 static gint attach_property_delete_event (GtkWidget *widget,
305 gboolean *cancelled);
306 static gboolean attach_property_key_pressed (GtkWidget *widget,
308 gboolean *cancelled);
310 static void compose_exec_ext_editor (Compose *compose);
312 static gint compose_exec_ext_editor_real (const gchar *file);
313 static gboolean compose_ext_editor_kill (Compose *compose);
314 static gboolean compose_input_cb (GIOChannel *source,
315 GIOCondition condition,
317 static void compose_set_ext_editor_sensitive (Compose *compose,
319 #endif /* G_OS_UNIX */
321 static void compose_undo_state_changed (UndoMain *undostruct,
326 static void compose_create_header_entry (Compose *compose);
327 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
328 static void compose_update_priority_menu_item(Compose * compose);
330 static void compose_add_field_list ( Compose *compose,
331 GList *listAddress );
333 /* callback functions */
335 static gboolean compose_edit_size_alloc (GtkEditable *widget,
336 GtkAllocation *allocation,
337 GtkSHRuler *shruler);
338 static void account_activated (GtkMenuItem *menuitem,
340 static void attach_selected (GtkTreeView *tree_view,
341 GtkTreePath *tree_path,
342 GtkTreeViewColumn *column,
344 static gboolean attach_button_pressed (GtkWidget *widget,
345 GdkEventButton *event,
347 static gboolean attach_key_pressed (GtkWidget *widget,
351 static void compose_send_cb (gpointer data,
354 static void compose_send_later_cb (gpointer data,
358 static void compose_draft_cb (gpointer data,
362 static void compose_attach_cb (gpointer data,
365 static void compose_insert_file_cb (gpointer data,
368 static void compose_insert_sig_cb (gpointer data,
372 static void compose_close_cb (gpointer data,
376 static void compose_set_encoding_cb (gpointer data,
380 static void compose_address_cb (gpointer data,
383 static void compose_template_activate_cb(GtkWidget *widget,
386 static void compose_ext_editor_cb (gpointer data,
390 static gint compose_delete_cb (GtkWidget *widget,
394 static void compose_undo_cb (Compose *compose);
395 static void compose_redo_cb (Compose *compose);
396 static void compose_cut_cb (Compose *compose);
397 static void compose_copy_cb (Compose *compose);
398 static void compose_paste_cb (Compose *compose);
399 static void compose_paste_as_quote_cb (Compose *compose);
400 static void compose_paste_no_wrap_cb (Compose *compose);
401 static void compose_paste_wrap_cb (Compose *compose);
402 static void compose_allsel_cb (Compose *compose);
404 static void compose_advanced_action_cb (Compose *compose,
405 ComposeCallAdvancedAction action);
407 static void compose_grab_focus_cb (GtkWidget *widget,
410 static void compose_changed_cb (GtkTextBuffer *textbuf,
413 static void compose_wrap_cb (gpointer data,
416 static void compose_find_cb (gpointer data,
419 static void compose_toggle_autowrap_cb (gpointer data,
423 static void compose_toggle_ruler_cb (gpointer data,
426 static void compose_toggle_sign_cb (gpointer data,
429 static void compose_toggle_encrypt_cb (gpointer data,
432 static void compose_set_privacy_system_cb(GtkWidget *widget,
434 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
435 static void activate_privacy_system (Compose *compose,
436 PrefsAccount *account,
438 static void compose_use_signing(Compose *compose, gboolean use_signing);
439 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
440 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
442 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
444 static void compose_set_priority_cb (gpointer data,
448 static void compose_attach_drag_received_cb (GtkWidget *widget,
449 GdkDragContext *drag_context,
452 GtkSelectionData *data,
456 static void compose_insert_drag_received_cb (GtkWidget *widget,
457 GdkDragContext *drag_context,
460 GtkSelectionData *data,
464 static void compose_header_drag_received_cb (GtkWidget *widget,
465 GdkDragContext *drag_context,
468 GtkSelectionData *data,
473 static gboolean compose_drag_drop (GtkWidget *widget,
474 GdkDragContext *drag_context,
476 guint time, gpointer user_data);
478 static void text_inserted (GtkTextBuffer *buffer,
483 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
484 gboolean to_all, gboolean to_ml,
486 gboolean followup_and_reply_to,
489 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
490 ComposeHeaderEntry *headerentry);
491 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
493 ComposeHeaderEntry *headerentry);
495 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
497 static void compose_allow_user_actions (Compose *compose, gboolean allow);
500 static void compose_check_all (Compose *compose);
501 static void compose_highlight_all (Compose *compose);
502 static void compose_check_backwards (Compose *compose);
503 static void compose_check_forwards_go (Compose *compose);
506 static gint compose_defer_auto_save_draft (Compose *compose);
507 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
509 static gboolean compose_close (Compose *compose);
511 static GtkItemFactoryEntry compose_popup_entries[] =
513 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
514 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
515 {N_("/---"), NULL, NULL, 0, "<Separator>"},
516 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
519 static GtkItemFactoryEntry compose_entries[] =
521 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
522 {N_("/_Message/_Send"), "<control>Return",
523 compose_send_cb, 0, NULL},
524 {N_("/_Message/Send _later"), "<shift><control>S",
525 compose_send_later_cb, 0, NULL},
526 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
528 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
529 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Save"),
532 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
533 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
536 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
537 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
538 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
539 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
540 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
541 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
542 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
543 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
544 {N_("/_Edit/Special paste/as _quotation"),
545 NULL, compose_paste_as_quote_cb, 0, NULL},
546 {N_("/_Edit/Special paste/_wrapped"),
547 NULL, compose_paste_wrap_cb, 0, NULL},
548 {N_("/_Edit/Special paste/_unwrapped"),
549 NULL, compose_paste_no_wrap_cb, 0, NULL},
550 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
551 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
552 {N_("/_Edit/A_dvanced/Move a character backward"),
554 compose_advanced_action_cb,
555 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
557 {N_("/_Edit/A_dvanced/Move a character forward"),
559 compose_advanced_action_cb,
560 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
562 {N_("/_Edit/A_dvanced/Move a word backward"),
564 compose_advanced_action_cb,
565 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
567 {N_("/_Edit/A_dvanced/Move a word forward"),
569 compose_advanced_action_cb,
570 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
572 {N_("/_Edit/A_dvanced/Move to beginning of line"),
573 NULL, /* "<control>A" */
574 compose_advanced_action_cb,
575 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
577 {N_("/_Edit/A_dvanced/Move to end of line"),
579 compose_advanced_action_cb,
580 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
582 {N_("/_Edit/A_dvanced/Move to previous line"),
584 compose_advanced_action_cb,
585 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
587 {N_("/_Edit/A_dvanced/Move to next line"),
589 compose_advanced_action_cb,
590 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
592 {N_("/_Edit/A_dvanced/Delete a character backward"),
594 compose_advanced_action_cb,
595 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
597 {N_("/_Edit/A_dvanced/Delete a character forward"),
599 compose_advanced_action_cb,
600 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
602 {N_("/_Edit/A_dvanced/Delete a word backward"),
603 NULL, /* "<control>W" */
604 compose_advanced_action_cb,
605 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
607 {N_("/_Edit/A_dvanced/Delete a word forward"),
608 NULL, /* "<alt>D", */
609 compose_advanced_action_cb,
610 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
612 {N_("/_Edit/A_dvanced/Delete line"),
614 compose_advanced_action_cb,
615 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
617 {N_("/_Edit/A_dvanced/Delete entire line"),
619 compose_advanced_action_cb,
620 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
622 {N_("/_Edit/A_dvanced/Delete to end of line"),
624 compose_advanced_action_cb,
625 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
627 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
629 "<control>F", compose_find_cb, 0, NULL},
630 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_Edit/_Wrap current paragraph"),
632 "<control>L", compose_wrap_cb, 0, NULL},
633 {N_("/_Edit/Wrap all long _lines"),
634 "<control><alt>L", compose_wrap_cb, 1, NULL},
635 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
636 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_Edit/Edit with e_xternal editor"),
638 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
640 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Spelling/_Check all or check selection"),
642 NULL, compose_check_all, 0, NULL},
643 {N_("/_Spelling/_Highlight all misspelled words"),
644 NULL, compose_highlight_all, 0, NULL},
645 {N_("/_Spelling/Check _backwards misspelled word"),
646 NULL, compose_check_backwards , 0, NULL},
647 {N_("/_Spelling/_Forward to next misspelled word"),
648 NULL, compose_check_forwards_go, 0, NULL},
649 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
650 {N_("/_Spelling/Options"),
651 NULL, NULL, 0, "<Branch>"},
653 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
655 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
656 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
657 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
658 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
660 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
661 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
662 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
663 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
664 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
665 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
667 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
668 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
669 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
671 #define ENC_ACTION(action) \
672 NULL, compose_set_encoding_cb, action, \
673 "/Options/Character encoding/Automatic"
675 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
676 {N_("/_Options/Character _encoding/_Automatic"),
677 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
678 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
680 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
681 ENC_ACTION(C_US_ASCII)},
682 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
683 ENC_ACTION(C_UTF_8)},
684 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
686 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
687 ENC_ACTION(C_ISO_8859_1)},
688 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
689 ENC_ACTION(C_ISO_8859_15)},
690 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
691 ENC_ACTION(C_WINDOWS_1252)},
692 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
694 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
695 ENC_ACTION(C_ISO_8859_2)},
696 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
698 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
699 ENC_ACTION(C_ISO_8859_13)},
700 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
701 ENC_ACTION(C_ISO_8859_4)},
702 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
704 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
705 ENC_ACTION(C_ISO_8859_7)},
706 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
708 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
709 ENC_ACTION(C_ISO_8859_8)},
710 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
711 ENC_ACTION(C_WINDOWS_1255)},
712 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
714 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
715 ENC_ACTION(C_ISO_8859_6)},
716 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
717 ENC_ACTION(C_CP1256)},
718 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
720 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
721 ENC_ACTION(C_ISO_8859_9)},
722 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
724 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
725 ENC_ACTION(C_ISO_8859_5)},
726 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
727 ENC_ACTION(C_KOI8_R)},
728 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
729 ENC_ACTION(C_KOI8_U)},
730 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
731 ENC_ACTION(C_WINDOWS_1251)},
732 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
735 ENC_ACTION(C_ISO_2022_JP)},
736 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
738 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
739 ENC_ACTION(C_GB2312)},
740 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
742 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
744 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
745 ENC_ACTION(C_EUC_TW)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
749 ENC_ACTION(C_EUC_KR)},
750 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
752 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
753 ENC_ACTION(C_TIS_620)},
754 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
755 ENC_ACTION(C_WINDOWS_874)},
757 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
759 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
760 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
761 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
762 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
763 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
766 static GtkTargetEntry compose_mime_types[] =
768 {"text/uri-list", 0, 0},
769 {"text/plain", 0, 0},
773 static gboolean compose_put_existing_to_front(MsgInfo *info)
775 GList *compose_list = compose_get_compose_list();
779 for (elem = compose_list; elem != NULL && elem->data != NULL;
781 Compose *c = (Compose*)elem->data;
783 if (!c->targetinfo || !c->targetinfo->msgid ||
787 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
788 gtkut_window_popup(c->window);
796 static GdkColor quote_color1 =
797 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
798 static GdkColor quote_color2 =
799 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
800 static GdkColor quote_color3 =
801 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
803 static GdkColor quote_bgcolor1 =
804 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
805 static GdkColor quote_bgcolor2 =
806 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
807 static GdkColor quote_bgcolor3 =
808 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
810 static GdkColor signature_color = {
817 static GdkColor uri_color = {
824 static void compose_create_tags(GtkTextView *text, Compose *compose)
826 GtkTextBuffer *buffer;
827 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
833 buffer = gtk_text_view_get_buffer(text);
835 if (prefs_common.enable_color) {
836 /* grab the quote colors, converting from an int to a GdkColor */
837 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
839 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
841 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
843 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
845 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
847 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
849 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
851 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
854 signature_color = quote_color1 = quote_color2 = quote_color3 =
855 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
858 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
859 gtk_text_buffer_create_tag(buffer, "quote0",
860 "foreground-gdk", "e_color1,
861 "paragraph-background-gdk", "e_bgcolor1,
863 gtk_text_buffer_create_tag(buffer, "quote1",
864 "foreground-gdk", "e_color2,
865 "paragraph-background-gdk", "e_bgcolor2,
867 gtk_text_buffer_create_tag(buffer, "quote2",
868 "foreground-gdk", "e_color3,
869 "paragraph-background-gdk", "e_bgcolor3,
872 gtk_text_buffer_create_tag(buffer, "quote0",
873 "foreground-gdk", "e_color1,
875 gtk_text_buffer_create_tag(buffer, "quote1",
876 "foreground-gdk", "e_color2,
878 gtk_text_buffer_create_tag(buffer, "quote2",
879 "foreground-gdk", "e_color3,
883 gtk_text_buffer_create_tag(buffer, "signature",
884 "foreground-gdk", &signature_color,
886 gtk_text_buffer_create_tag(buffer, "link",
887 "foreground-gdk", &uri_color,
889 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
890 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
892 color[0] = quote_color1;
893 color[1] = quote_color2;
894 color[2] = quote_color3;
895 color[3] = quote_bgcolor1;
896 color[4] = quote_bgcolor2;
897 color[5] = quote_bgcolor3;
898 color[6] = signature_color;
899 color[7] = uri_color;
900 cmap = gdk_drawable_get_colormap(compose->window->window);
901 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
903 for (i = 0; i < 8; i++) {
904 if (success[i] == FALSE) {
907 g_warning("Compose: color allocation failed.\n");
908 style = gtk_widget_get_style(text);
909 quote_color1 = quote_color2 = quote_color3 =
910 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
911 signature_color = uri_color = black;
916 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
917 GPtrArray *attach_files)
919 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
922 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
924 return compose_generic_new(account, NULL, item, NULL, NULL);
927 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
929 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
932 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
933 GPtrArray *attach_files, GList *listAddress )
936 GtkTextView *textview;
937 GtkTextBuffer *textbuf;
939 GtkItemFactory *ifactory;
941 if (item && item->prefs && item->prefs->enable_default_account)
942 account = account_find_from_id(item->prefs->default_account);
944 if (!account) account = cur_account;
945 g_return_val_if_fail(account != NULL, NULL);
947 compose = compose_create(account, COMPOSE_NEW, FALSE);
949 ifactory = gtk_item_factory_from_widget(compose->menubar);
951 compose->replyinfo = NULL;
952 compose->fwdinfo = NULL;
954 textview = GTK_TEXT_VIEW(compose->text);
955 textbuf = gtk_text_view_get_buffer(textview);
956 compose_create_tags(textview, compose);
958 undo_block(compose->undostruct);
960 if (item && item->prefs && item->prefs->enable_default_dictionary &&
962 gtkaspell_change_dict(compose->gtkaspell,
963 item->prefs->default_dictionary);
966 if (account->auto_sig)
967 compose_insert_sig(compose, FALSE);
968 gtk_text_buffer_get_start_iter(textbuf, &iter);
969 gtk_text_buffer_place_cursor(textbuf, &iter);
971 if (account->protocol != A_NNTP) {
972 if (mailto && *mailto != '\0') {
973 compose_entries_set(compose, mailto);
975 } else if (item && item->prefs->enable_default_to) {
976 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
977 compose_entry_mark_default_to(compose, item->prefs->default_to);
979 if (item && item->ret_rcpt) {
980 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
984 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
986 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
989 * CLAWS: just don't allow return receipt request, even if the user
990 * may want to send an email. simple but foolproof.
992 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
994 compose_add_field_list( compose, listAddress );
1000 for (i = 0; i < attach_files->len; i++) {
1001 file = g_ptr_array_index(attach_files, i);
1002 compose_attach_append(compose, file, file, NULL);
1006 compose_show_first_last_header(compose, TRUE);
1008 /* Set save folder */
1009 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1010 gchar *folderidentifier;
1012 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1013 folderidentifier = folder_item_get_identifier(item);
1014 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1015 g_free(folderidentifier);
1018 gtk_widget_grab_focus(compose->header_last->entry);
1020 undo_unblock(compose->undostruct);
1022 if (prefs_common.auto_exteditor)
1023 compose_exec_ext_editor(compose);
1025 compose->modified = FALSE;
1026 compose_set_title(compose);
1030 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1031 gboolean override_pref)
1033 gchar *privacy = NULL;
1035 g_return_if_fail(compose != NULL);
1036 g_return_if_fail(account != NULL);
1038 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1041 if (account->default_privacy_system
1042 && strlen(account->default_privacy_system)) {
1043 privacy = account->default_privacy_system;
1045 GSList *privacy_avail = privacy_get_system_ids();
1046 if (privacy_avail && g_slist_length(privacy_avail)) {
1047 privacy = (gchar *)(privacy_avail->data);
1050 if (privacy != NULL) {
1051 compose->privacy_system = g_strdup(privacy);
1052 compose_update_privacy_system_menu_item(compose, FALSE);
1053 compose_use_encryption(compose, TRUE);
1057 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1059 gchar *privacy = NULL;
1061 if (account->default_privacy_system
1062 && strlen(account->default_privacy_system)) {
1063 privacy = account->default_privacy_system;
1065 GSList *privacy_avail = privacy_get_system_ids();
1066 if (privacy_avail && g_slist_length(privacy_avail)) {
1067 privacy = (gchar *)(privacy_avail->data);
1070 if (privacy != NULL) {
1071 compose->privacy_system = g_strdup(privacy);
1072 compose_update_privacy_system_menu_item(compose, FALSE);
1073 compose_use_signing(compose, TRUE);
1077 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1081 Compose *compose = NULL;
1082 g_return_val_if_fail(msginfo_list != NULL, NULL);
1084 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1085 g_return_val_if_fail(msginfo != NULL, NULL);
1087 list_len = g_slist_length(msginfo_list);
1091 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1092 FALSE, prefs_common.default_reply_list, FALSE, body);
1094 case COMPOSE_REPLY_WITH_QUOTE:
1095 compose = compose_reply(msginfo, TRUE,
1096 FALSE, prefs_common.default_reply_list, FALSE, body);
1098 case COMPOSE_REPLY_WITHOUT_QUOTE:
1099 compose = compose_reply(msginfo, FALSE,
1100 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1102 case COMPOSE_REPLY_TO_SENDER:
1103 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1104 FALSE, FALSE, TRUE, body);
1106 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1107 compose = compose_followup_and_reply_to(msginfo,
1108 prefs_common.reply_with_quote,
1109 FALSE, FALSE, body);
1111 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1112 compose = compose_reply(msginfo, TRUE,
1113 FALSE, FALSE, TRUE, body);
1115 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1116 compose = compose_reply(msginfo, FALSE,
1117 FALSE, FALSE, TRUE, NULL);
1119 case COMPOSE_REPLY_TO_ALL:
1120 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1121 TRUE, FALSE, FALSE, body);
1123 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1124 compose = compose_reply(msginfo, TRUE,
1125 TRUE, FALSE, FALSE, body);
1127 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1128 compose = compose_reply(msginfo, FALSE,
1129 TRUE, FALSE, FALSE, NULL);
1131 case COMPOSE_REPLY_TO_LIST:
1132 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1133 FALSE, TRUE, FALSE, body);
1135 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1136 compose = compose_reply(msginfo, TRUE,
1137 FALSE, TRUE, FALSE, body);
1139 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1140 compose = compose_reply(msginfo, FALSE,
1141 FALSE, TRUE, FALSE, NULL);
1143 case COMPOSE_FORWARD:
1144 if (prefs_common.forward_as_attachment) {
1145 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1148 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1152 case COMPOSE_FORWARD_INLINE:
1153 /* check if we reply to more than one Message */
1154 if (list_len == 1) {
1155 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1158 /* more messages FALL THROUGH */
1159 case COMPOSE_FORWARD_AS_ATTACH:
1160 compose = compose_forward_multiple(NULL, msginfo_list);
1162 case COMPOSE_REDIRECT:
1163 compose = compose_redirect(NULL, msginfo, FALSE);
1166 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1171 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1172 gboolean to_ml, gboolean to_sender,
1175 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1176 to_sender, FALSE, body);
1179 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1184 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1185 to_sender, TRUE, body);
1188 static void compose_extract_original_charset(Compose *compose)
1190 MsgInfo *info = NULL;
1191 if (compose->replyinfo) {
1192 info = compose->replyinfo;
1193 } else if (compose->fwdinfo) {
1194 info = compose->fwdinfo;
1195 } else if (compose->targetinfo) {
1196 info = compose->targetinfo;
1199 MimeInfo *mimeinfo = procmime_scan_message(info);
1200 MimeInfo *partinfo = mimeinfo;
1201 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1202 partinfo = procmime_mimeinfo_next(partinfo);
1204 compose->orig_charset =
1205 g_strdup(procmime_mimeinfo_get_parameter(
1206 partinfo, "charset"));
1208 procmime_mimeinfo_free_all(mimeinfo);
1212 #define SIGNAL_BLOCK(buffer) { \
1213 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1214 G_CALLBACK(compose_changed_cb), \
1216 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1217 G_CALLBACK(text_inserted), \
1221 #define SIGNAL_UNBLOCK(buffer) { \
1222 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1223 G_CALLBACK(compose_changed_cb), \
1225 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1226 G_CALLBACK(text_inserted), \
1230 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1231 gboolean to_all, gboolean to_ml,
1233 gboolean followup_and_reply_to,
1236 GtkItemFactory *ifactory;
1238 PrefsAccount *account = NULL;
1239 PrefsAccount *reply_account;
1240 GtkTextView *textview;
1241 GtkTextBuffer *textbuf;
1243 g_return_val_if_fail(msginfo != NULL, NULL);
1244 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1246 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1248 g_return_val_if_fail(account != NULL, NULL);
1250 if (to_sender && account->protocol == A_NNTP &&
1251 !followup_and_reply_to) {
1253 account_find_from_address(account->address);
1255 reply_account = compose_current_mail_account();
1259 reply_account = account;
1261 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1262 ifactory = gtk_item_factory_from_widget(compose->menubar);
1264 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1265 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1267 compose->updating = TRUE;
1268 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1269 if (!compose->replyinfo)
1270 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1271 compose->updating = FALSE;
1273 if (compose->deferred_destroy) {
1274 compose_destroy(compose);
1278 compose_extract_original_charset(compose);
1280 if (msginfo->folder && msginfo->folder->ret_rcpt)
1281 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1283 /* Set save folder */
1284 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1285 gchar *folderidentifier;
1287 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1288 folderidentifier = folder_item_get_identifier(msginfo->folder);
1289 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1290 g_free(folderidentifier);
1293 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1294 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1295 to_sender, followup_and_reply_to);
1296 compose_show_first_last_header(compose, TRUE);
1298 textview = (GTK_TEXT_VIEW(compose->text));
1299 textbuf = gtk_text_view_get_buffer(textview);
1300 compose_create_tags(textview, compose);
1302 undo_block(compose->undostruct);
1304 if (msginfo->folder && msginfo->folder->prefs &&
1305 msginfo->folder->prefs &&
1306 msginfo->folder->prefs->enable_default_dictionary &&
1308 gtkaspell_change_dict(compose->gtkaspell,
1309 msginfo->folder->prefs->default_dictionary);
1315 if (prefs_common.quotemark && *prefs_common.quotemark)
1316 qmark = prefs_common.quotemark;
1320 compose_quote_fmt(compose, compose->replyinfo,
1321 prefs_common.quotefmt,
1322 qmark, body, FALSE);
1324 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1325 compose_force_encryption(compose, account, FALSE);
1328 SIGNAL_BLOCK(textbuf);
1330 if (account->auto_sig)
1331 compose_insert_sig(compose, FALSE);
1333 compose_wrap_all(compose);
1335 SIGNAL_UNBLOCK(textbuf);
1337 gtk_widget_grab_focus(compose->text);
1339 undo_unblock(compose->undostruct);
1341 if (prefs_common.auto_exteditor)
1342 compose_exec_ext_editor(compose);
1344 compose->modified = FALSE;
1345 compose_set_title(compose);
1349 #define INSERT_FW_HEADER(var, hdr) \
1350 if (msginfo->var && *msginfo->var) { \
1351 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1352 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1353 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1356 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1357 gboolean as_attach, const gchar *body,
1358 gboolean no_extedit,
1362 GtkTextView *textview;
1363 GtkTextBuffer *textbuf;
1366 g_return_val_if_fail(msginfo != NULL, NULL);
1367 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1370 !(account = compose_guess_forward_account_from_msginfo
1372 account = cur_account;
1374 compose = compose_create(account, COMPOSE_FORWARD, batch);
1376 compose->updating = TRUE;
1377 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1378 if (!compose->fwdinfo)
1379 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1380 compose->updating = FALSE;
1382 if (compose->deferred_destroy) {
1383 compose_destroy(compose);
1387 compose_extract_original_charset(compose);
1389 if (msginfo->subject && *msginfo->subject) {
1390 gchar *buf, *buf2, *p;
1392 buf = p = g_strdup(msginfo->subject);
1393 p += subject_get_prefix_length(p);
1394 memmove(buf, p, strlen(p) + 1);
1396 buf2 = g_strdup_printf("Fw: %s", buf);
1397 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1403 textview = GTK_TEXT_VIEW(compose->text);
1404 textbuf = gtk_text_view_get_buffer(textview);
1405 compose_create_tags(textview, compose);
1407 undo_block(compose->undostruct);
1411 msgfile = procmsg_get_message_file_path(msginfo);
1412 if (!is_file_exist(msgfile))
1413 g_warning("%s: file not exist\n", msgfile);
1415 compose_attach_append(compose, msgfile, msgfile,
1421 MsgInfo *full_msginfo;
1423 compose->updating = TRUE;
1424 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1426 full_msginfo = procmsg_msginfo_copy(msginfo);
1427 compose->updating = FALSE;
1429 if (compose->deferred_destroy) {
1430 compose_destroy(compose);
1434 if (prefs_common.fw_quotemark &&
1435 *prefs_common.fw_quotemark)
1436 qmark = prefs_common.fw_quotemark;
1440 compose_quote_fmt(compose, full_msginfo,
1441 prefs_common.fw_quotefmt,
1442 qmark, body, FALSE);
1443 compose_attach_parts(compose, msginfo);
1445 procmsg_msginfo_free(full_msginfo);
1448 SIGNAL_BLOCK(textbuf);
1450 if (account->auto_sig)
1451 compose_insert_sig(compose, FALSE);
1453 compose_wrap_all(compose);
1455 SIGNAL_UNBLOCK(textbuf);
1457 gtk_text_buffer_get_start_iter(textbuf, &iter);
1458 gtk_text_buffer_place_cursor(textbuf, &iter);
1460 gtk_widget_grab_focus(compose->header_last->entry);
1462 if (!no_extedit && prefs_common.auto_exteditor)
1463 compose_exec_ext_editor(compose);
1466 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1467 gchar *folderidentifier;
1469 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1470 folderidentifier = folder_item_get_identifier(msginfo->folder);
1471 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1472 g_free(folderidentifier);
1475 undo_unblock(compose->undostruct);
1477 compose->modified = FALSE;
1478 compose_set_title(compose);
1482 #undef INSERT_FW_HEADER
1484 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1487 GtkTextView *textview;
1488 GtkTextBuffer *textbuf;
1492 gboolean single_mail = TRUE;
1494 g_return_val_if_fail(msginfo_list != NULL, NULL);
1496 if (g_slist_length(msginfo_list) > 1)
1497 single_mail = FALSE;
1499 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1500 if (((MsgInfo *)msginfo->data)->folder == NULL)
1503 /* guess account from first selected message */
1505 !(account = compose_guess_forward_account_from_msginfo
1506 (msginfo_list->data)))
1507 account = cur_account;
1509 g_return_val_if_fail(account != NULL, NULL);
1511 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1512 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1513 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1516 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1518 textview = GTK_TEXT_VIEW(compose->text);
1519 textbuf = gtk_text_view_get_buffer(textview);
1520 compose_create_tags(textview, compose);
1522 undo_block(compose->undostruct);
1523 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1524 compose->updating = TRUE;
1525 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1526 compose->updating = FALSE;
1527 if (compose->deferred_destroy) {
1528 compose_destroy(compose);
1532 if (!is_file_exist(msgfile))
1533 g_warning("%s: file not exist\n", msgfile);
1535 compose_attach_append(compose, msgfile, msgfile,
1541 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1542 if (info->subject && *info->subject) {
1543 gchar *buf, *buf2, *p;
1545 buf = p = g_strdup(info->subject);
1546 p += subject_get_prefix_length(p);
1547 memmove(buf, p, strlen(p) + 1);
1549 buf2 = g_strdup_printf("Fw: %s", buf);
1550 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1556 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1557 _("Fw: multiple emails"));
1560 SIGNAL_BLOCK(textbuf);
1562 if (account->auto_sig)
1563 compose_insert_sig(compose, FALSE);
1565 compose_wrap_all(compose);
1567 SIGNAL_UNBLOCK(textbuf);
1569 gtk_text_buffer_get_start_iter(textbuf, &iter);
1570 gtk_text_buffer_place_cursor(textbuf, &iter);
1572 gtk_widget_grab_focus(compose->header_last->entry);
1573 undo_unblock(compose->undostruct);
1574 compose->modified = FALSE;
1575 compose_set_title(compose);
1579 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1581 GtkTextIter start = *iter;
1582 GtkTextIter end_iter;
1583 int start_pos = gtk_text_iter_get_offset(&start);
1585 if (!compose->account->sig_sep)
1588 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1589 start_pos+strlen(compose->account->sig_sep));
1591 /* check sig separator */
1592 str = gtk_text_iter_get_text(&start, &end_iter);
1593 if (!strcmp(str, compose->account->sig_sep)) {
1595 /* check end of line (\n) */
1596 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1597 start_pos+strlen(compose->account->sig_sep));
1598 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1599 start_pos+strlen(compose->account->sig_sep)+1);
1600 tmp = gtk_text_iter_get_text(&start, &end_iter);
1601 if (!strcmp(tmp,"\n")) {
1613 static void compose_colorize_signature(Compose *compose)
1615 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1617 GtkTextIter end_iter;
1618 gtk_text_buffer_get_start_iter(buffer, &iter);
1619 while (gtk_text_iter_forward_line(&iter))
1620 if (compose_is_sig_separator(compose, buffer, &iter)) {
1621 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1622 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1626 void compose_reedit(MsgInfo *msginfo)
1628 Compose *compose = NULL;
1629 PrefsAccount *account = NULL;
1630 GtkTextView *textview;
1631 GtkTextBuffer *textbuf;
1635 gchar buf[BUFFSIZE];
1636 gboolean use_signing = FALSE;
1637 gboolean use_encryption = FALSE;
1638 gchar *privacy_system = NULL;
1640 g_return_if_fail(msginfo != NULL);
1641 g_return_if_fail(msginfo->folder != NULL);
1643 if (compose_put_existing_to_front(msginfo)) {
1647 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1648 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1649 gchar queueheader_buf[BUFFSIZE];
1652 /* Select Account from queue headers */
1653 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1654 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1655 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1656 account = account_find_from_id(id);
1658 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1659 sizeof(queueheader_buf), "NAID:")) {
1660 id = atoi(&queueheader_buf[strlen("NAID:")]);
1661 account = account_find_from_id(id);
1663 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1664 sizeof(queueheader_buf), "MAID:")) {
1665 id = atoi(&queueheader_buf[strlen("MAID:")]);
1666 account = account_find_from_id(id);
1668 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1669 sizeof(queueheader_buf), "S:")) {
1670 account = account_find_from_address(queueheader_buf);
1672 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1673 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1674 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1675 use_signing = param;
1678 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1679 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1680 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1681 use_encryption = param;
1683 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1684 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1685 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1687 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1688 sizeof(queueheader_buf), "X-Priority: ")) {
1689 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1690 compose->priority = param;
1693 account = msginfo->folder->folder->account;
1696 if (!account && prefs_common.reedit_account_autosel) {
1697 gchar from[BUFFSIZE];
1698 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1699 extract_address(from);
1700 account = account_find_from_address(from);
1704 account = cur_account;
1706 g_return_if_fail(account != NULL);
1708 compose = compose_create(account, COMPOSE_REEDIT, FALSE);
1709 if (privacy_system != NULL) {
1710 compose->privacy_system = privacy_system;
1711 compose_use_signing(compose, use_signing);
1712 compose_use_encryption(compose, use_encryption);
1713 compose_update_privacy_system_menu_item(compose, FALSE);
1715 activate_privacy_system(compose, account, FALSE);
1718 compose->updating = TRUE;
1719 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1720 compose->updating = FALSE;
1722 if (compose->deferred_destroy) {
1723 compose_destroy(compose);
1727 compose_extract_original_charset(compose);
1729 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1730 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1731 gchar queueheader_buf[BUFFSIZE];
1733 /* Set message save folder */
1734 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1737 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1738 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1739 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1741 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1742 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1744 GtkItemFactory *ifactory;
1745 ifactory = gtk_item_factory_from_widget(compose->menubar);
1746 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1751 if (compose_parse_header(compose, msginfo) < 0) {
1754 compose_reedit_set_entry(compose, msginfo);
1756 textview = GTK_TEXT_VIEW(compose->text);
1757 textbuf = gtk_text_view_get_buffer(textview);
1758 compose_create_tags(textview, compose);
1760 mark = gtk_text_buffer_get_insert(textbuf);
1761 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1763 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1764 G_CALLBACK(compose_changed_cb),
1767 if (procmime_msginfo_is_encrypted(msginfo)) {
1768 fp = procmime_get_first_encrypted_text_content(msginfo);
1770 compose_force_encryption(compose, account, TRUE);
1773 fp = procmime_get_first_text_content(msginfo);
1776 g_warning("Can't get text part\n");
1780 gboolean prev_autowrap = compose->autowrap;
1782 compose->autowrap = FALSE;
1783 while (fgets(buf, sizeof(buf), fp) != NULL) {
1785 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1787 compose_wrap_all_full(compose, FALSE);
1788 compose->autowrap = prev_autowrap;
1792 compose_attach_parts(compose, msginfo);
1794 compose_colorize_signature(compose);
1796 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1797 G_CALLBACK(compose_changed_cb),
1800 gtk_widget_grab_focus(compose->text);
1802 if (prefs_common.auto_exteditor) {
1803 compose_exec_ext_editor(compose);
1805 compose->modified = FALSE;
1806 compose_set_title(compose);
1809 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1814 GtkItemFactory *ifactory;
1817 g_return_val_if_fail(msginfo != NULL, NULL);
1820 account = account_get_reply_account(msginfo,
1821 prefs_common.reply_account_autosel);
1822 g_return_val_if_fail(account != NULL, NULL);
1824 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1825 ifactory = gtk_item_factory_from_widget(compose->menubar);
1826 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1827 compose->replyinfo = NULL;
1828 compose->fwdinfo = NULL;
1830 compose_show_first_last_header(compose, TRUE);
1832 gtk_widget_grab_focus(compose->header_last->entry);
1834 compose->updating = TRUE;
1835 filename = procmsg_get_message_file_path(msginfo);
1836 compose->updating = FALSE;
1838 if (compose->deferred_destroy) {
1839 compose_destroy(compose);
1844 if (filename == NULL)
1847 compose->redirect_filename = filename;
1849 /* Set save folder */
1850 item = msginfo->folder;
1851 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1852 gchar *folderidentifier;
1854 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1855 folderidentifier = folder_item_get_identifier(item);
1856 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1857 g_free(folderidentifier);
1860 compose_attach_parts(compose, msginfo);
1862 if (msginfo->subject)
1863 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1865 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1867 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1868 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1870 compose_colorize_signature(compose);
1872 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1873 menu_set_sensitive(ifactory, "/Add...", FALSE);
1874 menu_set_sensitive(ifactory, "/Remove", FALSE);
1875 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1877 ifactory = gtk_item_factory_from_widget(compose->menubar);
1878 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1879 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1880 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1881 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1882 menu_set_sensitive(ifactory, "/Edit", FALSE);
1883 menu_set_sensitive(ifactory, "/Options", FALSE);
1884 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1885 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1887 if (compose->toolbar->draft_btn)
1888 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1889 if (compose->toolbar->insert_btn)
1890 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1891 if (compose->toolbar->attach_btn)
1892 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1893 if (compose->toolbar->sig_btn)
1894 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1895 if (compose->toolbar->exteditor_btn)
1896 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1897 if (compose->toolbar->linewrap_current_btn)
1898 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1899 if (compose->toolbar->linewrap_all_btn)
1900 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1902 compose->modified = FALSE;
1903 compose_set_title(compose);
1907 GList *compose_get_compose_list(void)
1909 return compose_list;
1912 void compose_entry_append(Compose *compose, const gchar *address,
1913 ComposeEntryType type)
1917 gboolean in_quote = FALSE;
1918 if (!address || *address == '\0') return;
1925 header = N_("Bcc:");
1927 case COMPOSE_REPLYTO:
1928 header = N_("Reply-To:");
1930 case COMPOSE_NEWSGROUPS:
1931 header = N_("Newsgroups:");
1933 case COMPOSE_FOLLOWUPTO:
1934 header = N_( "Followup-To:");
1941 header = prefs_common.trans_hdr ? gettext(header) : header;
1943 cur = begin = (gchar *)address;
1945 /* we separate the line by commas, but not if we're inside a quoted
1947 while (*cur != '\0') {
1949 in_quote = !in_quote;
1950 if (*cur == ',' && !in_quote) {
1951 gchar *tmp = g_strdup(begin);
1953 tmp[cur-begin]='\0';
1958 compose_add_header_entry(compose, header, tmp);
1965 gchar *tmp = g_strdup(begin);
1967 tmp[cur-begin]='\0';
1972 compose_add_header_entry(compose, header, tmp);
1977 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1979 static GdkColor yellow;
1980 static GdkColor black;
1981 static gboolean yellow_initialised = FALSE;
1985 if (!yellow_initialised) {
1986 gdk_color_parse("#f5f6be", &yellow);
1987 gdk_color_parse("#000000", &black);
1988 yellow_initialised = gdk_colormap_alloc_color(
1989 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
1990 yellow_initialised &= gdk_colormap_alloc_color(
1991 gdk_colormap_get_system(), &black, FALSE, TRUE);
1994 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1995 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1996 if (gtk_entry_get_text(entry) &&
1997 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1998 if (yellow_initialised) {
1999 gtk_widget_modify_base(
2000 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2001 GTK_STATE_NORMAL, &yellow);
2002 gtk_widget_modify_text(
2003 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2004 GTK_STATE_NORMAL, &black);
2010 void compose_toolbar_cb(gint action, gpointer data)
2012 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2013 Compose *compose = (Compose*)toolbar_item->parent;
2015 g_return_if_fail(compose != NULL);
2019 compose_send_cb(compose, 0, NULL);
2022 compose_send_later_cb(compose, 0, NULL);
2025 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2028 compose_insert_file_cb(compose, 0, NULL);
2031 compose_attach_cb(compose, 0, NULL);
2034 compose_insert_sig(compose, FALSE);
2037 compose_ext_editor_cb(compose, 0, NULL);
2039 case A_LINEWRAP_CURRENT:
2040 compose_beautify_paragraph(compose, NULL, TRUE);
2042 case A_LINEWRAP_ALL:
2043 compose_wrap_all_full(compose, TRUE);
2046 compose_address_cb(compose, 0, NULL);
2049 case A_CHECK_SPELLING:
2050 compose_check_all(compose);
2058 static void compose_entries_set(Compose *compose, const gchar *mailto)
2062 gchar *subject = NULL;
2067 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2070 compose_entry_append(compose, to, COMPOSE_TO);
2072 compose_entry_append(compose, cc, COMPOSE_CC);
2074 if (!g_utf8_validate (subject, -1, NULL)) {
2075 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2076 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2079 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2083 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2084 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2087 gboolean prev_autowrap = compose->autowrap;
2089 compose->autowrap = FALSE;
2091 mark = gtk_text_buffer_get_insert(buffer);
2092 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2094 if (!g_utf8_validate (body, -1, NULL)) {
2095 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2096 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2099 gtk_text_buffer_insert(buffer, &iter, body, -1);
2101 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2103 compose->autowrap = prev_autowrap;
2104 if (compose->autowrap)
2105 compose_wrap_all(compose);
2114 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2116 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2117 {"Cc:", NULL, TRUE},
2118 {"References:", NULL, FALSE},
2119 {"Bcc:", NULL, TRUE},
2120 {"Newsgroups:", NULL, TRUE},
2121 {"Followup-To:", NULL, TRUE},
2122 {"List-Post:", NULL, FALSE},
2123 {"X-Priority:", NULL, FALSE},
2124 {NULL, NULL, FALSE}};
2140 g_return_val_if_fail(msginfo != NULL, -1);
2142 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2143 procheader_get_header_fields(fp, hentry);
2146 if (hentry[H_REPLY_TO].body != NULL) {
2147 if (hentry[H_REPLY_TO].body[0] != '\0') {
2149 conv_unmime_header(hentry[H_REPLY_TO].body,
2152 g_free(hentry[H_REPLY_TO].body);
2153 hentry[H_REPLY_TO].body = NULL;
2155 if (hentry[H_CC].body != NULL) {
2156 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2157 g_free(hentry[H_CC].body);
2158 hentry[H_CC].body = NULL;
2160 if (hentry[H_REFERENCES].body != NULL) {
2161 if (compose->mode == COMPOSE_REEDIT)
2162 compose->references = hentry[H_REFERENCES].body;
2164 compose->references = compose_parse_references
2165 (hentry[H_REFERENCES].body, msginfo->msgid);
2166 g_free(hentry[H_REFERENCES].body);
2168 hentry[H_REFERENCES].body = NULL;
2170 if (hentry[H_BCC].body != NULL) {
2171 if (compose->mode == COMPOSE_REEDIT)
2173 conv_unmime_header(hentry[H_BCC].body, NULL);
2174 g_free(hentry[H_BCC].body);
2175 hentry[H_BCC].body = NULL;
2177 if (hentry[H_NEWSGROUPS].body != NULL) {
2178 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2179 hentry[H_NEWSGROUPS].body = NULL;
2181 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2182 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2183 compose->followup_to =
2184 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2187 g_free(hentry[H_FOLLOWUP_TO].body);
2188 hentry[H_FOLLOWUP_TO].body = NULL;
2190 if (hentry[H_LIST_POST].body != NULL) {
2193 extract_address(hentry[H_LIST_POST].body);
2194 if (hentry[H_LIST_POST].body[0] != '\0') {
2195 scan_mailto_url(hentry[H_LIST_POST].body,
2196 &to, NULL, NULL, NULL, NULL);
2198 g_free(compose->ml_post);
2199 compose->ml_post = to;
2202 g_free(hentry[H_LIST_POST].body);
2203 hentry[H_LIST_POST].body = NULL;
2206 /* CLAWS - X-Priority */
2207 if (compose->mode == COMPOSE_REEDIT)
2208 if (hentry[H_X_PRIORITY].body != NULL) {
2211 priority = atoi(hentry[H_X_PRIORITY].body);
2212 g_free(hentry[H_X_PRIORITY].body);
2214 hentry[H_X_PRIORITY].body = NULL;
2216 if (priority < PRIORITY_HIGHEST ||
2217 priority > PRIORITY_LOWEST)
2218 priority = PRIORITY_NORMAL;
2220 compose->priority = priority;
2223 if (compose->mode == COMPOSE_REEDIT) {
2224 if (msginfo->inreplyto && *msginfo->inreplyto)
2225 compose->inreplyto = g_strdup(msginfo->inreplyto);
2229 if (msginfo->msgid && *msginfo->msgid)
2230 compose->inreplyto = g_strdup(msginfo->msgid);
2232 if (!compose->references) {
2233 if (msginfo->msgid && *msginfo->msgid) {
2234 if (msginfo->inreplyto && *msginfo->inreplyto)
2235 compose->references =
2236 g_strdup_printf("<%s>\n\t<%s>",
2240 compose->references =
2241 g_strconcat("<", msginfo->msgid, ">",
2243 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2244 compose->references =
2245 g_strconcat("<", msginfo->inreplyto, ">",
2253 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2255 GSList *ref_id_list, *cur;
2259 ref_id_list = references_list_append(NULL, ref);
2260 if (!ref_id_list) return NULL;
2261 if (msgid && *msgid)
2262 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2267 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2268 /* "<" + Message-ID + ">" + CR+LF+TAB */
2269 len += strlen((gchar *)cur->data) + 5;
2271 if (len > MAX_REFERENCES_LEN) {
2272 /* remove second message-ID */
2273 if (ref_id_list && ref_id_list->next &&
2274 ref_id_list->next->next) {
2275 g_free(ref_id_list->next->data);
2276 ref_id_list = g_slist_remove
2277 (ref_id_list, ref_id_list->next->data);
2279 slist_free_strings(ref_id_list);
2280 g_slist_free(ref_id_list);
2287 new_ref = g_string_new("");
2288 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2289 if (new_ref->len > 0)
2290 g_string_append(new_ref, "\n\t");
2291 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2294 slist_free_strings(ref_id_list);
2295 g_slist_free(ref_id_list);
2297 new_ref_str = new_ref->str;
2298 g_string_free(new_ref, FALSE);
2303 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2304 const gchar *fmt, const gchar *qmark,
2305 const gchar *body, gboolean rewrap)
2307 static MsgInfo dummyinfo;
2308 gchar *quote_str = NULL;
2310 gboolean prev_autowrap;
2311 const gchar *trimmed_body = body;
2312 gint cursor_pos = -1;
2313 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2314 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2319 SIGNAL_BLOCK(buffer);
2322 msginfo = &dummyinfo;
2324 if (qmark != NULL) {
2325 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2326 quote_fmt_scan_string(qmark);
2329 buf = quote_fmt_get_buffer();
2331 alertpanel_error(_("Quote mark format error."));
2333 Xstrdup_a(quote_str, buf, goto error)
2336 if (fmt && *fmt != '\0') {
2337 while (trimmed_body && strlen(trimmed_body) > 1
2338 && trimmed_body[0]=='\n')
2341 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2342 quote_fmt_scan_string(fmt);
2345 buf = quote_fmt_get_buffer();
2347 alertpanel_error(_("Message reply/forward format error."));
2353 prev_autowrap = compose->autowrap;
2354 compose->autowrap = FALSE;
2356 mark = gtk_text_buffer_get_insert(buffer);
2357 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2358 if (g_utf8_validate(buf, -1, NULL)) {
2359 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2361 gchar *tmpout = NULL;
2362 tmpout = conv_codeset_strdup
2363 (buf, conv_get_locale_charset_str_no_utf8(),
2365 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2367 tmpout = g_malloc(strlen(buf)*2+1);
2368 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2370 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2374 cursor_pos = quote_fmt_get_cursor_pos();
2375 compose->set_cursor_pos = cursor_pos;
2376 if (cursor_pos == -1) {
2379 gtk_text_buffer_get_start_iter(buffer, &iter);
2380 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2381 gtk_text_buffer_place_cursor(buffer, &iter);
2383 compose->autowrap = prev_autowrap;
2384 if (compose->autowrap && rewrap)
2385 compose_wrap_all(compose);
2392 SIGNAL_UNBLOCK(buffer);
2398 /* if ml_post is of type addr@host and from is of type
2399 * addr-anything@host, return TRUE
2401 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2403 gchar *left_ml = NULL;
2404 gchar *right_ml = NULL;
2405 gchar *left_from = NULL;
2406 gchar *right_from = NULL;
2407 gboolean result = FALSE;
2409 if (!ml_post || !from)
2412 left_ml = g_strdup(ml_post);
2413 if (strstr(left_ml, "@")) {
2414 right_ml = strstr(left_ml, "@")+1;
2415 *(strstr(left_ml, "@")) = '\0';
2418 left_from = g_strdup(from);
2419 if (strstr(left_from, "@")) {
2420 right_from = strstr(left_from, "@")+1;
2421 *(strstr(left_from, "@")) = '\0';
2424 if (left_ml && left_from && right_ml && right_from
2425 && !strncmp(left_from, left_ml, strlen(left_ml))
2426 && !strcmp(right_from, right_ml)) {
2435 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2437 gchar *my_addr1, *my_addr2;
2439 if (!addr1 || !addr2)
2442 Xstrdup_a(my_addr1, addr1, return FALSE);
2443 Xstrdup_a(my_addr2, addr2, return FALSE);
2445 extract_address(my_addr1);
2446 extract_address(my_addr2);
2448 return !strcmp(my_addr1, my_addr2);
2451 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2452 gboolean to_all, gboolean to_ml,
2454 gboolean followup_and_reply_to)
2456 GSList *cc_list = NULL;
2459 gchar *replyto = NULL;
2460 GHashTable *to_table;
2462 gboolean reply_to_ml = FALSE;
2463 gboolean default_reply_to = FALSE;
2465 g_return_if_fail(compose->account != NULL);
2466 g_return_if_fail(msginfo != NULL);
2468 reply_to_ml = to_ml && compose->ml_post;
2470 default_reply_to = msginfo->folder &&
2471 msginfo->folder->prefs->enable_default_reply_to;
2473 if (compose->account->protocol != A_NNTP) {
2474 if (reply_to_ml && !default_reply_to) {
2476 gboolean is_subscr = is_subscription(compose->ml_post,
2479 /* normal answer to ml post with a reply-to */
2480 compose_entry_append(compose,
2483 if (compose->replyto
2484 && !same_address(compose->ml_post, compose->replyto))
2485 compose_entry_append(compose,
2489 /* answer to subscription confirmation */
2490 if (compose->replyto)
2491 compose_entry_append(compose,
2494 else if (msginfo->from)
2495 compose_entry_append(compose,
2500 else if (!(to_all || to_sender) && default_reply_to) {
2501 compose_entry_append(compose,
2502 msginfo->folder->prefs->default_reply_to,
2504 compose_entry_mark_default_to(compose,
2505 msginfo->folder->prefs->default_reply_to);
2510 Xstrdup_a(tmp1, msginfo->from, return);
2511 extract_address(tmp1);
2512 if (to_all || to_sender ||
2513 !account_find_from_address(tmp1))
2514 compose_entry_append(compose,
2515 (compose->replyto && !to_sender)
2516 ? compose->replyto :
2517 msginfo->from ? msginfo->from : "",
2519 else if (!to_all && !to_sender) {
2520 /* reply to the last list of recipients */
2521 compose_entry_append(compose,
2522 msginfo->to ? msginfo->to : "",
2524 compose_entry_append(compose,
2525 msginfo->cc ? msginfo->cc : "",
2530 if (to_sender || (compose->followup_to &&
2531 !strncmp(compose->followup_to, "poster", 6)))
2532 compose_entry_append
2534 (compose->replyto ? compose->replyto :
2535 msginfo->from ? msginfo->from : ""),
2538 else if (followup_and_reply_to || to_all) {
2539 compose_entry_append
2541 (compose->replyto ? compose->replyto :
2542 msginfo->from ? msginfo->from : ""),
2545 compose_entry_append
2547 compose->followup_to ? compose->followup_to :
2548 compose->newsgroups ? compose->newsgroups : "",
2549 COMPOSE_NEWSGROUPS);
2552 compose_entry_append
2554 compose->followup_to ? compose->followup_to :
2555 compose->newsgroups ? compose->newsgroups : "",
2556 COMPOSE_NEWSGROUPS);
2559 if (msginfo->subject && *msginfo->subject) {
2563 buf = p = g_strdup(msginfo->subject);
2564 p += subject_get_prefix_length(p);
2565 memmove(buf, p, strlen(p) + 1);
2567 buf2 = g_strdup_printf("Re: %s", buf);
2568 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2573 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2575 if (to_ml && compose->ml_post) return;
2576 if (!to_all || compose->account->protocol == A_NNTP) return;
2578 if (compose->replyto) {
2579 Xstrdup_a(replyto, compose->replyto, return);
2580 extract_address(replyto);
2582 if (msginfo->from) {
2583 Xstrdup_a(from, msginfo->from, return);
2584 extract_address(from);
2587 if (replyto && from)
2588 cc_list = address_list_append_with_comments(cc_list, from);
2589 if (to_all && msginfo->folder &&
2590 msginfo->folder->prefs->enable_default_reply_to)
2591 cc_list = address_list_append_with_comments(cc_list,
2592 msginfo->folder->prefs->default_reply_to);
2593 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2594 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2596 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2598 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2599 if (compose->account)
2600 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2601 GINT_TO_POINTER(1));
2603 /* remove address on To: and that of current account */
2604 for (cur = cc_list; cur != NULL; ) {
2605 GSList *next = cur->next;
2608 addr = g_strdup(cur->data);
2609 extract_address(addr);
2611 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2612 cc_list = g_slist_remove(cc_list, cur->data);
2614 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2618 hash_free_strings(to_table);
2619 g_hash_table_destroy(to_table);
2622 for (cur = cc_list; cur != NULL; cur = cur->next)
2623 compose_entry_append(compose, (gchar *)cur->data,
2625 slist_free_strings(cc_list);
2626 g_slist_free(cc_list);
2631 #define SET_ENTRY(entry, str) \
2634 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2637 #define SET_ADDRESS(type, str) \
2640 compose_entry_append(compose, str, type); \
2643 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2645 g_return_if_fail(msginfo != NULL);
2647 SET_ENTRY(subject_entry, msginfo->subject);
2648 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2649 SET_ADDRESS(COMPOSE_CC, compose->cc);
2650 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2651 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2652 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2653 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2655 compose_update_priority_menu_item(compose);
2656 compose_update_privacy_system_menu_item(compose, FALSE);
2657 compose_show_first_last_header(compose, TRUE);
2663 static void compose_insert_sig(Compose *compose, gboolean replace)
2665 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2666 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2668 GtkTextIter iter, iter_end;
2670 gboolean prev_autowrap;
2673 g_return_if_fail(compose->account != NULL);
2675 prev_autowrap = compose->autowrap;
2676 compose->autowrap = FALSE;
2678 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2679 G_CALLBACK(compose_changed_cb),
2682 mark = gtk_text_buffer_get_insert(buffer);
2683 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2684 cur_pos = gtk_text_iter_get_offset (&iter);
2686 gtk_text_buffer_get_end_iter(buffer, &iter);
2688 if (replace && compose->sig_str) {
2690 GtkTextIter first_iter, start_iter, end_iter;
2692 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2694 if (compose->sig_str[0] == '\0')
2697 found = gtk_text_iter_forward_search(&first_iter,
2699 GTK_TEXT_SEARCH_TEXT_ONLY,
2700 &start_iter, &end_iter,
2704 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2709 g_free(compose->sig_str);
2710 compose->sig_str = compose_get_signature_str(compose);
2711 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2712 compose->sig_str = g_strdup("");
2714 cur_pos = gtk_text_iter_get_offset(&iter);
2715 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2717 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2718 gtk_text_iter_forward_char(&iter);
2719 gtk_text_iter_forward_char(&iter);
2720 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2721 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2723 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2724 cur_pos = gtk_text_buffer_get_char_count (buffer);
2726 /* put the cursor where it should be
2727 * either where the quote_fmt says, either before the signature */
2728 if (compose->set_cursor_pos < 0)
2729 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2731 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2732 compose->set_cursor_pos);
2734 gtk_text_buffer_place_cursor(buffer, &iter);
2735 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2736 G_CALLBACK(compose_changed_cb),
2739 compose->autowrap = prev_autowrap;
2740 if (compose->autowrap)
2741 compose_wrap_all(compose);
2744 static gchar *compose_get_signature_str(Compose *compose)
2746 gchar *sig_body = NULL;
2747 gchar *sig_str = NULL;
2748 gchar *utf8_sig_str = NULL;
2750 g_return_val_if_fail(compose->account != NULL, NULL);
2752 if (!compose->account->sig_path)
2755 if (compose->account->sig_type == SIG_FILE) {
2756 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2757 g_warning("can't open signature file: %s\n",
2758 compose->account->sig_path);
2763 if (compose->account->sig_type == SIG_COMMAND)
2764 sig_body = get_command_output(compose->account->sig_path);
2768 tmp = file_read_to_str(compose->account->sig_path);
2771 sig_body = normalize_newlines(tmp);
2775 if (compose->account->sig_sep) {
2776 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2780 sig_str = g_strconcat("\n\n", sig_body, NULL);
2783 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2784 utf8_sig_str = sig_str;
2786 utf8_sig_str = conv_codeset_strdup
2787 (sig_str, conv_get_locale_charset_str_no_utf8(),
2793 return utf8_sig_str;
2796 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2799 GtkTextBuffer *buffer;
2802 const gchar *cur_encoding;
2803 gchar buf[BUFFSIZE];
2806 gboolean prev_autowrap;
2807 gboolean badtxt = FALSE;
2809 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2811 if ((fp = g_fopen(file, "rb")) == NULL) {
2812 FILE_OP_ERROR(file, "fopen");
2813 return COMPOSE_INSERT_READ_ERROR;
2816 prev_autowrap = compose->autowrap;
2817 compose->autowrap = FALSE;
2819 text = GTK_TEXT_VIEW(compose->text);
2820 buffer = gtk_text_view_get_buffer(text);
2821 mark = gtk_text_buffer_get_insert(buffer);
2822 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2824 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2825 G_CALLBACK(text_inserted),
2828 cur_encoding = conv_get_locale_charset_str_no_utf8();
2830 while (fgets(buf, sizeof(buf), fp) != NULL) {
2833 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2834 str = g_strdup(buf);
2836 str = conv_codeset_strdup
2837 (buf, cur_encoding, CS_INTERNAL);
2840 /* strip <CR> if DOS/Windows file,
2841 replace <CR> with <LF> if Macintosh file. */
2844 if (len > 0 && str[len - 1] != '\n') {
2846 if (str[len] == '\r') str[len] = '\n';
2849 gtk_text_buffer_insert(buffer, &iter, str, -1);
2853 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2854 G_CALLBACK(text_inserted),
2856 compose->autowrap = prev_autowrap;
2857 if (compose->autowrap)
2858 compose_wrap_all(compose);
2863 return COMPOSE_INSERT_INVALID_CHARACTER;
2865 return COMPOSE_INSERT_SUCCESS;
2868 static void compose_attach_append(Compose *compose, const gchar *file,
2869 const gchar *filename,
2870 const gchar *content_type)
2878 GtkListStore *store;
2880 gboolean has_binary = FALSE;
2882 if (!is_file_exist(file)) {
2883 g_warning("File %s doesn't exist\n", filename);
2886 if ((size = get_file_size(file)) < 0) {
2887 g_warning("Can't get file size of %s\n", filename);
2891 alertpanel_notice(_("File %s is empty."), filename);
2894 if ((fp = g_fopen(file, "rb")) == NULL) {
2895 alertpanel_error(_("Can't read %s."), filename);
2900 ainfo = g_new0(AttachInfo, 1);
2901 auto_ainfo = g_auto_pointer_new_with_free
2902 (ainfo, (GFreeFunc) compose_attach_info_free);
2903 ainfo->file = g_strdup(file);
2906 ainfo->content_type = g_strdup(content_type);
2907 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2909 MsgFlags flags = {0, 0};
2911 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2912 ainfo->encoding = ENC_7BIT;
2914 ainfo->encoding = ENC_8BIT;
2916 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2917 if (msginfo && msginfo->subject)
2918 name = g_strdup(msginfo->subject);
2920 name = g_path_get_basename(filename ? filename : file);
2922 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2924 procmsg_msginfo_free(msginfo);
2926 if (!g_ascii_strncasecmp(content_type, "text", 4))
2927 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2929 ainfo->encoding = ENC_BASE64;
2930 name = g_path_get_basename(filename ? filename : file);
2931 ainfo->name = g_strdup(name);
2935 ainfo->content_type = procmime_get_mime_type(file);
2936 if (!ainfo->content_type) {
2937 ainfo->content_type =
2938 g_strdup("application/octet-stream");
2939 ainfo->encoding = ENC_BASE64;
2940 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2942 procmime_get_encoding_for_text_file(file, &has_binary);
2944 ainfo->encoding = ENC_BASE64;
2945 name = g_path_get_basename(filename ? filename : file);
2946 ainfo->name = g_strdup(name);
2950 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2951 g_free(ainfo->content_type);
2952 ainfo->content_type = g_strdup("application/octet-stream");
2956 size_text = to_human_readable(size);
2958 store = GTK_LIST_STORE(gtk_tree_view_get_model
2959 (GTK_TREE_VIEW(compose->attach_clist)));
2961 gtk_list_store_append(store, &iter);
2962 gtk_list_store_set(store, &iter,
2963 COL_MIMETYPE, ainfo->content_type,
2964 COL_SIZE, size_text,
2965 COL_NAME, ainfo->name,
2967 COL_AUTODATA, auto_ainfo,
2970 g_auto_pointer_free(auto_ainfo);
2973 static void compose_use_signing(Compose *compose, gboolean use_signing)
2975 GtkItemFactory *ifactory;
2976 GtkWidget *menuitem = NULL;
2978 compose->use_signing = use_signing;
2979 ifactory = gtk_item_factory_from_widget(compose->menubar);
2980 menuitem = gtk_item_factory_get_item
2981 (ifactory, "/Options/Sign");
2982 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2986 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2988 GtkItemFactory *ifactory;
2989 GtkWidget *menuitem = NULL;
2991 compose->use_encryption = use_encryption;
2992 ifactory = gtk_item_factory_from_widget(compose->menubar);
2993 menuitem = gtk_item_factory_get_item
2994 (ifactory, "/Options/Encrypt");
2996 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3000 #define NEXT_PART_NOT_CHILD(info) \
3002 node = info->node; \
3003 while (node->children) \
3004 node = g_node_last_child(node); \
3005 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3008 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3012 MimeInfo *firsttext = NULL;
3013 MimeInfo *encrypted = NULL;
3016 const gchar *partname = NULL;
3018 mimeinfo = procmime_scan_message(msginfo);
3019 if (!mimeinfo) return;
3021 if (mimeinfo->node->children == NULL) {
3022 procmime_mimeinfo_free_all(mimeinfo);
3026 /* find first content part */
3027 child = (MimeInfo *) mimeinfo->node->children->data;
3028 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3029 child = (MimeInfo *)child->node->children->data;
3031 if (child->type == MIMETYPE_TEXT) {
3033 debug_print("First text part found\n");
3034 } else if (compose->mode == COMPOSE_REEDIT &&
3035 child->type == MIMETYPE_APPLICATION &&
3036 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3037 encrypted = (MimeInfo *)child->node->parent->data;
3040 child = (MimeInfo *) mimeinfo->node->children->data;
3041 while (child != NULL) {
3042 if (child == encrypted) {
3043 /* skip this part of tree */
3044 NEXT_PART_NOT_CHILD(child);
3048 if (child->type == MIMETYPE_MULTIPART) {
3049 /* get the actual content */
3050 child = procmime_mimeinfo_next(child);
3054 if (child == firsttext) {
3055 child = procmime_mimeinfo_next(child);
3059 outfile = procmime_get_tmp_file_name(child);
3060 if (procmime_get_part(outfile, child) < 0)
3061 g_warning("Can't get the part of multipart message.");
3063 gchar *content_type;
3065 content_type = procmime_get_content_type_str(child->type, child->subtype);
3067 /* if we meet a pgp signature, we don't attach it, but
3068 * we force signing. */
3069 if (strcmp(content_type, "application/pgp-signature")) {
3070 partname = procmime_mimeinfo_get_parameter(child, "filename");
3071 if (partname == NULL)
3072 partname = procmime_mimeinfo_get_parameter(child, "name");
3073 if (partname == NULL)
3075 compose_attach_append(compose, outfile,
3076 partname, content_type);
3078 compose_force_signing(compose, compose->account);
3080 g_free(content_type);
3083 NEXT_PART_NOT_CHILD(child);
3085 procmime_mimeinfo_free_all(mimeinfo);
3088 #undef NEXT_PART_NOT_CHILD
3093 WAIT_FOR_INDENT_CHAR,
3094 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3097 /* return indent length, we allow:
3098 indent characters followed by indent characters or spaces/tabs,
3099 alphabets and numbers immediately followed by indent characters,
3100 and the repeating sequences of the above
3101 If quote ends with multiple spaces, only the first one is included. */
3102 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3103 const GtkTextIter *start, gint *len)
3105 GtkTextIter iter = *start;
3109 IndentState state = WAIT_FOR_INDENT_CHAR;
3112 gint alnum_count = 0;
3113 gint space_count = 0;
3116 if (prefs_common.quote_chars == NULL) {
3120 while (!gtk_text_iter_ends_line(&iter)) {
3121 wc = gtk_text_iter_get_char(&iter);
3122 if (g_unichar_iswide(wc))
3124 clen = g_unichar_to_utf8(wc, ch);
3128 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3129 is_space = g_unichar_isspace(wc);
3131 if (state == WAIT_FOR_INDENT_CHAR) {
3132 if (!is_indent && !g_unichar_isalnum(wc))
3135 quote_len += alnum_count + space_count + 1;
3136 alnum_count = space_count = 0;
3137 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3140 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3141 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3145 else if (is_indent) {
3146 quote_len += alnum_count + space_count + 1;
3147 alnum_count = space_count = 0;
3150 state = WAIT_FOR_INDENT_CHAR;
3154 gtk_text_iter_forward_char(&iter);
3157 if (quote_len > 0 && space_count > 0)
3163 if (quote_len > 0) {
3165 gtk_text_iter_forward_chars(&iter, quote_len);
3166 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3172 /* return TRUE if the line is itemized */
3173 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3174 const GtkTextIter *start)
3176 GtkTextIter iter = *start;
3181 if (gtk_text_iter_ends_line(&iter))
3185 wc = gtk_text_iter_get_char(&iter);
3186 if (!g_unichar_isspace(wc))
3188 gtk_text_iter_forward_char(&iter);
3189 if (gtk_text_iter_ends_line(&iter))
3193 clen = g_unichar_to_utf8(wc, ch);
3197 if (!strchr("*-+", ch[0]))
3200 gtk_text_iter_forward_char(&iter);
3201 if (gtk_text_iter_ends_line(&iter))
3203 wc = gtk_text_iter_get_char(&iter);
3204 if (g_unichar_isspace(wc))
3210 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3211 const GtkTextIter *start,
3212 GtkTextIter *break_pos,
3216 GtkTextIter iter = *start, line_end = *start;
3217 PangoLogAttr *attrs;
3224 gboolean can_break = FALSE;
3225 gboolean do_break = FALSE;
3226 gboolean was_white = FALSE;
3227 gboolean prev_dont_break = FALSE;
3229 gtk_text_iter_forward_to_line_end(&line_end);
3230 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3231 len = g_utf8_strlen(str, -1);
3232 /* g_print("breaking line: %d: %s (len = %d)\n",
3233 gtk_text_iter_get_line(&iter), str, len); */
3234 attrs = g_new(PangoLogAttr, len + 1);
3236 pango_default_break(str, -1, NULL, attrs, len + 1);
3240 /* skip quote and leading spaces */
3241 for (i = 0; *p != '\0' && i < len; i++) {
3244 wc = g_utf8_get_char(p);
3245 if (i >= quote_len && !g_unichar_isspace(wc))
3247 if (g_unichar_iswide(wc))
3249 else if (*p == '\t')
3253 p = g_utf8_next_char(p);
3256 for (; *p != '\0' && i < len; i++) {
3257 PangoLogAttr *attr = attrs + i;
3261 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3264 was_white = attr->is_white;
3266 /* don't wrap URI */
3267 if ((uri_len = get_uri_len(p)) > 0) {
3269 if (pos > 0 && col > max_col) {
3279 wc = g_utf8_get_char(p);
3280 if (g_unichar_iswide(wc)) {
3282 if (prev_dont_break && can_break && attr->is_line_break)
3284 } else if (*p == '\t')
3288 if (pos > 0 && col > max_col) {
3293 if (*p == '-' || *p == '/')
3294 prev_dont_break = TRUE;
3296 prev_dont_break = FALSE;
3298 p = g_utf8_next_char(p);
3302 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3307 *break_pos = *start;
3308 gtk_text_iter_set_line_offset(break_pos, pos);
3313 static gboolean compose_join_next_line(Compose *compose,
3314 GtkTextBuffer *buffer,
3316 const gchar *quote_str)
3318 GtkTextIter iter_ = *iter, cur, prev, next, end;
3319 PangoLogAttr attrs[3];
3321 gchar *next_quote_str;
3324 gboolean keep_cursor = FALSE;
3326 if (!gtk_text_iter_forward_line(&iter_) ||
3327 gtk_text_iter_ends_line(&iter_))
3330 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3332 if ((quote_str || next_quote_str) &&
3333 strcmp2(quote_str, next_quote_str) != 0) {
3334 g_free(next_quote_str);
3337 g_free(next_quote_str);
3340 if (quote_len > 0) {
3341 gtk_text_iter_forward_chars(&end, quote_len);
3342 if (gtk_text_iter_ends_line(&end))
3346 /* don't join itemized lines */
3347 if (compose_is_itemized(buffer, &end))
3350 /* don't join signature separator */
3351 if (compose_is_sig_separator(compose, buffer, &iter_))
3354 /* delete quote str */
3356 gtk_text_buffer_delete(buffer, &iter_, &end);
3358 /* don't join line breaks put by the user */
3360 gtk_text_iter_backward_char(&cur);
3361 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3362 gtk_text_iter_forward_char(&cur);
3366 gtk_text_iter_forward_char(&cur);
3367 /* delete linebreak and extra spaces */
3368 while (gtk_text_iter_backward_char(&cur)) {
3369 wc1 = gtk_text_iter_get_char(&cur);
3370 if (!g_unichar_isspace(wc1))
3375 while (!gtk_text_iter_ends_line(&cur)) {
3376 wc1 = gtk_text_iter_get_char(&cur);
3377 if (!g_unichar_isspace(wc1))
3379 gtk_text_iter_forward_char(&cur);
3382 if (!gtk_text_iter_equal(&prev, &next)) {
3385 mark = gtk_text_buffer_get_insert(buffer);
3386 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3387 if (gtk_text_iter_equal(&prev, &cur))
3389 gtk_text_buffer_delete(buffer, &prev, &next);
3393 /* insert space if required */
3394 gtk_text_iter_backward_char(&prev);
3395 wc1 = gtk_text_iter_get_char(&prev);
3396 wc2 = gtk_text_iter_get_char(&next);
3397 gtk_text_iter_forward_char(&next);
3398 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3399 pango_default_break(str, -1, NULL, attrs, 3);
3400 if (!attrs[1].is_line_break ||
3401 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3402 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3404 gtk_text_iter_backward_char(&iter_);
3405 gtk_text_buffer_place_cursor(buffer, &iter_);
3414 #define ADD_TXT_POS(bp_, ep_, pti_) \
3415 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3416 last = last->next; \
3417 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3418 last->next = NULL; \
3420 g_warning("alloc error scanning URIs\n"); \
3423 static gboolean automatic_break = FALSE;
3424 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3426 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3427 GtkTextBuffer *buffer;
3428 GtkTextIter iter, break_pos, end_of_line;
3429 gchar *quote_str = NULL;
3431 gboolean wrap_quote = prefs_common.linewrap_quote;
3432 gboolean prev_autowrap = compose->autowrap;
3433 gint startq_offset = -1, noq_offset = -1;
3434 gint uri_start = -1, uri_stop = -1;
3435 gint nouri_start = -1, nouri_stop = -1;
3436 gint num_blocks = 0;
3437 gint quotelevel = -1;
3439 compose->autowrap = FALSE;
3441 buffer = gtk_text_view_get_buffer(text);
3442 undo_wrapping(compose->undostruct, TRUE);
3447 mark = gtk_text_buffer_get_insert(buffer);
3448 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3451 /* move to paragraph start */
3452 gtk_text_iter_set_line_offset(&iter, 0);
3453 if (gtk_text_iter_ends_line(&iter)) {
3454 while (gtk_text_iter_ends_line(&iter) &&
3455 gtk_text_iter_forward_line(&iter))
3458 while (gtk_text_iter_backward_line(&iter)) {
3459 if (gtk_text_iter_ends_line(&iter)) {
3460 gtk_text_iter_forward_line(&iter);
3466 /* go until paragraph end (empty line) */
3468 while (!gtk_text_iter_ends_line(&iter)) {
3469 gchar *scanpos = NULL;
3470 /* parse table - in order of priority */
3472 const gchar *needle; /* token */
3474 /* token search function */
3475 gchar *(*search) (const gchar *haystack,
3476 const gchar *needle);
3477 /* part parsing function */
3478 gboolean (*parse) (const gchar *start,
3479 const gchar *scanpos,
3483 /* part to URI function */
3484 gchar *(*build_uri) (const gchar *bp,
3488 static struct table parser[] = {
3489 {"http://", strcasestr, get_uri_part, make_uri_string},
3490 {"https://", strcasestr, get_uri_part, make_uri_string},
3491 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3492 {"www.", strcasestr, get_uri_part, make_http_string},
3493 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3494 {"@", strcasestr, get_email_part, make_email_string}
3496 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3497 gint last_index = PARSE_ELEMS;
3499 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3502 if (!prev_autowrap && num_blocks == 0) {
3504 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3505 G_CALLBACK(text_inserted),
3508 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3511 uri_start = uri_stop = -1;
3513 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3517 if (startq_offset == -1) {
3518 startq_offset = gtk_text_iter_get_offset(&iter);
3522 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3523 if (startq_offset == -1)
3524 startq_offset = gtk_text_iter_get_offset(&iter);
3525 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3526 if (quotelevel > 2) {
3527 /* recycle colors */
3528 if (prefs_common.recycle_quote_colors)
3534 if (startq_offset == -1)
3535 noq_offset = gtk_text_iter_get_offset(&iter);
3539 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3542 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3543 prefs_common.linewrap_len,
3545 GtkTextIter prev, next, cur;
3547 if (prev_autowrap != FALSE || force) {
3548 automatic_break = TRUE;
3549 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3550 automatic_break = FALSE;
3551 } else if (quote_str && wrap_quote) {
3552 automatic_break = TRUE;
3553 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3554 automatic_break = FALSE;
3557 /* remove trailing spaces */
3559 gtk_text_iter_backward_char(&cur);
3561 while (!gtk_text_iter_starts_line(&cur)) {
3564 gtk_text_iter_backward_char(&cur);
3565 wc = gtk_text_iter_get_char(&cur);
3566 if (!g_unichar_isspace(wc))
3570 if (!gtk_text_iter_equal(&prev, &next)) {
3571 gtk_text_buffer_delete(buffer, &prev, &next);
3573 gtk_text_iter_forward_char(&break_pos);
3577 gtk_text_buffer_insert(buffer, &break_pos,
3581 compose_join_next_line(compose, buffer, &iter, quote_str);
3583 /* move iter to current line start */
3584 gtk_text_iter_set_line_offset(&iter, 0);
3591 /* move iter to next line start */
3596 if (!prev_autowrap && num_blocks > 0) {
3598 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3599 G_CALLBACK(text_inserted),
3603 while (!gtk_text_iter_ends_line(&end_of_line)) {
3604 gtk_text_iter_forward_char(&end_of_line);
3606 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3608 nouri_start = gtk_text_iter_get_offset(&iter);
3609 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3611 walk_pos = gtk_text_iter_get_offset(&iter);
3612 /* FIXME: this looks phony. scanning for anything in the parse table */
3613 for (n = 0; n < PARSE_ELEMS; n++) {
3616 tmp = parser[n].search(walk, parser[n].needle);
3618 if (scanpos == NULL || tmp < scanpos) {
3627 /* check if URI can be parsed */
3628 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3629 (const gchar **)&ep, FALSE)
3630 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3634 strlen(parser[last_index].needle);
3637 uri_start = walk_pos + (bp - o_walk);
3638 uri_stop = walk_pos + (ep - o_walk);
3642 gtk_text_iter_forward_line(&iter);
3645 if (startq_offset != -1) {
3646 GtkTextIter startquote, endquote;
3647 gtk_text_buffer_get_iter_at_offset(
3648 buffer, &startquote, startq_offset);
3650 switch (quotelevel) {
3651 case 0: gtk_text_buffer_apply_tag_by_name(
3652 buffer, "quote0", &startquote, &endquote);
3654 case 1: gtk_text_buffer_apply_tag_by_name(
3655 buffer, "quote1", &startquote, &endquote);
3657 case 2: gtk_text_buffer_apply_tag_by_name(
3658 buffer, "quote2", &startquote, &endquote);
3662 } else if (noq_offset != -1) {
3663 GtkTextIter startnoquote, endnoquote;
3664 gtk_text_buffer_get_iter_at_offset(
3665 buffer, &startnoquote, noq_offset);
3667 gtk_text_buffer_remove_tag_by_name(
3668 buffer, "quote0", &startnoquote, &endnoquote);
3669 gtk_text_buffer_remove_tag_by_name(
3670 buffer, "quote1", &startnoquote, &endnoquote);
3671 gtk_text_buffer_remove_tag_by_name(
3672 buffer, "quote2", &startnoquote, &endnoquote);
3677 GtkTextIter nouri_start_iter, nouri_end_iter;
3678 gtk_text_buffer_get_iter_at_offset(
3679 buffer, &nouri_start_iter, nouri_start);
3680 gtk_text_buffer_get_iter_at_offset(
3681 buffer, &nouri_end_iter, nouri_stop);
3682 gtk_text_buffer_remove_tag_by_name(
3683 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3685 if (uri_start > 0 && uri_stop > 0) {
3686 GtkTextIter uri_start_iter, uri_end_iter;
3687 gtk_text_buffer_get_iter_at_offset(
3688 buffer, &uri_start_iter, uri_start);
3689 gtk_text_buffer_get_iter_at_offset(
3690 buffer, &uri_end_iter, uri_stop);
3691 gtk_text_buffer_apply_tag_by_name(
3692 buffer, "link", &uri_start_iter, &uri_end_iter);
3698 undo_wrapping(compose->undostruct, FALSE);
3699 compose->autowrap = prev_autowrap;
3702 void compose_action_cb(void *data)
3704 Compose *compose = (Compose *)data;
3705 compose_wrap_all(compose);
3708 static void compose_wrap_all(Compose *compose)
3710 compose_wrap_all_full(compose, FALSE);
3713 static void compose_wrap_all_full(Compose *compose, gboolean force)
3715 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3716 GtkTextBuffer *buffer;
3719 buffer = gtk_text_view_get_buffer(text);
3721 gtk_text_buffer_get_start_iter(buffer, &iter);
3722 while (!gtk_text_iter_is_end(&iter))
3723 compose_beautify_paragraph(compose, &iter, force);
3727 static void compose_set_title(Compose *compose)
3733 edited = compose->modified ? _(" [Edited]") : "";
3735 subject = gtk_editable_get_chars(
3736 GTK_EDITABLE(compose->subject_entry), 0, -1);
3738 if (subject && strlen(subject))
3739 str = g_strdup_printf(_("%s - Compose message%s"),
3742 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3743 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3749 * compose_current_mail_account:
3751 * Find a current mail account (the currently selected account, or the
3752 * default account, if a news account is currently selected). If a
3753 * mail account cannot be found, display an error message.
3755 * Return value: Mail account, or NULL if not found.
3757 static PrefsAccount *
3758 compose_current_mail_account(void)
3762 if (cur_account && cur_account->protocol != A_NNTP)
3765 ac = account_get_default();
3766 if (!ac || ac->protocol == A_NNTP) {
3767 alertpanel_error(_("Account for sending mail is not specified.\n"
3768 "Please select a mail account before sending."));
3775 static void compose_select_account(Compose *compose, PrefsAccount *account,
3778 GtkItemFactory *ifactory;
3780 g_return_if_fail(account != NULL);
3782 compose->account = account;
3784 compose_set_title(compose);
3786 ifactory = gtk_item_factory_from_widget(compose->menubar);
3788 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3789 menu_set_active(ifactory, "/Options/Sign", TRUE);
3791 menu_set_active(ifactory, "/Options/Sign", FALSE);
3792 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3793 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3795 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3797 activate_privacy_system(compose, account, FALSE);
3799 if (!init && compose->mode != COMPOSE_REDIRECT)
3800 compose_insert_sig(compose, TRUE);
3803 gboolean compose_check_for_valid_recipient(Compose *compose) {
3804 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3805 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3806 gboolean recipient_found = FALSE;
3810 /* free to and newsgroup list */
3811 slist_free_strings(compose->to_list);
3812 g_slist_free(compose->to_list);
3813 compose->to_list = NULL;
3815 slist_free_strings(compose->newsgroup_list);
3816 g_slist_free(compose->newsgroup_list);
3817 compose->newsgroup_list = NULL;
3819 /* search header entries for to and newsgroup entries */
3820 for (list = compose->header_list; list; list = list->next) {
3823 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3824 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3826 if (entry[0] != '\0') {
3827 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3828 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3829 compose->to_list = address_list_append(compose->to_list, entry);
3830 recipient_found = TRUE;
3833 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3834 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3835 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3836 recipient_found = TRUE;
3843 return recipient_found;
3846 static gboolean compose_check_for_set_recipients(Compose *compose)
3848 if (compose->account->set_autocc && compose->account->auto_cc) {
3849 gboolean found_other = FALSE;
3851 /* search header entries for to and newsgroup entries */
3852 for (list = compose->header_list; list; list = list->next) {
3855 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3856 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3858 if (strcmp(entry, compose->account->auto_cc)
3859 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3869 aval = alertpanel(_("Send"),
3870 _("The only recipient is the default CC address. Send anyway?"),
3871 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3872 if (aval != G_ALERTALTERNATE)
3876 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3877 gboolean found_other = FALSE;
3879 /* search header entries for to and newsgroup entries */
3880 for (list = compose->header_list; list; list = list->next) {
3883 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3884 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3886 if (strcmp(entry, compose->account->auto_cc)
3887 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3897 aval = alertpanel(_("Send"),
3898 _("The only recipient is the default BCC address. Send anyway?"),
3899 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3900 if (aval != G_ALERTALTERNATE)
3907 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3911 if (compose_check_for_valid_recipient(compose) == FALSE) {
3912 alertpanel_error(_("Recipient is not specified."));
3916 if (compose_check_for_set_recipients(compose) == FALSE) {
3920 if (!compose->batch) {
3921 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3922 if (*str == '\0' && check_subject == TRUE) {
3925 aval = alertpanel(_("Send"),
3926 _("Subject is empty. Send it anyway?"),
3927 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3928 if (aval != G_ALERTALTERNATE)
3936 gint compose_send(Compose *compose)
3941 gchar *msgpath = NULL;
3942 gboolean discard_window = FALSE;
3944 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
3945 || compose->batch == TRUE)
3946 discard_window = TRUE;
3948 compose_allow_user_actions (compose, FALSE);
3949 compose->sending = TRUE;
3951 if (compose_check_entries(compose, TRUE) == FALSE) {
3952 if (compose->batch) {
3953 gtk_widget_show_all(compose->window);
3958 val = compose_queue(compose, &msgnum, &folder, &msgpath);
3961 if (compose->batch) {
3962 gtk_widget_show_all(compose->window);
3965 alertpanel_error(_("Could not queue message for sending:\n\n"
3966 "Charset conversion failed."));
3967 } else if (val == -3) {
3968 alertpanel_error(_("Could not queue message for sending:\n\n"
3969 "Signature failed."));
3970 } else if (val == -2 && errno != 0) {
3971 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3973 alertpanel_error(_("Could not queue message for sending."));
3978 if (discard_window) {
3979 compose->sending = FALSE;
3980 compose_close(compose);
3981 /* No more compose access in the normal codepath
3982 * after this point! */
3987 if (!discard_window) {
3990 alertpanel_error(_("The message was queued but could not be "
3991 "sent.\nUse \"Send queued messages\" from "
3992 "the main window to retry."));
3996 if (msgpath == NULL) {
3997 msgpath = folder_item_fetch_msg(folder, msgnum);
3998 val = procmsg_send_message_queue(msgpath);
4001 val = procmsg_send_message_queue(msgpath);
4005 if (!discard_window) {
4006 compose->sending = FALSE;
4007 compose_allow_user_actions (compose, TRUE);
4009 folder_item_remove_msg(folder, msgnum);
4010 folder_item_scan(folder);
4015 folder_item_remove_msg(folder, msgnum);
4016 folder_item_scan(folder);
4017 if (!discard_window)
4018 compose_close(compose);
4020 if (!discard_window) {
4023 alertpanel_error(_("The message was queued but could not be "
4024 "sent.\nUse \"Send queued messages\" from "
4025 "the main window to retry."));
4032 compose_allow_user_actions (compose, TRUE);
4033 compose->sending = FALSE;
4034 compose->modified = TRUE;
4039 static gboolean compose_use_attach(Compose *compose)
4041 GtkTreeModel *model = gtk_tree_view_get_model
4042 (GTK_TREE_VIEW(compose->attach_clist));
4043 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4046 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4049 gchar buf[BUFFSIZE];
4051 gboolean first_to_address;
4052 gboolean first_cc_address;
4054 ComposeHeaderEntry *headerentry;
4055 const gchar *headerentryname;
4059 debug_print("Writing redirect header\n");
4061 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4062 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4064 first_to_address = TRUE;
4065 for (list = compose->header_list; list; list = list->next) {
4066 headerentry = ((ComposeHeaderEntry *)list->data);
4067 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4069 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4070 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4071 Xstrdup_a(str, entstr, return -1);
4073 if (str[0] != '\0') {
4074 compose_convert_header
4075 (compose, buf, sizeof(buf), str,
4076 strlen("Resent-To") + 2, TRUE);
4078 if (first_to_address) {
4079 fprintf(fp, "Resent-To: ");
4080 first_to_address = FALSE;
4084 fprintf(fp, "%s", buf);
4088 if (!first_to_address) {
4092 first_cc_address = TRUE;
4093 for (list = compose->header_list; list; list = list->next) {
4094 headerentry = ((ComposeHeaderEntry *)list->data);
4095 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4097 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4098 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4099 Xstrdup_a(str, strg, return -1);
4101 if (str[0] != '\0') {
4102 compose_convert_header
4103 (compose, buf, sizeof(buf), str,
4104 strlen("Resent-Cc") + 2, TRUE);
4106 if (first_cc_address) {
4107 fprintf(fp, "Resent-Cc: ");
4108 first_cc_address = FALSE;
4112 fprintf(fp, "%s", buf);
4116 if (!first_cc_address) {
4123 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4125 gchar buf[BUFFSIZE];
4127 const gchar *entstr;
4128 /* struct utsname utsbuf; */
4130 g_return_val_if_fail(fp != NULL, -1);
4131 g_return_val_if_fail(compose->account != NULL, -1);
4132 g_return_val_if_fail(compose->account->address != NULL, -1);
4135 get_rfc822_date(buf, sizeof(buf));
4136 fprintf(fp, "Resent-Date: %s\n", buf);
4139 if (compose->account->name && *compose->account->name) {
4140 compose_convert_header
4141 (compose, buf, sizeof(buf), compose->account->name,
4142 strlen("From: "), TRUE);
4143 fprintf(fp, "Resent-From: %s <%s>\n",
4144 buf, compose->account->address);
4146 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4149 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4150 if (*entstr != '\0') {
4151 Xstrdup_a(str, entstr, return -1);
4154 compose_convert_header(compose, buf, sizeof(buf), str,
4155 strlen("Subject: "), FALSE);
4156 fprintf(fp, "Subject: %s\n", buf);
4160 /* Resent-Message-ID */
4161 if (compose->account->gen_msgid) {
4162 generate_msgid(buf, sizeof(buf));
4163 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4164 compose->msgid = g_strdup(buf);
4167 compose_redirect_write_headers_from_headerlist(compose, fp);
4169 /* separator between header and body */
4175 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4179 gchar buf[BUFFSIZE];
4181 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4182 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4186 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4187 /* should filter returnpath, delivered-to */
4188 if (g_ascii_strncasecmp(buf, "Return-Path:",
4189 strlen("Return-Path:")) == 0 ||
4190 g_ascii_strncasecmp(buf, "Delivered-To:",
4191 strlen("Delivered-To:")) == 0 ||
4192 g_ascii_strncasecmp(buf, "Received:",
4193 strlen("Received:")) == 0 ||
4194 g_ascii_strncasecmp(buf, "Subject:",
4195 strlen("Subject:")) == 0 ||
4196 g_ascii_strncasecmp(buf, "X-UIDL:",
4197 strlen("X-UIDL:")) == 0)
4200 if (fputs(buf, fdest) == -1)
4203 if (!prefs_common.redirect_keep_from) {
4204 if (g_ascii_strncasecmp(buf, "From:",
4205 strlen("From:")) == 0) {
4206 fputs(" (by way of ", fdest);
4207 if (compose->account->name
4208 && *compose->account->name) {
4209 compose_convert_header
4210 (compose, buf, sizeof(buf),
4211 compose->account->name,
4214 fprintf(fdest, "%s <%s>",
4216 compose->account->address);
4218 fprintf(fdest, "%s",
4219 compose->account->address);
4224 if (fputs("\n", fdest) == -1)
4228 compose_redirect_write_headers(compose, fdest);
4230 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4231 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4244 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4246 GtkTextBuffer *buffer;
4247 GtkTextIter start, end;
4250 const gchar *out_codeset;
4251 EncodingType encoding;
4252 MimeInfo *mimemsg, *mimetext;
4255 /* create message MimeInfo */
4256 mimemsg = procmime_mimeinfo_new();
4257 mimemsg->type = MIMETYPE_MESSAGE;
4258 mimemsg->subtype = g_strdup("rfc822");
4259 mimemsg->content = MIMECONTENT_MEM;
4260 mimemsg->tmp = TRUE; /* must free content later */
4261 mimemsg->data.mem = compose_get_header(compose);
4263 /* Create text part MimeInfo */
4264 /* get all composed text */
4265 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4266 gtk_text_buffer_get_start_iter(buffer, &start);
4267 gtk_text_buffer_get_end_iter(buffer, &end);
4268 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4269 if (is_ascii_str(chars)) {
4272 out_codeset = CS_US_ASCII;
4273 encoding = ENC_7BIT;
4275 const gchar *src_codeset = CS_INTERNAL;
4277 out_codeset = conv_get_charset_str(compose->out_encoding);
4280 gchar *test_conv_global_out = NULL;
4281 gchar *test_conv_reply = NULL;
4283 /* automatic mode. be automatic. */
4284 codeconv_set_strict(TRUE);
4286 out_codeset = conv_get_outgoing_charset_str();
4288 debug_print("trying to convert to %s\n", out_codeset);
4289 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4292 if (!test_conv_global_out && compose->orig_charset
4293 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4294 out_codeset = compose->orig_charset;
4295 debug_print("failure; trying to convert to %s\n", out_codeset);
4296 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4299 if (!test_conv_global_out && !test_conv_reply) {
4301 out_codeset = CS_INTERNAL;
4302 debug_print("failure; finally using %s\n", out_codeset);
4304 g_free(test_conv_global_out);
4305 g_free(test_conv_reply);
4306 codeconv_set_strict(FALSE);
4309 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4310 out_codeset = CS_ISO_8859_1;
4312 if (prefs_common.encoding_method == CTE_BASE64)
4313 encoding = ENC_BASE64;
4314 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4315 encoding = ENC_QUOTED_PRINTABLE;
4316 else if (prefs_common.encoding_method == CTE_8BIT)
4317 encoding = ENC_8BIT;
4319 encoding = procmime_get_encoding_for_charset(out_codeset);
4321 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4322 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4324 if (action == COMPOSE_WRITE_FOR_SEND) {
4325 codeconv_set_strict(TRUE);
4326 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4327 codeconv_set_strict(FALSE);
4333 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4334 "to the specified %s charset.\n"
4335 "Send it as %s?"), out_codeset, src_codeset);
4336 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4337 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4340 if (aval != G_ALERTALTERNATE) {
4345 out_codeset = src_codeset;
4351 out_codeset = src_codeset;
4357 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4358 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4359 strstr(buf, "\nFrom ") != NULL) {
4360 encoding = ENC_QUOTED_PRINTABLE;
4364 mimetext = procmime_mimeinfo_new();
4365 mimetext->content = MIMECONTENT_MEM;
4366 mimetext->tmp = TRUE; /* must free content later */
4367 mimetext->data.mem = buf;
4368 mimetext->type = MIMETYPE_TEXT;
4369 mimetext->subtype = g_strdup("plain");
4370 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4371 g_strdup(out_codeset));
4372 /* protect trailing spaces when signing message */
4373 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4374 privacy_system_can_sign(compose->privacy_system)) {
4375 encoding = ENC_QUOTED_PRINTABLE;
4378 /* check for line length limit */
4379 if (action == COMPOSE_WRITE_FOR_SEND &&
4380 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4381 check_line_length(buf, 1000, &line) < 0) {
4385 msg = g_strdup_printf
4386 (_("Line %d exceeds the line length limit (998 bytes).\n"
4387 "The contents of the message might be broken on the way to the delivery.\n"
4389 "Send it anyway?"), line + 1);
4390 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4392 if (aval != G_ALERTALTERNATE) {
4397 if (encoding != ENC_UNKNOWN)
4398 procmime_encode_content(mimetext, encoding);
4400 /* append attachment parts */
4401 if (compose_use_attach(compose)) {
4402 MimeInfo *mimempart;
4403 gchar *boundary = NULL;
4404 mimempart = procmime_mimeinfo_new();
4405 mimempart->content = MIMECONTENT_EMPTY;
4406 mimempart->type = MIMETYPE_MULTIPART;
4407 mimempart->subtype = g_strdup("mixed");
4411 boundary = generate_mime_boundary(NULL);
4412 } while (strstr(buf, boundary) != NULL);
4414 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4417 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4419 g_node_append(mimempart->node, mimetext->node);
4420 g_node_append(mimemsg->node, mimempart->node);
4422 compose_add_attachments(compose, mimempart);
4424 g_node_append(mimemsg->node, mimetext->node);
4426 /* sign message if sending */
4427 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4428 privacy_system_can_sign(compose->privacy_system))
4429 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4432 procmime_write_mimeinfo(mimemsg, fp);
4434 procmime_mimeinfo_free_all(mimemsg);
4439 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4441 GtkTextBuffer *buffer;
4442 GtkTextIter start, end;
4447 if ((fp = g_fopen(file, "wb")) == NULL) {
4448 FILE_OP_ERROR(file, "fopen");
4452 /* chmod for security */
4453 if (change_file_mode_rw(fp, file) < 0) {
4454 FILE_OP_ERROR(file, "chmod");
4455 g_warning("can't change file mode\n");
4458 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4459 gtk_text_buffer_get_start_iter(buffer, &start);
4460 gtk_text_buffer_get_end_iter(buffer, &end);
4461 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4463 chars = conv_codeset_strdup
4464 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4467 if (!chars) return -1;
4470 len = strlen(chars);
4471 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4472 FILE_OP_ERROR(file, "fwrite");
4481 if (fclose(fp) == EOF) {
4482 FILE_OP_ERROR(file, "fclose");
4489 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4492 MsgInfo *msginfo = compose->targetinfo;
4494 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4495 if (!msginfo) return -1;
4497 if (!force && MSG_IS_LOCKED(msginfo->flags))
4500 item = msginfo->folder;
4501 g_return_val_if_fail(item != NULL, -1);
4503 if (procmsg_msg_exist(msginfo) &&
4504 (folder_has_parent_of_type(item, F_QUEUE) ||
4505 folder_has_parent_of_type(item, F_DRAFT)
4506 || msginfo == compose->autosaved_draft)) {
4507 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4508 g_warning("can't remove the old message\n");
4516 void compose_remove_draft(Compose *compose)
4519 MsgInfo *msginfo = compose->targetinfo;
4520 drafts = account_get_special_folder(compose->account, F_DRAFT);
4522 if (procmsg_msg_exist(msginfo)) {
4523 folder_item_remove_msg(drafts, msginfo->msgnum);
4528 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath)
4530 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE);
4532 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath, gboolean check_subject)
4539 static gboolean lock = FALSE;
4540 PrefsAccount *mailac = NULL, *newsac = NULL;
4542 debug_print("queueing message...\n");
4543 g_return_val_if_fail(compose->account != NULL, -1);
4547 if (compose_check_entries(compose, check_subject) == FALSE) {
4552 if (!compose->to_list && !compose->newsgroup_list) {
4553 g_warning("can't get recipient list.");
4558 if (compose->to_list) {
4559 if (compose->account->protocol != A_NNTP)
4560 mailac = compose->account;
4561 else if (cur_account && cur_account->protocol != A_NNTP)
4562 mailac = cur_account;
4563 else if (!(mailac = compose_current_mail_account())) {
4565 alertpanel_error(_("No account for sending mails available!"));
4570 if (compose->newsgroup_list) {
4571 if (compose->account->protocol == A_NNTP)
4572 newsac = compose->account;
4573 else if (!newsac->protocol != A_NNTP) {
4575 alertpanel_error(_("No account for posting news available!"));
4580 /* write queue header */
4581 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4582 G_DIR_SEPARATOR, compose);
4583 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4584 FILE_OP_ERROR(tmp, "fopen");
4589 if (change_file_mode_rw(fp, tmp) < 0) {
4590 FILE_OP_ERROR(tmp, "chmod");
4591 g_warning("can't change file mode\n");
4594 /* queueing variables */
4595 fprintf(fp, "AF:\n");
4596 fprintf(fp, "NF:0\n");
4597 fprintf(fp, "PS:10\n");
4598 fprintf(fp, "SRH:1\n");
4599 fprintf(fp, "SFN:\n");
4600 fprintf(fp, "DSR:\n");
4602 fprintf(fp, "MID:<%s>\n", compose->msgid);
4604 fprintf(fp, "MID:\n");
4605 fprintf(fp, "CFG:\n");
4606 fprintf(fp, "PT:0\n");
4607 fprintf(fp, "S:%s\n", compose->account->address);
4608 fprintf(fp, "RQ:\n");
4610 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4612 fprintf(fp, "SSV:\n");
4614 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4616 fprintf(fp, "NSV:\n");
4617 fprintf(fp, "SSH:\n");
4618 /* write recepient list */
4619 if (compose->to_list) {
4620 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4621 for (cur = compose->to_list->next; cur != NULL;
4623 fprintf(fp, ",<%s>", (gchar *)cur->data);
4626 /* write newsgroup list */
4627 if (compose->newsgroup_list) {
4629 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4630 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4631 fprintf(fp, ",%s", (gchar *)cur->data);
4634 /* Sylpheed account IDs */
4636 fprintf(fp, "MAID:%d\n", mailac->account_id);
4638 fprintf(fp, "NAID:%d\n", newsac->account_id);
4640 if (compose->privacy_system != NULL) {
4641 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4642 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4643 if (compose->use_encryption) {
4645 if (mailac && mailac->encrypt_to_self) {
4646 GSList *tmp_list = g_slist_copy(compose->to_list);
4647 tmp_list = g_slist_append(tmp_list, compose->account->address);
4648 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
4649 g_slist_free(tmp_list);
4651 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4653 if (encdata != NULL) {
4654 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4655 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4656 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4658 } /* else we finally dont want to encrypt */
4660 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4661 /* and if encdata was null, it means there's been a problem in
4668 /* Save copy folder */
4669 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4670 gchar *savefolderid;
4672 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4673 fprintf(fp, "SCF:%s\n", savefolderid);
4674 g_free(savefolderid);
4676 /* Save copy folder */
4677 if (compose->return_receipt) {
4678 fprintf(fp, "RRCPT:1\n");
4680 /* Message-ID of message replying to */
4681 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4684 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4685 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4688 /* Message-ID of message forwarding to */
4689 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4692 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4693 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4698 if (compose->redirect_filename != NULL) {
4699 if (compose_redirect_write_to_file(compose, fp) < 0) {
4708 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4713 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4717 if (fclose(fp) == EOF) {
4718 FILE_OP_ERROR(tmp, "fclose");
4724 queue = account_get_special_folder(compose->account, F_QUEUE);
4726 g_warning("can't find queue folder\n");
4731 folder_item_scan(queue);
4732 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4733 g_warning("can't queue the message\n");
4739 if (msgpath == NULL) {
4745 if (compose->mode == COMPOSE_REEDIT) {
4746 compose_remove_reedit_target(compose, FALSE);
4749 if ((msgnum != NULL) && (item != NULL)) {
4757 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4760 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4762 struct stat statbuf;
4763 gchar *type, *subtype;
4764 GtkTreeModel *model;
4767 model = gtk_tree_view_get_model(tree_view);
4769 if (!gtk_tree_model_get_iter_first(model, &iter))
4772 gtk_tree_model_get(model, &iter,
4776 mimepart = procmime_mimeinfo_new();
4777 mimepart->content = MIMECONTENT_FILE;
4778 mimepart->data.filename = g_strdup(ainfo->file);
4779 mimepart->tmp = FALSE; /* or we destroy our attachment */
4780 mimepart->offset = 0;
4782 stat(ainfo->file, &statbuf);
4783 mimepart->length = statbuf.st_size;
4785 type = g_strdup(ainfo->content_type);
4787 if (!strchr(type, '/')) {
4789 type = g_strdup("application/octet-stream");
4792 subtype = strchr(type, '/') + 1;
4793 *(subtype - 1) = '\0';
4794 mimepart->type = procmime_get_media_type(type);
4795 mimepart->subtype = g_strdup(subtype);
4798 if (mimepart->type == MIMETYPE_MESSAGE &&
4799 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4800 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4802 g_hash_table_insert(mimepart->typeparameters,
4803 g_strdup("name"), g_strdup(ainfo->name));
4804 g_hash_table_insert(mimepart->dispositionparameters,
4805 g_strdup("filename"), g_strdup(ainfo->name));
4806 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4809 if (compose->use_signing) {
4810 if (ainfo->encoding == ENC_7BIT)
4811 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4812 else if (ainfo->encoding == ENC_8BIT)
4813 ainfo->encoding = ENC_BASE64;
4816 procmime_encode_content(mimepart, ainfo->encoding);
4818 g_node_append(parent->node, mimepart->node);
4819 } while (gtk_tree_model_iter_next(model, &iter));
4822 #define QUOTE_IF_REQUIRED(out, str) \
4824 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4828 len = strlen(str) + 3; \
4829 if ((__tmp = alloca(len)) == NULL) { \
4830 g_warning("can't allocate memory\n"); \
4831 g_string_free(header, TRUE); \
4834 g_snprintf(__tmp, len, "\"%s\"", str); \
4839 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4840 g_warning("can't allocate memory\n"); \
4841 g_string_free(header, TRUE); \
4844 strcpy(__tmp, str); \
4850 #define IS_IN_CUSTOM_HEADER(header) \
4851 (compose->account->add_customhdr && \
4852 custom_header_find(compose->account->customhdr_list, header) != NULL)
4854 static void compose_add_headerfield_from_headerlist(Compose *compose,
4856 const gchar *fieldname,
4857 const gchar *seperator)
4859 gchar *str, *fieldname_w_colon, *trans_fieldname;
4860 gboolean add_field = FALSE;
4862 ComposeHeaderEntry *headerentry;
4863 const gchar * headerentryname;
4866 if (IS_IN_CUSTOM_HEADER(fieldname))
4869 debug_print("Adding %s-fields\n", fieldname);
4871 fieldstr = g_string_sized_new(64);
4873 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4874 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4876 for (list = compose->header_list; list; list = list->next) {
4877 headerentry = ((ComposeHeaderEntry *)list->data);
4878 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4880 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4881 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4883 if (str[0] != '\0') {
4885 g_string_append(fieldstr, seperator);
4886 g_string_append(fieldstr, str);
4895 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4896 compose_convert_header
4897 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4898 strlen(fieldname) + 2, TRUE);
4899 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4903 g_free(fieldname_w_colon);
4904 g_string_free(fieldstr, TRUE);
4909 static gchar *compose_get_header(Compose *compose)
4911 gchar buf[BUFFSIZE];
4912 const gchar *entry_str;
4916 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4919 g_return_val_if_fail(compose->account != NULL, NULL);
4920 g_return_val_if_fail(compose->account->address != NULL, NULL);
4922 header = g_string_sized_new(64);
4925 if (compose->account->add_date) {
4926 get_rfc822_date(buf, sizeof(buf));
4927 g_string_append_printf(header, "Date: %s\n", buf);
4931 if (compose->account->name && *compose->account->name) {
4932 compose_convert_header
4933 (compose, buf, sizeof(buf), compose->account->name,
4934 strlen("From: "), TRUE);
4935 QUOTE_IF_REQUIRED(name, buf);
4936 g_string_append_printf(header, "From: %s <%s>\n",
4937 name, compose->account->address);
4939 g_string_append_printf(header, "From: %s\n", compose->account->address);
4942 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4945 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4948 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4951 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4954 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4956 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4959 compose_convert_header(compose, buf, sizeof(buf), str,
4960 strlen("Subject: "), FALSE);
4961 g_string_append_printf(header, "Subject: %s\n", buf);
4967 if (compose->account->gen_msgid) {
4968 generate_msgid(buf, sizeof(buf));
4969 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4970 compose->msgid = g_strdup(buf);
4973 if (compose->remove_references == FALSE) {
4975 if (compose->inreplyto && compose->to_list)
4976 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4979 if (compose->references)
4980 g_string_append_printf(header, "References: %s\n", compose->references);
4984 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4987 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4990 if (compose->account->organization &&
4991 strlen(compose->account->organization) &&
4992 !IS_IN_CUSTOM_HEADER("Organization")) {
4993 compose_convert_header(compose, buf, sizeof(buf),
4994 compose->account->organization,
4995 strlen("Organization: "), FALSE);
4996 g_string_append_printf(header, "Organization: %s\n", buf);
4999 /* Program version and system info */
5000 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5001 !compose->newsgroup_list) {
5002 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5004 gtk_major_version, gtk_minor_version, gtk_micro_version,
5007 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5008 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5010 gtk_major_version, gtk_minor_version, gtk_micro_version,
5014 /* custom headers */
5015 if (compose->account->add_customhdr) {
5018 for (cur = compose->account->customhdr_list; cur != NULL;
5020 CustomHeader *chdr = (CustomHeader *)cur->data;
5022 if (custom_header_is_allowed(chdr->name)) {
5023 compose_convert_header
5024 (compose, buf, sizeof(buf),
5025 chdr->value ? chdr->value : "",
5026 strlen(chdr->name) + 2, FALSE);
5027 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5033 switch (compose->priority) {
5034 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5035 "X-Priority: 1 (Highest)\n");
5037 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5038 "X-Priority: 2 (High)\n");
5040 case PRIORITY_NORMAL: break;
5041 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5042 "X-Priority: 4 (Low)\n");
5044 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5045 "X-Priority: 5 (Lowest)\n");
5047 default: debug_print("compose: priority unknown : %d\n",
5051 /* Request Return Receipt */
5052 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5053 if (compose->return_receipt) {
5054 if (compose->account->name
5055 && *compose->account->name) {
5056 compose_convert_header(compose, buf, sizeof(buf),
5057 compose->account->name,
5058 strlen("Disposition-Notification-To: "),
5060 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5062 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5066 /* get special headers */
5067 for (list = compose->header_list; list; list = list->next) {
5068 ComposeHeaderEntry *headerentry;
5071 gchar *headername_wcolon;
5072 gchar *headername_trans;
5075 gboolean standard_header = FALSE;
5077 headerentry = ((ComposeHeaderEntry *)list->data);
5079 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5080 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5085 if (!strstr(tmp, ":")) {
5086 headername_wcolon = g_strconcat(tmp, ":", NULL);
5087 headername = g_strdup(tmp);
5089 headername_wcolon = g_strdup(tmp);
5090 headername = g_strdup(strtok(tmp, ":"));
5094 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5095 Xstrdup_a(headervalue, entry_str, return NULL);
5096 subst_char(headervalue, '\r', ' ');
5097 subst_char(headervalue, '\n', ' ');
5098 string = std_headers;
5099 while (*string != NULL) {
5100 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5101 if (!strcmp(headername_trans,headername_wcolon))
5102 standard_header = TRUE;
5105 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5106 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5109 g_free(headername_wcolon);
5113 g_string_free(header, FALSE);
5118 #undef IS_IN_CUSTOM_HEADER
5120 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5121 gint header_len, gboolean addr_field)
5123 gchar *tmpstr = NULL;
5124 const gchar *out_codeset = NULL;
5126 g_return_if_fail(src != NULL);
5127 g_return_if_fail(dest != NULL);
5129 if (len < 1) return;
5131 tmpstr = g_strdup(src);
5133 subst_char(tmpstr, '\n', ' ');
5134 subst_char(tmpstr, '\r', ' ');
5137 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5138 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5139 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5144 codeconv_set_strict(TRUE);
5145 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5146 conv_get_charset_str(compose->out_encoding));
5147 codeconv_set_strict(FALSE);
5149 if (!dest || *dest == '\0') {
5150 gchar *test_conv_global_out = NULL;
5151 gchar *test_conv_reply = NULL;
5153 /* automatic mode. be automatic. */
5154 codeconv_set_strict(TRUE);
5156 out_codeset = conv_get_outgoing_charset_str();
5158 debug_print("trying to convert to %s\n", out_codeset);
5159 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5162 if (!test_conv_global_out && compose->orig_charset
5163 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5164 out_codeset = compose->orig_charset;
5165 debug_print("failure; trying to convert to %s\n", out_codeset);
5166 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5169 if (!test_conv_global_out && !test_conv_reply) {
5171 out_codeset = CS_INTERNAL;
5172 debug_print("finally using %s\n", out_codeset);
5174 g_free(test_conv_global_out);
5175 g_free(test_conv_reply);
5176 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5178 codeconv_set_strict(FALSE);
5183 static void compose_create_header_entry(Compose *compose)
5185 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5189 GList *combo_list = NULL;
5191 const gchar *header = NULL;
5192 ComposeHeaderEntry *headerentry;
5193 gboolean standard_header = FALSE;
5195 headerentry = g_new0(ComposeHeaderEntry, 1);
5198 combo = gtk_combo_new();
5200 while(*string != NULL) {
5201 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5204 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5205 g_list_free(combo_list);
5206 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5207 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5208 G_CALLBACK(compose_grab_focus_cb), compose);
5209 gtk_widget_show(combo);
5210 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5211 if (compose->header_last) {
5212 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5214 while (*string != NULL) {
5215 if (!strcmp(*string, last_header_entry))
5216 standard_header = TRUE;
5219 if (standard_header)
5220 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5222 if (!compose->header_last || !standard_header) {
5223 switch(compose->account->protocol) {
5225 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5228 header = prefs_common.trans_hdr ? _("To:") : "To:";
5233 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5235 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5236 G_CALLBACK(compose_grab_focus_cb), compose);
5239 entry = gtk_entry_new();
5240 gtk_widget_show(entry);
5241 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);
5243 g_signal_connect(G_OBJECT(entry), "key-press-event",
5244 G_CALLBACK(compose_headerentry_key_press_event_cb),
5246 g_signal_connect(G_OBJECT(entry), "changed",
5247 G_CALLBACK(compose_headerentry_changed_cb),
5249 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5250 G_CALLBACK(compose_grab_focus_cb), compose);
5253 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5254 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5255 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5256 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5257 G_CALLBACK(compose_header_drag_received_cb),
5259 g_signal_connect(G_OBJECT(entry), "drag-drop",
5260 G_CALLBACK(compose_drag_drop),
5263 address_completion_register_entry(GTK_ENTRY(entry));
5265 headerentry->compose = compose;
5266 headerentry->combo = combo;
5267 headerentry->entry = entry;
5268 headerentry->headernum = compose->header_nextrow;
5270 compose->header_nextrow++;
5271 compose->header_last = headerentry;
5274 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5276 ComposeHeaderEntry *last_header;
5278 last_header = compose->header_last;
5280 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5281 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5284 static GtkWidget *compose_create_header(Compose *compose)
5288 GtkWidget *from_optmenu_hbox;
5289 GtkWidget *header_scrolledwin;
5290 GtkWidget *header_table;
5294 /* header labels and entries */
5295 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5296 gtk_widget_show(header_scrolledwin);
5297 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5299 header_table = gtk_table_new(2, 2, FALSE);
5300 gtk_widget_show(header_table);
5301 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5302 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5303 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5306 /* option menu for selecting accounts */
5307 hbox = gtk_hbox_new(FALSE, 0);
5308 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5309 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5310 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5312 from_optmenu_hbox = compose_account_option_menu_create(compose);
5313 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5314 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5317 compose->header_table = header_table;
5318 compose->header_list = NULL;
5319 compose->header_nextrow = count;
5321 compose_create_header_entry(compose);
5323 compose->table = NULL;
5325 return header_scrolledwin ;
5328 GtkWidget *compose_create_attach(Compose *compose)
5330 GtkWidget *attach_scrwin;
5331 GtkWidget *attach_clist;
5333 GtkListStore *store;
5334 GtkCellRenderer *renderer;
5335 GtkTreeViewColumn *column;
5336 GtkTreeSelection *selection;
5338 /* attachment list */
5339 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5340 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5341 GTK_POLICY_AUTOMATIC,
5342 GTK_POLICY_AUTOMATIC);
5343 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5345 store = gtk_list_store_new(N_ATTACH_COLS,
5350 G_TYPE_AUTO_POINTER,
5352 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5353 (GTK_TREE_MODEL(store)));
5354 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5355 g_object_unref(store);
5357 renderer = gtk_cell_renderer_text_new();
5358 column = gtk_tree_view_column_new_with_attributes
5359 (_("Mime type"), renderer, "text",
5360 COL_MIMETYPE, NULL);
5361 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5363 renderer = gtk_cell_renderer_text_new();
5364 column = gtk_tree_view_column_new_with_attributes
5365 (_("Size"), renderer, "text",
5367 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5369 renderer = gtk_cell_renderer_text_new();
5370 column = gtk_tree_view_column_new_with_attributes
5371 (_("Name"), renderer, "text",
5373 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5375 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5376 prefs_common.enable_rules_hint);
5377 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5378 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5380 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5381 G_CALLBACK(attach_selected), compose);
5382 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5383 G_CALLBACK(attach_button_pressed), compose);
5384 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5385 G_CALLBACK(attach_key_pressed), compose);
5388 gtk_drag_dest_set(attach_clist,
5389 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5390 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5391 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5392 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5393 G_CALLBACK(compose_attach_drag_received_cb),
5395 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5396 G_CALLBACK(compose_drag_drop),
5399 compose->attach_scrwin = attach_scrwin;
5400 compose->attach_clist = attach_clist;
5402 return attach_scrwin;
5405 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5406 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5408 static GtkWidget *compose_create_others(Compose *compose)
5411 GtkWidget *savemsg_checkbtn;
5412 GtkWidget *savemsg_entry;
5413 GtkWidget *savemsg_select;
5416 gchar *folderidentifier;
5418 /* Table for settings */
5419 table = gtk_table_new(3, 1, FALSE);
5420 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5421 gtk_widget_show(table);
5422 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5425 /* Save Message to folder */
5426 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5427 gtk_widget_show(savemsg_checkbtn);
5428 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5429 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5430 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5432 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5433 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5435 savemsg_entry = gtk_entry_new();
5436 gtk_widget_show(savemsg_entry);
5437 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5438 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5439 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5440 G_CALLBACK(compose_grab_focus_cb), compose);
5441 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5442 folderidentifier = folder_item_get_identifier(account_get_special_folder
5443 (compose->account, F_OUTBOX));
5444 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5445 g_free(folderidentifier);
5448 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5449 gtk_widget_show(savemsg_select);
5450 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5451 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5452 G_CALLBACK(compose_savemsg_select_cb),
5457 compose->savemsg_checkbtn = savemsg_checkbtn;
5458 compose->savemsg_entry = savemsg_entry;
5463 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5465 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5466 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5469 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5474 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5477 path = folder_item_get_identifier(dest);
5479 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5483 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5484 GdkAtom clip, GtkTextIter *insert_place);
5486 #define BLOCK_WRAP() { \
5487 prev_autowrap = compose->autowrap; \
5488 buffer = gtk_text_view_get_buffer( \
5489 GTK_TEXT_VIEW(compose->text)); \
5490 compose->autowrap = FALSE; \
5492 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5493 G_CALLBACK(compose_changed_cb), \
5495 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5496 G_CALLBACK(text_inserted), \
5499 #define UNBLOCK_WRAP() { \
5500 compose->autowrap = prev_autowrap; \
5501 if (compose->autowrap) \
5502 compose_wrap_all(compose); \
5504 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5505 G_CALLBACK(compose_changed_cb), \
5507 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5508 G_CALLBACK(text_inserted), \
5513 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5517 GtkTextBuffer *buffer;
5519 if (event->button == 3) {
5521 GtkTextIter sel_start, sel_end;
5522 gboolean stuff_selected;
5524 /* move the cursor to allow GtkAspell to check the word
5525 * under the mouse */
5526 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5527 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5529 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5532 stuff_selected = gtk_text_buffer_get_selection_bounds(
5533 GTK_TEXT_VIEW(text)->buffer,
5534 &sel_start, &sel_end);
5536 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5537 /* reselect stuff */
5539 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5540 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5541 &sel_start, &sel_end);
5543 return FALSE; /* pass the event so that the right-click goes through */
5546 if (event->button == 2) {
5551 /* get the middle-click position to paste at the correct place */
5552 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5553 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5555 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5558 entry_paste_clipboard(compose, text,
5559 prefs_common.linewrap_pastes,
5560 GDK_SELECTION_PRIMARY, &iter);
5568 static void compose_spell_menu_changed(void *data)
5570 Compose *compose = (Compose *)data;
5572 GtkWidget *menuitem;
5573 GtkWidget *parent_item;
5574 GtkMenu *menu = gtk_menu_new();
5575 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5578 parent_item = gtk_item_factory_get_item(ifactory,
5579 "/Spelling/Options");
5581 /* setting the submenu removes /Spelling/Options from the factory
5582 * so we need to save it */
5584 if (parent_item == NULL) {
5585 parent_item = compose->aspell_options_menu;
5586 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5588 compose->aspell_options_menu = parent_item;
5590 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5592 spell_menu = g_slist_reverse(spell_menu);
5593 for (items = spell_menu;
5594 items; items = items->next) {
5595 menuitem = GTK_MENU_ITEM(items->data);
5596 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5597 gtk_widget_show(GTK_WIDGET(menuitem));
5599 g_slist_free(spell_menu);
5601 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
5606 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5613 GtkWidget *handlebox;
5615 GtkWidget *notebook;
5620 GtkWidget *subject_hbox;
5621 GtkWidget *subject_frame;
5622 GtkWidget *subject_entry;
5626 GtkWidget *edit_vbox;
5627 GtkWidget *ruler_hbox;
5629 GtkWidget *scrolledwin;
5631 GtkTextBuffer *buffer;
5632 GtkClipboard *clipboard;
5634 UndoMain *undostruct;
5636 gchar *titles[N_ATTACH_COLS];
5637 guint n_menu_entries;
5638 GtkWidget *popupmenu;
5639 GtkItemFactory *popupfactory;
5640 GtkItemFactory *ifactory;
5641 GtkWidget *tmpl_menu;
5643 GtkWidget *menuitem;
5646 GtkAspell * gtkaspell = NULL;
5649 static GdkGeometry geometry;
5651 g_return_val_if_fail(account != NULL, NULL);
5653 debug_print("Creating compose window...\n");
5654 compose = g_new0(Compose, 1);
5656 titles[COL_MIMETYPE] = _("MIME type");
5657 titles[COL_SIZE] = _("Size");
5658 titles[COL_NAME] = _("Name");
5660 compose->batch = batch;
5661 compose->account = account;
5663 compose->mutex = g_mutex_new();
5664 compose->set_cursor_pos = -1;
5666 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5667 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5668 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5670 if (!geometry.max_width) {
5671 geometry.max_width = gdk_screen_width();
5672 geometry.max_height = gdk_screen_height();
5675 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5676 &geometry, GDK_HINT_MAX_SIZE);
5677 if (!geometry.min_width) {
5678 geometry.min_width = 600;
5679 geometry.min_height = 480;
5681 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5682 &geometry, GDK_HINT_MIN_SIZE);
5683 gtk_widget_set_uposition(window, prefs_common.compose_x,
5684 prefs_common.compose_y);
5686 g_signal_connect(G_OBJECT(window), "delete_event",
5687 G_CALLBACK(compose_delete_cb), compose);
5688 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5689 gtk_widget_realize(window);
5691 gtkut_widget_set_composer_icon(window);
5693 vbox = gtk_vbox_new(FALSE, 0);
5694 gtk_container_add(GTK_CONTAINER(window), vbox);
5696 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5697 menubar = menubar_create(window, compose_entries,
5698 n_menu_entries, "<Compose>", compose);
5699 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5701 if (prefs_common.toolbar_detachable) {
5702 handlebox = gtk_handle_box_new();
5704 handlebox = gtk_hbox_new(FALSE, 0);
5706 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5708 gtk_widget_realize(handlebox);
5709 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5712 vbox2 = gtk_vbox_new(FALSE, 2);
5713 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5714 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5717 notebook = gtk_notebook_new();
5718 gtk_widget_set_size_request(notebook, -1, 130);
5719 gtk_widget_show(notebook);
5721 /* header labels and entries */
5722 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5723 compose_create_header(compose),
5724 gtk_label_new_with_mnemonic(_("Hea_der")));
5725 /* attachment list */
5726 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5727 compose_create_attach(compose),
5728 gtk_label_new_with_mnemonic(_("_Attachments")));
5730 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5731 compose_create_others(compose),
5732 gtk_label_new_with_mnemonic(_("Othe_rs")));
5735 subject_hbox = gtk_hbox_new(FALSE, 0);
5736 gtk_widget_show(subject_hbox);
5738 subject_frame = gtk_frame_new(NULL);
5739 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5740 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5741 gtk_widget_show(subject_frame);
5743 subject = gtk_hbox_new(FALSE, 0);
5744 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5745 gtk_widget_show(subject);
5747 label = gtk_label_new(_("Subject:"));
5748 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5749 gtk_widget_show(label);
5751 subject_entry = gtk_entry_new();
5752 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5753 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5754 G_CALLBACK(compose_grab_focus_cb), compose);
5755 gtk_widget_show(subject_entry);
5756 compose->subject_entry = subject_entry;
5757 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5759 edit_vbox = gtk_vbox_new(FALSE, 0);
5761 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5764 ruler_hbox = gtk_hbox_new(FALSE, 0);
5765 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5767 ruler = gtk_shruler_new();
5768 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5769 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5773 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5774 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5775 GTK_POLICY_AUTOMATIC,
5776 GTK_POLICY_AUTOMATIC);
5777 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5779 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5780 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5782 text = gtk_text_view_new();
5783 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5784 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5785 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5786 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5787 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5789 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5791 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5792 G_CALLBACK(compose_edit_size_alloc),
5794 g_signal_connect(G_OBJECT(buffer), "changed",
5795 G_CALLBACK(compose_changed_cb), compose);
5796 g_signal_connect(G_OBJECT(text), "grab_focus",
5797 G_CALLBACK(compose_grab_focus_cb), compose);
5798 g_signal_connect(G_OBJECT(buffer), "insert_text",
5799 G_CALLBACK(text_inserted), compose);
5800 g_signal_connect(G_OBJECT(text), "button_press_event",
5801 G_CALLBACK(text_clicked), compose);
5802 g_signal_connect(G_OBJECT(subject_entry), "changed",
5803 G_CALLBACK(compose_changed_cb), compose);
5806 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5807 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5808 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5809 g_signal_connect(G_OBJECT(text), "drag_data_received",
5810 G_CALLBACK(compose_insert_drag_received_cb),
5812 g_signal_connect(G_OBJECT(text), "drag-drop",
5813 G_CALLBACK(compose_drag_drop),
5815 gtk_widget_show_all(vbox);
5817 /* pane between attach clist and text */
5818 paned = gtk_vpaned_new();
5819 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5820 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5821 gtk_paned_add1(GTK_PANED(paned), notebook);
5822 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5823 gtk_widget_show_all(paned);
5826 if (prefs_common.textfont) {
5827 PangoFontDescription *font_desc;
5829 font_desc = pango_font_description_from_string
5830 (prefs_common.textfont);
5832 gtk_widget_modify_font(text, font_desc);
5833 pango_font_description_free(font_desc);
5837 n_entries = sizeof(compose_popup_entries) /
5838 sizeof(compose_popup_entries[0]);
5839 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5840 "<Compose>", &popupfactory,
5843 ifactory = gtk_item_factory_from_widget(menubar);
5844 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5845 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5846 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5848 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5850 undostruct = undo_init(text);
5851 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5854 address_completion_start(window);
5856 compose->window = window;
5857 compose->vbox = vbox;
5858 compose->menubar = menubar;
5859 compose->handlebox = handlebox;
5861 compose->vbox2 = vbox2;
5863 compose->paned = paned;
5865 compose->edit_vbox = edit_vbox;
5866 compose->ruler_hbox = ruler_hbox;
5867 compose->ruler = ruler;
5868 compose->scrolledwin = scrolledwin;
5869 compose->text = text;
5871 compose->focused_editable = NULL;
5873 compose->popupmenu = popupmenu;
5874 compose->popupfactory = popupfactory;
5876 compose->tmpl_menu = tmpl_menu;
5878 compose->mode = mode;
5880 compose->targetinfo = NULL;
5881 compose->replyinfo = NULL;
5882 compose->fwdinfo = NULL;
5884 compose->replyto = NULL;
5886 compose->bcc = NULL;
5887 compose->followup_to = NULL;
5889 compose->ml_post = NULL;
5891 compose->inreplyto = NULL;
5892 compose->references = NULL;
5893 compose->msgid = NULL;
5894 compose->boundary = NULL;
5896 compose->autowrap = prefs_common.autowrap;
5898 compose->use_signing = FALSE;
5899 compose->use_encryption = FALSE;
5900 compose->privacy_system = NULL;
5902 compose->modified = FALSE;
5904 compose->return_receipt = FALSE;
5906 compose->to_list = NULL;
5907 compose->newsgroup_list = NULL;
5909 compose->undostruct = undostruct;
5911 compose->sig_str = NULL;
5913 compose->exteditor_file = NULL;
5914 compose->exteditor_pid = -1;
5915 compose->exteditor_tag = -1;
5916 compose->draft_timeout_tag = -1;
5919 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5920 if (mode != COMPOSE_REDIRECT) {
5921 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5922 strcmp(prefs_common.dictionary, "")) {
5923 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5924 prefs_common.dictionary,
5925 conv_get_locale_charset_str(),
5926 prefs_common.misspelled_col,
5927 prefs_common.check_while_typing,
5928 prefs_common.recheck_when_changing_dict,
5929 prefs_common.use_alternate,
5930 GTK_TEXT_VIEW(text),
5931 GTK_WINDOW(compose->window),
5932 compose_spell_menu_changed,
5935 alertpanel_error(_("Spell checker could not "
5937 gtkaspell_checkers_strerror());
5938 gtkaspell_checkers_reset_error();
5940 if (!gtkaspell_set_sug_mode(gtkaspell,
5941 prefs_common.aspell_sugmode)) {
5942 debug_print("Aspell: could not set "
5943 "suggestion mode %s\n",
5944 gtkaspell_checkers_strerror());
5945 gtkaspell_checkers_reset_error();
5948 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5952 compose->gtkaspell = gtkaspell;
5953 compose_spell_menu_changed(compose);
5956 compose_select_account(compose, account, TRUE);
5958 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5959 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5960 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5962 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5963 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5965 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5966 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5969 if (account->protocol != A_NNTP)
5970 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5972 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5974 addressbook_set_target_compose(compose);
5976 if (mode != COMPOSE_REDIRECT)
5977 compose_set_template_menu(compose);
5979 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5980 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5983 compose_list = g_list_append(compose_list, compose);
5985 if (!prefs_common.show_ruler)
5986 gtk_widget_hide(ruler_hbox);
5988 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5989 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5990 prefs_common.show_ruler);
5993 compose->priority = PRIORITY_NORMAL;
5994 compose_update_priority_menu_item(compose);
5996 compose_set_out_encoding(compose);
5999 compose_update_actions_menu(compose);
6001 /* Privacy Systems menu */
6002 compose_update_privacy_systems_menu(compose);
6004 activate_privacy_system(compose, account, TRUE);
6005 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6007 gtk_widget_realize(window);
6009 gtk_widget_show(window);
6015 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6020 gint num = 0, def_menu = 0;
6022 accounts = account_get_list();
6023 g_return_val_if_fail(accounts != NULL, NULL);
6025 optmenu = gtk_option_menu_new();
6026 menu = gtk_menu_new();
6028 for (; accounts != NULL; accounts = accounts->next, num++) {
6029 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6030 GtkWidget *menuitem;
6033 if (ac == compose->account) def_menu = num;
6035 if (prefs_common.compose_no_markup) {
6037 name = g_markup_printf_escaped("%s : %s <%s>",
6039 ac->name, ac->address);
6041 name = g_markup_printf_escaped("%s : <%s>",
6042 ac->account_name, ac->address);
6045 name = g_markup_printf_escaped("<i>%s</i> : %s <<b>%s</b>>",
6047 ac->name, ac->address);
6049 name = g_markup_printf_escaped("<i>%s</i> : <<b>%s</b>>",
6050 ac->account_name, ac->address);
6052 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
6053 gtk_label_set_use_markup (
6054 GTK_LABEL (gtk_bin_get_child (GTK_BIN (menuitem))),
6057 g_signal_connect(G_OBJECT(menuitem), "activate",
6058 G_CALLBACK(account_activated),
6062 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
6063 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
6068 static void compose_set_priority_cb(gpointer data,
6072 Compose *compose = (Compose *) data;
6073 compose->priority = action;
6076 static void compose_update_priority_menu_item(Compose * compose)
6078 GtkItemFactory *ifactory;
6079 GtkWidget *menuitem = NULL;
6081 ifactory = gtk_item_factory_from_widget(compose->menubar);
6083 switch (compose->priority) {
6084 case PRIORITY_HIGHEST:
6085 menuitem = gtk_item_factory_get_item
6086 (ifactory, "/Options/Priority/Highest");
6089 menuitem = gtk_item_factory_get_item
6090 (ifactory, "/Options/Priority/High");
6092 case PRIORITY_NORMAL:
6093 menuitem = gtk_item_factory_get_item
6094 (ifactory, "/Options/Priority/Normal");
6097 menuitem = gtk_item_factory_get_item
6098 (ifactory, "/Options/Priority/Low");
6100 case PRIORITY_LOWEST:
6101 menuitem = gtk_item_factory_get_item
6102 (ifactory, "/Options/Priority/Lowest");
6105 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6108 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6110 Compose *compose = (Compose *) data;
6112 GtkItemFactory *ifactory;
6113 gboolean can_sign = FALSE, can_encrypt = FALSE;
6115 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6117 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6120 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6121 g_free(compose->privacy_system);
6122 compose->privacy_system = NULL;
6123 if (systemid != NULL) {
6124 compose->privacy_system = g_strdup(systemid);
6126 can_sign = privacy_system_can_sign(systemid);
6127 can_encrypt = privacy_system_can_encrypt(systemid);
6130 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6132 ifactory = gtk_item_factory_from_widget(compose->menubar);
6133 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6134 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6137 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6139 static gchar *branch_path = "/Options/Privacy System";
6140 GtkItemFactory *ifactory;
6141 GtkWidget *menuitem = NULL;
6143 gboolean can_sign = FALSE, can_encrypt = FALSE;
6144 gboolean found = FALSE;
6146 ifactory = gtk_item_factory_from_widget(compose->menubar);
6148 if (compose->privacy_system != NULL) {
6151 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6152 g_return_if_fail(menuitem != NULL);
6154 amenu = GTK_MENU_SHELL(menuitem)->children;
6156 while (amenu != NULL) {
6157 GList *alist = amenu->next;
6159 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6160 if (systemid != NULL) {
6161 if (strcmp(systemid, compose->privacy_system) == 0) {
6162 menuitem = GTK_WIDGET(amenu->data);
6164 can_sign = privacy_system_can_sign(systemid);
6165 can_encrypt = privacy_system_can_encrypt(systemid);
6169 } else if (strlen(compose->privacy_system) == 0) {
6170 menuitem = GTK_WIDGET(amenu->data);
6173 can_encrypt = FALSE;
6180 if (menuitem != NULL)
6181 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6183 if (warn && !found && strlen(compose->privacy_system)) {
6184 gchar *tmp = g_strdup_printf(
6185 _("The privacy system '%s' cannot be loaded. You "
6186 "will not be able to sign or encrypt this message."),
6187 compose->privacy_system);
6188 alertpanel_warning(tmp);
6193 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6194 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6197 static void compose_set_out_encoding(Compose *compose)
6199 GtkItemFactoryEntry *entry;
6200 GtkItemFactory *ifactory;
6201 CharSet out_encoding;
6202 gchar *path, *p, *q;
6205 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6206 ifactory = gtk_item_factory_from_widget(compose->menubar);
6208 for (entry = compose_entries; entry->callback != compose_address_cb;
6210 if (entry->callback == compose_set_encoding_cb &&
6211 (CharSet)entry->callback_action == out_encoding) {
6212 p = q = path = g_strdup(entry->path);
6224 item = gtk_item_factory_get_item(ifactory, path);
6225 gtk_widget_activate(item);
6232 static void compose_set_template_menu(Compose *compose)
6234 GSList *tmpl_list, *cur;
6238 tmpl_list = template_get_config();
6240 menu = gtk_menu_new();
6242 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6243 Template *tmpl = (Template *)cur->data;
6245 item = gtk_menu_item_new_with_label(tmpl->name);
6246 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6247 g_signal_connect(G_OBJECT(item), "activate",
6248 G_CALLBACK(compose_template_activate_cb),
6250 g_object_set_data(G_OBJECT(item), "template", tmpl);
6251 gtk_widget_show(item);
6254 gtk_widget_show(menu);
6255 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6258 void compose_update_actions_menu(Compose *compose)
6260 GtkItemFactory *ifactory;
6262 ifactory = gtk_item_factory_from_widget(compose->menubar);
6263 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6266 void compose_update_privacy_systems_menu(Compose *compose)
6268 static gchar *branch_path = "/Options/Privacy System";
6269 GtkItemFactory *ifactory;
6270 GtkWidget *menuitem;
6271 GSList *systems, *cur;
6274 GtkWidget *system_none;
6277 ifactory = gtk_item_factory_from_widget(compose->menubar);
6279 /* remove old entries */
6280 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6281 g_return_if_fail(menuitem != NULL);
6283 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6284 while (amenu != NULL) {
6285 GList *alist = amenu->next;
6286 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6290 system_none = gtk_item_factory_get_widget(ifactory,
6291 "/Options/Privacy System/None");
6293 g_signal_connect(G_OBJECT(system_none), "activate",
6294 G_CALLBACK(compose_set_privacy_system_cb), compose);
6296 systems = privacy_get_system_ids();
6297 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6298 gchar *systemid = cur->data;
6300 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6301 widget = gtk_radio_menu_item_new_with_label(group,
6302 privacy_system_get_name(systemid));
6303 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6304 g_strdup(systemid), g_free);
6305 g_signal_connect(G_OBJECT(widget), "activate",
6306 G_CALLBACK(compose_set_privacy_system_cb), compose);
6308 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6309 gtk_widget_show(widget);
6312 g_slist_free(systems);
6315 void compose_reflect_prefs_all(void)
6320 for (cur = compose_list; cur != NULL; cur = cur->next) {
6321 compose = (Compose *)cur->data;
6322 compose_set_template_menu(compose);
6326 void compose_reflect_prefs_pixmap_theme(void)
6331 for (cur = compose_list; cur != NULL; cur = cur->next) {
6332 compose = (Compose *)cur->data;
6333 toolbar_update(TOOLBAR_COMPOSE, compose);
6337 static void compose_template_apply(Compose *compose, Template *tmpl,
6341 GtkTextBuffer *buffer;
6345 gchar *parsed_str = NULL;
6346 gint cursor_pos = 0;
6349 /* process the body */
6351 text = GTK_TEXT_VIEW(compose->text);
6352 buffer = gtk_text_view_get_buffer(text);
6355 gtk_text_buffer_set_text(buffer, "", -1);
6357 mark = gtk_text_buffer_get_insert(buffer);
6358 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6361 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6362 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6365 if (prefs_common.quotemark && *prefs_common.quotemark)
6366 qmark = prefs_common.quotemark;
6370 if (compose->replyinfo != NULL)
6371 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6372 tmpl->value, qmark, NULL, FALSE);
6373 else if (compose->fwdinfo != NULL)
6374 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6375 tmpl->value, qmark, NULL, FALSE);
6380 if (replace && parsed_str && compose->account->auto_sig)
6381 compose_insert_sig(compose, FALSE);
6383 if (replace && parsed_str) {
6384 gtk_text_buffer_get_start_iter(buffer, &iter);
6385 gtk_text_buffer_place_cursor(buffer, &iter);
6389 cursor_pos = quote_fmt_get_cursor_pos();
6390 compose->set_cursor_pos = cursor_pos;
6391 if (cursor_pos == -1)
6393 gtk_text_buffer_get_start_iter(buffer, &iter);
6394 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6395 gtk_text_buffer_place_cursor(buffer, &iter);
6398 /* process the other fields */
6399 compose_template_apply_fields(compose, tmpl);
6401 compose_changed_cb(NULL, compose);
6404 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6406 static MsgInfo dummyinfo;
6407 MsgInfo *msginfo = NULL;
6410 if (compose->replyinfo != NULL)
6411 msginfo = compose->replyinfo;
6412 else if (compose->fwdinfo != NULL)
6413 msginfo = compose->fwdinfo;
6415 msginfo = &dummyinfo;
6417 if (tmpl->to && *tmpl->to != '\0') {
6418 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6419 quote_fmt_scan_string(tmpl->to);
6422 buf = quote_fmt_get_buffer();
6424 alertpanel_error(_("Message To format error."));
6426 compose_entry_append(compose, buf, COMPOSE_TO);
6430 if (tmpl->cc && *tmpl->cc != '\0') {
6431 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6432 quote_fmt_scan_string(tmpl->cc);
6435 buf = quote_fmt_get_buffer();
6437 alertpanel_error(_("Message Cc format error."));
6439 compose_entry_append(compose, buf, COMPOSE_CC);
6443 if (tmpl->bcc && *tmpl->bcc != '\0') {
6444 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6445 quote_fmt_scan_string(tmpl->bcc);
6448 buf = quote_fmt_get_buffer();
6450 alertpanel_error(_("Message Bcc format error."));
6452 compose_entry_append(compose, buf, COMPOSE_BCC);
6456 /* process the subject */
6457 if (tmpl->subject && *tmpl->subject != '\0') {
6458 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6459 quote_fmt_scan_string(tmpl->subject);
6462 buf = quote_fmt_get_buffer();
6464 alertpanel_error(_("Message subject format error."));
6466 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6471 static void compose_destroy(Compose *compose)
6473 compose_list = g_list_remove(compose_list, compose);
6475 if (compose->updating) {
6476 debug_print("danger, not destroying anything now\n");
6477 compose->deferred_destroy = TRUE;
6480 /* NOTE: address_completion_end() does nothing with the window
6481 * however this may change. */
6482 address_completion_end(compose->window);
6484 slist_free_strings(compose->to_list);
6485 g_slist_free(compose->to_list);
6486 slist_free_strings(compose->newsgroup_list);
6487 g_slist_free(compose->newsgroup_list);
6488 slist_free_strings(compose->header_list);
6489 g_slist_free(compose->header_list);
6491 procmsg_msginfo_free(compose->targetinfo);
6492 procmsg_msginfo_free(compose->replyinfo);
6493 procmsg_msginfo_free(compose->fwdinfo);
6495 g_free(compose->replyto);
6496 g_free(compose->cc);
6497 g_free(compose->bcc);
6498 g_free(compose->newsgroups);
6499 g_free(compose->followup_to);
6501 g_free(compose->ml_post);
6503 g_free(compose->inreplyto);
6504 g_free(compose->references);
6505 g_free(compose->msgid);
6506 g_free(compose->boundary);
6508 g_free(compose->redirect_filename);
6509 if (compose->undostruct)
6510 undo_destroy(compose->undostruct);
6512 g_free(compose->sig_str);
6514 g_free(compose->exteditor_file);
6516 g_free(compose->orig_charset);
6518 g_free(compose->privacy_system);
6520 if (addressbook_get_target_compose() == compose)
6521 addressbook_set_target_compose(NULL);
6524 if (compose->gtkaspell) {
6525 gtkaspell_delete(compose->gtkaspell);
6526 compose->gtkaspell = NULL;
6530 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6531 prefs_common.compose_height = compose->window->allocation.height;
6533 if (!gtk_widget_get_parent(compose->paned))
6534 gtk_widget_destroy(compose->paned);
6535 gtk_widget_destroy(compose->popupmenu);
6537 gtk_widget_destroy(compose->window);
6538 toolbar_destroy(compose->toolbar);
6539 g_free(compose->toolbar);
6540 g_mutex_free(compose->mutex);
6544 static void compose_attach_info_free(AttachInfo *ainfo)
6546 g_free(ainfo->file);
6547 g_free(ainfo->content_type);
6548 g_free(ainfo->name);
6552 static void compose_attach_remove_selected(Compose *compose)
6554 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6555 GtkTreeSelection *selection;
6557 GtkTreeModel *model;
6559 selection = gtk_tree_view_get_selection(tree_view);
6560 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6565 for (cur = sel; cur != NULL; cur = cur->next) {
6566 GtkTreePath *path = cur->data;
6567 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6570 gtk_tree_path_free(path);
6573 for (cur = sel; cur != NULL; cur = cur->next) {
6574 GtkTreeRowReference *ref = cur->data;
6575 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6578 if (gtk_tree_model_get_iter(model, &iter, path))
6579 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6581 gtk_tree_path_free(path);
6582 gtk_tree_row_reference_free(ref);
6588 static struct _AttachProperty
6591 GtkWidget *mimetype_entry;
6592 GtkWidget *encoding_optmenu;
6593 GtkWidget *path_entry;
6594 GtkWidget *filename_entry;
6596 GtkWidget *cancel_btn;
6599 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6601 gtk_tree_path_free((GtkTreePath *)ptr);
6604 static void compose_attach_property(Compose *compose)
6606 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6608 GtkOptionMenu *optmenu;
6609 GtkTreeSelection *selection;
6611 GtkTreeModel *model;
6614 static gboolean cancelled;
6616 /* only if one selected */
6617 selection = gtk_tree_view_get_selection(tree_view);
6618 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6621 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6625 path = (GtkTreePath *) sel->data;
6626 gtk_tree_model_get_iter(model, &iter, path);
6627 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6630 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6636 if (!attach_prop.window)
6637 compose_attach_property_create(&cancelled);
6638 gtk_widget_grab_focus(attach_prop.ok_btn);
6639 gtk_widget_show(attach_prop.window);
6640 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6642 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6643 if (ainfo->encoding == ENC_UNKNOWN)
6644 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6645 GINT_TO_POINTER(ENC_BASE64));
6647 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6648 GINT_TO_POINTER(ainfo->encoding));
6650 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6651 ainfo->content_type ? ainfo->content_type : "");
6652 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6653 ainfo->file ? ainfo->file : "");
6654 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6655 ainfo->name ? ainfo->name : "");
6658 const gchar *entry_text;
6660 gchar *cnttype = NULL;
6664 GtkWidget *menuitem;
6669 gtk_widget_hide(attach_prop.window);
6674 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6675 if (*entry_text != '\0') {
6678 text = g_strstrip(g_strdup(entry_text));
6679 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6680 cnttype = g_strdup(text);
6683 alertpanel_error(_("Invalid MIME type."));
6689 menu = gtk_option_menu_get_menu(optmenu);
6690 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6691 ainfo->encoding = GPOINTER_TO_INT
6692 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6694 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6695 if (*entry_text != '\0') {
6696 if (is_file_exist(entry_text) &&
6697 (size = get_file_size(entry_text)) > 0)
6698 file = g_strdup(entry_text);
6701 (_("File doesn't exist or is empty."));
6707 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6708 if (*entry_text != '\0') {
6709 g_free(ainfo->name);
6710 ainfo->name = g_strdup(entry_text);
6714 g_free(ainfo->content_type);
6715 ainfo->content_type = cnttype;
6718 g_free(ainfo->file);
6724 /* update tree store */
6725 text = to_human_readable(ainfo->size);
6726 gtk_tree_model_get_iter(model, &iter, path);
6727 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6728 COL_MIMETYPE, ainfo->content_type,
6730 COL_NAME, ainfo->name,
6736 gtk_tree_path_free(path);
6739 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6741 label = gtk_label_new(str); \
6742 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6743 GTK_FILL, 0, 0, 0); \
6744 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6746 entry = gtk_entry_new(); \
6747 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6748 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6751 static void compose_attach_property_create(gboolean *cancelled)
6757 GtkWidget *mimetype_entry;
6760 GtkWidget *optmenu_menu;
6761 GtkWidget *menuitem;
6762 GtkWidget *path_entry;
6763 GtkWidget *filename_entry;
6766 GtkWidget *cancel_btn;
6767 GList *mime_type_list, *strlist;
6769 debug_print("Creating attach_property window...\n");
6771 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6772 gtk_widget_set_size_request(window, 480, -1);
6773 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6774 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6775 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6776 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6777 g_signal_connect(G_OBJECT(window), "delete_event",
6778 G_CALLBACK(attach_property_delete_event),
6780 g_signal_connect(G_OBJECT(window), "key_press_event",
6781 G_CALLBACK(attach_property_key_pressed),
6784 vbox = gtk_vbox_new(FALSE, 8);
6785 gtk_container_add(GTK_CONTAINER(window), vbox);
6787 table = gtk_table_new(4, 2, FALSE);
6788 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6789 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6790 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6792 label = gtk_label_new(_("MIME type"));
6793 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6795 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6796 mimetype_entry = gtk_combo_new();
6797 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6798 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6800 /* stuff with list */
6801 mime_type_list = procmime_get_mime_type_list();
6803 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6804 MimeType *type = (MimeType *) mime_type_list->data;
6807 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6809 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6812 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6813 (GCompareFunc)strcmp2);
6816 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6818 for (mime_type_list = strlist; mime_type_list != NULL;
6819 mime_type_list = mime_type_list->next)
6820 g_free(mime_type_list->data);
6821 g_list_free(strlist);
6823 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6825 label = gtk_label_new(_("Encoding"));
6826 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6828 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6830 hbox = gtk_hbox_new(FALSE, 0);
6831 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6832 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6834 optmenu = gtk_option_menu_new();
6835 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6837 optmenu_menu = gtk_menu_new();
6838 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6839 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6840 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6841 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6842 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6843 ENC_QUOTED_PRINTABLE);
6844 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6846 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6848 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6850 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6851 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6853 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6854 &ok_btn, GTK_STOCK_OK,
6856 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6857 gtk_widget_grab_default(ok_btn);
6859 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6860 G_CALLBACK(attach_property_ok),
6862 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6863 G_CALLBACK(attach_property_cancel),
6866 gtk_widget_show_all(vbox);
6868 attach_prop.window = window;
6869 attach_prop.mimetype_entry = mimetype_entry;
6870 attach_prop.encoding_optmenu = optmenu;
6871 attach_prop.path_entry = path_entry;
6872 attach_prop.filename_entry = filename_entry;
6873 attach_prop.ok_btn = ok_btn;
6874 attach_prop.cancel_btn = cancel_btn;
6877 #undef SET_LABEL_AND_ENTRY
6879 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6885 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6891 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6892 gboolean *cancelled)
6900 static gboolean attach_property_key_pressed(GtkWidget *widget,
6902 gboolean *cancelled)
6904 if (event && event->keyval == GDK_Escape) {
6911 static void compose_exec_ext_editor(Compose *compose)
6918 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6919 G_DIR_SEPARATOR, compose);
6921 if (pipe(pipe_fds) < 0) {
6927 if ((pid = fork()) < 0) {
6934 /* close the write side of the pipe */
6937 compose->exteditor_file = g_strdup(tmp);
6938 compose->exteditor_pid = pid;
6940 compose_set_ext_editor_sensitive(compose, FALSE);
6942 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6943 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6947 } else { /* process-monitoring process */
6953 /* close the read side of the pipe */
6956 if (compose_write_body_to_file(compose, tmp) < 0) {
6957 fd_write_all(pipe_fds[1], "2\n", 2);
6961 pid_ed = compose_exec_ext_editor_real(tmp);
6963 fd_write_all(pipe_fds[1], "1\n", 2);
6967 /* wait until editor is terminated */
6968 waitpid(pid_ed, NULL, 0);
6970 fd_write_all(pipe_fds[1], "0\n", 2);
6977 #endif /* G_OS_UNIX */
6981 static gint compose_exec_ext_editor_real(const gchar *file)
6988 g_return_val_if_fail(file != NULL, -1);
6990 if ((pid = fork()) < 0) {
6995 if (pid != 0) return pid;
6997 /* grandchild process */
6999 if (setpgid(0, getppid()))
7002 if (prefs_common.ext_editor_cmd &&
7003 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7004 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7005 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7007 if (prefs_common.ext_editor_cmd)
7008 g_warning("External editor command line is invalid: '%s'\n",
7009 prefs_common.ext_editor_cmd);
7010 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7013 cmdline = strsplit_with_quote(buf, " ", 1024);
7014 execvp(cmdline[0], cmdline);
7017 g_strfreev(cmdline);
7022 static gboolean compose_ext_editor_kill(Compose *compose)
7024 pid_t pgid = compose->exteditor_pid * -1;
7027 ret = kill(pgid, 0);
7029 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7033 msg = g_strdup_printf
7034 (_("The external editor is still working.\n"
7035 "Force terminating the process?\n"
7036 "process group id: %d"), -pgid);
7037 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7038 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7042 if (val == G_ALERTALTERNATE) {
7043 g_source_remove(compose->exteditor_tag);
7044 g_io_channel_shutdown(compose->exteditor_ch,
7046 g_io_channel_unref(compose->exteditor_ch);
7048 if (kill(pgid, SIGTERM) < 0) perror("kill");
7049 waitpid(compose->exteditor_pid, NULL, 0);
7051 g_warning("Terminated process group id: %d", -pgid);
7052 g_warning("Temporary file: %s",
7053 compose->exteditor_file);
7055 compose_set_ext_editor_sensitive(compose, TRUE);
7057 g_free(compose->exteditor_file);
7058 compose->exteditor_file = NULL;
7059 compose->exteditor_pid = -1;
7060 compose->exteditor_ch = NULL;
7061 compose->exteditor_tag = -1;
7069 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7073 Compose *compose = (Compose *)data;
7076 debug_print(_("Compose: input from monitoring process\n"));
7078 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7080 g_io_channel_shutdown(source, FALSE, NULL);
7081 g_io_channel_unref(source);
7083 waitpid(compose->exteditor_pid, NULL, 0);
7085 if (buf[0] == '0') { /* success */
7086 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7087 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7089 gtk_text_buffer_set_text(buffer, "", -1);
7090 compose_insert_file(compose, compose->exteditor_file);
7091 compose_changed_cb(NULL, compose);
7093 if (g_unlink(compose->exteditor_file) < 0)
7094 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7095 } else if (buf[0] == '1') { /* failed */
7096 g_warning("Couldn't exec external editor\n");
7097 if (g_unlink(compose->exteditor_file) < 0)
7098 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7099 } else if (buf[0] == '2') {
7100 g_warning("Couldn't write to file\n");
7101 } else if (buf[0] == '3') {
7102 g_warning("Pipe read failed\n");
7105 compose_set_ext_editor_sensitive(compose, TRUE);
7107 g_free(compose->exteditor_file);
7108 compose->exteditor_file = NULL;
7109 compose->exteditor_pid = -1;
7110 compose->exteditor_ch = NULL;
7111 compose->exteditor_tag = -1;
7116 static void compose_set_ext_editor_sensitive(Compose *compose,
7119 GtkItemFactory *ifactory;
7121 ifactory = gtk_item_factory_from_widget(compose->menubar);
7123 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7124 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7125 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7126 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7127 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7128 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7129 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7132 gtk_widget_set_sensitive(compose->text, sensitive);
7133 if (compose->toolbar->send_btn)
7134 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7135 if (compose->toolbar->sendl_btn)
7136 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7137 if (compose->toolbar->draft_btn)
7138 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7139 if (compose->toolbar->insert_btn)
7140 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7141 if (compose->toolbar->sig_btn)
7142 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7143 if (compose->toolbar->exteditor_btn)
7144 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7145 if (compose->toolbar->linewrap_current_btn)
7146 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7147 if (compose->toolbar->linewrap_all_btn)
7148 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7150 #endif /* G_OS_UNIX */
7153 * compose_undo_state_changed:
7155 * Change the sensivity of the menuentries undo and redo
7157 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7158 gint redo_state, gpointer data)
7160 GtkWidget *widget = GTK_WIDGET(data);
7161 GtkItemFactory *ifactory;
7163 g_return_if_fail(widget != NULL);
7165 ifactory = gtk_item_factory_from_widget(widget);
7167 switch (undo_state) {
7168 case UNDO_STATE_TRUE:
7169 if (!undostruct->undo_state) {
7170 undostruct->undo_state = TRUE;
7171 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7174 case UNDO_STATE_FALSE:
7175 if (undostruct->undo_state) {
7176 undostruct->undo_state = FALSE;
7177 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7180 case UNDO_STATE_UNCHANGED:
7182 case UNDO_STATE_REFRESH:
7183 menu_set_sensitive(ifactory, "/Edit/Undo",
7184 undostruct->undo_state);
7187 g_warning("Undo state not recognized");
7191 switch (redo_state) {
7192 case UNDO_STATE_TRUE:
7193 if (!undostruct->redo_state) {
7194 undostruct->redo_state = TRUE;
7195 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7198 case UNDO_STATE_FALSE:
7199 if (undostruct->redo_state) {
7200 undostruct->redo_state = FALSE;
7201 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7204 case UNDO_STATE_UNCHANGED:
7206 case UNDO_STATE_REFRESH:
7207 menu_set_sensitive(ifactory, "/Edit/Redo",
7208 undostruct->redo_state);
7211 g_warning("Redo state not recognized");
7216 /* callback functions */
7218 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7219 * includes "non-client" (windows-izm) in calculation, so this calculation
7220 * may not be accurate.
7222 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7223 GtkAllocation *allocation,
7224 GtkSHRuler *shruler)
7226 if (prefs_common.show_ruler) {
7227 gint char_width = 0, char_height = 0;
7228 gint line_width_in_chars;
7230 gtkut_get_font_size(GTK_WIDGET(widget),
7231 &char_width, &char_height);
7232 line_width_in_chars =
7233 (allocation->width - allocation->x) / char_width;
7235 /* got the maximum */
7236 gtk_ruler_set_range(GTK_RULER(shruler),
7237 0.0, line_width_in_chars, 0,
7238 /*line_width_in_chars*/ char_width);
7244 static void account_activated(GtkMenuItem *menuitem, gpointer data)
7246 Compose *compose = (Compose *)data;
7249 gchar *folderidentifier;
7251 ac = account_find_from_id(
7252 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
7253 g_return_if_fail(ac != NULL);
7255 if (ac != compose->account)
7256 compose_select_account(compose, ac, FALSE);
7258 /* Set message save folder */
7259 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7260 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7262 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7263 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7265 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7266 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7267 folderidentifier = folder_item_get_identifier(account_get_special_folder
7268 (compose->account, F_OUTBOX));
7269 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7270 g_free(folderidentifier);
7274 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7275 GtkTreeViewColumn *column, Compose *compose)
7277 compose_attach_property(compose);
7280 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7283 Compose *compose = (Compose *)data;
7284 GtkTreeSelection *attach_selection;
7285 gint attach_nr_selected;
7286 GtkItemFactory *ifactory;
7288 if (!event) return FALSE;
7290 if (event->button == 3) {
7291 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7292 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7293 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7295 if (attach_nr_selected > 0)
7297 menu_set_sensitive(ifactory, "/Remove", TRUE);
7298 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7300 menu_set_sensitive(ifactory, "/Remove", FALSE);
7301 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7304 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7305 NULL, NULL, event->button, event->time);
7312 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7315 Compose *compose = (Compose *)data;
7317 if (!event) return FALSE;
7319 switch (event->keyval) {
7321 compose_attach_remove_selected(compose);
7327 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7329 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7330 toolbar_comp_set_sensitive(compose, allow);
7331 menu_set_sensitive(ifactory, "/Message", allow);
7332 menu_set_sensitive(ifactory, "/Edit", allow);
7334 menu_set_sensitive(ifactory, "/Spelling", allow);
7336 menu_set_sensitive(ifactory, "/Options", allow);
7337 menu_set_sensitive(ifactory, "/Tools", allow);
7338 menu_set_sensitive(ifactory, "/Help", allow);
7340 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7344 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7346 Compose *compose = (Compose *)data;
7348 if (prefs_common.work_offline &&
7349 !inc_offline_should_override(
7350 _("Sylpheed-Claws needs network access in order "
7351 "to send this email.")))
7354 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7355 gtk_timeout_remove(compose->draft_timeout_tag);
7356 compose->draft_timeout_tag = -1;
7359 compose_send(compose);
7362 static void compose_send_later_cb(gpointer data, guint action,
7365 Compose *compose = (Compose *)data;
7368 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE);
7370 compose_close(compose);
7371 else if (val == -2) {
7372 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7373 } else if (val == -3) {
7374 alertpanel_error(_("Could not queue message for sending:\n\n"
7375 "Signature failed."));
7376 } else if (val == -4) {
7377 alertpanel_error(_("Could not queue message for sending:\n\n"
7378 "Charset conversion failed."));
7382 void compose_draft (gpointer data)
7384 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7387 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7389 Compose *compose = (Compose *)data;
7393 MsgFlags flag = {0, 0};
7394 static gboolean lock = FALSE;
7395 MsgInfo *newmsginfo;
7397 gboolean target_locked = FALSE;
7401 draft = account_get_special_folder(compose->account, F_DRAFT);
7402 g_return_if_fail(draft != NULL);
7404 if (!g_mutex_trylock(compose->mutex)) {
7405 /* we don't want to lock the mutex once it's available,
7406 * because as the only other part of compose.c locking
7407 * it is compose_close - which means once unlocked,
7408 * the compose struct will be freed */
7409 debug_print("couldn't lock mutex, probably sending\n");
7415 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7416 G_DIR_SEPARATOR, compose);
7417 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7418 FILE_OP_ERROR(tmp, "fopen");
7422 /* chmod for security */
7423 if (change_file_mode_rw(fp, tmp) < 0) {
7424 FILE_OP_ERROR(tmp, "chmod");
7425 g_warning("can't change file mode\n");
7428 /* Save draft infos */
7429 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7430 fprintf(fp, "S:%s\n", compose->account->address);
7431 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7432 gchar *savefolderid;
7434 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7435 fprintf(fp, "SCF:%s\n", savefolderid);
7436 g_free(savefolderid);
7438 if (compose->return_receipt) {
7439 fprintf(fp, "RRCPT:1\n");
7441 if (compose->privacy_system) {
7442 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7443 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7444 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7448 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7456 if (compose->targetinfo) {
7457 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7458 flag.perm_flags = target_locked?MSG_LOCKED:0;
7460 flag.tmp_flags = MSG_DRAFT;
7462 folder_item_scan(draft);
7463 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7466 if (action != COMPOSE_AUTO_SAVE)
7467 alertpanel_error(_("Could not save draft."));
7471 draft->mtime = 0; /* force updating */
7473 if (compose->mode == COMPOSE_REEDIT) {
7474 compose_remove_reedit_target(compose, TRUE);
7477 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7479 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7481 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7483 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7484 if (compose_use_attach(compose))
7485 procmsg_msginfo_set_flags(newmsginfo, 0,
7486 MSG_HAS_ATTACHMENT);
7488 procmsg_msginfo_free(newmsginfo);
7491 folder_item_scan(draft);
7493 if (action == COMPOSE_QUIT_EDITING) {
7495 g_mutex_unlock(compose->mutex); /* must be done before closing */
7496 compose_close(compose);
7502 path = folder_item_fetch_msg(draft, msgnum);
7504 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7507 if (g_stat(path, &s) < 0) {
7508 FILE_OP_ERROR(path, "stat");
7514 procmsg_msginfo_free(compose->targetinfo);
7515 compose->targetinfo = procmsg_msginfo_new();
7516 compose->targetinfo->msgnum = msgnum;
7517 compose->targetinfo->size = s.st_size;
7518 compose->targetinfo->mtime = s.st_mtime;
7519 compose->targetinfo->folder = draft;
7521 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7522 compose->mode = COMPOSE_REEDIT;
7524 if (action == COMPOSE_AUTO_SAVE) {
7525 compose->autosaved_draft = compose->targetinfo;
7527 compose->modified = FALSE;
7528 compose_set_title(compose);
7532 g_mutex_unlock(compose->mutex);
7535 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7537 Compose *compose = (Compose *)data;
7540 if (compose->redirect_filename != NULL)
7543 file_list = filesel_select_multiple_files_open(_("Select file"));
7548 for ( tmp = file_list; tmp; tmp = tmp->next) {
7549 gchar *file = (gchar *) tmp->data;
7550 gchar *utf8_filename = conv_filename_to_utf8(file);
7551 compose_attach_append(compose, file, utf8_filename, NULL);
7552 compose_changed_cb(NULL, compose);
7554 g_free(utf8_filename);
7556 g_list_free(file_list);
7560 static void compose_insert_file_cb(gpointer data, guint action,
7563 Compose *compose = (Compose *)data;
7566 file_list = filesel_select_multiple_files_open(_("Select file"));
7571 for ( tmp = file_list; tmp; tmp = tmp->next) {
7572 gchar *file = (gchar *) tmp->data;
7573 gchar *filedup = g_strdup(file);
7574 gchar *shortfile = g_path_get_basename(filedup);
7575 ComposeInsertResult res;
7577 res = compose_insert_file(compose, file);
7578 if (res == COMPOSE_INSERT_READ_ERROR) {
7579 alertpanel_error(_("File '%s' could not be read."), shortfile);
7580 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7581 alertpanel_error(_("File '%s' contained invalid characters\n"
7582 "for the current encoding, insertion may be incorrect."), shortfile);
7588 g_list_free(file_list);
7592 static void compose_insert_sig_cb(gpointer data, guint action,
7595 Compose *compose = (Compose *)data;
7597 compose_insert_sig(compose, FALSE);
7600 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7604 Compose *compose = (Compose *)data;
7606 gtkut_widget_get_uposition(widget, &x, &y);
7607 prefs_common.compose_x = x;
7608 prefs_common.compose_y = y;
7610 if (compose->sending)
7612 compose_close_cb(compose, 0, NULL);
7616 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7618 Compose *compose = (Compose *)data;
7622 if (compose->exteditor_tag != -1) {
7623 if (!compose_ext_editor_kill(compose))
7628 if (compose->modified) {
7629 val = alertpanel(_("Discard message"),
7630 _("This message has been modified. Discard it?"),
7631 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7634 case G_ALERTDEFAULT:
7635 if (prefs_common.autosave)
7636 compose_remove_draft(compose);
7638 case G_ALERTALTERNATE:
7639 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7646 compose_close(compose);
7649 static void compose_set_encoding_cb(gpointer data, guint action,
7652 Compose *compose = (Compose *)data;
7654 if (GTK_CHECK_MENU_ITEM(widget)->active)
7655 compose->out_encoding = (CharSet)action;
7658 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7660 Compose *compose = (Compose *)data;
7662 addressbook_open(compose);
7665 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7667 Compose *compose = (Compose *)data;
7672 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7673 g_return_if_fail(tmpl != NULL);
7675 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7677 val = alertpanel(_("Apply template"), msg,
7678 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7681 if (val == G_ALERTDEFAULT)
7682 compose_template_apply(compose, tmpl, TRUE);
7683 else if (val == G_ALERTALTERNATE)
7684 compose_template_apply(compose, tmpl, FALSE);
7687 static void compose_ext_editor_cb(gpointer data, guint action,
7690 Compose *compose = (Compose *)data;
7692 compose_exec_ext_editor(compose);
7695 static void compose_undo_cb(Compose *compose)
7697 gboolean prev_autowrap = compose->autowrap;
7699 compose->autowrap = FALSE;
7700 undo_undo(compose->undostruct);
7701 compose->autowrap = prev_autowrap;
7704 static void compose_redo_cb(Compose *compose)
7706 gboolean prev_autowrap = compose->autowrap;
7708 compose->autowrap = FALSE;
7709 undo_redo(compose->undostruct);
7710 compose->autowrap = prev_autowrap;
7713 static void entry_cut_clipboard(GtkWidget *entry)
7715 if (GTK_IS_EDITABLE(entry))
7716 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7717 else if (GTK_IS_TEXT_VIEW(entry))
7718 gtk_text_buffer_cut_clipboard(
7719 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7720 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7724 static void entry_copy_clipboard(GtkWidget *entry)
7726 if (GTK_IS_EDITABLE(entry))
7727 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7728 else if (GTK_IS_TEXT_VIEW(entry))
7729 gtk_text_buffer_copy_clipboard(
7730 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7731 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7734 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7735 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
7737 if (GTK_IS_TEXT_VIEW(entry)) {
7738 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7739 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7740 GtkTextIter start_iter, end_iter;
7743 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7745 if (contents == NULL)
7748 /* we shouldn't delete the selection when middle-click-pasting, or we
7749 * can't mid-click-paste our own selection */
7750 if (clip != GDK_SELECTION_PRIMARY)
7751 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7753 if (insert_place == NULL) {
7754 /* if insert_place isn't specified, insert at the cursor.
7755 * used for Ctrl-V pasting */
7756 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7757 start = gtk_text_iter_get_offset(&start_iter);
7758 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7760 /* if insert_place is specified, paste here.
7761 * used for mid-click-pasting */
7762 start = gtk_text_iter_get_offset(insert_place);
7763 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
7767 /* paste unwrapped: mark the paste so it's not wrapped later */
7768 end = start + strlen(contents);
7769 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7770 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7771 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7772 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7773 /* rewrap paragraph now (after a mid-click-paste) */
7774 mark_start = gtk_text_buffer_get_insert(buffer);
7775 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7776 gtk_text_iter_backward_char(&start_iter);
7777 compose_beautify_paragraph(compose, &start_iter, TRUE);
7780 } else if (GTK_IS_EDITABLE(entry))
7781 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7785 static void entry_allsel(GtkWidget *entry)
7787 if (GTK_IS_EDITABLE(entry))
7788 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7789 else if (GTK_IS_TEXT_VIEW(entry)) {
7790 GtkTextIter startiter, enditer;
7791 GtkTextBuffer *textbuf;
7793 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7794 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7795 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7797 gtk_text_buffer_move_mark_by_name(textbuf,
7798 "selection_bound", &startiter);
7799 gtk_text_buffer_move_mark_by_name(textbuf,
7800 "insert", &enditer);
7804 static void compose_cut_cb(Compose *compose)
7806 if (compose->focused_editable &&
7807 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7808 entry_cut_clipboard(compose->focused_editable);
7811 static void compose_copy_cb(Compose *compose)
7813 if (compose->focused_editable &&
7814 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7815 entry_copy_clipboard(compose->focused_editable);
7818 static void compose_paste_cb(Compose *compose)
7821 GtkTextBuffer *buffer;
7823 if (compose->focused_editable &&
7824 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7825 entry_paste_clipboard(compose, compose->focused_editable,
7826 prefs_common.linewrap_pastes,
7827 GDK_SELECTION_CLIPBOARD, NULL);
7831 static void compose_paste_as_quote_cb(Compose *compose)
7833 gint wrap_quote = prefs_common.linewrap_quote;
7834 if (compose->focused_editable &&
7835 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7836 /* let text_insert() (called directly or at a later time
7837 * after the gtk_editable_paste_clipboard) know that
7838 * text is to be inserted as a quotation. implemented
7839 * by using a simple refcount... */
7840 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7841 G_OBJECT(compose->focused_editable),
7842 "paste_as_quotation"));
7843 g_object_set_data(G_OBJECT(compose->focused_editable),
7844 "paste_as_quotation",
7845 GINT_TO_POINTER(paste_as_quotation + 1));
7846 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7847 entry_paste_clipboard(compose, compose->focused_editable,
7848 prefs_common.linewrap_pastes,
7849 GDK_SELECTION_CLIPBOARD, NULL);
7850 prefs_common.linewrap_quote = wrap_quote;
7854 static void compose_paste_no_wrap_cb(Compose *compose)
7857 GtkTextBuffer *buffer;
7859 if (compose->focused_editable &&
7860 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7861 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7862 GDK_SELECTION_CLIPBOARD, NULL);
7866 static void compose_paste_wrap_cb(Compose *compose)
7869 GtkTextBuffer *buffer;
7871 if (compose->focused_editable &&
7872 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7873 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7874 GDK_SELECTION_CLIPBOARD, NULL);
7878 static void compose_allsel_cb(Compose *compose)
7880 if (compose->focused_editable &&
7881 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7882 entry_allsel(compose->focused_editable);
7885 static void textview_move_beginning_of_line (GtkTextView *text)
7887 GtkTextBuffer *buffer;
7891 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7893 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7894 mark = gtk_text_buffer_get_insert(buffer);
7895 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7896 gtk_text_iter_set_line_offset(&ins, 0);
7897 gtk_text_buffer_place_cursor(buffer, &ins);
7900 static void textview_move_forward_character (GtkTextView *text)
7902 GtkTextBuffer *buffer;
7906 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7908 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7909 mark = gtk_text_buffer_get_insert(buffer);
7910 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7911 if (gtk_text_iter_forward_cursor_position(&ins))
7912 gtk_text_buffer_place_cursor(buffer, &ins);
7915 static void textview_move_backward_character (GtkTextView *text)
7917 GtkTextBuffer *buffer;
7921 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7923 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7924 mark = gtk_text_buffer_get_insert(buffer);
7925 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7926 if (gtk_text_iter_backward_cursor_position(&ins))
7927 gtk_text_buffer_place_cursor(buffer, &ins);
7930 static void textview_move_forward_word (GtkTextView *text)
7932 GtkTextBuffer *buffer;
7937 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7939 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7940 mark = gtk_text_buffer_get_insert(buffer);
7941 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7942 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7943 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7944 gtk_text_iter_backward_word_start(&ins);
7945 gtk_text_buffer_place_cursor(buffer, &ins);
7949 static void textview_move_backward_word (GtkTextView *text)
7951 GtkTextBuffer *buffer;
7956 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7958 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7959 mark = gtk_text_buffer_get_insert(buffer);
7960 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7961 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7962 if (gtk_text_iter_backward_word_starts(&ins, 1))
7963 gtk_text_buffer_place_cursor(buffer, &ins);
7966 static void textview_move_end_of_line (GtkTextView *text)
7968 GtkTextBuffer *buffer;
7972 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7974 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7975 mark = gtk_text_buffer_get_insert(buffer);
7976 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7977 if (gtk_text_iter_forward_to_line_end(&ins))
7978 gtk_text_buffer_place_cursor(buffer, &ins);
7981 static void textview_move_next_line (GtkTextView *text)
7983 GtkTextBuffer *buffer;
7988 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7990 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7991 mark = gtk_text_buffer_get_insert(buffer);
7992 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7993 offset = gtk_text_iter_get_line_offset(&ins);
7994 if (gtk_text_iter_forward_line(&ins)) {
7995 gtk_text_iter_set_line_offset(&ins, offset);
7996 gtk_text_buffer_place_cursor(buffer, &ins);
8000 static void textview_move_previous_line (GtkTextView *text)
8002 GtkTextBuffer *buffer;
8007 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8009 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8010 mark = gtk_text_buffer_get_insert(buffer);
8011 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8012 offset = gtk_text_iter_get_line_offset(&ins);
8013 if (gtk_text_iter_backward_line(&ins)) {
8014 gtk_text_iter_set_line_offset(&ins, offset);
8015 gtk_text_buffer_place_cursor(buffer, &ins);
8019 static void textview_delete_forward_character (GtkTextView *text)
8021 GtkTextBuffer *buffer;
8023 GtkTextIter ins, end_iter;
8025 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8027 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8028 mark = gtk_text_buffer_get_insert(buffer);
8029 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8031 if (gtk_text_iter_forward_char(&end_iter)) {
8032 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8036 static void textview_delete_backward_character (GtkTextView *text)
8038 GtkTextBuffer *buffer;
8040 GtkTextIter ins, end_iter;
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);
8048 if (gtk_text_iter_backward_char(&end_iter)) {
8049 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8053 static void textview_delete_forward_word (GtkTextView *text)
8055 GtkTextBuffer *buffer;
8057 GtkTextIter ins, end_iter;
8059 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8061 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8062 mark = gtk_text_buffer_get_insert(buffer);
8063 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8065 if (gtk_text_iter_forward_word_end(&end_iter)) {
8066 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8070 static void textview_delete_backward_word (GtkTextView *text)
8072 GtkTextBuffer *buffer;
8074 GtkTextIter ins, end_iter;
8076 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8078 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8079 mark = gtk_text_buffer_get_insert(buffer);
8080 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8082 if (gtk_text_iter_backward_word_start(&end_iter)) {
8083 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8087 static void textview_delete_line (GtkTextView *text)
8089 GtkTextBuffer *buffer;
8091 GtkTextIter ins, start_iter, end_iter;
8094 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8096 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8097 mark = gtk_text_buffer_get_insert(buffer);
8098 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8101 gtk_text_iter_set_line_offset(&start_iter, 0);
8104 if (gtk_text_iter_ends_line(&end_iter))
8105 found = gtk_text_iter_forward_char(&end_iter);
8107 found = gtk_text_iter_forward_to_line_end(&end_iter);
8110 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8113 static void textview_delete_to_line_end (GtkTextView *text)
8115 GtkTextBuffer *buffer;
8117 GtkTextIter ins, end_iter;
8120 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8122 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8123 mark = gtk_text_buffer_get_insert(buffer);
8124 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8126 if (gtk_text_iter_ends_line(&end_iter))
8127 found = gtk_text_iter_forward_char(&end_iter);
8129 found = gtk_text_iter_forward_to_line_end(&end_iter);
8131 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8134 static void compose_advanced_action_cb(Compose *compose,
8135 ComposeCallAdvancedAction action)
8137 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8139 void (*do_action) (GtkTextView *text);
8140 } action_table[] = {
8141 {textview_move_beginning_of_line},
8142 {textview_move_forward_character},
8143 {textview_move_backward_character},
8144 {textview_move_forward_word},
8145 {textview_move_backward_word},
8146 {textview_move_end_of_line},
8147 {textview_move_next_line},
8148 {textview_move_previous_line},
8149 {textview_delete_forward_character},
8150 {textview_delete_backward_character},
8151 {textview_delete_forward_word},
8152 {textview_delete_backward_word},
8153 {textview_delete_line},
8154 {NULL}, /* gtk_stext_delete_line_n */
8155 {textview_delete_to_line_end}
8158 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8160 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8161 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8162 if (action_table[action].do_action)
8163 action_table[action].do_action(text);
8165 g_warning("Not implemented yet.");
8169 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8173 if (GTK_IS_EDITABLE(widget)) {
8174 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8175 gtk_editable_set_position(GTK_EDITABLE(widget),
8178 if (widget->parent && widget->parent->parent
8179 && widget->parent->parent->parent) {
8180 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8181 gint y = widget->allocation.y;
8182 gint height = widget->allocation.height;
8183 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8184 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8186 if (y < (int)shown->value) {
8187 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8189 if (y + height > (int)shown->value + (int)shown->page_size) {
8190 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8191 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8192 y + height - (int)shown->page_size - 1);
8194 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8195 (int)shown->upper - (int)shown->page_size - 1);
8202 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8203 compose->focused_editable = widget;
8206 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8208 compose->modified = TRUE;
8209 compose_set_title(compose);
8212 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8214 Compose *compose = (Compose *)data;
8217 compose_wrap_all_full(compose, TRUE);
8219 compose_beautify_paragraph(compose, NULL, TRUE);
8222 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8224 Compose *compose = (Compose *)data;
8226 message_search_compose(compose);
8229 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8232 Compose *compose = (Compose *)data;
8233 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8234 if (compose->autowrap)
8235 compose_wrap_all_full(compose, TRUE);
8236 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8239 static void compose_toggle_sign_cb(gpointer data, guint action,
8242 Compose *compose = (Compose *)data;
8244 if (GTK_CHECK_MENU_ITEM(widget)->active)
8245 compose->use_signing = TRUE;
8247 compose->use_signing = FALSE;
8250 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8253 Compose *compose = (Compose *)data;
8255 if (GTK_CHECK_MENU_ITEM(widget)->active)
8256 compose->use_encryption = TRUE;
8258 compose->use_encryption = FALSE;
8261 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8263 g_free(compose->privacy_system);
8265 compose->privacy_system = g_strdup(account->default_privacy_system);
8266 compose_update_privacy_system_menu_item(compose, warn);
8269 static void compose_toggle_ruler_cb(gpointer data, guint action,
8272 Compose *compose = (Compose *)data;
8274 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8275 gtk_widget_show(compose->ruler_hbox);
8276 prefs_common.show_ruler = TRUE;
8278 gtk_widget_hide(compose->ruler_hbox);
8279 gtk_widget_queue_resize(compose->edit_vbox);
8280 prefs_common.show_ruler = FALSE;
8284 static void compose_attach_drag_received_cb (GtkWidget *widget,
8285 GdkDragContext *context,
8288 GtkSelectionData *data,
8293 Compose *compose = (Compose *)user_data;
8296 if (gdk_atom_name(data->type) &&
8297 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8298 && gtk_drag_get_source_widget(context) !=
8299 mainwindow_get_mainwindow()->summaryview->ctree) {
8300 list = uri_list_extract_filenames((const gchar *)data->data);
8301 for (tmp = list; tmp != NULL; tmp = tmp->next)
8302 compose_attach_append
8303 (compose, (const gchar *)tmp->data,
8304 (const gchar *)tmp->data, NULL);
8305 if (list) compose_changed_cb(NULL, compose);
8306 list_free_strings(list);
8308 } else if (gtk_drag_get_source_widget(context)
8309 == mainwindow_get_mainwindow()->summaryview->ctree) {
8310 /* comes from our summaryview */
8311 SummaryView * summaryview = NULL;
8312 GSList * list = NULL, *cur = NULL;
8314 if (mainwindow_get_mainwindow())
8315 summaryview = mainwindow_get_mainwindow()->summaryview;
8318 list = summary_get_selected_msg_list(summaryview);
8320 for (cur = list; cur; cur = cur->next) {
8321 MsgInfo *msginfo = (MsgInfo *)cur->data;
8324 file = procmsg_get_message_file_full(msginfo,
8327 compose_attach_append(compose, (const gchar *)file,
8328 (const gchar *)file, "message/rfc822");
8336 static gboolean compose_drag_drop(GtkWidget *widget,
8337 GdkDragContext *drag_context,
8339 guint time, gpointer user_data)
8341 /* not handling this signal makes compose_insert_drag_received_cb
8346 static void compose_insert_drag_received_cb (GtkWidget *widget,
8347 GdkDragContext *drag_context,
8350 GtkSelectionData *data,
8355 Compose *compose = (Compose *)user_data;
8358 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8360 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8361 list = uri_list_extract_filenames((const gchar *)data->data);
8362 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8363 compose_insert_file(compose, (const gchar *)tmp->data);
8365 list_free_strings(list);
8367 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8370 #if GTK_CHECK_VERSION(2, 8, 0)
8371 /* do nothing, handled by GTK */
8373 gchar *tmpfile = get_tmp_file();
8374 str_write_to_file((const gchar *)data->data, tmpfile);
8375 compose_insert_file(compose, tmpfile);
8378 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8382 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8385 static void compose_header_drag_received_cb (GtkWidget *widget,
8386 GdkDragContext *drag_context,
8389 GtkSelectionData *data,
8394 GtkEditable *entry = (GtkEditable *)user_data;
8395 gchar *email = (gchar *)data->data;
8397 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8400 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8401 gchar *decoded=g_new(gchar, strlen(email));
8404 email += strlen("mailto:");
8405 decode_uri(decoded, email); /* will fit */
8406 gtk_editable_delete_text(entry, 0, -1);
8407 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8408 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8412 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8415 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8418 Compose *compose = (Compose *)data;
8420 if (GTK_CHECK_MENU_ITEM(widget)->active)
8421 compose->return_receipt = TRUE;
8423 compose->return_receipt = FALSE;
8426 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8429 Compose *compose = (Compose *)data;
8431 if (GTK_CHECK_MENU_ITEM(widget)->active)
8432 compose->remove_references = TRUE;
8434 compose->remove_references = FALSE;
8437 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8439 ComposeHeaderEntry *headerentry)
8441 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8442 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8443 !(event->state & GDK_MODIFIER_MASK) &&
8444 (event->keyval == GDK_BackSpace) &&
8445 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8446 gtk_container_remove
8447 (GTK_CONTAINER(headerentry->compose->header_table),
8448 headerentry->combo);
8449 gtk_container_remove
8450 (GTK_CONTAINER(headerentry->compose->header_table),
8451 headerentry->entry);
8452 headerentry->compose->header_list =
8453 g_slist_remove(headerentry->compose->header_list,
8455 g_free(headerentry);
8456 } else if (event->keyval == GDK_Tab) {
8457 if (headerentry->compose->header_last == headerentry) {
8458 /* Override default next focus, and give it to subject_entry
8459 * instead of notebook tabs
8461 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8462 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8469 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8470 ComposeHeaderEntry *headerentry)
8472 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8473 headerentry->compose->header_list =
8474 g_slist_append(headerentry->compose->header_list,
8477 compose_create_header_entry(headerentry->compose);
8478 g_signal_handlers_disconnect_matched
8479 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8480 0, 0, NULL, NULL, headerentry);
8482 /* Automatically scroll down */
8483 compose_show_first_last_header(headerentry->compose, FALSE);
8489 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8491 GtkAdjustment *vadj;
8493 g_return_if_fail(compose);
8494 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8495 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8497 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8498 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8501 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8502 const gchar *text, gint len, Compose *compose)
8504 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8505 (G_OBJECT(compose->text), "paste_as_quotation"));
8508 g_return_if_fail(text != NULL);
8510 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8511 G_CALLBACK(text_inserted),
8513 if (paste_as_quotation) {
8520 new_text = g_strndup(text, len);
8521 if (prefs_common.quotemark && *prefs_common.quotemark)
8522 qmark = prefs_common.quotemark;
8526 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8527 gtk_text_buffer_place_cursor(buffer, iter);
8529 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8531 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8532 GINT_TO_POINTER(paste_as_quotation - 1));
8534 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8535 gtk_text_buffer_place_cursor(buffer, iter);
8537 if (strcmp(text, "\n") || automatic_break
8538 || gtk_text_iter_starts_line(iter))
8539 gtk_text_buffer_insert(buffer, iter, text, len);
8541 debug_print("insert nowrap \\n\n");
8542 gtk_text_buffer_insert_with_tags_by_name(buffer,
8543 iter, text, len, "no_join", NULL);
8547 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8549 compose_beautify_paragraph(compose, iter, FALSE);
8551 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8552 gtk_text_buffer_delete_mark(buffer, mark);
8554 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8555 G_CALLBACK(text_inserted),
8557 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8559 if (prefs_common.autosave &&
8560 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8561 compose->draft_timeout_tag = gtk_timeout_add
8562 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8564 static gint compose_defer_auto_save_draft(Compose *compose)
8566 compose->draft_timeout_tag = -1;
8567 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8572 static void compose_check_all(Compose *compose)
8574 if (compose->gtkaspell)
8575 gtkaspell_check_all(compose->gtkaspell);
8578 static void compose_highlight_all(Compose *compose)
8580 if (compose->gtkaspell)
8581 gtkaspell_highlight_all(compose->gtkaspell);
8584 static void compose_check_backwards(Compose *compose)
8586 if (compose->gtkaspell)
8587 gtkaspell_check_backwards(compose->gtkaspell);
8589 GtkItemFactory *ifactory;
8590 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8591 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8592 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8596 static void compose_check_forwards_go(Compose *compose)
8598 if (compose->gtkaspell)
8599 gtkaspell_check_forwards_go(compose->gtkaspell);
8601 GtkItemFactory *ifactory;
8602 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8603 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8604 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8610 *\brief Guess originating forward account from MsgInfo and several
8611 * "common preference" settings. Return NULL if no guess.
8613 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8615 PrefsAccount *account = NULL;
8617 g_return_val_if_fail(msginfo, NULL);
8618 g_return_val_if_fail(msginfo->folder, NULL);
8619 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8621 if (msginfo->folder->prefs->enable_default_account)
8622 account = account_find_from_id(msginfo->folder->prefs->default_account);
8625 account = msginfo->folder->folder->account;
8627 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8629 Xstrdup_a(to, msginfo->to, return NULL);
8630 extract_address(to);
8631 account = account_find_from_address(to);
8634 if (!account && prefs_common.forward_account_autosel) {
8636 if (!procheader_get_header_from_msginfo
8637 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8638 extract_address(cc);
8639 account = account_find_from_address(cc);
8646 static gboolean compose_close(Compose *compose)
8650 if (!g_mutex_trylock(compose->mutex)) {
8651 /* we have to wait for the (possibly deferred by auto-save)
8652 * drafting to be done, before destroying the compose under
8654 debug_print("waiting for drafting to finish...\n");
8655 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8658 g_return_val_if_fail(compose, FALSE);
8659 gtkut_widget_get_uposition(compose->window, &x, &y);
8660 prefs_common.compose_x = x;
8661 prefs_common.compose_y = y;
8662 g_mutex_unlock(compose->mutex);
8663 compose_destroy(compose);
8668 * Add entry field for each address in list.
8669 * \param compose E-Mail composition object.
8670 * \param listAddress List of (formatted) E-Mail addresses.
8672 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8677 addr = ( gchar * ) node->data;
8678 compose_entry_append( compose, addr, COMPOSE_TO );
8679 node = g_list_next( node );
8683 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8687 GSList *new_msglist = NULL;
8688 MsgInfo *tmp_msginfo = NULL;
8689 gboolean originally_enc = FALSE;
8690 Compose *compose = NULL;
8692 g_return_if_fail(msgview != NULL);
8694 g_return_if_fail(msginfo_list != NULL);
8696 if (g_slist_length(msginfo_list) == 1) {
8697 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8698 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8700 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8701 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8702 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8703 orig_msginfo, mimeinfo);
8704 if (tmp_msginfo != NULL) {
8705 new_msglist = g_slist_append(NULL, tmp_msginfo);
8706 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8707 originally_enc = TRUE;
8713 body = messageview_get_selection(msgview);
8716 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8717 procmsg_msginfo_free(tmp_msginfo);
8718 g_slist_free(new_msglist);
8720 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8722 if (originally_enc) {
8723 compose_force_encryption(compose, compose->account, FALSE);
8729 void compose_set_position(Compose *compose, gint pos)
8731 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8733 gtkut_text_view_set_position(text, pos);
8736 gboolean compose_search_string(Compose *compose,
8737 const gchar *str, gboolean case_sens)
8739 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8741 return gtkut_text_view_search_string(text, str, case_sens);
8744 gboolean compose_search_string_backward(Compose *compose,
8745 const gchar *str, gboolean case_sens)
8747 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8749 return gtkut_text_view_search_string_backward(text, str, case_sens);