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"
123 #include "combobox.h"
135 #define N_ATTACH_COLS (N_COL_COLUMNS)
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
154 } ComposeCallAdvancedAction;
158 PRIORITY_HIGHEST = 1,
167 COMPOSE_INSERT_SUCCESS,
168 COMPOSE_INSERT_READ_ERROR,
169 COMPOSE_INSERT_INVALID_CHARACTER,
170 COMPOSE_INSERT_NO_FILE
171 } ComposeInsertResult;
175 COMPOSE_QUIT_EDITING,
176 COMPOSE_KEEP_EDITING,
178 } ComposeDraftAction;
182 COMPOSE_WRITE_FOR_SEND,
183 COMPOSE_WRITE_FOR_STORE
186 #define B64_LINE_SIZE 57
187 #define B64_BUFFSIZE 77
189 #define MAX_REFERENCES_LEN 999
191 static GList *compose_list = NULL;
193 Compose *compose_generic_new (PrefsAccount *account,
196 GPtrArray *attach_files,
197 GList *listAddress );
199 static Compose *compose_create (PrefsAccount *account,
203 static GtkWidget *compose_account_option_menu_create
205 static void compose_set_out_encoding (Compose *compose);
206 static void compose_set_template_menu (Compose *compose);
207 static void compose_template_apply (Compose *compose,
210 static void compose_destroy (Compose *compose);
212 static void compose_entries_set (Compose *compose,
213 const gchar *mailto);
214 static gint compose_parse_header (Compose *compose,
216 static gchar *compose_parse_references (const gchar *ref,
219 static gchar *compose_quote_fmt (Compose *compose,
226 static void compose_reply_set_entry (Compose *compose,
232 followup_and_reply_to);
233 static void compose_reedit_set_entry (Compose *compose,
236 static void compose_insert_sig (Compose *compose,
238 static gchar *compose_get_signature_str (Compose *compose);
239 static ComposeInsertResult compose_insert_file (Compose *compose,
242 static void compose_attach_append (Compose *compose,
245 const gchar *content_type);
246 static void compose_attach_parts (Compose *compose,
249 static void compose_beautify_paragraph (Compose *compose,
250 GtkTextIter *par_iter,
252 static void compose_wrap_all (Compose *compose);
253 static void compose_wrap_all_full (Compose *compose,
256 static void compose_set_title (Compose *compose);
257 static void compose_select_account (Compose *compose,
258 PrefsAccount *account,
261 static PrefsAccount *compose_current_mail_account(void);
262 /* static gint compose_send (Compose *compose); */
263 static gboolean compose_check_for_valid_recipient
265 static gboolean compose_check_entries (Compose *compose,
266 gboolean check_subject);
267 static gint compose_write_to_file (Compose *compose,
270 gboolean attach_parts);
271 static gint compose_write_body_to_file (Compose *compose,
273 static gint compose_remove_reedit_target (Compose *compose,
275 void compose_remove_draft (Compose *compose);
276 static gint compose_queue_sub (Compose *compose,
280 gboolean check_subject,
281 gboolean remove_reedit_target);
282 static void compose_add_attachments (Compose *compose,
284 static gchar *compose_get_header (Compose *compose);
286 static void compose_convert_header (Compose *compose,
291 gboolean addr_field);
293 static void compose_attach_info_free (AttachInfo *ainfo);
294 static void compose_attach_remove_selected (Compose *compose);
296 static void compose_attach_property (Compose *compose);
297 static void compose_attach_property_create (gboolean *cancelled);
298 static void attach_property_ok (GtkWidget *widget,
299 gboolean *cancelled);
300 static void attach_property_cancel (GtkWidget *widget,
301 gboolean *cancelled);
302 static gint attach_property_delete_event (GtkWidget *widget,
304 gboolean *cancelled);
305 static gboolean attach_property_key_pressed (GtkWidget *widget,
307 gboolean *cancelled);
309 static void compose_exec_ext_editor (Compose *compose);
311 static gint compose_exec_ext_editor_real (const gchar *file);
312 static gboolean compose_ext_editor_kill (Compose *compose);
313 static gboolean compose_input_cb (GIOChannel *source,
314 GIOCondition condition,
316 static void compose_set_ext_editor_sensitive (Compose *compose,
318 #endif /* G_OS_UNIX */
320 static void compose_undo_state_changed (UndoMain *undostruct,
325 static void compose_create_header_entry (Compose *compose);
326 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
327 static void compose_update_priority_menu_item(Compose * compose);
329 static void compose_add_field_list ( Compose *compose,
330 GList *listAddress );
332 /* callback functions */
334 static gboolean compose_edit_size_alloc (GtkEditable *widget,
335 GtkAllocation *allocation,
336 GtkSHRuler *shruler);
337 static void account_activated (GtkComboBox *optmenu,
339 static void attach_selected (GtkTreeView *tree_view,
340 GtkTreePath *tree_path,
341 GtkTreeViewColumn *column,
343 static gboolean attach_button_pressed (GtkWidget *widget,
344 GdkEventButton *event,
346 static gboolean attach_key_pressed (GtkWidget *widget,
350 static void compose_send_cb (gpointer data,
353 static void compose_send_later_cb (gpointer data,
357 static void compose_draft_cb (gpointer data,
361 static void compose_attach_cb (gpointer data,
364 static void compose_insert_file_cb (gpointer data,
367 static void compose_insert_sig_cb (gpointer data,
371 static void compose_close_cb (gpointer data,
375 static void compose_set_encoding_cb (gpointer data,
379 static void compose_address_cb (gpointer data,
382 static void compose_template_activate_cb(GtkWidget *widget,
385 static void compose_ext_editor_cb (gpointer data,
389 static gint compose_delete_cb (GtkWidget *widget,
393 static void compose_undo_cb (Compose *compose);
394 static void compose_redo_cb (Compose *compose);
395 static void compose_cut_cb (Compose *compose);
396 static void compose_copy_cb (Compose *compose);
397 static void compose_paste_cb (Compose *compose);
398 static void compose_paste_as_quote_cb (Compose *compose);
399 static void compose_paste_no_wrap_cb (Compose *compose);
400 static void compose_paste_wrap_cb (Compose *compose);
401 static void compose_allsel_cb (Compose *compose);
403 static void compose_advanced_action_cb (Compose *compose,
404 ComposeCallAdvancedAction action);
406 static void compose_grab_focus_cb (GtkWidget *widget,
409 static void compose_changed_cb (GtkTextBuffer *textbuf,
412 static void compose_wrap_cb (gpointer data,
415 static void compose_find_cb (gpointer data,
418 static void compose_toggle_autowrap_cb (gpointer data,
422 static void compose_toggle_ruler_cb (gpointer data,
425 static void compose_toggle_sign_cb (gpointer data,
428 static void compose_toggle_encrypt_cb (gpointer data,
431 static void compose_set_privacy_system_cb(GtkWidget *widget,
433 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
434 static void activate_privacy_system (Compose *compose,
435 PrefsAccount *account,
437 static void compose_use_signing(Compose *compose, gboolean use_signing);
438 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
439 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
441 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
443 static void compose_set_priority_cb (gpointer data,
447 static void compose_attach_drag_received_cb (GtkWidget *widget,
448 GdkDragContext *drag_context,
451 GtkSelectionData *data,
455 static void compose_insert_drag_received_cb (GtkWidget *widget,
456 GdkDragContext *drag_context,
459 GtkSelectionData *data,
463 static void compose_header_drag_received_cb (GtkWidget *widget,
464 GdkDragContext *drag_context,
467 GtkSelectionData *data,
472 static gboolean compose_drag_drop (GtkWidget *widget,
473 GdkDragContext *drag_context,
475 guint time, gpointer user_data);
477 static void text_inserted (GtkTextBuffer *buffer,
482 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
483 gboolean to_all, gboolean to_ml,
485 gboolean followup_and_reply_to,
488 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
489 ComposeHeaderEntry *headerentry);
490 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
492 ComposeHeaderEntry *headerentry);
494 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
496 static void compose_allow_user_actions (Compose *compose, gboolean allow);
499 static void compose_check_all (Compose *compose);
500 static void compose_highlight_all (Compose *compose);
501 static void compose_check_backwards (Compose *compose);
502 static void compose_check_forwards_go (Compose *compose);
505 static gint compose_defer_auto_save_draft (Compose *compose);
506 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
508 static GtkItemFactoryEntry compose_popup_entries[] =
510 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
511 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
512 {N_("/---"), NULL, NULL, 0, "<Separator>"},
513 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
516 static GtkItemFactoryEntry compose_entries[] =
518 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
519 {N_("/_Message/_Send"), "<control>Return",
520 compose_send_cb, 0, NULL},
521 {N_("/_Message/Send _later"), "<shift><control>S",
522 compose_send_later_cb, 0, NULL},
523 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
524 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
525 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
526 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
527 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
528 {N_("/_Message/_Save"),
529 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
533 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
534 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
535 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
536 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
537 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
538 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
539 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
540 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/Special paste/as _quotation"),
542 NULL, compose_paste_as_quote_cb, 0, NULL},
543 {N_("/_Edit/Special paste/_wrapped"),
544 NULL, compose_paste_wrap_cb, 0, NULL},
545 {N_("/_Edit/Special paste/_unwrapped"),
546 NULL, compose_paste_no_wrap_cb, 0, NULL},
547 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
548 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
549 {N_("/_Edit/A_dvanced/Move a character backward"),
551 compose_advanced_action_cb,
552 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
554 {N_("/_Edit/A_dvanced/Move a character forward"),
556 compose_advanced_action_cb,
557 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
559 {N_("/_Edit/A_dvanced/Move a word backward"),
561 compose_advanced_action_cb,
562 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
564 {N_("/_Edit/A_dvanced/Move a word forward"),
566 compose_advanced_action_cb,
567 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
569 {N_("/_Edit/A_dvanced/Move to beginning of line"),
570 NULL, /* "<control>A" */
571 compose_advanced_action_cb,
572 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
574 {N_("/_Edit/A_dvanced/Move to end of line"),
576 compose_advanced_action_cb,
577 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
579 {N_("/_Edit/A_dvanced/Move to previous line"),
581 compose_advanced_action_cb,
582 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
584 {N_("/_Edit/A_dvanced/Move to next line"),
586 compose_advanced_action_cb,
587 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
589 {N_("/_Edit/A_dvanced/Delete a character backward"),
591 compose_advanced_action_cb,
592 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
594 {N_("/_Edit/A_dvanced/Delete a character forward"),
596 compose_advanced_action_cb,
597 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
599 {N_("/_Edit/A_dvanced/Delete a word backward"),
600 NULL, /* "<control>W" */
601 compose_advanced_action_cb,
602 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
604 {N_("/_Edit/A_dvanced/Delete a word forward"),
605 NULL, /* "<alt>D", */
606 compose_advanced_action_cb,
607 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
609 {N_("/_Edit/A_dvanced/Delete line"),
611 compose_advanced_action_cb,
612 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
614 {N_("/_Edit/A_dvanced/Delete entire line"),
616 compose_advanced_action_cb,
617 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
619 {N_("/_Edit/A_dvanced/Delete to end of line"),
621 compose_advanced_action_cb,
622 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
624 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
626 "<control>F", compose_find_cb, 0, NULL},
627 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
628 {N_("/_Edit/_Wrap current paragraph"),
629 "<control>L", compose_wrap_cb, 0, NULL},
630 {N_("/_Edit/Wrap all long _lines"),
631 "<control><alt>L", compose_wrap_cb, 1, NULL},
632 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
633 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
634 {N_("/_Edit/Edit with e_xternal editor"),
635 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
637 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Spelling/_Check all or check selection"),
639 NULL, compose_check_all, 0, NULL},
640 {N_("/_Spelling/_Highlight all misspelled words"),
641 NULL, compose_highlight_all, 0, NULL},
642 {N_("/_Spelling/Check _backwards misspelled word"),
643 NULL, compose_check_backwards , 0, NULL},
644 {N_("/_Spelling/_Forward to next misspelled word"),
645 NULL, compose_check_forwards_go, 0, NULL},
646 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
647 {N_("/_Spelling/Options"),
648 NULL, NULL, 0, "<Branch>"},
650 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
651 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
652 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
653 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
654 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
655 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
656 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
657 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
658 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
660 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
661 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
662 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
664 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
665 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
666 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
668 #define ENC_ACTION(action) \
669 NULL, compose_set_encoding_cb, action, \
670 "/Options/Character encoding/Automatic"
672 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
673 {N_("/_Options/Character _encoding/_Automatic"),
674 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
675 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
677 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
678 ENC_ACTION(C_US_ASCII)},
679 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
680 ENC_ACTION(C_UTF_8)},
681 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
683 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
684 ENC_ACTION(C_ISO_8859_1)},
685 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
686 ENC_ACTION(C_ISO_8859_15)},
687 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
688 ENC_ACTION(C_WINDOWS_1252)},
689 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
691 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
692 ENC_ACTION(C_ISO_8859_2)},
693 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
695 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
696 ENC_ACTION(C_ISO_8859_13)},
697 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
698 ENC_ACTION(C_ISO_8859_4)},
699 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
701 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
702 ENC_ACTION(C_ISO_8859_7)},
703 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
705 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
706 ENC_ACTION(C_ISO_8859_8)},
707 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
708 ENC_ACTION(C_WINDOWS_1255)},
709 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
711 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
712 ENC_ACTION(C_ISO_8859_6)},
713 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
714 ENC_ACTION(C_CP1256)},
715 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
717 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
718 ENC_ACTION(C_ISO_8859_9)},
719 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
721 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
722 ENC_ACTION(C_ISO_8859_5)},
723 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
724 ENC_ACTION(C_KOI8_R)},
725 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
726 ENC_ACTION(C_KOI8_U)},
727 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
728 ENC_ACTION(C_WINDOWS_1251)},
729 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
731 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
732 ENC_ACTION(C_ISO_2022_JP)},
733 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
735 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
736 ENC_ACTION(C_GB2312)},
737 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
739 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
741 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
742 ENC_ACTION(C_EUC_TW)},
743 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
745 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
746 ENC_ACTION(C_EUC_KR)},
747 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
749 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
750 ENC_ACTION(C_TIS_620)},
751 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
752 ENC_ACTION(C_WINDOWS_874)},
754 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
755 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
756 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
757 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
759 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
760 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
763 static GtkTargetEntry compose_mime_types[] =
765 {"text/uri-list", 0, 0},
766 {"text/plain", 0, 0},
770 static gboolean compose_put_existing_to_front(MsgInfo *info)
772 GList *compose_list = compose_get_compose_list();
776 for (elem = compose_list; elem != NULL && elem->data != NULL;
778 Compose *c = (Compose*)elem->data;
780 if (!c->targetinfo || !c->targetinfo->msgid ||
784 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
785 gtkut_window_popup(c->window);
793 static GdkColor quote_color1 =
794 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
795 static GdkColor quote_color2 =
796 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
797 static GdkColor quote_color3 =
798 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
800 static GdkColor quote_bgcolor1 =
801 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
802 static GdkColor quote_bgcolor2 =
803 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
804 static GdkColor quote_bgcolor3 =
805 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
807 static GdkColor signature_color = {
814 static GdkColor uri_color = {
821 static void compose_create_tags(GtkTextView *text, Compose *compose)
823 GtkTextBuffer *buffer;
824 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
830 buffer = gtk_text_view_get_buffer(text);
832 if (prefs_common.enable_color) {
833 /* grab the quote colors, converting from an int to a GdkColor */
834 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
836 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
838 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
840 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
842 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
844 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
846 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
848 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
851 signature_color = quote_color1 = quote_color2 = quote_color3 =
852 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
855 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
856 gtk_text_buffer_create_tag(buffer, "quote0",
857 "foreground-gdk", "e_color1,
858 "paragraph-background-gdk", "e_bgcolor1,
860 gtk_text_buffer_create_tag(buffer, "quote1",
861 "foreground-gdk", "e_color2,
862 "paragraph-background-gdk", "e_bgcolor2,
864 gtk_text_buffer_create_tag(buffer, "quote2",
865 "foreground-gdk", "e_color3,
866 "paragraph-background-gdk", "e_bgcolor3,
869 gtk_text_buffer_create_tag(buffer, "quote0",
870 "foreground-gdk", "e_color1,
872 gtk_text_buffer_create_tag(buffer, "quote1",
873 "foreground-gdk", "e_color2,
875 gtk_text_buffer_create_tag(buffer, "quote2",
876 "foreground-gdk", "e_color3,
880 gtk_text_buffer_create_tag(buffer, "signature",
881 "foreground-gdk", &signature_color,
883 gtk_text_buffer_create_tag(buffer, "link",
884 "foreground-gdk", &uri_color,
886 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
887 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
889 color[0] = quote_color1;
890 color[1] = quote_color2;
891 color[2] = quote_color3;
892 color[3] = quote_bgcolor1;
893 color[4] = quote_bgcolor2;
894 color[5] = quote_bgcolor3;
895 color[6] = signature_color;
896 color[7] = uri_color;
897 cmap = gdk_drawable_get_colormap(compose->window->window);
898 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
900 for (i = 0; i < 8; i++) {
901 if (success[i] == FALSE) {
904 g_warning("Compose: color allocation failed.\n");
905 style = gtk_widget_get_style(GTK_WIDGET(text));
906 quote_color1 = quote_color2 = quote_color3 =
907 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
908 signature_color = uri_color = black;
913 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
914 GPtrArray *attach_files)
916 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
919 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
921 return compose_generic_new(account, NULL, item, NULL, NULL);
924 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
926 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
929 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
930 GPtrArray *attach_files, GList *listAddress )
933 GtkTextView *textview;
934 GtkTextBuffer *textbuf;
936 GtkItemFactory *ifactory;
938 if (item && item->prefs && item->prefs->enable_default_account)
939 account = account_find_from_id(item->prefs->default_account);
941 if (!account) account = cur_account;
942 g_return_val_if_fail(account != NULL, NULL);
944 compose = compose_create(account, COMPOSE_NEW, FALSE);
946 ifactory = gtk_item_factory_from_widget(compose->menubar);
948 compose->replyinfo = NULL;
949 compose->fwdinfo = NULL;
951 textview = GTK_TEXT_VIEW(compose->text);
952 textbuf = gtk_text_view_get_buffer(textview);
953 compose_create_tags(textview, compose);
955 undo_block(compose->undostruct);
957 if (item && item->prefs && item->prefs->enable_default_dictionary &&
959 gtkaspell_change_dict(compose->gtkaspell,
960 item->prefs->default_dictionary);
963 if (account->auto_sig)
964 compose_insert_sig(compose, FALSE);
965 gtk_text_buffer_get_start_iter(textbuf, &iter);
966 gtk_text_buffer_place_cursor(textbuf, &iter);
968 if (account->protocol != A_NNTP) {
969 if (mailto && *mailto != '\0') {
970 compose_entries_set(compose, mailto);
972 } else if (item && item->prefs->enable_default_to) {
973 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
974 compose_entry_mark_default_to(compose, item->prefs->default_to);
976 if (item && item->ret_rcpt) {
977 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
981 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
983 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
986 * CLAWS: just don't allow return receipt request, even if the user
987 * may want to send an email. simple but foolproof.
989 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
991 compose_add_field_list( compose, listAddress );
997 for (i = 0; i < attach_files->len; i++) {
998 file = g_ptr_array_index(attach_files, i);
999 compose_attach_append(compose, file, file, NULL);
1003 compose_show_first_last_header(compose, TRUE);
1005 /* Set save folder */
1006 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1007 gchar *folderidentifier;
1009 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1010 folderidentifier = folder_item_get_identifier(item);
1011 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1012 g_free(folderidentifier);
1015 gtk_widget_grab_focus(compose->header_last->entry);
1017 undo_unblock(compose->undostruct);
1019 if (prefs_common.auto_exteditor)
1020 compose_exec_ext_editor(compose);
1022 compose->modified = FALSE;
1023 compose_set_title(compose);
1027 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1028 gboolean override_pref)
1030 gchar *privacy = NULL;
1032 g_return_if_fail(compose != NULL);
1033 g_return_if_fail(account != NULL);
1035 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1038 if (account->default_privacy_system
1039 && strlen(account->default_privacy_system)) {
1040 privacy = account->default_privacy_system;
1042 GSList *privacy_avail = privacy_get_system_ids();
1043 if (privacy_avail && g_slist_length(privacy_avail)) {
1044 privacy = (gchar *)(privacy_avail->data);
1047 if (privacy != NULL) {
1048 compose->privacy_system = g_strdup(privacy);
1049 compose_update_privacy_system_menu_item(compose, FALSE);
1050 compose_use_encryption(compose, TRUE);
1054 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1056 gchar *privacy = NULL;
1058 if (account->default_privacy_system
1059 && strlen(account->default_privacy_system)) {
1060 privacy = account->default_privacy_system;
1062 GSList *privacy_avail = privacy_get_system_ids();
1063 if (privacy_avail && g_slist_length(privacy_avail)) {
1064 privacy = (gchar *)(privacy_avail->data);
1067 if (privacy != NULL) {
1068 compose->privacy_system = g_strdup(privacy);
1069 compose_update_privacy_system_menu_item(compose, FALSE);
1070 compose_use_signing(compose, TRUE);
1074 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1078 Compose *compose = NULL;
1079 g_return_val_if_fail(msginfo_list != NULL, NULL);
1081 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1082 g_return_val_if_fail(msginfo != NULL, NULL);
1084 list_len = g_slist_length(msginfo_list);
1088 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1089 FALSE, prefs_common.default_reply_list, FALSE, body);
1091 case COMPOSE_REPLY_WITH_QUOTE:
1092 compose = compose_reply(msginfo, TRUE,
1093 FALSE, prefs_common.default_reply_list, FALSE, body);
1095 case COMPOSE_REPLY_WITHOUT_QUOTE:
1096 compose = compose_reply(msginfo, FALSE,
1097 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1099 case COMPOSE_REPLY_TO_SENDER:
1100 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1101 FALSE, FALSE, TRUE, body);
1103 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1104 compose = compose_followup_and_reply_to(msginfo,
1105 prefs_common.reply_with_quote,
1106 FALSE, FALSE, body);
1108 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1109 compose = compose_reply(msginfo, TRUE,
1110 FALSE, FALSE, TRUE, body);
1112 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1113 compose = compose_reply(msginfo, FALSE,
1114 FALSE, FALSE, TRUE, NULL);
1116 case COMPOSE_REPLY_TO_ALL:
1117 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1118 TRUE, FALSE, FALSE, body);
1120 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1121 compose = compose_reply(msginfo, TRUE,
1122 TRUE, FALSE, FALSE, body);
1124 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1125 compose = compose_reply(msginfo, FALSE,
1126 TRUE, FALSE, FALSE, NULL);
1128 case COMPOSE_REPLY_TO_LIST:
1129 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1130 FALSE, TRUE, FALSE, body);
1132 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1133 compose = compose_reply(msginfo, TRUE,
1134 FALSE, TRUE, FALSE, body);
1136 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1137 compose = compose_reply(msginfo, FALSE,
1138 FALSE, TRUE, FALSE, NULL);
1140 case COMPOSE_FORWARD:
1141 if (prefs_common.forward_as_attachment) {
1142 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1145 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1149 case COMPOSE_FORWARD_INLINE:
1150 /* check if we reply to more than one Message */
1151 if (list_len == 1) {
1152 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1155 /* more messages FALL THROUGH */
1156 case COMPOSE_FORWARD_AS_ATTACH:
1157 compose = compose_forward_multiple(NULL, msginfo_list);
1159 case COMPOSE_REDIRECT:
1160 compose = compose_redirect(NULL, msginfo, FALSE);
1163 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1168 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1169 gboolean to_ml, gboolean to_sender,
1172 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1173 to_sender, FALSE, body);
1176 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1181 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1182 to_sender, TRUE, body);
1185 static void compose_extract_original_charset(Compose *compose)
1187 MsgInfo *info = NULL;
1188 if (compose->replyinfo) {
1189 info = compose->replyinfo;
1190 } else if (compose->fwdinfo) {
1191 info = compose->fwdinfo;
1192 } else if (compose->targetinfo) {
1193 info = compose->targetinfo;
1196 MimeInfo *mimeinfo = procmime_scan_message(info);
1197 MimeInfo *partinfo = mimeinfo;
1198 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1199 partinfo = procmime_mimeinfo_next(partinfo);
1201 compose->orig_charset =
1202 g_strdup(procmime_mimeinfo_get_parameter(
1203 partinfo, "charset"));
1205 procmime_mimeinfo_free_all(mimeinfo);
1209 #define SIGNAL_BLOCK(buffer) { \
1210 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1211 G_CALLBACK(compose_changed_cb), \
1213 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1214 G_CALLBACK(text_inserted), \
1218 #define SIGNAL_UNBLOCK(buffer) { \
1219 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1220 G_CALLBACK(compose_changed_cb), \
1222 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1223 G_CALLBACK(text_inserted), \
1227 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1228 gboolean to_all, gboolean to_ml,
1230 gboolean followup_and_reply_to,
1233 GtkItemFactory *ifactory;
1235 PrefsAccount *account = NULL;
1236 PrefsAccount *reply_account;
1237 GtkTextView *textview;
1238 GtkTextBuffer *textbuf;
1240 g_return_val_if_fail(msginfo != NULL, NULL);
1241 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1243 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1245 g_return_val_if_fail(account != NULL, NULL);
1247 if (to_sender && account->protocol == A_NNTP &&
1248 !followup_and_reply_to) {
1250 account_find_from_address(account->address);
1252 reply_account = compose_current_mail_account();
1256 reply_account = account;
1258 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1260 compose->updating = TRUE;
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->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1268 if (!compose->replyinfo)
1269 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1271 compose_extract_original_charset(compose);
1273 if (msginfo->folder && msginfo->folder->ret_rcpt)
1274 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1276 /* Set save folder */
1277 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1278 gchar *folderidentifier;
1280 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1281 folderidentifier = folder_item_get_identifier(msginfo->folder);
1282 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1283 g_free(folderidentifier);
1286 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1287 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1288 to_sender, followup_and_reply_to);
1289 compose_show_first_last_header(compose, TRUE);
1291 textview = (GTK_TEXT_VIEW(compose->text));
1292 textbuf = gtk_text_view_get_buffer(textview);
1293 compose_create_tags(textview, compose);
1295 undo_block(compose->undostruct);
1297 if (msginfo->folder && msginfo->folder->prefs &&
1298 msginfo->folder->prefs &&
1299 msginfo->folder->prefs->enable_default_dictionary &&
1301 gtkaspell_change_dict(compose->gtkaspell,
1302 msginfo->folder->prefs->default_dictionary);
1308 if (prefs_common.quotemark && *prefs_common.quotemark)
1309 qmark = prefs_common.quotemark;
1313 compose_quote_fmt(compose, compose->replyinfo,
1314 prefs_common.quotefmt,
1315 qmark, body, FALSE);
1317 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1318 compose_force_encryption(compose, account, FALSE);
1321 SIGNAL_BLOCK(textbuf);
1323 if (account->auto_sig)
1324 compose_insert_sig(compose, FALSE);
1326 compose_wrap_all(compose);
1328 SIGNAL_UNBLOCK(textbuf);
1330 gtk_widget_grab_focus(compose->text);
1332 undo_unblock(compose->undostruct);
1334 if (prefs_common.auto_exteditor)
1335 compose_exec_ext_editor(compose);
1337 compose->modified = FALSE;
1338 compose_set_title(compose);
1340 compose->updating = FALSE;
1342 if (compose->deferred_destroy) {
1343 compose_destroy(compose);
1350 #define INSERT_FW_HEADER(var, hdr) \
1351 if (msginfo->var && *msginfo->var) { \
1352 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1353 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1354 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1357 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1358 gboolean as_attach, const gchar *body,
1359 gboolean no_extedit,
1363 GtkTextView *textview;
1364 GtkTextBuffer *textbuf;
1367 g_return_val_if_fail(msginfo != NULL, NULL);
1368 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1371 !(account = compose_guess_forward_account_from_msginfo
1373 account = cur_account;
1375 compose = compose_create(account, COMPOSE_FORWARD, batch);
1377 compose->updating = TRUE;
1378 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1379 if (!compose->fwdinfo)
1380 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1382 compose_extract_original_charset(compose);
1384 if (msginfo->subject && *msginfo->subject) {
1385 gchar *buf, *buf2, *p;
1387 buf = p = g_strdup(msginfo->subject);
1388 p += subject_get_prefix_length(p);
1389 memmove(buf, p, strlen(p) + 1);
1391 buf2 = g_strdup_printf("Fw: %s", buf);
1392 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1398 textview = GTK_TEXT_VIEW(compose->text);
1399 textbuf = gtk_text_view_get_buffer(textview);
1400 compose_create_tags(textview, compose);
1402 undo_block(compose->undostruct);
1406 msgfile = procmsg_get_message_file_path(msginfo);
1407 if (!is_file_exist(msgfile))
1408 g_warning("%s: file not exist\n", msgfile);
1410 compose_attach_append(compose, msgfile, msgfile,
1416 MsgInfo *full_msginfo;
1418 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1420 full_msginfo = procmsg_msginfo_copy(msginfo);
1422 if (prefs_common.fw_quotemark &&
1423 *prefs_common.fw_quotemark)
1424 qmark = prefs_common.fw_quotemark;
1428 compose_quote_fmt(compose, full_msginfo,
1429 prefs_common.fw_quotefmt,
1430 qmark, body, FALSE);
1431 compose_attach_parts(compose, msginfo);
1433 procmsg_msginfo_free(full_msginfo);
1436 SIGNAL_BLOCK(textbuf);
1438 if (account->auto_sig)
1439 compose_insert_sig(compose, FALSE);
1441 compose_wrap_all(compose);
1443 SIGNAL_UNBLOCK(textbuf);
1445 gtk_text_buffer_get_start_iter(textbuf, &iter);
1446 gtk_text_buffer_place_cursor(textbuf, &iter);
1448 gtk_widget_grab_focus(compose->header_last->entry);
1450 if (!no_extedit && prefs_common.auto_exteditor)
1451 compose_exec_ext_editor(compose);
1454 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1455 gchar *folderidentifier;
1457 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1458 folderidentifier = folder_item_get_identifier(msginfo->folder);
1459 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1460 g_free(folderidentifier);
1463 undo_unblock(compose->undostruct);
1465 compose->modified = FALSE;
1466 compose_set_title(compose);
1468 compose->updating = FALSE;
1470 if (compose->deferred_destroy) {
1471 compose_destroy(compose);
1478 #undef INSERT_FW_HEADER
1480 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1483 GtkTextView *textview;
1484 GtkTextBuffer *textbuf;
1488 gboolean single_mail = TRUE;
1490 g_return_val_if_fail(msginfo_list != NULL, NULL);
1492 if (g_slist_length(msginfo_list) > 1)
1493 single_mail = FALSE;
1495 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1496 if (((MsgInfo *)msginfo->data)->folder == NULL)
1499 /* guess account from first selected message */
1501 !(account = compose_guess_forward_account_from_msginfo
1502 (msginfo_list->data)))
1503 account = cur_account;
1505 g_return_val_if_fail(account != NULL, NULL);
1507 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1508 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1509 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1512 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1514 compose->updating = TRUE;
1516 textview = GTK_TEXT_VIEW(compose->text);
1517 textbuf = gtk_text_view_get_buffer(textview);
1518 compose_create_tags(textview, compose);
1520 undo_block(compose->undostruct);
1521 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1522 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1524 if (!is_file_exist(msgfile))
1525 g_warning("%s: file not exist\n", msgfile);
1527 compose_attach_append(compose, msgfile, msgfile,
1533 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1534 if (info->subject && *info->subject) {
1535 gchar *buf, *buf2, *p;
1537 buf = p = g_strdup(info->subject);
1538 p += subject_get_prefix_length(p);
1539 memmove(buf, p, strlen(p) + 1);
1541 buf2 = g_strdup_printf("Fw: %s", buf);
1542 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1548 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1549 _("Fw: multiple emails"));
1552 SIGNAL_BLOCK(textbuf);
1554 if (account->auto_sig)
1555 compose_insert_sig(compose, FALSE);
1557 compose_wrap_all(compose);
1559 SIGNAL_UNBLOCK(textbuf);
1561 gtk_text_buffer_get_start_iter(textbuf, &iter);
1562 gtk_text_buffer_place_cursor(textbuf, &iter);
1564 gtk_widget_grab_focus(compose->header_last->entry);
1565 undo_unblock(compose->undostruct);
1566 compose->modified = FALSE;
1567 compose_set_title(compose);
1569 compose->updating = FALSE;
1571 if (compose->deferred_destroy) {
1572 compose_destroy(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 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
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_val_if_fail(msginfo != NULL, NULL);
1641 g_return_val_if_fail(msginfo->folder != NULL, 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_val_if_fail(account != NULL, NULL);
1708 compose = compose_create(account, COMPOSE_REEDIT, batch);
1710 compose->updating = TRUE;
1712 if (privacy_system != NULL) {
1713 compose->privacy_system = privacy_system;
1714 compose_use_signing(compose, use_signing);
1715 compose_use_encryption(compose, use_encryption);
1716 compose_update_privacy_system_menu_item(compose, FALSE);
1718 activate_privacy_system(compose, account, FALSE);
1721 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1723 compose_extract_original_charset(compose);
1725 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1726 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1727 gchar queueheader_buf[BUFFSIZE];
1729 /* Set message save folder */
1730 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1733 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1734 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1735 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1737 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1738 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1740 GtkItemFactory *ifactory;
1741 ifactory = gtk_item_factory_from_widget(compose->menubar);
1742 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1747 if (compose_parse_header(compose, msginfo) < 0) {
1748 compose->updating = FALSE;
1749 compose_destroy(compose);
1752 compose_reedit_set_entry(compose, msginfo);
1754 textview = GTK_TEXT_VIEW(compose->text);
1755 textbuf = gtk_text_view_get_buffer(textview);
1756 compose_create_tags(textview, compose);
1758 mark = gtk_text_buffer_get_insert(textbuf);
1759 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1761 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1762 G_CALLBACK(compose_changed_cb),
1765 if (procmime_msginfo_is_encrypted(msginfo)) {
1766 fp = procmime_get_first_encrypted_text_content(msginfo);
1768 compose_force_encryption(compose, account, TRUE);
1771 fp = procmime_get_first_text_content(msginfo);
1774 g_warning("Can't get text part\n");
1778 gboolean prev_autowrap = compose->autowrap;
1780 compose->autowrap = FALSE;
1781 while (fgets(buf, sizeof(buf), fp) != NULL) {
1783 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1785 compose_wrap_all_full(compose, FALSE);
1786 compose->autowrap = prev_autowrap;
1790 compose_attach_parts(compose, msginfo);
1792 compose_colorize_signature(compose);
1794 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1795 G_CALLBACK(compose_changed_cb),
1798 gtk_widget_grab_focus(compose->text);
1800 if (prefs_common.auto_exteditor) {
1801 compose_exec_ext_editor(compose);
1803 compose->modified = FALSE;
1804 compose_set_title(compose);
1806 compose->updating = FALSE;
1808 if (compose->deferred_destroy) {
1809 compose_destroy(compose);
1815 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1820 GtkItemFactory *ifactory;
1823 g_return_val_if_fail(msginfo != NULL, NULL);
1826 account = account_get_reply_account(msginfo,
1827 prefs_common.reply_account_autosel);
1828 g_return_val_if_fail(account != NULL, NULL);
1830 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1832 compose->updating = TRUE;
1834 ifactory = gtk_item_factory_from_widget(compose->menubar);
1835 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1836 compose->replyinfo = NULL;
1837 compose->fwdinfo = NULL;
1839 compose_show_first_last_header(compose, TRUE);
1841 gtk_widget_grab_focus(compose->header_last->entry);
1843 filename = procmsg_get_message_file_path(msginfo);
1845 if (filename == NULL) {
1846 compose->updating = FALSE;
1847 compose_destroy(compose);
1852 compose->redirect_filename = filename;
1854 /* Set save folder */
1855 item = msginfo->folder;
1856 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1857 gchar *folderidentifier;
1859 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1860 folderidentifier = folder_item_get_identifier(item);
1861 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1862 g_free(folderidentifier);
1865 compose_attach_parts(compose, msginfo);
1867 if (msginfo->subject)
1868 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1870 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1872 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1873 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1875 compose_colorize_signature(compose);
1877 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1878 menu_set_sensitive(ifactory, "/Add...", FALSE);
1879 menu_set_sensitive(ifactory, "/Remove", FALSE);
1880 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1882 ifactory = gtk_item_factory_from_widget(compose->menubar);
1883 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1884 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1885 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1886 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1887 menu_set_sensitive(ifactory, "/Edit", FALSE);
1888 menu_set_sensitive(ifactory, "/Options", FALSE);
1889 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1890 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1892 if (compose->toolbar->draft_btn)
1893 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1894 if (compose->toolbar->insert_btn)
1895 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1896 if (compose->toolbar->attach_btn)
1897 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1898 if (compose->toolbar->sig_btn)
1899 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1900 if (compose->toolbar->exteditor_btn)
1901 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1902 if (compose->toolbar->linewrap_current_btn)
1903 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1904 if (compose->toolbar->linewrap_all_btn)
1905 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1907 compose->modified = FALSE;
1908 compose_set_title(compose);
1909 compose->updating = FALSE;
1911 if (compose->deferred_destroy) {
1912 compose_destroy(compose);
1919 GList *compose_get_compose_list(void)
1921 return compose_list;
1924 void compose_entry_append(Compose *compose, const gchar *address,
1925 ComposeEntryType type)
1929 gboolean in_quote = FALSE;
1930 if (!address || *address == '\0') return;
1937 header = N_("Bcc:");
1939 case COMPOSE_REPLYTO:
1940 header = N_("Reply-To:");
1942 case COMPOSE_NEWSGROUPS:
1943 header = N_("Newsgroups:");
1945 case COMPOSE_FOLLOWUPTO:
1946 header = N_( "Followup-To:");
1953 header = prefs_common.trans_hdr ? gettext(header) : header;
1955 cur = begin = (gchar *)address;
1957 /* we separate the line by commas, but not if we're inside a quoted
1959 while (*cur != '\0') {
1961 in_quote = !in_quote;
1962 if (*cur == ',' && !in_quote) {
1963 gchar *tmp = g_strdup(begin);
1965 tmp[cur-begin]='\0';
1968 while (*tmp == ' ' || *tmp == '\t')
1970 compose_add_header_entry(compose, header, tmp);
1977 gchar *tmp = g_strdup(begin);
1979 tmp[cur-begin]='\0';
1982 while (*tmp == ' ' || *tmp == '\t')
1984 compose_add_header_entry(compose, header, tmp);
1989 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1991 static GdkColor yellow;
1992 static GdkColor black;
1993 static gboolean yellow_initialised = FALSE;
1997 if (!yellow_initialised) {
1998 gdk_color_parse("#f5f6be", &yellow);
1999 gdk_color_parse("#000000", &black);
2000 yellow_initialised = gdk_colormap_alloc_color(
2001 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2002 yellow_initialised &= gdk_colormap_alloc_color(
2003 gdk_colormap_get_system(), &black, FALSE, TRUE);
2006 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2007 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2008 if (gtk_entry_get_text(entry) &&
2009 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2010 if (yellow_initialised) {
2011 gtk_widget_modify_base(
2012 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2013 GTK_STATE_NORMAL, &yellow);
2014 gtk_widget_modify_text(
2015 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2016 GTK_STATE_NORMAL, &black);
2022 void compose_toolbar_cb(gint action, gpointer data)
2024 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2025 Compose *compose = (Compose*)toolbar_item->parent;
2027 g_return_if_fail(compose != NULL);
2031 compose_send_cb(compose, 0, NULL);
2034 compose_send_later_cb(compose, 0, NULL);
2037 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2040 compose_insert_file_cb(compose, 0, NULL);
2043 compose_attach_cb(compose, 0, NULL);
2046 compose_insert_sig(compose, FALSE);
2049 compose_ext_editor_cb(compose, 0, NULL);
2051 case A_LINEWRAP_CURRENT:
2052 compose_beautify_paragraph(compose, NULL, TRUE);
2054 case A_LINEWRAP_ALL:
2055 compose_wrap_all_full(compose, TRUE);
2058 compose_address_cb(compose, 0, NULL);
2061 case A_CHECK_SPELLING:
2062 compose_check_all(compose);
2070 static void compose_entries_set(Compose *compose, const gchar *mailto)
2074 gchar *subject = NULL;
2079 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2082 compose_entry_append(compose, to, COMPOSE_TO);
2084 compose_entry_append(compose, cc, COMPOSE_CC);
2086 if (!g_utf8_validate (subject, -1, NULL)) {
2087 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2088 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2091 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2095 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2096 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2099 gboolean prev_autowrap = compose->autowrap;
2101 compose->autowrap = FALSE;
2103 mark = gtk_text_buffer_get_insert(buffer);
2104 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2106 if (!g_utf8_validate (body, -1, NULL)) {
2107 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2108 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2111 gtk_text_buffer_insert(buffer, &iter, body, -1);
2113 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2115 compose->autowrap = prev_autowrap;
2116 if (compose->autowrap)
2117 compose_wrap_all(compose);
2126 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2128 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2129 {"Cc:", NULL, TRUE},
2130 {"References:", NULL, FALSE},
2131 {"Bcc:", NULL, TRUE},
2132 {"Newsgroups:", NULL, TRUE},
2133 {"Followup-To:", NULL, TRUE},
2134 {"List-Post:", NULL, FALSE},
2135 {"X-Priority:", NULL, FALSE},
2136 {NULL, NULL, FALSE}};
2152 g_return_val_if_fail(msginfo != NULL, -1);
2154 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2155 procheader_get_header_fields(fp, hentry);
2158 if (hentry[H_REPLY_TO].body != NULL) {
2159 if (hentry[H_REPLY_TO].body[0] != '\0') {
2161 conv_unmime_header(hentry[H_REPLY_TO].body,
2164 g_free(hentry[H_REPLY_TO].body);
2165 hentry[H_REPLY_TO].body = NULL;
2167 if (hentry[H_CC].body != NULL) {
2168 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2169 g_free(hentry[H_CC].body);
2170 hentry[H_CC].body = NULL;
2172 if (hentry[H_REFERENCES].body != NULL) {
2173 if (compose->mode == COMPOSE_REEDIT)
2174 compose->references = hentry[H_REFERENCES].body;
2176 compose->references = compose_parse_references
2177 (hentry[H_REFERENCES].body, msginfo->msgid);
2178 g_free(hentry[H_REFERENCES].body);
2180 hentry[H_REFERENCES].body = NULL;
2182 if (hentry[H_BCC].body != NULL) {
2183 if (compose->mode == COMPOSE_REEDIT)
2185 conv_unmime_header(hentry[H_BCC].body, NULL);
2186 g_free(hentry[H_BCC].body);
2187 hentry[H_BCC].body = NULL;
2189 if (hentry[H_NEWSGROUPS].body != NULL) {
2190 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2191 hentry[H_NEWSGROUPS].body = NULL;
2193 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2194 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2195 compose->followup_to =
2196 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2199 g_free(hentry[H_FOLLOWUP_TO].body);
2200 hentry[H_FOLLOWUP_TO].body = NULL;
2202 if (hentry[H_LIST_POST].body != NULL) {
2205 extract_address(hentry[H_LIST_POST].body);
2206 if (hentry[H_LIST_POST].body[0] != '\0') {
2207 scan_mailto_url(hentry[H_LIST_POST].body,
2208 &to, NULL, NULL, NULL, NULL);
2210 g_free(compose->ml_post);
2211 compose->ml_post = to;
2214 g_free(hentry[H_LIST_POST].body);
2215 hentry[H_LIST_POST].body = NULL;
2218 /* CLAWS - X-Priority */
2219 if (compose->mode == COMPOSE_REEDIT)
2220 if (hentry[H_X_PRIORITY].body != NULL) {
2223 priority = atoi(hentry[H_X_PRIORITY].body);
2224 g_free(hentry[H_X_PRIORITY].body);
2226 hentry[H_X_PRIORITY].body = NULL;
2228 if (priority < PRIORITY_HIGHEST ||
2229 priority > PRIORITY_LOWEST)
2230 priority = PRIORITY_NORMAL;
2232 compose->priority = priority;
2235 if (compose->mode == COMPOSE_REEDIT) {
2236 if (msginfo->inreplyto && *msginfo->inreplyto)
2237 compose->inreplyto = g_strdup(msginfo->inreplyto);
2241 if (msginfo->msgid && *msginfo->msgid)
2242 compose->inreplyto = g_strdup(msginfo->msgid);
2244 if (!compose->references) {
2245 if (msginfo->msgid && *msginfo->msgid) {
2246 if (msginfo->inreplyto && *msginfo->inreplyto)
2247 compose->references =
2248 g_strdup_printf("<%s>\n\t<%s>",
2252 compose->references =
2253 g_strconcat("<", msginfo->msgid, ">",
2255 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2256 compose->references =
2257 g_strconcat("<", msginfo->inreplyto, ">",
2265 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2267 GSList *ref_id_list, *cur;
2271 ref_id_list = references_list_append(NULL, ref);
2272 if (!ref_id_list) return NULL;
2273 if (msgid && *msgid)
2274 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2279 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2280 /* "<" + Message-ID + ">" + CR+LF+TAB */
2281 len += strlen((gchar *)cur->data) + 5;
2283 if (len > MAX_REFERENCES_LEN) {
2284 /* remove second message-ID */
2285 if (ref_id_list && ref_id_list->next &&
2286 ref_id_list->next->next) {
2287 g_free(ref_id_list->next->data);
2288 ref_id_list = g_slist_remove
2289 (ref_id_list, ref_id_list->next->data);
2291 slist_free_strings(ref_id_list);
2292 g_slist_free(ref_id_list);
2299 new_ref = g_string_new("");
2300 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2301 if (new_ref->len > 0)
2302 g_string_append(new_ref, "\n\t");
2303 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2306 slist_free_strings(ref_id_list);
2307 g_slist_free(ref_id_list);
2309 new_ref_str = new_ref->str;
2310 g_string_free(new_ref, FALSE);
2315 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2316 const gchar *fmt, const gchar *qmark,
2317 const gchar *body, gboolean rewrap)
2319 static MsgInfo dummyinfo;
2320 gchar *quote_str = NULL;
2322 gboolean prev_autowrap;
2323 const gchar *trimmed_body = body;
2324 gint cursor_pos = -1;
2325 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2326 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2331 SIGNAL_BLOCK(buffer);
2334 msginfo = &dummyinfo;
2336 if (qmark != NULL) {
2337 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2338 quote_fmt_scan_string(qmark);
2341 buf = quote_fmt_get_buffer();
2343 alertpanel_error(_("Quote mark format error."));
2345 Xstrdup_a(quote_str, buf, goto error)
2348 if (fmt && *fmt != '\0') {
2349 while (trimmed_body && strlen(trimmed_body) > 1
2350 && trimmed_body[0]=='\n')
2353 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2354 quote_fmt_scan_string(fmt);
2357 buf = quote_fmt_get_buffer();
2359 alertpanel_error(_("Message reply/forward format error."));
2365 prev_autowrap = compose->autowrap;
2366 compose->autowrap = FALSE;
2368 mark = gtk_text_buffer_get_insert(buffer);
2369 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2370 if (g_utf8_validate(buf, -1, NULL)) {
2371 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2373 gchar *tmpout = NULL;
2374 tmpout = conv_codeset_strdup
2375 (buf, conv_get_locale_charset_str_no_utf8(),
2377 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2379 tmpout = g_malloc(strlen(buf)*2+1);
2380 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2382 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2386 cursor_pos = quote_fmt_get_cursor_pos();
2387 compose->set_cursor_pos = cursor_pos;
2388 if (cursor_pos == -1) {
2391 gtk_text_buffer_get_start_iter(buffer, &iter);
2392 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2393 gtk_text_buffer_place_cursor(buffer, &iter);
2395 compose->autowrap = prev_autowrap;
2396 if (compose->autowrap && rewrap)
2397 compose_wrap_all(compose);
2404 SIGNAL_UNBLOCK(buffer);
2410 /* if ml_post is of type addr@host and from is of type
2411 * addr-anything@host, return TRUE
2413 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2415 gchar *left_ml = NULL;
2416 gchar *right_ml = NULL;
2417 gchar *left_from = NULL;
2418 gchar *right_from = NULL;
2419 gboolean result = FALSE;
2421 if (!ml_post || !from)
2424 left_ml = g_strdup(ml_post);
2425 if (strstr(left_ml, "@")) {
2426 right_ml = strstr(left_ml, "@")+1;
2427 *(strstr(left_ml, "@")) = '\0';
2430 left_from = g_strdup(from);
2431 if (strstr(left_from, "@")) {
2432 right_from = strstr(left_from, "@")+1;
2433 *(strstr(left_from, "@")) = '\0';
2436 if (left_ml && left_from && right_ml && right_from
2437 && !strncmp(left_from, left_ml, strlen(left_ml))
2438 && !strcmp(right_from, right_ml)) {
2447 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2449 gchar *my_addr1, *my_addr2;
2451 if (!addr1 || !addr2)
2454 Xstrdup_a(my_addr1, addr1, return FALSE);
2455 Xstrdup_a(my_addr2, addr2, return FALSE);
2457 extract_address(my_addr1);
2458 extract_address(my_addr2);
2460 return !strcmp(my_addr1, my_addr2);
2463 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2464 gboolean to_all, gboolean to_ml,
2466 gboolean followup_and_reply_to)
2468 GSList *cc_list = NULL;
2471 gchar *replyto = NULL;
2472 GHashTable *to_table;
2474 gboolean reply_to_ml = FALSE;
2475 gboolean default_reply_to = FALSE;
2477 g_return_if_fail(compose->account != NULL);
2478 g_return_if_fail(msginfo != NULL);
2480 reply_to_ml = to_ml && compose->ml_post;
2482 default_reply_to = msginfo->folder &&
2483 msginfo->folder->prefs->enable_default_reply_to;
2485 if (compose->account->protocol != A_NNTP) {
2486 if (reply_to_ml && !default_reply_to) {
2488 gboolean is_subscr = is_subscription(compose->ml_post,
2491 /* normal answer to ml post with a reply-to */
2492 compose_entry_append(compose,
2495 if (compose->replyto
2496 && !same_address(compose->ml_post, compose->replyto))
2497 compose_entry_append(compose,
2501 /* answer to subscription confirmation */
2502 if (compose->replyto)
2503 compose_entry_append(compose,
2506 else if (msginfo->from)
2507 compose_entry_append(compose,
2512 else if (!(to_all || to_sender) && default_reply_to) {
2513 compose_entry_append(compose,
2514 msginfo->folder->prefs->default_reply_to,
2516 compose_entry_mark_default_to(compose,
2517 msginfo->folder->prefs->default_reply_to);
2522 Xstrdup_a(tmp1, msginfo->from, return);
2523 extract_address(tmp1);
2524 if (to_all || to_sender ||
2525 !account_find_from_address(tmp1))
2526 compose_entry_append(compose,
2527 (compose->replyto && !to_sender)
2528 ? compose->replyto :
2529 msginfo->from ? msginfo->from : "",
2531 else if (!to_all && !to_sender) {
2532 /* reply to the last list of recipients */
2533 compose_entry_append(compose,
2534 msginfo->to ? msginfo->to : "",
2536 compose_entry_append(compose,
2537 msginfo->cc ? msginfo->cc : "",
2542 if (to_sender || (compose->followup_to &&
2543 !strncmp(compose->followup_to, "poster", 6)))
2544 compose_entry_append
2546 (compose->replyto ? compose->replyto :
2547 msginfo->from ? msginfo->from : ""),
2550 else if (followup_and_reply_to || to_all) {
2551 compose_entry_append
2553 (compose->replyto ? compose->replyto :
2554 msginfo->from ? msginfo->from : ""),
2557 compose_entry_append
2559 compose->followup_to ? compose->followup_to :
2560 compose->newsgroups ? compose->newsgroups : "",
2561 COMPOSE_NEWSGROUPS);
2564 compose_entry_append
2566 compose->followup_to ? compose->followup_to :
2567 compose->newsgroups ? compose->newsgroups : "",
2568 COMPOSE_NEWSGROUPS);
2571 if (msginfo->subject && *msginfo->subject) {
2575 buf = p = g_strdup(msginfo->subject);
2576 p += subject_get_prefix_length(p);
2577 memmove(buf, p, strlen(p) + 1);
2579 buf2 = g_strdup_printf("Re: %s", buf);
2580 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2585 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2587 if (to_ml && compose->ml_post) return;
2588 if (!to_all || compose->account->protocol == A_NNTP) return;
2590 if (compose->replyto) {
2591 Xstrdup_a(replyto, compose->replyto, return);
2592 extract_address(replyto);
2594 if (msginfo->from) {
2595 Xstrdup_a(from, msginfo->from, return);
2596 extract_address(from);
2599 if (replyto && from)
2600 cc_list = address_list_append_with_comments(cc_list, from);
2601 if (to_all && msginfo->folder &&
2602 msginfo->folder->prefs->enable_default_reply_to)
2603 cc_list = address_list_append_with_comments(cc_list,
2604 msginfo->folder->prefs->default_reply_to);
2605 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2606 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2608 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2610 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2611 if (compose->account)
2612 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2613 GINT_TO_POINTER(1));
2615 /* remove address on To: and that of current account */
2616 for (cur = cc_list; cur != NULL; ) {
2617 GSList *next = cur->next;
2620 addr = g_strdup(cur->data);
2621 extract_address(addr);
2623 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2624 cc_list = g_slist_remove(cc_list, cur->data);
2626 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2630 hash_free_strings(to_table);
2631 g_hash_table_destroy(to_table);
2634 for (cur = cc_list; cur != NULL; cur = cur->next)
2635 compose_entry_append(compose, (gchar *)cur->data,
2637 slist_free_strings(cc_list);
2638 g_slist_free(cc_list);
2643 #define SET_ENTRY(entry, str) \
2646 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2649 #define SET_ADDRESS(type, str) \
2652 compose_entry_append(compose, str, type); \
2655 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2657 g_return_if_fail(msginfo != NULL);
2659 SET_ENTRY(subject_entry, msginfo->subject);
2660 SET_ENTRY(from_name, msginfo->from);
2661 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2662 SET_ADDRESS(COMPOSE_CC, compose->cc);
2663 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2664 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2665 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2666 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2668 compose_update_priority_menu_item(compose);
2669 compose_update_privacy_system_menu_item(compose, FALSE);
2670 compose_show_first_last_header(compose, TRUE);
2676 static void compose_insert_sig(Compose *compose, gboolean replace)
2678 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2679 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2681 GtkTextIter iter, iter_end;
2683 gboolean prev_autowrap;
2686 g_return_if_fail(compose->account != NULL);
2688 prev_autowrap = compose->autowrap;
2689 compose->autowrap = FALSE;
2691 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2692 G_CALLBACK(compose_changed_cb),
2695 mark = gtk_text_buffer_get_insert(buffer);
2696 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2697 cur_pos = gtk_text_iter_get_offset (&iter);
2699 gtk_text_buffer_get_end_iter(buffer, &iter);
2701 if (replace && compose->sig_str) {
2703 GtkTextIter first_iter, start_iter, end_iter;
2705 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2707 if (compose->sig_str[0] == '\0')
2710 found = gtk_text_iter_forward_search(&first_iter,
2712 GTK_TEXT_SEARCH_TEXT_ONLY,
2713 &start_iter, &end_iter,
2717 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2722 g_free(compose->sig_str);
2723 compose->sig_str = compose_get_signature_str(compose);
2724 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2725 compose->sig_str = g_strdup("");
2727 cur_pos = gtk_text_iter_get_offset(&iter);
2728 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2730 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2731 gtk_text_iter_forward_char(&iter);
2732 gtk_text_iter_forward_char(&iter);
2733 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2734 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2736 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2737 cur_pos = gtk_text_buffer_get_char_count (buffer);
2739 /* put the cursor where it should be
2740 * either where the quote_fmt says, either before the signature */
2741 if (compose->set_cursor_pos < 0)
2742 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2744 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2745 compose->set_cursor_pos);
2747 gtk_text_buffer_place_cursor(buffer, &iter);
2748 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2749 G_CALLBACK(compose_changed_cb),
2752 compose->autowrap = prev_autowrap;
2753 if (compose->autowrap)
2754 compose_wrap_all(compose);
2757 static gchar *compose_get_signature_str(Compose *compose)
2759 gchar *sig_body = NULL;
2760 gchar *sig_str = NULL;
2761 gchar *utf8_sig_str = NULL;
2763 g_return_val_if_fail(compose->account != NULL, NULL);
2765 if (!compose->account->sig_path)
2768 if (compose->account->sig_type == SIG_FILE) {
2769 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2770 g_warning("can't open signature file: %s\n",
2771 compose->account->sig_path);
2776 if (compose->account->sig_type == SIG_COMMAND)
2777 sig_body = get_command_output(compose->account->sig_path);
2781 tmp = file_read_to_str(compose->account->sig_path);
2784 sig_body = normalize_newlines(tmp);
2788 if (compose->account->sig_sep) {
2789 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2793 sig_str = g_strconcat("\n\n", sig_body, NULL);
2796 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2797 utf8_sig_str = sig_str;
2799 utf8_sig_str = conv_codeset_strdup
2800 (sig_str, conv_get_locale_charset_str_no_utf8(),
2806 return utf8_sig_str;
2809 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2812 GtkTextBuffer *buffer;
2815 const gchar *cur_encoding;
2816 gchar buf[BUFFSIZE];
2819 gboolean prev_autowrap;
2820 gboolean badtxt = FALSE;
2822 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2824 if ((fp = g_fopen(file, "rb")) == NULL) {
2825 FILE_OP_ERROR(file, "fopen");
2826 return COMPOSE_INSERT_READ_ERROR;
2829 prev_autowrap = compose->autowrap;
2830 compose->autowrap = FALSE;
2832 text = GTK_TEXT_VIEW(compose->text);
2833 buffer = gtk_text_view_get_buffer(text);
2834 mark = gtk_text_buffer_get_insert(buffer);
2835 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2837 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2838 G_CALLBACK(text_inserted),
2841 cur_encoding = conv_get_locale_charset_str_no_utf8();
2843 while (fgets(buf, sizeof(buf), fp) != NULL) {
2846 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2847 str = g_strdup(buf);
2849 str = conv_codeset_strdup
2850 (buf, cur_encoding, CS_INTERNAL);
2853 /* strip <CR> if DOS/Windows file,
2854 replace <CR> with <LF> if Macintosh file. */
2857 if (len > 0 && str[len - 1] != '\n') {
2859 if (str[len] == '\r') str[len] = '\n';
2862 gtk_text_buffer_insert(buffer, &iter, str, -1);
2866 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2867 G_CALLBACK(text_inserted),
2869 compose->autowrap = prev_autowrap;
2870 if (compose->autowrap)
2871 compose_wrap_all(compose);
2876 return COMPOSE_INSERT_INVALID_CHARACTER;
2878 return COMPOSE_INSERT_SUCCESS;
2881 static void compose_attach_append(Compose *compose, const gchar *file,
2882 const gchar *filename,
2883 const gchar *content_type)
2891 GtkListStore *store;
2893 gboolean has_binary = FALSE;
2895 if (!is_file_exist(file)) {
2896 g_warning("File %s doesn't exist\n", filename);
2899 if ((size = get_file_size(file)) < 0) {
2900 g_warning("Can't get file size of %s\n", filename);
2904 alertpanel_notice(_("File %s is empty."), filename);
2907 if ((fp = g_fopen(file, "rb")) == NULL) {
2908 alertpanel_error(_("Can't read %s."), filename);
2913 ainfo = g_new0(AttachInfo, 1);
2914 auto_ainfo = g_auto_pointer_new_with_free
2915 (ainfo, (GFreeFunc) compose_attach_info_free);
2916 ainfo->file = g_strdup(file);
2919 ainfo->content_type = g_strdup(content_type);
2920 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2922 MsgFlags flags = {0, 0};
2924 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2925 ainfo->encoding = ENC_7BIT;
2927 ainfo->encoding = ENC_8BIT;
2929 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2930 if (msginfo && msginfo->subject)
2931 name = g_strdup(msginfo->subject);
2933 name = g_path_get_basename(filename ? filename : file);
2935 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2937 procmsg_msginfo_free(msginfo);
2939 if (!g_ascii_strncasecmp(content_type, "text", 4))
2940 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2942 ainfo->encoding = ENC_BASE64;
2943 name = g_path_get_basename(filename ? filename : file);
2944 ainfo->name = g_strdup(name);
2948 ainfo->content_type = procmime_get_mime_type(file);
2949 if (!ainfo->content_type) {
2950 ainfo->content_type =
2951 g_strdup("application/octet-stream");
2952 ainfo->encoding = ENC_BASE64;
2953 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2955 procmime_get_encoding_for_text_file(file, &has_binary);
2957 ainfo->encoding = ENC_BASE64;
2958 name = g_path_get_basename(filename ? filename : file);
2959 ainfo->name = g_strdup(name);
2963 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2964 g_free(ainfo->content_type);
2965 ainfo->content_type = g_strdup("application/octet-stream");
2969 size_text = to_human_readable(size);
2971 store = GTK_LIST_STORE(gtk_tree_view_get_model
2972 (GTK_TREE_VIEW(compose->attach_clist)));
2974 gtk_list_store_append(store, &iter);
2975 gtk_list_store_set(store, &iter,
2976 COL_MIMETYPE, ainfo->content_type,
2977 COL_SIZE, size_text,
2978 COL_NAME, ainfo->name,
2980 COL_AUTODATA, auto_ainfo,
2983 g_auto_pointer_free(auto_ainfo);
2986 static void compose_use_signing(Compose *compose, gboolean use_signing)
2988 GtkItemFactory *ifactory;
2989 GtkWidget *menuitem = NULL;
2991 compose->use_signing = use_signing;
2992 ifactory = gtk_item_factory_from_widget(compose->menubar);
2993 menuitem = gtk_item_factory_get_item
2994 (ifactory, "/Options/Sign");
2995 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2999 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3001 GtkItemFactory *ifactory;
3002 GtkWidget *menuitem = NULL;
3004 compose->use_encryption = use_encryption;
3005 ifactory = gtk_item_factory_from_widget(compose->menubar);
3006 menuitem = gtk_item_factory_get_item
3007 (ifactory, "/Options/Encrypt");
3009 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3013 #define NEXT_PART_NOT_CHILD(info) \
3015 node = info->node; \
3016 while (node->children) \
3017 node = g_node_last_child(node); \
3018 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3021 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3025 MimeInfo *firsttext = NULL;
3026 MimeInfo *encrypted = NULL;
3029 const gchar *partname = NULL;
3031 mimeinfo = procmime_scan_message(msginfo);
3032 if (!mimeinfo) return;
3034 if (mimeinfo->node->children == NULL) {
3035 procmime_mimeinfo_free_all(mimeinfo);
3039 /* find first content part */
3040 child = (MimeInfo *) mimeinfo->node->children->data;
3041 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3042 child = (MimeInfo *)child->node->children->data;
3044 if (child->type == MIMETYPE_TEXT) {
3046 debug_print("First text part found\n");
3047 } else if (compose->mode == COMPOSE_REEDIT &&
3048 child->type == MIMETYPE_APPLICATION &&
3049 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3050 encrypted = (MimeInfo *)child->node->parent->data;
3053 child = (MimeInfo *) mimeinfo->node->children->data;
3054 while (child != NULL) {
3055 if (child == encrypted) {
3056 /* skip this part of tree */
3057 NEXT_PART_NOT_CHILD(child);
3061 if (child->type == MIMETYPE_MULTIPART) {
3062 /* get the actual content */
3063 child = procmime_mimeinfo_next(child);
3067 if (child == firsttext) {
3068 child = procmime_mimeinfo_next(child);
3072 outfile = procmime_get_tmp_file_name(child);
3073 if (procmime_get_part(outfile, child) < 0)
3074 g_warning("Can't get the part of multipart message.");
3076 gchar *content_type;
3078 content_type = procmime_get_content_type_str(child->type, child->subtype);
3080 /* if we meet a pgp signature, we don't attach it, but
3081 * we force signing. */
3082 if (strcmp(content_type, "application/pgp-signature")) {
3083 partname = procmime_mimeinfo_get_parameter(child, "filename");
3084 if (partname == NULL)
3085 partname = procmime_mimeinfo_get_parameter(child, "name");
3086 if (partname == NULL)
3088 compose_attach_append(compose, outfile,
3089 partname, content_type);
3091 compose_force_signing(compose, compose->account);
3093 g_free(content_type);
3096 NEXT_PART_NOT_CHILD(child);
3098 procmime_mimeinfo_free_all(mimeinfo);
3101 #undef NEXT_PART_NOT_CHILD
3106 WAIT_FOR_INDENT_CHAR,
3107 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3110 /* return indent length, we allow:
3111 indent characters followed by indent characters or spaces/tabs,
3112 alphabets and numbers immediately followed by indent characters,
3113 and the repeating sequences of the above
3114 If quote ends with multiple spaces, only the first one is included. */
3115 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3116 const GtkTextIter *start, gint *len)
3118 GtkTextIter iter = *start;
3122 IndentState state = WAIT_FOR_INDENT_CHAR;
3125 gint alnum_count = 0;
3126 gint space_count = 0;
3129 if (prefs_common.quote_chars == NULL) {
3133 while (!gtk_text_iter_ends_line(&iter)) {
3134 wc = gtk_text_iter_get_char(&iter);
3135 if (g_unichar_iswide(wc))
3137 clen = g_unichar_to_utf8(wc, ch);
3141 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3142 is_space = g_unichar_isspace(wc);
3144 if (state == WAIT_FOR_INDENT_CHAR) {
3145 if (!is_indent && !g_unichar_isalnum(wc))
3148 quote_len += alnum_count + space_count + 1;
3149 alnum_count = space_count = 0;
3150 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3153 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3154 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3158 else if (is_indent) {
3159 quote_len += alnum_count + space_count + 1;
3160 alnum_count = space_count = 0;
3163 state = WAIT_FOR_INDENT_CHAR;
3167 gtk_text_iter_forward_char(&iter);
3170 if (quote_len > 0 && space_count > 0)
3176 if (quote_len > 0) {
3178 gtk_text_iter_forward_chars(&iter, quote_len);
3179 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3185 /* return TRUE if the line is itemized */
3186 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3187 const GtkTextIter *start)
3189 GtkTextIter iter = *start;
3194 if (gtk_text_iter_ends_line(&iter))
3198 wc = gtk_text_iter_get_char(&iter);
3199 if (!g_unichar_isspace(wc))
3201 gtk_text_iter_forward_char(&iter);
3202 if (gtk_text_iter_ends_line(&iter))
3206 clen = g_unichar_to_utf8(wc, ch);
3210 if (!strchr("*-+", ch[0]))
3213 gtk_text_iter_forward_char(&iter);
3214 if (gtk_text_iter_ends_line(&iter))
3216 wc = gtk_text_iter_get_char(&iter);
3217 if (g_unichar_isspace(wc))
3223 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3224 const GtkTextIter *start,
3225 GtkTextIter *break_pos,
3229 GtkTextIter iter = *start, line_end = *start;
3230 PangoLogAttr *attrs;
3237 gboolean can_break = FALSE;
3238 gboolean do_break = FALSE;
3239 gboolean was_white = FALSE;
3240 gboolean prev_dont_break = FALSE;
3242 gtk_text_iter_forward_to_line_end(&line_end);
3243 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3244 len = g_utf8_strlen(str, -1);
3245 /* g_print("breaking line: %d: %s (len = %d)\n",
3246 gtk_text_iter_get_line(&iter), str, len); */
3247 attrs = g_new(PangoLogAttr, len + 1);
3249 pango_default_break(str, -1, NULL, attrs, len + 1);
3253 /* skip quote and leading spaces */
3254 for (i = 0; *p != '\0' && i < len; i++) {
3257 wc = g_utf8_get_char(p);
3258 if (i >= quote_len && !g_unichar_isspace(wc))
3260 if (g_unichar_iswide(wc))
3262 else if (*p == '\t')
3266 p = g_utf8_next_char(p);
3269 for (; *p != '\0' && i < len; i++) {
3270 PangoLogAttr *attr = attrs + i;
3274 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3277 was_white = attr->is_white;
3279 /* don't wrap URI */
3280 if ((uri_len = get_uri_len(p)) > 0) {
3282 if (pos > 0 && col > max_col) {
3292 wc = g_utf8_get_char(p);
3293 if (g_unichar_iswide(wc)) {
3295 if (prev_dont_break && can_break && attr->is_line_break)
3297 } else if (*p == '\t')
3301 if (pos > 0 && col > max_col) {
3306 if (*p == '-' || *p == '/')
3307 prev_dont_break = TRUE;
3309 prev_dont_break = FALSE;
3311 p = g_utf8_next_char(p);
3315 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3320 *break_pos = *start;
3321 gtk_text_iter_set_line_offset(break_pos, pos);
3326 static gboolean compose_join_next_line(Compose *compose,
3327 GtkTextBuffer *buffer,
3329 const gchar *quote_str)
3331 GtkTextIter iter_ = *iter, cur, prev, next, end;
3332 PangoLogAttr attrs[3];
3334 gchar *next_quote_str;
3337 gboolean keep_cursor = FALSE;
3339 if (!gtk_text_iter_forward_line(&iter_) ||
3340 gtk_text_iter_ends_line(&iter_))
3343 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3345 if ((quote_str || next_quote_str) &&
3346 strcmp2(quote_str, next_quote_str) != 0) {
3347 g_free(next_quote_str);
3350 g_free(next_quote_str);
3353 if (quote_len > 0) {
3354 gtk_text_iter_forward_chars(&end, quote_len);
3355 if (gtk_text_iter_ends_line(&end))
3359 /* don't join itemized lines */
3360 if (compose_is_itemized(buffer, &end))
3363 /* don't join signature separator */
3364 if (compose_is_sig_separator(compose, buffer, &iter_))
3367 /* delete quote str */
3369 gtk_text_buffer_delete(buffer, &iter_, &end);
3371 /* don't join line breaks put by the user */
3373 gtk_text_iter_backward_char(&cur);
3374 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3375 gtk_text_iter_forward_char(&cur);
3379 gtk_text_iter_forward_char(&cur);
3380 /* delete linebreak and extra spaces */
3381 while (gtk_text_iter_backward_char(&cur)) {
3382 wc1 = gtk_text_iter_get_char(&cur);
3383 if (!g_unichar_isspace(wc1))
3388 while (!gtk_text_iter_ends_line(&cur)) {
3389 wc1 = gtk_text_iter_get_char(&cur);
3390 if (!g_unichar_isspace(wc1))
3392 gtk_text_iter_forward_char(&cur);
3395 if (!gtk_text_iter_equal(&prev, &next)) {
3398 mark = gtk_text_buffer_get_insert(buffer);
3399 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3400 if (gtk_text_iter_equal(&prev, &cur))
3402 gtk_text_buffer_delete(buffer, &prev, &next);
3406 /* insert space if required */
3407 gtk_text_iter_backward_char(&prev);
3408 wc1 = gtk_text_iter_get_char(&prev);
3409 wc2 = gtk_text_iter_get_char(&next);
3410 gtk_text_iter_forward_char(&next);
3411 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3412 pango_default_break(str, -1, NULL, attrs, 3);
3413 if (!attrs[1].is_line_break ||
3414 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3415 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3417 gtk_text_iter_backward_char(&iter_);
3418 gtk_text_buffer_place_cursor(buffer, &iter_);
3427 #define ADD_TXT_POS(bp_, ep_, pti_) \
3428 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3429 last = last->next; \
3430 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3431 last->next = NULL; \
3433 g_warning("alloc error scanning URIs\n"); \
3436 static gboolean automatic_break = FALSE;
3437 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3439 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3440 GtkTextBuffer *buffer;
3441 GtkTextIter iter, break_pos, end_of_line;
3442 gchar *quote_str = NULL;
3444 gboolean wrap_quote = prefs_common.linewrap_quote;
3445 gboolean prev_autowrap = compose->autowrap;
3446 gint startq_offset = -1, noq_offset = -1;
3447 gint uri_start = -1, uri_stop = -1;
3448 gint nouri_start = -1, nouri_stop = -1;
3449 gint num_blocks = 0;
3450 gint quotelevel = -1;
3452 compose->autowrap = FALSE;
3454 buffer = gtk_text_view_get_buffer(text);
3455 undo_wrapping(compose->undostruct, TRUE);
3460 mark = gtk_text_buffer_get_insert(buffer);
3461 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3464 /* move to paragraph start */
3465 gtk_text_iter_set_line_offset(&iter, 0);
3466 if (gtk_text_iter_ends_line(&iter)) {
3467 while (gtk_text_iter_ends_line(&iter) &&
3468 gtk_text_iter_forward_line(&iter))
3471 while (gtk_text_iter_backward_line(&iter)) {
3472 if (gtk_text_iter_ends_line(&iter)) {
3473 gtk_text_iter_forward_line(&iter);
3479 /* go until paragraph end (empty line) */
3481 while (!gtk_text_iter_ends_line(&iter)) {
3482 gchar *scanpos = NULL;
3483 /* parse table - in order of priority */
3485 const gchar *needle; /* token */
3487 /* token search function */
3488 gchar *(*search) (const gchar *haystack,
3489 const gchar *needle);
3490 /* part parsing function */
3491 gboolean (*parse) (const gchar *start,
3492 const gchar *scanpos,
3496 /* part to URI function */
3497 gchar *(*build_uri) (const gchar *bp,
3501 static struct table parser[] = {
3502 {"http://", strcasestr, get_uri_part, make_uri_string},
3503 {"https://", strcasestr, get_uri_part, make_uri_string},
3504 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3505 {"www.", strcasestr, get_uri_part, make_http_string},
3506 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3507 {"@", strcasestr, get_email_part, make_email_string}
3509 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3510 gint last_index = PARSE_ELEMS;
3512 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3515 if (!prev_autowrap && num_blocks == 0) {
3517 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3518 G_CALLBACK(text_inserted),
3521 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3524 uri_start = uri_stop = -1;
3526 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3530 if (startq_offset == -1) {
3531 startq_offset = gtk_text_iter_get_offset(&iter);
3535 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3536 if (startq_offset == -1)
3537 startq_offset = gtk_text_iter_get_offset(&iter);
3538 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3539 if (quotelevel > 2) {
3540 /* recycle colors */
3541 if (prefs_common.recycle_quote_colors)
3547 if (startq_offset == -1)
3548 noq_offset = gtk_text_iter_get_offset(&iter);
3552 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3555 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3556 prefs_common.linewrap_len,
3558 GtkTextIter prev, next, cur;
3560 if (prev_autowrap != FALSE || force) {
3561 automatic_break = TRUE;
3562 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3563 automatic_break = FALSE;
3564 } else if (quote_str && wrap_quote) {
3565 automatic_break = TRUE;
3566 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3567 automatic_break = FALSE;
3570 /* remove trailing spaces */
3572 gtk_text_iter_backward_char(&cur);
3574 while (!gtk_text_iter_starts_line(&cur)) {
3577 gtk_text_iter_backward_char(&cur);
3578 wc = gtk_text_iter_get_char(&cur);
3579 if (!g_unichar_isspace(wc))
3583 if (!gtk_text_iter_equal(&prev, &next)) {
3584 gtk_text_buffer_delete(buffer, &prev, &next);
3586 gtk_text_iter_forward_char(&break_pos);
3590 gtk_text_buffer_insert(buffer, &break_pos,
3594 compose_join_next_line(compose, buffer, &iter, quote_str);
3596 /* move iter to current line start */
3597 gtk_text_iter_set_line_offset(&iter, 0);
3604 /* move iter to next line start */
3609 if (!prev_autowrap && num_blocks > 0) {
3611 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3612 G_CALLBACK(text_inserted),
3616 while (!gtk_text_iter_ends_line(&end_of_line)) {
3617 gtk_text_iter_forward_char(&end_of_line);
3619 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3621 nouri_start = gtk_text_iter_get_offset(&iter);
3622 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3624 walk_pos = gtk_text_iter_get_offset(&iter);
3625 /* FIXME: this looks phony. scanning for anything in the parse table */
3626 for (n = 0; n < PARSE_ELEMS; n++) {
3629 tmp = parser[n].search(walk, parser[n].needle);
3631 if (scanpos == NULL || tmp < scanpos) {
3640 /* check if URI can be parsed */
3641 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3642 (const gchar **)&ep, FALSE)
3643 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3647 strlen(parser[last_index].needle);
3650 uri_start = walk_pos + (bp - o_walk);
3651 uri_stop = walk_pos + (ep - o_walk);
3655 gtk_text_iter_forward_line(&iter);
3658 if (startq_offset != -1) {
3659 GtkTextIter startquote, endquote;
3660 gtk_text_buffer_get_iter_at_offset(
3661 buffer, &startquote, startq_offset);
3663 switch (quotelevel) {
3664 case 0: gtk_text_buffer_apply_tag_by_name(
3665 buffer, "quote0", &startquote, &endquote);
3667 case 1: gtk_text_buffer_apply_tag_by_name(
3668 buffer, "quote1", &startquote, &endquote);
3670 case 2: gtk_text_buffer_apply_tag_by_name(
3671 buffer, "quote2", &startquote, &endquote);
3675 } else if (noq_offset != -1) {
3676 GtkTextIter startnoquote, endnoquote;
3677 gtk_text_buffer_get_iter_at_offset(
3678 buffer, &startnoquote, noq_offset);
3680 gtk_text_buffer_remove_tag_by_name(
3681 buffer, "quote0", &startnoquote, &endnoquote);
3682 gtk_text_buffer_remove_tag_by_name(
3683 buffer, "quote1", &startnoquote, &endnoquote);
3684 gtk_text_buffer_remove_tag_by_name(
3685 buffer, "quote2", &startnoquote, &endnoquote);
3690 GtkTextIter nouri_start_iter, nouri_end_iter;
3691 gtk_text_buffer_get_iter_at_offset(
3692 buffer, &nouri_start_iter, nouri_start);
3693 gtk_text_buffer_get_iter_at_offset(
3694 buffer, &nouri_end_iter, nouri_stop);
3695 gtk_text_buffer_remove_tag_by_name(
3696 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3698 if (uri_start > 0 && uri_stop > 0) {
3699 GtkTextIter uri_start_iter, uri_end_iter;
3700 gtk_text_buffer_get_iter_at_offset(
3701 buffer, &uri_start_iter, uri_start);
3702 gtk_text_buffer_get_iter_at_offset(
3703 buffer, &uri_end_iter, uri_stop);
3704 gtk_text_buffer_apply_tag_by_name(
3705 buffer, "link", &uri_start_iter, &uri_end_iter);
3711 undo_wrapping(compose->undostruct, FALSE);
3712 compose->autowrap = prev_autowrap;
3715 void compose_action_cb(void *data)
3717 Compose *compose = (Compose *)data;
3718 compose_wrap_all(compose);
3721 static void compose_wrap_all(Compose *compose)
3723 compose_wrap_all_full(compose, FALSE);
3726 static void compose_wrap_all_full(Compose *compose, gboolean force)
3728 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3729 GtkTextBuffer *buffer;
3732 buffer = gtk_text_view_get_buffer(text);
3734 gtk_text_buffer_get_start_iter(buffer, &iter);
3735 while (!gtk_text_iter_is_end(&iter))
3736 compose_beautify_paragraph(compose, &iter, force);
3740 static void compose_set_title(Compose *compose)
3746 edited = compose->modified ? _(" [Edited]") : "";
3748 subject = gtk_editable_get_chars(
3749 GTK_EDITABLE(compose->subject_entry), 0, -1);
3751 if (subject && strlen(subject))
3752 str = g_strdup_printf(_("%s - Compose message%s"),
3755 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3756 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3762 * compose_current_mail_account:
3764 * Find a current mail account (the currently selected account, or the
3765 * default account, if a news account is currently selected). If a
3766 * mail account cannot be found, display an error message.
3768 * Return value: Mail account, or NULL if not found.
3770 static PrefsAccount *
3771 compose_current_mail_account(void)
3775 if (cur_account && cur_account->protocol != A_NNTP)
3778 ac = account_get_default();
3779 if (!ac || ac->protocol == A_NNTP) {
3780 alertpanel_error(_("Account for sending mail is not specified.\n"
3781 "Please select a mail account before sending."));
3788 #define QUOTE_IF_REQUIRED(out, str) \
3790 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3794 len = strlen(str) + 3; \
3795 if ((__tmp = alloca(len)) == NULL) { \
3796 g_warning("can't allocate memory\n"); \
3797 g_string_free(header, TRUE); \
3800 g_snprintf(__tmp, len, "\"%s\"", str); \
3805 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3806 g_warning("can't allocate memory\n"); \
3807 g_string_free(header, TRUE); \
3810 strcpy(__tmp, str); \
3816 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
3818 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3822 len = strlen(str) + 3; \
3823 if ((__tmp = alloca(len)) == NULL) { \
3824 g_warning("can't allocate memory\n"); \
3827 g_snprintf(__tmp, len, "\"%s\"", str); \
3832 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3833 g_warning("can't allocate memory\n"); \
3836 strcpy(__tmp, str); \
3842 static void compose_select_account(Compose *compose, PrefsAccount *account,
3845 GtkItemFactory *ifactory;
3848 g_return_if_fail(account != NULL);
3850 compose->account = account;
3852 if (account->name && *account->name) {
3854 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
3855 from = g_strdup_printf("%s <%s>",
3856 buf, account->address);
3857 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3859 from = g_strdup_printf("<%s>",
3861 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3866 compose_set_title(compose);
3868 ifactory = gtk_item_factory_from_widget(compose->menubar);
3870 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3871 menu_set_active(ifactory, "/Options/Sign", TRUE);
3873 menu_set_active(ifactory, "/Options/Sign", FALSE);
3874 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3875 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3877 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3879 activate_privacy_system(compose, account, FALSE);
3881 if (!init && compose->mode != COMPOSE_REDIRECT)
3882 compose_insert_sig(compose, TRUE);
3885 gboolean compose_check_for_valid_recipient(Compose *compose) {
3886 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3887 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3888 gboolean recipient_found = FALSE;
3892 /* free to and newsgroup list */
3893 slist_free_strings(compose->to_list);
3894 g_slist_free(compose->to_list);
3895 compose->to_list = NULL;
3897 slist_free_strings(compose->newsgroup_list);
3898 g_slist_free(compose->newsgroup_list);
3899 compose->newsgroup_list = NULL;
3901 /* search header entries for to and newsgroup entries */
3902 for (list = compose->header_list; list; list = list->next) {
3905 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3906 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3908 if (entry[0] != '\0') {
3909 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3910 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3911 compose->to_list = address_list_append(compose->to_list, entry);
3912 recipient_found = TRUE;
3915 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3916 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3917 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3918 recipient_found = TRUE;
3925 return recipient_found;
3928 static gboolean compose_check_for_set_recipients(Compose *compose)
3930 if (compose->account->set_autocc && compose->account->auto_cc) {
3931 gboolean found_other = FALSE;
3933 /* search header entries for to and newsgroup entries */
3934 for (list = compose->header_list; list; list = list->next) {
3937 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3938 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3940 if (strcmp(entry, compose->account->auto_cc)
3941 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3951 if (compose->batch) {
3952 gtk_widget_show_all(compose->window);
3954 aval = alertpanel(_("Send"),
3955 _("The only recipient is the default CC address. Send anyway?"),
3956 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3957 if (aval != G_ALERTALTERNATE)
3961 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3962 gboolean found_other = FALSE;
3964 /* search header entries for to and newsgroup entries */
3965 for (list = compose->header_list; list; list = list->next) {
3968 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3969 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3971 if (strcmp(entry, compose->account->auto_cc)
3972 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3982 if (compose->batch) {
3983 gtk_widget_show_all(compose->window);
3985 aval = alertpanel(_("Send"),
3986 _("The only recipient is the default BCC address. Send anyway?"),
3987 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3988 if (aval != G_ALERTALTERNATE)
3995 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3999 if (compose_check_for_valid_recipient(compose) == FALSE) {
4000 if (compose->batch) {
4001 gtk_widget_show_all(compose->window);
4003 alertpanel_error(_("Recipient is not specified."));
4007 if (compose_check_for_set_recipients(compose) == FALSE) {
4011 if (!compose->batch) {
4012 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4013 if (*str == '\0' && check_subject == TRUE) {
4016 aval = alertpanel(_("Send"),
4017 _("Subject is empty. Send it anyway?"),
4018 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4019 if (aval != G_ALERTALTERNATE)
4027 gint compose_send(Compose *compose)
4030 FolderItem *folder = NULL;
4032 gchar *msgpath = NULL;
4033 gboolean discard_window = FALSE;
4034 gchar *errstr = NULL;
4035 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4036 || compose->batch == TRUE)
4037 discard_window = TRUE;
4039 compose_allow_user_actions (compose, FALSE);
4040 compose->sending = TRUE;
4042 if (compose_check_entries(compose, TRUE) == FALSE) {
4043 if (compose->batch) {
4044 gtk_widget_show_all(compose->window);
4049 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
4052 if (compose->batch) {
4053 gtk_widget_show_all(compose->window);
4056 alertpanel_error(_("Could not queue message for sending:\n\n"
4057 "Charset conversion failed."));
4058 } else if (val == -3) {
4059 alertpanel_error(_("Could not queue message for sending:\n\n"
4060 "Signature failed: %s"), privacy_get_error());
4061 } else if (val == -2 && errno != 0) {
4062 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4064 alertpanel_error(_("Could not queue message for sending."));
4069 if (discard_window) {
4070 compose->sending = FALSE;
4071 compose_close(compose);
4072 /* No more compose access in the normal codepath
4073 * after this point! */
4078 alertpanel_error(_("The message was queued but could not be "
4079 "sent.\nUse \"Send queued messages\" from "
4080 "the main window to retry."));
4081 if (!discard_window) {
4087 if (msgpath == NULL) {
4088 msgpath = folder_item_fetch_msg(folder, msgnum);
4089 val = procmsg_send_message_queue(msgpath, &errstr);
4092 val = procmsg_send_message_queue(msgpath, &errstr);
4096 if (!discard_window) {
4097 compose->sending = FALSE;
4098 compose_allow_user_actions (compose, TRUE);
4100 folder_item_remove_msg(folder, msgnum);
4101 folder_item_scan(folder);
4106 folder_item_remove_msg(folder, msgnum);
4107 folder_item_scan(folder);
4108 if (!discard_window)
4109 compose_close(compose);
4112 gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
4113 "the main window to retry."), errstr);
4115 alertpanel_error_log(tmp);
4118 alertpanel_error_log(_("The message was queued but could not be "
4119 "sent.\nUse \"Send queued messages\" from "
4120 "the main window to retry."));
4122 if (!discard_window) {
4131 compose_allow_user_actions (compose, TRUE);
4132 compose->sending = FALSE;
4133 compose->modified = TRUE;
4138 static gboolean compose_use_attach(Compose *compose)
4140 GtkTreeModel *model = gtk_tree_view_get_model
4141 (GTK_TREE_VIEW(compose->attach_clist));
4142 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4145 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4148 gchar buf[BUFFSIZE];
4150 gboolean first_to_address;
4151 gboolean first_cc_address;
4153 ComposeHeaderEntry *headerentry;
4154 const gchar *headerentryname;
4158 debug_print("Writing redirect header\n");
4160 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4161 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4163 first_to_address = TRUE;
4164 for (list = compose->header_list; list; list = list->next) {
4165 headerentry = ((ComposeHeaderEntry *)list->data);
4166 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4168 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4169 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4170 Xstrdup_a(str, entstr, return -1);
4172 if (str[0] != '\0') {
4173 compose_convert_header
4174 (compose, buf, sizeof(buf), str,
4175 strlen("Resent-To") + 2, TRUE);
4177 if (first_to_address) {
4178 fprintf(fp, "Resent-To: ");
4179 first_to_address = FALSE;
4183 fprintf(fp, "%s", buf);
4187 if (!first_to_address) {
4191 first_cc_address = TRUE;
4192 for (list = compose->header_list; list; list = list->next) {
4193 headerentry = ((ComposeHeaderEntry *)list->data);
4194 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4196 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4197 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4198 Xstrdup_a(str, strg, return -1);
4200 if (str[0] != '\0') {
4201 compose_convert_header
4202 (compose, buf, sizeof(buf), str,
4203 strlen("Resent-Cc") + 2, TRUE);
4205 if (first_cc_address) {
4206 fprintf(fp, "Resent-Cc: ");
4207 first_cc_address = FALSE;
4211 fprintf(fp, "%s", buf);
4215 if (!first_cc_address) {
4222 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4224 gchar buf[BUFFSIZE];
4226 const gchar *entstr;
4227 /* struct utsname utsbuf; */
4229 g_return_val_if_fail(fp != NULL, -1);
4230 g_return_val_if_fail(compose->account != NULL, -1);
4231 g_return_val_if_fail(compose->account->address != NULL, -1);
4234 get_rfc822_date(buf, sizeof(buf));
4235 fprintf(fp, "Resent-Date: %s\n", buf);
4238 if (compose->account->name && *compose->account->name) {
4239 compose_convert_header
4240 (compose, buf, sizeof(buf), compose->account->name,
4241 strlen("From: "), TRUE);
4242 fprintf(fp, "Resent-From: %s <%s>\n",
4243 buf, compose->account->address);
4245 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4248 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4249 if (*entstr != '\0') {
4250 Xstrdup_a(str, entstr, return -1);
4253 compose_convert_header(compose, buf, sizeof(buf), str,
4254 strlen("Subject: "), FALSE);
4255 fprintf(fp, "Subject: %s\n", buf);
4259 /* Resent-Message-ID */
4260 if (compose->account->gen_msgid) {
4261 generate_msgid(buf, sizeof(buf));
4262 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4263 compose->msgid = g_strdup(buf);
4266 compose_redirect_write_headers_from_headerlist(compose, fp);
4268 /* separator between header and body */
4274 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4278 gchar buf[BUFFSIZE];
4280 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4281 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4285 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4286 /* should filter returnpath, delivered-to */
4287 if (g_ascii_strncasecmp(buf, "Return-Path:",
4288 strlen("Return-Path:")) == 0 ||
4289 g_ascii_strncasecmp(buf, "Delivered-To:",
4290 strlen("Delivered-To:")) == 0 ||
4291 g_ascii_strncasecmp(buf, "Received:",
4292 strlen("Received:")) == 0 ||
4293 g_ascii_strncasecmp(buf, "Subject:",
4294 strlen("Subject:")) == 0 ||
4295 g_ascii_strncasecmp(buf, "X-UIDL:",
4296 strlen("X-UIDL:")) == 0)
4299 if (fputs(buf, fdest) == -1)
4302 if (!prefs_common.redirect_keep_from) {
4303 if (g_ascii_strncasecmp(buf, "From:",
4304 strlen("From:")) == 0) {
4305 fputs(" (by way of ", fdest);
4306 if (compose->account->name
4307 && *compose->account->name) {
4308 compose_convert_header
4309 (compose, buf, sizeof(buf),
4310 compose->account->name,
4313 fprintf(fdest, "%s <%s>",
4315 compose->account->address);
4317 fprintf(fdest, "%s",
4318 compose->account->address);
4323 if (fputs("\n", fdest) == -1)
4327 compose_redirect_write_headers(compose, fdest);
4329 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4330 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4343 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
4345 GtkTextBuffer *buffer;
4346 GtkTextIter start, end;
4349 const gchar *out_codeset;
4350 EncodingType encoding;
4351 MimeInfo *mimemsg, *mimetext;
4354 if (action == COMPOSE_WRITE_FOR_SEND)
4355 attach_parts = TRUE;
4357 /* create message MimeInfo */
4358 mimemsg = procmime_mimeinfo_new();
4359 mimemsg->type = MIMETYPE_MESSAGE;
4360 mimemsg->subtype = g_strdup("rfc822");
4361 mimemsg->content = MIMECONTENT_MEM;
4362 mimemsg->tmp = TRUE; /* must free content later */
4363 mimemsg->data.mem = compose_get_header(compose);
4365 /* Create text part MimeInfo */
4366 /* get all composed text */
4367 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4368 gtk_text_buffer_get_start_iter(buffer, &start);
4369 gtk_text_buffer_get_end_iter(buffer, &end);
4370 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4371 if (is_ascii_str(chars)) {
4374 out_codeset = CS_US_ASCII;
4375 encoding = ENC_7BIT;
4377 const gchar *src_codeset = CS_INTERNAL;
4379 out_codeset = conv_get_charset_str(compose->out_encoding);
4382 gchar *test_conv_global_out = NULL;
4383 gchar *test_conv_reply = NULL;
4385 /* automatic mode. be automatic. */
4386 codeconv_set_strict(TRUE);
4388 out_codeset = conv_get_outgoing_charset_str();
4390 debug_print("trying to convert to %s\n", out_codeset);
4391 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4394 if (!test_conv_global_out && compose->orig_charset
4395 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4396 out_codeset = compose->orig_charset;
4397 debug_print("failure; trying to convert to %s\n", out_codeset);
4398 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4401 if (!test_conv_global_out && !test_conv_reply) {
4403 out_codeset = CS_INTERNAL;
4404 debug_print("failure; finally using %s\n", out_codeset);
4406 g_free(test_conv_global_out);
4407 g_free(test_conv_reply);
4408 codeconv_set_strict(FALSE);
4411 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4412 out_codeset = CS_ISO_8859_1;
4414 if (prefs_common.encoding_method == CTE_BASE64)
4415 encoding = ENC_BASE64;
4416 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4417 encoding = ENC_QUOTED_PRINTABLE;
4418 else if (prefs_common.encoding_method == CTE_8BIT)
4419 encoding = ENC_8BIT;
4421 encoding = procmime_get_encoding_for_charset(out_codeset);
4423 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4424 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4426 if (action == COMPOSE_WRITE_FOR_SEND) {
4427 codeconv_set_strict(TRUE);
4428 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4429 codeconv_set_strict(FALSE);
4435 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4436 "to the specified %s charset.\n"
4437 "Send it as %s?"), out_codeset, src_codeset);
4438 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4439 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4442 if (aval != G_ALERTALTERNATE) {
4447 out_codeset = src_codeset;
4453 out_codeset = src_codeset;
4459 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4460 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4461 strstr(buf, "\nFrom ") != NULL) {
4462 encoding = ENC_QUOTED_PRINTABLE;
4466 mimetext = procmime_mimeinfo_new();
4467 mimetext->content = MIMECONTENT_MEM;
4468 mimetext->tmp = TRUE; /* must free content later */
4469 mimetext->data.mem = buf;
4470 mimetext->type = MIMETYPE_TEXT;
4471 mimetext->subtype = g_strdup("plain");
4472 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4473 g_strdup(out_codeset));
4474 /* protect trailing spaces when signing message */
4475 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4476 privacy_system_can_sign(compose->privacy_system)) {
4477 encoding = ENC_QUOTED_PRINTABLE;
4480 /* check for line length limit */
4481 if (action == COMPOSE_WRITE_FOR_SEND &&
4482 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4483 check_line_length(buf, 1000, &line) < 0) {
4487 msg = g_strdup_printf
4488 (_("Line %d exceeds the line length limit (998 bytes).\n"
4489 "The contents of the message might be broken on the way to the delivery.\n"
4491 "Send it anyway?"), line + 1);
4492 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4494 if (aval != G_ALERTALTERNATE) {
4499 if (encoding != ENC_UNKNOWN)
4500 procmime_encode_content(mimetext, encoding);
4502 /* append attachment parts */
4503 if (compose_use_attach(compose) && attach_parts) {
4504 MimeInfo *mimempart;
4505 gchar *boundary = NULL;
4506 mimempart = procmime_mimeinfo_new();
4507 mimempart->content = MIMECONTENT_EMPTY;
4508 mimempart->type = MIMETYPE_MULTIPART;
4509 mimempart->subtype = g_strdup("mixed");
4513 boundary = generate_mime_boundary(NULL);
4514 } while (strstr(buf, boundary) != NULL);
4516 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4519 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4521 g_node_append(mimempart->node, mimetext->node);
4522 g_node_append(mimemsg->node, mimempart->node);
4524 compose_add_attachments(compose, mimempart);
4526 g_node_append(mimemsg->node, mimetext->node);
4528 /* sign message if sending */
4529 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4530 privacy_system_can_sign(compose->privacy_system))
4531 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4534 procmime_write_mimeinfo(mimemsg, fp);
4536 procmime_mimeinfo_free_all(mimemsg);
4541 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4543 GtkTextBuffer *buffer;
4544 GtkTextIter start, end;
4549 if ((fp = g_fopen(file, "wb")) == NULL) {
4550 FILE_OP_ERROR(file, "fopen");
4554 /* chmod for security */
4555 if (change_file_mode_rw(fp, file) < 0) {
4556 FILE_OP_ERROR(file, "chmod");
4557 g_warning("can't change file mode\n");
4560 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4561 gtk_text_buffer_get_start_iter(buffer, &start);
4562 gtk_text_buffer_get_end_iter(buffer, &end);
4563 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4565 chars = conv_codeset_strdup
4566 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4569 if (!chars) return -1;
4572 len = strlen(chars);
4573 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4574 FILE_OP_ERROR(file, "fwrite");
4583 if (fclose(fp) == EOF) {
4584 FILE_OP_ERROR(file, "fclose");
4591 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4594 MsgInfo *msginfo = compose->targetinfo;
4596 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4597 if (!msginfo) return -1;
4599 if (!force && MSG_IS_LOCKED(msginfo->flags))
4602 item = msginfo->folder;
4603 g_return_val_if_fail(item != NULL, -1);
4605 if (procmsg_msg_exist(msginfo) &&
4606 (folder_has_parent_of_type(item, F_QUEUE) ||
4607 folder_has_parent_of_type(item, F_DRAFT)
4608 || msginfo == compose->autosaved_draft)) {
4609 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4610 g_warning("can't remove the old message\n");
4618 void compose_remove_draft(Compose *compose)
4621 MsgInfo *msginfo = compose->targetinfo;
4622 drafts = account_get_special_folder(compose->account, F_DRAFT);
4624 if (procmsg_msg_exist(msginfo)) {
4625 folder_item_remove_msg(drafts, msginfo->msgnum);
4630 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
4631 gboolean remove_reedit_target)
4633 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
4635 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
4636 gchar **msgpath, gboolean check_subject,
4637 gboolean remove_reedit_target)
4644 static gboolean lock = FALSE;
4645 PrefsAccount *mailac = NULL, *newsac = NULL;
4647 debug_print("queueing message...\n");
4648 g_return_val_if_fail(compose->account != NULL, -1);
4652 if (compose_check_entries(compose, check_subject) == FALSE) {
4654 if (compose->batch) {
4655 gtk_widget_show_all(compose->window);
4660 if (!compose->to_list && !compose->newsgroup_list) {
4661 g_warning("can't get recipient list.");
4666 if (compose->to_list) {
4667 if (compose->account->protocol != A_NNTP)
4668 mailac = compose->account;
4669 else if (cur_account && cur_account->protocol != A_NNTP)
4670 mailac = cur_account;
4671 else if (!(mailac = compose_current_mail_account())) {
4673 alertpanel_error(_("No account for sending mails available!"));
4678 if (compose->newsgroup_list) {
4679 if (compose->account->protocol == A_NNTP)
4680 newsac = compose->account;
4681 else if (!newsac->protocol != A_NNTP) {
4683 alertpanel_error(_("No account for posting news available!"));
4688 /* write queue header */
4689 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4690 G_DIR_SEPARATOR, compose);
4691 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4692 FILE_OP_ERROR(tmp, "fopen");
4698 if (change_file_mode_rw(fp, tmp) < 0) {
4699 FILE_OP_ERROR(tmp, "chmod");
4700 g_warning("can't change file mode\n");
4703 /* queueing variables */
4704 fprintf(fp, "AF:\n");
4705 fprintf(fp, "NF:0\n");
4706 fprintf(fp, "PS:10\n");
4707 fprintf(fp, "SRH:1\n");
4708 fprintf(fp, "SFN:\n");
4709 fprintf(fp, "DSR:\n");
4711 fprintf(fp, "MID:<%s>\n", compose->msgid);
4713 fprintf(fp, "MID:\n");
4714 fprintf(fp, "CFG:\n");
4715 fprintf(fp, "PT:0\n");
4716 fprintf(fp, "S:%s\n", compose->account->address);
4717 fprintf(fp, "RQ:\n");
4719 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4721 fprintf(fp, "SSV:\n");
4723 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4725 fprintf(fp, "NSV:\n");
4726 fprintf(fp, "SSH:\n");
4727 /* write recepient list */
4728 if (compose->to_list) {
4729 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4730 for (cur = compose->to_list->next; cur != NULL;
4732 fprintf(fp, ",<%s>", (gchar *)cur->data);
4735 /* write newsgroup list */
4736 if (compose->newsgroup_list) {
4738 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4739 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4740 fprintf(fp, ",%s", (gchar *)cur->data);
4743 /* Sylpheed account IDs */
4745 fprintf(fp, "MAID:%d\n", mailac->account_id);
4747 fprintf(fp, "NAID:%d\n", newsac->account_id);
4750 if (compose->privacy_system != NULL) {
4751 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4752 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4753 if (compose->use_encryption) {
4755 if (mailac && mailac->encrypt_to_self) {
4756 GSList *tmp_list = g_slist_copy(compose->to_list);
4757 tmp_list = g_slist_append(tmp_list, compose->account->address);
4758 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
4759 g_slist_free(tmp_list);
4761 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4763 if (encdata != NULL) {
4764 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4765 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4766 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4768 } /* else we finally dont want to encrypt */
4770 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4771 /* and if encdata was null, it means there's been a problem in
4778 /* Save copy folder */
4779 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4780 gchar *savefolderid;
4782 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4783 fprintf(fp, "SCF:%s\n", savefolderid);
4784 g_free(savefolderid);
4786 /* Save copy folder */
4787 if (compose->return_receipt) {
4788 fprintf(fp, "RRCPT:1\n");
4790 /* Message-ID of message replying to */
4791 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4794 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4795 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4798 /* Message-ID of message forwarding to */
4799 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4802 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4803 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4807 /* end of headers */
4808 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
4810 if (compose->redirect_filename != NULL) {
4811 if (compose_redirect_write_to_file(compose, fp) < 0) {
4820 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
4825 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4829 if (fclose(fp) == EOF) {
4830 FILE_OP_ERROR(tmp, "fclose");
4837 if (item && *item) {
4840 queue = account_get_special_folder(compose->account, F_QUEUE);
4843 g_warning("can't find queue folder\n");
4849 folder_item_scan(queue);
4850 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4851 g_warning("can't queue the message\n");
4858 if (msgpath == NULL) {
4864 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
4865 compose_remove_reedit_target(compose, FALSE);
4868 if ((msgnum != NULL) && (item != NULL)) {
4876 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4879 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4881 struct stat statbuf;
4882 gchar *type, *subtype;
4883 GtkTreeModel *model;
4886 model = gtk_tree_view_get_model(tree_view);
4888 if (!gtk_tree_model_get_iter_first(model, &iter))
4891 gtk_tree_model_get(model, &iter,
4895 mimepart = procmime_mimeinfo_new();
4896 mimepart->content = MIMECONTENT_FILE;
4897 mimepart->data.filename = g_strdup(ainfo->file);
4898 mimepart->tmp = FALSE; /* or we destroy our attachment */
4899 mimepart->offset = 0;
4901 stat(ainfo->file, &statbuf);
4902 mimepart->length = statbuf.st_size;
4904 type = g_strdup(ainfo->content_type);
4906 if (!strchr(type, '/')) {
4908 type = g_strdup("application/octet-stream");
4911 subtype = strchr(type, '/') + 1;
4912 *(subtype - 1) = '\0';
4913 mimepart->type = procmime_get_media_type(type);
4914 mimepart->subtype = g_strdup(subtype);
4917 if (mimepart->type == MIMETYPE_MESSAGE &&
4918 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4919 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4921 g_hash_table_insert(mimepart->typeparameters,
4922 g_strdup("name"), g_strdup(ainfo->name));
4923 g_hash_table_insert(mimepart->dispositionparameters,
4924 g_strdup("filename"), g_strdup(ainfo->name));
4925 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4928 if (compose->use_signing) {
4929 if (ainfo->encoding == ENC_7BIT)
4930 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4931 else if (ainfo->encoding == ENC_8BIT)
4932 ainfo->encoding = ENC_BASE64;
4935 procmime_encode_content(mimepart, ainfo->encoding);
4937 g_node_append(parent->node, mimepart->node);
4938 } while (gtk_tree_model_iter_next(model, &iter));
4941 #define IS_IN_CUSTOM_HEADER(header) \
4942 (compose->account->add_customhdr && \
4943 custom_header_find(compose->account->customhdr_list, header) != NULL)
4945 static void compose_add_headerfield_from_headerlist(Compose *compose,
4947 const gchar *fieldname,
4948 const gchar *seperator)
4950 gchar *str, *fieldname_w_colon, *trans_fieldname;
4951 gboolean add_field = FALSE;
4953 ComposeHeaderEntry *headerentry;
4954 const gchar * headerentryname;
4957 if (IS_IN_CUSTOM_HEADER(fieldname))
4960 debug_print("Adding %s-fields\n", fieldname);
4962 fieldstr = g_string_sized_new(64);
4964 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4965 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4967 for (list = compose->header_list; list; list = list->next) {
4968 headerentry = ((ComposeHeaderEntry *)list->data);
4969 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4971 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4972 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4974 if (str[0] != '\0') {
4976 g_string_append(fieldstr, seperator);
4977 g_string_append(fieldstr, str);
4986 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4987 compose_convert_header
4988 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4989 strlen(fieldname) + 2, TRUE);
4990 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4994 g_free(fieldname_w_colon);
4995 g_string_free(fieldstr, TRUE);
5000 static gchar *compose_get_header(Compose *compose)
5002 gchar buf[BUFFSIZE];
5003 const gchar *entry_str;
5007 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5009 gchar *from_name = NULL, *from_address = NULL;
5012 g_return_val_if_fail(compose->account != NULL, NULL);
5013 g_return_val_if_fail(compose->account->address != NULL, NULL);
5015 header = g_string_sized_new(64);
5018 get_rfc822_date(buf, sizeof(buf));
5019 g_string_append_printf(header, "Date: %s\n", buf);
5023 if (compose->account->name && *compose->account->name) {
5025 QUOTE_IF_REQUIRED(buf, compose->account->name);
5026 tmp = g_strdup_printf("%s <%s>",
5027 buf, compose->account->address);
5029 tmp = g_strdup_printf("%s",
5030 compose->account->address);
5032 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5033 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5035 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5036 from_address = g_strdup(compose->account->address);
5038 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5039 /* extract name and address */
5040 if (strstr(spec, " <") && strstr(spec, ">")) {
5041 from_address = g_strdup(strrchr(spec, '<')+1);
5042 *(strrchr(from_address, '>')) = '\0';
5043 from_name = g_strdup(spec);
5044 *(strrchr(from_name, '<')) = '\0';
5047 from_address = g_strdup(spec);
5054 if (from_name && *from_name) {
5055 compose_convert_header
5056 (compose, buf, sizeof(buf), from_name,
5057 strlen("From: "), TRUE);
5058 QUOTE_IF_REQUIRED(name, buf);
5060 g_string_append_printf(header, "From: %s <%s>\n",
5061 name, from_address);
5063 g_string_append_printf(header, "From: %s\n", from_address);
5066 g_free(from_address);
5069 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5072 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5075 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5078 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5081 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5083 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5086 compose_convert_header(compose, buf, sizeof(buf), str,
5087 strlen("Subject: "), FALSE);
5088 g_string_append_printf(header, "Subject: %s\n", buf);
5094 if (compose->account->gen_msgid) {
5095 generate_msgid(buf, sizeof(buf));
5096 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5097 compose->msgid = g_strdup(buf);
5100 if (compose->remove_references == FALSE) {
5102 if (compose->inreplyto && compose->to_list)
5103 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5106 if (compose->references)
5107 g_string_append_printf(header, "References: %s\n", compose->references);
5111 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5114 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5117 if (compose->account->organization &&
5118 strlen(compose->account->organization) &&
5119 !IS_IN_CUSTOM_HEADER("Organization")) {
5120 compose_convert_header(compose, buf, sizeof(buf),
5121 compose->account->organization,
5122 strlen("Organization: "), FALSE);
5123 g_string_append_printf(header, "Organization: %s\n", buf);
5126 /* Program version and system info */
5127 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5128 !compose->newsgroup_list) {
5129 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5131 gtk_major_version, gtk_minor_version, gtk_micro_version,
5134 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5135 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5137 gtk_major_version, gtk_minor_version, gtk_micro_version,
5141 /* custom headers */
5142 if (compose->account->add_customhdr) {
5145 for (cur = compose->account->customhdr_list; cur != NULL;
5147 CustomHeader *chdr = (CustomHeader *)cur->data;
5149 if (custom_header_is_allowed(chdr->name)) {
5150 compose_convert_header
5151 (compose, buf, sizeof(buf),
5152 chdr->value ? chdr->value : "",
5153 strlen(chdr->name) + 2, FALSE);
5154 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5160 switch (compose->priority) {
5161 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5162 "X-Priority: 1 (Highest)\n");
5164 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5165 "X-Priority: 2 (High)\n");
5167 case PRIORITY_NORMAL: break;
5168 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5169 "X-Priority: 4 (Low)\n");
5171 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5172 "X-Priority: 5 (Lowest)\n");
5174 default: debug_print("compose: priority unknown : %d\n",
5178 /* Request Return Receipt */
5179 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5180 if (compose->return_receipt) {
5181 if (compose->account->name
5182 && *compose->account->name) {
5183 compose_convert_header(compose, buf, sizeof(buf),
5184 compose->account->name,
5185 strlen("Disposition-Notification-To: "),
5187 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5189 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5193 /* get special headers */
5194 for (list = compose->header_list; list; list = list->next) {
5195 ComposeHeaderEntry *headerentry;
5198 gchar *headername_wcolon;
5199 gchar *headername_trans;
5202 gboolean standard_header = FALSE;
5204 headerentry = ((ComposeHeaderEntry *)list->data);
5206 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5207 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5212 if (!strstr(tmp, ":")) {
5213 headername_wcolon = g_strconcat(tmp, ":", NULL);
5214 headername = g_strdup(tmp);
5216 headername_wcolon = g_strdup(tmp);
5217 headername = g_strdup(strtok(tmp, ":"));
5221 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5222 Xstrdup_a(headervalue, entry_str, return NULL);
5223 subst_char(headervalue, '\r', ' ');
5224 subst_char(headervalue, '\n', ' ');
5225 string = std_headers;
5226 while (*string != NULL) {
5227 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5228 if (!strcmp(headername_trans,headername_wcolon))
5229 standard_header = TRUE;
5232 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5233 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5236 g_free(headername_wcolon);
5240 g_string_free(header, FALSE);
5245 #undef IS_IN_CUSTOM_HEADER
5247 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5248 gint header_len, gboolean addr_field)
5250 gchar *tmpstr = NULL;
5251 const gchar *out_codeset = NULL;
5253 g_return_if_fail(src != NULL);
5254 g_return_if_fail(dest != NULL);
5256 if (len < 1) return;
5258 tmpstr = g_strdup(src);
5260 subst_char(tmpstr, '\n', ' ');
5261 subst_char(tmpstr, '\r', ' ');
5264 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5265 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5266 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5271 codeconv_set_strict(TRUE);
5272 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5273 conv_get_charset_str(compose->out_encoding));
5274 codeconv_set_strict(FALSE);
5276 if (!dest || *dest == '\0') {
5277 gchar *test_conv_global_out = NULL;
5278 gchar *test_conv_reply = NULL;
5280 /* automatic mode. be automatic. */
5281 codeconv_set_strict(TRUE);
5283 out_codeset = conv_get_outgoing_charset_str();
5285 debug_print("trying to convert to %s\n", out_codeset);
5286 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5289 if (!test_conv_global_out && compose->orig_charset
5290 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5291 out_codeset = compose->orig_charset;
5292 debug_print("failure; trying to convert to %s\n", out_codeset);
5293 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5296 if (!test_conv_global_out && !test_conv_reply) {
5298 out_codeset = CS_INTERNAL;
5299 debug_print("finally using %s\n", out_codeset);
5301 g_free(test_conv_global_out);
5302 g_free(test_conv_reply);
5303 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5305 codeconv_set_strict(FALSE);
5310 static void compose_create_header_entry(Compose *compose)
5312 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5316 GList *combo_list = NULL;
5318 const gchar *header = NULL;
5319 ComposeHeaderEntry *headerentry;
5320 gboolean standard_header = FALSE;
5322 headerentry = g_new0(ComposeHeaderEntry, 1);
5325 combo = gtk_combo_new();
5327 while(*string != NULL) {
5328 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5331 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5332 g_list_free(combo_list);
5333 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5334 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5335 G_CALLBACK(compose_grab_focus_cb), compose);
5336 gtk_widget_show(combo);
5337 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5338 if (compose->header_last) {
5339 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5341 while (*string != NULL) {
5342 if (!strcmp(*string, last_header_entry))
5343 standard_header = TRUE;
5346 if (standard_header)
5347 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5349 if (!compose->header_last || !standard_header) {
5350 switch(compose->account->protocol) {
5352 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5355 header = prefs_common.trans_hdr ? _("To:") : "To:";
5360 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5362 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5363 G_CALLBACK(compose_grab_focus_cb), compose);
5366 entry = gtk_entry_new();
5367 gtk_widget_show(entry);
5368 gtk_tooltips_set_tip(compose->tooltips, entry,
5369 _("Use <tab> to autocomplete from addressbook"), NULL);
5370 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);
5372 g_signal_connect(G_OBJECT(entry), "key-press-event",
5373 G_CALLBACK(compose_headerentry_key_press_event_cb),
5375 g_signal_connect(G_OBJECT(entry), "changed",
5376 G_CALLBACK(compose_headerentry_changed_cb),
5378 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5379 G_CALLBACK(compose_grab_focus_cb), compose);
5382 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5383 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5384 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5385 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5386 G_CALLBACK(compose_header_drag_received_cb),
5388 g_signal_connect(G_OBJECT(entry), "drag-drop",
5389 G_CALLBACK(compose_drag_drop),
5392 address_completion_register_entry(GTK_ENTRY(entry));
5394 headerentry->compose = compose;
5395 headerentry->combo = combo;
5396 headerentry->entry = entry;
5397 headerentry->headernum = compose->header_nextrow;
5399 compose->header_nextrow++;
5400 compose->header_last = headerentry;
5403 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5405 ComposeHeaderEntry *last_header;
5407 last_header = compose->header_last;
5409 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5410 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5413 static GtkWidget *compose_create_header(Compose *compose)
5415 GtkWidget *from_optmenu_hbox;
5416 GtkWidget *header_scrolledwin;
5417 GtkWidget *header_table;
5421 /* header labels and entries */
5422 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5423 gtk_widget_show(header_scrolledwin);
5424 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5426 header_table = gtk_table_new(2, 2, FALSE);
5427 gtk_widget_show(header_table);
5428 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5429 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5430 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5433 /* option menu for selecting accounts */
5434 from_optmenu_hbox = compose_account_option_menu_create(compose);
5435 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5436 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5439 compose->header_table = header_table;
5440 compose->header_list = NULL;
5441 compose->header_nextrow = count;
5443 compose_create_header_entry(compose);
5445 compose->table = NULL;
5447 return header_scrolledwin ;
5450 GtkWidget *compose_create_attach(Compose *compose)
5452 GtkWidget *attach_scrwin;
5453 GtkWidget *attach_clist;
5455 GtkListStore *store;
5456 GtkCellRenderer *renderer;
5457 GtkTreeViewColumn *column;
5458 GtkTreeSelection *selection;
5460 /* attachment list */
5461 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5462 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5463 GTK_POLICY_AUTOMATIC,
5464 GTK_POLICY_AUTOMATIC);
5465 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5467 store = gtk_list_store_new(N_ATTACH_COLS,
5472 G_TYPE_AUTO_POINTER,
5474 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5475 (GTK_TREE_MODEL(store)));
5476 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5477 g_object_unref(store);
5479 renderer = gtk_cell_renderer_text_new();
5480 column = gtk_tree_view_column_new_with_attributes
5481 (_("Mime type"), renderer, "text",
5482 COL_MIMETYPE, NULL);
5483 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5485 renderer = gtk_cell_renderer_text_new();
5486 column = gtk_tree_view_column_new_with_attributes
5487 (_("Size"), renderer, "text",
5489 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5491 renderer = gtk_cell_renderer_text_new();
5492 column = gtk_tree_view_column_new_with_attributes
5493 (_("Name"), renderer, "text",
5495 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5497 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5498 prefs_common.enable_rules_hint);
5499 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5500 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5502 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5503 G_CALLBACK(attach_selected), compose);
5504 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5505 G_CALLBACK(attach_button_pressed), compose);
5506 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5507 G_CALLBACK(attach_key_pressed), compose);
5510 gtk_drag_dest_set(attach_clist,
5511 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5512 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5513 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5514 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5515 G_CALLBACK(compose_attach_drag_received_cb),
5517 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5518 G_CALLBACK(compose_drag_drop),
5521 compose->attach_scrwin = attach_scrwin;
5522 compose->attach_clist = attach_clist;
5524 return attach_scrwin;
5527 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5528 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5530 static GtkWidget *compose_create_others(Compose *compose)
5533 GtkWidget *savemsg_checkbtn;
5534 GtkWidget *savemsg_entry;
5535 GtkWidget *savemsg_select;
5538 gchar *folderidentifier;
5540 /* Table for settings */
5541 table = gtk_table_new(3, 1, FALSE);
5542 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5543 gtk_widget_show(table);
5544 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5547 /* Save Message to folder */
5548 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5549 gtk_widget_show(savemsg_checkbtn);
5550 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5551 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5552 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5554 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5555 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5557 savemsg_entry = gtk_entry_new();
5558 gtk_widget_show(savemsg_entry);
5559 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5560 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5561 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5562 G_CALLBACK(compose_grab_focus_cb), compose);
5563 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5564 folderidentifier = folder_item_get_identifier(account_get_special_folder
5565 (compose->account, F_OUTBOX));
5566 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5567 g_free(folderidentifier);
5570 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5571 gtk_widget_show(savemsg_select);
5572 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5573 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5574 G_CALLBACK(compose_savemsg_select_cb),
5579 compose->savemsg_checkbtn = savemsg_checkbtn;
5580 compose->savemsg_entry = savemsg_entry;
5585 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5587 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5588 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5591 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5596 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5599 path = folder_item_get_identifier(dest);
5601 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5605 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5606 GdkAtom clip, GtkTextIter *insert_place);
5608 #define BLOCK_WRAP() { \
5609 prev_autowrap = compose->autowrap; \
5610 buffer = gtk_text_view_get_buffer( \
5611 GTK_TEXT_VIEW(compose->text)); \
5612 compose->autowrap = FALSE; \
5614 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5615 G_CALLBACK(compose_changed_cb), \
5617 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5618 G_CALLBACK(text_inserted), \
5621 #define UNBLOCK_WRAP() { \
5622 compose->autowrap = prev_autowrap; \
5623 if (compose->autowrap) \
5624 compose_wrap_all(compose); \
5626 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5627 G_CALLBACK(compose_changed_cb), \
5629 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5630 G_CALLBACK(text_inserted), \
5635 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5639 GtkTextBuffer *buffer;
5641 if (event->button == 3) {
5643 GtkTextIter sel_start, sel_end;
5644 gboolean stuff_selected;
5646 /* move the cursor to allow GtkAspell to check the word
5647 * under the mouse */
5648 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5649 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5651 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5654 stuff_selected = gtk_text_buffer_get_selection_bounds(
5655 GTK_TEXT_VIEW(text)->buffer,
5656 &sel_start, &sel_end);
5658 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5659 /* reselect stuff */
5661 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5662 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5663 &sel_start, &sel_end);
5665 return FALSE; /* pass the event so that the right-click goes through */
5668 if (event->button == 2) {
5673 /* get the middle-click position to paste at the correct place */
5674 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5675 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5677 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5680 entry_paste_clipboard(compose, text,
5681 prefs_common.linewrap_pastes,
5682 GDK_SELECTION_PRIMARY, &iter);
5690 static void compose_spell_menu_changed(void *data)
5692 Compose *compose = (Compose *)data;
5694 GtkWidget *menuitem;
5695 GtkWidget *parent_item;
5696 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5697 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5700 if (compose->gtkaspell == NULL)
5703 parent_item = gtk_item_factory_get_item(ifactory,
5704 "/Spelling/Options");
5706 /* setting the submenu removes /Spelling/Options from the factory
5707 * so we need to save it */
5709 if (parent_item == NULL) {
5710 parent_item = compose->aspell_options_menu;
5711 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5713 compose->aspell_options_menu = parent_item;
5715 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5717 spell_menu = g_slist_reverse(spell_menu);
5718 for (items = spell_menu;
5719 items; items = items->next) {
5720 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
5721 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5722 gtk_widget_show(GTK_WIDGET(menuitem));
5724 g_slist_free(spell_menu);
5726 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
5731 static gboolean compose_force_window_origin = TRUE;
5732 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5739 GtkWidget *handlebox;
5741 GtkWidget *notebook;
5746 GtkWidget *subject_hbox;
5747 GtkWidget *subject_frame;
5748 GtkWidget *subject_entry;
5752 GtkWidget *edit_vbox;
5753 GtkWidget *ruler_hbox;
5755 GtkWidget *scrolledwin;
5757 GtkTextBuffer *buffer;
5758 GtkClipboard *clipboard;
5760 UndoMain *undostruct;
5762 gchar *titles[N_ATTACH_COLS];
5763 guint n_menu_entries;
5764 GtkWidget *popupmenu;
5765 GtkItemFactory *popupfactory;
5766 GtkItemFactory *ifactory;
5767 GtkWidget *tmpl_menu;
5769 GtkWidget *menuitem;
5772 GtkAspell * gtkaspell = NULL;
5775 static GdkGeometry geometry;
5777 g_return_val_if_fail(account != NULL, NULL);
5779 debug_print("Creating compose window...\n");
5780 compose = g_new0(Compose, 1);
5782 titles[COL_MIMETYPE] = _("MIME type");
5783 titles[COL_SIZE] = _("Size");
5784 titles[COL_NAME] = _("Name");
5786 compose->batch = batch;
5787 compose->account = account;
5789 compose->mutex = g_mutex_new();
5790 compose->set_cursor_pos = -1;
5792 compose->tooltips = gtk_tooltips_new();
5794 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5795 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5796 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5798 if (!geometry.max_width) {
5799 geometry.max_width = gdk_screen_width();
5800 geometry.max_height = gdk_screen_height();
5803 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5804 &geometry, GDK_HINT_MAX_SIZE);
5805 if (!geometry.min_width) {
5806 geometry.min_width = 600;
5807 geometry.min_height = 480;
5809 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5810 &geometry, GDK_HINT_MIN_SIZE);
5812 if (compose_force_window_origin)
5813 gtk_widget_set_uposition(window, prefs_common.compose_x,
5814 prefs_common.compose_y);
5816 g_signal_connect(G_OBJECT(window), "delete_event",
5817 G_CALLBACK(compose_delete_cb), compose);
5818 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5819 gtk_widget_realize(window);
5821 gtkut_widget_set_composer_icon(window);
5823 vbox = gtk_vbox_new(FALSE, 0);
5824 gtk_container_add(GTK_CONTAINER(window), vbox);
5826 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5827 menubar = menubar_create(window, compose_entries,
5828 n_menu_entries, "<Compose>", compose);
5829 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5831 if (prefs_common.toolbar_detachable) {
5832 handlebox = gtk_handle_box_new();
5834 handlebox = gtk_hbox_new(FALSE, 0);
5836 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5838 gtk_widget_realize(handlebox);
5839 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5842 vbox2 = gtk_vbox_new(FALSE, 2);
5843 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5844 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5847 notebook = gtk_notebook_new();
5848 gtk_widget_set_size_request(notebook, -1, 130);
5849 gtk_widget_show(notebook);
5851 /* header labels and entries */
5852 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5853 compose_create_header(compose),
5854 gtk_label_new_with_mnemonic(_("Hea_der")));
5855 /* attachment list */
5856 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5857 compose_create_attach(compose),
5858 gtk_label_new_with_mnemonic(_("_Attachments")));
5860 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5861 compose_create_others(compose),
5862 gtk_label_new_with_mnemonic(_("Othe_rs")));
5865 subject_hbox = gtk_hbox_new(FALSE, 0);
5866 gtk_widget_show(subject_hbox);
5868 subject_frame = gtk_frame_new(NULL);
5869 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5870 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5871 gtk_widget_show(subject_frame);
5873 subject = gtk_hbox_new(FALSE, 0);
5874 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5875 gtk_widget_show(subject);
5877 label = gtk_label_new(_("Subject:"));
5878 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5879 gtk_widget_show(label);
5881 subject_entry = gtk_entry_new();
5882 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5883 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5884 G_CALLBACK(compose_grab_focus_cb), compose);
5885 gtk_widget_show(subject_entry);
5886 compose->subject_entry = subject_entry;
5887 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5889 edit_vbox = gtk_vbox_new(FALSE, 0);
5891 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5894 ruler_hbox = gtk_hbox_new(FALSE, 0);
5895 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5897 ruler = gtk_shruler_new();
5898 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5899 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5903 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5904 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5905 GTK_POLICY_AUTOMATIC,
5906 GTK_POLICY_AUTOMATIC);
5907 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5909 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5910 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5912 text = gtk_text_view_new();
5913 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5914 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5915 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5916 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5917 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5919 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5921 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5922 G_CALLBACK(compose_edit_size_alloc),
5924 g_signal_connect(G_OBJECT(buffer), "changed",
5925 G_CALLBACK(compose_changed_cb), compose);
5926 g_signal_connect(G_OBJECT(text), "grab_focus",
5927 G_CALLBACK(compose_grab_focus_cb), compose);
5928 g_signal_connect(G_OBJECT(buffer), "insert_text",
5929 G_CALLBACK(text_inserted), compose);
5930 g_signal_connect(G_OBJECT(text), "button_press_event",
5931 G_CALLBACK(text_clicked), compose);
5932 g_signal_connect(G_OBJECT(subject_entry), "changed",
5933 G_CALLBACK(compose_changed_cb), compose);
5936 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5937 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5938 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5939 g_signal_connect(G_OBJECT(text), "drag_data_received",
5940 G_CALLBACK(compose_insert_drag_received_cb),
5942 g_signal_connect(G_OBJECT(text), "drag-drop",
5943 G_CALLBACK(compose_drag_drop),
5945 gtk_widget_show_all(vbox);
5947 /* pane between attach clist and text */
5948 paned = gtk_vpaned_new();
5949 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5950 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5951 gtk_paned_add1(GTK_PANED(paned), notebook);
5952 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5953 gtk_widget_show_all(paned);
5956 if (prefs_common.textfont) {
5957 PangoFontDescription *font_desc;
5959 font_desc = pango_font_description_from_string
5960 (prefs_common.textfont);
5962 gtk_widget_modify_font(text, font_desc);
5963 pango_font_description_free(font_desc);
5967 n_entries = sizeof(compose_popup_entries) /
5968 sizeof(compose_popup_entries[0]);
5969 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5970 "<Compose>", &popupfactory,
5973 ifactory = gtk_item_factory_from_widget(menubar);
5974 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5975 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5976 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5978 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5980 undostruct = undo_init(text);
5981 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5984 address_completion_start(window);
5986 compose->window = window;
5987 compose->vbox = vbox;
5988 compose->menubar = menubar;
5989 compose->handlebox = handlebox;
5991 compose->vbox2 = vbox2;
5993 compose->paned = paned;
5995 compose->edit_vbox = edit_vbox;
5996 compose->ruler_hbox = ruler_hbox;
5997 compose->ruler = ruler;
5998 compose->scrolledwin = scrolledwin;
5999 compose->text = text;
6001 compose->focused_editable = NULL;
6003 compose->popupmenu = popupmenu;
6004 compose->popupfactory = popupfactory;
6006 compose->tmpl_menu = tmpl_menu;
6008 compose->mode = mode;
6010 compose->targetinfo = NULL;
6011 compose->replyinfo = NULL;
6012 compose->fwdinfo = NULL;
6014 compose->replyto = NULL;
6016 compose->bcc = NULL;
6017 compose->followup_to = NULL;
6019 compose->ml_post = NULL;
6021 compose->inreplyto = NULL;
6022 compose->references = NULL;
6023 compose->msgid = NULL;
6024 compose->boundary = NULL;
6026 compose->autowrap = prefs_common.autowrap;
6028 compose->use_signing = FALSE;
6029 compose->use_encryption = FALSE;
6030 compose->privacy_system = NULL;
6032 compose->modified = FALSE;
6034 compose->return_receipt = FALSE;
6036 compose->to_list = NULL;
6037 compose->newsgroup_list = NULL;
6039 compose->undostruct = undostruct;
6041 compose->sig_str = NULL;
6043 compose->exteditor_file = NULL;
6044 compose->exteditor_pid = -1;
6045 compose->exteditor_tag = -1;
6046 compose->draft_timeout_tag = -1;
6049 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6050 if (mode != COMPOSE_REDIRECT) {
6051 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6052 strcmp(prefs_common.dictionary, "")) {
6053 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6054 prefs_common.dictionary,
6055 conv_get_locale_charset_str(),
6056 prefs_common.misspelled_col,
6057 prefs_common.check_while_typing,
6058 prefs_common.recheck_when_changing_dict,
6059 prefs_common.use_alternate,
6060 GTK_TEXT_VIEW(text),
6061 GTK_WINDOW(compose->window),
6062 compose_spell_menu_changed,
6065 alertpanel_error(_("Spell checker could not "
6067 gtkaspell_checkers_strerror());
6068 gtkaspell_checkers_reset_error();
6070 if (!gtkaspell_set_sug_mode(gtkaspell,
6071 prefs_common.aspell_sugmode)) {
6072 debug_print("Aspell: could not set "
6073 "suggestion mode %s\n",
6074 gtkaspell_checkers_strerror());
6075 gtkaspell_checkers_reset_error();
6078 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6082 compose->gtkaspell = gtkaspell;
6083 compose_spell_menu_changed(compose);
6086 compose_select_account(compose, account, TRUE);
6088 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6089 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6090 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6092 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6093 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6095 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6096 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6099 if (account->protocol != A_NNTP)
6100 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6102 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6104 addressbook_set_target_compose(compose);
6106 if (mode != COMPOSE_REDIRECT)
6107 compose_set_template_menu(compose);
6109 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6110 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6113 compose_list = g_list_append(compose_list, compose);
6115 if (!prefs_common.show_ruler)
6116 gtk_widget_hide(ruler_hbox);
6118 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6119 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6120 prefs_common.show_ruler);
6123 compose->priority = PRIORITY_NORMAL;
6124 compose_update_priority_menu_item(compose);
6126 compose_set_out_encoding(compose);
6129 compose_update_actions_menu(compose);
6131 /* Privacy Systems menu */
6132 compose_update_privacy_systems_menu(compose);
6134 activate_privacy_system(compose, account, TRUE);
6135 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6137 gtk_widget_realize(window);
6139 gtk_widget_show(window);
6145 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6150 GtkWidget *optmenubox;
6153 GtkWidget *from_name = NULL;
6155 gint num = 0, def_menu = 0;
6157 accounts = account_get_list();
6158 g_return_val_if_fail(accounts != NULL, NULL);
6160 optmenubox = gtk_event_box_new();
6161 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
6162 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
6164 hbox = gtk_hbox_new(FALSE, 6);
6165 from_name = gtk_entry_new();
6167 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6168 G_CALLBACK(compose_grab_focus_cb), compose);
6170 for (; accounts != NULL; accounts = accounts->next, num++) {
6171 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6172 gchar *name, *from = NULL;
6174 if (ac == compose->account) def_menu = num;
6176 name = g_markup_printf_escaped(_("From: <i>%s</i>"),
6179 if (ac == compose->account) {
6180 if (ac->name && *ac->name) {
6182 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6183 from = g_strdup_printf("%s <%s>",
6185 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6187 from = g_strdup_printf("%s",
6189 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6192 COMBOBOX_ADD(menu, name, ac->account_id);
6197 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
6199 g_signal_connect(G_OBJECT(optmenu), "changed",
6200 G_CALLBACK(account_activated),
6203 gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
6204 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6206 gtk_tooltips_set_tip(compose->tooltips, optmenubox,
6207 _("Account to use for this email"), NULL);
6208 gtk_tooltips_set_tip(compose->tooltips, from_name,
6209 _("Sender address to be used"), NULL);
6211 compose->from_name = from_name;
6216 static void compose_set_priority_cb(gpointer data,
6220 Compose *compose = (Compose *) data;
6221 compose->priority = action;
6224 static void compose_update_priority_menu_item(Compose * compose)
6226 GtkItemFactory *ifactory;
6227 GtkWidget *menuitem = NULL;
6229 ifactory = gtk_item_factory_from_widget(compose->menubar);
6231 switch (compose->priority) {
6232 case PRIORITY_HIGHEST:
6233 menuitem = gtk_item_factory_get_item
6234 (ifactory, "/Options/Priority/Highest");
6237 menuitem = gtk_item_factory_get_item
6238 (ifactory, "/Options/Priority/High");
6240 case PRIORITY_NORMAL:
6241 menuitem = gtk_item_factory_get_item
6242 (ifactory, "/Options/Priority/Normal");
6245 menuitem = gtk_item_factory_get_item
6246 (ifactory, "/Options/Priority/Low");
6248 case PRIORITY_LOWEST:
6249 menuitem = gtk_item_factory_get_item
6250 (ifactory, "/Options/Priority/Lowest");
6253 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6256 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6258 Compose *compose = (Compose *) data;
6260 GtkItemFactory *ifactory;
6261 gboolean can_sign = FALSE, can_encrypt = FALSE;
6263 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6265 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6268 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6269 g_free(compose->privacy_system);
6270 compose->privacy_system = NULL;
6271 if (systemid != NULL) {
6272 compose->privacy_system = g_strdup(systemid);
6274 can_sign = privacy_system_can_sign(systemid);
6275 can_encrypt = privacy_system_can_encrypt(systemid);
6278 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6280 ifactory = gtk_item_factory_from_widget(compose->menubar);
6281 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6282 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6285 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6287 static gchar *branch_path = "/Options/Privacy System";
6288 GtkItemFactory *ifactory;
6289 GtkWidget *menuitem = NULL;
6291 gboolean can_sign = FALSE, can_encrypt = FALSE;
6292 gboolean found = FALSE;
6294 ifactory = gtk_item_factory_from_widget(compose->menubar);
6296 if (compose->privacy_system != NULL) {
6299 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6300 g_return_if_fail(menuitem != NULL);
6302 amenu = GTK_MENU_SHELL(menuitem)->children;
6304 while (amenu != NULL) {
6305 GList *alist = amenu->next;
6307 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6308 if (systemid != NULL) {
6309 if (strcmp(systemid, compose->privacy_system) == 0) {
6310 menuitem = GTK_WIDGET(amenu->data);
6312 can_sign = privacy_system_can_sign(systemid);
6313 can_encrypt = privacy_system_can_encrypt(systemid);
6317 } else if (strlen(compose->privacy_system) == 0) {
6318 menuitem = GTK_WIDGET(amenu->data);
6321 can_encrypt = FALSE;
6328 if (menuitem != NULL)
6329 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6331 if (warn && !found && strlen(compose->privacy_system)) {
6332 gchar *tmp = g_strdup_printf(
6333 _("The privacy system '%s' cannot be loaded. You "
6334 "will not be able to sign or encrypt this message."),
6335 compose->privacy_system);
6336 alertpanel_warning(tmp);
6341 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6342 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6345 static void compose_set_out_encoding(Compose *compose)
6347 GtkItemFactoryEntry *entry;
6348 GtkItemFactory *ifactory;
6349 CharSet out_encoding;
6350 gchar *path, *p, *q;
6353 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6354 ifactory = gtk_item_factory_from_widget(compose->menubar);
6356 for (entry = compose_entries; entry->callback != compose_address_cb;
6358 if (entry->callback == compose_set_encoding_cb &&
6359 (CharSet)entry->callback_action == out_encoding) {
6360 p = q = path = g_strdup(entry->path);
6372 item = gtk_item_factory_get_item(ifactory, path);
6373 gtk_widget_activate(item);
6380 static void compose_set_template_menu(Compose *compose)
6382 GSList *tmpl_list, *cur;
6386 tmpl_list = template_get_config();
6388 menu = gtk_menu_new();
6390 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6391 Template *tmpl = (Template *)cur->data;
6393 item = gtk_menu_item_new_with_label(tmpl->name);
6394 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6395 g_signal_connect(G_OBJECT(item), "activate",
6396 G_CALLBACK(compose_template_activate_cb),
6398 g_object_set_data(G_OBJECT(item), "template", tmpl);
6399 gtk_widget_show(item);
6402 gtk_widget_show(menu);
6403 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6406 void compose_update_actions_menu(Compose *compose)
6408 GtkItemFactory *ifactory;
6410 ifactory = gtk_item_factory_from_widget(compose->menubar);
6411 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6414 void compose_update_privacy_systems_menu(Compose *compose)
6416 static gchar *branch_path = "/Options/Privacy System";
6417 GtkItemFactory *ifactory;
6418 GtkWidget *menuitem;
6419 GSList *systems, *cur;
6422 GtkWidget *system_none;
6425 ifactory = gtk_item_factory_from_widget(compose->menubar);
6427 /* remove old entries */
6428 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6429 g_return_if_fail(menuitem != NULL);
6431 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6432 while (amenu != NULL) {
6433 GList *alist = amenu->next;
6434 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6438 system_none = gtk_item_factory_get_widget(ifactory,
6439 "/Options/Privacy System/None");
6441 g_signal_connect(G_OBJECT(system_none), "activate",
6442 G_CALLBACK(compose_set_privacy_system_cb), compose);
6444 systems = privacy_get_system_ids();
6445 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6446 gchar *systemid = cur->data;
6448 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6449 widget = gtk_radio_menu_item_new_with_label(group,
6450 privacy_system_get_name(systemid));
6451 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6452 g_strdup(systemid), g_free);
6453 g_signal_connect(G_OBJECT(widget), "activate",
6454 G_CALLBACK(compose_set_privacy_system_cb), compose);
6456 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6457 gtk_widget_show(widget);
6460 g_slist_free(systems);
6463 void compose_reflect_prefs_all(void)
6468 for (cur = compose_list; cur != NULL; cur = cur->next) {
6469 compose = (Compose *)cur->data;
6470 compose_set_template_menu(compose);
6474 void compose_reflect_prefs_pixmap_theme(void)
6479 for (cur = compose_list; cur != NULL; cur = cur->next) {
6480 compose = (Compose *)cur->data;
6481 toolbar_update(TOOLBAR_COMPOSE, compose);
6485 static void compose_template_apply(Compose *compose, Template *tmpl,
6489 GtkTextBuffer *buffer;
6493 gchar *parsed_str = NULL;
6494 gint cursor_pos = 0;
6497 /* process the body */
6499 text = GTK_TEXT_VIEW(compose->text);
6500 buffer = gtk_text_view_get_buffer(text);
6503 gtk_text_buffer_set_text(buffer, "", -1);
6505 mark = gtk_text_buffer_get_insert(buffer);
6506 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6509 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6510 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6513 if (prefs_common.quotemark && *prefs_common.quotemark)
6514 qmark = prefs_common.quotemark;
6518 if (compose->replyinfo != NULL)
6519 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6520 tmpl->value, qmark, NULL, FALSE);
6521 else if (compose->fwdinfo != NULL)
6522 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6523 tmpl->value, qmark, NULL, FALSE);
6528 if (replace && parsed_str && compose->account->auto_sig)
6529 compose_insert_sig(compose, FALSE);
6531 if (replace && parsed_str) {
6532 gtk_text_buffer_get_start_iter(buffer, &iter);
6533 gtk_text_buffer_place_cursor(buffer, &iter);
6537 cursor_pos = quote_fmt_get_cursor_pos();
6538 compose->set_cursor_pos = cursor_pos;
6539 if (cursor_pos == -1)
6541 gtk_text_buffer_get_start_iter(buffer, &iter);
6542 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6543 gtk_text_buffer_place_cursor(buffer, &iter);
6546 /* process the other fields */
6547 compose_template_apply_fields(compose, tmpl);
6549 compose_changed_cb(NULL, compose);
6552 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6554 static MsgInfo dummyinfo;
6555 MsgInfo *msginfo = NULL;
6558 if (compose->replyinfo != NULL)
6559 msginfo = compose->replyinfo;
6560 else if (compose->fwdinfo != NULL)
6561 msginfo = compose->fwdinfo;
6563 msginfo = &dummyinfo;
6565 if (tmpl->to && *tmpl->to != '\0') {
6566 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6567 quote_fmt_scan_string(tmpl->to);
6570 buf = quote_fmt_get_buffer();
6572 alertpanel_error(_("Message To format error."));
6574 compose_entry_append(compose, buf, COMPOSE_TO);
6578 if (tmpl->cc && *tmpl->cc != '\0') {
6579 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6580 quote_fmt_scan_string(tmpl->cc);
6583 buf = quote_fmt_get_buffer();
6585 alertpanel_error(_("Message Cc format error."));
6587 compose_entry_append(compose, buf, COMPOSE_CC);
6591 if (tmpl->bcc && *tmpl->bcc != '\0') {
6592 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6593 quote_fmt_scan_string(tmpl->bcc);
6596 buf = quote_fmt_get_buffer();
6598 alertpanel_error(_("Message Bcc format error."));
6600 compose_entry_append(compose, buf, COMPOSE_BCC);
6604 /* process the subject */
6605 if (tmpl->subject && *tmpl->subject != '\0') {
6606 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6607 quote_fmt_scan_string(tmpl->subject);
6610 buf = quote_fmt_get_buffer();
6612 alertpanel_error(_("Message subject format error."));
6614 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6619 static void compose_destroy(Compose *compose)
6621 compose_list = g_list_remove(compose_list, compose);
6623 if (compose->updating) {
6624 debug_print("danger, not destroying anything now\n");
6625 compose->deferred_destroy = TRUE;
6628 /* NOTE: address_completion_end() does nothing with the window
6629 * however this may change. */
6630 address_completion_end(compose->window);
6632 slist_free_strings(compose->to_list);
6633 g_slist_free(compose->to_list);
6634 slist_free_strings(compose->newsgroup_list);
6635 g_slist_free(compose->newsgroup_list);
6636 slist_free_strings(compose->header_list);
6637 g_slist_free(compose->header_list);
6639 procmsg_msginfo_free(compose->targetinfo);
6640 procmsg_msginfo_free(compose->replyinfo);
6641 procmsg_msginfo_free(compose->fwdinfo);
6643 g_free(compose->replyto);
6644 g_free(compose->cc);
6645 g_free(compose->bcc);
6646 g_free(compose->newsgroups);
6647 g_free(compose->followup_to);
6649 g_free(compose->ml_post);
6651 g_free(compose->inreplyto);
6652 g_free(compose->references);
6653 g_free(compose->msgid);
6654 g_free(compose->boundary);
6656 g_free(compose->redirect_filename);
6657 if (compose->undostruct)
6658 undo_destroy(compose->undostruct);
6660 g_free(compose->sig_str);
6662 g_free(compose->exteditor_file);
6664 g_free(compose->orig_charset);
6666 g_free(compose->privacy_system);
6668 if (addressbook_get_target_compose() == compose)
6669 addressbook_set_target_compose(NULL);
6672 if (compose->gtkaspell) {
6673 gtkaspell_delete(compose->gtkaspell);
6674 compose->gtkaspell = NULL;
6678 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6679 prefs_common.compose_height = compose->window->allocation.height;
6681 if (!gtk_widget_get_parent(compose->paned))
6682 gtk_widget_destroy(compose->paned);
6683 gtk_widget_destroy(compose->popupmenu);
6685 gtk_widget_destroy(compose->window);
6686 toolbar_destroy(compose->toolbar);
6687 g_free(compose->toolbar);
6688 g_mutex_free(compose->mutex);
6692 static void compose_attach_info_free(AttachInfo *ainfo)
6694 g_free(ainfo->file);
6695 g_free(ainfo->content_type);
6696 g_free(ainfo->name);
6700 static void compose_attach_remove_selected(Compose *compose)
6702 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6703 GtkTreeSelection *selection;
6705 GtkTreeModel *model;
6707 selection = gtk_tree_view_get_selection(tree_view);
6708 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6713 for (cur = sel; cur != NULL; cur = cur->next) {
6714 GtkTreePath *path = cur->data;
6715 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6718 gtk_tree_path_free(path);
6721 for (cur = sel; cur != NULL; cur = cur->next) {
6722 GtkTreeRowReference *ref = cur->data;
6723 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6726 if (gtk_tree_model_get_iter(model, &iter, path))
6727 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6729 gtk_tree_path_free(path);
6730 gtk_tree_row_reference_free(ref);
6736 static struct _AttachProperty
6739 GtkWidget *mimetype_entry;
6740 GtkWidget *encoding_optmenu;
6741 GtkWidget *path_entry;
6742 GtkWidget *filename_entry;
6744 GtkWidget *cancel_btn;
6747 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6749 gtk_tree_path_free((GtkTreePath *)ptr);
6752 static void compose_attach_property(Compose *compose)
6754 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6756 GtkComboBox *optmenu;
6757 GtkTreeSelection *selection;
6759 GtkTreeModel *model;
6762 static gboolean cancelled;
6764 /* only if one selected */
6765 selection = gtk_tree_view_get_selection(tree_view);
6766 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6769 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6773 path = (GtkTreePath *) sel->data;
6774 gtk_tree_model_get_iter(model, &iter, path);
6775 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6778 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6784 if (!attach_prop.window)
6785 compose_attach_property_create(&cancelled);
6786 gtk_widget_grab_focus(attach_prop.ok_btn);
6787 gtk_widget_show(attach_prop.window);
6788 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6790 optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
6791 if (ainfo->encoding == ENC_UNKNOWN)
6792 combobox_select_by_data(optmenu, ENC_BASE64);
6794 combobox_select_by_data(optmenu, ainfo->encoding);
6796 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6797 ainfo->content_type ? ainfo->content_type : "");
6798 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6799 ainfo->file ? ainfo->file : "");
6800 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6801 ainfo->name ? ainfo->name : "");
6804 const gchar *entry_text;
6806 gchar *cnttype = NULL;
6813 gtk_widget_hide(attach_prop.window);
6818 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6819 if (*entry_text != '\0') {
6822 text = g_strstrip(g_strdup(entry_text));
6823 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6824 cnttype = g_strdup(text);
6827 alertpanel_error(_("Invalid MIME type."));
6833 ainfo->encoding = combobox_get_active_data(optmenu);
6835 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6836 if (*entry_text != '\0') {
6837 if (is_file_exist(entry_text) &&
6838 (size = get_file_size(entry_text)) > 0)
6839 file = g_strdup(entry_text);
6842 (_("File doesn't exist or is empty."));
6848 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6849 if (*entry_text != '\0') {
6850 g_free(ainfo->name);
6851 ainfo->name = g_strdup(entry_text);
6855 g_free(ainfo->content_type);
6856 ainfo->content_type = cnttype;
6859 g_free(ainfo->file);
6865 /* update tree store */
6866 text = to_human_readable(ainfo->size);
6867 gtk_tree_model_get_iter(model, &iter, path);
6868 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6869 COL_MIMETYPE, ainfo->content_type,
6871 COL_NAME, ainfo->name,
6877 gtk_tree_path_free(path);
6880 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6882 label = gtk_label_new(str); \
6883 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6884 GTK_FILL, 0, 0, 0); \
6885 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6887 entry = gtk_entry_new(); \
6888 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6889 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6892 static void compose_attach_property_create(gboolean *cancelled)
6898 GtkWidget *mimetype_entry;
6901 GtkListStore *optmenu_menu;
6902 GtkWidget *path_entry;
6903 GtkWidget *filename_entry;
6906 GtkWidget *cancel_btn;
6907 GList *mime_type_list, *strlist;
6910 debug_print("Creating attach_property window...\n");
6912 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6913 gtk_widget_set_size_request(window, 480, -1);
6914 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6915 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6916 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6917 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6918 g_signal_connect(G_OBJECT(window), "delete_event",
6919 G_CALLBACK(attach_property_delete_event),
6921 g_signal_connect(G_OBJECT(window), "key_press_event",
6922 G_CALLBACK(attach_property_key_pressed),
6925 vbox = gtk_vbox_new(FALSE, 8);
6926 gtk_container_add(GTK_CONTAINER(window), vbox);
6928 table = gtk_table_new(4, 2, FALSE);
6929 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6930 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6931 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6933 label = gtk_label_new(_("MIME type"));
6934 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6936 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6937 mimetype_entry = gtk_combo_new();
6938 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6939 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6941 /* stuff with list */
6942 mime_type_list = procmime_get_mime_type_list();
6944 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6945 MimeType *type = (MimeType *) mime_type_list->data;
6948 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6950 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6953 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6954 (GCompareFunc)strcmp2);
6957 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6959 for (mime_type_list = strlist; mime_type_list != NULL;
6960 mime_type_list = mime_type_list->next)
6961 g_free(mime_type_list->data);
6962 g_list_free(strlist);
6964 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6966 label = gtk_label_new(_("Encoding"));
6967 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6969 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6971 hbox = gtk_hbox_new(FALSE, 0);
6972 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6973 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6975 optmenu = gtkut_sc_combobox_create(NULL, TRUE);
6976 optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
6978 COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
6979 COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
6980 COMBOBOX_ADD(optmenu_menu, "quoted-printable", ENC_QUOTED_PRINTABLE);
6981 COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
6982 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
6984 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6986 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6987 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6989 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6990 &ok_btn, GTK_STOCK_OK,
6992 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6993 gtk_widget_grab_default(ok_btn);
6995 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6996 G_CALLBACK(attach_property_ok),
6998 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6999 G_CALLBACK(attach_property_cancel),
7002 gtk_widget_show_all(vbox);
7004 attach_prop.window = window;
7005 attach_prop.mimetype_entry = mimetype_entry;
7006 attach_prop.encoding_optmenu = optmenu;
7007 attach_prop.path_entry = path_entry;
7008 attach_prop.filename_entry = filename_entry;
7009 attach_prop.ok_btn = ok_btn;
7010 attach_prop.cancel_btn = cancel_btn;
7013 #undef SET_LABEL_AND_ENTRY
7015 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7021 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7027 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7028 gboolean *cancelled)
7036 static gboolean attach_property_key_pressed(GtkWidget *widget,
7038 gboolean *cancelled)
7040 if (event && event->keyval == GDK_Escape) {
7047 static void compose_exec_ext_editor(Compose *compose)
7054 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7055 G_DIR_SEPARATOR, compose);
7057 if (pipe(pipe_fds) < 0) {
7063 if ((pid = fork()) < 0) {
7070 /* close the write side of the pipe */
7073 compose->exteditor_file = g_strdup(tmp);
7074 compose->exteditor_pid = pid;
7076 compose_set_ext_editor_sensitive(compose, FALSE);
7078 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7079 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7083 } else { /* process-monitoring process */
7089 /* close the read side of the pipe */
7092 if (compose_write_body_to_file(compose, tmp) < 0) {
7093 fd_write_all(pipe_fds[1], "2\n", 2);
7097 pid_ed = compose_exec_ext_editor_real(tmp);
7099 fd_write_all(pipe_fds[1], "1\n", 2);
7103 /* wait until editor is terminated */
7104 waitpid(pid_ed, NULL, 0);
7106 fd_write_all(pipe_fds[1], "0\n", 2);
7113 #endif /* G_OS_UNIX */
7117 static gint compose_exec_ext_editor_real(const gchar *file)
7124 g_return_val_if_fail(file != NULL, -1);
7126 if ((pid = fork()) < 0) {
7131 if (pid != 0) return pid;
7133 /* grandchild process */
7135 if (setpgid(0, getppid()))
7138 if (prefs_common.ext_editor_cmd &&
7139 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7140 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7141 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7143 if (prefs_common.ext_editor_cmd)
7144 g_warning("External editor command line is invalid: '%s'\n",
7145 prefs_common.ext_editor_cmd);
7146 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7149 cmdline = strsplit_with_quote(buf, " ", 1024);
7150 execvp(cmdline[0], cmdline);
7153 g_strfreev(cmdline);
7158 static gboolean compose_ext_editor_kill(Compose *compose)
7160 pid_t pgid = compose->exteditor_pid * -1;
7163 ret = kill(pgid, 0);
7165 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7169 msg = g_strdup_printf
7170 (_("The external editor is still working.\n"
7171 "Force terminating the process?\n"
7172 "process group id: %d"), -pgid);
7173 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7174 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7178 if (val == G_ALERTALTERNATE) {
7179 g_source_remove(compose->exteditor_tag);
7180 g_io_channel_shutdown(compose->exteditor_ch,
7182 g_io_channel_unref(compose->exteditor_ch);
7184 if (kill(pgid, SIGTERM) < 0) perror("kill");
7185 waitpid(compose->exteditor_pid, NULL, 0);
7187 g_warning("Terminated process group id: %d", -pgid);
7188 g_warning("Temporary file: %s",
7189 compose->exteditor_file);
7191 compose_set_ext_editor_sensitive(compose, TRUE);
7193 g_free(compose->exteditor_file);
7194 compose->exteditor_file = NULL;
7195 compose->exteditor_pid = -1;
7196 compose->exteditor_ch = NULL;
7197 compose->exteditor_tag = -1;
7205 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7209 Compose *compose = (Compose *)data;
7212 debug_print(_("Compose: input from monitoring process\n"));
7214 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7216 g_io_channel_shutdown(source, FALSE, NULL);
7217 g_io_channel_unref(source);
7219 waitpid(compose->exteditor_pid, NULL, 0);
7221 if (buf[0] == '0') { /* success */
7222 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7223 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7225 gtk_text_buffer_set_text(buffer, "", -1);
7226 compose_insert_file(compose, compose->exteditor_file);
7227 compose_changed_cb(NULL, compose);
7229 if (g_unlink(compose->exteditor_file) < 0)
7230 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7231 } else if (buf[0] == '1') { /* failed */
7232 g_warning("Couldn't exec external editor\n");
7233 if (g_unlink(compose->exteditor_file) < 0)
7234 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7235 } else if (buf[0] == '2') {
7236 g_warning("Couldn't write to file\n");
7237 } else if (buf[0] == '3') {
7238 g_warning("Pipe read failed\n");
7241 compose_set_ext_editor_sensitive(compose, TRUE);
7243 g_free(compose->exteditor_file);
7244 compose->exteditor_file = NULL;
7245 compose->exteditor_pid = -1;
7246 compose->exteditor_ch = NULL;
7247 compose->exteditor_tag = -1;
7252 static void compose_set_ext_editor_sensitive(Compose *compose,
7255 GtkItemFactory *ifactory;
7257 ifactory = gtk_item_factory_from_widget(compose->menubar);
7259 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7260 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7261 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7262 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7263 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7264 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7265 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7268 gtk_widget_set_sensitive(compose->text, sensitive);
7269 if (compose->toolbar->send_btn)
7270 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7271 if (compose->toolbar->sendl_btn)
7272 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7273 if (compose->toolbar->draft_btn)
7274 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7275 if (compose->toolbar->insert_btn)
7276 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7277 if (compose->toolbar->sig_btn)
7278 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7279 if (compose->toolbar->exteditor_btn)
7280 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7281 if (compose->toolbar->linewrap_current_btn)
7282 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7283 if (compose->toolbar->linewrap_all_btn)
7284 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7286 #endif /* G_OS_UNIX */
7289 * compose_undo_state_changed:
7291 * Change the sensivity of the menuentries undo and redo
7293 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7294 gint redo_state, gpointer data)
7296 GtkWidget *widget = GTK_WIDGET(data);
7297 GtkItemFactory *ifactory;
7299 g_return_if_fail(widget != NULL);
7301 ifactory = gtk_item_factory_from_widget(widget);
7303 switch (undo_state) {
7304 case UNDO_STATE_TRUE:
7305 if (!undostruct->undo_state) {
7306 undostruct->undo_state = TRUE;
7307 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7310 case UNDO_STATE_FALSE:
7311 if (undostruct->undo_state) {
7312 undostruct->undo_state = FALSE;
7313 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7316 case UNDO_STATE_UNCHANGED:
7318 case UNDO_STATE_REFRESH:
7319 menu_set_sensitive(ifactory, "/Edit/Undo",
7320 undostruct->undo_state);
7323 g_warning("Undo state not recognized");
7327 switch (redo_state) {
7328 case UNDO_STATE_TRUE:
7329 if (!undostruct->redo_state) {
7330 undostruct->redo_state = TRUE;
7331 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7334 case UNDO_STATE_FALSE:
7335 if (undostruct->redo_state) {
7336 undostruct->redo_state = FALSE;
7337 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7340 case UNDO_STATE_UNCHANGED:
7342 case UNDO_STATE_REFRESH:
7343 menu_set_sensitive(ifactory, "/Edit/Redo",
7344 undostruct->redo_state);
7347 g_warning("Redo state not recognized");
7352 /* callback functions */
7354 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7355 * includes "non-client" (windows-izm) in calculation, so this calculation
7356 * may not be accurate.
7358 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7359 GtkAllocation *allocation,
7360 GtkSHRuler *shruler)
7362 if (prefs_common.show_ruler) {
7363 gint char_width = 0, char_height = 0;
7364 gint line_width_in_chars;
7366 gtkut_get_font_size(GTK_WIDGET(widget),
7367 &char_width, &char_height);
7368 line_width_in_chars =
7369 (allocation->width - allocation->x) / char_width;
7371 /* got the maximum */
7372 gtk_ruler_set_range(GTK_RULER(shruler),
7373 0.0, line_width_in_chars, 0,
7374 /*line_width_in_chars*/ char_width);
7380 static void account_activated(GtkComboBox *optmenu, gpointer data)
7382 Compose *compose = (Compose *)data;
7385 gchar *folderidentifier;
7386 gint account_id = 0;
7390 /* Get ID of active account in the combo box */
7391 menu = gtk_combo_box_get_model(optmenu);
7392 gtk_combo_box_get_active_iter(optmenu, &iter);
7393 gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
7395 ac = account_find_from_id(account_id);
7396 g_return_if_fail(ac != NULL);
7398 if (ac != compose->account)
7399 compose_select_account(compose, ac, FALSE);
7401 /* Set message save folder */
7402 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7403 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7405 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7406 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7408 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7409 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7410 folderidentifier = folder_item_get_identifier(account_get_special_folder
7411 (compose->account, F_OUTBOX));
7412 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7413 g_free(folderidentifier);
7417 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7418 GtkTreeViewColumn *column, Compose *compose)
7420 compose_attach_property(compose);
7423 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7426 Compose *compose = (Compose *)data;
7427 GtkTreeSelection *attach_selection;
7428 gint attach_nr_selected;
7429 GtkItemFactory *ifactory;
7431 if (!event) return FALSE;
7433 if (event->button == 3) {
7434 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7435 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7436 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7438 if (attach_nr_selected > 0)
7440 menu_set_sensitive(ifactory, "/Remove", TRUE);
7441 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7443 menu_set_sensitive(ifactory, "/Remove", FALSE);
7444 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7447 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7448 NULL, NULL, event->button, event->time);
7455 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7458 Compose *compose = (Compose *)data;
7460 if (!event) return FALSE;
7462 switch (event->keyval) {
7464 compose_attach_remove_selected(compose);
7470 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7472 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7473 toolbar_comp_set_sensitive(compose, allow);
7474 menu_set_sensitive(ifactory, "/Message", allow);
7475 menu_set_sensitive(ifactory, "/Edit", allow);
7477 menu_set_sensitive(ifactory, "/Spelling", allow);
7479 menu_set_sensitive(ifactory, "/Options", allow);
7480 menu_set_sensitive(ifactory, "/Tools", allow);
7481 menu_set_sensitive(ifactory, "/Help", allow);
7483 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7487 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7489 Compose *compose = (Compose *)data;
7491 if (prefs_common.work_offline &&
7492 !inc_offline_should_override(
7493 _("Sylpheed-Claws needs network access in order "
7494 "to send this email.")))
7497 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7498 gtk_timeout_remove(compose->draft_timeout_tag);
7499 compose->draft_timeout_tag = -1;
7502 compose_send(compose);
7505 static void compose_send_later_cb(gpointer data, guint action,
7508 Compose *compose = (Compose *)data;
7511 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
7513 compose_close(compose);
7514 else if (val == -1) {
7515 alertpanel_error(_("Could not queue message."));
7516 } else if (val == -2) {
7517 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7518 } else if (val == -3) {
7519 alertpanel_error(_("Could not queue message for sending:\n\n"
7520 "Signature failed: %s"), privacy_get_error());
7521 } else if (val == -4) {
7522 alertpanel_error(_("Could not queue message for sending:\n\n"
7523 "Charset conversion failed."));
7527 void compose_draft (gpointer data)
7529 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7532 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7534 Compose *compose = (Compose *)data;
7538 MsgFlags flag = {0, 0};
7539 static gboolean lock = FALSE;
7540 MsgInfo *newmsginfo;
7542 gboolean target_locked = FALSE;
7546 draft = account_get_special_folder(compose->account, F_DRAFT);
7547 g_return_if_fail(draft != NULL);
7549 if (!g_mutex_trylock(compose->mutex)) {
7550 /* we don't want to lock the mutex once it's available,
7551 * because as the only other part of compose.c locking
7552 * it is compose_close - which means once unlocked,
7553 * the compose struct will be freed */
7554 debug_print("couldn't lock mutex, probably sending\n");
7560 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7561 G_DIR_SEPARATOR, compose);
7562 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7563 FILE_OP_ERROR(tmp, "fopen");
7567 /* chmod for security */
7568 if (change_file_mode_rw(fp, tmp) < 0) {
7569 FILE_OP_ERROR(tmp, "chmod");
7570 g_warning("can't change file mode\n");
7573 /* Save draft infos */
7574 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7575 fprintf(fp, "S:%s\n", compose->account->address);
7577 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7578 gchar *savefolderid;
7580 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7581 fprintf(fp, "SCF:%s\n", savefolderid);
7582 g_free(savefolderid);
7584 if (compose->return_receipt) {
7585 fprintf(fp, "RRCPT:1\n");
7587 if (compose->privacy_system) {
7588 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7589 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7590 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7593 /* end of headers */
7594 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
7596 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
7604 if (compose->targetinfo) {
7605 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7606 flag.perm_flags = target_locked?MSG_LOCKED:0;
7608 flag.tmp_flags = MSG_DRAFT;
7610 folder_item_scan(draft);
7611 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7614 if (action != COMPOSE_AUTO_SAVE)
7615 alertpanel_error(_("Could not save draft."));
7620 if (compose->mode == COMPOSE_REEDIT) {
7621 compose_remove_reedit_target(compose, TRUE);
7624 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7626 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7628 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7630 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7631 if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
7632 procmsg_msginfo_set_flags(newmsginfo, 0,
7633 MSG_HAS_ATTACHMENT);
7635 procmsg_msginfo_free(newmsginfo);
7638 folder_item_scan(draft);
7640 if (action == COMPOSE_QUIT_EDITING) {
7642 g_mutex_unlock(compose->mutex); /* must be done before closing */
7643 compose_close(compose);
7649 path = folder_item_fetch_msg(draft, msgnum);
7651 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7654 if (g_stat(path, &s) < 0) {
7655 FILE_OP_ERROR(path, "stat");
7661 procmsg_msginfo_free(compose->targetinfo);
7662 compose->targetinfo = procmsg_msginfo_new();
7663 compose->targetinfo->msgnum = msgnum;
7664 compose->targetinfo->size = s.st_size;
7665 compose->targetinfo->mtime = s.st_mtime;
7666 compose->targetinfo->folder = draft;
7668 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7669 compose->mode = COMPOSE_REEDIT;
7671 if (action == COMPOSE_AUTO_SAVE) {
7672 compose->autosaved_draft = compose->targetinfo;
7674 compose->modified = FALSE;
7675 compose_set_title(compose);
7679 g_mutex_unlock(compose->mutex);
7682 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7684 Compose *compose = (Compose *)data;
7687 if (compose->redirect_filename != NULL)
7690 file_list = filesel_select_multiple_files_open(_("Select file"));
7695 for ( tmp = file_list; tmp; tmp = tmp->next) {
7696 gchar *file = (gchar *) tmp->data;
7697 gchar *utf8_filename = conv_filename_to_utf8(file);
7698 compose_attach_append(compose, file, utf8_filename, NULL);
7699 compose_changed_cb(NULL, compose);
7701 g_free(utf8_filename);
7703 g_list_free(file_list);
7707 static void compose_insert_file_cb(gpointer data, guint action,
7710 Compose *compose = (Compose *)data;
7713 file_list = filesel_select_multiple_files_open(_("Select file"));
7718 for ( tmp = file_list; tmp; tmp = tmp->next) {
7719 gchar *file = (gchar *) tmp->data;
7720 gchar *filedup = g_strdup(file);
7721 gchar *shortfile = g_path_get_basename(filedup);
7722 ComposeInsertResult res;
7724 res = compose_insert_file(compose, file);
7725 if (res == COMPOSE_INSERT_READ_ERROR) {
7726 alertpanel_error(_("File '%s' could not be read."), shortfile);
7727 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7728 alertpanel_error(_("File '%s' contained invalid characters\n"
7729 "for the current encoding, insertion may be incorrect."), shortfile);
7735 g_list_free(file_list);
7739 static void compose_insert_sig_cb(gpointer data, guint action,
7742 Compose *compose = (Compose *)data;
7744 compose_insert_sig(compose, FALSE);
7747 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7751 Compose *compose = (Compose *)data;
7753 gtkut_widget_get_uposition(widget, &x, &y);
7754 prefs_common.compose_x = x;
7755 prefs_common.compose_y = y;
7757 if (compose->sending || compose->updating)
7759 compose_close_cb(compose, 0, NULL);
7763 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7765 Compose *compose = (Compose *)data;
7769 if (compose->exteditor_tag != -1) {
7770 if (!compose_ext_editor_kill(compose))
7775 if (compose->modified) {
7776 val = alertpanel(_("Discard message"),
7777 _("This message has been modified. Discard it?"),
7778 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7781 case G_ALERTDEFAULT:
7782 if (prefs_common.autosave)
7783 compose_remove_draft(compose);
7785 case G_ALERTALTERNATE:
7786 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7793 compose_close(compose);
7796 static void compose_set_encoding_cb(gpointer data, guint action,
7799 Compose *compose = (Compose *)data;
7801 if (GTK_CHECK_MENU_ITEM(widget)->active)
7802 compose->out_encoding = (CharSet)action;
7805 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7807 Compose *compose = (Compose *)data;
7809 addressbook_open(compose);
7812 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7814 Compose *compose = (Compose *)data;
7819 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7820 g_return_if_fail(tmpl != NULL);
7822 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7824 val = alertpanel(_("Apply template"), msg,
7825 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7828 if (val == G_ALERTDEFAULT)
7829 compose_template_apply(compose, tmpl, TRUE);
7830 else if (val == G_ALERTALTERNATE)
7831 compose_template_apply(compose, tmpl, FALSE);
7834 static void compose_ext_editor_cb(gpointer data, guint action,
7837 Compose *compose = (Compose *)data;
7839 compose_exec_ext_editor(compose);
7842 static void compose_undo_cb(Compose *compose)
7844 gboolean prev_autowrap = compose->autowrap;
7846 compose->autowrap = FALSE;
7847 undo_undo(compose->undostruct);
7848 compose->autowrap = prev_autowrap;
7851 static void compose_redo_cb(Compose *compose)
7853 gboolean prev_autowrap = compose->autowrap;
7855 compose->autowrap = FALSE;
7856 undo_redo(compose->undostruct);
7857 compose->autowrap = prev_autowrap;
7860 static void entry_cut_clipboard(GtkWidget *entry)
7862 if (GTK_IS_EDITABLE(entry))
7863 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7864 else if (GTK_IS_TEXT_VIEW(entry))
7865 gtk_text_buffer_cut_clipboard(
7866 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7867 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7871 static void entry_copy_clipboard(GtkWidget *entry)
7873 if (GTK_IS_EDITABLE(entry))
7874 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7875 else if (GTK_IS_TEXT_VIEW(entry))
7876 gtk_text_buffer_copy_clipboard(
7877 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7878 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7881 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7882 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
7884 if (GTK_IS_TEXT_VIEW(entry)) {
7885 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7886 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7887 GtkTextIter start_iter, end_iter;
7890 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7892 if (contents == NULL)
7895 /* we shouldn't delete the selection when middle-click-pasting, or we
7896 * can't mid-click-paste our own selection */
7897 if (clip != GDK_SELECTION_PRIMARY)
7898 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7900 if (insert_place == NULL) {
7901 /* if insert_place isn't specified, insert at the cursor.
7902 * used for Ctrl-V pasting */
7903 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7904 start = gtk_text_iter_get_offset(&start_iter);
7905 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7907 /* if insert_place is specified, paste here.
7908 * used for mid-click-pasting */
7909 start = gtk_text_iter_get_offset(insert_place);
7910 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
7914 /* paste unwrapped: mark the paste so it's not wrapped later */
7915 end = start + strlen(contents);
7916 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7917 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7918 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7919 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7920 /* rewrap paragraph now (after a mid-click-paste) */
7921 mark_start = gtk_text_buffer_get_insert(buffer);
7922 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7923 gtk_text_iter_backward_char(&start_iter);
7924 compose_beautify_paragraph(compose, &start_iter, TRUE);
7927 } else if (GTK_IS_EDITABLE(entry))
7928 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7932 static void entry_allsel(GtkWidget *entry)
7934 if (GTK_IS_EDITABLE(entry))
7935 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7936 else if (GTK_IS_TEXT_VIEW(entry)) {
7937 GtkTextIter startiter, enditer;
7938 GtkTextBuffer *textbuf;
7940 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7941 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7942 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7944 gtk_text_buffer_move_mark_by_name(textbuf,
7945 "selection_bound", &startiter);
7946 gtk_text_buffer_move_mark_by_name(textbuf,
7947 "insert", &enditer);
7951 static void compose_cut_cb(Compose *compose)
7953 if (compose->focused_editable &&
7954 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7955 entry_cut_clipboard(compose->focused_editable);
7958 static void compose_copy_cb(Compose *compose)
7960 if (compose->focused_editable &&
7961 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7962 entry_copy_clipboard(compose->focused_editable);
7965 static void compose_paste_cb(Compose *compose)
7968 GtkTextBuffer *buffer;
7970 if (compose->focused_editable &&
7971 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7972 entry_paste_clipboard(compose, compose->focused_editable,
7973 prefs_common.linewrap_pastes,
7974 GDK_SELECTION_CLIPBOARD, NULL);
7978 static void compose_paste_as_quote_cb(Compose *compose)
7980 gint wrap_quote = prefs_common.linewrap_quote;
7981 if (compose->focused_editable &&
7982 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7983 /* let text_insert() (called directly or at a later time
7984 * after the gtk_editable_paste_clipboard) know that
7985 * text is to be inserted as a quotation. implemented
7986 * by using a simple refcount... */
7987 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7988 G_OBJECT(compose->focused_editable),
7989 "paste_as_quotation"));
7990 g_object_set_data(G_OBJECT(compose->focused_editable),
7991 "paste_as_quotation",
7992 GINT_TO_POINTER(paste_as_quotation + 1));
7993 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7994 entry_paste_clipboard(compose, compose->focused_editable,
7995 prefs_common.linewrap_pastes,
7996 GDK_SELECTION_CLIPBOARD, NULL);
7997 prefs_common.linewrap_quote = wrap_quote;
8001 static void compose_paste_no_wrap_cb(Compose *compose)
8004 GtkTextBuffer *buffer;
8006 if (compose->focused_editable &&
8007 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8008 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
8009 GDK_SELECTION_CLIPBOARD, NULL);
8013 static void compose_paste_wrap_cb(Compose *compose)
8016 GtkTextBuffer *buffer;
8018 if (compose->focused_editable &&
8019 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8020 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
8021 GDK_SELECTION_CLIPBOARD, NULL);
8025 static void compose_allsel_cb(Compose *compose)
8027 if (compose->focused_editable &&
8028 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8029 entry_allsel(compose->focused_editable);
8032 static void textview_move_beginning_of_line (GtkTextView *text)
8034 GtkTextBuffer *buffer;
8038 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8040 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8041 mark = gtk_text_buffer_get_insert(buffer);
8042 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8043 gtk_text_iter_set_line_offset(&ins, 0);
8044 gtk_text_buffer_place_cursor(buffer, &ins);
8047 static void textview_move_forward_character (GtkTextView *text)
8049 GtkTextBuffer *buffer;
8053 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8055 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8056 mark = gtk_text_buffer_get_insert(buffer);
8057 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8058 if (gtk_text_iter_forward_cursor_position(&ins))
8059 gtk_text_buffer_place_cursor(buffer, &ins);
8062 static void textview_move_backward_character (GtkTextView *text)
8064 GtkTextBuffer *buffer;
8068 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8070 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8071 mark = gtk_text_buffer_get_insert(buffer);
8072 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8073 if (gtk_text_iter_backward_cursor_position(&ins))
8074 gtk_text_buffer_place_cursor(buffer, &ins);
8077 static void textview_move_forward_word (GtkTextView *text)
8079 GtkTextBuffer *buffer;
8084 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8086 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8087 mark = gtk_text_buffer_get_insert(buffer);
8088 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8089 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8090 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8091 gtk_text_iter_backward_word_start(&ins);
8092 gtk_text_buffer_place_cursor(buffer, &ins);
8096 static void textview_move_backward_word (GtkTextView *text)
8098 GtkTextBuffer *buffer;
8103 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8105 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8106 mark = gtk_text_buffer_get_insert(buffer);
8107 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8108 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8109 if (gtk_text_iter_backward_word_starts(&ins, 1))
8110 gtk_text_buffer_place_cursor(buffer, &ins);
8113 static void textview_move_end_of_line (GtkTextView *text)
8115 GtkTextBuffer *buffer;
8119 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8121 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8122 mark = gtk_text_buffer_get_insert(buffer);
8123 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8124 if (gtk_text_iter_forward_to_line_end(&ins))
8125 gtk_text_buffer_place_cursor(buffer, &ins);
8128 static void textview_move_next_line (GtkTextView *text)
8130 GtkTextBuffer *buffer;
8135 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8137 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8138 mark = gtk_text_buffer_get_insert(buffer);
8139 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8140 offset = gtk_text_iter_get_line_offset(&ins);
8141 if (gtk_text_iter_forward_line(&ins)) {
8142 gtk_text_iter_set_line_offset(&ins, offset);
8143 gtk_text_buffer_place_cursor(buffer, &ins);
8147 static void textview_move_previous_line (GtkTextView *text)
8149 GtkTextBuffer *buffer;
8154 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8156 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8157 mark = gtk_text_buffer_get_insert(buffer);
8158 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8159 offset = gtk_text_iter_get_line_offset(&ins);
8160 if (gtk_text_iter_backward_line(&ins)) {
8161 gtk_text_iter_set_line_offset(&ins, offset);
8162 gtk_text_buffer_place_cursor(buffer, &ins);
8166 static void textview_delete_forward_character (GtkTextView *text)
8168 GtkTextBuffer *buffer;
8170 GtkTextIter ins, end_iter;
8172 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8174 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8175 mark = gtk_text_buffer_get_insert(buffer);
8176 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8178 if (gtk_text_iter_forward_char(&end_iter)) {
8179 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8183 static void textview_delete_backward_character (GtkTextView *text)
8185 GtkTextBuffer *buffer;
8187 GtkTextIter ins, end_iter;
8189 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8191 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8192 mark = gtk_text_buffer_get_insert(buffer);
8193 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8195 if (gtk_text_iter_backward_char(&end_iter)) {
8196 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8200 static void textview_delete_forward_word (GtkTextView *text)
8202 GtkTextBuffer *buffer;
8204 GtkTextIter ins, end_iter;
8206 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8208 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8209 mark = gtk_text_buffer_get_insert(buffer);
8210 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8212 if (gtk_text_iter_forward_word_end(&end_iter)) {
8213 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8217 static void textview_delete_backward_word (GtkTextView *text)
8219 GtkTextBuffer *buffer;
8221 GtkTextIter ins, end_iter;
8223 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8225 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8226 mark = gtk_text_buffer_get_insert(buffer);
8227 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8229 if (gtk_text_iter_backward_word_start(&end_iter)) {
8230 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8234 static void textview_delete_line (GtkTextView *text)
8236 GtkTextBuffer *buffer;
8238 GtkTextIter ins, start_iter, end_iter;
8241 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8243 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8244 mark = gtk_text_buffer_get_insert(buffer);
8245 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8248 gtk_text_iter_set_line_offset(&start_iter, 0);
8251 if (gtk_text_iter_ends_line(&end_iter))
8252 found = gtk_text_iter_forward_char(&end_iter);
8254 found = gtk_text_iter_forward_to_line_end(&end_iter);
8257 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8260 static void textview_delete_to_line_end (GtkTextView *text)
8262 GtkTextBuffer *buffer;
8264 GtkTextIter ins, end_iter;
8267 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8269 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8270 mark = gtk_text_buffer_get_insert(buffer);
8271 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8273 if (gtk_text_iter_ends_line(&end_iter))
8274 found = gtk_text_iter_forward_char(&end_iter);
8276 found = gtk_text_iter_forward_to_line_end(&end_iter);
8278 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8281 static void compose_advanced_action_cb(Compose *compose,
8282 ComposeCallAdvancedAction action)
8284 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8286 void (*do_action) (GtkTextView *text);
8287 } action_table[] = {
8288 {textview_move_beginning_of_line},
8289 {textview_move_forward_character},
8290 {textview_move_backward_character},
8291 {textview_move_forward_word},
8292 {textview_move_backward_word},
8293 {textview_move_end_of_line},
8294 {textview_move_next_line},
8295 {textview_move_previous_line},
8296 {textview_delete_forward_character},
8297 {textview_delete_backward_character},
8298 {textview_delete_forward_word},
8299 {textview_delete_backward_word},
8300 {textview_delete_line},
8301 {NULL}, /* gtk_stext_delete_line_n */
8302 {textview_delete_to_line_end}
8305 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8307 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8308 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8309 if (action_table[action].do_action)
8310 action_table[action].do_action(text);
8312 g_warning("Not implemented yet.");
8316 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8320 if (GTK_IS_EDITABLE(widget)) {
8321 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8322 gtk_editable_set_position(GTK_EDITABLE(widget),
8325 if (widget->parent && widget->parent->parent
8326 && widget->parent->parent->parent) {
8327 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8328 gint y = widget->allocation.y;
8329 gint height = widget->allocation.height;
8330 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8331 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8333 if (y < (int)shown->value) {
8334 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8336 if (y + height > (int)shown->value + (int)shown->page_size) {
8337 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8338 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8339 y + height - (int)shown->page_size - 1);
8341 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8342 (int)shown->upper - (int)shown->page_size - 1);
8349 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8350 compose->focused_editable = widget;
8353 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8355 compose->modified = TRUE;
8356 compose_set_title(compose);
8359 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8361 Compose *compose = (Compose *)data;
8364 compose_wrap_all_full(compose, TRUE);
8366 compose_beautify_paragraph(compose, NULL, TRUE);
8369 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8371 Compose *compose = (Compose *)data;
8373 message_search_compose(compose);
8376 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8379 Compose *compose = (Compose *)data;
8380 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8381 if (compose->autowrap)
8382 compose_wrap_all_full(compose, TRUE);
8383 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8386 static void compose_toggle_sign_cb(gpointer data, guint action,
8389 Compose *compose = (Compose *)data;
8391 if (GTK_CHECK_MENU_ITEM(widget)->active)
8392 compose->use_signing = TRUE;
8394 compose->use_signing = FALSE;
8397 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8400 Compose *compose = (Compose *)data;
8402 if (GTK_CHECK_MENU_ITEM(widget)->active)
8403 compose->use_encryption = TRUE;
8405 compose->use_encryption = FALSE;
8408 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8410 g_free(compose->privacy_system);
8412 compose->privacy_system = g_strdup(account->default_privacy_system);
8413 compose_update_privacy_system_menu_item(compose, warn);
8416 static void compose_toggle_ruler_cb(gpointer data, guint action,
8419 Compose *compose = (Compose *)data;
8421 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8422 gtk_widget_show(compose->ruler_hbox);
8423 prefs_common.show_ruler = TRUE;
8425 gtk_widget_hide(compose->ruler_hbox);
8426 gtk_widget_queue_resize(compose->edit_vbox);
8427 prefs_common.show_ruler = FALSE;
8431 static void compose_attach_drag_received_cb (GtkWidget *widget,
8432 GdkDragContext *context,
8435 GtkSelectionData *data,
8440 Compose *compose = (Compose *)user_data;
8443 if (gdk_atom_name(data->type) &&
8444 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8445 && gtk_drag_get_source_widget(context) !=
8446 mainwindow_get_mainwindow()->summaryview->ctree) {
8447 list = uri_list_extract_filenames((const gchar *)data->data);
8448 for (tmp = list; tmp != NULL; tmp = tmp->next)
8449 compose_attach_append
8450 (compose, (const gchar *)tmp->data,
8451 (const gchar *)tmp->data, NULL);
8452 if (list) compose_changed_cb(NULL, compose);
8453 list_free_strings(list);
8455 } else if (gtk_drag_get_source_widget(context)
8456 == mainwindow_get_mainwindow()->summaryview->ctree) {
8457 /* comes from our summaryview */
8458 SummaryView * summaryview = NULL;
8459 GSList * list = NULL, *cur = NULL;
8461 if (mainwindow_get_mainwindow())
8462 summaryview = mainwindow_get_mainwindow()->summaryview;
8465 list = summary_get_selected_msg_list(summaryview);
8467 for (cur = list; cur; cur = cur->next) {
8468 MsgInfo *msginfo = (MsgInfo *)cur->data;
8471 file = procmsg_get_message_file_full(msginfo,
8474 compose_attach_append(compose, (const gchar *)file,
8475 (const gchar *)file, "message/rfc822");
8483 static gboolean compose_drag_drop(GtkWidget *widget,
8484 GdkDragContext *drag_context,
8486 guint time, gpointer user_data)
8488 /* not handling this signal makes compose_insert_drag_received_cb
8493 static void compose_insert_drag_received_cb (GtkWidget *widget,
8494 GdkDragContext *drag_context,
8497 GtkSelectionData *data,
8502 Compose *compose = (Compose *)user_data;
8505 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8507 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8508 AlertValue val = G_ALERTDEFAULT;
8510 switch (prefs_common.compose_dnd_mode) {
8511 case COMPOSE_DND_ASK:
8512 val = alertpanel_full(_("Insert or attach?"),
8513 _("Do you want to insert the contents of the file(s) "
8514 "into the message body, or attach it to the email?"),
8515 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
8516 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
8518 case COMPOSE_DND_INSERT:
8519 val = G_ALERTALTERNATE;
8521 case COMPOSE_DND_ATTACH:
8525 /* unexpected case */
8526 g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
8529 if (val & G_ALERTDISABLE) {
8530 val &= ~G_ALERTDISABLE;
8531 /* remember what action to perform by default, only if we don't click Cancel */
8532 if (val == G_ALERTALTERNATE)
8533 prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
8534 else if (val == G_ALERTOTHER)
8535 prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
8538 if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
8539 gtk_drag_finish(drag_context, FALSE, FALSE, time);
8541 } else if (val == G_ALERTOTHER) {
8542 compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
8545 list = uri_list_extract_filenames((const gchar *)data->data);
8546 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8547 compose_insert_file(compose, (const gchar *)tmp->data);
8549 list_free_strings(list);
8551 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8554 #if GTK_CHECK_VERSION(2, 8, 0)
8555 /* do nothing, handled by GTK */
8557 gchar *tmpfile = get_tmp_file();
8558 str_write_to_file((const gchar *)data->data, tmpfile);
8559 compose_insert_file(compose, tmpfile);
8562 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8566 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8569 static void compose_header_drag_received_cb (GtkWidget *widget,
8570 GdkDragContext *drag_context,
8573 GtkSelectionData *data,
8578 GtkEditable *entry = (GtkEditable *)user_data;
8579 gchar *email = (gchar *)data->data;
8581 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8584 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8585 gchar *decoded=g_new(gchar, strlen(email));
8588 email += strlen("mailto:");
8589 decode_uri(decoded, email); /* will fit */
8590 gtk_editable_delete_text(entry, 0, -1);
8591 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8592 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8596 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8599 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8602 Compose *compose = (Compose *)data;
8604 if (GTK_CHECK_MENU_ITEM(widget)->active)
8605 compose->return_receipt = TRUE;
8607 compose->return_receipt = FALSE;
8610 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8613 Compose *compose = (Compose *)data;
8615 if (GTK_CHECK_MENU_ITEM(widget)->active)
8616 compose->remove_references = TRUE;
8618 compose->remove_references = FALSE;
8621 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8623 ComposeHeaderEntry *headerentry)
8625 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8626 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8627 !(event->state & GDK_MODIFIER_MASK) &&
8628 (event->keyval == GDK_BackSpace) &&
8629 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8630 gtk_container_remove
8631 (GTK_CONTAINER(headerentry->compose->header_table),
8632 headerentry->combo);
8633 gtk_container_remove
8634 (GTK_CONTAINER(headerentry->compose->header_table),
8635 headerentry->entry);
8636 headerentry->compose->header_list =
8637 g_slist_remove(headerentry->compose->header_list,
8639 g_free(headerentry);
8640 } else if (event->keyval == GDK_Tab) {
8641 if (headerentry->compose->header_last == headerentry) {
8642 /* Override default next focus, and give it to subject_entry
8643 * instead of notebook tabs
8645 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8646 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8653 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8654 ComposeHeaderEntry *headerentry)
8656 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8657 headerentry->compose->header_list =
8658 g_slist_append(headerentry->compose->header_list,
8661 compose_create_header_entry(headerentry->compose);
8662 g_signal_handlers_disconnect_matched
8663 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8664 0, 0, NULL, NULL, headerentry);
8666 /* Automatically scroll down */
8667 compose_show_first_last_header(headerentry->compose, FALSE);
8673 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8675 GtkAdjustment *vadj;
8677 g_return_if_fail(compose);
8678 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8679 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8681 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8682 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8685 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8686 const gchar *text, gint len, Compose *compose)
8688 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8689 (G_OBJECT(compose->text), "paste_as_quotation"));
8692 g_return_if_fail(text != NULL);
8694 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8695 G_CALLBACK(text_inserted),
8697 if (paste_as_quotation) {
8704 new_text = g_strndup(text, len);
8705 if (prefs_common.quotemark && *prefs_common.quotemark)
8706 qmark = prefs_common.quotemark;
8710 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8711 gtk_text_buffer_place_cursor(buffer, iter);
8713 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8715 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8716 GINT_TO_POINTER(paste_as_quotation - 1));
8718 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8719 gtk_text_buffer_place_cursor(buffer, iter);
8721 if (strcmp(text, "\n") || automatic_break
8722 || gtk_text_iter_starts_line(iter))
8723 gtk_text_buffer_insert(buffer, iter, text, len);
8725 debug_print("insert nowrap \\n\n");
8726 gtk_text_buffer_insert_with_tags_by_name(buffer,
8727 iter, text, len, "no_join", NULL);
8731 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8733 compose_beautify_paragraph(compose, iter, FALSE);
8735 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8736 gtk_text_buffer_delete_mark(buffer, mark);
8738 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8739 G_CALLBACK(text_inserted),
8741 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8743 if (prefs_common.autosave &&
8744 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8745 compose->draft_timeout_tag = gtk_timeout_add
8746 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8748 static gint compose_defer_auto_save_draft(Compose *compose)
8750 compose->draft_timeout_tag = -1;
8751 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8756 static void compose_check_all(Compose *compose)
8758 if (compose->gtkaspell)
8759 gtkaspell_check_all(compose->gtkaspell);
8762 static void compose_highlight_all(Compose *compose)
8764 if (compose->gtkaspell)
8765 gtkaspell_highlight_all(compose->gtkaspell);
8768 static void compose_check_backwards(Compose *compose)
8770 if (compose->gtkaspell)
8771 gtkaspell_check_backwards(compose->gtkaspell);
8773 GtkItemFactory *ifactory;
8774 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8775 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8776 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8780 static void compose_check_forwards_go(Compose *compose)
8782 if (compose->gtkaspell)
8783 gtkaspell_check_forwards_go(compose->gtkaspell);
8785 GtkItemFactory *ifactory;
8786 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8787 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8788 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8794 *\brief Guess originating forward account from MsgInfo and several
8795 * "common preference" settings. Return NULL if no guess.
8797 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8799 PrefsAccount *account = NULL;
8801 g_return_val_if_fail(msginfo, NULL);
8802 g_return_val_if_fail(msginfo->folder, NULL);
8803 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8805 if (msginfo->folder->prefs->enable_default_account)
8806 account = account_find_from_id(msginfo->folder->prefs->default_account);
8809 account = msginfo->folder->folder->account;
8811 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8813 Xstrdup_a(to, msginfo->to, return NULL);
8814 extract_address(to);
8815 account = account_find_from_address(to);
8818 if (!account && prefs_common.forward_account_autosel) {
8820 if (!procheader_get_header_from_msginfo
8821 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8822 extract_address(cc);
8823 account = account_find_from_address(cc);
8830 gboolean compose_close(Compose *compose)
8834 if (!g_mutex_trylock(compose->mutex)) {
8835 /* we have to wait for the (possibly deferred by auto-save)
8836 * drafting to be done, before destroying the compose under
8838 debug_print("waiting for drafting to finish...\n");
8839 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8842 g_return_val_if_fail(compose, FALSE);
8843 gtkut_widget_get_uposition(compose->window, &x, &y);
8844 prefs_common.compose_x = x;
8845 prefs_common.compose_y = y;
8846 g_mutex_unlock(compose->mutex);
8847 compose_destroy(compose);
8852 * Add entry field for each address in list.
8853 * \param compose E-Mail composition object.
8854 * \param listAddress List of (formatted) E-Mail addresses.
8856 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8861 addr = ( gchar * ) node->data;
8862 compose_entry_append( compose, addr, COMPOSE_TO );
8863 node = g_list_next( node );
8867 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
8868 guint action, gboolean opening_multiple)
8871 GSList *new_msglist = NULL;
8872 MsgInfo *tmp_msginfo = NULL;
8873 gboolean originally_enc = FALSE;
8874 Compose *compose = NULL;
8876 g_return_if_fail(msgview != NULL);
8878 g_return_if_fail(msginfo_list != NULL);
8880 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
8881 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8882 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8884 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8885 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8886 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8887 orig_msginfo, mimeinfo);
8888 if (tmp_msginfo != NULL) {
8889 new_msglist = g_slist_append(NULL, tmp_msginfo);
8890 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8891 originally_enc = TRUE;
8897 if (!opening_multiple)
8898 body = messageview_get_selection(msgview);
8901 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8902 procmsg_msginfo_free(tmp_msginfo);
8903 g_slist_free(new_msglist);
8905 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8907 if (originally_enc) {
8908 compose_force_encryption(compose, compose->account, FALSE);
8914 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8917 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
8918 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
8919 GSList *cur = msginfo_list;
8920 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
8921 "messages. Opening the windows "
8922 "could take some time. Do you "
8923 "want to continue?"),
8924 g_slist_length(msginfo_list));
8925 if (g_slist_length(msginfo_list) > 9
8926 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
8927 != G_ALERTALTERNATE) {
8932 /* We'll open multiple compose windows */
8933 /* let the WM place the next windows */
8934 compose_force_window_origin = FALSE;
8935 for (; cur; cur = cur->next) {
8937 tmplist.data = cur->data;
8938 tmplist.next = NULL;
8939 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
8941 compose_force_window_origin = TRUE;
8943 /* forwarding multiple mails as attachments is done via a
8944 * single compose window */
8945 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
8949 void compose_set_position(Compose *compose, gint pos)
8951 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8953 gtkut_text_view_set_position(text, pos);
8956 gboolean compose_search_string(Compose *compose,
8957 const gchar *str, gboolean case_sens)
8959 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8961 return gtkut_text_view_search_string(text, str, case_sens);
8964 gboolean compose_search_string_backward(Compose *compose,
8965 const gchar *str, gboolean case_sens)
8967 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8969 return gtkut_text_view_search_string_backward(text, str, case_sens);